File: GPUMemoryHeap.h

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (61 lines) | stat: -rw-r--r-- 1,564 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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;
	gr_buffer_handle _bufferHandle;

	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.
	 */
	gr_buffer_handle bufferHandle();
};

}
}