Nebula
Loading...
Searching...
No Matches
memory.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11//------------------------------------------------------------------------------
13#include "util/array.h"
14#include "ids/idpool.h"
16#if __VULKAN__
17#include "vk/vkloader.h"
18#endif
19namespace CoreGraphics
20{
21
22#if __VULKAN__
23typedef VkDeviceSize DeviceSize;
24typedef VkDeviceMemory DeviceMemory;
25typedef VkDeviceAddress DeviceAddress;
26#else
27#error "coregraphics/memory.h is not supported for the renderer"
28#endif
29
39
40struct Alloc
41{
42 DeviceMemory mem;
43 DeviceSize offset;
44 DeviceSize size;
48};
49
51{
52 DeviceSize offset;
53 DeviceSize size;
54};
55
57{
58 DeviceSize space;
59};
60
62{
63 // make a new allocation
64 Alloc AllocateMemory(uint alignment, uint size);
65 // deallocate memory
66 bool DeallocateMemory(const Alloc& alloc);
67
68 // clear memory pool
69 void Clear();
70
71 // get mapped memory
72 void* GetMappedMemory(const Alloc& alloc);
73
74 DeviceSize blockSize;
80 DeviceSize size;
81
82 const char* budgetCounter;
83 DeviceSize maxSize;
85
87
88private:
89
90 static constexpr uint DedicatedBlockNodeIndex = 0xFFFFFFFF;
91
92 // create new memory block
93 DeviceMemory CreateBlock(void** outMappedPtr);
94 // destroy block
95 void DestroyBlock(DeviceMemory mem);
96 // allocate an exclusive block
97 Alloc AllocateExclusiveBlock(DeviceSize alignment, DeviceSize size);
98};
99
103
106 DeviceSize deviceLocalMemory,
107 DeviceSize hostLocalMemory,
108 DeviceSize hostToDeviceMemory,
109 DeviceSize deviceToHostMemory);
111void DiscardMemoryPools(VkDevice dev);
112
114void FreeMemory(const CoreGraphics::Alloc& alloc);
116void* GetMappedMemory(const CoreGraphics::Alloc& alloc);
117
118} // namespace CoreGraphics
Definition idpool.h:29
Critical section objects are used to protect a portion of code from parallel execution.
Nebula's dynamic array class.
Definition array.h:60
Acceleration structures are used to enable ray tracing on the GPU by dividing the scene into a BVH.
Definition accelerationstructure.h:24
void DiscardMemoryPools(VkDevice dev)
discard memory pools
Definition vkmemory.cc:95
void FreeMemory(const CoreGraphics::Alloc &alloc)
free memory
Definition vkmemory.cc:107
Util::Array< MemoryHeap > Heaps
Definition memory.cc:12
void * GetMappedMemory(const CoreGraphics::Alloc &alloc)
get mapped memory pointer
Definition vkmemory.cc:122
Util::Array< MemoryPool > Pools
Definition memory.cc:11
MemoryPoolType
Definition memory.h:31
@ MemoryPool_HostLocal
Memory which should reside solely on the GPU.
Definition memory.h:33
@ MemoryPool_DeviceLocal
Definition memory.h:32
@ NumMemoryPoolTypes
Memory which is visible on both device and host side.
Definition memory.h:37
@ MemoryPool_DeviceAndHost
Memory which is cached on host, meaning memory is flushed with a call to Flush or Invalidate.
Definition memory.h:35
@ MemoryPool_HostCached
Memory which should reside solely on the CPU and is coherent, requires no flush/invalidate.
Definition memory.h:34
void SetupMemoryPools(DeviceSize deviceLocalMemory, DeviceSize hostLocalMemory, DeviceSize hostToDeviceMemory, DeviceSize deviceToHostMemory)
setup memory pools
Definition vkmemory.cc:22
Threading::CriticalSection AllocationLock
Definition memory.cc:13
Definition memory.h:41
uint poolIndex
Definition memory.h:46
uint blockIndex
Definition memory.h:47
uint nodeIndex
Definition memory.h:45
DeviceSize size
Definition memory.h:44
DeviceSize offset
Definition memory.h:43
DeviceMemory mem
Definition memory.h:42
Definition memory.h:51
DeviceSize size
Definition memory.h:53
DeviceSize offset
Definition memory.h:52
Definition memory.h:57
DeviceSize space
Definition memory.h:58
Definition memory.h:62
uint memoryType
Definition memory.h:75
static constexpr uint DedicatedBlockNodeIndex
Definition memory.h:90
DeviceSize maxSize
Definition memory.h:83
Ids::IdPool blockPool
Definition memory.h:76
void * GetMappedMemory(const Alloc &alloc)
Definition memory.cc:111
void Clear()
Definition memory.cc:97
Alloc AllocateMemory(uint alignment, uint size)
Definition memory.cc:19
DeviceSize size
Definition memory.h:80
Util::Array< DeviceMemory > blocks
Definition memory.h:77
void DestroyBlock(DeviceMemory mem)
Definition vkmemory.cc:170
DeviceMemory CreateBlock(void **outMappedPtr)
Definition vkmemory.cc:131
bool mapMemory
Definition memory.h:84
bool DeallocateMemory(const Alloc &alloc)
Deallocates memory, if a GPU block was freed this function returns true.
Definition memory.cc:71
Util::Array< void * > blockMappedPointers
Definition memory.h:79
Util::Array< Memory::RangeAllocator > allocators
Definition memory.h:78
MemoryHeap * heap
Definition memory.h:86
const char * budgetCounter
Definition memory.h:82
Alloc AllocateExclusiveBlock(DeviceSize alignment, DeviceSize size)
Definition memory.cc:120
DeviceSize blockSize
Definition memory.h:74
unsigned int uint
Definition types.h:31