From 6585bec7cae42818f633b248c5b42b8355e02283 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Fri, 3 Aug 2018 02:08:53 -0700 Subject: Implemented shader variable access by index; Fixed issues with UAV binding in D3D11; Improved shader resource layout in D3D12 --- Graphics/GraphicsEngine/include/ShaderBase.h | 22 +++++++++++++++- Graphics/GraphicsEngine/interface/Buffer.h | 6 +++-- Graphics/GraphicsEngine/interface/Shader.h | 29 ++++++++++++++++++++++ .../interface/ShaderResourceBinding.h | 20 ++++++++++++++- 4 files changed, 73 insertions(+), 4 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/ShaderBase.h b/Graphics/GraphicsEngine/include/ShaderBase.h index c62dc0bb..61ff881f 100644 --- a/Graphics/GraphicsEngine/include/ShaderBase.h +++ b/Graphics/GraphicsEngine/include/ShaderBase.h @@ -163,7 +163,7 @@ protected: }; /// Implementation of a dummy shader variable that silently ignores all operations -struct DummyShaderVariable : ShaderVariableBase +struct DummyShaderVariable final : ShaderVariableBase { DummyShaderVariable(IObject& Owner) : ShaderVariableBase(Owner) @@ -180,6 +180,26 @@ struct DummyShaderVariable : ShaderVariableBase // Ignore operation // Probably output warning } + + virtual SHADER_VARIABLE_TYPE GetType()const override final + { + return SHADER_VARIABLE_TYPE_NUM_TYPES; + } + + virtual Uint32 GetArraySize()const override final + { + return 0; + } + + virtual const Char* GetName()const override final + { + return ""; + } + + virtual Uint32 GetIndex()const override final + { + return static_cast(-1); + } }; /// Template class implementing base functionality for a shader object diff --git a/Graphics/GraphicsEngine/interface/Buffer.h b/Graphics/GraphicsEngine/interface/Buffer.h index e025c37f..077e2925 100644 --- a/Graphics/GraphicsEngine/interface/Buffer.h +++ b/Graphics/GraphicsEngine/interface/Buffer.h @@ -43,10 +43,12 @@ enum BUFFER_MODE : Int32 /// Undefined mode. BUFFER_MODE_UNDEFINED = 0, - /// Formated buffer. + /// Formated buffer. Access to the buffer will use format conversion operations. + /// In this mode, the BufferFormat member of BufferDesc defines the buffer format. BUFFER_MODE_FORMATTED, - + /// Structured buffer. + /// In this mode, ElementByteStride member of BufferDesc defines the structure stride. BUFFER_MODE_STRUCTURED, /// Helper value storing the total number of modes in the enumeration. diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index 43404edc..b89d840c 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -292,6 +292,19 @@ public: /// For instance, shader resource view cannot /// be assigned to a constant buffer variable. virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) = 0; + + /// Returns shader variable type + virtual SHADER_VARIABLE_TYPE GetType()const = 0; + + /// Returns array size. For non-array variables returns one. + virtual Uint32 GetArraySize()const = 0; + + /// Returns the variable name + virtual const Char* GetName()const = 0; + + /// Returns variable index that can be used to access the variable through + /// shader or shader resource binding object + virtual Uint32 GetIndex()const = 0; }; /// Shader interface @@ -319,6 +332,22 @@ public: /// \remark The method does not increment the reference counter /// of the returned interface. virtual IShaderVariable* GetShaderVariable(const Char* Name) = 0; + + /// Returns the number of shader variables. + + /// \remark Only static variables (that can be accessed directly through the shader) are counted. + /// Mutable and dynamic variables are accessed through Shader Resource Binding object. + virtual Uint32 GetVariableCount() const = 0; + + /// Returns shader variable by its index. + + /// \param [in] Index - Shader variable index. The index must be between + /// 0 and the total number of variables returned by + /// GetVariableCount(). + /// \remark Only static shader variables can be accessed through this method. + /// Mutable and dynamic variables are accessed through Shader Resource + /// Binding object + virtual IShaderVariable* GetShaderVariable(Uint32 Index) = 0; }; } diff --git a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h index 6e024311..2c177926 100644 --- a/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h +++ b/Graphics/GraphicsEngine/interface/ShaderResourceBinding.h @@ -65,7 +65,25 @@ public: /// \param [in] ShaderType - Type of the shader to look up the variable. /// Must be one of Diligent::SHADER_TYPE. /// \param Name - Variable name - virtual IShaderVariable *GetVariable(SHADER_TYPE ShaderType, const char *Name) = 0; + virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, const char *Name) = 0; + + /// Returns the total variable count for the specific shader stage. + + /// \param [in] ShaderType - Type of the shader. + /// \remark The method only counts mutable and dynamic variables that can be accessed through + /// the Shader Resource Binding object. Static variables are accessed through the Shader + /// object. + virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const = 0; + + /// Returns variable + + /// \param [in] ShaderType - Type of the shader to look up the variable. + /// Must be one of Diligent::SHADER_TYPE. + /// \param Index - Variable index. The index must be between 0 and the total number + /// of variables in this shader stage as returned by GetVariableCount(). + /// \remark Only mutable and dynamic variables can be accessed through this method. + /// Static variables are accessed through the Shader object. + virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, Uint32 Index) = 0; }; } -- cgit v1.2.3