Changeset 996dd3e in opengl-game for vulkan-game.cpp


Ignore:
Timestamp:
May 14, 2021, 1:09:34 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
a3cefaa
Parents:
9d21aac
Message:

Completely remove storage buffers from the GraphicsPipeline_Vulkan class and start moving storage buffer operations out of the addObject() and updateObject() functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-game.cpp

    r9d21aac r996dd3e  
    126126      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline);
    127127   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);
    129129   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    130130      VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
     
    145145         }, {
    146146            mat4(1.0f)
    147          }, false);
     147         }, storageBuffers_modelPipeline, false);
     148
     149   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
    148150
    149151   texturedSquare->model_base =
     
    164166         }, {
    165167            mat4(1.0f)
    166          }, false);
     168         }, storageBuffers_modelPipeline, false);
     169
     170   updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare->ssbo);
    167171
    168172   texturedSquare->model_base =
     
    189193      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline);
    190194   shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
    191       VK_SHADER_STAGE_VERTEX_BIT, &shipPipeline.storageBufferSet.infoSet);
     195      VK_SHADER_STAGE_VERTEX_BIT, &storageBuffers_shipPipeline.infoSet);
    192196
    193197   // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
     
    424428      }, {
    425429         mat4(1.0f)
    426       }, false);
     430      }, storageBuffers_shipPipeline, false);
     431
     432   updateStorageBuffer(storageBuffers_shipPipeline, shipPipeline.numObjects - 1, ship.ssbo);
    427433
    428434   ship.model_base =
     
    449455      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline);
    450456   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);
    452458
    453459   asteroidPipeline.createDescriptorSetLayout();
     
    467473      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_laserPipeline);
    468474   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);
    470476   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
    471477      VK_SHADER_STAGE_FRAGMENT_BIT, &laserTextureImageDescriptor);
     
    487493      VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_explosionPipeline);
    488494   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);
    490496
    491497   explosionPipeline.createDescriptorSetLayout();
     
    599605      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    600606      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);
    603609
    604610   shipPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
     
    609615      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    610616      VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
    611       shipPipeline.storageBufferSet.buffers, shipPipeline.storageBufferSet.memory,
    612       shipPipeline.storageBufferSet.infoSet);
     617      storageBuffers_shipPipeline.buffers, storageBuffers_shipPipeline.memory,
     618      storageBuffers_shipPipeline.infoSet);
    613619
    614620   asteroidPipeline = GraphicsPipeline_Vulkan<ModelVertex>(
     
    619625      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    620626      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);
    623629
    624630   laserPipeline = GraphicsPipeline_Vulkan<LaserVertex>(
     
    629635      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    630636      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);
    633639
    634640   explosionPipeline = GraphicsPipeline_Vulkan<ExplosionVertex>(
     
    640646      VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    641647      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);
    644650}
    645651
     
    762768                           }, {
    763769                              mat4(1.0f)
    764                            }, true);
     770                           }, storageBuffers_modelPipeline, true);
     771
     772                  updateStorageBuffer(storageBuffers_modelPipeline, modelPipeline.numObjects - 1, texturedSquare.ssbo);
    765773
    766774                  texturedSquare.model_base =
     
    10421050                  10.0f,
    10431051                  false
    1044                }, true);
     1052               }, storageBuffers_asteroidPipeline, true);
     1053
     1054      updateStorageBuffer(storageBuffers_asteroidPipeline, asteroidPipeline.numObjects - 1, asteroid.ssbo);
    10451055
    10461056      // This accounts for the scaling in model_base.
     
    10701080      if (shipObjects[i].modified) {
    10711081         updateObject(shipObjects, shipPipeline, i);
     1082         updateStorageBuffer(storageBuffers_shipPipeline, i, shipObjects[i].ssbo);
    10721083      }
    10731084   }
     
    10761087      if (modelObjects[i].modified) {
    10771088         updateObject(modelObjects, modelPipeline, i);
     1089         updateStorageBuffer(storageBuffers_modelPipeline, i, modelObjects[i].ssbo);
    10781090      }
    10791091   }
     
    10821094      if (asteroidObjects[i].modified) {
    10831095         updateObject(asteroidObjects, asteroidPipeline, i);
     1096         updateStorageBuffer(storageBuffers_asteroidPipeline, i, asteroidObjects[i].ssbo);
    10841097      }
    10851098   }
     
    10881101      if (laserObjects[i].modified) {
    10891102         updateObject(laserObjects, laserPipeline, i);
     1103         updateStorageBuffer(storageBuffers_laserPipeline, i, laserObjects[i].ssbo);
    10901104      }
    10911105   }
     
    10941108      if (explosionObjects[i].modified) {
    10951109         updateObject(explosionObjects, explosionPipeline, i);
     1110         updateStorageBuffer(storageBuffers_explosionPipeline, i, explosionObjects[i].ssbo);
    10961111      }
    10971112   }
     
    11311146   explosionPipeline.cleanupBuffers();
    11321147
    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);
     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);
    11561171   }
    11571172
     
    19141929         color,
    19151930         false
    1916       }, true);
     1931      }, storageBuffers_laserPipeline, true);
     1932
     1933   updateStorageBuffer(storageBuffers_laserPipeline, laserPipeline.numObjects - 1, laser.ssbo);
    19171934
    19181935   float xAxisRotation = asin(ray.y / length);
     
    21242141         duration,
    21252142         false
    2126       }, true);
     2143      }, storageBuffers_explosionPipeline, true);
     2144
     2145   updateStorageBuffer(storageBuffers_explosionPipeline, explosionPipeline.numObjects - 1, explosion.ssbo);
    21272146
    21282147   explosion.model_base = model_mat;
Note: See TracChangeset for help on using the changeset viewer.