Changeset 9d21aac in opengl-game for vulkan-game.cpp
- Timestamp:
- May 6, 2021, 3:24:42 AM (3 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 996dd3e
- Parents:
- 756162f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r756162f r9d21aac 119 119 modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 120 120 121 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 121 createBufferSet(sizeof(UBO_VP_mats), 122 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 122 123 uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline); 123 124 124 125 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 125 126 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline); 126 modelPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 127 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 128 VK_SHADER_STAGE_VERTEX_BIT, &modelPipeline.storageBufferSet.infoSet); 127 129 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 128 130 VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor); … … 180 182 shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 181 183 182 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 184 createBufferSet(sizeof(UBO_VP_mats), 185 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 183 186 uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); 184 187 185 188 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 186 189 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline); 187 shipPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 190 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 191 VK_SHADER_STAGE_VERTEX_BIT, &shipPipeline.storageBufferSet.infoSet); 188 192 189 193 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly … … 438 442 asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex)); 439 443 440 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 444 createBufferSet(sizeof(UBO_VP_mats), 445 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 441 446 uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline); 442 447 443 448 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 444 449 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline); 445 asteroidPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 450 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 451 VK_SHADER_STAGE_VERTEX_BIT, &asteroidPipeline.storageBufferSet.infoSet); 446 452 447 453 asteroidPipeline.createDescriptorSetLayout(); … … 454 460 laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex)); 455 461 456 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 462 createBufferSet(sizeof(UBO_VP_mats), 463 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 457 464 uniformBuffers_laserPipeline, uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline); 458 465 459 466 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 460 467 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline); 461 laserPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT); 468 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 469 VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, &laserPipeline.storageBufferSet.infoSet); 462 470 laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 463 471 VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor); … … 472 480 explosionPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ExplosionVertex::objIndex)); 473 481 474 createBufferSet(sizeof(UBO_Explosion), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 482 createBufferSet(sizeof(UBO_Explosion), 483 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 475 484 uniformBuffers_explosionPipeline, uniformBuffersMemory_explosionPipeline, uniformBufferInfoList_explosionPipeline); 476 485 477 486 explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 478 487 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_explosionPipeline); 479 explosionPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT); 488 explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 489 VK_SHADER_STAGE_VERTEX_BIT, &explosionPipeline.storageBufferSet.infoSet); 480 490 481 491 explosionPipeline.createDescriptorSetLayout(); … … 582 592 583 593 void VulkanGame::initGraphicsPipelines() { 584 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex , SSBO_ModelObject>(594 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 585 595 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 586 596 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 24, 10); 587 597 588 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject>( 598 createBufferSet(modelPipeline.objectCapacity * sizeof(SSBO_ModelObject), 599 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 600 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 601 modelPipeline.storageBufferSet.buffers, modelPipeline.storageBufferSet.memory, 602 modelPipeline.storageBufferSet.infoSet); 603 604 shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 589 605 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 590 606 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138, 10); 591 607 592 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex, SSBO_Asteroid>( 608 createBufferSet(modelPipeline.objectCapacity * sizeof(SSBO_ModelObject), 609 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 610 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 611 shipPipeline.storageBufferSet.buffers, shipPipeline.storageBufferSet.memory, 612 shipPipeline.storageBufferSet.infoSet); 613 614 asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>( 593 615 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 594 616 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36, 10); 595 617 596 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex, SSBO_Laser>( 618 createBufferSet(modelPipeline.objectCapacity * sizeof(SSBO_Asteroid), 619 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 620 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 621 asteroidPipeline.storageBufferSet.buffers, asteroidPipeline.storageBufferSet.memory, 622 asteroidPipeline.storageBufferSet.infoSet); 623 624 laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>( 597 625 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, physicalDevice, device, renderPass, 598 626 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 8, 18, 2); 599 627 600 explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex, SSBO_Explosion>( 628 createBufferSet(modelPipeline.objectCapacity * sizeof(SSBO_Laser), 629 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 630 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 631 laserPipeline.storageBufferSet.buffers, laserPipeline.storageBufferSet.memory, 632 laserPipeline.storageBufferSet.infoSet); 633 634 explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex>( 601 635 VK_PRIMITIVE_TOPOLOGY_POINT_LIST, physicalDevice, device, renderPass, 602 636 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 603 637 swapChainImages, EXPLOSION_PARTICLE_COUNT, EXPLOSION_PARTICLE_COUNT, 2); 638 639 createBufferSet(modelPipeline.objectCapacity * sizeof(SSBO_Explosion), 640 VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, 641 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 642 explosionPipeline.storageBufferSet.buffers, explosionPipeline.storageBufferSet.memory, 643 explosionPipeline.storageBufferSet.infoSet); 604 644 } 605 645 … … 1091 1131 explosionPipeline.cleanupBuffers(); 1092 1132 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 < shipPipeline.storageBufferSet.buffers.size(); i++) { 1139 vkDestroyBuffer(device, shipPipeline.storageBufferSet.buffers[i], nullptr); 1140 vkFreeMemory(device, shipPipeline.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); 1156 } 1157 1093 1158 // END UNREVIEWED SECTION 1094 1159 … … 1810 1875 } 1811 1876 1812 void VulkanGame::createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, 1813 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, vector<VkDescriptorBufferInfo>& bufferInfoList) { 1877 void VulkanGame::createBufferSet(VkDeviceSize bufferSize, VkBufferUsageFlags flags, VkMemoryPropertyFlags properties, 1878 vector<VkBuffer>& buffers, vector<VkDeviceMemory>& buffersMemory, 1879 vector<VkDescriptorBufferInfo>& bufferInfoList) { 1814 1880 buffers.resize(swapChainImageCount); 1815 1881 buffersMemory.resize(swapChainImageCount); … … 1817 1883 1818 1884 for (size_t i = 0; i < swapChainImageCount; i++) { 1819 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags, 1820 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 1821 buffers[i], buffersMemory[i]); 1885 VulkanUtils::createBuffer(device, physicalDevice, bufferSize, flags, properties, buffers[i], buffersMemory[i]); 1822 1886 1823 1887 bufferInfoList[i].buffer = buffers[i]; … … 2093 2157 // instead of recreated every time 2094 2158 2095 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2159 createBufferSet(sizeof(UBO_VP_mats), 2160 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2096 2161 uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline); 2097 2162 … … 2101 2166 modelPipeline.createDescriptorSets(swapChainImages); 2102 2167 2103 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2168 createBufferSet(sizeof(UBO_VP_mats), 2169 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2104 2170 uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); 2105 2171 … … 2109 2175 shipPipeline.createDescriptorSets(swapChainImages); 2110 2176 2111 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2177 createBufferSet(sizeof(UBO_VP_mats), 2178 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2112 2179 uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline); 2113 2180 … … 2117 2184 asteroidPipeline.createDescriptorSets(swapChainImages); 2118 2185 2119 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2186 createBufferSet(sizeof(UBO_VP_mats), 2187 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2120 2188 uniformBuffers_laserPipeline, uniformBuffersMemory_laserPipeline, uniformBufferInfoList_laserPipeline); 2121 2189 … … 2125 2193 laserPipeline.createDescriptorSets(swapChainImages); 2126 2194 2127 createBufferSet(sizeof(UBO_Explosion), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 2195 createBufferSet(sizeof(UBO_Explosion), 2196 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, 2128 2197 uniformBuffers_explosionPipeline, uniformBuffersMemory_explosionPipeline, uniformBufferInfoList_explosionPipeline); 2129 2198
Note:
See TracChangeset
for help on using the changeset viewer.