summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-25 03:23:36 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:11 +0000
commitd40df7d9e6b15c3aac87fe78d2bafd3f868c5352 (patch)
treeb882e513037a33569eb3fe82d247d77c2151db45 /Graphics/GraphicsEngineVulkan
parentSome updates to ShaderVariableD3D12 (diff)
downloadDiligentCore-d40df7d9e6b15c3aac87fe78d2bafd3f868c5352.tar.gz
DiligentCore-d40df7d9e6b15c3aac87fe78d2bafd3f868c5352.zip
Reworked ShaderVariableVkImpl and ShaderVariableD3D12Impl: removed some duplicate code
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp63
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp79
2 files changed, 33 insertions, 109 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp
index d0a5bb41..1bab5a48 100644
--- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp
+++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp
@@ -103,6 +103,8 @@ public:
Uint32 GetVariableCount() const { return m_NumVariables; }
+ IObject& GetOwner() { return m_Owner; }
+
private:
friend ShaderVariableVkImpl;
using ResourceAttribs = PipelineResourceSignatureVkImpl::ResourceAttribs;
@@ -150,12 +152,14 @@ private:
};
// sizeof(ShaderVariableVkImpl) == 24 (x64)
-class ShaderVariableVkImpl final : public IShaderResourceVariable
+class ShaderVariableVkImpl final : public ShaderVariableBase<ShaderVariableManagerVk, IShaderResourceVariable>
{
public:
+ using TBase = ShaderVariableBase<ShaderVariableManagerVk, IShaderResourceVariable>;
+
ShaderVariableVkImpl(ShaderVariableManagerVk& ParentManager,
Uint32 ResIndex) :
- m_ParentManager{ParentManager},
+ TBase{ParentManager},
m_ResIndex{ResIndex}
{}
@@ -166,41 +170,15 @@ public:
ShaderVariableVkImpl& operator= (ShaderVariableVkImpl&&) = delete;
// clang-format on
-
- virtual IReferenceCounters* DILIGENT_CALL_TYPE GetReferenceCounters() const override final
- {
- return m_ParentManager.m_Owner.GetReferenceCounters();
- }
-
- virtual Atomics::Long DILIGENT_CALL_TYPE AddRef() override final
- {
- return m_ParentManager.m_Owner.AddRef();
- }
-
- virtual Atomics::Long DILIGENT_CALL_TYPE Release() override final
- {
- return m_ParentManager.m_Owner.Release();
- }
-
- void DILIGENT_CALL_TYPE 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();
- }
- }
-
virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final
{
return GetDesc().VarType;
}
- virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final;
+ virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final
+ {
+ BindResource(pObject, 0);
+ }
virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects,
Uint32 FirstElement,
@@ -219,20 +197,25 @@ public:
return m_ParentManager.GetVariableIndex(*this);
}
- virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final;
+ virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
+ {
+ return m_ParentManager.m_pSignature->IsBound(ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache);
+ }
+
+ const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); }
+
+ void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const
+ {
+ m_ParentManager.m_pSignature->BindResource(pObj, ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache);
+ }
private:
- friend ShaderVariableManagerVk;
using ResourceAttribs = PipelineResourceSignatureVkImpl::ResourceAttribs;
- const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); }
- const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetAttribs(m_ResIndex); }
-
- void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const;
+ const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetAttribs(m_ResIndex); }
private:
- ShaderVariableManagerVk& m_ParentManager;
- const Uint32 m_ResIndex; // Index in Signatures' m_Desc.Resources
+ const Uint32 m_ResIndex; // Index in Signatures' m_Desc.Resources
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp
index 9628fbd7..2fd071f6 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp
@@ -142,18 +142,13 @@ void ShaderVariableManagerVk::DestroyVariables(IMemoryAllocator& Allocator)
ShaderVariableVkImpl* ShaderVariableManagerVk::GetVariable(const Char* Name) const
{
- ShaderVariableVkImpl* pVar = nullptr;
for (Uint32 v = 0; v < m_NumVariables; ++v)
{
- auto& Var = m_pVariables[v];
- const auto& Res = Var.GetDesc();
- if (strcmp(Res.Name, Name) == 0)
- {
- pVar = &Var;
- break;
- }
+ auto& Var = m_pVariables[v];
+ if (strcmp(Var.GetDesc().Name, Name) == 0)
+ return &Var;
}
- return pVar;
+ return nullptr;
}
@@ -173,18 +168,18 @@ Uint32 ShaderVariableManagerVk::GetVariableIndex(const ShaderVariableVkImpl& Var
if (m_pVariables == nullptr)
{
LOG_ERROR("This shader variable manager has no variables");
- return static_cast<Uint32>(-1);
+ return ~0u;
}
- 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));
+ const auto Offset = reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<Uint8*>(m_pVariables);
+ DEV_CHECK_ERR(Offset % sizeof(ShaderVariableVkImpl) == 0, "Offset is not multiple of ShaderVariableVkImpl class size");
+ const 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);
+ return ~0u;
}
}
@@ -201,48 +196,10 @@ void ShaderVariableManagerVk::BindResources(IResourceMapping* pResourceMapping,
for (Uint32 v = 0; v < m_NumVariables; ++v)
{
- auto& Var = m_pVariables[v];
- const auto& Res = Var.GetDesc();
- const auto& Attr = Var.GetAttribs();
-
- // There should be no immutable separate samplers
- VERIFY(Attr.GetDescriptorType() != DescriptorType::Sampler || !Attr.IsImmutableSamplerAssigned(),
- "There must be no shader resource variables for immutable separate samplers");
-
- if ((Flags & (1u << Res.VarType)) == 0)
- continue;
-
- for (Uint32 ArrInd = 0; ArrInd < Res.ArraySize; ++ArrInd)
- {
- if ((Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) && Var.IsBound(ArrInd))
- continue;
-
- const auto* VarName = Res.Name;
- RefCntAutoPtr<IDeviceObject> pObj;
- pResourceMapping->GetResource(VarName, &pObj, ArrInd);
- if (pObj)
- {
- Var.BindResource(pObj, ArrInd);
- }
- else
- {
- if ((Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !Var.IsBound(ArrInd))
- {
- LOG_ERROR_MESSAGE("Unable to bind resource to shader variable '",
- GetShaderResourcePrintName(Res, ArrInd),
- "': resource is not found in the resource mapping. "
- "Do not use BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED flag to suppress the message if this is not an issue.");
- }
- }
- }
+ m_pVariables[v].BindResources<ShaderVariableVkImpl>(pResourceMapping, Flags);
}
}
-void ShaderVariableVkImpl::Set(IDeviceObject* pObject)
-{
- BindResource(pObject, 0);
-}
-
void ShaderVariableVkImpl::SetArray(IDeviceObject* const* ppObjects,
Uint32 FirstElement,
Uint32 NumElements)
@@ -254,20 +211,4 @@ void ShaderVariableVkImpl::SetArray(IDeviceObject* const* ppObjects,
BindResource(ppObjects[Elem], FirstElement + Elem);
}
-bool ShaderVariableVkImpl::IsBound(Uint32 ArrayIndex) const
-{
- auto* pSignature = m_ParentManager.m_pSignature;
- auto& ResourceCache = m_ParentManager.m_ResourceCache;
-
- return pSignature->IsBound(ArrayIndex, m_ResIndex, ResourceCache);
-}
-
-void ShaderVariableVkImpl::BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const
-{
- auto* pSignature = m_ParentManager.m_pSignature;
- auto& ResourceCache = m_ParentManager.m_ResourceCache;
-
- pSignature->BindResource(pObj, ArrayIndex, m_ResIndex, ResourceCache);
-}
-
} // namespace Diligent