Changeset 5ea0a37 in opengl-game


Ignore:
Timestamp:
Jun 11, 2021, 10:05:25 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
90880fb
Parents:
6486ba8
Message:

Add a function to VulkanBuffer to return a pointer to the buffer memory, and replace the use of updateBufferSet with copyDataToMemory to update all the data for a single pipeline in one call

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    r6486ba8 r5ea0a37  
    465465      objData.model = obj.model_transform * obj.model_base;
    466466      obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    467 
    468       updateBufferSet(storageBuffers_modelPipeline, i, objData);
    469    }
     467   }
     468
     469   VulkanUtils::copyDataToMemory(device, objects_modelPipeline.data(), storageBuffers_modelPipeline.memory[imageIndex],
     470                                 0, objects_modelPipeline.memorySize(), false);
    470471
    471472   VulkanUtils::copyDataToMemory(device, &object_VP_mats, uniformBuffers_modelPipeline.memory[imageIndex], 0,
  • sdl-game.hpp

    r6486ba8 r5ea0a37  
    300300                           bool copyData);
    301301
    302       template<class SSBOType>
    303       void updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo);
    304 
    305302      // TODO: Since addObject() returns a reference to the new object now,
    306303      // stop using objects.back() to access the object that was just created
     
    338335      void quitGame();
    339336};
    340 
    341 // TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
    342 template<class SSBOType>
    343 void VulkanGame::updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo) {
    344    for (size_t i = 0; i < set.memory.size(); i++) {
    345       VulkanUtils::copyDataToMemory(device, &ssbo, set.memory[i], objIndex * sizeof(SSBOType), sizeof(ssbo), false);
    346    }
    347 }
    348337
    349338// TODO: Right now, it's basically necessary to pass the identity matrix in for ssbo.model and to change
  • vulkan-buffer.hpp

    r6486ba8 r5ea0a37  
    3131      VulkanBuffer<T>& operator=(VulkanBuffer<T>&& other) noexcept;
    3232
    33       void resize();
     33      size_t memorySize();
     34
     35      T* data();  // Not sure I need to expose this
    3436
    3537      T& get(uint32_t index);
    3638      void add(T obj);
    3739
    38       size_t memorySize();
     40      void resize();
    3941
    4042   private:
     
    114116      range = other.range;
    115117
     118      mappedData = other.mappedData;
     119
    116120      if (rawData != nullptr) {
    117121         free(rawData);
     
    124128      other.range = 0;
    125129
     130      other.mappedData.clear();
    126131      other.rawData = nullptr;
    127132   }
     
    131136
    132137template<class T>
    133 void VulkanBuffer<T>::resize() {
    134    resized = false;
     138size_t VulkanBuffer<T>::memorySize() {
     139   return memRequirement(capacity);
     140}
     141
     142template<class T>
     143T* VulkanBuffer<T>::data() {
     144   return rawData;
    135145}
    136146
     
    145155template<class T>
    146156void VulkanBuffer<T>::add(T obj) {
     157   // TODO: Maybe copy this to the resize() function and call that function here
    147158   if (numObjects == capacity) {
    148159      // Once I add Vulkan buffer objects in here, make sure this doesn't overlap with resizeBufferSet
     
    171182
    172183template<class T>
    173 size_t VulkanBuffer<T>::memorySize() {
    174    return memRequirement(capacity);
     184void VulkanBuffer<T>::resize() {
     185   resized = false;
    175186}
    176187
  • vulkan-game.cpp

    r6486ba8 r5ea0a37  
    10221022
    10231023   // TODO: Probably move the resizing to the VulkanBuffer class
    1024 
    1025    // TODO: Replace updateBufferSet to one call to copyDataToMemory, using VulkanBuffer to provide the data source
    10261024   // TODO: Figure out a way to make updateDescriptorInfo easier to use, maybe store the binding index in the buffer set
    10271025
     
    10461044      objData.model = obj.model_transform * obj.model_base;
    10471045      obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    1048 
    1049       updateBufferSet(storageBuffers_modelPipeline, i, objData);
    1050    }
     1046   }
     1047
     1048   VulkanUtils::copyDataToMemory(device, objects_modelPipeline.data(), storageBuffers_modelPipeline.memory[imageIndex],
     1049                                 0, objects_modelPipeline.memorySize(), false);
    10511050
    10521051   if (objects_shipPipeline.resized) {
     
    10661065      objData.model = obj.model_transform * obj.model_base;
    10671066      obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    1068 
    1069       updateBufferSet(storageBuffers_shipPipeline, i, objData);
    1070    }
     1067   }
     1068
     1069   VulkanUtils::copyDataToMemory(device, objects_shipPipeline.data(), storageBuffers_shipPipeline.memory[imageIndex],
     1070                                 0, objects_shipPipeline.memorySize(), false);
    10711071
    10721072   if (objects_asteroidPipeline.resized) {
     
    11081108         objData.model = obj.model_transform * obj.model_base;
    11091109         obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    1110 
    1111          updateBufferSet(storageBuffers_asteroidPipeline, i, objData);
    11121110      }
    11131111   }
     1112
     1113   VulkanUtils::copyDataToMemory(device, objects_asteroidPipeline.data(), storageBuffers_asteroidPipeline.memory[imageIndex],
     1114                                 0, objects_asteroidPipeline.memorySize(), false);
    11141115
    11151116   if (objects_laserPipeline.resized) {
     
    11351136      objData.model = obj.model_transform * obj.model_base;
    11361137      obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    1137 
    1138       updateBufferSet(storageBuffers_laserPipeline, i, objData);
    1139    }
     1138   }
     1139
     1140   VulkanUtils::copyDataToMemory(device, objects_laserPipeline.data(), storageBuffers_laserPipeline.memory[imageIndex],
     1141                                 0, objects_laserPipeline.memorySize(), false);
    11401142
    11411143   if (objects_explosionPipeline.resized) {
     
    11601162      objData.model = obj.model_transform * obj.model_base;
    11611163      obj.center = vec3(objData.model * vec4(0.0f, 0.0f, 0.0f, 1.0f));
    1162 
    1163       updateBufferSet(storageBuffers_explosionPipeline, i, objData);
    1164    }
     1164   }
     1165
     1166   VulkanUtils::copyDataToMemory(device, objects_explosionPipeline.data(), storageBuffers_explosionPipeline.memory[imageIndex],
     1167                                 0, objects_explosionPipeline.memorySize(), false);
    11651168
    11661169   explosion_UBO.cur_time = curTime;
  • vulkan-game.hpp

    r6486ba8 r5ea0a37  
    432432                           bool copyData);
    433433
    434       template<class SSBOType>
    435       void updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo);
    436 
    437434      // TODO: Since addObject() returns a reference to the new object now,
    438435      // stop using objects.back() to access the object that was just created
     
    490487
    491488// End of specialized no-op functions
    492 
    493 // TODO: See if it makes sense to pass in the current swapchain index instead of updating all of them
    494 template<class SSBOType>
    495 void VulkanGame::updateBufferSet(BufferSet& set, size_t objIndex, SSBOType& ssbo) {
    496    for (size_t i = 0; i < set.memory.size(); i++) {
    497       VulkanUtils::copyDataToMemory(device, &ssbo, set.memory[i], objIndex * sizeof(SSBOType), sizeof(ssbo), false);
    498    }
    499 }
    500489
    501490// TODO: Right now, it's basically necessary to pass the identity matrix in for ssbo.model and to change
Note: See TracChangeset for help on using the changeset viewer.