git.s-ol.nu ~forks/DiligentCore / 96e2faa
Enabled pipeline resource validation in release build assiduous 6 months ago
5 changed file(s) with 45 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
120120
121121 void Destruct();
122122
123 #ifdef DILIGENT_DEVELOPMENT
124123 struct ResourceAttribution
125124 {
126125 static constexpr Uint32 InvalidSignatureIndex = ~0u;
159158 };
160159 ResourceAttribution GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const;
161160
162 void DvpValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig);
163 #endif
161 void ValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig);
164162
165163 private:
166164 CComPtr<ID3D12DeviceChild> m_pd3d12PSO;
634634 "Compile the shader using SM5.1+ or change the resource layout to use only one space.");
635635 }
636636
637 #ifdef DILIGENT_DEVELOPMENT
638637 // Validate resources before remapping
639 DvpValidateShaderResources(pShader, pLocalRootSig);
640 #endif
638 ValidateShaderResources(pShader, pLocalRootSig);
641639
642640 CComPtr<ID3DBlob> pBlob;
643641 if (IsDXILBytecode(pBytecode->GetBufferPointer(), pBytecode->GetBufferSize()))
662660 }
663661
664662
665 #ifdef DILIGENT_DEVELOPMENT
666663 PipelineStateD3D12Impl::ResourceAttribution PipelineStateD3D12Impl::GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const
667664 {
668665 const auto SignCount = GetResourceSignatureCount();
685682 return ResourceAttribution{};
686683 }
687684
688 void PipelineStateD3D12Impl::DvpValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig)
685 void PipelineStateD3D12Impl::ValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig)
689686 {
690687 const auto& pShaderResources = pShader->GetShaderResources();
691688 const auto ShaderType = pShader->GetDesc().ShaderType;
692689
690 #ifdef DILIGENT_DEVELOPMENT
693691 m_ShaderResources.emplace_back(pShaderResources);
692 #endif
694693
695694 // Check compatibility between shader resources and resource signature.
696695 pShaderResources->ProcessResources(
697696 [&](const D3DShaderResourceAttribs& Attribs, Uint32) //
698697 {
698 #ifdef DILIGENT_DEVELOPMENT
699699 m_ResourceAttibutions.emplace_back();
700 auto& ResAttribution = m_ResourceAttibutions.back();
701 #else
702 ResourceAttribution ResAttribution;
703 #endif
700704
701705 if (pLocalRootSig != nullptr && pLocalRootSig->IsShaderRecord(Attribs))
702706 return;
704708 const auto IsSampler = Attribs.GetInputType() == D3D_SIT_SAMPLER;
705709 if (IsSampler && pShaderResources->IsUsingCombinedTextureSamplers())
706710 return;
707
708 auto& ResAttribution = m_ResourceAttibutions.back();
709711
710712 ResAttribution = GetResourceAttribution(Attribs.Name, ShaderType);
711713 if (!ResAttribution)
748750 );
749751 }
750752
753 #ifdef DILIGENT_DEVELOPMENT
751754 void PipelineStateD3D12Impl::DvpVerifySRBResources(ShaderResourceBindingD3D12Impl* pSRBs[], Uint32 NumSRBs) const
752755 {
753756 // Verify SRB compatibility with this pipeline
107107 SHADER_TYPE GetShaderStageType(Uint32 Index) const;
108108 Uint32 GetNumShaderStages() const { return m_NumPrograms; }
109109
110 #ifdef DILIGENT_DEVELOPMENT
110
111111 struct ResourceAttribution
112112 {
113113 static constexpr Uint32 InvalidSignatureIndex = ~0u;
146146 };
147147 ResourceAttribution GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const;
148148
149 void DvpValidateShaderResources(const std::shared_ptr<const ShaderResourcesGL>& pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages);
150 #endif
149 void ValidateShaderResources(std::shared_ptr<const ShaderResourcesGL> pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages);
151150
152151 private:
153152 // Linked GL programs for every shader stage. Every pipeline needs to have its own programs
217217 pSignature->AddBindings(Bindings);
218218 }
219219
220 #ifdef DILIGENT_DEVELOPMENT
221220 const auto& Limits = GetDevice()->GetDeviceLimits();
222221
223 DEV_CHECK_ERR(Bindings[BINDING_RANGE_UNIFORM_BUFFER] <= static_cast<Uint32>(Limits.MaxUniformBlocks),
224 "Number of bindings in range '", GetBindingRangeName(BINDING_RANGE_UNIFORM_BUFFER), "' is greater than maximum allowed (", Limits.MaxUniformBlocks, ").");
225 DEV_CHECK_ERR(Bindings[BINDING_RANGE_TEXTURE] <= static_cast<Uint32>(Limits.MaxTextureUnits),
226 "Number of bindings in range '", GetBindingRangeName(BINDING_RANGE_TEXTURE), "' is greater than maximum allowed (", Limits.MaxTextureUnits, ").");
227 DEV_CHECK_ERR(Bindings[BINDING_RANGE_STORAGE_BUFFER] <= static_cast<Uint32>(Limits.MaxStorageBlock),
228 "Number of bindings in range '", GetBindingRangeName(BINDING_RANGE_STORAGE_BUFFER), "' is greater than maximum allowed (", Limits.MaxStorageBlock, ").");
229 DEV_CHECK_ERR(Bindings[BINDING_RANGE_IMAGE] <= static_cast<Uint32>(Limits.MaxImagesUnits),
230 "Number of bindings in range '", GetBindingRangeName(BINDING_RANGE_IMAGE), "' is greater than maximum allowed (", Limits.MaxImagesUnits, ").");
222 if (Bindings[BINDING_RANGE_UNIFORM_BUFFER] > static_cast<Uint32>(Limits.MaxUniformBlocks))
223 LOG_ERROR_AND_THROW("The number of bindings in range '", GetBindingRangeName(BINDING_RANGE_UNIFORM_BUFFER), "' is greater than the maximum allowed (", Limits.MaxUniformBlocks, ").");
224 if (Bindings[BINDING_RANGE_TEXTURE] > static_cast<Uint32>(Limits.MaxTextureUnits))
225 LOG_ERROR_AND_THROW("The number of bindings in range '", GetBindingRangeName(BINDING_RANGE_TEXTURE), "' is greater than the maximum allowed (", Limits.MaxTextureUnits, ").");
226 if (Bindings[BINDING_RANGE_STORAGE_BUFFER] > static_cast<Uint32>(Limits.MaxStorageBlock))
227 LOG_ERROR_AND_THROW("The number of bindings in range '", GetBindingRangeName(BINDING_RANGE_STORAGE_BUFFER), "' is greater than the maximum allowed (", Limits.MaxStorageBlock, ").");
228 if (Bindings[BINDING_RANGE_IMAGE] > static_cast<Uint32>(Limits.MaxImagesUnits))
229 LOG_ERROR_AND_THROW("The number of bindings in range '", GetBindingRangeName(BINDING_RANGE_IMAGE), "' is greater than the maximum allowed (", Limits.MaxImagesUnits, ").");
231230
232231 if (m_IsProgramPipelineSupported)
233232 {
234233 for (size_t i = 0; i < ShaderStages.size(); ++i)
235234 {
236235 auto* pShaderGL = ShaderStages[i];
237 DvpValidateShaderResources(pShaderGL->GetShaderResources(), pShaderGL->GetDesc().Name, pShaderGL->GetDesc().ShaderType);
236 ValidateShaderResources(pShaderGL->GetShaderResources(), pShaderGL->GetDesc().Name, pShaderGL->GetDesc().ShaderType);
238237 }
239238 }
240239 else
241240 {
242 auto pImmediateCtx = m_pDevice->GetImmediateContext();
243 VERIFY_EXPR(pImmediateCtx);
241 auto* pImmediateCtx = m_pDevice->GetImmediateContext().RawPtr<DeviceContextGLImpl>();
242 VERIFY_EXPR(pImmediateCtx != nullptr);
244243 VERIFY_EXPR(m_GLPrograms[0] != 0);
245244
246 std::unique_ptr<ShaderResourcesGL> pResources{new ShaderResourcesGL{}};
247 pResources->LoadUniforms(ActiveStages, m_GLPrograms[0], pImmediateCtx.RawPtr<DeviceContextGLImpl>()->GetContextState());
248
249 std::shared_ptr<const ShaderResourcesGL> pShaderResources{pResources.release()};
250 DvpValidateShaderResources(pShaderResources, m_Desc.Name, ActiveStages);
251 }
252 #endif
245 std::shared_ptr<ShaderResourcesGL> pResources{new ShaderResourcesGL{}};
246 pResources->LoadUniforms(ActiveStages, m_GLPrograms[0], pImmediateCtx->GetContextState());
247 ValidateShaderResources(std::move(pResources), m_Desc.Name, ActiveStages);
248 }
253249 }
254250
255251 template <typename PSOCreateInfoType>
472468 return ctx_pipeline.second;
473469 }
474470
475 #ifdef DILIGENT_DEVELOPMENT
476471 PipelineStateGLImpl::ResourceAttribution PipelineStateGLImpl::GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const
477472 {
478473 const auto SignCount = GetResourceSignatureCount();
495490 return ResourceAttribution{};
496491 }
497492
498 void PipelineStateGLImpl::DvpValidateShaderResources(const std::shared_ptr<const ShaderResourcesGL>& pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages)
499 {
500 m_ShaderResources.emplace_back(pShaderResources);
501 m_ShaderNames.emplace_back(ShaderName);
502
493 void PipelineStateGLImpl::ValidateShaderResources(std::shared_ptr<const ShaderResourcesGL> pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages)
494 {
503495 const auto HandleResource = [&](const ShaderResourcesGL::GLResourceAttribs& Attribs, SHADER_RESOURCE_TYPE AltResourceType, PIPELINE_RESOURCE_FLAGS Flags) //
504496 {
505 m_ResourceAttibutions.emplace_back();
506 auto& ResAttribution = m_ResourceAttibutions.back();
507
508 ResAttribution = GetResourceAttribution(Attribs.Name, ShaderStages);
497 const auto ResAttribution = GetResourceAttribution(Attribs.Name, ShaderStages);
498
499 #ifdef DILIGENT_DEVELOPMENT
500 m_ResourceAttibutions.emplace_back(ResAttribution);
501 #endif
502
509503 if (!ResAttribution)
510504 {
511505 LOG_ERROR_AND_THROW("Shader '", ShaderName, "' contains resource '", Attribs.Name,
555549 };
556550
557551 pShaderResources->ProcessConstResources(HandleUB, HandleTexture, HandleImage, HandleSB);
558 }
559
552
553 #ifdef DILIGENT_DEVELOPMENT
554 m_ShaderResources.emplace_back(std::move(pShaderResources));
555 m_ShaderNames.emplace_back(ShaderName);
556 #endif
557 }
558
559 #ifdef DILIGENT_DEVELOPMENT
560560 void PipelineStateGLImpl::DvpVerifySRBResources(ShaderResourceBindingGLImpl* pSRBs[],
561561 const TBindings BoundResOffsets[],
562562 Uint32 NumSRBs) const
259259 if (TestingEnvironment::GetInstance()->GetDevice()->GetDeviceCaps().Features.RayTracing)
260260 ExpectedErrorSubstring = "Incorrect Desc.Resources[1].Flags (NO_DYNAMIC_BUFFERS). Only the following flags are valid for a acceleration structure: RUNTIME_ARRAY";
261261 else
262 ExpectedErrorSubstring = "Incorrect Desc.Resources[1].ResourceType (ACCEL_STRUCT): acceleration structure is not supported by device";
262 ExpectedErrorSubstring = "Incorrect Desc.Resources[1].ResourceType (ACCEL_STRUCT): ray tracing is not supported by device";
263263
264264 TestCreatePRSFailure(PRSDesc, ExpectedErrorSubstring);
265265 }