summaryrefslogtreecommitdiffstats
path: root/Graphics
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
parentSome updates to ShaderVariableD3D12 (diff)
downloadDiligentCore-d40df7d9e6b15c3aac87fe78d2bafd3f868c5352.tar.gz
DiligentCore-d40df7d9e6b15c3aac87fe78d2bafd3f868c5352.zip
Reworked ShaderVariableVkImpl and ShaderVariableD3D12Impl: removed some duplicate code
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp63
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp110
-rw-r--r--Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp79
-rw-r--r--Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp3
-rw-r--r--Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp4
-rw-r--r--Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp4
-rw-r--r--Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp36
-rw-r--r--Graphics/GraphicsEngineD3DBase/interface/ShaderResourceVariableD3D.h2
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderVariableVk.hpp63
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVariableVk.cpp79
11 files changed, 160 insertions, 285 deletions
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp
index edd850d1..7b8115a9 100644
--- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp
+++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp
@@ -492,32 +492,23 @@ std::string GetShaderGroupName(const ShaderVectorType& Shaders)
return Name;
}
-struct DefaultShaderVariableIDComparator
-{
- bool operator()(const INTERFACE_ID& IID) const
- {
- return IID == IID_ShaderResourceVariable || IID == IID_Unknown;
- } // namespace Diligent
-};
-
/// Base implementation of a shader variable
-template <typename ResourceLayoutType,
- typename ResourceVariableBaseInterface = IShaderResourceVariable,
- typename VariableIDComparator = DefaultShaderVariableIDComparator>
+template <typename VarManagerType,
+ typename ResourceVariableBaseInterface = IShaderResourceVariable>
struct ShaderVariableBase : public ResourceVariableBaseInterface
{
- ShaderVariableBase(ResourceLayoutType& ParentResLayout) :
- m_ParentResLayout{ParentResLayout}
+ ShaderVariableBase(VarManagerType& ParentManager) :
+ m_ParentManager{ParentManager}
{
}
- virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final
+ virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override
{
if (ppInterface == nullptr)
return;
*ppInterface = nullptr;
- if (VariableIDComparator{}(IID))
+ if (IID == IID_ShaderResourceVariable || IID == IID_Unknown)
{
*ppInterface = this;
(*ppInterface)->AddRef();
@@ -526,21 +517,55 @@ struct ShaderVariableBase : public ResourceVariableBaseInterface
virtual Atomics::Long DILIGENT_CALL_TYPE AddRef() override final
{
- return m_ParentResLayout.GetOwner().AddRef();
+ return m_ParentManager.GetOwner().AddRef();
}
virtual Atomics::Long DILIGENT_CALL_TYPE Release() override final
{
- return m_ParentResLayout.GetOwner().Release();
+ return m_ParentManager.GetOwner().Release();
}
virtual IReferenceCounters* DILIGENT_CALL_TYPE GetReferenceCounters() const override final
{
- return m_ParentResLayout.GetOwner().GetReferenceCounters();
+ return m_ParentManager.GetOwner().GetReferenceCounters();
+ }
+
+ template <typename ThisImplType>
+ void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags)
+ {
+ auto* const pThis = static_cast<ThisImplType*>(this);
+
+ const auto& ResDesc = pThis->GetDesc();
+
+ if ((Flags & (1u << ResDesc.VarType)) == 0)
+ return;
+
+ for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd)
+ {
+ if ((Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) != 0 && pThis->IsBound(ArrInd))
+ continue;
+
+ RefCntAutoPtr<IDeviceObject> pObj;
+ pResourceMapping->GetResource(ResDesc.Name, &pObj, ArrInd);
+ if (pObj)
+ {
+ pThis->BindResource(pObj, ArrInd);
+ }
+ else
+ {
+ if ((Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !pThis->IsBound(ArrInd))
+ {
+ LOG_ERROR_MESSAGE("Unable to bind resource to shader variable '",
+ GetShaderResourcePrintName(ResDesc, 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.");
+ }
+ }
+ }
}
protected:
- ResourceLayoutType& m_ParentResLayout;
+ VarManagerType& m_ParentManager;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp
index 6448ebd1..5923c5b8 100644
--- a/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/ShaderVariableD3D12.hpp
@@ -37,29 +37,27 @@
// * ShaderVariableManagerD3D12 is used by PipelineResourceSignatureD3D12Impl to manage static resources and by
// ShaderResourceBindingD3D12Impl to manage mutable and dynamic resources
//
-// _____________________________ ________________________________________________________________________________
-// | | | | | |
-// .----| ShaderVariableManagerD3D12 |---------------->| ShaderVariableD3D12Impl[0] | ShaderVariableD3D12Impl[1] | ... |
-// | |_____________________________| |______________________________|_______________________________|_________________|
-// | | | |
-// | | m_ResIndex m_ResIndex
-// | | | |
-// | _____________V____________________ __________V_______________________________V_________________________________
-// | | | m_pResourceAttribs | | | | |
-// | |PipelineResourceSignatureD3D12Impl|------------------->| Resource[0] | Resource[1] | ... | Resource[s+m+d-1] |
-// | |__________________________________| |__________________|__________________|_____________|________________________|
-// | | |
-// | | |
-// | | (RootTable, Offset) / (RootTable, Offset)
-// | \ /
-// | __________________________ _______________V________________________________________________V_______
-// | | | | |
-// '--->| ShaderResourceCacheD3D12 |---------------->| Resources |
-// |__________________________| |________________________________________________________________________|
+// _____________________________ ________________________________________________________________________________
+// | | | | | |
+// .----| ShaderVariableManagerD3D12 |---------------->| ShaderVariableD3D12Impl[0] | ShaderVariableD3D12Impl[1] | ... |
+// | |_____________________________| |______________________________|_______________________________|_________________|
+// | | | |
+// | m_pSignature m_ResIndex m_ResIndex
+// | | | |
+// | _____________V____________________ __________V_______________________________V_________________________________
+// | | | m_pResourceAttribs | | | | |
+// | |PipelineResourceSignatureD3D12Impl|------------------->| Resource[0] | Resource[1] | ... | Resource[s+m+d-1] |
+// | |__________________________________| |__________________|__________________|_____________|________________________|
+// | | |
+// m_ResourceCache | |
+// | | (RootTable, Offset) / (RootTable, Offset)
+// | \ /
+// | __________________________ _______________V________________________________________________V_______
+// | | | | |
+// '--->| ShaderResourceCacheD3D12 |---------------->| Resources |
+// |__________________________| |________________________________________________________________________|
//
-#include <memory>
-
#include "ShaderResourceVariableD3D.h"
#include "ShaderResourceVariableBase.hpp"
#include "ShaderResourceCacheD3D12.hpp"
@@ -109,6 +107,8 @@ public:
Uint32 GetVariableCount() const { return m_NumVariables; }
+ IObject& GetOwner() { return m_Owner; }
+
private:
friend ShaderVariableD3D12Impl;
using ResourceAttribs = PipelineResourceSignatureD3D12Impl::ResourceAttribs;
@@ -117,12 +117,12 @@ private:
const PipelineResourceDesc& GetResourceDesc(Uint32 Index) const
{
- VERIFY_EXPR(m_pSignature);
+ VERIFY_EXPR(m_pSignature != nullptr);
return m_pSignature->GetResourceDesc(Index);
}
const ResourceAttribs& GetResourceAttribs(Uint32 Index) const
{
- VERIFY_EXPR(m_pSignature);
+ VERIFY_EXPR(m_pSignature != nullptr);
return m_pSignature->GetResourceAttribs(Index);
}
@@ -138,9 +138,9 @@ private:
IObject& m_Owner;
- // Variable mgr is owned by either Pipeline Resource Signature (in which case m_ResourceCache references
+ // Variable manager is owned by either Pipeline Resource Signature (in which case m_ResourceCache references
// static resource cache owned by the same signature object), or by SRB object (in which case
- // m_ResourceCache references the cache in the SRB). Thus the cache and the resource layout
+ // m_ResourceCache references the cache in the SRB). Thus the cache and the signature
// (which the variables reference) are guaranteed to be alive while the manager is alive.
ShaderResourceCacheD3D12& m_ResourceCache;
@@ -156,12 +156,13 @@ private:
};
// sizeof(ShaderVariableD3D12Impl) == 24 (x64)
-class ShaderVariableD3D12Impl final : public IShaderResourceVariableD3D
+class ShaderVariableD3D12Impl final : public ShaderVariableBase<ShaderVariableManagerD3D12, IShaderResourceVariableD3D>
{
public:
+ using TBase = ShaderVariableBase<ShaderVariableManagerD3D12, IShaderResourceVariableD3D>;
ShaderVariableD3D12Impl(ShaderVariableManagerD3D12& ParentManager,
Uint32 ResIndex) :
- m_ParentManager{ParentManager},
+ TBase{ParentManager},
m_ResIndex{ResIndex}
{}
@@ -172,21 +173,6 @@ public:
ShaderVariableD3D12Impl& operator= (ShaderVariableD3D12Impl&&) = 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();
- }
-
virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final
{
if (ppInterface == nullptr)
@@ -205,7 +191,10 @@ public:
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, Uint32 NumElements) override final;
@@ -222,33 +211,30 @@ public:
return m_ParentManager.GetVariableIndex(*this);
}
- virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final;
-
- virtual HLSLShaderResourceDesc DILIGENT_CALL_TYPE GetHLSLResourceDesc() const override final
+ virtual bool DILIGENT_CALL_TYPE IsBound(Uint32 ArrayIndex) const override final
{
- const auto& ResDesc = GetDesc();
- const auto& ResAttribs = GetAttribs();
-
- HLSLShaderResourceDesc HLSLResDesc;
- HLSLResDesc.Name = ResDesc.Name;
- HLSLResDesc.Type = ResDesc.ResourceType;
- HLSLResDesc.ArraySize = ResDesc.ArraySize;
- HLSLResDesc.ShaderRegister = ResAttribs.Register;
- return HLSLResDesc;
+ return m_ParentManager.m_pSignature->IsBound(ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache);
}
-private:
- friend ShaderVariableManagerD3D12;
- using ResourceAttribs = PipelineResourceSignatureD3D12Impl::ResourceAttribs;
+ virtual void DILIGENT_CALL_TYPE GetHLSLResourceDesc(HLSLShaderResourceDesc& HLSLResDesc) const override final
+ {
+ GetResourceDesc(HLSLResDesc);
+ HLSLResDesc.ShaderRegister = GetAttribs().Register;
+ }
const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); }
- const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetResourceAttribs(m_ResIndex); }
- void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const;
+ void BindResource(IDeviceObject* pObj, Uint32 ArrayIndex) const
+ {
+ m_ParentManager.m_pSignature->BindResource(pObj, ArrayIndex, m_ResIndex, m_ParentManager.m_ResourceCache);
+ }
+
+private:
+ using ResourceAttribs = PipelineResourceSignatureD3D12Impl::ResourceAttribs;
+ const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetResourceAttribs(m_ResIndex); }
private:
- ShaderVariableManagerD3D12& m_ParentManager;
- const Uint32 m_ResIndex;
+ const Uint32 m_ResIndex;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp
index 475c9661..203af1fe 100644
--- a/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp
+++ b/Graphics/GraphicsEngineD3D12/include/TextureD3D12Impl.hpp
@@ -98,8 +98,6 @@ protected:
void CreateUAV(TextureViewDesc& UAVDesc, D3D12_CPU_DESCRIPTOR_HANDLE UAVHandle);
D3D12_PLACED_SUBRESOURCE_FOOTPRINT* m_StagingFootprints = nullptr;
-
- friend class RenderDeviceD3D12Impl;
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
index d106388e..c7ee4cdc 100644
--- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableD3D12.cpp
@@ -28,7 +28,6 @@
#include "pch.h"
#include "ShaderVariableD3D12.hpp"
-#include "ShaderResourceVariableBase.hpp"
#include "RenderDeviceD3D12Impl.hpp"
namespace Diligent
@@ -42,7 +41,7 @@ void ShaderVariableManagerD3D12::ProcessSignatureResources(const PipelineResourc
HandlerType Handler)
{
const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
- const bool UsingSeparateSamplers = Signature.IsUsingSeparateSamplers();
+ const bool UsingCombinedSamplers = Signature.IsUsingCombinedSamplers();
for (SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; VarType < SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES; VarType = static_cast<SHADER_RESOURCE_VARIABLE_TYPE>(VarType + 1))
{
@@ -59,7 +58,7 @@ void ShaderVariableManagerD3D12::ProcessSignatureResources(const PipelineResourc
continue;
if (Res.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER &&
- (!UsingSeparateSamplers || Attr.IsImmutableSamplerAssigned()))
+ (UsingCombinedSamplers || Attr.IsImmutableSamplerAssigned()))
continue;
Handler(r);
@@ -137,18 +136,13 @@ void ShaderVariableManagerD3D12::Destroy(IMemoryAllocator& Allocator)
ShaderVariableD3D12Impl* ShaderVariableManagerD3D12::GetVariable(const Char* Name) const
{
- ShaderVariableD3D12Impl* 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;
}
@@ -168,18 +162,18 @@ Uint32 ShaderVariableManagerD3D12::GetVariableIndex(const ShaderVariableD3D12Imp
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(ShaderVariableD3D12Impl) == 0, "Offset is not multiple of ShaderVariableD3D12Impl class size");
+ const auto Offset = reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<Uint8*>(m_pVariables);
+ DEV_CHECK_ERR(Offset % sizeof(ShaderVariableD3D12Impl) == 0, "Offset is not multiple of ShaderVariableD3D12Impl class size");
auto Index = static_cast<Uint32>(Offset / sizeof(ShaderVariableD3D12Impl));
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;
}
}
@@ -192,45 +186,10 @@ void ShaderVariableManagerD3D12::BindResources(IResourceMapping* pResourceMappin
for (Uint32 v = 0; v < m_NumVariables; ++v)
{
- auto& Var = m_pVariables[v];
- const auto& Res = Var.GetDesc();
-
- 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<ShaderVariableD3D12Impl>(pResourceMapping, Flags);
}
}
-
-
-void ShaderVariableD3D12Impl::Set(IDeviceObject* pObject)
-{
- BindResource(pObject, 0);
-}
-
void ShaderVariableD3D12Impl::SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)
{
const auto& ResDesc = GetDesc();
@@ -240,20 +199,4 @@ void ShaderVariableD3D12Impl::SetArray(IDeviceObject* const* ppObjects, Uint32 F
BindResource(ppObjects[Elem], FirstElement + Elem);
}
-bool ShaderVariableD3D12Impl::IsBound(Uint32 ArrayIndex) const
-{
- auto* pSignature = m_ParentManager.m_pSignature;
- auto& ResourceCache = m_ParentManager.m_ResourceCache;
-
- return pSignature->IsBound(ArrayIndex, m_ResIndex, ResourceCache);
-}
-
-void ShaderVariableD3D12Impl::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
diff --git a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
index 6781b091..279acf70 100644
--- a/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/SwapChainD3D12Impl.cpp
@@ -75,7 +75,8 @@ void SwapChainD3D12Impl::InitBuffersAndViews()
for (Uint32 backbuff = 0; backbuff < m_SwapChainDesc.BufferCount; ++backbuff)
{
CComPtr<ID3D12Resource> pBackBuffer;
- auto hr = m_pSwapChain->GetBuffer(backbuff, __uuidof(pBackBuffer), reinterpret_cast<void**>(static_cast<ID3D12Resource**>(&pBackBuffer)));
+
+ auto hr = m_pSwapChain->GetBuffer(backbuff, __uuidof(pBackBuffer), reinterpret_cast<void**>(static_cast<ID3D12Resource**>(&pBackBuffer)));
if (FAILED(hr))
LOG_ERROR_AND_THROW("Failed to get back buffer ", backbuff, " from the swap chain");
diff --git a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp
index 3a75df4c..ce8b702f 100644
--- a/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/TextureD3D12Impl.cpp
@@ -36,12 +36,10 @@
#include "EngineMemory.h"
#include "StringTools.hpp"
-using namespace Diligent;
-
namespace Diligent
{
-DXGI_FORMAT GetClearFormat(DXGI_FORMAT Fmt, D3D12_RESOURCE_FLAGS Flags)
+static DXGI_FORMAT GetClearFormat(DXGI_FORMAT Fmt, D3D12_RESOURCE_FLAGS Flags)
{
if (Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)
{
diff --git a/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp
index 78115a70..78b519ba 100644
--- a/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/TextureViewD3D12Impl.cpp
@@ -55,8 +55,8 @@ TextureViewD3D12Impl::TextureViewD3D12Impl(IReferenceCounters* pRefCounte
if (!TexArraySRVDescriptor.IsNull() && !MipLevelUAVDescriptors.IsNull())
{
m_MipGenerationDescriptors = ALLOCATE(GetRawAllocator(), "Raw memory for DescriptorHeapAllocation", DescriptorHeapAllocation, 2);
- new (&m_MipGenerationDescriptors[0]) DescriptorHeapAllocation(std::move(TexArraySRVDescriptor));
- new (&m_MipGenerationDescriptors[1]) DescriptorHeapAllocation(std::move(MipLevelUAVDescriptors));
+ new (&m_MipGenerationDescriptors[0]) DescriptorHeapAllocation{std::move(TexArraySRVDescriptor)};
+ new (&m_MipGenerationDescriptors[1]) DescriptorHeapAllocation{std::move(MipLevelUAVDescriptors)};
}
}
diff --git a/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp
index 3a9ae5d7..9ee26ff4 100644
--- a/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/TopLevelASD3D12Impl.cpp
@@ -41,10 +41,10 @@ TopLevelASD3D12Impl::TopLevelASD3D12Impl(IReferenceCounters* pRefCounters,
const TopLevelASDesc& Desc) :
TTopLevelASBase{pRefCounters, pDeviceD3D12, Desc}
{
- auto* pd3d12Device = pDeviceD3D12->GetD3D12Device5();
- const auto& Limits = pDeviceD3D12->GetProperties();
- UINT64 ResultDataMaxSizeInBytes = 0;
+ auto* const pd3d12Device = pDeviceD3D12->GetD3D12Device5();
+ const auto& Limits = pDeviceD3D12->GetProperties();
+ UINT64 ResultDataMaxSizeInBytes = 0;
if (m_Desc.CompactedSize > 0)
{
ResultDataMaxSizeInBytes = m_Desc.CompactedSize;
@@ -64,7 +64,7 @@ TopLevelASD3D12Impl::TopLevelASD3D12Impl(IReferenceCounters* pRefCounters,
pd3d12Device->GetRaytracingAccelerationStructurePrebuildInfo(&d3d12TopLevelInputs, &d3d12TopLevelPrebuildInfo);
if (d3d12TopLevelPrebuildInfo.ResultDataMaxSizeInBytes == 0)
- LOG_ERROR_AND_THROW("Failed to get ray tracing acceleration structure prebuild info");
+ LOG_ERROR_AND_THROW("Failed to get ray tracing acceleration structure prebuild info.");
ResultDataMaxSizeInBytes = d3d12TopLevelPrebuildInfo.ResultDataMaxSizeInBytes;
@@ -72,25 +72,25 @@ TopLevelASD3D12Impl::TopLevelASD3D12Impl(IReferenceCounters* pRefCounters,
m_ScratchSize.Update = static_cast<Uint32>(d3d12TopLevelPrebuildInfo.UpdateScratchDataSizeInBytes);
}
- D3D12_HEAP_PROPERTIES HeapProps;
+ D3D12_HEAP_PROPERTIES HeapProps{};
HeapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
HeapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
HeapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
HeapProps.CreationNodeMask = 1;
HeapProps.VisibleNodeMask = 1;
- D3D12_RESOURCE_DESC d3d12ASDesc = {};
- d3d12ASDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
- d3d12ASDesc.Alignment = 0;
- d3d12ASDesc.Width = ResultDataMaxSizeInBytes;
- d3d12ASDesc.Height = 1;
- d3d12ASDesc.DepthOrArraySize = 1;
- d3d12ASDesc.MipLevels = 1;
- d3d12ASDesc.Format = DXGI_FORMAT_UNKNOWN;
- d3d12ASDesc.SampleDesc.Count = 1;
- d3d12ASDesc.SampleDesc.Quality = 0;
- d3d12ASDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
- d3d12ASDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
+ D3D12_RESOURCE_DESC d3d12ASDesc{};
+ d3d12ASDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
+ d3d12ASDesc.Alignment = 0;
+ d3d12ASDesc.Width = ResultDataMaxSizeInBytes;
+ d3d12ASDesc.Height = 1;
+ d3d12ASDesc.DepthOrArraySize = 1;
+ d3d12ASDesc.MipLevels = 1;
+ d3d12ASDesc.Format = DXGI_FORMAT_UNKNOWN;
+ d3d12ASDesc.SampleDesc.Count = 1;
+ d3d12ASDesc.SampleDesc.Quality = 0;
+ d3d12ASDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
+ d3d12ASDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
auto hr = pd3d12Device->CreateCommittedResource(&HeapProps, D3D12_HEAP_FLAG_NONE,
&d3d12ASDesc, D3D12_RESOURCE_STATE_RAYTRACING_ACCELERATION_STRUCTURE, nullptr,
@@ -104,7 +104,7 @@ TopLevelASD3D12Impl::TopLevelASD3D12Impl(IReferenceCounters* pRefCounters,
m_DescriptorHandle = pDeviceD3D12->AllocateDescriptors(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
- D3D12_SHADER_RESOURCE_VIEW_DESC d3d12SRVDesc;
+ D3D12_SHADER_RESOURCE_VIEW_DESC d3d12SRVDesc{};
d3d12SRVDesc.ViewDimension = D3D12_SRV_DIMENSION_RAYTRACING_ACCELERATION_STRUCTURE;
d3d12SRVDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
d3d12SRVDesc.Format = DXGI_FORMAT_UNKNOWN;
diff --git a/Graphics/GraphicsEngineD3DBase/interface/ShaderResourceVariableD3D.h b/Graphics/GraphicsEngineD3DBase/interface/ShaderResourceVariableD3D.h
index f89805b9..535be90b 100644
--- a/Graphics/GraphicsEngineD3DBase/interface/ShaderResourceVariableD3D.h
+++ b/Graphics/GraphicsEngineD3DBase/interface/ShaderResourceVariableD3D.h
@@ -42,7 +42,7 @@ class IShaderResourceVariableD3D : public IShaderResourceVariable
{
public:
/// Returns HLSL ShaderResourceVariable resource description
- virtual HLSLShaderResourceDesc DILIGENT_CALL_TYPE GetHLSLResourceDesc() const = 0;
+ virtual void DILIGENT_CALL_TYPE GetHLSLResourceDesc(HLSLShaderResourceDesc& HLSLResDesc) const = 0;
};
} // namespace Diligent
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