Changeset 996dd3e in opengl-game for sdl-game.cpp


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.