Changeset 58453c3 in opengl-game for graphics-pipeline_vulkan.hpp
- Timestamp:
- May 20, 2021, 3:50:12 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 567fa88
- Parents:
- c163d81
- git-author:
- Dmitry Portnoy <dportnoy@…> (05/20/21 15:48:15)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (05/20/21 15:50:12)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.hpp
rc163d81 r58453c3 39 39 GraphicsPipeline_Vulkan(); 40 40 41 // TODO: swapChainImages is only ever used to get its size. Check how that is determined and,42 // if it will never change, just pass it in the constructor and save it43 // If it does change, I could add an updateSwapchainImageCount() function44 41 GraphicsPipeline_Vulkan(VkPrimitiveTopology topology, VkPhysicalDevice physicalDevice, VkDevice device, 45 VkRenderPass renderPass, Viewport viewport, vector<VkImage>& swapChainImages, 46 size_t vertexCapacity, size_t indexCapacity); 42 VkRenderPass renderPass, Viewport viewport, size_t vertexCapacity, size_t indexCapacity); 47 43 ~GraphicsPipeline_Vulkan(); 48 44 … … 60 56 void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData); 61 57 62 void updateDescriptorInfo(uint32_t index, vector<VkDescriptorBufferInfo>* bufferData, 63 vector<VkImage>& swapChainImages); 64 // TODO: Maybe make an analogous one for updating image info 58 void updateDescriptorInfo(uint32_t index, vector<VkDescriptorBufferInfo>* bufferData, uint32_t size); 65 59 66 60 void createPipeline(string vertShaderFile, string fragShaderFile); 67 61 void createDescriptorSetLayout(); 68 void createDescriptorPool( vector<VkImage>& swapChainImages);69 void createDescriptorSets( vector<VkImage>& swapChainImages);62 void createDescriptorPool(uint32_t size); 63 void createDescriptorSets(uint32_t size); 70 64 71 65 void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage); … … 128 122 VkPhysicalDevice physicalDevice, VkDevice device, 129 123 VkRenderPass renderPass, Viewport viewport, 130 vector<VkImage>& swapChainImages, size_t vertexCapacity, 131 size_t indexCapacity) 124 size_t vertexCapacity, size_t indexCapacity) 132 125 : topology(topology) 133 126 , physicalDevice(physicalDevice) … … 190 183 191 184 template<class VertexType> 192 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, 193 VkShaderStageFlags stageFlags,vector<VkDescriptorBufferInfo>* bufferData) {185 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, 186 vector<VkDescriptorBufferInfo>* bufferData) { 194 187 this->descriptorInfoList.push_back({ type, stageFlags, bufferData, nullptr }); 195 188 } 196 189 197 190 template<class VertexType> 198 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, 199 VkShaderStageFlags stageFlags,VkDescriptorImageInfo* imageData) {191 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, 192 VkDescriptorImageInfo* imageData) { 200 193 this->descriptorInfoList.push_back({ type, stageFlags, nullptr, imageData }); 201 194 } 202 195 196 // TODO: Maybe make an analogous one for updating image info 197 // Also, I may want to rewrite this function to call vkUpdateDescriptorSets once and call it once 198 // per swapchain image from VulkanGame 203 199 template<class VertexType> 204 200 void GraphicsPipeline_Vulkan<VertexType>::updateDescriptorInfo(uint32_t index, 205 201 vector<VkDescriptorBufferInfo>* bufferData, 206 vector<VkImage>& swapChainImages) {202 uint32_t size) { 207 203 this->descriptorInfoList[index].bufferDataList = bufferData; 208 204 209 205 // TODO: This code was mostly copied from createDescriptorSets. I should make some common function they both use 210 206 // for updating descriptor sets 211 for (size_t i = 0; i < s wapChainImages.size(); i++) {207 for (size_t i = 0; i < size; i++) { 212 208 VkWriteDescriptorSet descriptorWrite = {}; 213 209 … … 237 233 } 238 234 239 // TODO: Instead, assert that (bufferData->size() == swapChainImages.size() 240 if (bufferData->size() != s wapChainImages.size()) {235 // TODO: Instead, assert that (bufferData->size() == swapChainImages.size() (now just changed to size) 236 if (bufferData->size() != size) { 241 237 cout << "ALERT ALERT ALERT: SIZE MISMATCH!!!!!!!" << endl; 242 238 } … … 410 406 411 407 template<class VertexType> 412 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorPool( vector<VkImage>& swapChainImages) {408 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorPool(uint32_t size) { 413 409 vector<VkDescriptorPoolSize> poolSizes(this->descriptorInfoList.size()); 414 410 415 411 for (size_t i = 0; i < poolSizes.size(); i++) { 416 412 poolSizes[i].type = this->descriptorInfoList[i].type; 417 poolSizes[i].descriptorCount = s tatic_cast<uint32_t>(swapChainImages.size());413 poolSizes[i].descriptorCount = size; 418 414 } 419 415 … … 422 418 poolInfo.poolSizeCount = static_cast<uint32_t>(poolSizes.size()); 423 419 poolInfo.pPoolSizes = poolSizes.data(); 424 poolInfo.maxSets = s tatic_cast<uint32_t>(swapChainImages.size());420 poolInfo.maxSets = size; 425 421 426 422 if (vkCreateDescriptorPool(this->device, &poolInfo, nullptr, &this->descriptorPool) != VK_SUCCESS) { … … 429 425 } 430 426 431 // TODO: Since I only need the size of the swapChainImages array, I should just pass that in instead of the whole array 432 template<class VertexType> 433 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorSets(vector<VkImage>& swapChainImages) { 434 vector<VkDescriptorSetLayout> layouts(swapChainImages.size(), this->descriptorSetLayout); 427 template<class VertexType> 428 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorSets(uint32_t size) { 429 vector<VkDescriptorSetLayout> layouts(size, this->descriptorSetLayout); 435 430 436 431 VkDescriptorSetAllocateInfo allocInfo = {}; 437 432 allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; 438 433 allocInfo.descriptorPool = this->descriptorPool; 439 allocInfo.descriptorSetCount = s tatic_cast<uint32_t>(swapChainImages.size());434 allocInfo.descriptorSetCount = size; 440 435 allocInfo.pSetLayouts = layouts.data(); 441 436 442 this->descriptorSets.resize(s wapChainImages.size());437 this->descriptorSets.resize(size); 443 438 if (vkAllocateDescriptorSets(device, &allocInfo, this->descriptorSets.data()) != VK_SUCCESS) { 444 439 throw runtime_error("failed to allocate descriptor sets!"); 445 440 } 446 441 447 for (size_t i = 0; i < s wapChainImages.size(); i++) {442 for (size_t i = 0; i < size; i++) { 448 443 vector<VkWriteDescriptorSet> descriptorWrites(this->descriptorInfoList.size()); 449 444
Note:
See TracChangeset
for help on using the changeset viewer.