Changeset bb76950 in opengl-game


Ignore:
Timestamp:
Jun 9, 2021, 6:41:48 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
b7fc3c2
Parents:
6bac215
git-author:
Dmitry Portnoy <dportnoy@…> (06/09/21 18:41:20)
git-committer:
Dmitry Portnoy <dportnoy@…> (06/09/21 18:41:48)
Message:

Change VulkanGame::resizeBufferSet() to take a buffer size instead of an entire
VulkanBuffer object, and to not update descriptor sets, which obviates the need
to pass in a GraphicsPipeline_Vulkan object. Descriptor set updates must
now be handled separetly.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r6bac215 rbb76950  
    459459   if (objects_modelPipeline.resized) {
    460460      // TODO: Also resize the dynamic ubo
    461       resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline, modelPipeline, resourceCommandPool,
    462                       graphicsQueue);
     461      resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
     462                      resourceCommandPool, graphicsQueue, true);
    463463
    464464      objects_modelPipeline.resize();
     465
     466      modelPipeline.updateDescriptorInfo(1, &storageBuffers_modelPipeline.infoSet, swapChainImages.size());
    465467   }
    466468
     
    11301132}
    11311133
     1134void VulkanGame::resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool,
     1135                                 VkQueue graphicsQueue, bool copyData) {
     1136   for (size_t i = 0; i < set.buffers.size(); i++) {
     1137      VkBuffer newBuffer;
     1138      VkDeviceMemory newMemory;
     1139
     1140      VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory);
     1141
     1142      if (copyData) {
     1143         VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range,
     1144                                 graphicsQueue);
     1145      }
     1146
     1147      vkDestroyBuffer(device, set.buffers[i], nullptr);
     1148      vkFreeMemory(device, set.memory[i], nullptr);
     1149
     1150      set.buffers[i] = newBuffer;
     1151      set.memory[i] = newMemory;
     1152
     1153      set.infoSet[i].buffer = set.buffers[i];
     1154      set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
     1155      set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
     1156   }
     1157}
     1158
    11321159void VulkanGame::renderFrame(ImDrawData* draw_data) {
    11331160   VkResult result = vkAcquireNextImageKHR(device, swapChain, numeric_limits<uint64_t>::max(),
  • sdl-game.hpp

    r6bac215 rbb76950  
    108108   vec3 center; // currently only matters for asteroids
    109109   float radius; // currently only matters for asteroids
     110
     111   // Move the targetAsteroid stuff out of this class since it is very specific to lasers
     112   // and makes moving SceneObject into its own header file more problematic
    110113   SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers
    111114};
     
    297300                           BufferSet& set);
    298301
    299       template<class VertexType, class SSBOType>
    300       void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
    301                            GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
    302                            VkQueue graphicsQueue);
     302      void resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool, VkQueue graphicsQueue,
     303                           bool copyData);
    303304
    304305      template<class SSBOType>
     
    343344      void quitGame();
    344345};
    345 
    346 template<class VertexType, class SSBOType>
    347 void VulkanGame::resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
    348                                  GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
    349                                  VkQueue graphicsQueue) {
    350    VkDeviceSize newSize = buffer.capacity * sizeof(SSBOType);
    351 
    352    for (size_t i = 0; i < set.buffers.size(); i++) {
    353       VkBuffer newBuffer;
    354       VkDeviceMemory newMemory;
    355 
    356       VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory);
    357 
    358       VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range,
    359                               graphicsQueue);
    360 
    361       vkDestroyBuffer(device, set.buffers[i], nullptr);
    362       vkFreeMemory(device, set.memory[i], nullptr);
    363 
    364       set.buffers[i] = newBuffer;
    365       set.memory[i] = newMemory;
    366 
    367       set.infoSet[i].buffer = set.buffers[i];
    368       set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
    369       set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
    370    }
    371 
    372    // Assume the SSBO is always the 2nd binding
    373    // TODO: Figure out a way to make this more flexible
    374    pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages.size());
    375 }
    376346
    377347// TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
  • vulkan-game.cpp

    r6bac215 rbb76950  
    10891089   }
    10901090
     1091   // TODO: Replace updateBufferSet to one call to copyDataToMemory, using VulkanBuffer to provide the data source
     1092   // TODO: Figure out a way to make updateDescriptorInfo easier to use, maybe store the binding index in the buffer set
    10911093   // TODO: Probably move the resizing to the VulkanBuffer class
     1094
    10921095   if (objects_modelPipeline.resized) {
    1093       resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline, modelPipeline, resourceCommandPool,
    1094                       graphicsQueue);
     1096      resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
     1097                      resourceCommandPool, graphicsQueue, true);
    10951098
    10961099      objects_modelPipeline.resize();
     1100
     1101      modelPipeline.updateDescriptorInfo(1, &storageBuffers_modelPipeline.infoSet, swapChainImages.size());
    10971102   }
    10981103
     
    11061111   // TODO: Probably move the resizing to the VulkanBuffer class
    11071112   if (objects_shipPipeline.resized) {
    1108       resizeBufferSet(storageBuffers_shipPipeline, objects_shipPipeline, shipPipeline, resourceCommandPool,
    1109                       graphicsQueue);
     1113      resizeBufferSet(storageBuffers_shipPipeline, objects_shipPipeline.capacity * sizeof(SSBO_ModelObject),
     1114                      resourceCommandPool, graphicsQueue, true);
    11101115
    11111116      objects_shipPipeline.resize();
     1117
     1118      shipPipeline.updateDescriptorInfo(1, &storageBuffers_shipPipeline.infoSet, swapChainImages.size());
    11121119   }
    11131120
     
    11211128   // TODO: Probably move the resizing to the VulkanBuffer class
    11221129   if (objects_asteroidPipeline.resized) {
    1123       resizeBufferSet(storageBuffers_asteroidPipeline, objects_asteroidPipeline, asteroidPipeline,
    1124                       resourceCommandPool, graphicsQueue);
     1130      resizeBufferSet(storageBuffers_asteroidPipeline, objects_asteroidPipeline.capacity * sizeof(SSBO_Asteroid),
     1131                      resourceCommandPool, graphicsQueue, true);
    11251132
    11261133      objects_asteroidPipeline.resize();
     1134
     1135      asteroidPipeline.updateDescriptorInfo(1, &storageBuffers_asteroidPipeline.infoSet, swapChainImages.size());
    11271136   }
    11281137
     
    11361145   // TODO: Probably move the resizing to the VulkanBuffer class
    11371146   if (objects_laserPipeline.resized) {
    1138       resizeBufferSet(storageBuffers_laserPipeline, objects_laserPipeline, laserPipeline, resourceCommandPool,
    1139                       graphicsQueue);
     1147      resizeBufferSet(storageBuffers_laserPipeline, objects_laserPipeline.capacity * sizeof(SSBO_Laser),
     1148                      resourceCommandPool, graphicsQueue, true);
    11401149
    11411150      objects_laserPipeline.resize();
     1151
     1152      laserPipeline.updateDescriptorInfo(1, &storageBuffers_laserPipeline.infoSet, swapChainImages.size());
    11421153   }
    11431154
     
    11511162   // TODO: Probably move the resizing to the VulkanBuffer class
    11521163   if (objects_explosionPipeline.resized) {
    1153       resizeBufferSet(storageBuffers_explosionPipeline, objects_explosionPipeline, explosionPipeline,
    1154                      resourceCommandPool, graphicsQueue);
     1164      resizeBufferSet(storageBuffers_explosionPipeline, objects_explosionPipeline.capacity * sizeof(SSBO_Explosion),
     1165                      resourceCommandPool, graphicsQueue, true);
    11551166
    11561167      objects_explosionPipeline.resize();
     1168
     1169      explosionPipeline.updateDescriptorInfo(1, &storageBuffers_explosionPipeline.infoSet, swapChainImages.size());
    11571170   }
    11581171
     
    19621975      set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
    19631976      set.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
     1977   }
     1978}
     1979
     1980void VulkanGame::resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool,
     1981                                 VkQueue graphicsQueue, bool copyData) {
     1982   for (size_t i = 0; i < set.buffers.size(); i++) {
     1983      VkBuffer newBuffer;
     1984      VkDeviceMemory newMemory;
     1985
     1986      VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory);
     1987
     1988      if (copyData) {
     1989         VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range,
     1990                                 graphicsQueue);
     1991      }
     1992
     1993      vkDestroyBuffer(device, set.buffers[i], nullptr);
     1994      vkFreeMemory(device, set.memory[i], nullptr);
     1995
     1996      set.buffers[i] = newBuffer;
     1997      set.memory[i] = newMemory;
     1998
     1999      set.infoSet[i].buffer = set.buffers[i];
     2000      set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
     2001      set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
    19642002   }
    19652003}
  • vulkan-game.hpp

    r6bac215 rbb76950  
    124124   vec3 center; // currently only matters for asteroids
    125125   float radius; // currently only matters for asteroids
     126
     127   // Move the targetAsteroid stuff out of this class since it is very specific to lasers
     128   // and makes moving SceneObject into its own header file more problematic
    126129   SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers
    127130};
     
    432435                           BufferSet& set);
    433436
    434       template<class VertexType, class SSBOType>
    435       void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
    436                            GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
    437                            VkQueue graphicsQueue);
     437      void resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool, VkQueue graphicsQueue,
     438                           bool copyData);
    438439
    439440      template<class SSBOType>
     
    498499
    499500// End of specialized no-op functions
    500 
    501 template<class VertexType, class SSBOType>
    502 void VulkanGame::resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,
    503                                  GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
    504                                  VkQueue graphicsQueue) {
    505    VkDeviceSize newSize = buffer.capacity * sizeof(SSBOType);
    506 
    507    for (size_t i = 0; i < set.buffers.size(); i++) {
    508       VkBuffer newBuffer;
    509       VkDeviceMemory newMemory;
    510 
    511       VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory);
    512 
    513       VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range,
    514                               graphicsQueue);
    515 
    516       vkDestroyBuffer(device, set.buffers[i], nullptr);
    517       vkFreeMemory(device, set.memory[i], nullptr);
    518 
    519       set.buffers[i] = newBuffer;
    520       set.memory[i] = newMemory;
    521 
    522       set.infoSet[i].buffer = set.buffers[i];
    523       set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
    524       set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
    525    }
    526 
    527    // Assume the SSBO is always the 2nd binding
    528    // TODO: Figure out a way to make this more flexible
    529    pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages.size());
    530 }
    531501
    532502// TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
Note: See TracChangeset for help on using the changeset viewer.