Nameless Engine
Loading...
Searching...
No Matches
HlslComputeShaderInterface.h
1#pragma once
2
3// Standard.
4#include <unordered_map>
5#include <format>
6
7// Custom.
8#include "shader/ComputeShaderInterface.h"
9#include "render/directx/resource/DirectXResource.h"
10#include "render/directx/descriptors/DirectXDescriptorHeap.h"
11
12// External.
13#include "directx/d3dx12.h"
14
15namespace ne {
18 // Only parent class can create instances of this class because there are some specific things
19 // we need to do when creating objects of this class and parent class handles these things.
20 friend class ComputeShaderInterface;
21
22 public:
24 virtual ~HlslComputeShaderInterface() override = default;
25
28
48 [[nodiscard]] virtual std::optional<Error> bindResource(
49 GpuResource* pResource,
50 const std::string& sShaderResourceName,
51 ComputeResourceUsage usage,
52 bool bUpdateOnlyCurrentFrameResourceDescriptors = false) override;
53
61 inline void dispatchOnGraphicsQueue(ID3D12GraphicsCommandList* pCommandList) {
62 // Bind CBVs.
63 for (const auto& [iRootParameterIndex, pResource] : cbvResources) {
64 pCommandList->SetComputeRootConstantBufferView(
65 iRootParameterIndex, pResource->getInternalResource()->GetGPUVirtualAddress());
66 }
67
68 // Bind UAVs.
69 for (const auto& [iRootParameterIndex, pResource] : uavResources) {
70 pCommandList->SetComputeRootUnorderedAccessView(
71 iRootParameterIndex, pResource->getInternalResource()->GetGPUVirtualAddress());
72 }
73
74 // Bind SRVs.
75 for (const auto& [iRootParameterIndex, pResource] : srvResources) {
76 pCommandList->SetComputeRootShaderResourceView(
77 iRootParameterIndex, pResource->getInternalResource()->GetGPUVirtualAddress());
78 }
79
80 // Bind table views.
81 for (const auto& [iRootParameterIndex, pDescriptor] : tableResources) {
82 // Set table.
83 pCommandList->SetComputeRootDescriptorTable(
84 iRootParameterIndex,
85 D3D12_GPU_DESCRIPTOR_HANDLE{
86 pCbvSrvUavHeap->getInternalHeap()->GetGPUDescriptorHandleForHeapStart().ptr +
87 pDescriptor->getDescriptorOffsetInDescriptors() * iCbvSrvUavDescriptorSize});
88 }
89
90 // Add a dispatch command.
92 }
93
94 protected:
106 const std::string& sComputeShaderName,
107 ComputeExecutionStage executionStage,
108 ComputeExecutionGroup executionGroup);
109
111 std::unordered_map<UINT, DirectXResource*> cbvResources;
112
114 std::unordered_map<UINT, DirectXResource*> uavResources;
115
117 std::unordered_map<UINT, DirectXResource*> srvResources;
118
120 std::unordered_map<UINT, DirectXDescriptor*> tableResources;
121
124
127 };
128}
Definition: ComputeShaderInterface.h:46
unsigned int getThreadGroupCountX() const
Definition: ComputeShaderInterface.h:223
Renderer * pRenderer
Definition: ComputeShaderInterface.h:241
unsigned int getThreadGroupCountY() const
Definition: ComputeShaderInterface.h:230
const ComputeExecutionGroup executionGroup
Definition: ComputeShaderInterface.h:259
const ComputeExecutionStage executionStage
Definition: ComputeShaderInterface.h:256
unsigned int getThreadGroupCountZ() const
Definition: ComputeShaderInterface.h:237
const std::string sComputeShaderName
Definition: ComputeShaderInterface.h:262
Definition: DirectXDescriptorHeap.h:211
ID3D12DescriptorHeap * getInternalHeap() const
Definition: DirectXDescriptorHeap.h:348
Definition: GpuResource.h:16
Definition: HlslComputeShaderInterface.h:17
DirectXDescriptorHeap * pCbvSrvUavHeap
Definition: HlslComputeShaderInterface.h:123
void dispatchOnGraphicsQueue(ID3D12GraphicsCommandList *pCommandList)
Definition: HlslComputeShaderInterface.h:61
virtual std::optional< Error > bindResource(GpuResource *pResource, const std::string &sShaderResourceName, ComputeResourceUsage usage, bool bUpdateOnlyCurrentFrameResourceDescriptors=false) override
Definition: HlslComputeShaderInterface.cpp:30
std::unordered_map< UINT, DirectXResource * > uavResources
Definition: HlslComputeShaderInterface.h:114
std::unordered_map< UINT, DirectXDescriptor * > tableResources
Definition: HlslComputeShaderInterface.h:120
std::unordered_map< UINT, DirectXResource * > cbvResources
Definition: HlslComputeShaderInterface.h:111
UINT iCbvSrvUavDescriptorSize
Definition: HlslComputeShaderInterface.h:126
std::unordered_map< UINT, DirectXResource * > srvResources
Definition: HlslComputeShaderInterface.h:117
Definition: Renderer.h:43