Changeset 996dd3e in opengl-game
- Timestamp:
- May 14, 2021, 1:09:34 AM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- a3cefaa
- Parents:
- 9d21aac
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
graphics-pipeline_vulkan.hpp
r9d21aac r996dd3e 22 22 using namespace glm; 23 23 24 // TODO: Use this struct for uniform buffers as well and rename it to VulkanBuffer (maybe move it to VulkanUtils)25 // Also, probably better to make this a vector of structs where each struct26 // has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo27 struct StorageBufferSet {28 vector<VkBuffer> buffers;29 vector<VkDeviceMemory> memory;30 vector<VkDescriptorBufferInfo> infoSet;31 };32 33 24 // TODO: Maybe change the name of this struct so I can call the list something other than descriptorInfoList 34 25 struct DescriptorInfo { … … 45 36 public: 46 37 string vertShaderFile, fragShaderFile; 47 48 // TODO: Move this outside this classs, since it is no longer used here49 StorageBufferSet storageBufferSet;50 38 51 39 // Both of these are only used for managing the SSBO, so move them out as well -
sdl-game.cpp
r9d21aac r996dd3e 110 110 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline); 111 111 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 112 VK_SHADER_STAGE_VERTEX_BIT, & modelPipeline.storageBufferSet.infoSet);112 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_modelPipeline.infoSet); 113 113 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 114 114 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); … … 131 131 }, { 132 132 mat4(1.0f) 133 }, false); 133 }, storageBuffers_modelPipeline, false); 134 135 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo); 134 136 135 137 texturedSquare->model_base = … … 150 152 }, { 151 153 mat4(1.0f) 152 }, false); 154 }, storageBuffers_modelPipeline, false); 155 156 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo); 153 157 154 158 texturedSquare->model_base = … … 264 268 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 265 269 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 266 modelPipeline.storageBufferSet.buffers, modelPipeline.storageBufferSet.memory,267 modelPipeline.storageBufferSet.infoSet);270 storageBuffers_modelPipeline.buffers, storageBuffers_modelPipeline.memory, 271 storageBuffers_modelPipeline.infoSet); 268 272 } 269 273 … … 372 376 }, { 373 377 mat4(1.0f) 374 }, true); 378 }, storageBuffers_modelPipeline, true); 379 380 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo); 375 381 376 382 texturedSquare.model_base = … … 439 445 } 440 446 441 // TODO: The only updates that need to happen once per Vulkan image are the SSBO ones,442 // which are already handled by updateObject(). Move this code to a different place,443 // where it will run just once per frame444 447 void VulkanGame::updateScene() { 448 // TODO: These two for loops could probably be combined into one 449 445 450 for (SceneObject<ModelVertex, SSBO_ModelObject>& model : this->modelObjects) { 446 451 model.model_transform = … … 450 455 } 451 456 457 // TODO: Instead, update entire sections (up to 64k) of the dynamic ubo if some objects there have changed 458 // Also, update the objects modelMat and center in the loop above instead of here 452 459 for (size_t i = 0; i < modelObjects.size(); i++) { 453 460 if (modelObjects[i].modified) { 461 // TODO: Think about changing the SSBO-related code to also use a contiguous array 462 // to store the data on the cpu side instead of storing it per-object 463 // Then, I could also copy it to the GPU in one go 464 // Also, double-check if the alignment restrictions also hold for SSBOs 465 454 466 updateObject(modelObjects, modelPipeline, i); 467 updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo); 455 468 } 456 469 } … … 475 488 modelPipeline.cleanupBuffers(); 476 489 477 for (size_t i = 0; i < modelPipeline.storageBufferSet.buffers.size(); i++) {478 vkDestroyBuffer(device, modelPipeline.storageBufferSet.buffers[i], nullptr);479 vkFreeMemory(device, modelPipeline.storageBufferSet.memory[i], nullptr);490 for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) { 491 vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr); 492 vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr); 480 493 } 481 494 -
sdl-game.hpp
r9d21aac r996dd3e 72 72 alignas(16) mat4 view; 73 73 alignas(16) mat4 proj; 74 }; 75 76 // TODO: Use this struct for uniform buffers as well and probably combine it with the VulkanBuffer class 77 // Also, probably better to make this a vector of structs where each struct 78 // has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo 79 struct StorageBufferSet { 80 vector<VkBuffer> buffers; 81 vector<VkDeviceMemory> memory; 82 vector<VkDescriptorBufferInfo> infoSet; 74 83 }; 75 84 … … 208 217 // wouldn't work since the whole pipeline couldn't have a common set of descriptors for the textures 209 218 GraphicsPipeline_Vulkan<ModelVertex> modelPipeline; 219 220 StorageBufferSet storageBuffers_modelPipeline; 210 221 211 222 // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo … … 297 308 GraphicsPipeline_Vulkan<VertexType>& pipeline, 298 309 const vector<VertexType>& vertices, vector<uint16_t> indices, 299 SSBOType ssbo, bool pipelinesCreated); 310 SSBOType ssbo, StorageBufferSet& storageBuffers, 311 bool pipelinesCreated); 300 312 301 313 template<class VertexType> … … 381 393 GraphicsPipeline_Vulkan<VertexType>& pipeline, 382 394 const vector<VertexType>& vertices, vector<uint16_t> indices, 383 SSBOType ssbo, bool pipelinesCreated) { 395 SSBOType ssbo, StorageBufferSet& storageBuffers, 396 bool pipelinesCreated) { 384 397 // TODO: Use the model field of ssbo to set the object's model_base 385 398 // currently, the passed in model is useless since it gets overridden in updateObject() anyway … … 403 416 pipeline.addObject(obj.vertices, obj.indices, resourceCommandPool, graphicsQueue); 404 417 418 // TODO: Probably move the resizing to the VulkanBuffer class 419 // First, try moving this out of addObject 405 420 bool resizeStorageBuffer = pipeline.numObjects == pipeline.objectCapacity; 406 421 407 422 if (resizeStorageBuffer) { 408 resizeStorageBufferSet<VertexType, SSBOType>( pipeline.storageBufferSet, resourceCommandPool, graphicsQueue, pipeline);423 resizeStorageBufferSet<VertexType, SSBOType>(storageBuffers, resourceCommandPool, graphicsQueue, pipeline); 409 424 pipeline.cleanup(); 410 425 411 426 // Assume the SSBO is always the 2nd binding 412 pipeline.updateDescriptorInfo(1, &pipeline.storageBufferSet.infoSet); 427 // TODO: Figure out a way to make this more flexible 428 pipeline.updateDescriptorInfo(1, &storageBuffers.infoSet); 413 429 } 414 430 415 431 pipeline.numObjects++; 416 417 updateStorageBuffer(pipeline.storageBufferSet, pipeline.numObjects - 1, obj.ssbo);418 432 419 433 // TODO: Figure out why I am destroying and recreating the ubos when the swap chain is recreated, … … 421 435 422 436 if (pipelinesCreated) { 437 // TODO: See if I can avoid doing this when recreating the pipeline 423 438 vkDeviceWaitIdle(device); 424 439 … … 531 546 obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 532 547 533 updateStorageBuffer(pipeline.storageBufferSet, index, obj.ssbo);534 535 548 obj.modified = false; 536 549 } -
vulkan-game.cpp
r9d21aac r996dd3e 126 126 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline); 127 127 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 128 VK_SHADER_STAGE_VERTEX_BIT, & modelPipeline.storageBufferSet.infoSet);128 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_modelPipeline.infoSet); 129 129 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 130 130 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); … … 145 145 }, { 146 146 mat4(1.0f) 147 }, false); 147 }, storageBuffers_modelPipeline, false); 148 149 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo); 148 150 149 151 texturedSquare->model_base = … … 164 166 }, { 165 167 mat4(1.0f) 166 }, false); 168 }, storageBuffers_modelPipeline, false); 169 170 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo); 167 171 168 172 texturedSquare->model_base = … … 189 193 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline); 190 194 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 191 VK_SHADER_STAGE_VERTEX_BIT, &s hipPipeline.storageBufferSet.infoSet);195 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_shipPipeline.infoSet); 192 196 193 197 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly … … 424 428 }, { 425 429 mat4(1.0f) 426 }, false); 430 }, storageBuffers_shipPipeline, false); 431 432 updateStorageBuffer(storageBuffers_shipPipeline, shipPipeline.numObjects - 1, ship.ssbo); 427 433 428 434 ship.model_base = … … 449 455 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline); 450 456 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 451 VK_SHADER_STAGE_VERTEX_BIT, & asteroidPipeline.storageBufferSet.infoSet);457 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_asteroidPipeline.infoSet); 452 458 453 459 asteroidPipeline.createDescriptorSetLayout(); … … 467 473 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline); 468 474 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 469 VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, & laserPipeline.storageBufferSet.infoSet);475 VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, &storageBuffers_laserPipeline.infoSet); 470 476 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 471 477 VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor); … … 487 493 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_explosionPipeline); 488 494 explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 489 VK_SHADER_STAGE_VERTEX_BIT, & explosionPipeline.storageBufferSet.infoSet);495 VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_explosionPipeline.infoSet); 490 496 491 497 explosionPipeline.createDescriptorSetLayout(); … … 599 605 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 600 606 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 601 modelPipeline.storageBufferSet.buffers, modelPipeline.storageBufferSet.memory,602 modelPipeline.storageBufferSet.infoSet);607 storageBuffers_modelPipeline.buffers, storageBuffers_modelPipeline.memory, 608 storageBuffers_modelPipeline.infoSet); 603 609 604 610 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>( … … 609 615 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 610 616 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 611 s hipPipeline.storageBufferSet.buffers, shipPipeline.storageBufferSet.memory,612 s hipPipeline.storageBufferSet.infoSet);617 storageBuffers_shipPipeline.buffers, storageBuffers_shipPipeline.memory, 618 storageBuffers_shipPipeline.infoSet); 613 619 614 620 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>( … … 619 625 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 620 626 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 621 asteroidPipeline.storageBufferSet.buffers, asteroidPipeline.storageBufferSet.memory,622 asteroidPipeline.storageBufferSet.infoSet);627 storageBuffers_asteroidPipeline.buffers, storageBuffers_asteroidPipeline.memory, 628 storageBuffers_asteroidPipeline.infoSet); 623 629 624 630 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>( … … 629 635 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 630 636 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 631 laserPipeline.storageBufferSet.buffers, laserPipeline.storageBufferSet.memory,632 laserPipeline.storageBufferSet.infoSet);637 storageBuffers_laserPipeline.buffers, storageBuffers_laserPipeline.memory, 638 storageBuffers_laserPipeline.infoSet); 633 639 634 640 explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex>( … … 640 646 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 641 647 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 642 explosionPipeline.storageBufferSet.buffers, explosionPipeline.storageBufferSet.memory,643 explosionPipeline.storageBufferSet.infoSet);648 storageBuffers_explosionPipeline.buffers, storageBuffers_explosionPipeline.memory, 649 storageBuffers_explosionPipeline.infoSet); 644 650 } 645 651 … … 762 768 }, { 763 769 mat4(1.0f) 764 }, true); 770 }, storageBuffers_modelPipeline, true); 771 772 updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo); 765 773 766 774 texturedSquare.model_base = … … 1042 1050 10.0f, 1043 1051 false 1044 }, true); 1052 }, storageBuffers_asteroidPipeline, true); 1053 1054 updateStorageBuffer(storageBuffers_asteroidPipeline, asteroidPipeline.numObjects - 1, asteroid.ssbo); 1045 1055 1046 1056 // This accounts for the scaling in model_base. … … 1070 1080 if (shipObjects[i].modified) { 1071 1081 updateObject(shipObjects, shipPipeline, i); 1082 updateStorageBuffer(storageBuffers_shipPipeline, i, shipObjects[i].ssbo); 1072 1083 } 1073 1084 } … … 1076 1087 if (modelObjects[i].modified) { 1077 1088 updateObject(modelObjects, modelPipeline, i); 1089 updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo); 1078 1090 } 1079 1091 } … … 1082 1094 if (asteroidObjects[i].modified) { 1083 1095 updateObject(asteroidObjects, asteroidPipeline, i); 1096 updateStorageBuffer(storageBuffers_asteroidPipeline, i, asteroidObjects[i].ssbo); 1084 1097 } 1085 1098 } … … 1088 1101 if (laserObjects[i].modified) { 1089 1102 updateObject(laserObjects, laserPipeline, i); 1103 updateStorageBuffer(storageBuffers_laserPipeline, i, laserObjects[i].ssbo); 1090 1104 } 1091 1105 } … … 1094 1108 if (explosionObjects[i].modified) { 1095 1109 updateObject(explosionObjects, explosionPipeline, i); 1110 updateStorageBuffer(storageBuffers_explosionPipeline, i, explosionObjects[i].ssbo); 1096 1111 } 1097 1112 } … … 1131 1146 explosionPipeline.cleanupBuffers(); 1132 1147 1133 for (size_t i = 0; i < modelPipeline.storageBufferSet.buffers.size(); i++) {1134 vkDestroyBuffer(device, modelPipeline.storageBufferSet.buffers[i], nullptr);1135 vkFreeMemory(device, modelPipeline.storageBufferSet.memory[i], nullptr);1136 } 1137 1138 for (size_t i = 0; i < s hipPipeline.storageBufferSet.buffers.size(); i++) {1139 vkDestroyBuffer(device, s hipPipeline.storageBufferSet.buffers[i], nullptr);1140 vkFreeMemory(device, s hipPipeline.storageBufferSet.memory[i], nullptr);1141 } 1142 1143 for (size_t i = 0; i < asteroidPipeline.storageBufferSet.buffers.size(); i++) {1144 vkDestroyBuffer(device, asteroidPipeline.storageBufferSet.buffers[i], nullptr);1145 vkFreeMemory(device, asteroidPipeline.storageBufferSet.memory[i], nullptr);1146 } 1147 1148 for (size_t i = 0; i < laserPipeline.storageBufferSet.buffers.size(); i++) {1149 vkDestroyBuffer(device, laserPipeline.storageBufferSet.buffers[i], nullptr);1150 vkFreeMemory(device, laserPipeline.storageBufferSet.memory[i], nullptr);1151 } 1152 1153 for (size_t i = 0; i < explosionPipeline.storageBufferSet.buffers.size(); i++) {1154 vkDestroyBuffer(device, explosionPipeline.storageBufferSet.buffers[i], nullptr);1155 vkFreeMemory(device, explosionPipeline.storageBufferSet.memory[i], nullptr);1148 for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) { 1149 vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr); 1150 vkFreeMemory(device, storageBuffers_modelPipeline.memory[i], nullptr); 1151 } 1152 1153 for (size_t i = 0; i < storageBuffers_shipPipeline.buffers.size(); i++) { 1154 vkDestroyBuffer(device, storageBuffers_shipPipeline.buffers[i], nullptr); 1155 vkFreeMemory(device, storageBuffers_shipPipeline.memory[i], nullptr); 1156 } 1157 1158 for (size_t i = 0; i < storageBuffers_asteroidPipeline.buffers.size(); i++) { 1159 vkDestroyBuffer(device, storageBuffers_asteroidPipeline.buffers[i], nullptr); 1160 vkFreeMemory(device, storageBuffers_asteroidPipeline.memory[i], nullptr); 1161 } 1162 1163 for (size_t i = 0; i < storageBuffers_laserPipeline.buffers.size(); i++) { 1164 vkDestroyBuffer(device, storageBuffers_laserPipeline.buffers[i], nullptr); 1165 vkFreeMemory(device, storageBuffers_laserPipeline.memory[i], nullptr); 1166 } 1167 1168 for (size_t i = 0; i < storageBuffers_explosionPipeline.buffers.size(); i++) { 1169 vkDestroyBuffer(device, storageBuffers_explosionPipeline.buffers[i], nullptr); 1170 vkFreeMemory(device, storageBuffers_explosionPipeline.memory[i], nullptr); 1156 1171 } 1157 1172 … … 1914 1929 color, 1915 1930 false 1916 }, true); 1931 }, storageBuffers_laserPipeline, true); 1932 1933 updateStorageBuffer(storageBuffers_laserPipeline, laserPipeline.numObjects - 1, laser.ssbo); 1917 1934 1918 1935 float xAxisRotation = asin(ray.y / length); … … 2124 2141 duration, 2125 2142 false 2126 }, true); 2143 }, storageBuffers_explosionPipeline, true); 2144 2145 updateStorageBuffer(storageBuffers_explosionPipeline, explosionPipeline.numObjects - 1, explosion.ssbo); 2127 2146 2128 2147 explosion.model_base = model_mat; -
vulkan-game.hpp
r9d21aac r996dd3e 96 96 alignas(16) mat4 proj; 97 97 alignas(4) float cur_time; 98 }; 99 100 // TODO: Use this struct for uniform buffers as well and probably combine it with the VulkanBuffer class 101 // Also, probably better to make this a vector of structs where each struct 102 // has a VkBuffer, VkDeviceMemory, and VkDescriptorBufferInfo 103 struct StorageBufferSet { 104 vector<VkBuffer> buffers; 105 vector<VkDeviceMemory> memory; 106 vector<VkDescriptorBufferInfo> infoSet; 98 107 }; 99 108 … … 305 314 GraphicsPipeline_Vulkan<LaserVertex> laserPipeline; 306 315 GraphicsPipeline_Vulkan<ExplosionVertex> explosionPipeline; 316 317 StorageBufferSet storageBuffers_modelPipeline; 318 StorageBufferSet storageBuffers_shipPipeline; 319 StorageBufferSet storageBuffers_asteroidPipeline; 320 StorageBufferSet storageBuffers_laserPipeline; 321 StorageBufferSet storageBuffers_explosionPipeline; 307 322 308 323 // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo … … 440 455 GraphicsPipeline_Vulkan<VertexType>& pipeline, 441 456 const vector<VertexType>& vertices, vector<uint16_t> indices, 442 SSBOType ssbo, bool pipelinesCreated); 457 SSBOType ssbo, StorageBufferSet& storageBuffers, 458 bool pipelinesCreated); 443 459 444 460 template<class VertexType> … … 544 560 GraphicsPipeline_Vulkan<VertexType>& pipeline, 545 561 const vector<VertexType>& vertices, vector<uint16_t> indices, 546 SSBOType ssbo, bool pipelinesCreated) { 562 SSBOType ssbo, StorageBufferSet& storageBuffers, 563 bool pipelinesCreated) { 547 564 // TODO: Use the model field of ssbo to set the object's model_base 548 565 // currently, the passed in model is useless since it gets overridden in updateObject() anyway … … 566 583 pipeline.addObject(obj.vertices, obj.indices, resourceCommandPool, graphicsQueue); 567 584 585 // TODO: Probably move the resizing to the VulkanBuffer class 586 // First, try moving this out of addObject 568 587 bool resizeStorageBuffer = pipeline.numObjects == pipeline.objectCapacity; 569 588 570 589 if (resizeStorageBuffer) { 571 resizeStorageBufferSet<VertexType, SSBOType>( pipeline.storageBufferSet, resourceCommandPool, graphicsQueue, pipeline);590 resizeStorageBufferSet<VertexType, SSBOType>(storageBuffers, resourceCommandPool, graphicsQueue, pipeline); 572 591 pipeline.cleanup(); 573 592 574 593 // Assume the SSBO is always the 2nd binding 575 pipeline.updateDescriptorInfo(1, &pipeline.storageBufferSet.infoSet); 594 // TODO: Figure out a way to make this more flexible 595 pipeline.updateDescriptorInfo(1, &storageBuffers.infoSet); 576 596 } 577 597 578 598 pipeline.numObjects++; 579 580 updateStorageBuffer(pipeline.storageBufferSet, pipeline.numObjects - 1, obj.ssbo);581 599 582 600 // TODO: Figure out why I am destroying and recreating the ubos when the swap chain is recreated, … … 584 602 585 603 if (pipelinesCreated) { 604 // TODO: See if I can avoid doing this when recreating the pipeline 586 605 vkDeviceWaitIdle(device); 587 606 … … 699 718 obj.center = vec3(obj.ssbo.model * vec4(0.0f, 0.0f, 0.0f, 1.0f)); 700 719 701 updateStorageBuffer(pipeline.storageBufferSet, index, obj.ssbo);702 703 720 obj.modified = false; 704 721 } -
vulkan-utils.hpp
r9d21aac r996dd3e 117 117 template<class DataType> 118 118 void VulkanUtils::copyDataToBuffer(VkDevice device, VkPhysicalDevice physicalDevice, VkCommandPool commandPool, 119 const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, VkQueue graphicsQueue) { 119 const vector<DataType>& srcData, VkBuffer dstBuffer, size_t dstVertexOffset, 120 VkQueue graphicsQueue) { 120 121 VkDeviceSize srcDataSize = srcData.size() * sizeof(DataType); 121 122 … … 140 141 template<class DataType> 141 142 void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory, 142 VkDeviceSize offset) {143 VkDeviceSize offset) { 143 144 copyDataToMemory(device, srcData, bufferMemory, offset, sizeof(DataType)); 144 145 } 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 146 149 template<class DataType> 147 150 void VulkanUtils::copyDataToMemory(VkDevice device, const DataType& srcData, VkDeviceMemory bufferMemory,
Note:
See TracChangeset
for help on using the changeset viewer.