Changeset bb76950 in opengl-game
- Timestamp:
- Jun 9, 2021, 6:41:48 PM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- b7fc3c2
- Parents:
- 6bac215
- git-author:
- Dmitry Portnoy <dportnoy@…> (06/09/21 18:41:20)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (06/09/21 18:41:48)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.cpp
r6bac215 rbb76950 459 459 if (objects_modelPipeline.resized) { 460 460 // TODO: Also resize the dynamic ubo 461 resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline , modelPipeline, resourceCommandPool,462 graphicsQueue);461 resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline.capacity * sizeof(SSBO_ModelObject), 462 resourceCommandPool, graphicsQueue, true); 463 463 464 464 objects_modelPipeline.resize(); 465 466 modelPipeline.updateDescriptorInfo(1, &storageBuffers_modelPipeline.infoSet, swapChainImages.size()); 465 467 } 466 468 … … 1130 1132 } 1131 1133 1134 void VulkanGame::resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool, 1135 VkQueue graphicsQueue, bool copyData) { 1136 for (size_t i = 0; i < set.buffers.size(); i++) { 1137 VkBuffer newBuffer; 1138 VkDeviceMemory newMemory; 1139 1140 VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory); 1141 1142 if (copyData) { 1143 VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range, 1144 graphicsQueue); 1145 } 1146 1147 vkDestroyBuffer(device, set.buffers[i], nullptr); 1148 vkFreeMemory(device, set.memory[i], nullptr); 1149 1150 set.buffers[i] = newBuffer; 1151 set.memory[i] = newMemory; 1152 1153 set.infoSet[i].buffer = set.buffers[i]; 1154 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now 1155 set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE 1156 } 1157 } 1158 1132 1159 void VulkanGame::renderFrame(ImDrawData* draw_data) { 1133 1160 VkResult result = vkAcquireNextImageKHR(device, swapChain, numeric_limits<uint64_t>::max(), -
sdl-game.hpp
r6bac215 rbb76950 108 108 vec3 center; // currently only matters for asteroids 109 109 float radius; // currently only matters for asteroids 110 111 // Move the targetAsteroid stuff out of this class since it is very specific to lasers 112 // and makes moving SceneObject into its own header file more problematic 110 113 SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers 111 114 }; … … 297 300 BufferSet& set); 298 301 299 template<class VertexType, class SSBOType> 300 void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer, 301 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool, 302 VkQueue graphicsQueue); 302 void resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool, VkQueue graphicsQueue, 303 bool copyData); 303 304 304 305 template<class SSBOType> … … 343 344 void quitGame(); 344 345 }; 345 346 template<class VertexType, class SSBOType>347 void VulkanGame::resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,348 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,349 VkQueue graphicsQueue) {350 VkDeviceSize newSize = buffer.capacity * sizeof(SSBOType);351 352 for (size_t i = 0; i < set.buffers.size(); i++) {353 VkBuffer newBuffer;354 VkDeviceMemory newMemory;355 356 VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory);357 358 VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range,359 graphicsQueue);360 361 vkDestroyBuffer(device, set.buffers[i], nullptr);362 vkFreeMemory(device, set.memory[i], nullptr);363 364 set.buffers[i] = newBuffer;365 set.memory[i] = newMemory;366 367 set.infoSet[i].buffer = set.buffers[i];368 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now369 set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE370 }371 372 // Assume the SSBO is always the 2nd binding373 // TODO: Figure out a way to make this more flexible374 pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages.size());375 }376 346 377 347 // TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them -
vulkan-game.cpp
r6bac215 rbb76950 1089 1089 } 1090 1090 1091 // TODO: Replace updateBufferSet to one call to copyDataToMemory, using VulkanBuffer to provide the data source 1092 // TODO: Figure out a way to make updateDescriptorInfo easier to use, maybe store the binding index in the buffer set 1091 1093 // TODO: Probably move the resizing to the VulkanBuffer class 1094 1092 1095 if (objects_modelPipeline.resized) { 1093 resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline , modelPipeline, resourceCommandPool,1094 graphicsQueue);1096 resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline.capacity * sizeof(SSBO_ModelObject), 1097 resourceCommandPool, graphicsQueue, true); 1095 1098 1096 1099 objects_modelPipeline.resize(); 1100 1101 modelPipeline.updateDescriptorInfo(1, &storageBuffers_modelPipeline.infoSet, swapChainImages.size()); 1097 1102 } 1098 1103 … … 1106 1111 // TODO: Probably move the resizing to the VulkanBuffer class 1107 1112 if (objects_shipPipeline.resized) { 1108 resizeBufferSet(storageBuffers_shipPipeline, objects_shipPipeline , shipPipeline, resourceCommandPool,1109 graphicsQueue);1113 resizeBufferSet(storageBuffers_shipPipeline, objects_shipPipeline.capacity * sizeof(SSBO_ModelObject), 1114 resourceCommandPool, graphicsQueue, true); 1110 1115 1111 1116 objects_shipPipeline.resize(); 1117 1118 shipPipeline.updateDescriptorInfo(1, &storageBuffers_shipPipeline.infoSet, swapChainImages.size()); 1112 1119 } 1113 1120 … … 1121 1128 // TODO: Probably move the resizing to the VulkanBuffer class 1122 1129 if (objects_asteroidPipeline.resized) { 1123 resizeBufferSet(storageBuffers_asteroidPipeline, objects_asteroidPipeline , asteroidPipeline,1124 resourceCommandPool, graphicsQueue );1130 resizeBufferSet(storageBuffers_asteroidPipeline, objects_asteroidPipeline.capacity * sizeof(SSBO_Asteroid), 1131 resourceCommandPool, graphicsQueue, true); 1125 1132 1126 1133 objects_asteroidPipeline.resize(); 1134 1135 asteroidPipeline.updateDescriptorInfo(1, &storageBuffers_asteroidPipeline.infoSet, swapChainImages.size()); 1127 1136 } 1128 1137 … … 1136 1145 // TODO: Probably move the resizing to the VulkanBuffer class 1137 1146 if (objects_laserPipeline.resized) { 1138 resizeBufferSet(storageBuffers_laserPipeline, objects_laserPipeline , laserPipeline, resourceCommandPool,1139 graphicsQueue);1147 resizeBufferSet(storageBuffers_laserPipeline, objects_laserPipeline.capacity * sizeof(SSBO_Laser), 1148 resourceCommandPool, graphicsQueue, true); 1140 1149 1141 1150 objects_laserPipeline.resize(); 1151 1152 laserPipeline.updateDescriptorInfo(1, &storageBuffers_laserPipeline.infoSet, swapChainImages.size()); 1142 1153 } 1143 1154 … … 1151 1162 // TODO: Probably move the resizing to the VulkanBuffer class 1152 1163 if (objects_explosionPipeline.resized) { 1153 resizeBufferSet(storageBuffers_explosionPipeline, objects_explosionPipeline , explosionPipeline,1154 resourceCommandPool, graphicsQueue);1164 resizeBufferSet(storageBuffers_explosionPipeline, objects_explosionPipeline.capacity * sizeof(SSBO_Explosion), 1165 resourceCommandPool, graphicsQueue, true); 1155 1166 1156 1167 objects_explosionPipeline.resize(); 1168 1169 explosionPipeline.updateDescriptorInfo(1, &storageBuffers_explosionPipeline.infoSet, swapChainImages.size()); 1157 1170 } 1158 1171 … … 1962 1975 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now 1963 1976 set.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE 1977 } 1978 } 1979 1980 void VulkanGame::resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool, 1981 VkQueue graphicsQueue, bool copyData) { 1982 for (size_t i = 0; i < set.buffers.size(); i++) { 1983 VkBuffer newBuffer; 1984 VkDeviceMemory newMemory; 1985 1986 VulkanUtils::createBuffer(device, physicalDevice, newSize, set.usages, set.properties, newBuffer, newMemory); 1987 1988 if (copyData) { 1989 VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newBuffer, 0, 0, set.infoSet[i].range, 1990 graphicsQueue); 1991 } 1992 1993 vkDestroyBuffer(device, set.buffers[i], nullptr); 1994 vkFreeMemory(device, set.memory[i], nullptr); 1995 1996 set.buffers[i] = newBuffer; 1997 set.memory[i] = newMemory; 1998 1999 set.infoSet[i].buffer = set.buffers[i]; 2000 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now 2001 set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE 1964 2002 } 1965 2003 } -
vulkan-game.hpp
r6bac215 rbb76950 124 124 vec3 center; // currently only matters for asteroids 125 125 float radius; // currently only matters for asteroids 126 127 // Move the targetAsteroid stuff out of this class since it is very specific to lasers 128 // and makes moving SceneObject into its own header file more problematic 126 129 SceneObject<ModelVertex, SSBO_Asteroid>* targetAsteroid; // currently only used for lasers 127 130 }; … … 432 435 BufferSet& set); 433 436 434 template<class VertexType, class SSBOType> 435 void resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer, 436 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool, 437 VkQueue graphicsQueue); 437 void resizeBufferSet(BufferSet& set, VkDeviceSize newSize, VkCommandPool commandPool, VkQueue graphicsQueue, 438 bool copyData); 438 439 439 440 template<class SSBOType> … … 498 499 499 500 // End of specialized no-op functions 500 501 template<class VertexType, class SSBOType>502 void VulkanGame::resizeBufferSet(BufferSet& set, VulkanBuffer<SSBOType>& buffer,503 GraphicsPipeline_Vulkan<VertexType>& pipeline, VkCommandPool commandPool,504 VkQueue graphicsQueue) {505 VkDeviceSize newSize = buffer.capacity * sizeof(SSBOType);506 507 for (size_t i = 0; i < set.buffers.size(); i++) {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);515 516 vkDestroyBuffer(device, set.buffers[i], nullptr);517 vkFreeMemory(device, set.memory[i], nullptr);518 519 set.buffers[i] = newBuffer;520 set.memory[i] = newMemory;521 522 set.infoSet[i].buffer = set.buffers[i];523 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now524 set.infoSet[i].range = newSize; // Size of the update starting from offset, or VK_WHOLE_SIZE525 }526 527 // Assume the SSBO is always the 2nd binding528 // TODO: Figure out a way to make this more flexible529 pipeline.updateDescriptorInfo(1, &set.infoSet, swapChainImages.size());530 }531 501 532 502 // TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
Note:
See TracChangeset
for help on using the changeset viewer.