Changeset 87c8f1a in opengl-game for graphics-pipeline_vulkan.cpp
- Timestamp:
- Nov 1, 2019, 5:11:45 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- d2d9286
- Parents:
- 34bdf3a
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (11/01/19 17:09:16)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (11/01/19 17:11:45)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.cpp
r34bdf3a r87c8f1a 5 5 #include <iostream> 6 6 7 #include "vulkan-utils.hpp" 8 7 9 using namespace std; 8 10 9 11 // TODO: Remove any instances of cout and instead throw exceptions 10 12 11 GraphicsPipeline_Vulkan::GraphicsPipeline_Vulkan(VkDevice device, VkRenderPass renderPass, Viewport viewport, 12 int vertexSize) { 13 GraphicsPipeline_Vulkan::GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device, 14 VkRenderPass renderPass, Viewport viewport, int vertexSize) { 15 this->physicalDevice = physicalDevice; 13 16 this->device = device; 14 17 this->renderPass = renderPass; 15 18 this->viewport = viewport; 16 19 20 // Since there is only one array of vertex data, we use binding = 0 21 // I'll probably do that for the foreseeable future 22 // I can calculate the stride myself given info about all the varying attributes 17 23 this->bindingDescription.binding = 0; 18 24 this->bindingDescription.stride = vertexSize; … … 21 27 22 28 GraphicsPipeline_Vulkan::~GraphicsPipeline_Vulkan() { 29 } 30 31 void GraphicsPipeline_Vulkan::createVertexBuffer(const void* bufferData, int vertexSize, 32 VkCommandPool commandPool, VkQueue graphicsQueue) { 33 VkDeviceSize bufferSize = numVertices * vertexSize; 34 VkDeviceSize bufferCapacity = vertexCapacity * vertexSize; 35 36 VkBuffer stagingBuffer; 37 VkDeviceMemory stagingBufferMemory; 38 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, 39 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 40 stagingBuffer, stagingBufferMemory); 41 42 void* data; 43 vkMapMemory(device, stagingBufferMemory, 0, bufferSize, 0, &data); 44 memcpy(data, bufferData, (size_t) bufferSize); 45 vkUnmapMemory(device, stagingBufferMemory); 46 47 VulkanUtils::createBuffer(device, physicalDevice, bufferCapacity, 48 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, 49 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, vertexBuffer, vertexBufferMemory); 50 51 VulkanUtils::copyBuffer(device, commandPool, stagingBuffer, vertexBuffer, 0, 0, bufferSize, graphicsQueue); 52 53 vkDestroyBuffer(device, stagingBuffer, nullptr); 54 vkFreeMemory(device, stagingBufferMemory, nullptr); 55 } 56 57 void GraphicsPipeline_Vulkan::createIndexBuffer(const void* bufferData, int indexSize, 58 VkCommandPool commandPool, VkQueue graphicsQueue) { 59 VkDeviceSize bufferSize = numIndices * indexSize; 60 VkDeviceSize bufferCapacity = indexCapacity * indexSize; 61 62 VkBuffer stagingBuffer; 63 VkDeviceMemory stagingBufferMemory; 64 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, 65 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 66 stagingBuffer, stagingBufferMemory); 67 68 void* data; 69 vkMapMemory(device, stagingBufferMemory, 0, bufferSize, 0, &data); 70 memcpy(data, bufferData, (size_t) bufferSize); 71 vkUnmapMemory(device, stagingBufferMemory); 72 73 VulkanUtils::createBuffer(device, physicalDevice, bufferCapacity, 74 VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT, 75 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexBuffer, indexBufferMemory); 76 77 VulkanUtils::copyBuffer(device, commandPool, stagingBuffer, indexBuffer, 0, 0, bufferSize, graphicsQueue); 78 79 vkDestroyBuffer(device, stagingBuffer, nullptr); 80 vkFreeMemory(device, stagingBufferMemory, nullptr); 23 81 } 24 82 … … 313 371 314 372 void GraphicsPipeline_Vulkan::cleanup() { 315 vkDestroyPipeline( this->device, this->pipeline, nullptr);316 vkDestroyDescriptorPool( this->device, this->descriptorPool, nullptr);317 vkDestroyPipelineLayout( this->device, this->pipelineLayout, nullptr);373 vkDestroyPipeline(device, pipeline, nullptr); 374 vkDestroyDescriptorPool(device, descriptorPool, nullptr); 375 vkDestroyPipelineLayout(device, pipelineLayout, nullptr); 318 376 } 319 377 320 378 void GraphicsPipeline_Vulkan::cleanupBuffers() { 321 vkDestroyDescriptorSetLayout(this->device, this->descriptorSetLayout, nullptr); 322 } 379 vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); 380 381 vkDestroyBuffer(device, vertexBuffer, nullptr); 382 vkFreeMemory(device, vertexBufferMemory, nullptr); 383 vkDestroyBuffer(device, indexBuffer, nullptr); 384 vkFreeMemory(device, indexBufferMemory, nullptr); 385 }
Note:
See TracChangeset
for help on using the changeset viewer.