26 #include "RingBuffer.h" 32 #define DEFAULT_ALIGN 256 34 struct DynamicAllocation
36 DynamicAllocation(ID3D12Resource *pBuff =
nullptr,
size_t ThisOffset = 0,
size_t ThisSize = 0)
37 : pBuffer(pBuff), Offset(ThisOffset), Size(ThisSize) {}
40 ID3D12Resource *pBuffer =
nullptr;
44 D3D12_GPU_VIRTUAL_ADDRESS GPUAddress = 0;
46 Uint64 FrameNum =
static_cast<Uint64
>(-1);
50 class GPURingBuffer :
public RingBuffer
53 GPURingBuffer(
size_t MaxSize, IMemoryAllocator &Allocator, ID3D12Device *pd3d12Device,
bool AllowCPUAccess);
55 GPURingBuffer(GPURingBuffer&& rhs) :
56 RingBuffer(
std::move(rhs)),
57 m_CpuVirtualAddress(rhs.m_CpuVirtualAddress),
58 m_GpuVirtualAddress(rhs.m_GpuVirtualAddress),
59 m_pBuffer(
std::move(rhs.m_pBuffer))
61 rhs.m_CpuVirtualAddress =
nullptr;
62 rhs.m_GpuVirtualAddress = 0;
63 rhs.m_pBuffer.Release();
66 GPURingBuffer& operator =(GPURingBuffer&& rhs)
70 static_cast<RingBuffer&
>(*this) = std::move(rhs);
71 m_CpuVirtualAddress = rhs.m_CpuVirtualAddress;
72 m_GpuVirtualAddress = rhs.m_GpuVirtualAddress;
73 m_pBuffer = std::move(rhs.m_pBuffer);
74 rhs.m_CpuVirtualAddress = 0;
75 rhs.m_GpuVirtualAddress = 0;
82 DynamicAllocation Allocate(
size_t SizeInBytes)
84 auto Offset = RingBuffer::Allocate(SizeInBytes);
85 if (Offset != RingBuffer::InvalidOffset)
87 DynamicAllocation DynAlloc(m_pBuffer, Offset, SizeInBytes);
88 DynAlloc.GPUAddress = m_GpuVirtualAddress + Offset;
89 DynAlloc.CPUAddress = m_CpuVirtualAddress;
90 if(DynAlloc.CPUAddress)
91 DynAlloc.CPUAddress =
reinterpret_cast<char*
>(DynAlloc.CPUAddress) + Offset;
96 return DynamicAllocation(
nullptr, 0, 0);
100 GPURingBuffer(
const GPURingBuffer&) =
delete;
101 GPURingBuffer& operator =(GPURingBuffer&) =
delete;
106 void* m_CpuVirtualAddress;
107 D3D12_GPU_VIRTUAL_ADDRESS m_GpuVirtualAddress;
108 CComPtr<ID3D12Resource> m_pBuffer;
111 class DynamicUploadHeap
115 DynamicUploadHeap(IMemoryAllocator &Allocator,
bool bIsCPUAccessible,
class RenderDeviceD3D12Impl* pDevice,
size_t InitialSize);
117 DynamicUploadHeap(
const DynamicUploadHeap&)=
delete;
118 DynamicUploadHeap(DynamicUploadHeap&&)=
delete;
119 DynamicUploadHeap& operator=(
const DynamicUploadHeap&)=
delete;
120 DynamicUploadHeap& operator=(DynamicUploadHeap&&)=
delete;
122 DynamicAllocation Allocate(
size_t SizeInBytes,
size_t Alignment = DEFAULT_ALIGN );
124 void FinishFrame(Uint64 FenceValue, Uint64 LastCompletedFenceValue);
127 const bool m_bIsCPUAccessible;
131 std::vector<GPURingBuffer, STDAllocatorRawMem<GPURingBuffer> > m_RingBuffers;
132 IMemoryAllocator &m_Allocator;
133 RenderDeviceD3D12Impl* m_pDeviceD3D12 =
nullptr;
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Definition: AdvancedMath.h:316