git.s-ol.nu ~forks/DiligentCore / f8d94db
Few updates to PipelineStateD3D11Impl assiduous 6 months ago
1 changed file(s) with 52 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
206206 const auto ShaderType = pShader->GetDesc().ShaderType;
207207 auto* pBytecode = Shaders[s]->GetBytecode();
208208
209 D3D11ShaderResourceCounters BindingsPerStage = {};
209 D3D11ShaderResourceCounters BaseBindings = {};
210210 if (m_Desc.IsAnyGraphicsPipeline())
211 BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][PSInd] = GetGraphicsPipelineDesc().NumRenderTargets;
211 {
212 // In Direct3D11, UAVs use the same register space as render targets
213 BaseBindings[D3D11_RESOURCE_RANGE_UAV][PSInd] = GetGraphicsPipelineDesc().NumRenderTargets;
214 }
212215
213216 ResourceBinding::TMap ResourceMap;
214217 for (Uint32 sign = 0; sign < m_SignatureCount; ++sign)
218221 continue;
219222
220223 VERIFY_EXPR(pSignature->GetDesc().BindingIndex == sign);
221 pSignature->UpdateShaderResourceBindingMap(ResourceMap, ShaderType, BindingsPerStage);
222 pSignature->ShiftBindings(BindingsPerStage);
224 pSignature->UpdateShaderResourceBindingMap(ResourceMap, ShaderType, BaseBindings);
225 pSignature->ShiftBindings(BaseBindings);
223226 }
224227
225228 ValidateShaderResources(pShader);
235238 }
236239
237240 #ifdef DILIGENT_DEVELOPMENT
238 D3D11ShaderResourceCounters BindingsPerStage = {};
239
240 if (m_Desc.IsAnyGraphicsPipeline())
241 BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][PSInd] = GetGraphicsPipelineDesc().NumRenderTargets;
242
243 for (Uint32 sign = 0; sign < m_SignatureCount; ++sign)
244 {
245 const auto& pSignature = m_Signatures[sign];
246 if (pSignature != nullptr)
247 pSignature->ShiftBindings(BindingsPerStage);
248 }
249
250 for (Uint32 s = 0; s < D3D11ResourceBindPoints::NumShaderTypes; ++s)
251 {
252 DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_CBV][s] <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
253 "Constant buffer count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_CBV][s]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
254 DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_SRV][s] <= D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
255 "SRV count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_SRV][s]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
256 DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_SAMPLER][s] <= D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT,
257 "Sampler count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_SAMPLER][s]}, " exceeds D3D11 limit ", D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT);
258 DEV_CHECK_ERR(BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][s] <= D3D11_PS_CS_UAV_REGISTER_COUNT,
259 "UAV count ", Uint32{BindingsPerStage[D3D11_RESOURCE_RANGE_UAV][s]}, " exceeds D3D11 limit ", D3D11_PS_CS_UAV_REGISTER_COUNT);
241 {
242 D3D11ShaderResourceCounters ResCounters = {};
243
244 if (m_Desc.IsAnyGraphicsPipeline())
245 ResCounters[D3D11_RESOURCE_RANGE_UAV][PSInd] = GetGraphicsPipelineDesc().NumRenderTargets;
246
247 for (Uint32 sign = 0; sign < m_SignatureCount; ++sign)
248 {
249 const auto& pSignature = m_Signatures[sign];
250 if (pSignature != nullptr)
251 pSignature->ShiftBindings(ResCounters);
252 }
253
254 for (Uint32 s = 0; s < D3D11ResourceBindPoints::NumShaderTypes; ++s)
255 {
256 const auto ShaderType = GetShaderTypeFromIndex(s);
257 DEV_CHECK_ERR(ResCounters[D3D11_RESOURCE_RANGE_CBV][s] <= D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
258 "Constant buffer count ", Uint32{ResCounters[D3D11_RESOURCE_RANGE_CBV][s]},
259 " in ", GetShaderTypeLiteralName(ShaderType), " stage exceeds D3D11 limit ",
260 D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT);
261 DEV_CHECK_ERR(ResCounters[D3D11_RESOURCE_RANGE_SRV][s] <= D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
262 "SRV count ", Uint32{ResCounters[D3D11_RESOURCE_RANGE_SRV][s]},
263 " in ", GetShaderTypeLiteralName(ShaderType), " stage exceeds D3D11 limit ",
264 D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT);
265 DEV_CHECK_ERR(ResCounters[D3D11_RESOURCE_RANGE_SAMPLER][s] <= D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT,
266 "Sampler count ", Uint32{ResCounters[D3D11_RESOURCE_RANGE_SAMPLER][s]},
267 " in ", GetShaderTypeLiteralName(ShaderType), " stage exceeds D3D11 limit ",
268 D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT);
269 DEV_CHECK_ERR(ResCounters[D3D11_RESOURCE_RANGE_UAV][s] <= D3D11_PS_CS_UAV_REGISTER_COUNT,
270 "UAV count ", Uint32{ResCounters[D3D11_RESOURCE_RANGE_UAV][s]},
271 " in ", GetShaderTypeLiteralName(ShaderType), " stage exceeds D3D11 limit ",
272 D3D11_PS_CS_UAV_REGISTER_COUNT);
273 }
260274 }
261275 #endif
262276 }
465479
466480 if (ResAttribution.ResourceIndex != ResourceAttribution::InvalidResourceIndex)
467481 {
468 const auto& ResDesc = pSignature->GetResourceDesc(ResAttribution.ResourceIndex);
469
470 auto ResourceType = ResDesc.ResourceType;
471 if (ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT)
472 ResourceType = SHADER_RESOURCE_TYPE_TEXTURE_SRV;
473 if (Type != ResourceType)
474 {
475 LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' contains resource with name '", Attribs.Name,
476 "' and type '", GetShaderResourceTypeLiteralName(Type), "' that is not compatible with type '",
477 GetShaderResourceTypeLiteralName(ResDesc.ResourceType), "' in pipeline resource signature '", pSignature->GetDesc().Name, "'.");
478 }
479
480 if ((Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER))
481 {
482 LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' contains resource '", Attribs.Name,
483 "' that is", ((Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) ? "" : " not"),
484 " labeled as formatted buffer, while the same resource specified by the pipeline resource signature '",
485 pSignature->GetDesc().Name, "' is", ((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) ? "" : " not"),
486 " labeled as such.");
487 }
488
489 VERIFY(Attribs.BindCount != 0,
490 "Runtime-sized array is not supported in Direct3D11, shader must not be compiled.");
482 auto ResDesc = pSignature->GetResourceDesc(ResAttribution.ResourceIndex);
483 if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT)
484 ResDesc.ResourceType = SHADER_RESOURCE_TYPE_TEXTURE_SRV;
485
486 VERIFY(Attribs.BindCount != 0, "Runtime-sized arrays are not supported in Direct3D11.");
491487 VERIFY((ResDesc.Flags & PIPELINE_RESOURCE_FLAG_RUNTIME_ARRAY) == 0,
492488 "Runtime-sized array flag is not supported in Direct3D11, this error must be handled by ValidatePipelineResourceSignatureDesc()");
493489
494 if (ResDesc.ArraySize < Attribs.BindCount)
495 {
496 LOG_ERROR_AND_THROW("Shader '", pShader->GetDesc().Name, "' contains resource '", Attribs.Name,
497 "' whose array size (", Attribs.BindCount, ") is greater than the array size (",
498 ResDesc.ArraySize, ") specified by the pipeline resource signature '", pSignature->GetDesc().Name, "'.");
499 }
490 ValidatePipelineResourceCompatibility(ResDesc, Type, Flags, Attribs.BindCount,
491 pShader->GetDesc().Name, pSignature->GetDesc().Name);
500492 }
501493 else if (ResAttribution.ImmutableSamplerIndex != ResourceAttribution::InvalidResourceIndex)
502494 {
522514 Uint32 NumSRBs) const
523515 {
524516 // Verify SRB compatibility with this pipeline
525 const auto SignCount = GetResourceSignatureCount();
526 D3D11ShaderResourceCounters Bindings = {};
517 const auto SignCount = GetResourceSignatureCount();
518 D3D11ShaderResourceCounters ResCounters = {};
527519
528520 if (m_Desc.IsAnyGraphicsPipeline())
529 Bindings[D3D11_RESOURCE_RANGE_UAV][GetShaderTypeIndex(SHADER_TYPE_PIXEL)] = static_cast<Uint8>(GetGraphicsPipelineDesc().NumRenderTargets);
521 ResCounters[D3D11_RESOURCE_RANGE_UAV][GetShaderTypeIndex(SHADER_TYPE_PIXEL)] = static_cast<Uint8>(GetGraphicsPipelineDesc().NumRenderTargets);
530522
531523 for (Uint32 sign = 0; sign < SignCount; ++sign)
532524 {
550542 "' is not compatible with pipeline layout in current pipeline '", m_Desc.Name, "'.");
551543 }
552544
553 DEV_CHECK_ERR(Bindings == BaseBindings[sign],
545 DEV_CHECK_ERR(ResCounters == BaseBindings[sign],
554546 "Bound resources has incorrect base binding indices, this may indicate a bug in resource signature compatibility comparison.");
555547
556 pSignature->ShiftBindings(Bindings);
548 pSignature->ShiftBindings(ResCounters);
557549 }
558550
559551 auto attrib_it = m_ResourceAttibutions.begin();