Changeset 860a0da in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
Feb 18, 2020, 9:36:51 PM (5 years ago)
Author:
Dmitry Portnoy <dmitry.portnoy@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
2da64ef
Parents:
d25381b
Message:

In VulkanGame, move fields related to the ssbo, as well as code to create thee ssbo, destroy it, and create a descriptor for it, into GraphicsPipeline_Vulkan

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    rd25381b r860a0da  
    194194   initGraphicsPipelines();
    195195
     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
    196217   modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::pos));
    197218   modelPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ModelVertex::color));
     
    201222   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    202223      uniformBuffers_modelPipeline, uniformBuffersMemory_modelPipeline, uniformBufferInfoList_modelPipeline);
    203    // TODO: Calculate the size of this buffer (and all the other SSBOs) based on the number of objects
    204    createBufferSet(10 * sizeof(SSBO_ModelObject), VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    205       storageBuffers_modelPipeline, storageBuffersMemory_modelPipeline, storageBufferInfoList_modelPipeline);
    206224
    207225   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    208226      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();
    211228
    212229   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
     
    242259   modelPipeline.createDescriptorSets(swapChainImages);
    243260
    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, 0
    258       }, {});
    259 
    260    overlayPipeline.createDescriptorSetLayout();
    261    overlayPipeline.createPipeline("shaders/overlay-vert.spv", "shaders/overlay-frag.spv");
    262    overlayPipeline.createDescriptorPool(swapChainImages);
    263    overlayPipeline.createDescriptorSets(swapChainImages);
    264 
    265261   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::pos));
    266262   shipPipeline.addAttribute(VK_FORMAT_R32G32B32_SFLOAT, offset_of(&ShipVertex::color));
     
    270266   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    271267      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);
    274268
    275269   shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    276270      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();
    279272
    280273   // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
     
    526519   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    527520      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);
    530521
    531522   asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
    532523      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();
    535525
    536526   addObject(asteroidObjects, asteroidPipeline,
     
    631621void VulkanGame::initGraphicsPipelines() {
    632622   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);
    634624
    635625   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);
    637627
    638628   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);
    640630
    641631   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);
    643633}
    644634
     
    790780
    791781   for (size_t i = 0; i < modelObjects.size(); i++) {
    792       VulkanUtils::copyDataToMemory(device, storageBuffersMemory_modelPipeline[currentImage],
     782      VulkanUtils::copyDataToMemory(device, modelPipeline.storageBufferSet.memory[currentImage],
    793783         i, so_Object);
    794784   }
     
    796786   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_shipPipeline[currentImage], 0, ship_VP_mats);
    797787
    798    VulkanUtils::copyDataToMemory(device, storageBuffersMemory_shipPipeline[currentImage], 0, so_Ship);
     788   VulkanUtils::copyDataToMemory(device, shipPipeline.storageBufferSet.memory[currentImage], 0, so_Ship);
    799789
    800790   VulkanUtils::copyDataToMemory(device, uniformBuffersMemory_asteroidPipeline[currentImage], 0, asteroid_VP_mats);
    801791
    802    VulkanUtils::copyDataToMemory(device, storageBuffersMemory_asteroidPipeline[currentImage], 0, so_Asteroid);
     792   VulkanUtils::copyDataToMemory(device, asteroidPipeline.storageBufferSet.memory[currentImage], 0, so_Asteroid);
    803793}
    804794
     
    14611451   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    14621452      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);
    14651453
    14661454   modelPipeline.updateRenderPass(renderPass);
     
    14761464   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    14771465      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);
    14801466
    14811467   shipPipeline.updateRenderPass(renderPass);
     
    14861472   createBufferSet(sizeof(UBO_VP_mats), VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    14871473      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);
    14901474
    14911475   asteroidPipeline.updateRenderPass(renderPass);
     
    15061490   vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data());
    15071491
     1492   overlayPipeline.cleanup();
    15081493   modelPipeline.cleanup();
    1509    overlayPipeline.cleanup();
    15101494   shipPipeline.cleanup();
    15111495   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);
    15201496
    15211497   for (size_t i = 0; i < uniformBuffers_modelPipeline.size(); i++) {
     
    15241500   }
    15251501
    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 
    15311502   for (size_t i = 0; i < uniformBuffers_shipPipeline.size(); i++) {
    15321503      vkDestroyBuffer(device, uniformBuffers_shipPipeline[i], nullptr);
     
    15341505   }
    15351506
    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 
    15411507   for (size_t i = 0; i < uniformBuffers_asteroidPipeline.size(); i++) {
    15421508      vkDestroyBuffer(device, uniformBuffers_asteroidPipeline[i], nullptr);
     
    15441510   }
    15451511
    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.