Changeset 860a0da in opengl-game


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

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • graphics-pipeline_vulkan.hpp

    rd25381b r860a0da  
    55
    66#include <fstream>
     7#include <iostream>
    78#include <stdexcept>
    89#include <vector>
     
    3132};
    3233
     34struct StorageBufferSet {
     35   vector<VkBuffer> buffers;
     36   vector<VkDeviceMemory> memory;
     37   vector<VkDescriptorBufferInfo> infoSet;
     38};
     39
    3340template<class VertexType, class SSBOType>
    3441class GraphicsPipeline_Vulkan : public GraphicsPipeline {
    3542   public:
    3643      GraphicsPipeline_Vulkan();
     44
     45      // TODO: swapChainImages is only ever used to get its size. Check how that is determined and,
     46      // if it will never change, just pass it in the constructor and save it
     47      // If it does change, I could add an updateSwapchainImageCount() function
    3748      GraphicsPipeline_Vulkan(VkPhysicalDevice physicalDevice, VkDevice device, VkRenderPass renderPass,
    38          Viewport viewport, size_t vertexCapacity, size_t indexCapacity);
     49         Viewport viewport, vector<VkImage>& swapChainImages,
     50         size_t vertexCapacity, size_t indexCapacity, size_t objectCapacity);
    3951      ~GraphicsPipeline_Vulkan();
    4052
     
    4658
    4759      void addAttribute(VkFormat format, size_t offset);
     60
     61      void addStorageDescriptor();
    4862
    4963      void addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData);
     
    6276      void cleanup();
    6377      void cleanupBuffers();
     78
     79      StorageBufferSet storageBufferSet;
    6480   
    6581   private:
     
    90106      VkDeviceMemory indexBufferMemory;
    91107
     108      size_t numObjects;
     109      size_t objectCapacity;
     110
    92111      VkShaderModule createShaderModule(const vector<char>& code);
    93112      vector<char> readFile(const string& filename);
     
    107126GraphicsPipeline_Vulkan<VertexType, SSBOType>::GraphicsPipeline_Vulkan(
    108127      VkPhysicalDevice physicalDevice, VkDevice device,
    109       VkRenderPass renderPass, Viewport viewport, size_t vertexCapacity, size_t indexCapacity) {
     128      VkRenderPass renderPass, Viewport viewport, vector<VkImage>& swapChainImages,
     129      size_t vertexCapacity, size_t indexCapacity, size_t objectCapacity) {
    110130   this->physicalDevice = physicalDevice;
    111131   this->device = device;
     
    133153      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
    134154      VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, indexBuffer, indexBufferMemory);
    135 }
    136 
     155
     156   this->numObjects = 0;
     157   this->objectCapacity = objectCapacity;
     158
     159   // Hacky way to allow an SSBO to be optional
     160   // Specifying void* as the SSBOType will skip allocating the related buffers
     161   if (!is_same_v<SSBOType, void*>) {
     162      VkDeviceSize bufferSize = objectCapacity * sizeof(SSBOType);
     163      cout << "NUM SWAP CHAIN IMAGES: " << swapChainImages.size() << endl;
     164
     165      storageBufferSet.buffers.resize(swapChainImages.size());
     166      storageBufferSet.memory.resize(swapChainImages.size());
     167      storageBufferSet.infoSet.resize(swapChainImages.size());
     168
     169      for (size_t i = 0; i < swapChainImages.size(); i++) {
     170         VulkanUtils::createBuffer(this->device, this->physicalDevice, bufferSize,
     171            VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
     172            VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     173            storageBufferSet.buffers[i], storageBufferSet.memory[i]);
     174
     175         storageBufferSet.infoSet[i].buffer = storageBufferSet.buffers[i];
     176         storageBufferSet.infoSet[i].offset = 0; // This is the offset from the start of the buffer, so always 0 for now
     177         storageBufferSet.infoSet[i].range = bufferSize; // Size of the update starting from offset, or VK_WHOLE_SIZE
     178      }
     179   }
     180}
     181
     182// TODO: Move as much cleanup as I can into the destructor
    137183template<class VertexType, class SSBOType>
    138184GraphicsPipeline_Vulkan<VertexType, SSBOType>::~GraphicsPipeline_Vulkan() {
     
    162208
    163209template<class VertexType, class SSBOType>
    164 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData) {
     210void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addStorageDescriptor() {
     211   if (!is_same_v<SSBOType, void*>) {
     212      addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
     213         VK_SHADER_STAGE_VERTEX_BIT, &storageBufferSet.infoSet);
     214   }
     215}
     216
     217template<class VertexType, class SSBOType>
     218void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addDescriptorInfo(VkDescriptorType type,
     219      VkShaderStageFlags stageFlags, vector<VkDescriptorBufferInfo>* bufferData) {
    165220   this->descriptorInfoList.push_back({ type, stageFlags, bufferData, nullptr });
    166221}
    167222
    168223template<class VertexType, class SSBOType>
    169 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addDescriptorInfo(VkDescriptorType type, VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData) {
     224void GraphicsPipeline_Vulkan<VertexType, SSBOType>::addDescriptorInfo(VkDescriptorType type,
     225      VkShaderStageFlags stageFlags, VkDescriptorImageInfo* imageData) {
    170226   this->descriptorInfoList.push_back({ type, stageFlags, nullptr, imageData });
    171227}
     
    351407}
    352408
     409// TODO: Since I only need the size of the swapChainImages array, I should just pass that in instead of the whole array
    353410template<class VertexType, class SSBOType>
    354411void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createDescriptorSets(vector<VkImage>& swapChainImages) {
     
    398455
    399456template<class VertexType, class SSBOType>
    400 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createRenderCommands(VkCommandBuffer& commandBuffer, uint32_t currentImage) {
     457void GraphicsPipeline_Vulkan<VertexType, SSBOType>::createRenderCommands(VkCommandBuffer& commandBuffer,
     458      uint32_t currentImage) {
    401459   vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);
    402460   vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1,
     
    436494   vkDestroyPipeline(device, pipeline, nullptr);
    437495   vkDestroyDescriptorPool(device, descriptorPool, nullptr);
     496
     497   // TODO: I read that the pipeline layout does not have to be recreated every time
     498   // Try only creating it once
    438499   vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
    439500}
     
    447508   vkDestroyBuffer(device, indexBuffer, nullptr);
    448509   vkFreeMemory(device, indexBufferMemory, nullptr);
     510
     511   if (!is_same_v<SSBOType, void*>) {
     512      for (size_t i = 0; i < storageBufferSet.buffers.size(); i++) {
     513         vkDestroyBuffer(device, storageBufferSet.buffers[i], nullptr);
     514         vkFreeMemory(device, storageBufferSet.memory[i], nullptr);
     515      }
     516   }
    449517}
    450518
     
    486554
    487555template<class VertexType, class SSBOType>
    488 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeVertexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue) {
     556void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeVertexBuffer(VkCommandPool commandPool,
     557      VkQueue graphicsQueue) {
    489558   VkBuffer newVertexBuffer;
    490559   VkDeviceMemory newVertexBufferMemory;
    491    vertexCapacity *= 2;
    492 
    493    VulkanUtils::createBuffer(device, physicalDevice, vertexCapacity * sizeof(VertexType),
     560   this->vertexCapacity *= 2;
     561
     562   VulkanUtils::createBuffer(this->device, this->physicalDevice, this->vertexCapacity * sizeof(VertexType),
    494563      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,
    495564      VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, newVertexBuffer, newVertexBufferMemory);
    496565
    497    VulkanUtils::copyBuffer(device, commandPool, vertexBuffer, newVertexBuffer, 0, 0, numVertices * sizeof(VertexType), graphicsQueue);
    498 
    499    vkDestroyBuffer(device, vertexBuffer, nullptr);
    500    vkFreeMemory(device, vertexBufferMemory, nullptr);
     566   VulkanUtils::copyBuffer(this->device, commandPool, vertexBuffer, newVertexBuffer, 0, 0, numVertices * sizeof(VertexType), graphicsQueue);
     567
     568   vkDestroyBuffer(this->device, vertexBuffer, nullptr);
     569   vkFreeMemory(this->device, vertexBufferMemory, nullptr);
    501570
    502571   vertexBuffer = newVertexBuffer;
     
    505574
    506575template<class VertexType, class SSBOType>
    507 void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeIndexBuffer(VkCommandPool commandPool, VkQueue graphicsQueue) {
     576void GraphicsPipeline_Vulkan<VertexType, SSBOType>::resizeIndexBuffer(VkCommandPool commandPool,
     577      VkQueue graphicsQueue) {
    508578   VkBuffer newIndexBuffer;
    509579   VkDeviceMemory newIndexBufferMemory;
    510    indexCapacity *= 2;
    511 
    512    VulkanUtils::createBuffer(device, physicalDevice, indexCapacity * sizeof(uint16_t),
     580   this->indexCapacity *= 2;
     581
     582   VulkanUtils::createBuffer(this->device, this->physicalDevice, this->indexCapacity * sizeof(uint16_t),
    513583      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT,
    514584      VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, newIndexBuffer, newIndexBufferMemory);
    515585
    516    VulkanUtils::copyBuffer(device, commandPool, indexBuffer, newIndexBuffer, 0, 0, numIndices * sizeof(uint16_t), graphicsQueue);
    517 
    518    vkDestroyBuffer(device, indexBuffer, nullptr);
    519    vkFreeMemory(device, indexBufferMemory, nullptr);
     586   VulkanUtils::copyBuffer(this->device, commandPool, indexBuffer, newIndexBuffer, 0, 0, numIndices * sizeof(uint16_t), graphicsQueue);
     587
     588   vkDestroyBuffer(this->device, indexBuffer, nullptr);
     589   vkFreeMemory(this->device, indexBufferMemory, nullptr);
    520590
    521591   indexBuffer = newIndexBuffer;
  • 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}
  • vulkan-game.hpp

    rd25381b r860a0da  
    142142      bool framebufferResized;
    143143
    144       // TODO: I should probably rename the uniformBuffer* and storageBuffer*
    145       // variables to better reflect the data they hold
    146 
    147       // TODO: Create a struct that holds the buffers, memory, and info objects (Probably in VulkanUtils)
    148 
    149144      GraphicsPipeline_Vulkan<OverlayVertex, void*> overlayPipeline;
    150145      vector<SceneObject<OverlayVertex, void*>> overlayObjects;
     146
     147      // TODO: Maybe make the ubo objects part of the pipeline class since there's only one ubo
     148      // per pipeline.
     149      // Or maybe create a higher level wrapper around GraphicsPipeline_Vulkan to hold things like
     150      // the objects vector, the ubo, and the ssbo
    151151
    152152      GraphicsPipeline_Vulkan<ModelVertex, SSBO_ModelObject> modelPipeline;
     
    157157      vector<VkDescriptorBufferInfo> uniformBufferInfoList_modelPipeline;
    158158
    159       vector<VkBuffer> storageBuffers_modelPipeline;
    160       vector<VkDeviceMemory> storageBuffersMemory_modelPipeline;
    161       vector<VkDescriptorBufferInfo> storageBufferInfoList_modelPipeline;
    162 
    163159      UBO_VP_mats object_VP_mats;
    164160      SSBO_ModelObject so_Object;
     
    171167      vector<VkDescriptorBufferInfo> uniformBufferInfoList_shipPipeline;
    172168
    173       vector<VkBuffer> storageBuffers_shipPipeline;
    174       vector<VkDeviceMemory> storageBuffersMemory_shipPipeline;
    175       vector<VkDescriptorBufferInfo> storageBufferInfoList_shipPipeline;
    176 
    177169      UBO_VP_mats ship_VP_mats;
    178170      SSBO_ModelObject so_Ship;
     
    184176      vector<VkDeviceMemory> uniformBuffersMemory_asteroidPipeline;
    185177      vector<VkDescriptorBufferInfo> uniformBufferInfoList_asteroidPipeline;
    186 
    187       vector<VkBuffer> storageBuffers_asteroidPipeline;
    188       vector<VkDeviceMemory> storageBuffersMemory_asteroidPipeline;
    189       vector<VkDescriptorBufferInfo> storageBufferInfoList_asteroidPipeline;
    190178
    191179      UBO_VP_mats asteroid_VP_mats;
Note: See TracChangeset for help on using the changeset viewer.