From f57fc688a659087f5e85d8533f61c4a1fd914810 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 2 Mar 2019 22:43:26 -0800 Subject: Reworked ShaderD3D11Impl to comply with the updated API --- .../include/RenderDeviceD3D11Impl.h | 3 +- .../GraphicsEngineD3D11/include/ShaderD3D11Impl.h | 33 ++---------------- .../include/ShaderResourceLayoutD3D11.h | 40 +++++++++++++--------- .../GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp | 30 ++++------------ 4 files changed, 33 insertions(+), 73 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h index 95548464..0e7f66ad 100644 --- a/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/RenderDeviceD3D11Impl.h @@ -49,7 +49,7 @@ public: virtual void CreateBuffer(const BufferDesc& BuffDesc, const BufferData* pBuffData, IBuffer** ppBuffer)override final; - virtual void CreateShader(const ShaderCreationAttribs& ShaderCreationAttribs, IShader** ppShader)override final; + virtual void CreateShader(const ShaderCreateInfo& ShaderCI, IShader** ppShader)override final; virtual void CreateTexture(const TextureDesc& TexDesc, const TextureData* pData, ITexture** ppTexture)override final; @@ -81,3 +81,4 @@ private: }; } + diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h index 5bafbb1f..c5005c4e 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderD3D11Impl.h @@ -50,31 +50,10 @@ public: ShaderD3D11Impl(IReferenceCounters* pRefCounters, class RenderDeviceD3D11Impl* pRenderDeviceD3D11, - const ShaderCreationAttribs& CreationAttribs); + const ShaderCreateInfo& ShaderCI); ~ShaderD3D11Impl(); - virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject** ppInterface )override final; - - virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final - { - m_StaticResLayout.BindResources(pResourceMapping, Flags, m_StaticResCache); - } - - virtual IShaderVariable* GetShaderVariable( const Char* Name )override final - { - return m_StaticResLayout.GetShaderVariable(Name); - } - - virtual Uint32 GetVariableCount() const override final - { - return m_StaticResLayout.GetTotalResourceCount(); - } - - virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final - { - return m_StaticResLayout.GetShaderVariable(Index); - } - + IMPLEMENT_QUERY_INTERFACE_IN_PLACE(IID_ShaderD3D11, TShaderBase); virtual ID3D11DeviceChild* GetD3D11Shader()override final { @@ -83,20 +62,12 @@ public: ID3DBlob* GetBytecode(){return m_pShaderByteCode;} - ShaderResourceLayoutD3D11& GetStaticResourceLayout(){return m_StaticResLayout;} - const std::shared_ptr& GetResources()const{return m_pShaderResources;} Uint32 GetShaderTypeIndex()const{return m_ShaderTypeIndex;} private: /// D3D11 shader CComPtr m_pShader; - // ShaderResources class instance must be referenced through the shared pointer, because - // it is referenced by ShaderResourceLayoutD3D11 class instances - std::shared_ptr m_pShaderResources; - - ShaderResourceCacheD3D11 m_StaticResCache; - ShaderResourceLayoutD3D11 m_StaticResLayout; Uint32 m_ShaderTypeIndex; // VS == 0, PS == 1, GS == 2, HS == 3, DS == 4, CS == 5 }; diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h index 61970f9d..b6079b0c 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h @@ -54,11 +54,11 @@ public: ShaderResourceLayoutD3D11& operator = ( ShaderResourceLayoutD3D11&&) = delete; static size_t GetRequiredMemorySize(const ShaderResourcesD3D11& SrcResources, - const SHADER_VARIABLE_TYPE* VarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, Uint32 NumVarTypes); void Initialize(std::shared_ptr pSrcResources, - const SHADER_VARIABLE_TYPE* VarTypes, + const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, Uint32 NumVarTypes, ShaderResourceCacheD3D11& ResourceCache, IMemoryAllocator& ResCacheDataAllocator, @@ -71,8 +71,9 @@ public: struct ConstBuffBindInfo final : ShaderVariableD3D11Base { ConstBuffBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function __forceinline void BindResource(IDeviceObject* pObject, Uint32 ArrayIndex); @@ -91,8 +92,9 @@ public: { TexSRVBindInfo( const D3DShaderResourceAttribs& _TextureAttribs, Uint32 _SamplerIndex, - ShaderResourceLayoutD3D11& ParentResLayout) : - ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs), + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base(ParentResLayout, _TextureAttribs, VariableType), SamplerIndex(_SamplerIndex) {} @@ -117,8 +119,9 @@ public: struct TexUAVBindInfo final : ShaderVariableD3D11Base { TexUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Provide non-virtual function @@ -137,8 +140,9 @@ public: struct BuffUAVBindInfo final : ShaderVariableD3D11Base { BuffUAVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -157,8 +161,9 @@ public: struct BuffSRVBindInfo final : ShaderVariableD3D11Base { BuffSRVBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -177,8 +182,9 @@ public: struct SamplerBindInfo final : ShaderVariableD3D11Base { SamplerBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, - ShaderResourceLayoutD3D11& ParentResLayout ) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs) + ShaderResourceLayoutD3D11& ParentResLayout, + SHADER_RESOURCE_VARIABLE_TYPE VariableType ) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -202,8 +208,8 @@ public: bool dvpVerifyBindings()const; #endif - IShaderVariable* GetShaderVariable( const Char* Name ); - IShaderVariable* GetShaderVariable( Uint32 Index ); + IShaderResourceVariable* GetShaderVariable( const Char* Name ); + IShaderResourceVariable* GetShaderVariable( Uint32 Index ); __forceinline SHADER_TYPE GetShaderType()const{return m_pResources->GetShaderType();} IObject& GetOwner(){return m_Owner;} @@ -280,7 +286,7 @@ private: } template - IShaderVariable* GetResourceByName( const Char* Name ); + IShaderResourceVariable* GetResourceByName( const Char* Name ); templateGetD3D11Device(); - switch(CreationAttribs.Desc.ShaderType) + switch (ShaderCI.Desc.ShaderType) { #define CREATE_SHADER(SHADER_NAME, ShaderName)\ @@ -75,30 +74,13 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, DEV_CHECK_ERR(SUCCEEDED(hr), "Failed to set shader name"); } - // Load shader resources - auto &Allocator = GetRawAllocator(); - auto *pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(ShaderResourcesD3D11)); - auto *pResources = new (pRawMem) ShaderResourcesD3D11(pRenderDeviceD3D11, m_pShaderByteCode, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr); - m_pShaderResources.reset(pResources, STDDeleterRawMem(Allocator)); - - // Clone only static resources that will be set directly in the shader - SHADER_VARIABLE_TYPE VarTypes[] = {SHADER_VARIABLE_TYPE_STATIC}; - // The method will also initialize resource cache to have enough space to hold static variables only! - m_StaticResLayout.Initialize(m_pShaderResources, VarTypes, _countof(VarTypes), m_StaticResCache, GetRawAllocator(), GetRawAllocator()); - - // This is not required, but still... - m_pShaderResources->SetStaticSamplers(m_StaticResCache); - // Byte code is only required for the vertex shader to create input layout - if( CreationAttribs.Desc.ShaderType != SHADER_TYPE_VERTEX ) + if( ShaderCI.Desc.ShaderType != SHADER_TYPE_VERTEX ) m_pShaderByteCode.Release(); } ShaderD3D11Impl::~ShaderD3D11Impl() { - m_StaticResCache.Destroy(GetRawAllocator()); } -IMPLEMENT_QUERY_INTERFACE( ShaderD3D11Impl, IID_ShaderD3D11, TShaderBase ) - } -- cgit v1.2.3