From 42b12901274c2aabee3ddbb9d3a012d28e5f5f7d Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 7 Oct 2019 09:19:35 -0700 Subject: Completely reworked shader resource binding implementation in OpenGL backend to make it function similar to other backends --- .../include/ShaderVariableD3DBase.h | 48 +++++++--------------- .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 13 +++--- 2 files changed, 20 insertions(+), 41 deletions(-) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h index be1f6de9..a8716edb 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h @@ -23,6 +23,7 @@ #pragma once +#include "ShaderResourceVariableBase.h" #include "ShaderResourceVariableD3D.h" /// \file @@ -30,46 +31,28 @@ namespace Diligent { - template - struct ShaderVariableD3DBase : public IShaderResourceVariableD3D + struct D3DVariableIDComparator { - ShaderVariableD3DBase(TShaderResourceLayout& ParentResLayout, - const D3DShaderResourceAttribs& Attribs, - SHADER_RESOURCE_VARIABLE_TYPE VariableType) : - m_ParentResLayout (ParentResLayout), - m_Attribs (Attribs), - m_VariableType (VariableType) + bool operator() (const INTERFACE_ID& IID)const { + return IID == IID_ShaderResourceVariableD3D || IID == IID_ShaderResourceVariable || IID == IID_Unknown; } + }; - virtual IReferenceCounters* GetReferenceCounters()const override final - { - return m_ParentResLayout.GetOwner().GetReferenceCounters(); - } - - virtual Atomics::Long AddRef()override final - { - return m_ParentResLayout.GetOwner().AddRef(); - } + template + struct ShaderVariableD3DBase : public ShaderVariableBase + { + using TBase = ShaderVariableBase; - virtual Atomics::Long Release()override final + ShaderVariableD3DBase(TShaderResourceLayout& ParentResLayout, + const D3DShaderResourceAttribs& Attribs, + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + TBase {ParentResLayout}, + m_Attribs {Attribs }, + m_VariableType {VariableType } { - return m_ParentResLayout.GetOwner().Release(); } - void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override final - { - if( ppInterface == nullptr ) - return; - - *ppInterface = nullptr; - if( IID == IID_ShaderResourceVariableD3D || IID == IID_ShaderResourceVariable || IID == IID_Unknown ) - { - *ppInterface = this; - (*ppInterface)->AddRef(); - } - } - virtual SHADER_RESOURCE_VARIABLE_TYPE GetType()const override final { return m_VariableType; @@ -93,7 +76,6 @@ namespace Diligent const D3DShaderResourceAttribs& m_Attribs; protected: - TShaderResourceLayout& m_ParentResLayout; const SHADER_RESOURCE_VARIABLE_TYPE m_VariableType; }; } diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 6bac589e..066751ea 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -117,14 +117,11 @@ Int32 ShaderResources::FindStaticSampler(const D3DShaderResourceAttribs& Resou { VERIFY(ResourceAttribs.GetInputType() == D3D_SIT_SAMPLER, "Sampler is expected"); - for (Uint32 s=0; s < ResourceLayoutDesc.NumStaticSamplers; ++s) - { - const auto& StSam = ResourceLayoutDesc.StaticSamplers[s]; - if ( ((StSam.ShaderStages & m_ShaderType) != 0) && StreqSuff(ResourceAttribs.Name, StSam.SamplerOrTextureName, m_SamplerSuffix) ) - return s; - } - - return -1; + return Diligent::FindStaticSampler(ResourceLayoutDesc.StaticSamplers, + ResourceLayoutDesc.NumStaticSamplers, + m_ShaderType, + ResourceAttribs.Name, + m_SamplerSuffix); } -- cgit v1.2.3