mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-11 04:31:35 -10:00
This changes the model loading code such that all index and vertex data is packed in a single GPU buffer for each data type (index and vertex data are still in separate buffers). This reduces the amount of buffer rebinding needed when rendering a scene which will reduce the CPU overhead. Furthermore, this opens up possibilities of future improvements for which it is beneficial if all data is in the same buffer (e.g. MultiDrawIndirect rendering). To manage where to put the data in the GPU buffer I implemented a custom HeapAllocator which manages where data can be put. It uses a very primitive first-fit algorithm but that is sufficient for this usage type. This does add quite a lot of overhead while allocating GPU model data (I did some tracing and some allocation calls took as long as 130ms). This fixes #1457.
62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#pragma once
|
|
|
|
#include "globalincs/pstypes.h"
|
|
#include "utils/HeapAllocator.h"
|
|
#include "graphics/2d.h"
|
|
|
|
|
|
namespace graphics {
|
|
namespace util {
|
|
|
|
/**
|
|
* @brief A custom heap structure that uses a GPU buffer for storing the data
|
|
*
|
|
* @details This also keeps a client side copy of the data since that is required if the buffer is resized since the
|
|
* original data will not be kept in that case.
|
|
*/
|
|
class GPUMemoryHeap {
|
|
std::unique_ptr<::util::HeapAllocator> _allocator;
|
|
int _bufferHandle = -1;
|
|
|
|
void* _dataBuffer = nullptr;
|
|
size_t _bufferSize = 0;
|
|
|
|
void resizeBuffer(size_t newSize);
|
|
|
|
void* bufferPointer(size_t offset);
|
|
public:
|
|
explicit GPUMemoryHeap(GpuHeap heap_type);
|
|
~GPUMemoryHeap();
|
|
|
|
GPUMemoryHeap(const GPUMemoryHeap&) = delete;
|
|
GPUMemoryHeap& operator=(const GPUMemoryHeap&) = delete;
|
|
|
|
/**
|
|
* @brief Store some data in a GPU heap
|
|
* @param size The size of the data to store
|
|
* @param data The data to store
|
|
* @return The offset in bytes from the beginning of the buffer where the stored data begins
|
|
*/
|
|
size_t allocateGpuData(size_t size, void* data);
|
|
|
|
/**
|
|
* @brief Frees up some GPU data from this heap
|
|
* @param offset The offset at which to free the data
|
|
*/
|
|
void freeGpuData(size_t offset);
|
|
|
|
/**
|
|
* @brief Gets the handle of the used buffer for use in rendering operations
|
|
*
|
|
* @warning Do no change the contents of this buffer! The contents are managed by this class and may not be changed
|
|
* by external code.
|
|
*
|
|
* @return The graphics code buffer handle.
|
|
*/
|
|
int bufferHandle();
|
|
};
|
|
|
|
}
|
|
}
|
|
|