Changeset 996dd3e in opengl-game


Ignore:
Timestamp:
May 14, 2021, 1:09:34 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
a3cefaa
Parents:
9d21aac
Message:

Completely remove storage buffers from the GraphicsPipeline_Vulkan class and start moving storage buffer operations out of the addObject() and updateObject() functions

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    r9d21aac r996dd3e  
    2222using namespace glm;
    2323
    24 // TODO: Use this struct for uniform buffers as well and rename it to VulkanBuffer (maybe move it to VulkanUtils)
    25 // Also, probably better to make this a vector of structs where each struct
    26 // has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo
    27 struct StorageBufferSet {
    28    vector<VkBuffer> buffers;
    29    vector<VkDeviceMemory> memory;
    30    vector<VkDescriptorBufferInfo> infoSet;
    31 };
    32 
    3324// TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList
    3425struct DescriptorInfo {
     
    4536   public:
    4637      string vertShaderFile, fragShaderFile;
    47 
    48       // TODO: Move this outside this classs, since it is no longer used here
    49       StorageBufferSet storageBufferSet;
    5038
    5139      // Both of these are only used for managing the SSBO, so move them out as well
  • sdl-game.cpp

    r9d21aac r996dd3e  
    110110      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline);
    111111   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    112       VK_SHADER_STAGE_VERTEX_BIT, &modelPipeline.storageBufferSet.infoSet);
     112      VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_modelPipeline.infoSet);
    113113   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    114114      VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
     
    131131      }, {
    132132         mat4(1.0f)
    133       }, false);
     133      }, storageBuffers_modelPipeline, false);
     134
     135   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
    134136
    135137   texturedSquare->model_base =
     
    150152      }, {
    151153         mat4(1.0f)
    152       }, false);
     154      }, storageBuffers_modelPipeline, false);
     155
     156   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
    153157
    154158   texturedSquare->model_base =
     
    264268      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    265269      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    266       modelPipeline.storageBufferSet.buffers, modelPipeline.storageBufferSet.memory,
    267       modelPipeline.storageBufferSet.infoSet);
     270      storageBuffers_modelPipeline.buffers, storageBuffers_modelPipeline.memory,
     271      storageBuffers_modelPipeline.infoSet);
    268272}
    269273
     
    372376                        }, {
    373377                           mat4(1.0f)
    374                         }, true);
     378                        }, storageBuffers_modelPipeline, true);
     379
     380                  updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo);
    375381
    376382                  texturedSquare.model_base =
     
    439445}
    440446
    441 // TODO: The only updates that need to happen once per Vulkan image are the SSBO ones,
    442 // which are already handled by updateObject(). Move this code to a different place,
    443 // where it will run just once per frame
    444447void VulkanGame::updateScene() {
     448   // TODO: These two for loops could probably be combined into one
     449
    445450   for (SceneObject<ModelVertex, SSBO_ModelObject>& model : this->modelObjects) {
    446451      model.model_transform =
     
    450455   }
    451456
     457   // TODO: Instead, update entire sections (up to 64k) of the dynamic ubo if some objects there have changed
     458   // Also, update the objects modelMat and center in the loop above instead of here
    452459   for (size_t i = 0; i < modelObjects.size(); i++) {
    453460      if (modelObjects[i].modified) {
     461         // TODO: Think about changing the SSBO-related code to also use a contiguous array
     462         // to store the data on the cpu side instead of storing it per-object
     463         // Then, I could also copy it to the GPU in one go
     464         // Also, double-check if the alignment restrictions also hold for SSBOs
     465
    454466         updateObject(modelObjects, modelPipeline, i);
     467         updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo);
    455468      }
    456469   }
     
    475488   modelPipeline.cleanupBuffers();
    476489
    477    for (size_t i = 0; i < modelPipeline.storageBufferSet.buffers.size(); i++) {
    478       vkDestroyBuffer(device, modelPipeline.storageBufferSet.buffers[i], nullptr);
    479       vkFreeMemory(device, modelPipeline.storageBufferSet.memory[i], nullptr);
     490   for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {
     491      vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);
     492      vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr);
    480493   }
    481494
  • sdl-game.hpp

    r9d21aac r996dd3e  
    7272   alignas(16) mat4 view;
    7373   alignas(16) mat4 proj;
     74};
     75
     76// TODO: Use this struct for uniform buffers as well and probably combine it with the VulkanBuffer class
     77// Also, probably better to make this a vector of structs where each struct
     78// has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo
     79struct StorageBufferSet {
     80   vector<VkBuffer> buffers;
     81   vector<VkDeviceMemory> memory;
     82   vector<VkDescriptorBufferInfo> infoSet;
    7483};
    7584
     
    208217      // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures
    209218      GraphicsPipeline_Vulkan<ModelVertex> modelPipeline;
     219
     220      StorageBufferSet storageBuffers_modelPipeline;
    210221
    211222      // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo
     
    297308                                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    298309                                                   const vector<VertexType>& vertices, vector<uint16_t> indices,
    299                                                    SSBOType ssbo, bool pipelinesCreated);
     310                                                   SSBOType ssbo, StorageBufferSet& storageBuffers,
     311                                                   bool pipelinesCreated);
    300312
    301313      template<class VertexType>
     
    381393                                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    382394                                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
    383                                                          SSBOType ssbo, bool pipelinesCreated) {
     395                                                         SSBOType ssbo, StorageBufferSet& storageBuffers,
     396                                                         bool pipelinesCreated) {
    384397   // TODO: Use the model field of ssbo to set the object's model_base
    385398   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
     
    403416   pipeline.addObject(obj.vertices, obj.indices, resourceCommandPool, graphicsQueue);
    404417
     418   // TODO: Probably move the resizing to the VulkanBuffer class
     419   // First, try moving this out of addObject
    405420   bool resizeStorageBuffer = pipeline.numObjects == pipeline.objectCapacity;
    406421
    407422   if (resizeStorageBuffer) {
    408       resizeStorageBufferSet<VertexType, SSBOType>(pipeline.storageBufferSet, resourceCommandPool, graphicsQueue, pipeline);
     423      resizeStorageBufferSet<VertexType, SSBOType>(storageBuffers, resourceCommandPool, graphicsQueue, pipeline);
    409424      pipeline.cleanup();
    410425
    411426      // Assume the SSBO is always the 2nd binding
    412       pipeline.updateDescriptorInfo(1, &pipeline.storageBufferSet.infoSet);
     427      // TODO: Figure out a way to make this more flexible
     428      pipeline.updateDescriptorInfo(1, &storageBuffers.infoSet);
    413429   }
    414430
    415431   pipeline.numObjects++;
    416 
    417    updateStorageBuffer(pipeline.storageBufferSet, pipeline.numObjects - 1, obj.ssbo);
    418432
    419433   // TODO: Figure out why I am destroying and recreating the ubos when the swap chain is recreated,
     
    421435
    422436   if (pipelinesCreated) {
     437      // TODO: See if I can avoid doing this when recreating the pipeline
    423438      vkDeviceWaitIdle(device);
    424439
     
    531546   obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    532547
    533    updateStorageBuffer(pipeline.storageBufferSet, index, obj.ssbo);
    534 
    535548   obj.modified = false;
    536549}
  • vulkan-game.cpp

    r9d21aac r996dd3e  
    126126      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline);
    127127   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    128       VK_SHADER_STAGE_VERTEX_BIT, &modelPipeline.storageBufferSet.infoSet);
     128      VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_modelPipeline.infoSet);
    129129   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    130130      VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
     
    145145         }, {
    146146            mat4(1.0f)
    147          }, false);
     147         }, storageBuffers_modelPipeline, false);
     148
     149   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
    148150
    149151   texturedSquare->model_base =
     
    164166         }, {
    165167            mat4(1.0f)
    166          }, false);
     168         }, storageBuffers_modelPipeline, false);
     169
     170   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
    167171
    168172   texturedSquare->model_base =
     
    189193      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline);
    190194   shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    191       VK_SHADER_STAGE_VERTEX_BIT, &shipPipeline.storageBufferSet.infoSet);
     195      VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_shipPipeline.infoSet);
    192196
    193197   // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
     
    424428      }, {
    425429         mat4(1.0f)
    426       }, false);
     430      }, storageBuffers_shipPipeline, false);
     431
     432   updateStorageBuffer(storageBuffers_shipPipeline, shipPipeline.numObjects - 1, ship.ssbo);
    427433
    428434   ship.model_base =
     
    449455      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline);
    450456   asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    451       VK_SHADER_STAGE_VERTEX_BIT, &asteroidPipeline.storageBufferSet.infoSet);
     457      VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_asteroidPipeline.infoSet);
    452458
    453459   asteroidPipeline.createDescriptorSetLayout();
     
    467473      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline);
    468474   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    469       VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, &laserPipeline.storageBufferSet.infoSet);
     475      VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, &storageBuffers_laserPipeline.infoSet);
    470476   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    471477      VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor);
     
    487493      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_explosionPipeline);
    488494   explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    489       VK_SHADER_STAGE_VERTEX_BIT, &explosionPipeline.storageBufferSet.infoSet);
     495      VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_explosionPipeline.infoSet);
    490496
    491497   explosionPipeline.createDescriptorSetLayout();
     
    599605      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    600606      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    601       modelPipeline.storageBufferSet.buffers, modelPipeline.storageBufferSet.memory,
    602       modelPipeline.storageBufferSet.infoSet);
     607      storageBuffers_modelPipeline.buffers, storageBuffers_modelPipeline.memory,
     608      storageBuffers_modelPipeline.infoSet);
    603609
    604610   shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
     
    609615      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    610616      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    611       shipPipeline.storageBufferSet.buffers, shipPipeline.storageBufferSet.memory,
    612       shipPipeline.storageBufferSet.infoSet);
     617      storageBuffers_shipPipeline.buffers, storageBuffers_shipPipeline.memory,
     618      storageBuffers_shipPipeline.infoSet);
    613619
    614620   asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
     
    619625      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    620626      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    621       asteroidPipeline.storageBufferSet.buffers, asteroidPipeline.storageBufferSet.memory,
    622       asteroidPipeline.storageBufferSet.infoSet);
     627      storageBuffers_asteroidPipeline.buffers, storageBuffers_asteroidPipeline.memory,
     628      storageBuffers_asteroidPipeline.infoSet);
    623629
    624630   laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>(
     
    629635      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    630636      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    631       laserPipeline.storageBufferSet.buffers, laserPipeline.storageBufferSet.memory,
    632       laserPipeline.storageBufferSet.infoSet);
     637      storageBuffers_laserPipeline.buffers, storageBuffers_laserPipeline.memory,
     638      storageBuffers_laserPipeline.infoSet);
    633639
    634640   explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex>(
     
    640646      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    641647      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    642       explosionPipeline.storageBufferSet.buffers, explosionPipeline.storageBufferSet.memory,
    643       explosionPipeline.storageBufferSet.infoSet);
     648      storageBuffers_explosionPipeline.buffers, storageBuffers_explosionPipeline.memory,
     649      storageBuffers_explosionPipeline.infoSet);
    644650}
    645651
     
    762768                           }, {
    763769                              mat4(1.0f)
    764                            }, true);
     770                           }, storageBuffers_modelPipeline, true);
     771
     772                  updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo);
    765773
    766774                  texturedSquare.model_base =
     
    10421050                  10.0f,
    10431051                  false
    1044                }, true);
     1052               }, storageBuffers_asteroidPipeline, true);
     1053
     1054      updateStorageBuffer(storageBuffers_asteroidPipeline, asteroidPipeline.numObjects - 1, asteroid.ssbo);
    10451055
    10461056      // This accounts for the scaling in model_base.
     
    10701080      if (shipObjects[i].modified) {
    10711081         updateObject(shipObjects, shipPipeline, i);
     1082         updateStorageBuffer(storageBuffers_shipPipeline, i, shipObjects[i].ssbo);
    10721083      }
    10731084   }
     
    10761087      if (modelObjects[i].modified) {
    10771088         updateObject(modelObjects, modelPipeline, i);
     1089         updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo);
    10781090      }
    10791091   }
     
    10821094      if (asteroidObjects[i].modified) {
    10831095         updateObject(asteroidObjects, asteroidPipeline, i);
     1096         updateStorageBuffer(storageBuffers_asteroidPipeline, i, asteroidObjects[i].ssbo);
    10841097      }
    10851098   }
     
    10881101      if (laserObjects[i].modified) {
    10891102         updateObject(laserObjects, laserPipeline, i);
     1103         updateStorageBuffer(storageBuffers_laserPipeline, i, laserObjects[i].ssbo);
    10901104      }
    10911105   }
     
    10941108      if (explosionObjects[i].modified) {
    10951109         updateObject(explosionObjects, explosionPipeline, i);
     1110         updateStorageBuffer(storageBuffers_explosionPipeline, i, explosionObjects[i].ssbo);
    10961111      }
    10971112   }
     
    11311146   explosionPipeline.cleanupBuffers();
    11321147
    1133    for (size_t i = 0; i < modelPipeline.storageBufferSet.buffers.size(); i++) {
    1134       vkDestroyBuffer(device, modelPipeline.storageBufferSet.buffers[i], nullptr);
    1135       vkFreeMemory(device, modelPipeline.storageBufferSet.memory[i], nullptr);
    1136    }
    1137 
    1138    for (size_t i = 0; i < shipPipeline.storageBufferSet.buffers.size(); i++) {
    1139       vkDestroyBuffer(device, shipPipeline.storageBufferSet.buffers[i], nullptr);
    1140       vkFreeMemory(device, shipPipeline.storageBufferSet.memory[i], nullptr);
    1141    }
    1142 
    1143    for (size_t i = 0; i < asteroidPipeline.storageBufferSet.buffers.size(); i++) {
    1144       vkDestroyBuffer(device, asteroidPipeline.storageBufferSet.buffers[i], nullptr);
    1145       vkFreeMemory(device, asteroidPipeline.storageBufferSet.memory[i], nullptr);
    1146    }
    1147 
    1148    for (size_t i = 0; i < laserPipeline.storageBufferSet.buffers.size(); i++) {
    1149       vkDestroyBuffer(device, laserPipeline.storageBufferSet.buffers[i], nullptr);
    1150       vkFreeMemory(device, laserPipeline.storageBufferSet.memory[i], nullptr);
    1151    }
    1152 
    1153    for (size_t i = 0; i < explosionPipeline.storageBufferSet.buffers.size(); i++) {
    1154       vkDestroyBuffer(device, explosionPipeline.storageBufferSet.buffers[i], nullptr);
    1155       vkFreeMemory(device, explosionPipeline.storageBufferSet.memory[i], nullptr);
     1148   for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {
     1149      vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);
     1150      vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr);
     1151   }
     1152
     1153   for (size_t i = 0; i < storageBuffers_shipPipeline.buffers.size(); i++) {
     1154      vkDestroyBuffer(device, storageBuffers_shipPipeline.buffers[i], nullptr);
     1155      vkFreeMemory(device, storageBuffers_shipPipeline.memory[i], nullptr);
     1156   }
     1157
     1158   for (size_t i = 0; i < storageBuffers_asteroidPipeline.buffers.size(); i++) {
     1159      vkDestroyBuffer(device, storageBuffers_asteroidPipeline.buffers[i], nullptr);
     1160      vkFreeMemory(device, storageBuffers_asteroidPipeline.memory[i], nullptr);
     1161   }
     1162
     1163   for (size_t i = 0; i < storageBuffers_laserPipeline.buffers.size(); i++) {
     1164      vkDestroyBuffer(device, storageBuffers_laserPipeline.buffers[i], nullptr);
     1165      vkFreeMemory(device, storageBuffers_laserPipeline.memory[i], nullptr);
     1166   }
     1167
     1168   for (size_t i = 0; i < storageBuffers_explosionPipeline.buffers.size(); i++) {
     1169      vkDestroyBuffer(device, storageBuffers_explosionPipeline.buffers[i], nullptr);
     1170      vkFreeMemory(device, storageBuffers_explosionPipeline.memory[i], nullptr);
    11561171   }
    11571172
     
    19141929         color,
    19151930         false
    1916       }, true);
     1931      }, storageBuffers_laserPipeline, true);
     1932
     1933   updateStorageBuffer(storageBuffers_laserPipeline, laserPipeline.numObjects - 1, laser.ssbo);
    19171934
    19181935   float xAxisRotation = asin(ray.y / length);
     
    21242141         duration,
    21252142         false
    2126       }, true);
     2143      }, storageBuffers_explosionPipeline, true);
     2144
     2145   updateStorageBuffer(storageBuffers_explosionPipeline, explosionPipeline.numObjects - 1, explosion.ssbo);
    21272146
    21282147   explosion.model_base = model_mat;
  • vulkan-game.hpp

    r9d21aac r996dd3e  
    9696   alignas(16) mat4 proj;
    9797   alignas(4) float cur_time;
     98};
     99
     100// TODO: Use this struct for uniform buffers as well and probably combine it with the VulkanBuffer class
     101// Also, probably better to make this a vector of structs where each struct
     102// has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo
     103struct StorageBufferSet {
     104   vector<VkBuffer> buffers;
     105   vector<VkDeviceMemory> memory;
     106   vector<VkDescriptorBufferInfo> infoSet;
    98107};
    99108
     
    305314      GraphicsPipeline_Vulkan<LaserVertex> laserPipeline;
    306315      GraphicsPipeline_Vulkan<ExplosionVertex> explosionPipeline;
     316
     317      StorageBufferSet storageBuffers_modelPipeline;
     318      StorageBufferSet storageBuffers_shipPipeline;
     319      StorageBufferSet storageBuffers_asteroidPipeline;
     320      StorageBufferSet storageBuffers_laserPipeline;
     321      StorageBufferSet storageBuffers_explosionPipeline;
    307322
    308323      // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo
     
    440455                                                   GraphicsPipeline_Vulkan<VertexType>& pipeline,
    441456                                                   const vector<VertexType>& vertices, vector<uint16_t> indices,
    442                                                    SSBOType ssbo, bool pipelinesCreated);
     457                                                   SSBOType ssbo, StorageBufferSet& storageBuffers,
     458                                                   bool pipelinesCreated);
    443459
    444460      template<class VertexType>
     
    544560                                                         GraphicsPipeline_Vulkan<VertexType>& pipeline,
    545561                                                         const vector<VertexType>& vertices, vector<uint16_t> indices,
    546                                                          SSBOType ssbo, bool pipelinesCreated) {
     562                                                         SSBOType ssbo, StorageBufferSet& storageBuffers,
     563                                                         bool pipelinesCreated) {
    547564   // TODO: Use the model field of ssbo to set the object's model_base
    548565   // currently, the passed in model is useless since it gets overridden in updateObject() anyway
     
    566583   pipeline.addObject(obj.vertices, obj.indices, resourceCommandPool, graphicsQueue);
    567584
     585   // TODO: Probably move the resizing to the VulkanBuffer class
     586   // First, try moving this out of addObject
    568587   bool resizeStorageBuffer = pipeline.numObjects == pipeline.objectCapacity;
    569588
    570589   if (resizeStorageBuffer) {
    571       resizeStorageBufferSet<VertexType, SSBOType>(pipeline.storageBufferSet, resourceCommandPool, graphicsQueue, pipeline);
     590      resizeStorageBufferSet<VertexType, SSBOType>(storageBuffers, resourceCommandPool, graphicsQueue, pipeline);
    572591      pipeline.cleanup();
    573592
    574593      // Assume the SSBO is always the 2nd binding
    575       pipeline.updateDescriptorInfo(1, &pipeline.storageBufferSet.infoSet);
     594      // TODO: Figure out a way to make this more flexible
     595      pipeline.updateDescriptorInfo(1, &storageBuffers.infoSet);
    576596   }
    577597
    578598   pipeline.numObjects++;
    579 
    580    updateStorageBuffer(pipeline.storageBufferSet, pipeline.numObjects - 1, obj.ssbo);
    581599
    582600   // TODO: Figure out why I am destroying and recreating the ubos when the swap chain is recreated,
     
    584602
    585603   if (pipelinesCreated) {
     604      // TODO: See if I can avoid doing this when recreating the pipeline
    586605      vkDeviceWaitIdle(device);
    587606
     
    699718   obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    700719
    701    updateStorageBuffer(pipeline.storageBufferSet, index, obj.ssbo);
    702 
    703720   obj.modified = false;
    704721}
  • vulkan-utils.hpp

    r9d21aac r996dd3e  
    117117template<class DataType>
    118118void VulkanUtils::copyDataToBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool,
    119       const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, VkQueue graphicsQueue) {
     119                                   const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset,
     120                                   VkQueue graphicsQueue) {
    120121   VkDeviceSize srcDataSize = srcData.size() * sizeof(DataType);
    121122
     
    140141template<class DataType>
    141142void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory,
    142    VkDeviceSize offset) {
     143                                   VkDeviceSize offset) {
    143144   copyDataToMemory(device, srcData, bufferMemory, offset, sizeof(DataType));
    144145}
    145146
     147// TODO: This would be used when the GPU memory is host-coherent. If it it not, I also need to use vkFlushMappedMemoryRanges
     148// I should create a variant that supports non-coherent memory
    146149template<class DataType>
    147150void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory,
Note: See TracChangeset for help on using the changeset viewer.