32 #include <unordered_set>
54 template <
typename D3D_SHADER_DESC,
55 typename D3D_SHADER_INPUT_BIND_DESC,
57 typename TShaderReflection,
58 typename THandleShaderDesc,
59 typename TOnResourcesCounted,
61 typename TOnNewTexUAV,
62 typename TOnNewBuffUAV,
63 typename TOnNewBuffSRV,
64 typename TOnNewSampler,
65 typename TOnNewTexSRV,
66 typename TOnNewAccelStruct>
68 THandleShaderDesc HandleShaderDesc,
69 TOnResourcesCounted OnResourcesCounted,
71 TOnNewTexUAV OnNewTexUAV,
72 TOnNewBuffUAV OnNewBuffUAV,
73 TOnNewBuffSRV OnNewBuffSRV,
74 TOnNewSampler OnNewSampler,
75 TOnNewTexSRV OnNewTexSRV,
76 TOnNewAccelStruct OnNewAccelStruct)
78 D3D_SHADER_DESC shaderDesc = {};
79 pShaderReflection->GetDesc(&shaderDesc);
81 HandleShaderDesc(shaderDesc);
84 Resources.reserve(shaderDesc.BoundResources);
85 std::unordered_set<std::string> ResourceNamesTmpPool;
89 size_t ResourceNamesPoolSize = 0;
92 for (UINT Res = 0; Res < shaderDesc.BoundResources; Res += SkipCount)
94 D3D_SHADER_INPUT_BIND_DESC BindingDesc = {};
95 pShaderReflection->GetResourceBindingDesc(Res, &BindingDesc);
97 if (BindingDesc.BindPoint == UINT32_MAX)
100 std::string Name(BindingDesc.Name);
129 auto OpenBracketPos = Name.find(
'[');
130 if (String::npos != OpenBracketPos)
132 VERIFY(
BindCount == 1,
"When array elements are enumerated individually, BindCount is expected to always be 1");
137 Name.erase(OpenBracketPos, Name.length() - OpenBracketPos);
140 #ifdef DILIGENT_DEBUG
141 for (
const auto& ExistingRes : Resources)
143 VERIFY(Name.compare(ExistingRes.Name) != 0,
"Resource with the same name has already been enumerated. All array elements are expected to be enumerated one after another");
146 for (UINT ArrElem = Res + 1; ArrElem < shaderDesc.BoundResources; ++ArrElem)
148 D3D_SHADER_INPUT_BIND_DESC ArrElemBindingDesc = {};
149 pShaderReflection->GetResourceBindingDesc(ArrElem, &ArrElemBindingDesc);
153 if (strncmp(Name.c_str(), ArrElemBindingDesc.Name, OpenBracketPos) == 0 && ArrElemBindingDesc.Name[OpenBracketPos] ==
'[')
157 UINT Ind = atoi(ArrElemBindingDesc.Name + OpenBracketPos + 1);
159 VERIFY(ArrElemBindingDesc.BindPoint == BindingDesc.BindPoint + Ind,
160 "Array elements are expected to use contigous bind points.\n",
161 BindingDesc.Name,
" uses slot ", BindingDesc.BindPoint,
", so ", ArrElemBindingDesc.Name,
162 " is expected to use slot ", BindingDesc.BindPoint + Ind,
" while ", ArrElemBindingDesc.BindPoint,
163 " is actually used");
176 switch (BindingDesc.Type)
179 case D3D_SIT_CBUFFER: ++RC.
NumCBs;
break;
180 case D3D_SIT_TBUFFER:
UNSUPPORTED(
"TBuffers are not supported" );
break;
184 case D3D_SIT_STRUCTURED: ++RC.
NumBufSRVs;
break;
185 case D3D_SIT_UAV_RWSTRUCTURED: ++RC.
NumBufUAVs;
break;
186 case D3D_SIT_BYTEADDRESS: ++RC.
NumBufSRVs;
break;
187 case D3D_SIT_UAV_RWBYTEADDRESS: ++RC.
NumBufUAVs;
break;
188 case D3D_SIT_UAV_APPEND_STRUCTURED:
UNSUPPORTED(
"Append structured buffers are not supported" );
break;
189 case D3D_SIT_UAV_CONSUME_STRUCTURED:
UNSUPPORTED(
"Consume structured buffers are not supported" );
break;
190 case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
UNSUPPORTED(
"RW structured buffers with counter are not supported" );
break;
193 #pragma warning(push)
194 #pragma warning(disable : 4063)
201 default:
UNEXPECTED(
"Unexpected resource type");
203 ResourceNamesPoolSize += Name.length() + 1;
204 auto it = ResourceNamesTmpPool.emplace(std::move(Name));
205 Resources.emplace_back(
207 BindingDesc.BindPoint,
210 BindingDesc.Dimension,
214 OnResourcesCounted(RC, ResourceNamesPoolSize);
219 for (
size_t ResInd = 0; ResInd < Resources.size(); ++ResInd)
221 const auto& Res = Resources[ResInd];
222 switch (Res.GetInputType())
224 case D3D_SIT_CBUFFER:
230 case D3D_SIT_TBUFFER:
236 case D3D_SIT_TEXTURE:
245 TexSRVInds.push_back(ResInd);
250 case D3D_SIT_SAMPLER:
256 case D3D_SIT_UAV_RWTYPED:
269 case D3D_SIT_STRUCTURED:
275 case D3D_SIT_UAV_RWSTRUCTURED:
281 case D3D_SIT_BYTEADDRESS:
287 case D3D_SIT_UAV_RWBYTEADDRESS:
293 case D3D_SIT_UAV_APPEND_STRUCTURED:
295 UNSUPPORTED(
"Append structured buffers are not supported");
299 case D3D_SIT_UAV_CONSUME_STRUCTURED:
301 UNSUPPORTED(
"Consume structured buffers are not supported");
305 case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER:
307 UNSUPPORTED(
"RW structured buffers with counter are not supported");
311 #pragma warning(push)
312 #pragma warning(disable : 4063)
319 OnNewAccelStruct(Res);
331 for (
auto TexSRVInd : TexSRVInds)
333 OnNewTexSRV(Resources[TexSRVInd]);