summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-05-10 15:13:15 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-05-10 15:13:15 +0000
commitf7c89c4913936491c5e5c8138c39c3fc5abd585b (patch)
tree59ecb4afe6d77f89e588f93a5ee243207a1e61a8 /Graphics/GraphicsEngineD3DBase
parentImplemented VK shader resource layout initialization (diff)
downloadDiligentCore-f7c89c4913936491c5e5c8138c39c3fc5abd585b.tar.gz
DiligentCore-f7c89c4913936491c5e5c8138c39c3fc5abd585b.zip
Implemented static sampler initialization in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.h19
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp70
2 files changed, 8 insertions, 81 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
index 57e395ed..c44972f5 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
@@ -286,13 +286,6 @@ class ShaderResources
public:
ShaderResources(IMemoryAllocator &Allocator, SHADER_TYPE ShaderType);
- // Copies specified types of resources from another ShaderResources objects
- // Only resources listed in AllowedVarTypes are copied
- ShaderResources(IMemoryAllocator &Allocator,
- const ShaderResources& SrcResources,
- const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- Uint32 NumAllowedTypes);
-
ShaderResources (const ShaderResources&) = delete;
ShaderResources (ShaderResources&&) = delete;
ShaderResources& operator = (const ShaderResources&) = delete;
@@ -305,7 +298,7 @@ public:
Uint32 GetNumTexUAV() const noexcept{ return (m_BufSRVOffset - m_TexUAVOffset); }
Uint32 GetNumBufSRV() const noexcept{ return (m_BufUAVOffset - m_BufSRVOffset); }
Uint32 GetNumBufUAV() const noexcept{ return (m_SamplersOffset - m_BufUAVOffset); }
- Uint32 GetNumSamplers()const noexcept{ return (m_BufferEndOffset- m_SamplersOffset); }
+ Uint32 GetNumSamplers()const noexcept{ return (m_TotalResources - m_SamplersOffset); }
const D3DShaderResourceAttribs& GetCB (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumCBs(), 0); }
const D3DShaderResourceAttribs& GetTexSRV (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumTexSRV(), m_TexSRVOffset); }
@@ -382,15 +375,15 @@ protected:
__forceinline D3DShaderResourceAttribs& GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset)noexcept
{
- VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Max allowed index: ", NumResources-1);
- VERIFY_EXPR(Offset + n < m_BufferEndOffset);
+ VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Resource array size: ", NumResources);
+ VERIFY_EXPR(Offset + n < m_TotalResources);
return reinterpret_cast<D3DShaderResourceAttribs*>(m_MemoryBuffer.get())[Offset + n];
}
__forceinline const D3DShaderResourceAttribs& GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset)const noexcept
{
- VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Max allowed index: ", NumResources-1);
- VERIFY_EXPR(Offset + n < m_BufferEndOffset);
+ VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Resource array size: ", NumResources);
+ VERIFY_EXPR(Offset + n < m_TotalResources);
return reinterpret_cast<D3DShaderResourceAttribs*>(m_MemoryBuffer.get())[Offset + n];
}
@@ -415,7 +408,7 @@ private:
OffsetType m_BufSRVOffset = 0;
OffsetType m_BufUAVOffset = 0;
OffsetType m_SamplersOffset = 0;
- OffsetType m_BufferEndOffset = 0;
+ OffsetType m_TotalResources = 0;
SHADER_TYPE m_ShaderType = SHADER_TYPE_UNKNOWN;
};
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
index 1df20b18..4abf2673 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
@@ -72,9 +72,9 @@ void ShaderResources::Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uin
m_SamplersOffset = m_BufUAVOffset + static_cast<OffsetType>(NumBufUAVs);
VERIFY(m_SamplersOffset + NumSamplers<= MaxOffset, "Max offset exceeded");
- m_BufferEndOffset = m_SamplersOffset + static_cast<OffsetType>(NumSamplers);
+ m_TotalResources = m_SamplersOffset + static_cast<OffsetType>(NumSamplers);
- auto MemorySize = m_BufferEndOffset * sizeof(D3DShaderResourceAttribs);
+ auto MemorySize = m_TotalResources * sizeof(D3DShaderResourceAttribs);
VERIFY_EXPR(GetNumCBs() == NumCBs);
VERIFY_EXPR(GetNumTexSRV() == NumTexSRVs);
@@ -146,72 +146,6 @@ void ShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes
);
}
-ShaderResources::ShaderResources(IMemoryAllocator &Allocator,
- const ShaderResources& SrcResources,
- const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- Uint32 NumAllowedTypes) :
- m_MemoryBuffer(nullptr, STDDeleterRawMem<void>(Allocator)),
- m_ShaderType(SrcResources.m_ShaderType)
-{
- Uint32 NumCBs = 0, NumTexSRVs = 0, NumTexUAVs = 0, NumBufSRVs = 0, NumBufUAVs = 0, NumSamplers = 0;
- SrcResources.CountResources(AllowedVarTypes, NumAllowedTypes, NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers);
-
- Initialize(Allocator, NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers);
-
- // In release mode, MS compiler generates this false warning:
- // Warning C4189 'AllowedTypeBits': local variable is initialized but not referenced
- // Most likely it somehow gets confused by the variable being eliminated during function inlining
-#pragma warning(push)
-#pragma warning(disable : 4189)
- Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-#pragma warning(pop)
-
- Uint32 CurrCB = 0, CurrTexSRV = 0, CurrTexUAV = 0, CurrBufSRV = 0, CurrBufUAV = 0, CurrSampler = 0;
- SrcResources.ProcessResources(
- AllowedVarTypes, NumAllowedTypes,
-
- [&](const D3DShaderResourceAttribs &CB, Uint32)
- {
- VERIFY_EXPR( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) );
- new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(CB);
- },
- [&](const D3DShaderResourceAttribs& TexSRV, Uint32)
- {
- VERIFY_EXPR(IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits));
-
- auto SamplerId = D3DShaderResourceAttribs::InvalidSamplerId;
- if (TexSRV.IsValidSampler())
- {
- SamplerId = CurrSampler;
- new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs(SrcResources.GetSampler(TexSRV.GetSamplerId()));
- }
-
- new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs(TexSRV, SamplerId);
- },
- [&](const D3DShaderResourceAttribs &TexUAV, Uint32)
- {
- VERIFY_EXPR( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) );
- new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs(TexUAV);
- },
- [&](const D3DShaderResourceAttribs &BufSRV, Uint32)
- {
- VERIFY_EXPR( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) );
- new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs(BufSRV);
- },
- [&](const D3DShaderResourceAttribs &BufUAV, Uint32)
- {
- VERIFY_EXPR( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) );
- new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs(BufUAV);
- }
- );
-
- VERIFY_EXPR(CurrCB == NumCBs);
- VERIFY_EXPR(CurrTexSRV == NumTexSRVs );
- VERIFY_EXPR(CurrTexUAV == NumTexUAVs );
- VERIFY_EXPR(CurrBufSRV == NumBufSRVs );
- VERIFY_EXPR(CurrBufUAV == NumBufUAVs );
- VERIFY_EXPR(CurrSampler == NumSamplers );
-}
Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& TexSRV)const
{