summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-08-03 09:08:53 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-08-03 09:08:53 +0000
commit6585bec7cae42818f633b248c5b42b8355e02283 (patch)
tree56b73a3e3e883b8ed2223efd915c6e91a2632bef /Graphics/GraphicsEngineVulkan
parentCouple fixes to Vulkan upload heap (diff)
downloadDiligentCore-6585bec7cae42818f633b248c5b42b8355e02283.tar.gz
DiligentCore-6585bec7cae42818f633b248c5b42b8355e02283.zip
Implemented shader variable access by index;
Fixed issues with UAV binding in D3D11; Improved shader resource layout in D3D12
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h12
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h27
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h6
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp2
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp30
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp30
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp11
7 files changed, 108 insertions, 10 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h
index 34186c61..23264799 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.h
@@ -40,7 +40,7 @@ class FixedBlockMemoryAllocator;
/// Implementation of the Diligent::IShaderResourceBindingVk interface
// sizeof(ShaderResourceBindingVkImpl) == 80 (x64, msvc, Release)
-class ShaderResourceBindingVkImpl : public ShaderResourceBindingBase<IShaderResourceBindingVk>
+class ShaderResourceBindingVkImpl final : public ShaderResourceBindingBase<IShaderResourceBindingVk>
{
public:
using TBase = ShaderResourceBindingBase<IShaderResourceBindingVk>;
@@ -48,11 +48,15 @@ public:
ShaderResourceBindingVkImpl(IReferenceCounters* pRefCounters, class PipelineStateVkImpl* pPSO, bool IsPSOInternal);
~ShaderResourceBindingVkImpl();
- virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface )override;
+ virtual void QueryInterface( const Diligent::INTERFACE_ID& IID, IObject** ppInterface )override final;
- virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)override;
+ virtual void BindResources(Uint32 ShaderFlags, IResourceMapping* pResMapping, Uint32 Flags)override final;
- virtual IShaderVariable *GetVariable(SHADER_TYPE ShaderType, const char *Name)override;
+ virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, const char* Name)override final;
+
+ virtual Uint32 GetVariableCount(SHADER_TYPE ShaderType) const override final;
+
+ virtual IShaderVariable* GetVariable(SHADER_TYPE ShaderType, Uint32 Index)override final;
ShaderResourceCacheVk& GetResourceCache(){return m_ShaderResourceCache;}
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h
index d531084b..5071b857 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.h
@@ -82,6 +82,7 @@ public:
void Destroy(IMemoryAllocator& Allocator);
ShaderVariableVkImpl* GetVariable(const Char* Name);
+ ShaderVariableVkImpl* GetVariable(Uint32 Index);
void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags);
@@ -90,9 +91,13 @@ public:
Uint32 NumAllowedTypes,
Uint32& NumVariables);
+ Uint32 GetVariableCount()const { return m_NumVariables; }
+
private:
friend ShaderVariableVkImpl;
+ Uint32 GetVariableIndex(const ShaderVariableVkImpl& Variable);
+
IObject& m_Owner;
// Variable mgr is owned by either Shader object (in which case m_pResourceLayout points to
// static resource layout owned by the same shader object), or by SRB object (in which case
@@ -113,7 +118,7 @@ private:
};
// sizeof(ShaderVariableVkImpl) == 24 (x64)
-class ShaderVariableVkImpl : public IShaderVariable
+class ShaderVariableVkImpl final : public IShaderVariable
{
public:
ShaderVariableVkImpl(ShaderVariableManagerVk& ParentManager,
@@ -156,6 +161,11 @@ public:
}
}
+ virtual SHADER_VARIABLE_TYPE GetType()const override final
+ {
+ return m_Resource.SpirvAttribs.VarType;
+ }
+
virtual void Set(IDeviceObject *pObject)override final
{
VERIFY_EXPR(m_ParentManager.m_pResourceCache != nullptr);
@@ -169,6 +179,21 @@ public:
m_Resource.BindResource(ppObjects[Elem], FirstElement + Elem, *m_ParentManager.m_pResourceCache);
}
+ virtual Uint32 GetArraySize()const override final
+ {
+ return m_Resource.SpirvAttribs.ArraySize;
+ }
+
+ virtual const Char* GetName()const override final
+ {
+ return m_Resource.SpirvAttribs.Name;
+ }
+
+ virtual Uint32 GetIndex()const override final
+ {
+ return m_ParentManager.GetVariableIndex(*this);
+ }
+
const ShaderResourceLayoutVk::VkResource& GetResource()const
{
return m_Resource;
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
index c091a46a..9daeb665 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h
@@ -41,7 +41,7 @@ class ResourceMapping;
class FixedBlockMemoryAllocator;
/// Implementation of the Diligent::IShaderVk interface
-class ShaderVkImpl : public ShaderBase<IShaderVk, RenderDeviceVkImpl>
+class ShaderVkImpl final : public ShaderBase<IShaderVk, RenderDeviceVkImpl>
{
public:
using TShaderBase = ShaderBase<IShaderVk, RenderDeviceVkImpl>;
@@ -55,6 +55,10 @@ public:
virtual IShaderVariable* GetShaderVariable(const Char* Name)override;
+ virtual Uint32 GetVariableCount() const override final;
+
+ virtual IShaderVariable* GetShaderVariable(Uint32 Index)override final;
+
virtual const std::vector<uint32_t>& GetSPIRV()const override final
{
return m_SPIRV;
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
index f3c60eb2..399adcbc 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp
@@ -157,7 +157,7 @@ PipelineStateVkImpl :: PipelineStateVkImpl(IReferenceCounters* pRefCounters
std::array<size_t, MaxShadersInPipeline> ShaderVariableDataSizes = {};
for (Uint32 s = 0; s < m_NumShaders; ++s)
{
- std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_STATIC, SHADER_VARIABLE_TYPE_MUTABLE };
+ std::array<SHADER_VARIABLE_TYPE, 2> AllowedVarTypes = { SHADER_VARIABLE_TYPE_MUTABLE, SHADER_VARIABLE_TYPE_DYNAMIC };
Uint32 UnusedNumVars = 0;
ShaderVariableDataSizes[s] = ShaderVariableManagerVk::GetRequiredMemorySize(m_ShaderResourceLayouts[s], AllowedVarTypes.data(), static_cast<Uint32>(AllowedVarTypes.size()), UnusedNumVars);
}
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
index 4d1f1015..0d13319e 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp
@@ -101,19 +101,19 @@ void ShaderResourceBindingVkImpl::BindResources(Uint32 ShaderFlags, IResourceMap
}
}
-IShaderVariable *ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType, const char *Name)
+IShaderVariable* ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType, const char *Name)
{
auto ShaderInd = GetShaderTypeIndex(ShaderType);
auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
if (ResLayoutInd < 0)
{
- LOG_ERROR_MESSAGE("Failed to find variable \"", Name,"\" in shader resource binding: shader type ", GetShaderTypeLiteralName(ShaderType), " is not initialized");
+ LOG_ERROR("Failed to find variable \"", Name,"\" in shader resource binding: shader type ", GetShaderTypeLiteralName(ShaderType), " is not initialized");
return ValidatedCast<PipelineStateVkImpl>(GetPipelineState())->GetDummyShaderVar();
}
auto *pVar = m_pShaderVarMgrs[ResLayoutInd].GetVariable(Name);
if(pVar == nullptr)
{
- LOG_ERROR_MESSAGE("Failed to find variable \"", Name,"\" in shader resource binding. Note that only dynamic and mutable variables can be accessed through SRB object.");
+ 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<PipelineStateVkImpl>(GetPipelineState())->GetDummyShaderVar();
}
else
@@ -123,4 +123,28 @@ IShaderVariable *ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType
}
}
+Uint32 ShaderResourceBindingVkImpl::GetVariableCount(SHADER_TYPE ShaderType) const
+{
+ auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
+ if (ResLayoutInd < 0)
+ {
+ LOG_ERROR("Unable to get the number of varibles for shader type ", GetShaderTypeLiteralName(ShaderType), ": shader stage is not initialized");
+ return 0;
+ }
+ return m_pShaderVarMgrs[ResLayoutInd].GetVariableCount();
+}
+
+IShaderVariable* ShaderResourceBindingVkImpl::GetVariable(SHADER_TYPE ShaderType, Uint32 Index)
+{
+ auto ShaderInd = GetShaderTypeIndex(ShaderType);
+ auto ResLayoutInd = m_ResourceLayoutIndex[ShaderInd];
+ 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<PipelineStateVkImpl>(GetPipelineState())->GetDummyShaderVar();
+ }
+ return m_pShaderVarMgrs[ResLayoutInd].GetVariable(Index);
+}
+
}
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp
index 15107306..f1019e7c 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp
@@ -118,6 +118,36 @@ ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(const Char* Name)
}
+ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(Uint32 Index)
+{
+ if (Index >= m_NumVariables)
+ {
+ LOG_ERROR("Index ", Index, " is out of range");
+ return nullptr;
+ }
+
+ return m_pVariables + Index;
+}
+
+Uint32 ShaderVariableManagerVk::GetVariableIndex(const ShaderVariableVkImpl& Variable)
+{
+ if (m_pVariables == nullptr)
+ {
+ LOG_ERROR("This shader variable manager has no variables");
+ return static_cast<Uint32>(-1);
+ }
+
+ auto Offset = reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<Uint8*>(m_pVariables);
+ VERIFY(Offset % sizeof(ShaderVariableVkImpl) == 0, "Offset is not multiple of ShaderVariableVkImpl class size");
+ auto Index = static_cast<Uint32>(Offset / sizeof(ShaderVariableVkImpl));
+ if (Index < m_NumVariables)
+ return Index;
+ else
+ {
+ LOG_ERROR("Failed to get variable index. The variable ", &Variable, " does not belong to this shader variable manager");
+ return static_cast<Uint32>(-1);
+ }
+}
void ShaderVariableManagerVk::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags)
{
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index 1d6bd8e9..0db36dee 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -86,6 +86,17 @@ IShaderVariable* ShaderVkImpl::GetShaderVariable(const Char* Name)
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()
{