Changeset b7fc3c2 in opengl-game for vulkan-buffer.hpp


Ignore:
Timestamp:
Jun 10, 2021, 2:58:54 PM (3 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
c1ec4f6
Parents:
bb76950
git-author:
Dmitry Portnoy <dportnoy@…> (06/10/21 14:53:52)
git-committer:
Dmitry Portnoy <dportnoy@…> (06/10/21 14:58:54)
Message:

Modify the VulkanBuffer class to take a range and to align data based on that rather than the size of an individual data item. Also, reorganize the code in VulkanGae::updateScene() in a more logical fashion, and remove VulkanGame::updateObject() and inline its functionality.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vulkan-buffer.hpp

    rbb76950 rb7fc3c2  
    2121
    2222      VulkanBuffer();
    23       VulkanBuffer(size_t capacity, size_t minOffsetAlignment);
     23      VulkanBuffer(size_t capacity, size_t range, size_t minOffsetAlignment);
    2424
    2525      VulkanBuffer(const VulkanBuffer<T>&) = delete;
     
    3535      void add(T obj);
    3636
    37       // TODO: Add a resize function
     37      size_t memorySize();
    3838
    3939   private:
    4040
    4141      size_t alignment;
     42      size_t range;
    4243      size_t numObjects;
    4344
     
    4849      // Maybe rename it to mappedData or something to make that clearer
    4950      void* rawData;
     51
     52      size_t memRequirement(size_t capacity);
    5053};
    5154
     
    6669VulkanBuffer<T>::VulkanBuffer()
    6770                              : alignment(0)
     71                              , range(0)
    6872                              , capacity(0)
    6973                              , numObjects(0)
     
    7579
    7680template<class T>
    77 VulkanBuffer<T>::VulkanBuffer(size_t capacity, size_t minOffsetAlignment)
    78                               : alignment(sizeof(T))
     81VulkanBuffer<T>::VulkanBuffer(size_t capacity, size_t range, size_t minOffsetAlignment)
     82                              : alignment(range)
     83                              , range(range / sizeof(T))
    7984                              , capacity(capacity)
    8085                              , numObjects(0)
     
    8792   }
    8893
    89    srcData = (T*)malloc(capacity * alignment);
     94   srcData = (T*)malloc(memRequirement(capacity));
    9095}
    9196
     
    110115
    111116      alignment = other.alignment;
     117      range = other.range;
    112118
    113119      if (srcData != nullptr) {
     
    119125      other.capacity = 0;
    120126      other.numObjects = 0;
    121       // TODO: Maybe set rnage to 0 as well
     127      other.range = 0;
    122128
    123129      other.srcData = nullptr;
     
    144150}
    145151
     152template<class T>
     153size_t VulkanBuffer<T>::memorySize() {
     154   return memRequirement(capacity);
     155}
     156
     157template<class T>
     158size_t VulkanBuffer<T>::memRequirement(size_t capacity) {
     159   return (capacity / range) * alignment + (capacity % range) * sizeof(T);
     160}
     161
    146162#endif // _VULKAN_BUFFER_H
Note: See TracChangeset for help on using the changeset viewer.