Changeset 58453c3 in opengl-game
- Timestamp:
- May 20, 2021, 3:50:12 PM (3 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)
- Files:
-
- 5 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 -
sdl-game.cpp
rc163d81 r58453c3 169 169 modelPipeline.createDescriptorSetLayout(); 170 170 modelPipeline.createPipeline("shaders/model-vert.spv", "shaders/model-frag.spv"); 171 modelPipeline.createDescriptorPool(swapChainImages );172 modelPipeline.createDescriptorSets(swapChainImages );171 modelPipeline.createDescriptorPool(swapChainImages.size()); 172 modelPipeline.createDescriptorSets(swapChainImages.size()); 173 173 174 174 currentRenderScreenFn = &VulkanGame::renderMainScreen; … … 270 270 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 271 271 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 272 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages,16, 24);272 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 16, 24); 273 273 274 274 createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject), … … 1266 1266 modelPipeline.updateRenderPass(renderPass); 1267 1267 modelPipeline.createPipeline("shaders/model-vert.spv", "shaders/model-frag.spv"); 1268 modelPipeline.createDescriptorPool(swapChainImages );1269 modelPipeline.createDescriptorSets(swapChainImages );1268 modelPipeline.createDescriptorPool(swapChainImages.size()); 1269 modelPipeline.createDescriptorSets(swapChainImages.size()); 1270 1270 1271 1271 imageIndex = 0; -
sdl-game.hpp
rc163d81 r58453c3 292 292 BufferSet& set); 293 293 294 // TODO: See if it makes sense to rename this to resizeBufferSet() and use it to resize other types of buffers as well295 // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in296 294 template<class VertexType, class SSBOType> 297 295 void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer, … … 378 376 // Assume the SSBO is always the 2nd binding 379 377 // TODO: Figure out a way to make this more flexible 380 pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages );378 pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages.size()); 381 379 } 382 380 -
vulkan-game.cpp
rc163d81 r58453c3 194 194 modelPipeline.createDescriptorSetLayout(); 195 195 modelPipeline.createPipeline("shaders/model-vert.spv", "shaders/model-frag.spv"); 196 modelPipeline.createDescriptorPool(swapChainImages );197 modelPipeline.createDescriptorSets(swapChainImages );196 modelPipeline.createDescriptorPool(swapChainImages.size()); 197 modelPipeline.createDescriptorSets(swapChainImages.size()); 198 198 199 199 // START UNREVIEWED SECTION … … 458 458 shipPipeline.createDescriptorSetLayout(); 459 459 shipPipeline.createPipeline("shaders/ship-vert.spv", "shaders/ship-frag.spv"); 460 shipPipeline.createDescriptorPool(swapChainImages );461 shipPipeline.createDescriptorSets(swapChainImages );460 shipPipeline.createDescriptorPool(swapChainImages.size()); 461 shipPipeline.createDescriptorSets(swapChainImages.size()); 462 462 463 463 asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos)); … … 478 478 asteroidPipeline.createDescriptorSetLayout(); 479 479 asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv"); 480 asteroidPipeline.createDescriptorPool(swapChainImages );481 asteroidPipeline.createDescriptorSets(swapChainImages );480 asteroidPipeline.createDescriptorPool(swapChainImages.size()); 481 asteroidPipeline.createDescriptorSets(swapChainImages.size()); 482 482 483 483 laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::pos)); … … 498 498 laserPipeline.createDescriptorSetLayout(); 499 499 laserPipeline.createPipeline("shaders/laser-vert.spv", "shaders/laser-frag.spv"); 500 laserPipeline.createDescriptorPool(swapChainImages );501 laserPipeline.createDescriptorSets(swapChainImages );500 laserPipeline.createDescriptorPool(swapChainImages.size()); 501 laserPipeline.createDescriptorSets(swapChainImages.size()); 502 502 503 503 explosionPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ExplosionVertex::particleStartVelocity)); … … 516 516 explosionPipeline.createDescriptorSetLayout(); 517 517 explosionPipeline.createPipeline("shaders/explosion-vert.spv", "shaders/explosion-frag.spv"); 518 explosionPipeline.createDescriptorPool(swapChainImages );519 explosionPipeline.createDescriptorSets(swapChainImages );518 explosionPipeline.createDescriptorPool(swapChainImages.size()); 519 explosionPipeline.createDescriptorSets(swapChainImages.size()); 520 520 521 521 // END UNREVIEWED SECTION … … 619 619 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 620 620 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 621 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages,24, 24);621 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 24); 622 622 623 623 createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject), … … 628 628 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 629 629 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 630 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages,138, 138);630 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 138, 138); 631 631 632 632 createBufferSet(objects_shipPipeline.capacity * sizeof(SSBO_ModelObject), … … 637 637 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 638 638 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 639 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages,24, 36);639 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 36); 640 640 641 641 createBufferSet(objects_asteroidPipeline.capacity * sizeof(SSBO_Asteroid), … … 646 646 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>( 647 647 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 648 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages,8, 18);648 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 8, 18); 649 649 650 650 createBufferSet(objects_laserPipeline.capacity * sizeof(SSBO_Laser), … … 656 656 VK_PRIMITIVE_TOPOLOGY_POINT_LIST, physicalDevice, device, renderPass, 657 657 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 658 swapChainImages,EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT);658 EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT); 659 659 660 660 createBufferSet(objects_explosionPipeline.capacity * sizeof(SSBO_Explosion), … … 2226 2226 modelPipeline.updateRenderPass(renderPass); 2227 2227 modelPipeline.createPipeline("shaders/model-vert.spv", "shaders/model-frag.spv"); 2228 modelPipeline.createDescriptorPool(swapChainImages );2229 modelPipeline.createDescriptorSets(swapChainImages );2228 modelPipeline.createDescriptorPool(swapChainImages.size()); 2229 modelPipeline.createDescriptorSets(swapChainImages.size()); 2230 2230 2231 2231 createBufferSet(sizeof(UBO_VP_mats), … … 2235 2235 shipPipeline.updateRenderPass(renderPass); 2236 2236 shipPipeline.createPipeline("shaders/ship-vert.spv", "shaders/ship-frag.spv"); 2237 shipPipeline.createDescriptorPool(swapChainImages );2238 shipPipeline.createDescriptorSets(swapChainImages );2237 shipPipeline.createDescriptorPool(swapChainImages.size()); 2238 shipPipeline.createDescriptorSets(swapChainImages.size()); 2239 2239 2240 2240 createBufferSet(sizeof(UBO_VP_mats), … … 2244 2244 asteroidPipeline.updateRenderPass(renderPass); 2245 2245 asteroidPipeline.createPipeline("shaders/asteroid-vert.spv", "shaders/asteroid-frag.spv"); 2246 asteroidPipeline.createDescriptorPool(swapChainImages );2247 asteroidPipeline.createDescriptorSets(swapChainImages );2246 asteroidPipeline.createDescriptorPool(swapChainImages.size()); 2247 asteroidPipeline.createDescriptorSets(swapChainImages.size()); 2248 2248 2249 2249 createBufferSet(sizeof(UBO_VP_mats), … … 2253 2253 laserPipeline.updateRenderPass(renderPass); 2254 2254 laserPipeline.createPipeline("shaders/laser-vert.spv", "shaders/laser-frag.spv"); 2255 laserPipeline.createDescriptorPool(swapChainImages );2256 laserPipeline.createDescriptorSets(swapChainImages );2255 laserPipeline.createDescriptorPool(swapChainImages.size()); 2256 laserPipeline.createDescriptorSets(swapChainImages.size()); 2257 2257 2258 2258 createBufferSet(sizeof(UBO_Explosion), … … 2262 2262 explosionPipeline.updateRenderPass(renderPass); 2263 2263 explosionPipeline.createPipeline("shaders/explosion-vert.spv", "shaders/explosion-frag.spv"); 2264 explosionPipeline.createDescriptorPool(swapChainImages );2265 explosionPipeline.createDescriptorSets(swapChainImages );2264 explosionPipeline.createDescriptorPool(swapChainImages.size()); 2265 explosionPipeline.createDescriptorSets(swapChainImages.size()); 2266 2266 2267 2267 imageIndex = 0; -
vulkan-game.hpp
rc163d81 r58453c3 435 435 BufferSet& set); 436 436 437 // TODO: See if it makes sense to rename this to resizeBufferSet() and use it to resize other types of buffers as well438 // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in439 437 template<class VertexType, class SSBOType> 440 438 void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer, … … 541 539 // Assume the SSBO is always the 2nd binding 542 540 // TODO: Figure out a way to make this more flexible 543 pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages );541 pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages.size()); 544 542 } 545 543
Note:
See TracChangeset
for help on using the changeset viewer.