From cbf6f3c8a7e1d4a370d4c9ca2840a143cfbea216 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 27 Oct 2020 20:58:28 -0700 Subject: ShaderResourceLayout{D3D12,Vk}: implemented GetShaderName --- .../include/ShaderResourceLayoutD3D12.hpp | 16 +++++++++++----- .../src/ShaderResourceLayoutD3D12.cpp | 12 ++++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp index 1f2b3d2d..f7f2fa13 100644 --- a/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp +++ b/Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp @@ -302,7 +302,7 @@ private: const Char* GetShaderName() const { - return ""; // AZ TODO + return GetStringPoolData(); } @@ -323,14 +323,14 @@ private: D3D12Resource& GetResource(Uint32 r) { VERIFY_EXPR(r < GetTotalResourceCount()); - auto* Resource = reinterpret_cast(m_ResourceBuffer.get()); - return Resource[r]; + auto* Resources = reinterpret_cast(m_ResourceBuffer.get()); + return Resources[r]; } const D3D12Resource& GetResource(Uint32 r) const { VERIFY_EXPR(r < GetTotalResourceCount()); - auto* Resource = reinterpret_cast(m_ResourceBuffer.get()); - return Resource[r]; + const auto* Resources = reinterpret_cast(m_ResourceBuffer.get()); + return Resources[r]; } Uint32 GetSrvCbvUavOffset(SHADER_RESOURCE_VARIABLE_TYPE VarType, Uint32 r) const @@ -362,6 +362,12 @@ private: return GetResource(m_SamplersOffsets[0] + s); } + const char* GetStringPoolData() const + { + const auto* Resources = reinterpret_cast(m_ResourceBuffer.get()); + return reinterpret_cast(Resources + GetTotalResourceCount()); + } + StringPool AllocateMemory(IMemoryAllocator& Allocator, const std::array& CbvSrvUavCount, const std::array& SamplerCount, diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index 34b15c4c..b4bb1f72 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -115,7 +115,8 @@ StringPool ShaderResourceLayoutD3D12::AllocateMemory(IMemoryAllocator& auto* pStringPoolData = MemPool.ConstructArray(StringPoolSize); m_ResourceBuffer = std::unique_ptr>(MemPool.Release(), Allocator); - VERIFY_EXPR(m_ResourceBuffer.get() == pResources); + VERIFY_EXPR(pResources == nullptr || m_ResourceBuffer.get() == pResources); + VERIFY_EXPR(pStringPoolData == GetStringPoolData()); StringPool stringPool; stringPool.AssignMemory(pStringPoolData, StringPoolSize); @@ -145,12 +146,17 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* std::array CbvSrvUavCount = {}; std::array SamplerCount = {}; + // Maps resource name to its index in m_ResourceBuffer std::unordered_map ResourceNameToIndex; // Count the number of resources to allocate all needed memory m_IsUsingSeparateSamplers = !Shaders[0]->GetShaderResources()->IsUsingCombinedTextureSamplers(); m_ShaderType = Shaders[0]->GetDesc().ShaderType; - size_t StringPoolSize = 0; + + // Construct shader or shader group name + const auto ShaderName = GetShaderGroupName(Shaders); + + size_t StringPoolSize = ShaderName.length() + 1; static constexpr Uint32 InvalidResourceIndex = ~0u; @@ -225,6 +231,8 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device* auto stringPool = AllocateMemory(LayoutDataAllocator, CbvSrvUavCount, SamplerCount, StringPoolSize); + stringPool.CopyString(ShaderName); + std::array CurrCbvSrvUav = {}; std::array CurrSampler = {}; std::array StaticResCacheTblSizes = {}; -- cgit v1.2.3