Changeset 58453c3 in opengl-game


Ignore:
Timestamp:
May 20, 2021, 3:50:12 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
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)
Message:

Remove the swapChainImages parameter from the GraphicsPipeline_Vulkan constructor and modify createDescriptorPool(), createDescriptorSets(), and updateDescriptorInfo() to accept a size paramter instead of accepting a vector of swap chain images and getting the size from that

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    rc163d81 r58453c3  
    3939      GraphicsPipeline_Vulkan();
    4040
    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 it
    43       // If it does change, I could add an updateSwapchainImageCount() function
    4441      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);
    4743      ~GraphicsPipeline_Vulkan();
    4844
     
    6056      void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData);
    6157
    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);
    6559
    6660      void createPipeline(string vertShaderFile, string fragShaderFile);
    6761      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);
    7064
    7165      void createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage);
     
    128122                                                             VkPhysicalDevice physicalDevice, VkDevice device,
    129123                                                             VkRenderPass renderPass, Viewport viewport,
    130                                                              vector<VkImage>& swapChainImages, size_t vertexCapacity,
    131                                                              size_t indexCapacity)
     124                                                             size_t vertexCapacity, size_t indexCapacity)
    132125                                                            : topology(topology)
    133126                                                            , physicalDevice(physicalDevice)
     
    190183
    191184template<class VertexType>
    192 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type,
    193       VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData) {
     185void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags,
     186                                                            vector<VkDescriptorBufferInfo>* bufferData) {
    194187   this->descriptorInfoList.push_back({ type, stageFlags, bufferData, nullptr });
    195188}
    196189
    197190template<class VertexType>
    198 void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type,
    199       VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData) {
     191void GraphicsPipeline_Vulkan<VertexType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags,
     192                                                            VkDescriptorImageInfo* imageData) {
    200193   this->descriptorInfoList.push_back({ type, stageFlags, nullptr, imageData });
    201194}
    202195
     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
    203199template<class VertexType>
    204200void GraphicsPipeline_Vulkan<VertexType>::updateDescriptorInfo(uint32_t index,
    205201                                                               vector<VkDescriptorBufferInfo>* bufferData,
    206                                                                vector<VkImage>& swapChainImages) {
     202                                                               uint32_t size) {
    207203   this->descriptorInfoList[index].bufferDataList = bufferData;
    208204
    209205   // TODO: This code was mostly copied from createDescriptorSets. I should make some common function they both use
    210206   // for updating descriptor sets
    211    for (size_t i = 0; i < swapChainImages.size(); i++) {
     207   for (size_t i = 0; i < size; i++) {
    212208      VkWriteDescriptorSet descriptorWrite = {};
    213209
     
    237233      }
    238234
    239       // TODO: Instead, assert that (bufferData->size() == swapChainImages.size()
    240       if (bufferData->size() != swapChainImages.size()) {
     235      // TODO: Instead, assert that (bufferData->size() == swapChainImages.size() (now just changed to size)
     236      if (bufferData->size() != size) {
    241237         cout << "ALERT ALERT ALERT: SIZE MISMATCH!!!!!!!" << endl;
    242238      }
     
    410406
    411407template<class VertexType>
    412 void GraphicsPipeline_Vulkan<VertexType>::createDescriptorPool(vector<VkImage>& swapChainImages) {
     408void GraphicsPipeline_Vulkan<VertexType>::createDescriptorPool(uint32_t size) {
    413409   vector<VkDescriptorPoolSize> poolSizes(this->descriptorInfoList.size());
    414410
    415411   for (size_t i = 0; i < poolSizes.size(); i++) {
    416412      poolSizes[i].type = this->descriptorInfoList[i].type;
    417       poolSizes[i].descriptorCount = static_cast<uint32_t>(swapChainImages.size());
     413      poolSizes[i].descriptorCount = size;
    418414   }
    419415
     
    422418   poolInfo.poolSizeCount = static_cast<uint32_t>(poolSizes.size());
    423419   poolInfo.pPoolSizes = poolSizes.data();
    424    poolInfo.maxSets = static_cast<uint32_t>(swapChainImages.size());
     420   poolInfo.maxSets = size;
    425421
    426422   if (vkCreateDescriptorPool(this->device, &poolInfo, nullptr, &this->descriptorPool) != VK_SUCCESS) {
     
    429425}
    430426
    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);
     427template<class VertexType>
     428void GraphicsPipeline_Vulkan<VertexType>::createDescriptorSets(uint32_t size) {
     429   vector<VkDescriptorSetLayout> layouts(size, this->descriptorSetLayout);
    435430
    436431   VkDescriptorSetAllocateInfo allocInfo = {};
    437432   allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
    438433   allocInfo.descriptorPool = this->descriptorPool;
    439    allocInfo.descriptorSetCount = static_cast<uint32_t>(swapChainImages.size());
     434   allocInfo.descriptorSetCount = size;
    440435   allocInfo.pSetLayouts = layouts.data();
    441436
    442    this->descriptorSets.resize(swapChainImages.size());
     437   this->descriptorSets.resize(size);
    443438   if (vkAllocateDescriptorSets(device, &allocInfo, this->descriptorSets.data()) != VK_SUCCESS) {
    444439      throw runtime_error("failed to allocate descriptor sets!");
    445440   }
    446441
    447    for (size_t i = 0; i < swapChainImages.size(); i++) {
     442   for (size_t i = 0; i < size; i++) {
    448443      vector<VkWriteDescriptorSet> descriptorWrites(this->descriptorInfoList.size());
    449444
  • sdl-game.cpp

    rc163d81 r58453c3  
    169169   modelPipeline.createDescriptorSetLayout();
    170170   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());
    173173
    174174   currentRenderScreenFn = &VulkanGame::renderMainScreen;
     
    270270   modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
    271271      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);
    273273
    274274   createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
     
    12661266   modelPipeline.updateRenderPass(renderPass);
    12671267   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());
    12701270
    12711271   imageIndex = 0;
  • sdl-game.hpp

    rc163d81 r58453c3  
    292292                           BufferSet& set);
    293293
    294       // TODO: See if it makes sense to rename this to resizeBufferSet() and use it to resize other types of buffers as well
    295       // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in
    296294      template<class VertexType, class SSBOType>
    297295      void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
     
    378376   // Assume the SSBO is always the 2nd binding
    379377   // 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());
    381379}
    382380
  • vulkan-game.cpp

    rc163d81 r58453c3  
    194194   modelPipeline.createDescriptorSetLayout();
    195195   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());
    198198
    199199   // START UNREVIEWED SECTION
     
    458458   shipPipeline.createDescriptorSetLayout();
    459459   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());
    462462
    463463   asteroidPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos));
     
    478478   asteroidPipeline.createDescriptorSetLayout();
    479479   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());
    482482
    483483   laserPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&LaserVertex::pos));
     
    498498   laserPipeline.createDescriptorSetLayout();
    499499   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());
    502502
    503503   explosionPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ExplosionVertex::particleStartVelocity));
     
    516516   explosionPipeline.createDescriptorSetLayout();
    517517   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());
    520520
    521521   // END UNREVIEWED SECTION
     
    619619   modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
    620620      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);
    622622
    623623   createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
     
    628628   shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
    629629      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);
    631631
    632632   createBufferSet(objects_shipPipeline.capacity * sizeof(SSBO_ModelObject),
     
    637637   asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
    638638      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);
    640640
    641641   createBufferSet(objects_asteroidPipeline.capacity * sizeof(SSBO_Asteroid),
     
    646646   laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>(
    647647      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);
    649649
    650650   createBufferSet(objects_laserPipeline.capacity * sizeof(SSBO_Laser),
     
    656656      VK_PRIMITIVE_TOPOLOGY_POINT_LIST, physicalDevice, device, renderPass,
    657657      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height },
    658       swapChainImages, EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT);
     658      EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT);
    659659
    660660   createBufferSet(objects_explosionPipeline.capacity * sizeof(SSBO_Explosion),
     
    22262226   modelPipeline.updateRenderPass(renderPass);
    22272227   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());
    22302230
    22312231   createBufferSet(sizeof(UBO_VP_mats),
     
    22352235   shipPipeline.updateRenderPass(renderPass);
    22362236   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());
    22392239
    22402240   createBufferSet(sizeof(UBO_VP_mats),
     
    22442244   asteroidPipeline.updateRenderPass(renderPass);
    22452245   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());
    22482248
    22492249   createBufferSet(sizeof(UBO_VP_mats),
     
    22532253   laserPipeline.updateRenderPass(renderPass);
    22542254   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());
    22572257
    22582258   createBufferSet(sizeof(UBO_Explosion),
     
    22622262   explosionPipeline.updateRenderPass(renderPass);
    22632263   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());
    22662266
    22672267   imageIndex = 0;
  • vulkan-game.hpp

    rc163d81 r58453c3  
    435435                           BufferSet& set);
    436436
    437       // TODO: See if it makes sense to rename this to resizeBufferSet() and use it to resize other types of buffers as well
    438       // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in
    439437      template<class VertexType, class SSBOType>
    440438      void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
     
    541539   // Assume the SSBO is always the 2nd binding
    542540   // 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());
    544542}
    545543
Note: See TracChangeset for help on using the changeset viewer.