Changeset 44f23af in opengl-game for graphics-pipeline_vulkan.hpp
- Timestamp:
- Feb 25, 2020, 9:29:36 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 0807aeb
- Parents:
- 3b84bb6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.hpp
r3b84bb6 r44f23af 41 41 class GraphicsPipeline_Vulkan : public GraphicsPipeline { 42 42 public: 43 string vertShaderFile, fragShaderFile; 44 43 45 GraphicsPipeline_Vulkan(); 44 46 … … 116 118 void resizeVertexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue); 117 119 void resizeIndexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue); 120 void resizeStorageBufferSet(StorageBufferSet& set, VkCommandPool commandPool, VkQueue graphicsQueue); 118 121 }; 119 122 … … 233 236 template<class VertexType, class SSBOType> 234 237 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createPipeline(string vertShaderFile, string fragShaderFile) { 238 this->vertShaderFile = vertShaderFile; 239 this->fragShaderFile = fragShaderFile; 240 235 241 vector<char> vertShaderCode = readFile(vertShaderFile); 236 242 vector<char> fragShaderCode = readFile(fragShaderFile); … … 492 498 resizeVertexBuffer(commandPool, graphicsQueue); 493 499 } 494 if (numIndices + indices.size() > indexCapacity) {495 resizeIndexBuffer(commandPool, graphicsQueue);496 }497 498 500 VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices, 499 501 graphicsQueue); 500 502 numVertices += vertices.size(); 501 503 504 if (numIndices + indices.size() > indexCapacity) { 505 resizeIndexBuffer(commandPool, graphicsQueue); 506 } 502 507 VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, indices, indexBuffer, numIndices, 503 508 graphicsQueue); … … 505 510 506 511 bool resizedStorageBuffer = false; 512 513 if (!is_same_v<SSBOType, void*>) { 514 if (this->numObjects == this->objectCapacity) { 515 resizeStorageBufferSet(storageBufferSet, commandPool, graphicsQueue); 516 cleanup(); 517 518 // Assume the SSBO is always the 2nd binding 519 this->descriptorInfoList[1].bufferDataList = &storageBufferSet.infoSet; 520 resizedStorageBuffer = true; 521 522 cout << "SSBO resized, New object capacity: " << this->objectCapacity << endl; 523 524 // TODO: I'll need to correctly update the descriptor set array instead of appending to it 525 // Then, I'll have to call createDescriptorSets() and finally createCommandBuffers() (from vulkan-game) 526 // This isn't too bad actually, since I have to call createCommandBuffers() every time I add a newobject 527 // anyway. So, in this function, I'll just have to call createDescriptorSets() 528 } 529 530 updateObject(this->numObjects, ssbo); 531 } 532 533 this->numObjects++; 507 534 508 535 return resizedStorageBuffer; … … 621 648 } 622 649 650 template<class VertexType, class SSBOType> 651 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeStorageBufferSet(StorageBufferSet& set, 652 VkCommandPool commandPool, VkQueue graphicsQueue) { 653 this->objectCapacity *= 2; 654 VkDeviceSize bufferSize = objectCapacity * sizeof(SSBOType); 655 656 for (size_t i = 0; i < set.buffers.size(); i++) { 657 VkBuffer newStorageBuffer; 658 VkDeviceMemory newStorageBufferMemory; 659 660 VulkanUtils::createBuffer(this->device, this->physicalDevice, bufferSize, 661 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 662 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 663 newStorageBuffer, newStorageBufferMemory); 664 665 VulkanUtils::copyBuffer(this->device, commandPool, set.buffers[i], newStorageBuffer, 666 0, 0, this->numObjects * sizeof(SSBOType), graphicsQueue); 667 668 vkDestroyBuffer(this->device, set.buffers[i], nullptr); 669 vkFreeMemory(this->device, set.memory[i], nullptr); 670 671 set.buffers[i] = newStorageBuffer; 672 set.memory[i] = newStorageBufferMemory; 673 674 set.infoSet[i].buffer = set.buffers[i]; 675 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now 676 set.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE 677 } 678 } 679 623 680 #endif // _GRAPHICS_PIPELINE_VULKAN_H
Note:
See TracChangeset
for help on using the changeset viewer.