From 86c84f4f12d3b78678dfec7666d8aaf1d138ecc3 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 20 Aug 2018 20:35:22 -0700 Subject: Removed dummy shader variable. Added final kw to implementation classes. Fixed https://github.com/DiligentGraphics/DiligentCore/issues/22 --- .../include/BufferViewVkImpl.h | 2 +- .../GraphicsEngineVulkan/include/BufferVkImpl.h | 2 +- .../include/CommandListVkImpl.h | 2 +- .../include/CommandQueueVkImpl.h | 2 +- .../include/DeviceContextVkImpl.h | 2 +- .../GraphicsEngineVulkan/include/FenceVkImpl.h | 2 +- .../include/PipelineStateVkImpl.h | 9 ++----- .../include/RenderDeviceVkImpl.h | 2 +- .../GraphicsEngineVulkan/include/SamplerVkImpl.h | 2 +- .../GraphicsEngineVulkan/include/ShaderVkImpl.h | 25 +++++++++++++------ .../GraphicsEngineVulkan/include/SwapChainVkImpl.h | 2 +- .../include/TextureViewVkImpl.h | 2 +- .../GraphicsEngineVulkan/include/TextureVkImpl.h | 2 +- .../src/PipelineStateVkImpl.cpp | 1 - .../src/ShaderResourceBindingVkImpl.cpp | 16 +++--------- Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 29 ---------------------- 16 files changed, 33 insertions(+), 69 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.h b/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.h index 1108597d..ca57e3e8 100644 --- a/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/BufferViewVkImpl.h @@ -39,7 +39,7 @@ class FixedBlockMemoryAllocator; class BufferVkImpl; /// Implementation of the Diligent::IBufferViewVk interface -class BufferViewVkImpl : public BufferViewBase +class BufferViewVkImpl final : public BufferViewBase { public: using TBufferViewBase = BufferViewBase; diff --git a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h index 90148d2b..72b5e217 100644 --- a/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/BufferVkImpl.h @@ -44,7 +44,7 @@ class FixedBlockMemoryAllocator; class DeviceContextVkImpl; /// Implementation of the Diligent::IBufferVk interface -class BufferVkImpl : public BufferBase +class BufferVkImpl final : public BufferBase { public: using TBufferBase = BufferBase; diff --git a/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.h b/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.h index 19051478..b64f32bb 100644 --- a/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/CommandListVkImpl.h @@ -34,7 +34,7 @@ namespace Diligent { /// Implementation of the Diligent::ICommandList interface -class CommandListVkImpl : public CommandListBase +class CommandListVkImpl final : public CommandListBase { public: using TCommandListBase = CommandListBase; diff --git a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h index 8e2bb941..5e31bf01 100644 --- a/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/CommandQueueVkImpl.h @@ -38,7 +38,7 @@ namespace Diligent { /// Implementation of the Diligent::ICommandQueueVk interface -class CommandQueueVkImpl : public ObjectBase +class CommandQueueVkImpl final : public ObjectBase { public: using TBase = ObjectBase; diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 94c0a3c8..9b8ad516 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -45,7 +45,7 @@ namespace Diligent { /// Implementation of the Diligent::IDeviceContext interface -class DeviceContextVkImpl : public DeviceContextBase +class DeviceContextVkImpl final : public DeviceContextBase { public: using TDeviceContextBase = DeviceContextBase; diff --git a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h index 7883d268..d1cb588d 100644 --- a/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/FenceVkImpl.h @@ -38,7 +38,7 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Implementation of the Diligent::IFenceVk interface -class FenceVkImpl : public FenceBase +class FenceVkImpl final : public FenceBase { public: using TFenceBase = FenceBase; diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h index bb5bdd3f..1475c9ff 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.h @@ -46,7 +46,7 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Implementation of the Diligent::IRenderDeviceVk interface -class PipelineStateVkImpl : public PipelineStateBase +class PipelineStateVkImpl final : public PipelineStateBase { public: using TPipelineStateBase = PipelineStateBase; @@ -88,9 +88,7 @@ public: { return m_SRBMemAllocator; } - - IShaderVariable *GetDummyShaderVar(){return &m_DummyVar;} - + static VkRenderPassCreateInfo GetRenderPassCreateInfo(Uint32 NumRenderTargets, const TEXTURE_FORMAT RTVFormats[], TEXTURE_FORMAT DSVFormat, @@ -101,9 +99,6 @@ public: private: - - DummyShaderVariable m_DummyVar; - ShaderResourceLayoutVk* m_ShaderResourceLayouts = nullptr; // SRB memory allocator must be declared before m_pDefaultShaderResBinding diff --git a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h index 5dc4514d..227526b2 100644 --- a/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/RenderDeviceVkImpl.h @@ -51,7 +51,7 @@ namespace Diligent { /// Implementation of the Diligent::IRenderDeviceVk interface -class RenderDeviceVkImpl : public RenderDeviceBase +class RenderDeviceVkImpl final : public RenderDeviceBase { public: using TRenderDeviceBase = RenderDeviceBase; diff --git a/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.h b/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.h index 290ce87c..d8adb0a9 100644 --- a/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/SamplerVkImpl.h @@ -37,7 +37,7 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Implementation of the Diligent::ISamplerVk interface -class SamplerVkImpl : public SamplerBase +class SamplerVkImpl final : public SamplerBase { public: using TSamplerBase = SamplerBase; diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h index 9daeb665..f2febb53 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h @@ -51,13 +51,25 @@ public: //virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override; - virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override; - - virtual IShaderVariable* GetShaderVariable(const Char* Name)override; + virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override + { + m_StaticVarsMgr.BindResources(pResourceMapping, Flags); + } + + virtual IShaderVariable* GetShaderVariable(const Char* Name)override + { + return m_StaticVarsMgr.GetVariable(Name); + } - virtual Uint32 GetVariableCount() const override final; + virtual Uint32 GetVariableCount() const override final + { + return m_StaticVarsMgr.GetVariableCount(); + } - virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final; + virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final + { + return m_StaticVarsMgr.GetVariable(Index); + } virtual const std::vector& GetSPIRV()const override final { @@ -73,9 +85,6 @@ public: #endif private: - - DummyShaderVariable m_DummyShaderVar; ///< Dummy shader variable - // ShaderResources class instance must be referenced through the shared pointer, because // it is referenced by ShaderResourceLayoutVk class instances std::shared_ptr m_pShaderResources; diff --git a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h index dcb62ab5..9c448ce1 100644 --- a/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/SwapChainVkImpl.h @@ -37,7 +37,7 @@ namespace Diligent class ITextureViewVk; class IMemoryAllocator; /// Implementation of the Diligent::ISwapChainVk interface -class SwapChainVkImpl : public SwapChainBase +class SwapChainVkImpl final : public SwapChainBase { public: using TSwapChainBase = SwapChainBase; diff --git a/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.h b/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.h index 4d283d51..467a2241 100644 --- a/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/TextureViewVkImpl.h @@ -37,7 +37,7 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Implementation of the Diligent::ITextureViewVk interface -class TextureViewVkImpl : public TextureViewBase +class TextureViewVkImpl final : public TextureViewBase { public: using TTextureViewBase = TextureViewBase; diff --git a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h index b027710a..eee1a938 100644 --- a/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/TextureVkImpl.h @@ -39,7 +39,7 @@ namespace Diligent class FixedBlockMemoryAllocator; /// Base implementation of the Diligent::ITextureVk interface -class TextureVkImpl : public TextureBase +class TextureVkImpl final : public TextureBase { public: using TTextureBase = TextureBase; diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 399adcbc..f379d25f 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -130,7 +130,6 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters* pRefCounters RenderDeviceVkImpl* pDeviceVk, const PipelineStateDesc& PipelineDesc) : TPipelineStateBase(pRefCounters, pDeviceVk, PipelineDesc), - m_DummyVar(*this), m_SRBMemAllocator(GetRawAllocator()), m_pDefaultShaderResBinding(nullptr, STDDeleter(pDeviceVk->GetSRBAllocator()) ) { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index 0d13319e..f91eea9b 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -108,19 +108,9 @@ IShaderVariable* ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType if (ResLayoutInd < 0) { LOG_ERROR("Failed to find variable \"", Name,"\" in shader resource binding: shader type ", GetShaderTypeLiteralName(ShaderType), " is not initialized"); - return ValidatedCast(GetPipelineState())->GetDummyShaderVar(); - } - auto *pVar = m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name); - if(pVar == nullptr) - { - LOG_ERROR("Failed to find variable \"", Name,"\" in shader resource binding. Note that only dynamic and mutable variables can be accessed through SRB object."); - return ValidatedCast(GetPipelineState())->GetDummyShaderVar(); - } - else - { - VERIFY(pVar->GetResource().SpirvAttribs.VarType != SHADER_VARIABLE_TYPE_STATIC, "Static variables cannot be accessed through shader resource binding"); - return pVar; + return nullptr; } + return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name); } Uint32 ShaderResourceBindingVkImpl::GetVariableCount(SHADER_TYPE ShaderType) const @@ -142,7 +132,7 @@ IShaderVariable* ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType if (ResLayoutInd < 0) { LOG_ERROR("Failed to find variable at index \"", Index, "\" in shader resource binding: shader type ", GetShaderTypeLiteralName(ShaderType), " is not initialized"); - return ValidatedCast(GetPipelineState())->GetDummyShaderVar(); + return nullptr; } return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index); } diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 0db36dee..8117aa30 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -38,7 +38,6 @@ namespace Diligent ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* pRenderDeviceVk, const ShaderCreationAttribs& CreationAttribs) : TShaderBase(pRefCounters, pRenderDeviceVk, CreationAttribs.Desc), - m_DummyShaderVar(*this), m_StaticResLayout(*this, pRenderDeviceVk->GetLogicalDevice(), GetRawAllocator()), m_StaticResCache(ShaderResourceCacheVk::DbgCacheContentType::StaticShaderResources), m_StaticVarsMgr(*this) @@ -69,34 +68,6 @@ ShaderVkImpl::~ShaderVkImpl() m_StaticVarsMgr.Destroy(GetRawAllocator()); } -void ShaderVkImpl::BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) -{ - m_StaticVarsMgr.BindResources(pResourceMapping, Flags); -} - -IShaderVariable* ShaderVkImpl::GetShaderVariable(const Char* Name) -{ - IShaderVariable *pVar = m_StaticVarsMgr.GetVariable(Name); - if (pVar == nullptr) - { - LOG_ERROR_MESSAGE("Shader variable \"", Name, "\" is not found in shader \"", m_Desc.Name, "\". Note that only static variables can be accessed through shader object."); - return &m_DummyShaderVar; - } - else - return pVar; -} - -Uint32 ShaderVkImpl::GetVariableCount()const -{ - return m_StaticVarsMgr.GetVariableCount(); -} - -IShaderVariable* ShaderVkImpl::GetShaderVariable(Uint32 Index) -{ - return m_StaticVarsMgr.GetVariable(Index); -} - - #ifdef DEVELOPMENT void ShaderVkImpl::DvpVerifyStaticResourceBindings() { -- cgit v1.2.3