Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
DescriptorIndexAllocator.cpp
Go to the documentation of this file.
2#include <algorithm>
3#include <stdexcept>
5
6namespace EngineCore
7{
8
9DescriptorIndexAllocator::DescriptorIndexAllocator(int descriptorCount): capacity(descriptorCount) {
10 for (int i = descriptorCount - 1; i >= 0; i--) {
11 freeIndices.push(i);
12 }
13}
14
16{
17 if (freeIndices.empty())
18 {
19 throw AllocationException("Failed to acquire a free index");
20 }
21
22 const uint32_t index = freeIndices.top();
23 freeIndices.pop();
24 usedIndices.push_back(index);
25 return index;
26}
27
29{
30 usedIndices.erase(std::remove(usedIndices.begin(), usedIndices.end(), index), usedIndices.end());
31 freeIndices.push(index);
32}
33
34const std::vector<uint32_t> &DescriptorIndexAllocator::getUsedIndices() const
35{
36 return usedIndices;
37}
38
39void DescriptorIndexAllocator::reset(const int newSize) {
40 usedIndices.clear();
41 for (int i = 0; i < freeIndices.size(); i++) {
42 freeIndices.pop();
43 }
44 for(int i = newSize-1; i >= 0; i--)
45 {
46 freeIndices.push(i);
47 }
48
49}
50
52 return capacity;
53}
54
55} // namespace EngineCore
Used when we allocate memory in finite space (e.g. array) and run out of space.
Definition Exceptions.h:42
uint32_t allocate()
Get an index where there is no data in the array.
void reset(int newSize)
Resets all values in the buffers and allocates with new size.
const std::vector< uint32_t > & getUsedIndices() const
Gets the indices of all allocated fields in the array.
void free(uint32_t index)
Frees a cell in the array where the memory is not used anymore.
Log category system implementation.