Changeset 860a0da in opengl-game for vulkan-game.cpp
- Timestamp:
- Feb 18, 2020, 9:36:51 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 2da64ef
- Parents:
- d25381b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rd25381b r860a0da 194 194 initGraphicsPipelines(); 195 195 196 overlayPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos)); 197 overlayPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&OverlayVertex::texCoord)); 198 199 overlayPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 200 VK_SHADER_STAGE_FRAGMENT_BIT, &sdlOverlayImageDescriptor); 201 202 addObject(overlayObjects, overlayPipeline, 203 { 204 {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}}, 205 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}}, 206 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}}, 207 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}} 208 }, { 209 0, 1, 2, 2, 3, 0 210 }, {}); 211 212 overlayPipeline.createDescriptorSetLayout(); 213 overlayPipeline.createPipeline("shaders/overlay-vert.spv", "shaders/overlay-frag.spv"); 214 overlayPipeline.createDescriptorPool(swapChainImages); 215 overlayPipeline.createDescriptorSets(swapChainImages); 216 196 217 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos)); 197 218 modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color)); … … 201 222 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 202 223 uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline); 203 // TODO: Calculate the size of this buffer (and all the other SSBOs) based on the number of objects204 createBufferSet(10 * sizeof(SSBO_ModelObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,205 storageBuffers_modelPipeline, storageBuffersMemory_modelPipeline, storageBufferInfoList_modelPipeline);206 224 207 225 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 208 226 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline); 209 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 210 VK_SHADER_STAGE_VERTEX_BIT, &storageBufferInfoList_modelPipeline); 227 modelPipeline.addStorageDescriptor(); 211 228 212 229 modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, … … 242 259 modelPipeline.createDescriptorSets(swapChainImages); 243 260 244 overlayPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&OverlayVertex::pos));245 overlayPipeline.addAttribute(VK_FORMAT_R32G32_SFLOAT, offset_of(&OverlayVertex::texCoord));246 247 overlayPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,248 VK_SHADER_STAGE_FRAGMENT_BIT, &sdlOverlayImageDescriptor);249 250 addObject(overlayObjects, overlayPipeline,251 {252 {{-1.0f, 1.0f, 0.0f}, {0.0f, 1.0f}},253 {{ 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},254 {{ 1.0f, -1.0f, 0.0f}, {1.0f, 0.0f}},255 {{-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f}}256 }, {257 0, 1, 2, 2, 3, 0258 }, {});259 260 overlayPipeline.createDescriptorSetLayout();261 overlayPipeline.createPipeline("shaders/overlay-vert.spv", "shaders/overlay-frag.spv");262 overlayPipeline.createDescriptorPool(swapChainImages);263 overlayPipeline.createDescriptorSets(swapChainImages);264 265 261 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos)); 266 262 shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color)); … … 270 266 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 271 267 uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); 272 createBufferSet(10 * sizeof(SSBO_ModelObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,273 storageBuffers_shipPipeline, storageBuffersMemory_shipPipeline, storageBufferInfoList_shipPipeline);274 268 275 269 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 276 270 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline); 277 shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 278 VK_SHADER_STAGE_VERTEX_BIT, &storageBufferInfoList_shipPipeline); 271 shipPipeline.addStorageDescriptor(); 279 272 280 273 // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly … … 526 519 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 527 520 uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline); 528 createBufferSet(10 * sizeof(SSBO_Asteroid), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,529 storageBuffers_asteroidPipeline, storageBuffersMemory_asteroidPipeline, storageBufferInfoList_asteroidPipeline);530 521 531 522 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 532 523 VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline); 533 asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 534 VK_SHADER_STAGE_VERTEX_BIT, &storageBufferInfoList_asteroidPipeline); 524 asteroidPipeline.addStorageDescriptor(); 535 525 536 526 addObject(asteroidObjects, asteroidPipeline, … … 631 621 void VulkanGame::initGraphicsPipelines() { 632 622 overlayPipeline = GraphicsPipeline_Vulkan<OverlayVertex, void*>(physicalDevice, device, renderPass, 633 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 4, 6);623 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 4, 6, 0); 634 624 635 625 modelPipeline = GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject>(physicalDevice, device, renderPass, 636 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 16, 24);626 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 16, 24, 10); 637 627 638 628 shipPipeline = GraphicsPipeline_Vulkan<ShipVertex, SSBO_ModelObject>(physicalDevice, device, renderPass, 639 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 138, 138);629 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 138, 138, 10); 640 630 641 631 asteroidPipeline = GraphicsPipeline_Vulkan<AsteroidVertex, SSBO_Asteroid>(physicalDevice, device, renderPass, 642 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, 24, 36);632 { 0, 0, (int)swapChainExtent.width, (int)swapChainExtent.height }, swapChainImages, 24, 36, 10); 643 633 } 644 634 … … 790 780 791 781 for (size_t i = 0; i < modelObjects.size(); i++) { 792 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_modelPipeline[currentImage],782 VulkanUtils::copyDataToMemory(device, modelPipeline.storageBufferSet.memory[currentImage], 793 783 i, so_Object); 794 784 } … … 796 786 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[currentImage], 0, ship_VP_mats); 797 787 798 VulkanUtils::copyDataToMemory(device, s torageBuffersMemory_shipPipeline[currentImage], 0, so_Ship);788 VulkanUtils::copyDataToMemory(device, shipPipeline.storageBufferSet.memory[currentImage], 0, so_Ship); 799 789 800 790 VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], 0, asteroid_VP_mats); 801 791 802 VulkanUtils::copyDataToMemory(device, storageBuffersMemory_asteroidPipeline[currentImage], 0, so_Asteroid);792 VulkanUtils::copyDataToMemory(device, asteroidPipeline.storageBufferSet.memory[currentImage], 0, so_Asteroid); 803 793 } 804 794 … … 1461 1451 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1462 1452 uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline); 1463 createBufferSet(10 * sizeof(SSBO_ModelObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,1464 storageBuffers_modelPipeline, storageBuffersMemory_modelPipeline, storageBufferInfoList_modelPipeline);1465 1453 1466 1454 modelPipeline.updateRenderPass(renderPass); … … 1476 1464 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1477 1465 uniformBuffers_shipPipeline, uniformBuffersMemory_shipPipeline, uniformBufferInfoList_shipPipeline); 1478 createBufferSet(10 * sizeof(SSBO_ModelObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,1479 storageBuffers_shipPipeline, storageBuffersMemory_shipPipeline, storageBufferInfoList_shipPipeline);1480 1466 1481 1467 shipPipeline.updateRenderPass(renderPass); … … 1486 1472 createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, 1487 1473 uniformBuffers_asteroidPipeline, uniformBuffersMemory_asteroidPipeline, uniformBufferInfoList_asteroidPipeline); 1488 createBufferSet(10 * sizeof(SSBO_Asteroid), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,1489 storageBuffers_asteroidPipeline, storageBuffersMemory_asteroidPipeline, storageBufferInfoList_asteroidPipeline);1490 1474 1491 1475 asteroidPipeline.updateRenderPass(renderPass); … … 1506 1490 vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data()); 1507 1491 1492 overlayPipeline.cleanup(); 1508 1493 modelPipeline.cleanup(); 1509 overlayPipeline.cleanup();1510 1494 shipPipeline.cleanup(); 1511 1495 asteroidPipeline.cleanup(); 1512 1513 vkDestroyRenderPass(device, renderPass, nullptr);1514 1515 for (VkImageView imageView : swapChainImageViews) {1516 vkDestroyImageView(device, imageView, nullptr);1517 }1518 1519 vkDestroySwapchainKHR(device, swapChain, nullptr);1520 1496 1521 1497 for (size_t i = 0; i < uniformBuffers_modelPipeline.size(); i++) { … … 1524 1500 } 1525 1501 1526 for (size_t i = 0; i < storageBuffers_modelPipeline.size(); i++) {1527 vkDestroyBuffer(device, storageBuffers_modelPipeline[i], nullptr);1528 vkFreeMemory(device, storageBuffersMemory_modelPipeline[i], nullptr);1529 }1530 1531 1502 for (size_t i = 0; i < uniformBuffers_shipPipeline.size(); i++) { 1532 1503 vkDestroyBuffer(device, uniformBuffers_shipPipeline[i], nullptr); … … 1534 1505 } 1535 1506 1536 for (size_t i = 0; i < storageBuffers_shipPipeline.size(); i++) {1537 vkDestroyBuffer(device, storageBuffers_shipPipeline[i], nullptr);1538 vkFreeMemory(device, storageBuffersMemory_shipPipeline[i], nullptr);1539 }1540 1541 1507 for (size_t i = 0; i < uniformBuffers_asteroidPipeline.size(); i++) { 1542 1508 vkDestroyBuffer(device, uniformBuffers_asteroidPipeline[i], nullptr); … … 1544 1510 } 1545 1511 1546 for (size_t i = 0; i < storageBuffers_asteroidPipeline.size(); i++) { 1547 vkDestroyBuffer(device, storageBuffers_asteroidPipeline[i], nullptr); 1548 vkFreeMemory(device, storageBuffersMemory_asteroidPipeline[i], nullptr); 1549 } 1550 } 1512 vkDestroyRenderPass(device, renderPass, nullptr); 1513 1514 for (VkImageView imageView : swapChainImageViews) { 1515 vkDestroyImageView(device, imageView, nullptr); 1516 } 1517 1518 vkDestroySwapchainKHR(device, swapChain, nullptr); 1519 }
Note:
See TracChangeset
for help on using the changeset viewer.