Changeset c074f81 in opengl-game for vulkan-utils.hpp
- Timestamp:
- Jun 8, 2021, 2:29:12 PM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 8aa4888
- Parents:
- 567fa88
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-utils.hpp
r567fa88 rc074f81 103 103 104 104 template<class DataType> 105 static void copyDataToMemory(VkDevice device, const DataType&srcData, VkDeviceMemory bufferMemory,106 VkDeviceSize offset );105 static void copyDataToMemory(VkDevice device, DataType* srcData, VkDeviceMemory bufferMemory, 106 VkDeviceSize offset, VkDeviceSize size, bool flush); 107 107 108 108 template<class DataType> 109 static void copyDataToM emory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory,110 VkDeviceSize offset, VkDeviceSize size);109 static void copyDataToMappedMemory(VkDevice device, DataType* srcData, void* mappedData, 110 VkDeviceMemory bufferMemory, VkDeviceSize size, bool flush); 111 111 112 112 static bool hasStencilComponent(VkFormat format); … … 140 140 141 141 template<class DataType> 142 void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 143 VkDeviceSize offset) { 144 copyDataToMemory(device, srcData, bufferMemory, offset, sizeof(DataType)); 145 } 146 147 // TODO: This would be used when the GPU memory is host-coherent. If it it not, I also need to use vkFlushMappedMemoryRanges 148 // I should create a variant that supports non-coherent memory 149 template<class DataType> 150 void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 151 VkDeviceSize offset, VkDeviceSize size) { 142 void VulkanUtils::copyDataToMemory(VkDevice device, DataType* srcData, VkDeviceMemory bufferMemory, 143 VkDeviceSize offset, VkDeviceSize size, bool flush) { 152 144 void* data; 153 145 154 146 vkMapMemory(device, bufferMemory, offset, size, 0, &data); 155 memcpy(data, &srcData, size); 147 148 memcpy(data, srcData, size); 149 150 if (flush) { 151 VkMappedMemoryRange memoryRange{}; 152 memoryRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; 153 memoryRange.memory = bufferMemory; 154 memoryRange.size = size; 155 156 vkFlushMappedMemoryRanges(device, 1, &memoryRange); 157 } 158 156 159 vkUnmapMemory(device, bufferMemory); 160 } 161 162 template<class DataType> 163 void VulkanUtils::copyDataToMappedMemory(VkDevice device, DataType* srcData, void* mappedData, 164 VkDeviceMemory bufferMemory, VkDeviceSize size, bool flush) { 165 memcpy(mappedData, srcData, size); 166 167 if (flush) { 168 VkMappedMemoryRange memoryRange{}; 169 memoryRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; 170 memoryRange.memory = bufferMemory; 171 memoryRange.size = size; 172 173 vkFlushMappedMemoryRanges(device, 1, &memoryRange); 174 } 157 175 } 158 176
Note:
See TracChangeset
for help on using the changeset viewer.