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 --- .../GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp | 12 ++++++++++-- Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp | 12 +++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp index a0e40615..5406dee3 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp @@ -371,7 +371,7 @@ public: const Char* GetShaderName() const { - return ""; // AZ TODO + return GetStringPoolData(); } SHADER_TYPE GetShaderType() const { return m_ShaderType; } @@ -405,7 +405,7 @@ private: const VkResource& GetResource(Uint32 r) const { VERIFY_EXPR(r < GetTotalResourceCount()); - auto* Resources = reinterpret_cast(m_ResourceBuffer.get()); + const auto* Resources = reinterpret_cast(m_ResourceBuffer.get()); return Resources[r]; } @@ -414,8 +414,16 @@ private: return m_NumResources[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES]; } + const char* GetStringPoolData() const + { + const auto* ResourceDataEnd = reinterpret_cast(m_ResourceBuffer.get()) + GetTotalResourceCount(); + const auto* SamplerDataEnd = reinterpret_cast(ResourceDataEnd) + m_NumImmutableSamplers; + return reinterpret_cast(SamplerDataEnd); + } + static constexpr Uint32 InvalidResourceIndex = ~0u; + // Maps resource name to its index in m_ResourceBuffer using ResourceNameToIndex_t = std::unordered_map; StringPool AllocateMemory(const std::vector& Shaders, IMemoryAllocator& Allocator, diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index 499c35ef..76bd77ee 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -135,11 +135,15 @@ StringPool ShaderResourceLayoutVk::AllocateMemory(const std::vector 0); VERIFY_EXPR(m_ShaderType == SHADER_TYPE_UNKNOWN); - size_t StringPoolSize = 0; m_ShaderType = Shaders[0]->GetDesc().ShaderType; m_IsUsingSeparateSamplers = !Shaders[0]->GetShaderResources()->IsUsingCombinedSamplers(); const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + // Construct shader or shader group name + const auto ShaderName = GetShaderGroupName(Shaders); + + size_t StringPoolSize = ShaderName.length() + 1; + // Count the number of resources to allocate all needed memory for (size_t s = 0; s < Shaders.size(); ++s) { @@ -202,11 +206,13 @@ StringPool ShaderResourceLayoutVk::AllocateMemory(const std::vector>(MemPool.Release(), Allocator); - VERIFY_EXPR(m_ResourceBuffer.get() == pResources); - VERIFY_EXPR(m_NumImmutableSamplers == 0 || pImtblSamplers == std::addressof(GetImmutableSampler(0))); + VERIFY_EXPR(pResources == nullptr || m_ResourceBuffer.get() == pResources); + VERIFY_EXPR(pImtblSamplers == nullptr || pImtblSamplers == std::addressof(GetImmutableSampler(0))); + VERIFY_EXPR(pStringData == GetStringPoolData()); StringPool stringPool; stringPool.AssignMemory(pStringData, StringPoolSize); + stringPool.CopyString(ShaderName); return stringPool; } -- cgit v1.2.3