Changeset e3bef3a in opengl-game for vulkan-utils.hpp


Ignore:
Timestamp:
Nov 12, 2019, 6:55:07 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
cd487fb
Parents:
5a23277
Message:

Finish the rewrite of the original vulkangame project

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-utils.hpp

    r5a23277 re3bef3a  
    8787            uint32_t width, uint32_t height, VkQueue graphicsQueue);
    8888
     89      template<class DataType>
     90      static void copyDataToBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool,
     91            const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, VkQueue graphicsQueue);
     92
    8993      static void copyBuffer(VkDevice device, VkCommandPool commandPool, VkBuffer srcBuffer, VkBuffer dstBuffer,
    9094            VkDeviceSize srcOffset, VkDeviceSize dstOffset, VkDeviceSize size, VkQueue graphicsQueue);
     
    9599};
    96100
     101template<class DataType>
     102void VulkanUtils::copyDataToBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool,
     103      const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, VkQueue graphicsQueue) {
     104   VkDeviceSize srcDataSize = srcData.size() * sizeof(DataType);
     105
     106   VkBuffer stagingBuffer;
     107   VkDeviceMemory stagingBufferMemory;
     108   createBuffer(device, physicalDevice, srcDataSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
     109      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     110      stagingBuffer, stagingBufferMemory);
     111
     112   void* data;
     113   vkMapMemory(device, stagingBufferMemory, 0, srcDataSize, 0, &data);
     114   memcpy(data, srcData.data(), (size_t)srcDataSize);
     115   vkUnmapMemory(device, stagingBufferMemory);
     116
     117   copyBuffer(device, commandPool, stagingBuffer, dstBuffer, 0, dstVertexOffset * sizeof(DataType), srcDataSize,
     118      graphicsQueue);
     119
     120   vkDestroyBuffer(device, stagingBuffer, nullptr);
     121   vkFreeMemory(device, stagingBufferMemory, nullptr);
     122}
     123
    97124#endif // _VULKAN_UTILS_H
Note: See TracChangeset for help on using the changeset viewer.