Changeset 58453c3 in opengl-game for graphics-pipeline_vulkan.hpp


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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.