summaryrefslogtreecommitdiffstats
path: root/Graphics/GLSLTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-05-18 04:36:46 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-05-18 04:36:46 +0000
commitc0087704ea69eec2d52d4db891309b362a2c2812 (patch)
tree98f1d5efaaec4a8d57524e7d55714402a862d3c3 /Graphics/GLSLTools
parentAdded texel uniform/storage buffer detection (diff)
downloadDiligentCore-c0087704ea69eec2d52d4db891309b362a2c2812.tar.gz
DiligentCore-c0087704ea69eec2d52d4db891309b362a2c2812.zip
Reworked SPIRVShaderResources: reduced sizeof(SPIRVShaderResourceAttribs) to 32; packing resource names into the string pool
Diffstat (limited to 'Graphics/GLSLTools')
-rw-r--r--Graphics/GLSLTools/include/SPIRVShaderResources.h66
-rw-r--r--Graphics/GLSLTools/src/SPIRVShaderResources.cpp174
2 files changed, 185 insertions, 55 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.h b/Graphics/GLSLTools/include/SPIRVShaderResources.h
index 6290d55c..a7b610b5 100644
--- a/Graphics/GLSLTools/include/SPIRVShaderResources.h
+++ b/Graphics/GLSLTools/include/SPIRVShaderResources.h
@@ -30,10 +30,11 @@
//
// m_MemoryBuffer m_TotalResources
// | |
-// | Uniform Buffers | Storage Buffers | Storage Images | Sampled Images | Atomic Counters | Separate Images | Separate Samplers | Static Samplers |
+// | Uniform Buffers | Storage Buffers | Storage Images | Sampled Images | Atomic Counters | Separate Images | Separate Samplers | Static Samplers | Resource Names |
#include <memory>
#include <vector>
+#include <sstream>
#include "Shader.h"
#include "Sampler.h"
@@ -41,6 +42,7 @@
#include "STDAllocator.h"
#include "HashUtils.h"
#include "RefCntAutoPtr.h"
+#include "StringPool.h"
namespace spirv_cross
{
@@ -84,19 +86,19 @@ struct SPIRVShaderResourceAttribs
NumResourceTypes
};
- const String Name;
-
+ const char *Name;
const Uint16 ArraySize;
const ResourceType Type : 4;
const SHADER_VARIABLE_TYPE VarType : 4;
const Int8 StaticSamplerInd;
- // offset in SPIRV words (uint32_t) for a decoration which was originally declared in the SPIRV binary
+ // Offset in SPIRV words (uint32_t) of binding & descriptor set decorations in SPIRV binary
const uint32_t BindingDecorationOffset;
const uint32_t DescriptorSetDecorationOffset;
SPIRVShaderResourceAttribs(const spirv_cross::Compiler& Compiler,
const spirv_cross::Resource& Res,
+ const char* _Name,
ResourceType _Type,
SHADER_VARIABLE_TYPE _VarType,
Int32 _StaticSamplerInd);
@@ -105,7 +107,11 @@ struct SPIRVShaderResourceAttribs
{
VERIFY_EXPR(ArrayInd < ArraySize);
if (ArraySize > 1)
- return Name+ '[' + std::to_string(ArrayInd) + ']';
+ {
+ std::stringstream ss;
+ ss << Name << '[' << ArrayInd << ']';
+ return ss.str();
+ }
else
return Name;
}
@@ -122,10 +128,10 @@ static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of
class SPIRVShaderResources
{
public:
- SPIRVShaderResources(IMemoryAllocator& Allocator,
- IRenderDevice* pRenderDevice,
- std::vector<uint32_t> spirv_binary,
- const ShaderDesc& shaderDesc);
+ SPIRVShaderResources(IMemoryAllocator& Allocator,
+ IRenderDevice* pRenderDevice,
+ std::vector<uint32_t> spirv_binary,
+ const ShaderDesc& shaderDesc);
SPIRVShaderResources (const SPIRVShaderResources&) = delete;
SPIRVShaderResources (SPIRVShaderResources&&) = delete;
@@ -134,6 +140,8 @@ public:
~SPIRVShaderResources();
+ using SamplerPtrType = RefCntAutoPtr<ISampler>;
+
Uint32 GetNumUBs ()const noexcept{ return (m_StorageBufferOffset - 0); }
Uint32 GetNumSBs ()const noexcept{ return (m_StorageImageOffset - m_StorageBufferOffset); }
Uint32 GetNumImgs ()const noexcept{ return (m_SampledImageOffset - m_StorageImageOffset); }
@@ -159,7 +167,7 @@ public:
VERIFY(ResAttribs.StaticSamplerInd < m_NumStaticSamplers, "Static sampler index (", ResAttribs.StaticSamplerInd, ") is out of range. Array size: ", m_NumStaticSamplers);
auto *ResourceMemoryEnd = reinterpret_cast<SPIRVShaderResourceAttribs*>(m_MemoryBuffer.get()) + m_TotalResources;
- return reinterpret_cast<RefCntAutoPtr<ISampler>*>(ResourceMemoryEnd)[ResAttribs.StaticSamplerInd];
+ return reinterpret_cast<SamplerPtrType*>(ResourceMemoryEnd)[ResAttribs.StaticSamplerInd];
}
void CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes,
@@ -182,15 +190,15 @@ public:
typename THandleAC,
typename THandleSepImg,
typename THandleSepSmpl>
- void ProcessResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes,
- Uint32 NumAllowedTypes,
- THandleUB HandleUB,
- THandleSB HandleSB,
- THandleImg HandleImg,
- THandleSmplImg HandleSmplImg,
- THandleAC HandleAC,
- THandleSepImg HandleSepImg,
- THandleSepSmpl HandleSepSmpl)const
+ void ProcessResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
+ Uint32 NumAllowedTypes,
+ THandleUB HandleUB,
+ THandleSB HandleSB,
+ THandleImg HandleImg,
+ THandleSmplImg HandleSmplImg,
+ THandleAC HandleAC,
+ THandleSepImg HandleSepImg,
+ THandleSepSmpl HandleSepSmpl)const
{
Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
@@ -259,12 +267,23 @@ public:
}
}
+ std::string DumpResources();
+
//bool IsCompatibleWith(const ShaderResources &Resources)const;
//size_t GetHash()const;
protected:
- void Initialize(IMemoryAllocator &Allocator, Uint32 NumUBs, Uint32 NumSBs, Uint32 NumImgs, Uint32 NumSmplImgs, Uint32 NumACs, Uint32 NumSepImgs, Uint32 NumSepSmpls, Uint32 NumStaticSamplers);
+ void Initialize(IMemoryAllocator& Allocator,
+ Uint32 NumUBs,
+ Uint32 NumSBs,
+ Uint32 NumImgs,
+ Uint32 NumSmplImgs,
+ Uint32 NumACs,
+ Uint32 NumSepImgs,
+ Uint32 NumSepSmpls,
+ Uint32 NumStaticSamplers,
+ size_t ResourceNamesPoolSize);
__forceinline SPIRVShaderResourceAttribs& GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset)noexcept
{
@@ -288,17 +307,18 @@ protected:
SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); }
SPIRVShaderResourceAttribs& GetSepSmpl (Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepSmpls(), m_SeparateSamplerOffset); }
SPIRVShaderResourceAttribs& GetResource(Uint32 n)noexcept{ return GetResAttribs(n, GetTotalResources(), 0); }
- RefCntAutoPtr<ISampler>& GetStaticSampler(Uint32 n)noexcept
+ SamplerPtrType& GetStaticSampler(Uint32 n)noexcept
{
VERIFY(n < m_NumStaticSamplers, "Static sampler index (", n, ") is out of range. Array size: ", m_NumStaticSamplers);
auto *ResourceMemoryEnd = reinterpret_cast<SPIRVShaderResourceAttribs*>(m_MemoryBuffer.get()) + m_TotalResources;
- return reinterpret_cast<RefCntAutoPtr<ISampler>*>(ResourceMemoryEnd)[n];
+ return reinterpret_cast<SamplerPtrType*>(ResourceMemoryEnd)[n];
}
private:
// Memory buffer that holds all resources as continuous chunk of memory:
- // | UBs | SBs | StrgImgs | SmplImgs | ACs | SepImgs | SepSamplers | Static Samplers |
+ // | UBs | SBs | StrgImgs | SmplImgs | ACs | SepImgs | SepSamplers | Static Samplers | Resource Names |
std::unique_ptr< void, STDDeleterRawMem<void> > m_MemoryBuffer;
+ StringPool m_ResourceNames;
using OffsetType = Uint16;
OffsetType m_StorageBufferOffset = 0;
diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
index a1cd5639..41d21946 100644
--- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
+++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
@@ -21,6 +21,7 @@
* of the possibility of such damages.
*/
+#include <iomanip>
#include "SPIRVShaderResources.h"
#include "spirv_cross.hpp"
#include "ShaderBase.h"
@@ -58,27 +59,28 @@ static uint32_t GetDecorationOffset(const spirv_cross::Compiler &Compiler,
SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const spirv_cross::Compiler& Compiler,
const spirv_cross::Resource& Res,
+ const char* _Name,
ResourceType _Type,
SHADER_VARIABLE_TYPE _VarType,
Int32 _StaticSamplerInd) :
- Name(Res.name),
+ Name(_Name),
ArraySize(GetResourceArraySize<decltype(ArraySize)>(Compiler, Res)),
- BindingDecorationOffset(GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationBinding)),
- DescriptorSetDecorationOffset(GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationDescriptorSet)),
Type(_Type),
VarType(_VarType),
- StaticSamplerInd(static_cast<decltype(StaticSamplerInd)>(_StaticSamplerInd))
+ StaticSamplerInd(static_cast<decltype(StaticSamplerInd)>(_StaticSamplerInd)),
+ BindingDecorationOffset(GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationBinding)),
+ DescriptorSetDecorationOffset(GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationDescriptorSet))
{
VERIFY(_StaticSamplerInd >= std::numeric_limits<decltype(StaticSamplerInd)>::min() &&
_StaticSamplerInd <= std::numeric_limits<decltype(StaticSamplerInd)>::max(), "Static sampler index is out of representable range" );
}
-Int32 FindStaticSampler(const ShaderDesc& shaderDesc, const char* SamplerName)
+Int32 FindStaticSampler(const ShaderDesc& shaderDesc, const std::string& SamplerName)
{
for(Uint32 s=0; s < shaderDesc.NumStaticSamplers; ++s)
{
const auto& StSam = shaderDesc.StaticSamplers[s];
- if(strcmp(SamplerName, StSam.TextureName) == 0)
+ if(SamplerName.compare(StSam.TextureName) == 0)
return s;
}
@@ -98,6 +100,23 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
// The SPIR-V is now parsed, and we can perform reflection on it.
spirv_cross::ShaderResources resources = Compiler.get_shader_resources();
+ size_t ResourceNamesPoolSize = 0;
+ for(auto *pResType :
+ {
+ &resources.uniform_buffers,
+ &resources.storage_buffers,
+ &resources.storage_images,
+ &resources.sampled_images,
+ &resources.atomic_counters,
+ &resources.push_constant_buffers,
+ &resources.separate_images,
+ &resources.separate_samplers
+ })
+ {
+ for(const auto &res : *pResType)
+ ResourceNamesPoolSize += res.name.length() + 1;
+ }
+
Initialize(Allocator,
static_cast<Uint32>(resources.uniform_buffers.size()),
static_cast<Uint32>(resources.storage_buffers.size()),
@@ -106,14 +125,20 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
static_cast<Uint32>(resources.atomic_counters.size()),
static_cast<Uint32>(resources.separate_images.size()),
static_cast<Uint32>(resources.separate_samplers.size()),
- shaderDesc.NumStaticSamplers);
+ shaderDesc.NumStaticSamplers,
+ ResourceNamesPoolSize);
{
Uint32 CurrUB = 0;
for (const auto &UB : resources.uniform_buffers)
{
- auto VarType = GetShaderVariableType(UB.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
- new (&GetUB(CurrUB++)) SPIRVShaderResourceAttribs(Compiler, UB, SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, VarType, false);
+ new (&GetUB(CurrUB++))
+ SPIRVShaderResourceAttribs(Compiler,
+ UB,
+ m_ResourceNames.CopyString(UB.name),
+ SPIRVShaderResourceAttribs::ResourceType::UniformBuffer,
+ GetShaderVariableType(UB.name, shaderDesc),
+ -1);
}
VERIFY_EXPR(CurrUB == GetNumUBs());
}
@@ -122,8 +147,13 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrSB = 0;
for (const auto &SB : resources.storage_buffers)
{
- auto VarType = GetShaderVariableType(SB.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
- new (&GetSB(CurrSB++)) SPIRVShaderResourceAttribs(Compiler, SB, SPIRVShaderResourceAttribs::ResourceType::StorageBuffer, VarType, false);
+ new (&GetSB(CurrSB++))
+ SPIRVShaderResourceAttribs(Compiler,
+ SB,
+ m_ResourceNames.CopyString(SB.name),
+ SPIRVShaderResourceAttribs::ResourceType::StorageBuffer,
+ GetShaderVariableType(SB.name, shaderDesc),
+ -1);
}
VERIFY_EXPR(CurrSB == GetNumSBs());
}
@@ -132,13 +162,18 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrSmplImg = 0;
for (const auto &SmplImg : resources.sampled_images)
{
- auto VarType = GetShaderVariableType(SmplImg.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
- auto StaticSamplerInd = FindStaticSampler(shaderDesc, SmplImg.name.c_str());
+ auto StaticSamplerInd = FindStaticSampler(shaderDesc, SmplImg.name);
const auto& type = Compiler.get_type(SmplImg.type_id);
auto ResType = type.image.dim == spv::DimBuffer ?
SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer :
SPIRVShaderResourceAttribs::ResourceType::SampledImage;
- new (&GetSmplImg(CurrSmplImg++)) SPIRVShaderResourceAttribs(Compiler, SmplImg, ResType, VarType, StaticSamplerInd);
+ new (&GetSmplImg(CurrSmplImg++))
+ SPIRVShaderResourceAttribs(Compiler,
+ SmplImg,
+ m_ResourceNames.CopyString(SmplImg.name),
+ ResType,
+ GetShaderVariableType(SmplImg.name, shaderDesc),
+ StaticSamplerInd);
}
VERIFY_EXPR(CurrSmplImg == GetNumSmplImgs());
}
@@ -147,12 +182,17 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrImg = 0;
for (const auto &Img : resources.storage_images)
{
- auto VarType = GetShaderVariableType(Img.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
const auto& type = Compiler.get_type(Img.type_id);
auto ResType = type.image.dim == spv::DimBuffer ?
SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer :
SPIRVShaderResourceAttribs::ResourceType::StorageImage;
- new (&GetImg(CurrImg++)) SPIRVShaderResourceAttribs(Compiler, Img, ResType, VarType, false);
+ new (&GetImg(CurrImg++))
+ SPIRVShaderResourceAttribs(Compiler,
+ Img,
+ m_ResourceNames.CopyString(Img.name),
+ ResType,
+ GetShaderVariableType(Img.name, shaderDesc),
+ -1);
}
VERIFY_EXPR(CurrImg == GetNumImgs());
}
@@ -161,8 +201,13 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrAC = 0;
for (const auto &AC : resources.atomic_counters)
{
- auto VarType = GetShaderVariableType(AC.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
- new (&GetAC(CurrAC++)) SPIRVShaderResourceAttribs(Compiler, AC, SPIRVShaderResourceAttribs::ResourceType::AtomicCounter, VarType, false);
+ new (&GetAC(CurrAC++))
+ SPIRVShaderResourceAttribs(Compiler,
+ AC,
+ m_ResourceNames.CopyString(AC.name),
+ SPIRVShaderResourceAttribs::ResourceType::AtomicCounter,
+ GetShaderVariableType(AC.name, shaderDesc),
+ -1);
}
VERIFY_EXPR(CurrAC == GetNumACs());
}
@@ -171,8 +216,13 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrSepImg = 0;
for (const auto &SepImg : resources.separate_images)
{
- auto VarType = GetShaderVariableType(SepImg.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
- new (&GetSepImg(CurrSepImg++)) SPIRVShaderResourceAttribs(Compiler, SepImg, SPIRVShaderResourceAttribs::ResourceType::SeparateImage, VarType, false);
+ new (&GetSepImg(CurrSepImg++))
+ SPIRVShaderResourceAttribs(Compiler,
+ SepImg,
+ m_ResourceNames.CopyString(SepImg.name),
+ SPIRVShaderResourceAttribs::ResourceType::SeparateImage,
+ GetShaderVariableType(SepImg.name, shaderDesc),
+ -1);
}
VERIFY_EXPR(CurrSepImg == GetNumSepImgs());
}
@@ -181,21 +231,29 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrSepSmpl = 0;
for (const auto &SepSam : resources.separate_samplers)
{
- auto VarType = GetShaderVariableType(SepSam.name.c_str(), shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables);
- auto StaticSamplerInd = FindStaticSampler(shaderDesc, SepSam.name.c_str());
- new (&GetSepSmpl(CurrSepSmpl++)) SPIRVShaderResourceAttribs(Compiler, SepSam, SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, VarType, StaticSamplerInd);
+ auto StaticSamplerInd = FindStaticSampler(shaderDesc, SepSam.name);
+ new (&GetSepSmpl(CurrSepSmpl++))
+ SPIRVShaderResourceAttribs(Compiler,
+ SepSam,
+ m_ResourceNames.CopyString(SepSam.name),
+ SPIRVShaderResourceAttribs::ResourceType::SeparateSampler,
+ GetShaderVariableType(SepSam.name, shaderDesc),
+ StaticSamplerInd);
}
VERIFY_EXPR(CurrSepSmpl == GetNumSepSmpls());
}
+ VERIFY(m_ResourceNames.GetRemainingSize() == 0, "Names pool must be empty");
for (Uint32 s = 0; s < m_NumStaticSamplers; ++s)
{
- RefCntAutoPtr<ISampler> &pStaticSampler = GetStaticSampler(s);
- new (std::addressof(pStaticSampler)) RefCntAutoPtr<ISampler>();
+ SamplerPtrType &pStaticSampler = GetStaticSampler(s);
+ new (std::addressof(pStaticSampler)) SamplerPtrType();
pRenderDevice->CreateSampler(shaderDesc.StaticSamplers[s].Desc, &pStaticSampler);
}
+ //LOG_INFO_MESSAGE(DumpResources());
+
#ifdef _DEBUG
if (shaderDesc.NumVariables != 0)
{
@@ -208,7 +266,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
for (Uint32 res = 0; res < GetTotalResources(); ++res)
{
const auto &ResAttribs = GetResource(res);
- if (ResAttribs.Name.compare(VarName) == 0)
+ if (strcmp(ResAttribs.Name, VarName) == 0)
{
VariableFound = true;
break;
@@ -230,7 +288,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
for (Uint32 i = 0; i < GetNumSmplImgs(); ++i)
{
const auto &SmplImg = GetSmplImg(i);
- if (SmplImg.Name.compare(SamName) == 0)
+ if (strcmp(SmplImg.Name, SamName) == 0)
{
SamplerFound = true;
break;
@@ -243,7 +301,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
for (Uint32 i = 0; i < GetNumSepSmpls(); ++i)
{
const auto &SepSmpl = GetSepSmpl(i);
- if (SepSmpl.Name.compare(SamName) == 0)
+ if (strcmp(SepSmpl.Name, SamName) == 0)
{
SamplerFound = true;
break;
@@ -267,11 +325,12 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
Uint32 NumACs,
Uint32 NumSepImgs,
Uint32 NumSepSmpls,
- Uint32 NumStaticSamplers)
+ Uint32 NumStaticSamplers,
+ size_t ResourceNamesPoolSize)
{
VERIFY(&m_MemoryBuffer.get_deleter().m_Allocator == &Allocator, "Incosistent allocators provided");
- static constexpr Uint16 UniformBufferOffset = 0;
+ static constexpr OffsetType UniformBufferOffset = 0;
const auto MaxOffset = static_cast<Uint32>(std::numeric_limits<OffsetType>::max());
VERIFY(UniformBufferOffset + NumUBs <= MaxOffset, "Max offset exceeded");
@@ -298,7 +357,11 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
VERIFY(m_NumStaticSamplers <= MaxOffset, "Max offset exceeded");
m_NumStaticSamplers = static_cast<OffsetType>(NumStaticSamplers);
- auto MemorySize = m_TotalResources * sizeof(SPIRVShaderResourceAttribs) + m_NumStaticSamplers * sizeof(RefCntAutoPtr<ISampler>);
+ static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of SPIRVShaderResourceAttribs struct must be multiple of sizeof(void*)");
+ static_assert(sizeof(SamplerPtrType) % sizeof(void*) == 0, "Size of SamplerPtrType must be multiple of sizeof(void*)");
+ auto MemorySize = m_TotalResources * sizeof(SPIRVShaderResourceAttribs) +
+ m_NumStaticSamplers * sizeof(SamplerPtrType) +
+ ResourceNamesPoolSize * sizeof(char);
VERIFY_EXPR(GetNumUBs() == NumUBs);
VERIFY_EXPR(GetNumSBs() == NumSBs);
@@ -312,6 +375,10 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
{
auto *pRawMem = Allocator.Allocate(MemorySize, "Memory for shader resources", __FILE__, __LINE__);
m_MemoryBuffer.reset(pRawMem);
+ char* NamesPool = reinterpret_cast<char*>(m_MemoryBuffer.get()) +
+ m_TotalResources * sizeof(SPIRVShaderResourceAttribs) +
+ m_NumStaticSamplers * sizeof(SamplerPtrType);
+ m_ResourceNames.AssignMemory(NamesPool, ResourceNamesPoolSize);
}
}
@@ -339,7 +406,7 @@ SPIRVShaderResources::~SPIRVShaderResources()
GetSepSmpl(n).~SPIRVShaderResourceAttribs();
for (Uint32 n = 0; n < GetNumStaticSamplers(); ++n)
- GetStaticSampler(n).~RefCntAutoPtr<ISampler>();
+ GetStaticSampler(n).~SamplerPtrType();
}
void SPIRVShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes,
@@ -402,4 +469,47 @@ void SPIRVShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVar
);
}
+std::string SPIRVShaderResources::DumpResources()
+{
+ std::stringstream ss;
+ ss << "Resource counters:" << std::endl << "UBs: " << GetNumUBs() << "; SBs: " << GetNumSBs() << "; Imgs: " << GetNumImgs()
+ << "; Smpl Imgs: " << GetNumSmplImgs() << "; ACs: " << GetNumACs() << "; Sep Imgs: " << GetNumSepImgs()
+ << "; Sep Smpls: " << GetNumSepSmpls() << "; Static Samplers: " << GetNumStaticSamplers() << std::endl << "Resources:";
+
+ ProcessResources(nullptr, 0,
+ [&](const SPIRVShaderResourceAttribs& Res, Uint32)
+ {
+ ss << std::endl;
+ switch(Res.Type)
+ {
+ case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer: ss << "Uniform Buffer "; break;
+ case SPIRVShaderResourceAttribs::ResourceType::StorageBuffer: ss << "Storage Buffer "; break;
+ case SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer: ss << "Uniform Txl Buff"; break;
+ case SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer: ss << "Storage Txl Buff"; break;
+ case SPIRVShaderResourceAttribs::ResourceType::StorageImage: ss << "Storage Image "; break;
+ case SPIRVShaderResourceAttribs::ResourceType::SampledImage: ss << "Sampled Image "; break;
+ case SPIRVShaderResourceAttribs::ResourceType::AtomicCounter: ss << "Atomic Cntr "; break;
+ case SPIRVShaderResourceAttribs::ResourceType::SeparateImage: ss << "Separate Img "; break;
+ case SPIRVShaderResourceAttribs::ResourceType::SeparateSampler: ss << "Separate Smpl "; break;
+ default: UNEXPECTED("Unknown resource type");
+ }
+
+ std::stringstream FullResNameSS;
+ FullResNameSS << '\'' << Res.Name;
+ if(Res.ArraySize > 1)
+ FullResNameSS << '[' << Res.ArraySize << ']';
+ FullResNameSS << '\'';
+ ss << std::setw(32) << FullResNameSS.str();
+ ss << " (" << GetShaderVariableTypeLiteralName(Res.VarType) << ")";
+
+ if(Res.StaticSamplerInd >= 0)
+ {
+ ss << " Static sampler: " << Int32{Res.StaticSamplerInd};
+ }
+ }
+ );
+
+ return ss.str();
+}
+
}