Changeset c074f81 in opengl-game
- Timestamp:
- Jun 8, 2021, 2:29:12 PM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 8aa4888
- Parents:
- 567fa88
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
r567fa88 rc074f81 475 475 } 476 476 477 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0); 477 VulkanUtils::copyDataToMemory(device, &object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0, 478 sizeof(object_VP_mats), false); 478 479 } 479 480 -
sdl-game.hpp
r567fa88 rc074f81 383 383 void VulkanGame::updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo) { 384 384 for (size_t i = 0; i < set.memory.size(); i++) { 385 VulkanUtils::copyDataToMemory(device, ssbo, set.memory[i], objIndex * sizeof(SSBOType));385 VulkanUtils::copyDataToMemory(device, &ssbo, set.memory[i], objIndex * sizeof(SSBOType), sizeof(ssbo), false); 386 386 } 387 387 } -
vulkan-game.cpp
r567fa88 rc074f81 1161 1161 explosion_UBO.cur_time = curTime; 1162 1162 1163 VulkanUtils::copyDataToMemory(device, object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0); 1164 1165 VulkanUtils::copyDataToMemory(device, ship_VP_mats, uniformBuffers_shipPipeline.memory[imageIndex], 0); 1166 1167 VulkanUtils::copyDataToMemory(device, asteroid_VP_mats, uniformBuffers_asteroidPipeline.memory[imageIndex], 0); 1168 1169 VulkanUtils::copyDataToMemory(device, laser_VP_mats, uniformBuffers_laserPipeline.memory[imageIndex], 0); 1170 1171 VulkanUtils::copyDataToMemory(device, explosion_UBO, uniformBuffers_explosionPipeline.memory[imageIndex], 0); 1163 VulkanUtils::copyDataToMemory(device, &object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0, 1164 sizeof(object_VP_mats), false); 1165 1166 VulkanUtils::copyDataToMemory(device, &ship_VP_mats, uniformBuffers_shipPipeline.memory[imageIndex], 0, 1167 sizeof(ship_VP_mats), false); 1168 1169 VulkanUtils::copyDataToMemory(device, &asteroid_VP_mats, uniformBuffers_asteroidPipeline.memory[imageIndex], 0, 1170 sizeof(asteroid_VP_mats), false); 1171 1172 VulkanUtils::copyDataToMemory(device, &laser_VP_mats, uniformBuffers_laserPipeline.memory[imageIndex], 0, 1173 sizeof(laser_VP_mats), false); 1174 1175 VulkanUtils::copyDataToMemory(device, &explosion_UBO, uniformBuffers_explosionPipeline.memory[imageIndex], 0, 1176 sizeof(explosion_UBO), false); 1172 1177 } 1173 1178 -
vulkan-game.hpp
r567fa88 rc074f81 39 39 // TODO: Consider if there is a better way of dealing with all the vertex types and ssbo types, maybe 40 40 // by consolidating some and trying to keep new ones to a minimum 41 42 struct OverlayVertex {43 vec3 pos;44 vec2 texCoord;45 };46 41 47 42 struct ModelVertex { … … 546 541 void VulkanGame::updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo) { 547 542 for (size_t i = 0; i < set.memory.size(); i++) { 548 VulkanUtils::copyDataToMemory(device, ssbo, set.memory[i], objIndex * sizeof(SSBOType));543 VulkanUtils::copyDataToMemory(device, &ssbo, set.memory[i], objIndex * sizeof(SSBOType), sizeof(ssbo), false); 549 544 } 550 545 } -
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.