diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-02-24 05:49:04 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:10 +0000 |
| commit | a730e3b5baa208b7a152800b2323db6be88ad243 (patch) | |
| tree | b7aef0227512709034177105208daaedfd85c1d3 /Graphics/GraphicsEngine | |
| parent | Reworked ShaderResourceBindingVkImpl and ShaderResourceBindingD3D12Impl: move... (diff) | |
| download | DiligentCore-a730e3b5baa208b7a152800b2323db6be88ad243.tar.gz DiligentCore-a730e3b5baa208b7a152800b2323db6be88ad243.zip | |
Replaced InitializeStaticResources and InitializeStaticResourcesWithSignature methods of IShaderResourceBinding with IPipelineState::InitializeStaticSRBResources and IPipelineResourceSignature::InitializeStaticSRBResources
Diffstat (limited to 'Graphics/GraphicsEngine')
6 files changed, 150 insertions, 97 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp index bf7b2bf7..4cc9f3b6 100644 --- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp @@ -392,6 +392,29 @@ protected: } } + template <typename SRBImplType, typename InitResourcesHandler> + void InitializeStaticSRBResourcesImpl(SRBImplType* pSRB, InitResourcesHandler Handler) const + { + DEV_CHECK_ERR(pSRB != nullptr, "SRB must not be null"); + if (pSRB->StaticResourcesInitialized()) + { + LOG_WARNING_MESSAGE("Static resources have already been initialized in this shader resource binding object."); + return; + } + + const auto* const pSRBSignature = pSRB->GetPipelineResourceSignature(); +#ifdef DILIGENT_DEVELOPMENT + if (!pSRBSignature->IsCompatibleWith(this)) + { + LOG_ERROR_MESSAGE("Shader resource binding is not compatible with resource signature '", this->m_Desc.Name, "'."); + } +#endif + + Handler(pSRB); + + pSRB->SetStaticResourcesInitialized(); + } + // Finds a sampler that is assigned to texture Tex, when combined texture samplers are used. // Returns an index of the sampler in m_Desc.Resources array, or InvalidSamplerValue if there is // no such sampler, or if combined samplers are not used. diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 3c452223..363f3899 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -361,6 +361,18 @@ public: return this->GetResourceSignature(0)->BindStaticResources(ShaderFlags, pResourceMapping, Flags); } + virtual void DILIGENT_CALL_TYPE InitializeStaticSRBResources(IShaderResourceBinding* pSRB) const override final + { + if (!m_UsingImplicitSignature) + { + LOG_ERROR_MESSAGE("IPipelineState::InitializeStaticSRBResources is not allowed for pipelines that use explicit " + "resource signatures. Use IPipelineResourceSignature::InitializeStaticSRBResources instead."); + return; + } + + return this->GetResourceSignature(0)->InitializeStaticSRBResources(pSRB); + } + protected: using TNameToGroupIndexMap = std::unordered_map<HashMapStringKey, Uint32, HashMapStringKey::Hasher>; diff --git a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp index 8282fa40..060ccfce 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp @@ -95,39 +95,9 @@ public: } /// Implementation of IShaderResourceBinding::GetPipelineResourceSignature(). - virtual IPipelineResourceSignature* DILIGENT_CALL_TYPE GetPipelineResourceSignature() override final + virtual IPipelineResourceSignature* DILIGENT_CALL_TYPE GetPipelineResourceSignature() const override final { - return m_pPRS; - } - - virtual void DILIGENT_CALL_TYPE InitializeStaticResources(const IPipelineState* pPipelineState) override - { - if (StaticResourcesInitialized()) - { - LOG_WARNING_MESSAGE("Static resources have already been initialized in this shader resource binding object. The operation will be ignored."); - return; - } - - const IPipelineResourceSignature* pResourceSignature = nullptr; - if (pPipelineState != nullptr) - { - pResourceSignature = pPipelineState->GetResourceSignature(GetBindingIndex()); - if (pResourceSignature == nullptr) - { - LOG_ERROR_MESSAGE("Shader resource binding is not compatible with pipeline state."); - return; - } - -#ifdef DILIGENT_DEVELOPMENT - if (!pResourceSignature->IsCompatibleWith(GetSignature())) - { - LOG_ERROR_MESSAGE("Shader resource binding is not compatible with pipeline state."); - return; - } -#endif - } - - InitializeStaticResourcesWithSignature(pResourceSignature); + return GetSignature(); } ResourceSignatureType* GetSignature() const @@ -140,6 +110,12 @@ public: return m_bStaticResourcesInitialized; } + void SetStaticResourcesInitialized() + { + VERIFY_EXPR(!m_bStaticResourcesInitialized); + m_bStaticResourcesInitialized = true; + } + protected: template <typename ShaderVarManagerType> IShaderResourceVariable* GetVariableByNameImpl(SHADER_TYPE ShaderType, diff --git a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h index 05feb54f..5b6aac96 100644 --- a/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h +++ b/Graphics/GraphicsEngine/interface/PipelineResourceSignature.h @@ -239,7 +239,7 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject) /// binding object is written. /// \param [in] InitStaticResources - If set to true, the method will initialize static resources in /// the created object, which has the exact same effect as calling - /// IShaderResourceBinding::InitializeStaticResources(). + /// IPipelineResourceSignature::InitializeStaticSRBResources(). VIRTUAL void METHOD(CreateShaderResourceBinding)(THIS_ IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources DEFAULT_VALUE(false)) PURE; @@ -318,7 +318,26 @@ DILIGENT_BEGIN_INTERFACE(IPipelineResourceSignature, IDeviceObject) VIRTUAL Uint32 METHOD(GetStaticVariableCount)(THIS_ SHADER_TYPE ShaderType) CONST PURE; - /// AZ TODO: comment + /// Initializes static resources in the shader binding object. + + /// If static shader resources were not initialized when the SRB was created, + /// this method must be called to initialize them before the SRB can be used. + /// The method should be called after all static variables have been initialized + /// in the signature. + /// + /// \param [in] pShaderResourceBinding - Shader resource binding object to initialize. + /// The pipeline resource signature must be compatible + /// with the shader resource binding object. + /// + /// \note If static resources have already been initialized in the SRB and the method + /// is called again, it will have no effect and a warning messge will be displayed. + VIRTUAL void METHOD(InitializeStaticSRBResources)(THIS_ + struct IShaderResourceBinding* pShaderResourceBinding) CONST PURE; + + /// Returns true if the signature is compatible with another one. + + /// \remarks Two signatures are compatible if they contain identical resources, defined in the samer order + /// disregarding their names. VIRTUAL bool METHOD(IsCompatibleWith)(THIS_ const struct IPipelineResourceSignature* pPRS) CONST PURE; }; @@ -337,6 +356,7 @@ DILIGENT_END_INTERFACE # define IPipelineResourceSignature_GetStaticVariableByName(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, GetStaticVariableByName, This, __VA_ARGS__) # define IPipelineResourceSignature_GetStaticVariableByIndex(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, GetStaticVariableByIndex, This, __VA_ARGS__) # define IPipelineResourceSignature_GetStaticVariableCount(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, GetStaticVariableCount, This, __VA_ARGS__) +# define IPipelineResourceSignature_InitializeStaticSRBResources(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, InitializeStaticSRBResources,This, __VA_ARGS__) # define IPipelineResourceSignature_IsCompatibleWith(This, ...) CALL_IFACE_METHOD(PipelineResourceSignature, IsCompatibleWith, This, __VA_ARGS__) // clang-format on diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h index d8d765c1..801548e1 100644 --- a/Graphics/GraphicsEngine/interface/PipelineState.h +++ b/Graphics/GraphicsEngine/interface/PipelineState.h @@ -513,12 +513,17 @@ DILIGENT_BEGIN_INTERFACE(IPipelineState, IDeviceObject) VIRTUAL const RayTracingPipelineDesc REF METHOD(GetRayTracingPipelineDesc)(THIS) CONST PURE; - /// Binds resources for all shaders in the pipeline state + /// Binds resources for all shaders in the pipeline state. - /// \param [in] ShaderFlags - Flags that specify shader stages, for which resources will be bound. - /// Any combination of Diligent::SHADER_TYPE may be used. + /// \param [in] ShaderFlags - Flags that specify shader stages, for which resources will be bound. + /// Any combination of Diligent::SHADER_TYPE may be used. /// \param [in] pResourceMapping - Pointer to the resource mapping interface. - /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS. + /// \param [in] Flags - Additional flags. See Diligent::BIND_SHADER_RESOURCES_FLAGS. + /// + /// \remarks This metod is only allowed for pipelines that use implicit resource signature + /// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc). + /// For pipelines that use explicit resource signatures, use + /// IPipelineResourceSignature::BindStaticResources() method. VIRTUAL void METHOD(BindStaticResources)(THIS_ Uint32 ShaderFlags, IResourceMapping* pResourceMapping, @@ -526,58 +531,100 @@ DILIGENT_BEGIN_INTERFACE(IPipelineState, IDeviceObject) /// Returns the number of static shader resource variables. - /// Deprecated: use GetResourceSignature() and call IPipelineResourceSignature::GetStaticVariableCount(). /// \param [in] ShaderType - Type of the shader. - /// \remark Only static variables (that can be accessed directly through the PSO) are counted. - /// Mutable and dynamic variables are accessed through Shader Resource Binding object. + /// + /// \remarks Only static variables (that can be accessed directly through the PSO) are counted. + /// Mutable and dynamic variables are accessed through Shader Resource Binding object. + /// + /// This metod is only allowed for pipelines that use implicit resource signature + /// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc). + /// For pipelines that use explicit resource signatures, use + /// IPipelineResourceSignature::GetStaticVariableCount() method. VIRTUAL Uint32 METHOD(GetStaticVariableCount)(THIS_ SHADER_TYPE ShaderType) CONST PURE; /// Returns static shader resource variable. If the variable is not found, /// returns nullptr. - /// Deprecated: use GetResourceSignature() and call IPipelineResourceSignature::GetStaticVariableByName(). - /// \param [in] ShaderType - Type of the shader to look up the variable. + /// \param [in] ShaderType - The type of the shader to look up the variable. /// Must be one of Diligent::SHADER_TYPE. - /// \param [in] Name - Name of the variable. - /// \remarks The method does not increment the reference counter - /// of the returned interface. + /// \param [in] Name - Name of the variable. + /// + /// \remarks The method does not increment the reference counter + /// of the returned interface. + /// + /// This metod is only allowed for pipelines that use implicit resource signature + /// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc). + /// For pipelines that use explicit resource signatures, use + /// IPipelineResourceSignature::GetStaticVariableByName() method. VIRTUAL IShaderResourceVariable* METHOD(GetStaticVariableByName)(THIS_ SHADER_TYPE ShaderType, const Char* Name) PURE; /// Returns static shader resource variable by its index. - /// Deprecated: use GetResourceSignature() and call IPipelineResourceSignature::GetStaticVariableByIndex(). - /// \param [in] ShaderType - Type of the shader to look up the variable. + /// \param [in] ShaderType - The type of the shader to look up the variable. /// Must be one of Diligent::SHADER_TYPE. - /// \param [in] Index - Shader variable index. The index must be between - /// 0 and the total number of variables returned by - /// GetStaticVariableCount(). - /// \remarks Only static shader resource variables can be accessed through this method. - /// Mutable and dynamic variables are accessed through Shader Resource - /// Binding object + /// \param [in] Index - Shader variable index. The index must be between + /// 0 and the total number of variables returned by + /// GetStaticVariableCount(). + /// + /// \remarks Only static shader resource variables can be accessed through this method. + /// Mutable and dynamic variables are accessed through Shader Resource + /// Binding object. + /// + /// This metod is only allowed for pipelines that use implicit resource signature + /// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc). + /// For pipelines that use explicit resource signatures, use + /// IPipelineResourceSignature::GetStaticVariableByIndex() method. VIRTUAL IShaderResourceVariable* METHOD(GetStaticVariableByIndex)(THIS_ SHADER_TYPE ShaderType, Uint32 Index) PURE; /// Creates a shader resource binding object. - /// Deprecated: use GetResourceSignature() and call IPipelineResourceSignature::CreateShaderResourceBinding(). - /// \param [out] ppShaderResourceBinding - memory location where pointer to the new shader resource + /// \param [out] ppShaderResourceBinding - Memory location where pointer to the new shader resource /// binding object is written. - /// \param [in] InitStaticResources - if set to true, the method will initialize static resources in + /// \param [in] InitStaticResources - If set to true, the method will initialize static resources in /// the created object, which has the exact same effect as calling - /// IShaderResourceBinding::InitializeStaticResources(). + /// IPipelineState::InitializeStaticSRBResources(). + /// + /// \remarks This metod is only allowed for pipelines that use implicit resource signature + /// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc). + /// For pipelines that use explicit resource signatures, use + /// IPipelineResourceSignature::CreateShaderResourceBinding() method. VIRTUAL void METHOD(CreateShaderResourceBinding)(THIS_ IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources DEFAULT_VALUE(false)) PURE; + + /// Initializes static resources in the shader binding object. + + /// If static shader resources were not initialized when the SRB was created, + /// this method must be called to initialize them before the SRB can be used. + /// The method should be called after all static variables have been initialized + /// in the PSO. + /// + /// \param [in] pShaderResourceBinding - Shader resource binding object to initialize. + /// The pipeline state must be compatible + /// with the shader resource binding object. + /// + /// \note If static resources have already been initialized in the SRB and the method + /// is called again, it will have no effect and a warning messge will be displayed. + /// + /// \remarks This metod is only allowed for pipelines that use implicit resource signature + /// (e.g. shader resources are defined through ResourceLayout member of the pipeline desc). + /// For pipelines that use explicit resource signatures, use + /// IPipelineResourceSignature::InitializeStaticSRBResources() method. + VIRTUAL void METHOD(InitializeStaticSRBResources)(THIS_ + struct IShaderResourceBinding* pShaderResourceBinding) CONST PURE; + + /// Checks if this pipeline state object is compatible with another PSO /// If two pipeline state objects are compatible, they can use shader resource binding @@ -606,10 +653,10 @@ DILIGENT_BEGIN_INTERFACE(IPipelineState, IDeviceObject) const struct IPipelineState* pPSO) CONST PURE; - /// AZ TODO: comment + /// Returns the number of pipeline resource signature used to created this pipeline. VIRTUAL Uint32 METHOD(GetResourceSignatureCount)(THIS) CONST PURE; - /// AZ TODO: comment + /// Returns pipeline resource signature at the give index. VIRTUAL IPipelineResourceSignature* METHOD(GetResourceSignature)(THIS_ Uint32 Index) CONST PURE; }; @@ -623,16 +670,17 @@ DILIGENT_END_INTERFACE # define IPipelineState_GetDesc(This) (const struct PipelineStateDesc*)IDeviceObject_GetDesc(This) -# define IPipelineState_GetGraphicsPipelineDesc(This) CALL_IFACE_METHOD(PipelineState, GetGraphicsPipelineDesc, This) -# define IPipelineState_GetRayTracingPipelineDesc(This) CALL_IFACE_METHOD(PipelineState, GetRayTracingPipelineDesc, This) -# define IPipelineState_BindStaticResources(This, ...) CALL_IFACE_METHOD(PipelineState, BindStaticResources, This, __VA_ARGS__) -# define IPipelineState_GetStaticVariableCount(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableCount, This, __VA_ARGS__) -# define IPipelineState_GetStaticVariableByName(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableByName, This, __VA_ARGS__) -# define IPipelineState_GetStaticVariableByIndex(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableByIndex, This, __VA_ARGS__) -# define IPipelineState_CreateShaderResourceBinding(This, ...) CALL_IFACE_METHOD(PipelineState, CreateShaderResourceBinding, This, __VA_ARGS__) -# define IPipelineState_IsCompatibleWith(This, ...) CALL_IFACE_METHOD(PipelineState, IsCompatibleWith, This, __VA_ARGS__) -# define IPipelineState_GetResourceSignatureCount(This) CALL_IFACE_METHOD(PipelineState, GetResourceSignatureCount, This) -# define IPipelineState_GetResourceSignature(This, ...) CALL_IFACE_METHOD(PipelineState, GetResourceSignature, This, __VA_ARGS__) +# define IPipelineState_GetGraphicsPipelineDesc(This) CALL_IFACE_METHOD(PipelineState, GetGraphicsPipelineDesc, This) +# define IPipelineState_GetRayTracingPipelineDesc(This) CALL_IFACE_METHOD(PipelineState, GetRayTracingPipelineDesc, This) +# define IPipelineState_BindStaticResources(This, ...) CALL_IFACE_METHOD(PipelineState, BindStaticResources, This, __VA_ARGS__) +# define IPipelineState_GetStaticVariableCount(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableCount, This, __VA_ARGS__) +# define IPipelineState_GetStaticVariableByName(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableByName, This, __VA_ARGS__) +# define IPipelineState_GetStaticVariableByIndex(This, ...) CALL_IFACE_METHOD(PipelineState, GetStaticVariableByIndex, This, __VA_ARGS__) +# define IPipelineState_CreateShaderResourceBinding(This, ...) CALL_IFACE_METHOD(PipelineState, CreateShaderResourceBinding, This, __VA_ARGS__) +# define IPipelineState_InitializeStaticSRBResources(This, ...) CALL_IFACE_METHOD(PipelineState, InitializeStaticSRBResources, This, __VA_ARGS__) +# define IPipelineState_IsCompatibleWith(This, ...) CALL_IFACE_METHOD(PipelineState, IsCompatibleWith, This, __VA_ARGS__) +# define IPipelineState_GetResourceSignatureCount(This) CALL_IFACE_METHOD(PipelineState, GetResourceSignatureCount, This) +# define IPipelineState_GetResourceSignature(This, ...) CALL_IFACE_METHOD(PipelineState, GetResourceSignature, This, __VA_ARGS__) // clang-format on diff --git a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h index 39815ade..0078926c 100644 --- a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h +++ b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h @@ -69,7 +69,7 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceBinding, IObject) /// The method calls AddRef() on the returned interface, /// so Release() must be called to avoid memory leaks. - VIRTUAL struct IPipelineResourceSignature* METHOD(GetPipelineResourceSignature)(THIS) PURE; + VIRTUAL struct IPipelineResourceSignature* METHOD(GetPipelineResourceSignature)(THIS) CONST PURE; /// Binds mutable and dynamice resources using the resource mapping @@ -119,30 +119,6 @@ DILIGENT_BEGIN_INTERFACE(IShaderResourceBinding, IObject) VIRTUAL IShaderResourceVariable* METHOD(GetVariableByIndex)(THIS_ SHADER_TYPE ShaderType, Uint32 Index) PURE; - - - /// Initializes static resources - // Deprecated: use InitializeStaticResourcesWithSignature() - - /// If the parent pipeline state object contain static resources - /// (see Diligent::SHADER_RESOURCE_VARIABLE_TYPE_STATIC), this method must be called - /// once to initialize static resources in this shader resource binding object. - /// The method must be called after all static variables are initialized - /// in the PSO. - /// \param [in] pPipelineState - Pipeline state to copy static shader resource - /// bindings from. The pipeline state must be compatible - /// with this shader resource binding object. - /// If null pointer is provided, the pipeline state - /// that this SRB object was created from is used. - /// \note The method must be called exactly once. If static resources have - /// already been initialized and the method is called again, it will have - /// no effect and a warning messge will be displayed. - VIRTUAL void METHOD(InitializeStaticResources)(THIS_ - const struct IPipelineState* pPipelineState DEFAULT_VALUE(nullptr)) PURE; - - /// AZ TODO: comment - VIRTUAL void METHOD(InitializeStaticResourcesWithSignature)(THIS_ - const struct IPipelineResourceSignature* pResourceSignature DEFAULT_VALUE(nullptr)) PURE; }; DILIGENT_END_INTERFACE @@ -158,8 +134,6 @@ DILIGENT_END_INTERFACE # define IShaderResourceBinding_GetVariableByName(This, ...) CALL_IFACE_METHOD(ShaderResourceBinding, GetVariableByName, This, __VA_ARGS__) # define IShaderResourceBinding_GetVariableCount(This, ...) CALL_IFACE_METHOD(ShaderResourceBinding, GetVariableCount, This, __VA_ARGS__) # define IShaderResourceBinding_GetVariableByIndex(This, ...) CALL_IFACE_METHOD(ShaderResourceBinding, GetVariableByIndex, This, __VA_ARGS__) -# define IShaderResourceBinding_InitializeStaticResources(This, ...) CALL_IFACE_METHOD(ShaderResourceBinding, InitializeStaticResources, This, __VA_ARGS__) -# define IShaderResourceBinding_InitializeStaticResourcesWithSignature(This, ...) CALL_IFACE_METHOD(ShaderResourceBinding, InitializeStaticResourcesWithSignature, This, __VA_ARGS__) // clang-format on |
