Changeset a52ba87 in opengl-game


Ignore:
Timestamp:
Apr 17, 2020, 3:03:40 AM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
6385d0f
Parents:
0ecab17
Message:

In GraphicsPipeline_Vulkan, change addStorageDescriptor() to take a parameter indicating the shader stage, and add an updateObjectVertices() method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    r0ecab17 ra52ba87  
    3232};
    3333
     34// TODO: Use this struct for uniform buffers as well (maybe move it to VulkanUtils)
    3435struct StorageBufferSet {
    3536   vector<VkBuffer> buffers;
     
    6162      void addAttribute(VkFormat format, size_t offset);
    6263
    63       void addStorageDescriptor();
     64      void addStorageDescriptor(VkShaderStageFlags stageFlags);
    6465
    6566      void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData);
     
    7778
    7879      void updateObject(size_t objIndex, SSBOType& ssbo);
     80
     81      void updateObjectVertices(size_t objIndex, const vector<VertexType>& vertices, VkCommandPool commandPool,
     82         VkQueue graphicsQueue);
    7983
    8084      void cleanup();
     
    214218}
    215219
    216 template<class VertexType, class SSBOType>
    217 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addStorageDescriptor() {
     220// TODO: The SSBOType check isn't really needed since I call this function in VulkanGame explicitly
     221template<class VertexType, class SSBOType>
     222void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addStorageDescriptor(VkShaderStageFlags stageFlags) {
    218223   if (!is_same_v<SSBOType, void*>) {
    219224      addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    220          VK_SHADER_STAGE_VERTEX_BIT, &storageBufferSet.infoSet);
     225         stageFlags, &storageBufferSet.infoSet);
    221226   }
    222227}
     
    495500   //    - don't resize, but rewrite data in the buffer to only have non-deleted objects
    496501
    497    if (numVertices + vertices.size() > vertexCapacity) {
     502   if (this->numVertices + vertices.size() > this->vertexCapacity) {
    498503      resizeVertexBuffer(commandPool, graphicsQueue);
    499504   }
    500    VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, vertices, vertexBuffer, numVertices,
    501       graphicsQueue);
    502    numVertices += vertices.size();
    503 
    504    if (numIndices + indices.size() > indexCapacity) {
     505   VulkanUtils::copyDataToBuffer(this->device, this->physicalDevice, commandPool, vertices,
     506      this->vertexBuffer, this->numVertices, graphicsQueue);
     507   this->numVertices += vertices.size();
     508
     509   if (this->numIndices + indices.size() > this->indexCapacity) {
    505510      resizeIndexBuffer(commandPool, graphicsQueue);
    506511   }
    507    VulkanUtils::copyDataToBuffer(device, physicalDevice, commandPool, indices, indexBuffer, numIndices,
    508       graphicsQueue);
    509    numIndices += indices.size();
     512   VulkanUtils::copyDataToBuffer(this->device, this->physicalDevice, commandPool, indices,
     513      this->indexBuffer, this->numIndices, graphicsQueue);
     514   this->numIndices += indices.size();
    510515
    511516   bool resizedStorageBuffer = false;
     
    540545   if (!is_same_v<SSBOType, void*>) {
    541546      for (size_t i = 0; i < storageBufferSet.memory.size(); i++) {
    542          VulkanUtils::copyDataToMemory(device, storageBufferSet.memory[i], objIndex, ssbo);
     547         VulkanUtils::copyDataToMemory(this->device, storageBufferSet.memory[i], objIndex, ssbo);
    543548      }
    544549   }
     550}
     551
     552// Should only be used if the number of vertices has not changed
     553template<class VertexType, class SSBOType>
     554void GraphicsPipeline_Vulkan<VertexType, SSBOType>::updateObjectVertices(size_t objIndex,
     555      const vector<VertexType>& vertices, VkCommandPool commandPool, VkQueue graphicsQueue) {
     556   VulkanUtils::copyDataToBuffer(this->device, this->physicalDevice, commandPool, vertices,
     557      this->vertexBuffer, objIndex * vertices.size(), graphicsQueue);
    545558}
    546559
Note: See TracChangeset for help on using the changeset viewer.