Cogs.Core
RenderTargetsD3D12.h
1#pragma once
2
3#include "../IRenderTargets.h"
4
5#include "Foundation/Collections/ConfigurablePagedPool.h"
6
7#include "CommonD3D12.h"
8
9namespace Cogs
10{
11 struct TexturesD3D12;
12
14 {
15 PoolDescriptor * next;
16 D3D12_CPU_DESCRIPTOR_HANDLE handle;
17 };
18
20 {
22 D3D12_DESCRIPTOR_HEAP_TYPE heapType;
23 };
24
26 {
27 DescriptorPage(DescriptorContext & context, size_t pageSize)
28 {
29 storage.resize(sizeof(PoolDescriptor) * pageSize);
30
31 D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};
32 heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
33 heapDesc.Type = context.heapType;
34 heapDesc.NumDescriptors = static_cast<UINT>(pageSize);
35 heapDesc.NodeMask = 0;
36
37 context.device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(heap.internalPointer()));
38
39 auto heapStart = heap->GetCPUDescriptorHandleForHeapStart();
40 auto descriptorSize = context.device->GetDescriptorHandleIncrementSize(context.heapType);
41
42 for (size_t i = 0; i < pageSize; ++i) {
43 PoolDescriptor * block = reinterpret_cast<PoolDescriptor *>(storage.data() + i * static_cast<size_t>(sizeof(PoolDescriptor)));
44
45 CD3DX12_CPU_DESCRIPTOR_HANDLE::InitOffsetted(block->handle, heapStart, static_cast<int>(i), descriptorSize);
46 block->next = (i == pageSize - 1) ? nullptr : block + 1;
47 }
48 }
49
50 PoolDescriptor * getHead() { return reinterpret_cast<PoolDescriptor *>(storage.data()); }
51
52 private:
54 std::vector<uint8_t> storage;
55 };
56
57 struct DescriptorPool : public Collections::ConfigurablePagedPool<DescriptorContext, DescriptorPage, PoolDescriptor>
58 {
59 void initialize(ResourcePointer<ID3D12Device> device, size_t capacity, D3D12_DESCRIPTOR_HEAP_TYPE heapType)
60 {
61 DescriptorContext context;
62 context.device = device;
63 context.heapType = heapType;
64
65 ConfigurablePagedPool::initialize(context, capacity, capacity);
66 }
67 };
68
69 const size_t kMaxRenderTargets = 8;
70
72 {
73 PoolDescriptor * descriptor[kMaxRenderTargets];
74
75 D3D12_RENDER_TARGET_VIEW_DESC viewDesc[kMaxRenderTargets];
77 uint32_t numSamples = 1;
78
79 TextureHandle textures[kMaxRenderTargets];
80
81 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle[kMaxRenderTargets];
82 uint8_t numViews = 1;
83 };
84
86 {
87 PoolDescriptor * descriptor;
88
89 D3D12_DEPTH_STENCIL_VIEW_DESC viewDesc;
90
91 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle;
92
93 TextureHandle texture;
94 };
95
97 {
98 D3D12_RASTERIZER_DESC rasterizerDesc;
99 };
100
102 {
103 D3D12_DEPTH_STENCIL_DESC depthStencilDesc;
104 };
105
107 {
108 D3D12_BLEND_DESC blendDesc;
109 };
110
112 {
113 HRESULT initialize(struct GraphicsDeviceD3D12 * graphicsDevice);
114
115 TexturesD3D12 * textures;
116
117 RenderTargetHandle createRenderTarget(ID3D12Resource * resource);
118 RenderTargetHandle createRenderTarget(const RenderTargetViewDescription * renderTargetViews, const size_t numViews) override;
120
123 DepthStencilHandle createDepthStencilTarget(const RenderTargetHandle handle, const DepthStencilViewDescription & depthStencilView) override;
125
128
131
132 BlendStateHandle loadBlendState(const BlendState& blendState);
133 BlendStateHandle loadBlendState(const BlendState& blendStateColor, const BlendState& blendStateAlpha) override;
134 BlendStateHandle loadBlendState(const BlendState& blendStateColor, const BlendState& blendStateAlpha, const uint32_t flags) override;
135 BlendStateHandle loadBlendState(const BlendState* blendStateColor, const BlendState* blendStateAlpha, const uint32_t numBlendState, const uint32_t flags) override;
137
138 void releaseResources();
139
142
146
147 DescriptorPool rtvPool;
148 DescriptorPool dsvPool;
149
150 private:
152 GraphicsDeviceD3D12 * graphicsDevice;
153 };
154}
Provides a configurable pool implementation usable as base implementation for several pool-like stora...
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
Encapsulates blend state for the graphics pipeline in a state object.
Definition: BlendState.h:9
Encapsulates state for depth buffer usage and stencil buffer usage in a state object.
Describes a single depth stencil view and which resources to use from the underlying texture.
Provides render target management functionality.
Encapsulates state for primitive rasterization in a state object.
Describes a single render target view and which resources to use from the underlying texture.
void releaseRenderTarget(RenderTargetHandle handle)
Release the render target with the given renderTargetHandle.
RasterizerStateHandle loadRasterizerState(const RasterizerState &rasterizerState)
Load a rasterizer state object.
BlendStateHandle loadBlendState(const BlendState &blendState)
Load a blend state object.
void releaseBlendState(BlendStateHandle handle)
Release the blend state with the given handle.
void releaseDepthStencilTarget(DepthStencilHandle handle)
Release the depth target with the given depthStencilHandle.
DepthStencilStateHandle loadDepthStencilState(const DepthStencilState &depthStencilState)
Load a depth stencil state object.
void releaseDepthStencilState(DepthStencilStateHandle handle)
Release the depth stencil state with the given handle.
void releaseRasterizerState(RasterizerStateHandle handle)
Release the rasterizer state with the given handle.
void releaseResources()
Release all allocated render target resources.
DepthStencilHandle createDepthStencilTarget(const RenderTargetHandle handle)
Creates a depth/stencil target to back the render target with the given handle.