Changeset a3cefaa in opengl-game for sdl-game.cpp


Ignore:
Timestamp:
May 17, 2021, 4:06:33 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
1abebc1
Parents:
996dd3e
Message:

Move SSBO resizing and pipeline recreation checks out of addObject() and into updateScene() so that those operations are only done at most once per pipeline per frame, using vkUpdateDescriptorSets() instead of recreating the whole graphics pipeline, and create a VulkanBuffer class for managing data related to uniform buffers and shader storage buffers, move objectCapacity and numObjects out of GraphicsPipeline_vulkan and use VulkanBuffer to manage them instead

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r996dd3e ra3cefaa  
    7070                     , gui(nullptr)
    7171                     , window(nullptr)
     72                     , objects_modelPipeline()
    7273                     , score(0)
    7374                     , fps(0.0f) {
     
    8788
    8889   initVulkan();
     90
     91   VkPhysicalDeviceProperties deviceProperties;
     92   vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
     93
     94   objects_modelPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.minUniformBufferOffsetAlignment);
    8995
    9096   initImGuiOverlay();
     
    131137      }, {
    132138         mat4(1.0f)
    133       }, storageBuffers_modelPipeline, false);
    134 
    135    updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
     139      }, storageBuffers_modelPipeline);
     140
     141   objects_modelPipeline.numObjects++;
    136142
    137143   texturedSquare->model_base =
     
    152158      }, {
    153159         mat4(1.0f)
    154       }, storageBuffers_modelPipeline, false);
    155 
    156    updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
     160      }, storageBuffers_modelPipeline);
     161
     162   objects_modelPipeline.numObjects++;
    157163
    158164   texturedSquare->model_base =
     
    263269   modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
    264270      VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass,
    265       { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 16, 24, 10);
    266 
    267    createBufferSet(modelPipeline.objectCapacity * sizeof(SSBO_ModelObject),
     271      { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 16, 24);
     272
     273   createBufferSet(objects_modelPipeline.capacity * sizeof(SSBO_ModelObject),
    268274      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    269275      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     
    376382                        }, {
    377383                           mat4(1.0f)
    378                         }, storageBuffers_modelPipeline, true);
    379 
    380                   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo);
     384                        }, storageBuffers_modelPipeline);
     385
     386                  objects_modelPipeline.numObjects++;
    381387
    382388                  texturedSquare.model_base =
     
    446452
    447453void VulkanGame::updateScene() {
    448    // TODO: These two for loops could probably be combined into one
    449 
     454   // Rotate the textured squares
    450455   for (SceneObject<ModelVertex, SSBO_ModelObject>& model : this->modelObjects) {
    451456      model.model_transform =
     
    455460   }
    456461
    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
     462   // TODO: Probably move the resizing to the VulkanBuffer class
     463   if (objects_modelPipeline.numObjects > objects_modelPipeline.capacity) {
     464      resizeStorageBufferSet(storageBuffers_modelPipeline, objects_modelPipeline, modelPipeline, resourceCommandPool,
     465                             graphicsQueue);
     466   }
     467
    459468   for (size_t i = 0; i < modelObjects.size(); i++) {
    460469      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 
    466470         updateObject(modelObjects, modelPipeline, i);
    467471         updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo);
     
    845849   return VulkanUtils::findSupportedFormat(
    846850      physicalDevice,
    847       { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT },
     851      { VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D32_SFLOAT, VK_FORMAT_D24_UNORM_S8_UINT },
    848852      VK_IMAGE_TILING_OPTIMAL,
    849853      VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
Note: See TracChangeset for help on using the changeset viewer.