Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
descriptor_heap.h
1 #pragma once
2 
3 #include "d3d12_includes.h"
4 
5 #include "util/string.h"
6 #include "util/weak_ptr.h"
7 
8 #define BLOWBOX_DESCRIPTOR_ID_UNKNOWN ~(0u)
9 
10 namespace blowbox
11 {
12  //typedef unsigned int DescriptorId;
13 
14  class Device;
15 
22  {
23  public:
28 
36  void Create(const WString& name, D3D12_DESCRIPTOR_HEAP_TYPE heap_type, D3D12_DESCRIPTOR_HEAP_FLAGS flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, UINT descriptor_count = 4096U);
37 
43  UINT CreateDepthStencilView(ID3D12Resource* dsv_buffer, D3D12_DEPTH_STENCIL_VIEW_DESC* desc);
44 
50  UINT CreateRenderTargetView(ID3D12Resource* rtv_buffer, D3D12_RENDER_TARGET_VIEW_DESC* desc);
51 
56  UINT CreateConstantBufferView(D3D12_CONSTANT_BUFFER_VIEW_DESC* desc);
57 
63  UINT CreateShaderResourceView(ID3D12Resource* srv_buffer, D3D12_SHADER_RESOURCE_VIEW_DESC* desc);
64 
71  UINT CreateUnorderedAccessView(ID3D12Resource* buffer, ID3D12Resource* counter_buffer, D3D12_UNORDERED_ACCESS_VIEW_DESC* desc);
72 
77  UINT CreateSampler(D3D12_SAMPLER_DESC* desc);
78 
83  D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorById(UINT id);
84 
89  D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptorById(UINT id);
90 
92  ID3D12DescriptorHeap* Get() { return heap_; }
93 
95  const D3D12_DESCRIPTOR_HEAP_DESC& GetDesc() { return heap_desc_; }
96 
98  void Clear();
99 
101  UINT GetDescriptorSize() const { return descriptor_size_; }
102 
105 
107  UINT GetDescriptorHeapMaxAllocations() const { return heap_->GetDesc().NumDescriptors; }
108  private:
109  ID3D12DescriptorHeap* heap_;
110  D3D12_DESCRIPTOR_HEAP_DESC heap_desc_;
111 
112  // @todo Make the descriptor heap use a pool strategy instead of linear strategy
115  };
116 }
UINT GetDescriptorsAllocated() const
Definition: descriptor_heap.h:104
const D3D12_DESCRIPTOR_HEAP_DESC & GetDesc()
Definition: descriptor_heap.h:95
UINT CreateRenderTargetView(ID3D12Resource *rtv_buffer, D3D12_RENDER_TARGET_VIEW_DESC *desc)
Creates a RenderTargetView (descriptor)
Definition: descriptor_heap.cc:51
Manages a ID3D12DescriptorHeap of a certain type.
Definition: descriptor_heap.h:21
void Clear()
Essentially resets the DescriptorHeap.
Definition: descriptor_heap.cc:126
UINT CreateShaderResourceView(ID3D12Resource *srv_buffer, D3D12_SHADER_RESOURCE_VIEW_DESC *desc)
Creates a ShaderResourceView (descriptor)
Definition: descriptor_heap.cc:73
UINT GetDescriptorHeapMaxAllocations() const
Definition: descriptor_heap.h:107
UINT GetDescriptorSize() const
Definition: descriptor_heap.h:101
ID3D12DescriptorHeap * Get()
Definition: descriptor_heap.h:92
UINT CreateConstantBufferView(D3D12_CONSTANT_BUFFER_VIEW_DESC *desc)
Creates a ConstantBufferView (descriptor)
Definition: descriptor_heap.cc:62
ID3D12DescriptorHeap * heap_
The underlying descriptor heap.
Definition: descriptor_heap.h:109
eastl::wstring WString
Typedef for wrapping the EASTL wstring.
Definition: string.h:20
D3D12_GPU_DESCRIPTOR_HANDLE GetGPUDescriptorById(UINT id)
Get a gpu handle to a descriptor by its id.
Definition: descriptor_heap.cc:115
~DescriptorHeap()
Destructs the DescriptorHeap.
Definition: descriptor_heap.cc:19
UINT descriptor_size_
The size of a single descriptor.
Definition: descriptor_heap.h:114
UINT CreateSampler(D3D12_SAMPLER_DESC *desc)
Creates a sampler state (descriptor)
Definition: descriptor_heap.cc:95
The main Blowbox namespace.
Definition: image.cc:8
DescriptorHeap()
Constructs a DescriptorHeap.
Definition: descriptor_heap.cc:10
D3D12_DESCRIPTOR_HEAP_DESC heap_desc_
The description for the descriptor heap.
Definition: descriptor_heap.h:110
UINT CreateDepthStencilView(ID3D12Resource *dsv_buffer, D3D12_DEPTH_STENCIL_VIEW_DESC *desc)
Creates a DepthStencilView (descriptor)
Definition: descriptor_heap.cc:40
D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorById(UINT id)
Get a cpu handle to a descriptor by its id.
Definition: descriptor_heap.cc:106
UINT current_allocations_
The number of descriptors in the descriptor heap in active use.
Definition: descriptor_heap.h:113
void Create(const WString &name, D3D12_DESCRIPTOR_HEAP_TYPE heap_type, D3D12_DESCRIPTOR_HEAP_FLAGS flags=D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, UINT descriptor_count=4096U)
Creates the DescriptorHeap.
Definition: descriptor_heap.cc:25
UINT CreateUnorderedAccessView(ID3D12Resource *buffer, ID3D12Resource *counter_buffer, D3D12_UNORDERED_ACCESS_VIEW_DESC *desc)
Creates a UnorderedAccessView (descriptor)
Definition: descriptor_heap.cc:84