Changeset 9d21aac in opengl-game for sdl-game.hpp
- Timestamp:
- May 6, 2021, 3:24:42 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 996dd3e
- Parents:
- 756162f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sdl-game.hpp
r756162f r9d21aac 207 207 // the same pipeline, but use different textures, the approach I took when initially creating GraphicsPipeline_Vulkan 208 208 // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures 209 GraphicsPipeline_Vulkan<ModelVertex , SSBO_ModelObject> modelPipeline;209 GraphicsPipeline_Vulkan<ModelVertex> modelPipeline; 210 210 211 211 // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo … … 276 276 void cleanupImGuiOverlay(); 277 277 278 void createBufferSet(vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, VkDeviceSize bufferSize, 279 VkBufferUsageFlags flags, VkMemoryPropertyFlags properties, 278 // TODO: Maybe move these to a different class, possibly VulkanBuffer or some new related class 279 280 void createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties, 281 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, 280 282 vector<VkDescriptorBufferInfo>& bufferInfoList); 283 284 // TODO: See if it makes sense to rename this to resizeBufferSet() and use it to resize other types of buffers as well 285 // TODO: Remove the need for templating, which is only there so a GraphicsPupeline_Vulkan can be passed in 286 template<class VertexType, class SSBOType> 287 void resizeStorageBufferSet(StorageBufferSet& set, VkCommandPool commandPool, VkQueue graphicsQueue, 288 GraphicsPipeline_Vulkan<VertexType>& pipeline); 289 290 template<class SSBOType> 291 void updateStorageBuffer(StorageBufferSet& storageBufferSet, size_t objIndex, SSBOType& ssbo); 281 292 282 293 // TODO: Since addObject() returns a reference to the new object now, … … 284 295 template<class VertexType, class SSBOType> 285 296 SceneObject<VertexType, SSBOType>& addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 286 GraphicsPipeline_Vulkan<VertexType , SSBOType>& pipeline,297 GraphicsPipeline_Vulkan<VertexType>& pipeline, 287 298 const vector<VertexType>& vertices, vector<uint16_t> indices, 288 299 SSBOType ssbo, bool pipelinesCreated); … … 298 309 299 310 template<class VertexType, class SSBOType> 300 void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, GraphicsPipeline_Vulkan<VertexType,301 SSBOType>& pipeline, size_t index);311 void updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, 312 GraphicsPipeline_Vulkan<VertexType>& pipeline, size_t index); 302 313 303 314 void renderFrame(ImDrawData* draw_data); … … 320 331 }; 321 332 333 template<class VertexType, class SSBOType> 334 void VulkanGame::resizeStorageBufferSet(StorageBufferSet& set, VkCommandPool commandPool, VkQueue graphicsQueue, 335 GraphicsPipeline_Vulkan<VertexType>& pipeline) { 336 pipeline.objectCapacity *= 2; 337 VkDeviceSize bufferSize = pipeline.objectCapacity * sizeof(SSBOType); 338 339 for (size_t i = 0; i < set.buffers.size(); i++) { 340 VkBuffer newStorageBuffer; 341 VkDeviceMemory newStorageBufferMemory; 342 343 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, 344 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 345 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 346 newStorageBuffer, newStorageBufferMemory); 347 348 VulkanUtils::copyBuffer(device, commandPool, set.buffers[i], newStorageBuffer, 349 0, 0, pipeline.numObjects * sizeof(SSBOType), graphicsQueue); 350 351 vkDestroyBuffer(device, set.buffers[i], nullptr); 352 vkFreeMemory(device, set.memory[i], nullptr); 353 354 set.buffers[i] = newStorageBuffer; 355 set.memory[i] = newStorageBufferMemory; 356 357 set.infoSet[i].buffer = set.buffers[i]; 358 set.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now 359 set.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE 360 } 361 } 362 363 // TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them 364 template<class SSBOType> 365 void VulkanGame::updateStorageBuffer(StorageBufferSet& storageBufferSet, size_t objIndex, SSBOType& ssbo) { 366 for (size_t i = 0; i < storageBufferSet.memory.size(); i++) { 367 VulkanUtils::copyDataToMemory(device, ssbo, storageBufferSet.memory[i], objIndex * sizeof(SSBOType)); 368 } 369 } 370 322 371 // TODO: Right now, it's basically necessary to pass the identity matrix in for ssbo.model 323 372 // and to change the model matrix later by setting model_transform and then calling updateObject() 324 // Figure out a better way to allow the model matrix to be set during object ingcreation373 // Figure out a better way to allow the model matrix to be set during object creation 325 374 326 375 // TODO: Maybe return a reference to the object from this method if I decide that updating it … … 329 378 // to account for scaling 330 379 template<class VertexType, class SSBOType> 331 SceneObject<VertexType, SSBOType>& VulkanGame::addObject( 332 vector<SceneObject<VertexType, SSBOType>>& objects, 333 GraphicsPipeline_Vulkan<VertexType, SSBOType>& pipeline, 334 const vector<VertexType>& vertices, vector<uint16_t> indices, SSBOType ssbo, 335 bool pipelinesCreated) { 380 SceneObject<VertexType, SSBOType>& VulkanGame::addObject(vector<SceneObject<VertexType, SSBOType>>& objects, 381 GraphicsPipeline_Vulkan<VertexType>& pipeline, 382 const vector<VertexType>& vertices, vector<uint16_t> indices, 383 SSBOType ssbo, bool pipelinesCreated) { 336 384 // TODO: Use the model field of ssbo to set the object's model_base 337 385 // currently, the passed in model is useless since it gets overridden in updateObject() anyway … … 353 401 } 354 402 355 bool storageBufferResized = pipeline.addObject(obj.vertices, obj.indices, obj.ssbo, 356 resourceCommandPool, graphicsQueue); 403 pipeline.addObject(obj.vertices, obj.indices, resourceCommandPool, graphicsQueue); 404 405 bool resizeStorageBuffer = pipeline.numObjects == pipeline.objectCapacity; 406 407 if (resizeStorageBuffer) { 408 resizeStorageBufferSet<VertexType, SSBOType>(pipeline.storageBufferSet, resourceCommandPool, graphicsQueue, pipeline); 409 pipeline.cleanup(); 410 411 // Assume the SSBO is always the 2nd binding 412 pipeline.updateDescriptorInfo(1, &pipeline.storageBufferSet.infoSet); 413 } 414 415 pipeline.numObjects++; 416 417 updateStorageBuffer(pipeline.storageBufferSet, pipeline.numObjects - 1, obj.ssbo); 418 419 // TODO: Figure out why I am destroying and recreating the ubos when the swap chain is recreated, 420 // but am reusing the same ssbos. Maybe I don't need to recreate the ubos. 357 421 358 422 if (pipelinesCreated) { … … 367 431 // Refactor the logic to check for any resized SSBOs after all objects for the frame 368 432 // are created and then recreate each of the corresponding pipelines only once per frame 369 if (storageBufferResized) { 433 434 // TODO: Also, verify if I actually need to recreate all of these, or maybe just the descriptor sets, for instance 435 436 if (resizeStorageBuffer) { 370 437 pipeline.createPipeline(pipeline.vertShaderFile, pipeline.fragShaderFile); 371 438 pipeline.createDescriptorPool(swapChainImages); … … 457 524 // TODO: Just pass in the single object instead of a list of all of them 458 525 template<class VertexType, class SSBOType> 459 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, GraphicsPipeline_Vulkan<VertexType,460 SSBOType>& pipeline, size_t index) {526 void VulkanGame::updateObject(vector<SceneObject<VertexType, SSBOType>>& objects, 527 GraphicsPipeline_Vulkan<VertexType>& pipeline, size_t index) { 461 528 SceneObject<VertexType, SSBOType>& obj = objects[index]; 462 529 … … 464 531 obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 465 532 466 pipeline.updateObject(index, obj.ssbo);533 updateStorageBuffer(pipeline.storageBufferSet, index, obj.ssbo); 467 534 468 535 obj.modified = false;
Note:
See TracChangeset
for help on using the changeset viewer.