summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-10-28 03:58:28 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-10-28 03:58:28 +0000
commitcbf6f3c8a7e1d4a370d4c9ca2840a143cfbea216 (patch)
tree587e1bd262ad08c814a4c82032ce9a2ba05f6dbe /Graphics
parentFixed two minor merge issues (diff)
downloadDiligentCore-cbf6f3c8a7e1d4a370d4c9ca2840a143cfbea216.tar.gz
DiligentCore-cbf6f3c8a7e1d4a370d4c9ca2840a143cfbea216.zip
ShaderResourceLayout{D3D12,Vk}: implemented GetShaderName
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp22
-rw-r--r--Graphics/GraphicsEngineD3D12/include/ShaderResourceLayoutD3D12.hpp16
-rw-r--r--Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp12
-rw-r--r--Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp12
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp12
5 files changed, 62 insertions, 12 deletions
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp
index 1130fbff..9fef2399 100644
--- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp
+++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp
@@ -381,6 +381,28 @@ inline void VerifyAndCorrectSetArrayArguments(const char* Name, Uint32 ArraySize
}
}
+template <typename ShaderVectorType>
+std::string GetShaderGroupName(const ShaderVectorType& Shaders)
+{
+ std::string Name;
+ if (Shaders.size() == 1)
+ {
+ Name = Shaders[0]->GetDesc().Name;
+ }
+ else
+ {
+ Name = "{";
+ for (size_t s = 0; s < Shaders.size(); ++s)
+ {
+ if (s > 0)
+ Name += ", ";
+ Name += Shaders[s]->GetDesc().Name;
+ }
+ Name += "}";
+ }
+ return Name;
+}
+
struct DefaultShaderVariableIDComparator
{
bool operator()(const INTERFACE_ID& IID) const
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<D3D12Resource*>(m_ResourceBuffer.get());
- return Resource[r];
+ auto* Resources = reinterpret_cast<D3D12Resource*>(m_ResourceBuffer.get());
+ return Resources[r];
}
const D3D12Resource& GetResource(Uint32 r) const
{
VERIFY_EXPR(r < GetTotalResourceCount());
- auto* Resource = reinterpret_cast<const D3D12Resource*>(m_ResourceBuffer.get());
- return Resource[r];
+ const auto* Resources = reinterpret_cast<const D3D12Resource*>(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<const D3D12Resource*>(m_ResourceBuffer.get());
+ return reinterpret_cast<const char*>(Resources + GetTotalResourceCount());
+ }
+
StringPool AllocateMemory(IMemoryAllocator& Allocator,
const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& CbvSrvUavCount,
const std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES>& 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<char>(StringPoolSize);
m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void>>(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<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CbvSrvUavCount = {};
std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> SamplerCount = {};
+ // Maps resource name to its index in m_ResourceBuffer
std::unordered_map<HashMapStringKey, Uint32, HashMapStringKey::Hasher> 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<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CurrCbvSrvUav = {};
std::array<Uint32, SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES> CurrSampler = {};
std::array<Uint32, D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER + 1> StaticResCacheTblSizes = {};
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<const VkResource*>(m_ResourceBuffer.get());
+ const auto* Resources = reinterpret_cast<const VkResource*>(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<const VkResource*>(m_ResourceBuffer.get()) + GetTotalResourceCount();
+ const auto* SamplerDataEnd = reinterpret_cast<const ImmutableSamplerPtrType*>(ResourceDataEnd) + m_NumImmutableSamplers;
+ return reinterpret_cast<const char*>(SamplerDataEnd);
+ }
+
static constexpr Uint32 InvalidResourceIndex = ~0u;
+ // Maps resource name to its index in m_ResourceBuffer
using ResourceNameToIndex_t = std::unordered_map<HashMapStringKey, Uint32, HashMapStringKey::Hasher>;
StringPool AllocateMemory(const std::vector<const ShaderVkImpl*>& 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<const Shader
VERIFY_EXPR(Shaders.size() > 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<const Shader
m_ResourceBuffer = std::unique_ptr<void, STDDeleterRawMem<void>>(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;
}