Changeset 6bac215 in opengl-game for vulkan-game.hpp


Ignore:
Timestamp:
Jun 9, 2021, 12:38:14 AM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
bb76950
Parents:
8dcbf62
git-author:
Dmitry Portnoy <dportnoy@…> (06/09/21 00:38:09)
git-committer:
Dmitry Portnoy <dportnoy@…> (06/09/21 00:38:14)
Message:

Rewrite a large portion of the VulkanBuffer class, start using it more
to resize buffers, and simplify resizeBufferSet() since the additions to
VulkanBuffer can now do some of what that function used to do

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.hpp

    r8dcbf62 r6bac215  
    503503                                 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,
    504504                                 VkQueue graphicsQueue) {
    505    size_t numObjects = buffer.numObjects < buffer.capacity ? buffer.numObjects : buffer.capacity;
    506 
    507    do {
    508       buffer.capacity *= 2;
    509    } while (buffer.capacity < buffer.numObjects);
    510 
    511    VkDeviceSize bufferSize = buffer.capacity * sizeof(SSBOType);
     505   VkDeviceSize newSize = buffer.capacity * sizeof(SSBOType);
    512506
    513507   for (size_t i = 0; i < set.buffers.size(); i++) {
    514       VkBuffer newStorageBuffer;
    515       VkDeviceMemory newStorageBufferMemory;
    516 
    517       VulkanUtils::createBuffer(device, physicalDevice, bufferSize,
    518          VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    519          VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    520          newStorageBuffer, newStorageBufferMemory);
    521 
    522       VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newStorageBuffer,
    523          0, 0, numObjects * sizeof(SSBOType), graphicsQueue);
     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);
    524515
    525516      vkDestroyBuffer(device, set.buffers[i], nullptr);
    526517      vkFreeMemory(device, set.memory[i], nullptr);
    527518
    528       set.buffers[i] = newStorageBuffer;
    529       set.memory[i] = newStorageBufferMemory;
     519      set.buffers[i] = newBuffer;
     520      set.memory[i] = newMemory;
    530521
    531522      set.infoSet[i].buffer = set.buffers[i];
    532523      set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
    533       set.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
     524      set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
    534525   }
    535526
Note: See TracChangeset for help on using the changeset viewer.