Changeset 2f4ff8c in opengl-game


Ignore:
Timestamp:
Jun 20, 2021, 7:05:14 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
b01b50c
Parents:
90880fb
git-author:
Dmitry Portnoy <dportnoy@…> (06/18/21 16:39:49)
git-committer:
Dmitry Portnoy <dportnoy@…> (06/20/21 19:05:14)
Message:

Change the uniform buffers to always be mapped instead of mapping them every time data needs to be copied

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r90880fb r2f4ff8c  
    7070                     , gui(nullptr)
    7171                     , window(nullptr)
    72                      , vp_mats_modelPipeline()
     72                     , uniforms_modelPipeline()
    7373                     , objects_modelPipeline()
    7474                     , score(0)
     
    9393   vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
    9494
    95    vp_mats_modelPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
    96                                                      deviceProperties.limits.minUniformBufferOffsetAlignment);
     95   uniforms_modelPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
     96                                                      deviceProperties.limits.minUniformBufferOffsetAlignment);
    9797
    9898   objects_modelPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange,
     
    114114   modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
    115115
    116    createBufferSet(vp_mats_modelPipeline.memorySize(),
     116   createBufferSet(uniforms_modelPipeline.memorySize(),
    117117                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    118                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     118                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    119119                   uniformBuffers_modelPipeline);
     120
     121   uniforms_modelPipeline.map(uniformBuffers_modelPipeline.memory, device);
    120122
    121123   createBufferSet(objects_modelPipeline.memorySize(),
    122124                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    123125                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    124                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     126                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    125127                   storageBuffers_modelPipeline);
     128
     129   objects_modelPipeline.map(storageBuffers_modelPipeline.memory, device);
    126130
    127131   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     
    445449
    446450void VulkanGame::updateScene() {
    447    vp_mats_modelPipeline.data()->view = viewMat;
    448    vp_mats_modelPipeline.data()->proj = projMat;
     451   uniforms_modelPipeline.data()->view = viewMat;
     452   uniforms_modelPipeline.data()->proj = projMat;
    449453
    450454   // TODO: Probably move the resizing to the VulkanBuffer class's add() method
     
    453457
    454458   if (objects_modelPipeline.resized) {
     459      objects_modelPipeline.unmap(storageBuffers_modelPipeline.memory, device);
     460
    455461      resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline.memorySize(), resourceCommandPool,
    456462                      graphicsQueue, true);
     463
     464      objects_modelPipeline.map(storageBuffers_modelPipeline.memory, device);
    457465
    458466      objects_modelPipeline.resize();
     
    474482   }
    475483
    476    VulkanUtils::copyDataToMemory(device, vp_mats_modelPipeline.data(), uniformBuffers_modelPipeline.memory[imageIndex],
    477                                  0, vp_mats_modelPipeline.memorySize(), false);
    478 
    479    VulkanUtils::copyDataToMemory(device, objects_modelPipeline.data(), storageBuffers_modelPipeline.memory[imageIndex],
    480                                  0, objects_modelPipeline.memorySize(), false);
     484   VulkanUtils::copyDataToMappedMemory(device, uniforms_modelPipeline.data(), uniforms_modelPipeline.mapped(imageIndex),
     485                                       uniformBuffers_modelPipeline.memory[imageIndex],
     486                                       uniforms_modelPipeline.memorySize(), true);
     487
     488   VulkanUtils::copyDataToMappedMemory(device, objects_modelPipeline.data(), objects_modelPipeline.mapped(imageIndex),
     489                                       storageBuffers_modelPipeline.memory[imageIndex],
     490                                       objects_modelPipeline.memorySize(), true);
    481491}
    482492
     
    12821292   createSyncObjects();
    12831293
    1284    createBufferSet(vp_mats_modelPipeline.memorySize(),
     1294   createBufferSet(uniforms_modelPipeline.memorySize(),
    12851295                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    1286                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     1296                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    12871297                   uniformBuffers_modelPipeline);
     1298
     1299   uniforms_modelPipeline.map(uniformBuffers_modelPipeline.memory, device);
    12881300
    12891301   createBufferSet(objects_modelPipeline.memorySize(),
    12901302                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    12911303                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    1292                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     1304                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    12931305                   storageBuffers_modelPipeline);
     1306
     1307   objects_modelPipeline.map(storageBuffers_modelPipeline.memory, device);
    12941308
    12951309   modelPipeline.updateRenderPass(renderPass);
     
    13151329   modelPipeline.cleanup();
    13161330
     1331   uniforms_modelPipeline.unmap(uniformBuffers_modelPipeline.memory, device);
     1332
    13171333   for (size_t i = 0; i < uniformBuffers_modelPipeline.buffers.size(); i++) {
    13181334      vkDestroyBuffer(device, uniformBuffers_modelPipeline.buffers[i], nullptr);
    13191335      vkFreeMemory(device, uniformBuffers_modelPipeline.memory[i], nullptr);
    13201336   }
     1337
     1338   objects_modelPipeline.unmap(storageBuffers_modelPipeline.memory, device);
    13211339
    13221340   for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {
  • sdl-game.hpp

    r90880fb r2f4ff8c  
    228228      BufferSet storageBuffers_modelPipeline;
    229229
    230       VulkanBuffer<UBO_VP_mats> vp_mats_modelPipeline;
     230      VulkanBuffer<UBO_VP_mats> uniforms_modelPipeline;
    231231      VulkanBuffer<SSBO_ModelObject> objects_modelPipeline;
    232232
  • vulkan-game.cpp

    r90880fb r2f4ff8c  
    7777                     , gui(nullptr)
    7878                     , window(nullptr)
    79                      , vp_mats_modelPipeline()
     79                     , uniforms_modelPipeline()
    8080                     , objects_modelPipeline()
    81                      , vp_mats_shipPipeline()
     81                     , uniforms_shipPipeline()
    8282                     , objects_shipPipeline()
    83                      , vp_mats_asteroidPipeline()
     83                     , uniforms_asteroidPipeline()
    8484                     , objects_asteroidPipeline()
    85                      , vp_mats_laserPipeline()
     85                     , uniforms_laserPipeline()
    8686                     , objects_laserPipeline()
    8787                     , uniforms_explosionPipeline()
     
    110110   vkGetPhysicalDeviceProperties(physicalDevice, &deviceProperties);
    111111
    112    vp_mats_modelPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
    113                                                      deviceProperties.limits.minUniformBufferOffsetAlignment);
     112   uniforms_modelPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
     113                                                      deviceProperties.limits.minUniformBufferOffsetAlignment);
    114114
    115115   objects_modelPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange,
    116116                                                          deviceProperties.limits.minStorageBufferOffsetAlignment);
    117117
    118    vp_mats_shipPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
    119                                                     deviceProperties.limits.minUniformBufferOffsetAlignment);
     118   uniforms_shipPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
     119                                                     deviceProperties.limits.minUniformBufferOffsetAlignment);
    120120
    121121   objects_shipPipeline = VulkanBuffer<SSBO_ModelObject>(10, deviceProperties.limits.maxStorageBufferRange,
    122122                                                         deviceProperties.limits.minStorageBufferOffsetAlignment);
    123123
    124    vp_mats_asteroidPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
    125                                                         deviceProperties.limits.minUniformBufferOffsetAlignment);
     124   uniforms_asteroidPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
     125                                                         deviceProperties.limits.minUniformBufferOffsetAlignment);
    126126
    127127   objects_asteroidPipeline = VulkanBuffer<SSBO_Asteroid>(10, deviceProperties.limits.maxStorageBufferRange,
    128128                                                          deviceProperties.limits.minStorageBufferOffsetAlignment);
    129129
    130    vp_mats_laserPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
    131                                                      deviceProperties.limits.minUniformBufferOffsetAlignment);
     130   uniforms_laserPipeline = VulkanBuffer<UBO_VP_mats>(1, deviceProperties.limits.maxUniformBufferRange,
     131                                                      deviceProperties.limits.minUniformBufferOffsetAlignment);
    132132
    133133   objects_laserPipeline = VulkanBuffer<SSBO_Laser>(2, deviceProperties.limits.maxStorageBufferRange,
     
    157157   modelPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
    158158
    159    createBufferSet(vp_mats_modelPipeline.memorySize(),
     159   createBufferSet(uniforms_modelPipeline.memorySize(),
    160160                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    161                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     161                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    162162                   uniformBuffers_modelPipeline);
     163
     164   uniforms_modelPipeline.map(uniformBuffers_modelPipeline.memory, device);
    163165
    164166   createBufferSet(objects_modelPipeline.memorySize(),
    165167                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    166168                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    167                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     169                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    168170                   storageBuffers_modelPipeline);
     171
     172   objects_modelPipeline.map(storageBuffers_modelPipeline.memory, device);
    169173
    170174   modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     
    227231   shipPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
    228232
    229    createBufferSet(vp_mats_shipPipeline.memorySize(),
     233   createBufferSet(uniforms_shipPipeline.memorySize(),
    230234                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    231                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     235                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    232236                   uniformBuffers_shipPipeline);
     237
     238   uniforms_shipPipeline.map(uniformBuffers_shipPipeline.memory, device);
    233239
    234240   createBufferSet(objects_shipPipeline.memorySize(),
    235241                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    236242                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    237                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     243                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    238244                   storageBuffers_shipPipeline);
     245
     246   objects_shipPipeline.map(storageBuffers_shipPipeline.memory, device);
    239247
    240248   shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     
    494502   asteroidPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&ModelVertex::objIndex));
    495503
    496    createBufferSet(vp_mats_asteroidPipeline.memorySize(),
     504   createBufferSet(uniforms_asteroidPipeline.memorySize(),
    497505                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    498                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     506                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    499507                   uniformBuffers_asteroidPipeline);
     508
     509   uniforms_asteroidPipeline.map(uniformBuffers_asteroidPipeline.memory, device);
    500510
    501511   createBufferSet(objects_asteroidPipeline.memorySize(),
    502512                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    503513                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    504                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     514                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    505515                   storageBuffers_asteroidPipeline);
     516
     517   objects_asteroidPipeline.map(storageBuffers_asteroidPipeline.memory, device);
    506518
    507519   asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     
    519531   laserPipeline.addAttribute(VK_FORMAT_R32_UINT, offset_of(&LaserVertex::objIndex));
    520532
    521    createBufferSet(vp_mats_laserPipeline.memorySize(),
     533   createBufferSet(uniforms_laserPipeline.memorySize(),
    522534                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    523                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     535                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    524536                   uniformBuffers_laserPipeline);
     537
     538   uniforms_laserPipeline.map(uniformBuffers_laserPipeline.memory, device);
    525539
    526540   createBufferSet(objects_laserPipeline.memorySize(),
    527541                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    528542                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    529                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     543                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    530544                   storageBuffers_laserPipeline);
     545
     546   objects_laserPipeline.map(storageBuffers_laserPipeline.memory, device);
    531547
    532548   laserPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     
    548564   createBufferSet(uniforms_explosionPipeline.memorySize(),
    549565                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    550                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     566                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    551567                   uniformBuffers_explosionPipeline);
     568
     569   uniforms_explosionPipeline.map(uniformBuffers_explosionPipeline.memory, device);
    552570
    553571   createBufferSet(objects_explosionPipeline.memorySize(),
    554572                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    555573                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    556                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     574                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    557575                   storageBuffers_explosionPipeline);
     576
     577   objects_explosionPipeline.map(storageBuffers_explosionPipeline.memory, device);
    558578
    559579   explosionPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
     
    945965void VulkanGame::updateScene() {
    946966
    947    vp_mats_modelPipeline.data()->view = viewMat;
    948    vp_mats_modelPipeline.data()->proj = projMat;
    949 
    950    vp_mats_shipPipeline.data()->view = viewMat;
    951    vp_mats_shipPipeline.data()->proj = projMat;
    952 
    953    vp_mats_asteroidPipeline.data()->view = viewMat;
    954    vp_mats_asteroidPipeline.data()->proj = projMat;
    955 
    956    vp_mats_laserPipeline.data()->view = viewMat;
    957    vp_mats_laserPipeline.data()->proj = projMat;
     967   // TODO: I can probably use one buffer to store the view and projection mats
     968   // and share it across all the shader pipelines
     969
     970   uniforms_modelPipeline.data()->view = viewMat;
     971   uniforms_modelPipeline.data()->proj = projMat;
     972
     973   uniforms_shipPipeline.data()->view = viewMat;
     974   uniforms_shipPipeline.data()->proj = projMat;
     975
     976   uniforms_asteroidPipeline.data()->view = viewMat;
     977   uniforms_asteroidPipeline.data()->proj = projMat;
     978
     979   uniforms_laserPipeline.data()->view = viewMat;
     980   uniforms_laserPipeline.data()->proj = projMat;
    958981
    959982   uniforms_explosionPipeline.data()->view = viewMat;
     
    10591082
    10601083   if (objects_modelPipeline.resized) {
     1084      objects_modelPipeline.unmap(storageBuffers_modelPipeline.memory, device);
     1085
    10611086      resizeBufferSet(storageBuffers_modelPipeline, objects_modelPipeline.memorySize(), resourceCommandPool,
    10621087                      graphicsQueue, true);
     1088
     1089      objects_modelPipeline.map(storageBuffers_modelPipeline.memory, device);
    10631090
    10641091      objects_modelPipeline.resize();
     
    10801107   }
    10811108
    1082    VulkanUtils::copyDataToMemory(device, vp_mats_modelPipeline.data(), uniformBuffers_modelPipeline.memory[imageIndex],
    1083                                  0, vp_mats_modelPipeline.memorySize(), false);
    1084 
    1085    VulkanUtils::copyDataToMemory(device, objects_modelPipeline.data(), storageBuffers_modelPipeline.memory[imageIndex],
    1086                                  0, objects_modelPipeline.memorySize(), false);
     1109   VulkanUtils::copyDataToMappedMemory(device, uniforms_modelPipeline.data(), uniforms_modelPipeline.mapped(imageIndex),
     1110                                       uniformBuffers_modelPipeline.memory[imageIndex],
     1111                                       uniforms_modelPipeline.memorySize(), true);
     1112
     1113   VulkanUtils::copyDataToMappedMemory(device, objects_modelPipeline.data(), objects_modelPipeline.mapped(imageIndex),
     1114                                       storageBuffers_modelPipeline.memory[imageIndex],
     1115                                       objects_modelPipeline.memorySize(), true);
    10871116
    10881117   if (objects_shipPipeline.resized) {
     1118      objects_shipPipeline.unmap(storageBuffers_shipPipeline.memory, device);
     1119
    10891120      resizeBufferSet(storageBuffers_shipPipeline, objects_shipPipeline.memorySize(), resourceCommandPool,
    10901121                      graphicsQueue, true);
     1122
     1123      objects_shipPipeline.map(storageBuffers_shipPipeline.memory, device);
    10911124
    10921125      objects_shipPipeline.resize();
     
    11041137   }
    11051138
    1106    VulkanUtils::copyDataToMemory(device, vp_mats_shipPipeline.data(), uniformBuffers_shipPipeline.memory[imageIndex],
    1107                                  0, vp_mats_shipPipeline.memorySize(), false);
    1108 
    1109    VulkanUtils::copyDataToMemory(device, objects_shipPipeline.data(), storageBuffers_shipPipeline.memory[imageIndex],
    1110                                  0, objects_shipPipeline.memorySize(), false);
     1139   VulkanUtils::copyDataToMappedMemory(device, uniforms_shipPipeline.data(), uniforms_shipPipeline.mapped(imageIndex),
     1140                                       uniformBuffers_shipPipeline.memory[imageIndex],
     1141                                       uniforms_shipPipeline.memorySize(), true);
     1142
     1143   VulkanUtils::copyDataToMappedMemory(device, objects_shipPipeline.data(), objects_shipPipeline.mapped(imageIndex),
     1144                                       storageBuffers_shipPipeline.memory[imageIndex],
     1145                                       objects_shipPipeline.memorySize(), true);
    11111146
    11121147   if (objects_asteroidPipeline.resized) {
     1148      objects_asteroidPipeline.unmap(storageBuffers_asteroidPipeline.memory, device);
     1149
    11131150      resizeBufferSet(storageBuffers_asteroidPipeline, objects_asteroidPipeline.memorySize(), resourceCommandPool,
    11141151                      graphicsQueue, true);
     1152
     1153      objects_asteroidPipeline.map(storageBuffers_asteroidPipeline.memory, device);
    11151154
    11161155      objects_asteroidPipeline.resize();
     
    11511190   }
    11521191
    1153    VulkanUtils::copyDataToMemory(device, vp_mats_asteroidPipeline.data(), uniformBuffers_asteroidPipeline.memory[imageIndex],
    1154                                  0, vp_mats_asteroidPipeline.memorySize(), false);
    1155 
    1156    VulkanUtils::copyDataToMemory(device, objects_asteroidPipeline.data(), storageBuffers_asteroidPipeline.memory[imageIndex],
    1157                                  0, objects_asteroidPipeline.memorySize(), false);
     1192   VulkanUtils::copyDataToMappedMemory(device, uniforms_asteroidPipeline.data(), uniforms_asteroidPipeline.mapped(imageIndex),
     1193                                       uniformBuffers_asteroidPipeline.memory[imageIndex],
     1194                                       uniforms_asteroidPipeline.memorySize(), true);
     1195
     1196   VulkanUtils::copyDataToMappedMemory(device, objects_asteroidPipeline.data(), objects_asteroidPipeline.mapped(imageIndex),
     1197                                       storageBuffers_asteroidPipeline.memory[imageIndex],
     1198                                       objects_asteroidPipeline.memorySize(), true);
    11581199
    11591200   if (objects_laserPipeline.resized) {
     1201      objects_laserPipeline.unmap(storageBuffers_laserPipeline.memory, device);
     1202
    11601203      resizeBufferSet(storageBuffers_laserPipeline, objects_laserPipeline.memorySize(), resourceCommandPool,
    11611204                      graphicsQueue, true);
     1205
     1206      objects_laserPipeline.map(storageBuffers_laserPipeline.memory, device);
    11621207
    11631208      objects_laserPipeline.resize();
     
    11811226   }
    11821227
    1183    VulkanUtils::copyDataToMemory(device, vp_mats_laserPipeline.data(), uniformBuffers_laserPipeline.memory[imageIndex],
    1184                                  0, vp_mats_laserPipeline.memorySize(), false);
    1185 
    1186    VulkanUtils::copyDataToMemory(device, objects_laserPipeline.data(), storageBuffers_laserPipeline.memory[imageIndex],
    1187                                  0, objects_laserPipeline.memorySize(), false);
     1228   VulkanUtils::copyDataToMappedMemory(device, uniforms_laserPipeline.data(), uniforms_laserPipeline.mapped(imageIndex),
     1229                                       uniformBuffers_laserPipeline.memory[imageIndex],
     1230                                       uniforms_laserPipeline.memorySize(), true);
     1231
     1232   VulkanUtils::copyDataToMappedMemory(device, objects_laserPipeline.data(), objects_laserPipeline.mapped(imageIndex),
     1233                                       storageBuffers_laserPipeline.memory[imageIndex],
     1234                                       objects_laserPipeline.memorySize(), true);
    11881235
    11891236   if (objects_explosionPipeline.resized) {
     1237      objects_explosionPipeline.unmap(storageBuffers_explosionPipeline.memory, device);
     1238
    11901239      resizeBufferSet(storageBuffers_explosionPipeline, objects_explosionPipeline.memorySize(), resourceCommandPool,
    11911240                      graphicsQueue, true);
     1241
     1242      objects_explosionPipeline.map(storageBuffers_explosionPipeline.memory, device);
    11921243
    11931244      objects_explosionPipeline.resize();
     
    12101261   }
    12111262
    1212    VulkanUtils::copyDataToMemory(device, uniforms_explosionPipeline.data(), uniformBuffers_explosionPipeline.memory[imageIndex],
    1213                                  0, uniforms_explosionPipeline.memorySize(), false);
    1214 
    1215    VulkanUtils::copyDataToMemory(device, objects_explosionPipeline.data(), storageBuffers_explosionPipeline.memory[imageIndex],
    1216                                  0, objects_explosionPipeline.memorySize(), false);
     1263   VulkanUtils::copyDataToMappedMemory(device, uniforms_explosionPipeline.data(), uniforms_explosionPipeline.mapped(imageIndex),
     1264                                       uniformBuffers_explosionPipeline.memory[imageIndex],
     1265                                       uniforms_explosionPipeline.memorySize(), true);
     1266
     1267   VulkanUtils::copyDataToMappedMemory(device, objects_explosionPipeline.data(), objects_explosionPipeline.mapped(imageIndex),
     1268                                       storageBuffers_explosionPipeline.memory[imageIndex],
     1269                                       objects_explosionPipeline.memorySize(), true);
    12171270}
    12181271
     
    22532306   createSyncObjects();
    22542307
    2255    createBufferSet(vp_mats_modelPipeline.memorySize(),
     2308   createBufferSet(uniforms_modelPipeline.memorySize(),
    22562309                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    2257                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2310                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    22582311                   uniformBuffers_modelPipeline);
     2312
     2313   uniforms_modelPipeline.map(uniformBuffers_modelPipeline.memory, device);
    22592314
    22602315   createBufferSet(objects_modelPipeline.memorySize(),
    22612316                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    22622317                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    2263                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2318                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    22642319                   storageBuffers_modelPipeline);
     2320
     2321    objects_modelPipeline.map(storageBuffers_modelPipeline.memory, device);
    22652322
    22662323   modelPipeline.updateRenderPass(renderPass);
     
    22692326   modelPipeline.createDescriptorSets(swapChainImages.size());
    22702327
    2271    createBufferSet(vp_mats_shipPipeline.memorySize(),
     2328   createBufferSet(uniforms_shipPipeline.memorySize(),
    22722329                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    2273                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2330                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    22742331                   uniformBuffers_shipPipeline);
     2332
     2333   uniforms_shipPipeline.map(uniformBuffers_shipPipeline.memory, device);
    22752334
    22762335   createBufferSet(objects_shipPipeline.memorySize(),
    22772336                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    22782337                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    2279                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2338                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    22802339                   storageBuffers_shipPipeline);
     2340
     2341    objects_shipPipeline.map(storageBuffers_shipPipeline.memory, device);
    22812342
    22822343   shipPipeline.updateRenderPass(renderPass);
     
    22852346   shipPipeline.createDescriptorSets(swapChainImages.size());
    22862347
    2287    createBufferSet(vp_mats_asteroidPipeline.memorySize(),
     2348   createBufferSet(uniforms_asteroidPipeline.memorySize(),
    22882349                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    2289                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2350                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    22902351                   uniformBuffers_asteroidPipeline);
     2352
     2353   uniforms_asteroidPipeline.map(uniformBuffers_asteroidPipeline.memory, device);
    22912354
    22922355   createBufferSet(objects_asteroidPipeline.memorySize(),
    22932356                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    22942357                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    2295                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2358                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    22962359                   storageBuffers_asteroidPipeline);
     2360
     2361    objects_asteroidPipeline.map(storageBuffers_asteroidPipeline.memory, device);
    22972362
    22982363   asteroidPipeline.updateRenderPass(renderPass);
     
    23012366   asteroidPipeline.createDescriptorSets(swapChainImages.size());
    23022367
    2303    createBufferSet(vp_mats_laserPipeline.memorySize(),
     2368   createBufferSet(uniforms_laserPipeline.memorySize(),
    23042369                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    2305                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2370                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    23062371                   uniformBuffers_laserPipeline);
     2372
     2373   uniforms_laserPipeline.map(uniformBuffers_laserPipeline.memory, device);
    23072374
    23082375   createBufferSet(objects_laserPipeline.memorySize(),
    23092376                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    23102377                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    2311                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2378                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    23122379                   storageBuffers_laserPipeline);
     2380
     2381    objects_laserPipeline.map(storageBuffers_laserPipeline.memory, device);
    23132382
    23142383   laserPipeline.updateRenderPass(renderPass);
     
    23192388   createBufferSet(uniforms_explosionPipeline.memorySize(),
    23202389                   VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
    2321                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2390                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    23222391                   uniformBuffers_explosionPipeline);
     2392
     2393   uniforms_explosionPipeline.map(uniformBuffers_explosionPipeline.memory, device);
    23232394
    23242395   createBufferSet(objects_explosionPipeline.memorySize(),
    23252396                   VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT
    23262397                   | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
    2327                    VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
     2398                   VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT,
    23282399                   storageBuffers_explosionPipeline);
     2400
     2401    objects_explosionPipeline.map(storageBuffers_explosionPipeline.memory, device);
    23292402
    23302403   explosionPipeline.updateRenderPass(renderPass);
     
    23492422
    23502423   modelPipeline.cleanup();
    2351    shipPipeline.cleanup();
    2352    asteroidPipeline.cleanup();
    2353    laserPipeline.cleanup();
    2354    explosionPipeline.cleanup();
     2424
     2425   uniforms_modelPipeline.unmap(uniformBuffers_modelPipeline.memory, device);
    23552426
    23562427   for (size_t i = 0; i < uniformBuffers_modelPipeline.buffers.size(); i++) {
     
    23592430   }
    23602431
     2432   objects_modelPipeline.unmap(storageBuffers_modelPipeline.memory, device);
     2433
    23612434   for (size_t i = 0; i < storageBuffers_modelPipeline.buffers.size(); i++) {
    23622435      vkDestroyBuffer(device, storageBuffers_modelPipeline.buffers[i], nullptr);
     
    23642437   }
    23652438
     2439   shipPipeline.cleanup();
     2440
     2441   uniforms_shipPipeline.unmap(uniformBuffers_shipPipeline.memory, device);
     2442
    23662443   for (size_t i = 0; i < uniformBuffers_shipPipeline.buffers.size(); i++) {
    23672444      vkDestroyBuffer(device, uniformBuffers_shipPipeline.buffers[i], nullptr);
     
    23692446   }
    23702447
     2448   objects_shipPipeline.unmap(storageBuffers_shipPipeline.memory, device);
     2449
    23712450   for (size_t i = 0; i < storageBuffers_shipPipeline.buffers.size(); i++) {
    23722451      vkDestroyBuffer(device, storageBuffers_shipPipeline.buffers[i], nullptr);
     
    23742453   }
    23752454
     2455   asteroidPipeline.cleanup();
     2456
     2457   uniforms_asteroidPipeline.unmap(uniformBuffers_asteroidPipeline.memory, device);
     2458
    23762459   for (size_t i = 0; i < uniformBuffers_asteroidPipeline.buffers.size(); i++) {
    23772460      vkDestroyBuffer(device, uniformBuffers_asteroidPipeline.buffers[i], nullptr);
     
    23792462   }
    23802463
     2464   objects_asteroidPipeline.unmap(storageBuffers_asteroidPipeline.memory, device);
     2465
    23812466   for (size_t i = 0; i < storageBuffers_asteroidPipeline.buffers.size(); i++) {
    23822467      vkDestroyBuffer(device, storageBuffers_asteroidPipeline.buffers[i], nullptr);
     
    23842469   }
    23852470
     2471   laserPipeline.cleanup();
     2472
     2473   uniforms_laserPipeline.unmap(uniformBuffers_laserPipeline.memory, device);
     2474
    23862475   for (size_t i = 0; i < uniformBuffers_laserPipeline.buffers.size(); i++) {
    23872476      vkDestroyBuffer(device, uniformBuffers_laserPipeline.buffers[i], nullptr);
     
    23892478   }
    23902479
     2480   objects_laserPipeline.unmap(storageBuffers_laserPipeline.memory, device);
     2481
    23912482   for (size_t i = 0; i < storageBuffers_laserPipeline.buffers.size(); i++) {
    23922483      vkDestroyBuffer(device, storageBuffers_laserPipeline.buffers[i], nullptr);
     
    23942485   }
    23952486
     2487   explosionPipeline.cleanup();
     2488
     2489   uniforms_explosionPipeline.unmap(uniformBuffers_explosionPipeline.memory, device);
     2490
    23962491   for (size_t i = 0; i < uniformBuffers_explosionPipeline.buffers.size(); i++) {
    23972492      vkDestroyBuffer(device, uniformBuffers_explosionPipeline.buffers[i], nullptr);
    23982493      vkFreeMemory(device, uniformBuffers_explosionPipeline.memory[i], nullptr);
    23992494   }
     2495
     2496   objects_explosionPipeline.unmap(storageBuffers_explosionPipeline.memory, device);
    24002497
    24012498   for (size_t i = 0; i < storageBuffers_explosionPipeline.buffers.size(); i++) {
  • vulkan-game.hpp

    r90880fb r2f4ff8c  
    314314      BufferSet storageBuffers_modelPipeline;
    315315
    316       VulkanBuffer<UBO_VP_mats> vp_mats_modelPipeline;
     316      VulkanBuffer<UBO_VP_mats> uniforms_modelPipeline;
    317317      VulkanBuffer<SSBO_ModelObject> objects_modelPipeline;
    318318
     
    320320      BufferSet storageBuffers_shipPipeline;
    321321
    322       VulkanBuffer<UBO_VP_mats> vp_mats_shipPipeline;
     322      VulkanBuffer<UBO_VP_mats> uniforms_shipPipeline;
    323323      VulkanBuffer<SSBO_ModelObject> objects_shipPipeline;
    324324
     
    326326      BufferSet storageBuffers_asteroidPipeline;
    327327
    328       VulkanBuffer<UBO_VP_mats> vp_mats_asteroidPipeline;
     328      VulkanBuffer<UBO_VP_mats> uniforms_asteroidPipeline;
    329329      VulkanBuffer<SSBO_Asteroid> objects_asteroidPipeline;
    330330
     
    332332      BufferSet storageBuffers_laserPipeline;
    333333
    334       VulkanBuffer<UBO_VP_mats> vp_mats_laserPipeline;
     334      VulkanBuffer<UBO_VP_mats> uniforms_laserPipeline;
    335335      VulkanBuffer<SSBO_Laser> objects_laserPipeline;
    336336
  • vulkan-utils.hpp

    r90880fb r2f4ff8c  
    169169      memoryRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
    170170      memoryRange.memory = bufferMemory;
    171       memoryRange.size = size;
     171      memoryRange.size = VK_WHOLE_SIZE; // memoryRange.size = size;
     172
     173      // TODO: Think about the best approach here, and when creating a Vulka buffer.
     174      // The issue arises when calling vkMapMemory, because the size passed to it needs to be
     175      // VK_WHOLE_SIZE or a multiple of some Vulkan constant. When I create a buffer and matching memory,
     176      // the memory size (I believe) needs to be a multiple of the same or a similar constant, while
     177      // the buffer can bind to only a part of the memory and I don't think has a size restriction.
     178      // As long as I save the actual zize of the allocated memory, I can use that for things
     179      // like vkMapMemory, but still continue to use the buffer's size for most operations
    172180
    173181      vkFlushMappedMemoryRanges(device, 1, &memoryRange);
Note: See TracChangeset for help on using the changeset viewer.