summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-02-28 04:45:24 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-02-28 04:45:24 +0000
commit43302d5fc3b3978952dd4215eea8f3f5668b95dd (patch)
treea0a8ac14e10c007d2bca671fcd7e27a1afdce364 /Graphics/GraphicsEngine
parentUpdated ShaderVariableVk and ShaderResourceBindingVk (diff)
downloadDiligentCore-43302d5fc3b3978952dd4215eea8f3f5668b95dd.tar.gz
DiligentCore-43302d5fc3b3978952dd4215eea8f3f5668b95dd.zip
Working on resource binding API refactor
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/CMakeLists.txt2
-rw-r--r--Graphics/GraphicsEngine/include/ShaderBase.h147
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h161
-rw-r--r--Graphics/GraphicsEngine/interface/RenderDevice.h7
-rw-r--r--Graphics/GraphicsEngine/interface/Texture.h6
-rw-r--r--Graphics/GraphicsEngine/interface/TextureView.h2
6 files changed, 174 insertions, 151 deletions
diff --git a/Graphics/GraphicsEngine/CMakeLists.txt b/Graphics/GraphicsEngine/CMakeLists.txt
index 1fc418f3..25618d84 100644
--- a/Graphics/GraphicsEngine/CMakeLists.txt
+++ b/Graphics/GraphicsEngine/CMakeLists.txt
@@ -18,6 +18,7 @@ set(INCLUDE
include/SamplerBase.h
include/ShaderBase.h
include/ShaderResourceBindingBase.h
+ include/ShaderResourceVariableBase.h
include/StateObjectsRegistry.h
include/SwapChainBase.h
include/TextureBase.h
@@ -45,6 +46,7 @@ set(INTERFACE
interface/Sampler.h
interface/Shader.h
interface/ShaderResourceBinding.h
+ interface/ShaderResourceVariable.h
interface/SwapChain.h
interface/Texture.h
interface/TextureView.h
diff --git a/Graphics/GraphicsEngine/include/ShaderBase.h b/Graphics/GraphicsEngine/include/ShaderBase.h
index ff015829..a9c1ae13 100644
--- a/Graphics/GraphicsEngine/include/ShaderBase.h
+++ b/Graphics/GraphicsEngine/include/ShaderBase.h
@@ -37,12 +37,12 @@
namespace Diligent
{
-inline SHADER_TYPE GetShaderTypeFromIndex( Int32 Index )
+inline SHADER_TYPE GetShaderTypeFromIndex(Int32 Index)
{
return static_cast<SHADER_TYPE>(1 << Index);
}
-inline Int32 GetShaderTypeIndex( SHADER_TYPE Type )
+inline Int32 GetShaderTypeIndex(SHADER_TYPE Type)
{
Int32 ShaderIndex = PlatformMisc::GetLSB(Type);
@@ -70,100 +70,6 @@ static const int HSInd = GetShaderTypeIndex(SHADER_TYPE_HULL);
static const int DSInd = GetShaderTypeIndex(SHADER_TYPE_DOMAIN);
static const int CSInd = GetShaderTypeIndex(SHADER_TYPE_COMPUTE);
-template<typename TNameCompare>
-SHADER_VARIABLE_TYPE GetShaderVariableType(SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc* VariableDesc, Uint32 NumVars, TNameCompare NameCompare)
-{
- for (Uint32 v = 0; v < NumVars; ++v)
- {
- const auto &CurrVarDesc = VariableDesc[v];
- if ( NameCompare(CurrVarDesc.Name) )
- {
- return CurrVarDesc.Type;
- }
- }
- return DefaultVariableType;
-}
-
-inline SHADER_VARIABLE_TYPE GetShaderVariableType(const Char* Name, SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc* VariableDesc, Uint32 NumVars)
-{
- return GetShaderVariableType(DefaultVariableType, VariableDesc, NumVars,
- [&](const char *VarName)
- {
- return strcmp(VarName, Name) == 0;
- }
- );
-}
-
-inline SHADER_VARIABLE_TYPE GetShaderVariableType(const Char* Name, const ShaderDesc& ShdrDesc)
-{
- return GetShaderVariableType(Name, ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables);
-}
-
-inline SHADER_VARIABLE_TYPE GetShaderVariableType(const String& Name, SHADER_VARIABLE_TYPE DefaultVariableType, const ShaderVariableDesc *VariableDesc, Uint32 NumVars)
-{
- return GetShaderVariableType(DefaultVariableType, VariableDesc, NumVars,
- [&](const char *VarName)
- {
- return Name.compare(VarName) == 0;
- }
- );
-}
-
-inline SHADER_VARIABLE_TYPE GetShaderVariableType(const String& Name, const ShaderDesc& ShdrDesc)
-{
- return GetShaderVariableType(Name, ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables);
-}
-
-
-/// Base implementation of a shader variable
-
-struct ShaderVariableBase : public IShaderVariable
-{
- ShaderVariableBase(IObject& Owner) :
- // Shader variables are always created as part of the shader, or
- // shader resource binding, so we must provide owner pointer to
- // the base class constructor
- m_Owner(Owner)
- {
- }
-
- IObject& GetOwner()
- {
- return m_Owner;
- }
-
- virtual IReferenceCounters* GetReferenceCounters()const override final
- {
- return m_Owner.GetReferenceCounters();
- }
-
- virtual Atomics::Long AddRef()override final
- {
- return m_Owner.AddRef();
- }
-
- virtual Atomics::Long Release()override final
- {
- return m_Owner.Release();
- }
-
- virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override final
- {
- if( ppInterface == nullptr )
- return;
-
- *ppInterface = nullptr;
- if( IID == IID_ShaderVariable || IID == IID_Unknown )
- {
- *ppInterface = this;
- (*ppInterface)->AddRef();
- }
- }
-
-protected:
- IObject& m_Owner;
-};
-
/// Template class implementing base functionality for a shader object
@@ -184,57 +90,12 @@ public:
/// \param ShdrDesc - shader description.
/// \param bIsDeviceInternal - flag indicating if the shader is an internal device object and
/// must not keep a strong reference to the device.
- ShaderBase( IReferenceCounters* pRefCounters, RenderDeviceImplType* pDevice, const ShaderDesc& ShdrDesc, bool bIsDeviceInternal = false ) :
- TDeviceObjectBase( pRefCounters, pDevice, ShdrDesc, bIsDeviceInternal ),
- m_VariablesDesc (ShdrDesc.NumVariables, ShaderVariableDesc(), STD_ALLOCATOR_RAW_MEM(ShaderVariableDesc, GetRawAllocator(), "Allocator for vector<ShaderVariableDesc>") ),
- m_StringPool (ShdrDesc.NumVariables + ShdrDesc.NumStaticSamplers, String(), STD_ALLOCATOR_RAW_MEM(String, GetRawAllocator(), "Allocator for vector<String>")),
- m_StaticSamplers(ShdrDesc.NumStaticSamplers, StaticSamplerDesc(), STD_ALLOCATOR_RAW_MEM(StaticSamplerDesc, GetRawAllocator(), "Allocator for vector<StaticSamplerDesc>") )
+ ShaderBase(IReferenceCounters* pRefCounters, RenderDeviceImplType* pDevice, const ShaderDesc& ShdrDesc, bool bIsDeviceInternal = false) :
+ TDeviceObjectBase(pRefCounters, pDevice, ShdrDesc, bIsDeviceInternal)
{
- auto Str = m_StringPool.begin();
- if(this->m_Desc.VariableDesc)
- {
- for (Uint32 v = 0; v < this->m_Desc.NumVariables; ++v, ++Str)
- {
- m_VariablesDesc[v] = this->m_Desc.VariableDesc[v];
- VERIFY(m_VariablesDesc[v].Name != nullptr, "Variable name not provided");
- *Str = m_VariablesDesc[v].Name;
- m_VariablesDesc[v].Name = Str->c_str();
- }
- this->m_Desc.VariableDesc = m_VariablesDesc.data();
- }
- if(this->m_Desc.StaticSamplers)
- {
- for (Uint32 s = 0; s < this->m_Desc.NumStaticSamplers; ++s, ++Str)
- {
- m_StaticSamplers[s] = this->m_Desc.StaticSamplers[s];
- VERIFY(m_StaticSamplers[s].SamplerOrTextureName != nullptr, "Static sampler or texture name is not provided");
- *Str = m_StaticSamplers[s].SamplerOrTextureName;
- m_StaticSamplers[s].SamplerOrTextureName = Str->c_str();
-#ifdef DEVELOPMENT
- const auto &BorderColor = m_StaticSamplers[s].Desc.BorderColor;
- if( !( (BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 0) ||
- (BorderColor[0] == 0 && BorderColor[1] == 0 && BorderColor[2] == 0 && BorderColor[3] == 1) ||
- (BorderColor[0] == 1 && BorderColor[1] == 1 && BorderColor[2] == 1 && BorderColor[3] == 1) ) )
- {
- LOG_WARNING_MESSAGE("Static sampler for variable \"", *Str , "\" specifies border color (", BorderColor[0], ", ", BorderColor[1], ", ", BorderColor[2], ", ", BorderColor[3], "). D3D12 static samplers only allow transparent black (0,0,0,0), opaque black (0,0,0,1) or opaque white (1,1,1,1) as border colors");
- }
-#endif
- }
- this->m_Desc.StaticSamplers = m_StaticSamplers.data();
- }
-
- VERIFY_EXPR(Str == m_StringPool.end());
}
IMPLEMENT_QUERY_INTERFACE_IN_PLACE( IID_Shader, TDeviceObjectBase )
-
-protected:
- /// Shader variable descriptions
- std::vector<ShaderVariableDesc, STDAllocatorRawMem<ShaderVariableDesc> > m_VariablesDesc;
- /// String pool that is used to hold copies of variable names and static sampler names
- std::vector<String, STDAllocatorRawMem<String> > m_StringPool;
- /// Static sampler descriptions
- std::vector<StaticSamplerDesc, STDAllocatorRawMem<StaticSamplerDesc> > m_StaticSamplers;
};
}
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h
new file mode 100644
index 00000000..5c5629d3
--- /dev/null
+++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h
@@ -0,0 +1,161 @@
+/* Copyright 2015-2019 Egor Yusov
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
+ *
+ * In no event and under no legal theory, whether in tort (including negligence),
+ * contract, or otherwise, unless required by applicable law (such as deliberate
+ * and grossly negligent acts) or agreed to in writing, shall any Contributor be
+ * liable for any damages, including any direct, indirect, special, incidental,
+ * or consequential damages of any character arising as a result of this License or
+ * out of the use or inability to use the software (including but not limited to damages
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
+ * all other commercial damages or losses), even if such Contributor has been advised
+ * of the possibility of such damages.
+ */
+
+#pragma once
+
+/// \file
+/// Implementation of the Diligent::ShaderBase template class
+
+#include <vector>
+
+#include "ShaderResourceVariable.h"
+#include "PipelineState.h"
+
+namespace Diligent
+{
+
+template<typename TNameCompare>
+SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType(SHADER_TYPE ShaderStage,
+ SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType,
+ const ShaderResourceVariableDesc* Variables,
+ Uint32 NumVars,
+ TNameCompare NameCompare)
+{
+ for (Uint32 v = 0; v < NumVars; ++v)
+ {
+ const auto& CurrVarDesc = Variables[v];
+ if ( ((CurrVarDesc.ShaderStages & ShaderStage) != 0) && NameCompare(CurrVarDesc.Name) )
+ {
+ return CurrVarDesc.Type;
+ }
+ }
+ return DefaultVariableType;
+}
+
+inline SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType(SHADER_TYPE ShaderStage,
+ const Char* Name,
+ SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType,
+ const ShaderResourceVariableDesc* Variables,
+ Uint32 NumVars)
+{
+ return GetShaderVariableType(ShaderStage, DefaultVariableType, Variables, NumVars,
+ [&](const char* VarName)
+ {
+ return strcmp(VarName, Name) == 0;
+ }
+ );
+}
+
+inline SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType(SHADER_TYPE ShaderStage,
+ const Char* Name,
+ const PipelineLayoutDesc& LayoutDesc)
+{
+ return GetShaderVariableType(ShaderStage, Name, LayoutDesc.DefaultVariableType, LayoutDesc.Variables, LayoutDesc.NumVariables);
+}
+
+inline SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType(SHADER_TYPE ShaderStage,
+ const String& Name,
+ SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType,
+ const ShaderResourceVariableDesc* Variables,
+ Uint32 NumVars)
+{
+ return GetShaderVariableType(ShaderStage, DefaultVariableType, Variables, NumVars,
+ [&](const char* VarName)
+ {
+ return Name.compare(VarName) == 0;
+ }
+ );
+}
+
+inline SHADER_RESOURCE_VARIABLE_TYPE GetShaderVariableType(SHADER_TYPE ShaderStage,
+ const String& Name,
+ const PipelineLayoutDesc& LayoutDesc)
+{
+ return GetShaderVariableType(ShaderStage, Name, LayoutDesc.DefaultVariableType, LayoutDesc.Variables, LayoutDesc.NumVariables);
+}
+
+inline bool IsAllowedType(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 AllowedTypeBits)noexcept
+{
+ return ((1 << VarType) & AllowedTypeBits) != 0;
+}
+
+inline Uint32 GetAllowedTypeBits(const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes)noexcept
+{
+ if(AllowedVarTypes == nullptr)
+ return 0xFFFFFFFF;
+
+ Uint32 AllowedTypeBits = 0;
+ for(Uint32 i=0; i < NumAllowedTypes; ++i)
+ AllowedTypeBits |= 1 << AllowedVarTypes[i];
+ return AllowedTypeBits;
+}
+
+/// Base implementation of a shader variable
+struct ShaderVariableBase : public IShaderResourceVariable
+{
+ ShaderVariableBase(IObject& Owner) :
+ // Shader variables are always created as part of the shader, or
+ // shader resource binding, so we must provide owner pointer to
+ // the base class constructor
+ m_Owner(Owner)
+ {
+ }
+
+ IObject& GetOwner()
+ {
+ return m_Owner;
+ }
+
+ virtual IReferenceCounters* GetReferenceCounters()const override final
+ {
+ return m_Owner.GetReferenceCounters();
+ }
+
+ virtual Atomics::Long AddRef()override final
+ {
+ return m_Owner.AddRef();
+ }
+
+ virtual Atomics::Long Release()override final
+ {
+ return m_Owner.Release();
+ }
+
+ virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override final
+ {
+ if( ppInterface == nullptr )
+ return;
+
+ *ppInterface = nullptr;
+ if( IID == IID_ShaderResourceVariable || IID == IID_Unknown )
+ {
+ *ppInterface = this;
+ (*ppInterface)->AddRef();
+ }
+ }
+
+protected:
+ IObject& m_Owner;
+};
+
+}
diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h
index c844df8a..fd10f17c 100644
--- a/Graphics/GraphicsEngine/interface/RenderDevice.h
+++ b/Graphics/GraphicsEngine/interface/RenderDevice.h
@@ -80,14 +80,13 @@ public:
/// Creates a new shader object
- /// \param [in] CreationAttribs - Shader creation attributes, see
- /// Diligent::ShaderCreationAttribs for details.
+ /// \param [in] ShaderCI - Shader create info, see Diligent::ShaderCreateInfo for details.
/// \param [out] ppShader - Address of the memory location where the pointer to the
/// shader interface will be stored.
/// The function calls AddRef(), so that the new object will contain
/// one refernce.
- virtual void CreateShader(const ShaderCreationAttribs& CreationAttribs,
- IShader** ppShader) = 0;
+ virtual void CreateShader(const ShaderCreateInfo& ShaderCI,
+ IShader** ppShader) = 0;
/// Creates a new texture object
diff --git a/Graphics/GraphicsEngine/interface/Texture.h b/Graphics/GraphicsEngine/interface/Texture.h
index 7c3cb941..a1b56ed9 100644
--- a/Graphics/GraphicsEngine/interface/Texture.h
+++ b/Graphics/GraphicsEngine/interface/Texture.h
@@ -273,7 +273,7 @@ class ITexture : public IDeviceObject
{
public:
/// Queries the specific interface, see IObject::QueryInterface() for details
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) = 0;
/// Returns the texture description used to create the object
virtual const TextureDesc& GetDesc()const = 0;
@@ -297,7 +297,7 @@ public:
/// until all views are released.\n
/// The function calls AddRef() for the created interface, so it must be released by
/// a call to Release() when it is no longer needed.
- virtual void CreateView(const struct TextureViewDesc &ViewDesc, class ITextureView **ppView) = 0;
+ virtual void CreateView(const struct TextureViewDesc& ViewDesc, class ITextureView** ppView) = 0;
/// Returns the pointer to the default view.
@@ -306,7 +306,7 @@ public:
///
/// \note The function does not increase the reference counter for the returned interface, so
/// Release() must *NOT* be called.
- virtual ITextureView* GetDefaultView( TEXTURE_VIEW_TYPE ViewType ) = 0;
+ virtual ITextureView* GetDefaultView(TEXTURE_VIEW_TYPE ViewType) = 0;
/// Returns native texture handle specific to the underlying graphics API
diff --git a/Graphics/GraphicsEngine/interface/TextureView.h b/Graphics/GraphicsEngine/interface/TextureView.h
index d77cf87a..84df8ce4 100644
--- a/Graphics/GraphicsEngine/interface/TextureView.h
+++ b/Graphics/GraphicsEngine/interface/TextureView.h
@@ -163,7 +163,7 @@ class ITextureView : public IDeviceObject
{
public:
/// Queries the specific interface, see IObject::QueryInterface() for details
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0;
+ virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface ) = 0;
/// Returns the texture view description used to create the object
virtual const TextureViewDesc& GetDesc()const = 0;