BRE12
CbvSrvUavDescriptorManager.h
1 #pragma once
2 
3 #include <d3d12.h>
4 #include <mutex>
5 #include <wrl.h>
6 
7 #include <Utils/DebugUtils.h>
8 
9 namespace BRE {
10 // To create Constant Buffer / Shader GetResource / Unordered Access Views descriptor heaps
11 // To create Constant Buffer / Shader GetResource / Unordered Access descriptors
13 public:
14  CbvSrvUavDescriptorManager() = delete;
15  ~CbvSrvUavDescriptorManager() = delete;
17  const CbvSrvUavDescriptorManager& operator=(const CbvSrvUavDescriptorManager&) = delete;
20 
21  static void Init() noexcept;
22 
23  //
24  // The following methods return GPU descriptor handle for the CBV, SRV or UAV.
25  //
26  // In the case of methods that creates several views, it returns the GPU desc handle
27  // to the first element. As we guarantee all the other views are contiguous, then
28  // you can easily build GPU desc handle for other view.
29  //
30 
31  static D3D12_GPU_DESCRIPTOR_HANDLE CreateConstantBufferView(const D3D12_CONSTANT_BUFFER_VIEW_DESC& cBufferViewDescriptor) noexcept;
32 
33  // Preconditions:
34  // - "descriptors" must not be nullptr
35  // - "descriptorCount" must be greated than zero
36  static D3D12_GPU_DESCRIPTOR_HANDLE CreateConstantBufferViews(const D3D12_CONSTANT_BUFFER_VIEW_DESC* descriptors,
37  const std::uint32_t descriptorCount) noexcept;
38 
39  static D3D12_GPU_DESCRIPTOR_HANDLE CreateShaderResourceView(ID3D12Resource& resource,
40  const D3D12_SHADER_RESOURCE_VIEW_DESC& shaderResourceViewDescriptor) noexcept;
41 
42  // Preconditions:
43  // - "resources" must not be nullptr
44  // - "descriptors" must not be nullptr
45  // - "descriptorCount" must be greated than zero
46  static D3D12_GPU_DESCRIPTOR_HANDLE CreateShaderResourceViews(ID3D12Resource* *resources,
47  const D3D12_SHADER_RESOURCE_VIEW_DESC* descriptors,
48  const std::uint32_t descriptorCount) noexcept;
49 
50  static D3D12_GPU_DESCRIPTOR_HANDLE CreateUnorderedAccessView(ID3D12Resource& resource,
51  const D3D12_UNORDERED_ACCESS_VIEW_DESC& descriptor) noexcept;
52 
53  // Preconditions:
54  // - "resources" must not be nullptr
55  // - "descriptors" must not be nullptr
56  // - "descriptorCount" must be greated than zero
57  static D3D12_GPU_DESCRIPTOR_HANDLE CreateUnorderedAccessViews(ID3D12Resource* *resources,
58  const D3D12_UNORDERED_ACCESS_VIEW_DESC* descriptors,
59  const std::uint32_t descriptorCount) noexcept;
60 
61  static ID3D12DescriptorHeap& GetDescriptorHeap() noexcept
62  {
63  BRE_ASSERT(mCbvSrvUavDescriptorHeap.Get() != nullptr);
64  return *mCbvSrvUavDescriptorHeap.Get();
65  }
66 
67 private:
68  static Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> mCbvSrvUavDescriptorHeap;
69 
70  static D3D12_GPU_DESCRIPTOR_HANDLE mCurrentCbvSrvUavGpuDescriptorHandle;
71  static D3D12_CPU_DESCRIPTOR_HANDLE mCurrentCbvSrvUavCpuDescriptorHandle;
72 
73  static std::mutex mMutex;
74 };
75 
76 }
77 
Definition: Camera.cpp:8
Definition: CbvSrvUavDescriptorManager.h:12