summaryrefslogtreecommitdiffstats
path: root/Graphics/GLSLTools
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-02-26 05:01:54 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-02-26 05:01:54 +0000
commit324c7540bfe3a30c94f18941e2e4131e0aee4b84 (patch)
treeb21489c8949f57e35b02be5c242a104325697a43 /Graphics/GLSLTools
parentCosmetic changes (diff)
downloadDiligentCore-324c7540bfe3a30c94f18941e2e4131e0aee4b84.tar.gz
DiligentCore-324c7540bfe3a30c94f18941e2e4131e0aee4b84.zip
Updated SPIRVShaderResources: removed immutable samplers and variable type
Diffstat (limited to 'Graphics/GLSLTools')
-rw-r--r--Graphics/GLSLTools/include/SPIRVShaderResources.h161
-rw-r--r--Graphics/GLSLTools/src/SPIRVShaderResources.cpp230
2 files changed, 52 insertions, 339 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.h b/Graphics/GLSLTools/include/SPIRVShaderResources.h
index f4c9edfe..7f0796ed 100644
--- a/Graphics/GLSLTools/include/SPIRVShaderResources.h
+++ b/Graphics/GLSLTools/include/SPIRVShaderResources.h
@@ -30,17 +30,15 @@
//
// m_MemoryBuffer m_TotalResources
// | |
-// | Uniform Buffers | Storage Buffers | Storage Images | Sampled Images | Atomic Counters | Separate Samplers | Separate Images | Immutable Samplers | Stage Inputs | Resource Names |
+// | Uniform Buffers | Storage Buffers | Storage Images | Sampled Images | Atomic Counters | Separate Samplers | Separate Images | Stage Inputs | Resource Names |
#include <memory>
#include <vector>
#include <sstream>
#include "Shader.h"
-#include "Sampler.h"
#include "RenderDevice.h"
#include "STDAllocator.h"
-#include "HashUtils.h"
#include "RefCntAutoPtr.h"
#include "StringPool.h"
@@ -53,22 +51,6 @@ struct Resource;
namespace Diligent
{
-inline bool IsAllowedType(SHADER_VARIABLE_TYPE VarType, Uint32 AllowedTypeBits)noexcept
-{
- return ((1 << VarType) & AllowedTypeBits) != 0;
-}
-
-inline Uint32 GetAllowedTypeBits(const SHADER_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes)noexcept
-{
- if(AllowedVarTypes == nullptr)
- return 0xFFFFFFFF;
-
- Uint32 AllowedTypeBits = 0;
- for(Uint32 i=0; i < NumAllowedTypes; ++i)
- AllowedTypeBits |= 1 << AllowedVarTypes[i];
- return AllowedTypeBits;
-}
-
// sizeof(SPIRVShaderResourceAttribs) == 24, msvc x64
struct SPIRVShaderResourceAttribs
{
@@ -86,21 +68,12 @@ struct SPIRVShaderResourceAttribs
NumResourceTypes
};
- static constexpr const Uint32 ResourceTypeBits = 4;
- static constexpr const Uint32 VarTypeBits = 4;
- static_assert(SHADER_VARIABLE_TYPE_NUM_TYPES < (1 << VarTypeBits), "Not enough bits to represent SHADER_VARIABLE_TYPE");
- static_assert(ResourceType::NumResourceTypes < (1 << ResourceTypeBits), "Not enough bits to represent ResourceType");
-
- static constexpr const Uint32 InvalidSepSmplrOrImgInd = static_cast<Uint32>(-1);
+ static constexpr const Uint32 InvalidSepSmplrOrImgInd = static_cast<Uint32>(-1);
/* 0 */const char* const Name;
/* 8 */const Uint16 ArraySize;
-/*10.0*/const ResourceType Type : ResourceTypeBits;
-/*10.4*/const SHADER_VARIABLE_TYPE VarType : VarTypeBits;
+/*10 */const ResourceType Type;
private:
- static constexpr const Uint8 InvalidImmutableSamplerInd = static_cast<Uint8>(-1);
-/*11*/const Uint8 ImmutableSamplerInd;
-
// Defines mapping between separate samplers and seperate images when HLSL-style
// combined texture samplers are in use (i.e. texture2D g_Tex + sampler g_Tex_sampler).
/*12*/ Uint32 SepSmplrOrImgInd = InvalidSepSmplrOrImgInd;
@@ -110,13 +83,11 @@ public:
/*20*/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 _ImmutableSamplerInd = -1,
- Uint32 _SamplerOrSepImgInd = InvalidSepSmplrOrImgInd)noexcept;
+ SPIRVShaderResourceAttribs(const spirv_cross::Compiler& Compiler,
+ const spirv_cross::Resource& Res,
+ const char* _Name,
+ ResourceType _Type,
+ Uint32 _SamplerOrSepImgInd = InvalidSepSmplrOrImgInd) noexcept;
bool IsValidSepSamplerAssigned() const
{
@@ -154,17 +125,6 @@ public:
SepSmplrOrImgInd = SepImageInd;
}
- bool IsImmutableSamplerAssigned() const
- {
- return ImmutableSamplerInd != InvalidImmutableSamplerInd;
- }
-
- Uint32 GetImmutableSamplerInd()const
- {
- VERIFY(Type == ResourceType::SampledImage || Type == ResourceType::SeparateSampler, "Only sampled images and separate samplers can be assigned immutable samplers");
- return ImmutableSamplerInd;
- }
-
String GetPrintName(Uint32 ArrayInd)const
{
VERIFY_EXPR(ArrayInd < ArraySize);
@@ -182,10 +142,7 @@ public:
{
return ArraySize == Attribs.ArraySize &&
Type == Attribs.Type &&
- VarType == Attribs.VarType &&
- SepSmplrOrImgInd == Attribs.SepSmplrOrImgInd &&
- ( (IsImmutableSamplerAssigned() && Attribs.IsImmutableSamplerAssigned()) ||
- (!IsImmutableSamplerAssigned() && !Attribs.IsImmutableSamplerAssigned()) );
+ SepSmplrOrImgInd == Attribs.SepSmplrOrImgInd;
}
};
static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of SPIRVShaderResourceAttribs struct must be multiple of sizeof(void*)" );
@@ -221,8 +178,6 @@ 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); }
@@ -231,7 +186,6 @@ public:
Uint32 GetNumSepSmplrs()const noexcept{ return (m_SeparateImageOffset - m_SeparateSamplerOffset);}
Uint32 GetNumSepImgs ()const noexcept{ return (m_TotalResources - m_SeparateImageOffset); }
Uint32 GetTotalResources() const noexcept { return m_TotalResources; }
- Uint32 GetNumImmutableSamplers()const noexcept { return m_NumImmutableSamplers; }
Uint32 GetNumShaderStageInputs()const noexcept { return m_NumShaderStageInputs; }
const SPIRVShaderResourceAttribs& GetUB (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumUBs(), 0 ); }
@@ -243,23 +197,11 @@ public:
const SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); }
const SPIRVShaderResourceAttribs& GetResource(Uint32 n)const noexcept{ return GetResAttribs(n, GetTotalResources(), 0 ); }
- ISampler* GetImmutableSampler(const SPIRVShaderResourceAttribs& ResAttribs)const noexcept
- {
- if (!ResAttribs.IsImmutableSamplerAssigned())
- return nullptr;
-
- auto ImmutableSamplerInd = ResAttribs.GetImmutableSamplerInd();
- VERIFY(ImmutableSamplerInd < m_NumImmutableSamplers, "Static sampler index (", ImmutableSamplerInd, ") is out of range. Array size: ", m_NumImmutableSamplers);
- auto* ResourceMemoryEnd = reinterpret_cast<SPIRVShaderResourceAttribs*>(m_MemoryBuffer.get()) + m_TotalResources;
- return reinterpret_cast<SamplerPtrType*>(ResourceMemoryEnd)[ImmutableSamplerInd];
- }
-
const SPIRVShaderStageInputAttribs& GetShaderStageInputAttribs(Uint32 n)const noexcept
{
VERIFY(n < m_NumShaderStageInputs, "Shader stage input index (", n, ") is out of range. Total input count: ", m_NumShaderStageInputs);
auto* ResourceMemoryEnd = reinterpret_cast<const SPIRVShaderResourceAttribs*>(m_MemoryBuffer.get()) + m_TotalResources;
- auto* ImmutableSamplerMemoryEnd = reinterpret_cast<const SamplerPtrType*>(ResourceMemoryEnd) + m_NumImmutableSamplers;
- return reinterpret_cast<const SPIRVShaderStageInputAttribs*>(ImmutableSamplerMemoryEnd)[n];
+ return reinterpret_cast<const SPIRVShaderStageInputAttribs*>(ResourceMemoryEnd)[n];
}
struct ResourceCounters
@@ -272,8 +214,6 @@ public:
Uint32 NumSepSmplrs = 0;
Uint32 NumSepImgs = 0;
};
- ResourceCounters CountResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes)const noexcept;
SHADER_TYPE GetShaderType()const noexcept{return m_ShaderType;}
@@ -285,80 +225,64 @@ public:
typename THandleAC,
typename THandleSepSmpl,
typename THandleSepImg>
- void ProcessResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- THandleUB HandleUB,
- THandleSB HandleSB,
- THandleImg HandleImg,
- THandleSmplImg HandleSmplImg,
- THandleAC HandleAC,
- THandleSepSmpl HandleSepSmpl,
- THandleSepImg HandleSepImg)const
+ void ProcessResources(THandleUB HandleUB,
+ THandleSB HandleSB,
+ THandleImg HandleImg,
+ THandleSmplImg HandleSmplImg,
+ THandleAC HandleAC,
+ THandleSepSmpl HandleSepSmpl,
+ THandleSepImg HandleSepImg)const
{
- Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-
for(Uint32 n=0; n < GetNumUBs(); ++n)
{
const auto& UB = GetUB(n);
- if( IsAllowedType(UB.VarType, AllowedTypeBits) )
- HandleUB(UB, n);
+ HandleUB(UB, n);
}
for (Uint32 n = 0; n < GetNumSBs(); ++n)
{
const auto& SB = GetSB(n);
- if (IsAllowedType(SB.VarType, AllowedTypeBits))
- HandleSB(SB, n);
+ HandleSB(SB, n);
}
for (Uint32 n = 0; n < GetNumImgs(); ++n)
{
const auto& Img = GetImg(n);
- if (IsAllowedType(Img.VarType, AllowedTypeBits))
- HandleImg(Img, n);
+ HandleImg(Img, n);
}
for (Uint32 n = 0; n < GetNumSmpldImgs(); ++n)
{
const auto& SmplImg = GetSmpldImg(n);
- if (IsAllowedType(SmplImg.VarType, AllowedTypeBits))
- HandleSmplImg(SmplImg, n);
+ HandleSmplImg(SmplImg, n);
}
for (Uint32 n = 0; n < GetNumACs(); ++n)
{
const auto& AC = GetAC(n);
- if (IsAllowedType(AC.VarType, AllowedTypeBits))
- HandleAC(AC, n);
+ HandleAC(AC, n);
}
for (Uint32 n = 0; n < GetNumSepSmplrs(); ++n)
{
const auto& SepSmpl = GetSepSmplr(n);
- if (IsAllowedType(SepSmpl.VarType, AllowedTypeBits))
- HandleSepSmpl(SepSmpl, n);
+ HandleSepSmpl(SepSmpl, n);
}
for (Uint32 n = 0; n < GetNumSepImgs(); ++n)
{
const auto& SepImg = GetSepImg(n);
- if (IsAllowedType(SepImg.VarType, AllowedTypeBits))
- HandleSepImg(SepImg, n);
+ HandleSepImg(SepImg, n);
}
}
template<typename THandler>
- void ProcessResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- THandler Handler)const
+ void ProcessResources(THandler Handler)const
{
- Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-
for(Uint32 n=0; n < GetTotalResources(); ++n)
{
const auto& Res = GetResource(n);
- if( IsAllowedType(Res.VarType, AllowedTypeBits) )
- Handler(Res, n);
+ Handler(Res, n);
}
}
@@ -375,7 +299,6 @@ public:
private:
void Initialize(IMemoryAllocator& Allocator,
const ResourceCounters& Counters,
- Uint32 NumImmutableSamplers,
Uint32 NumShaderStageInputs,
size_t ResourceNamesPoolSize);
@@ -402,20 +325,13 @@ private:
SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); }
SPIRVShaderResourceAttribs& GetResource(Uint32 n)noexcept{ return GetResAttribs(n, GetTotalResources(), 0 ); }
- SamplerPtrType& GetImmutableSampler(Uint32 n)noexcept
- {
- VERIFY(n < m_NumImmutableSamplers, "Immutable sampler index (", n, ") is out of range. Total immutable sampler count: ", m_NumImmutableSamplers);
- auto* ResourceMemoryEnd = reinterpret_cast<SPIRVShaderResourceAttribs*>(m_MemoryBuffer.get()) + m_TotalResources;
- return reinterpret_cast<SamplerPtrType*>(ResourceMemoryEnd)[n];
- }
-
SPIRVShaderStageInputAttribs& GetShaderStageInputAttribs(Uint32 n)noexcept
{
return const_cast<SPIRVShaderStageInputAttribs&>(const_cast<const SPIRVShaderResources*>(this)->GetShaderStageInputAttribs(n));
}
// Memory buffer that holds all resources as continuous chunk of memory:
- // | UBs | SBs | StrgImgs | SmplImgs | ACs | SepSamplers | SepImgs | Immutable Samplers | Stage Inputs | Resource Names |
+ // | UBs | SBs | StrgImgs | SmplImgs | ACs | SepSamplers | SepImgs | Stage Inputs | Resource Names |
std::unique_ptr< void, STDDeleterRawMem<void> > m_MemoryBuffer;
StringPool m_ResourceNames;
@@ -429,7 +345,6 @@ private:
OffsetType m_SeparateSamplerOffset = 0;
OffsetType m_SeparateImageOffset = 0;
OffsetType m_TotalResources = 0;
- OffsetType m_NumImmutableSamplers = 0;
OffsetType m_NumShaderStageInputs = 0;
SHADER_TYPE m_ShaderType = SHADER_TYPE_UNKNOWN;
@@ -437,25 +352,3 @@ private:
}
-namespace std
-{
-#if 0
- template<>
- struct hash<Diligent::D3DShaderResourceAttribs>
- {
- size_t operator()(const Diligent::D3DShaderResourceAttribs &Attribs) const
- {
- return Attribs.GetHash();
- }
- };
-
- template<>
- struct hash<Diligent::ShaderResources>
- {
- size_t operator()(const Diligent::ShaderResources &Res) const
- {
- return Res.GetHash();
- }
- };
-#endif
-}
diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
index 6b896c8d..4f733103 100644
--- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
+++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp
@@ -50,7 +50,7 @@ Type GetResourceArraySize(const spirv_cross::Compiler& Compiler,
static uint32_t GetDecorationOffset(const spirv_cross::Compiler& Compiler,
const spirv_cross::Resource& Res,
- spv::Decoration Decoration)
+ spv::Decoration Decoration)
{
VERIFY(Compiler.has_decoration(Res.id, Decoration), "Res \'", Res.name, "\' has no requested decoration");
uint32_t offset = 0;
@@ -63,34 +63,18 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const spirv_cross::Compil
const spirv_cross::Resource& Res,
const char* _Name,
ResourceType _Type,
- SHADER_VARIABLE_TYPE _VarType,
- Int32 _ImmutableSamplerInd,
Uint32 _SepSmplrOrImgInd)noexcept :
Name (_Name),
ArraySize (GetResourceArraySize<decltype(ArraySize)>(Compiler, Res)),
Type (_Type),
- VarType (_VarType),
- ImmutableSamplerInd (_ImmutableSamplerInd >= 0 ? static_cast<decltype(ImmutableSamplerInd)>(_ImmutableSamplerInd) : InvalidImmutableSamplerInd),
SepSmplrOrImgInd (_SepSmplrOrImgInd),
BindingDecorationOffset (GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationBinding)),
DescriptorSetDecorationOffset(GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationDescriptorSet))
{
- VERIFY(_ImmutableSamplerInd < 0 || _ImmutableSamplerInd <= std::numeric_limits<decltype(ImmutableSamplerInd)>::max(), "Static sampler index is out of representable range" );
VERIFY(_SepSmplrOrImgInd == SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd || _Type == ResourceType::SeparateSampler ||
_Type == ResourceType::SeparateImage, "Only separate images or separate samplers can be assinged valid SepSmplrOrImgInd value");
}
-static Int32 FindImmutableSampler(const ShaderDesc& shaderDesc, const std::string& SamplerName, const char* SamplerSuffix)
-{
- for (Uint32 s=0; s < shaderDesc.NumStaticSamplers; ++s)
- {
- const auto& StSam = shaderDesc.StaticSamplers[s];
- if (StreqSuff(SamplerName.c_str(), StSam.SamplerOrTextureName, SamplerSuffix))
- return s;
- }
-
- return -1;
-}
static spv::ExecutionModel ShaderTypeToExecutionModel(SHADER_TYPE ShaderType)
{
@@ -256,7 +240,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
ResCounters.NumACs = static_cast<Uint32>(resources.atomic_counters.size());
ResCounters.NumSepSmplrs = static_cast<Uint32>(resources.separate_samplers.size());
ResCounters.NumSepImgs = static_cast<Uint32>(resources.separate_images.size());
- Initialize(Allocator, ResCounters, shaderDesc.NumStaticSamplers, NumShaderStageInputs, ResourceNamesPoolSize);
+ Initialize(Allocator, ResCounters, NumShaderStageInputs, ResourceNamesPoolSize);
{
Uint32 CurrUB = 0;
@@ -267,8 +251,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SPIRVShaderResourceAttribs(Compiler,
UB,
m_ResourceNames.CopyString(name),
- SPIRVShaderResourceAttribs::ResourceType::UniformBuffer,
- GetShaderVariableType(name, shaderDesc));
+ SPIRVShaderResourceAttribs::ResourceType::UniformBuffer);
}
VERIFY_EXPR(CurrUB == GetNumUBs());
}
@@ -281,8 +264,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SPIRVShaderResourceAttribs(Compiler,
SB,
m_ResourceNames.CopyString(SB.name),
- SPIRVShaderResourceAttribs::ResourceType::StorageBuffer,
- GetShaderVariableType(SB.name, shaderDesc));
+ SPIRVShaderResourceAttribs::ResourceType::StorageBuffer);
}
VERIFY_EXPR(CurrSB == GetNumSBs());
}
@@ -291,7 +273,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
Uint32 CurrSmplImg = 0;
for (const auto &SmplImg : resources.sampled_images)
{
- auto ImmutableSamplerInd = FindImmutableSampler(shaderDesc, SmplImg.name, nullptr);
const auto& type = Compiler.get_type(SmplImg.type_id);
auto ResType = type.image.dim == spv::DimBuffer ?
SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer :
@@ -300,16 +281,14 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SPIRVShaderResourceAttribs(Compiler,
SmplImg,
m_ResourceNames.CopyString(SmplImg.name),
- ResType,
- GetShaderVariableType(SmplImg.name, shaderDesc),
- ImmutableSamplerInd);
+ ResType);
}
VERIFY_EXPR(CurrSmplImg == GetNumSmpldImgs());
}
{
Uint32 CurrImg = 0;
- for (const auto &Img : resources.storage_images)
+ for (const auto& Img : resources.storage_images)
{
const auto& type = Compiler.get_type(Img.type_id);
auto ResType = type.image.dim == spv::DimBuffer ?
@@ -319,52 +298,40 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SPIRVShaderResourceAttribs(Compiler,
Img,
m_ResourceNames.CopyString(Img.name),
- ResType,
- GetShaderVariableType(Img.name, shaderDesc));
+ ResType);
}
VERIFY_EXPR(CurrImg == GetNumImgs());
}
{
Uint32 CurrAC = 0;
- for (const auto &AC : resources.atomic_counters)
+ for (const auto& AC : resources.atomic_counters)
{
new (&GetAC(CurrAC++))
SPIRVShaderResourceAttribs(Compiler,
AC,
m_ResourceNames.CopyString(AC.name),
- SPIRVShaderResourceAttribs::ResourceType::AtomicCounter,
- GetShaderVariableType(AC.name, shaderDesc));
+ SPIRVShaderResourceAttribs::ResourceType::AtomicCounter);
}
VERIFY_EXPR(CurrAC == GetNumACs());
}
{
Uint32 CurrSepSmpl = 0;
- for (const auto &SepSam : resources.separate_samplers)
+ for (const auto& SepSam : resources.separate_samplers)
{
- auto ImmutableSamplerInd = FindImmutableSampler(shaderDesc, SepSam.name, CombinedSamplerSuffix);
- // Use texture or sampler name to derive sampler type
- auto VarType = GetShaderVariableType(shaderDesc.DefaultVariableType, shaderDesc.VariableDesc, shaderDesc.NumVariables,
- [&](const char* VarName)
- {
- return StreqSuff(SepSam.name.c_str(), VarName, CombinedSamplerSuffix);
- });
-
new (&GetSepSmplr(CurrSepSmpl++))
SPIRVShaderResourceAttribs(Compiler,
SepSam,
m_ResourceNames.CopyString(SepSam.name),
- SPIRVShaderResourceAttribs::ResourceType::SeparateSampler,
- VarType,
- ImmutableSamplerInd);
+ SPIRVShaderResourceAttribs::ResourceType::SeparateSampler);
}
VERIFY_EXPR(CurrSepSmpl == GetNumSepSmplrs());
}
{
Uint32 CurrSepImg = 0;
- for (const auto &SepImg : resources.separate_images)
+ for (const auto& SepImg : resources.separate_images)
{
Uint32 SamplerInd = SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd;
if (CombinedSamplerSuffix != nullptr)
@@ -376,10 +343,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
if (StreqSuff(SepSmplr.Name, SepImg.name.c_str(), CombinedSamplerSuffix))
{
SepSmplr.AssignSeparateImage(CurrSepImg);
- // Do no assign immutable samplers to separate images as immutable
- // samplers are permanently bound into the set layout
- if (SepSmplr.IsImmutableSamplerAssigned())
- SamplerInd = NumSepSmpls;
break;
}
}
@@ -391,8 +354,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SepImg,
m_ResourceNames.CopyString(SepImg.name),
SPIRVShaderResourceAttribs::ResourceType::SeparateImage,
- GetShaderVariableType(SepImg.name, shaderDesc),
- -1,
SamplerInd);
if (pNewSepImg->IsValidSepSamplerAssigned())
{
@@ -413,13 +374,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
m_CombinedSamplerSuffix = m_ResourceNames.CopyString(CombinedSamplerSuffix);
}
- for (Uint32 s = 0; s < m_NumImmutableSamplers; ++s)
- {
- SamplerPtrType& pStaticSampler = GetImmutableSampler(s);
- new (std::addressof(pStaticSampler)) SamplerPtrType;
- pRenderDevice->CreateSampler(shaderDesc.StaticSamplers[s].Desc, &pStaticSampler);
- }
-
if (LoadShaderStageInputs)
{
Uint32 CurrStageInput = 0;
@@ -438,85 +392,10 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
VERIFY(m_ResourceNames.GetRemainingSize() == 0, "Names pool must be empty");
//LOG_INFO_MESSAGE(DumpResources());
-
-#ifdef DEVELOPMENT
- if (shaderDesc.NumVariables != 0)
- {
- for (Uint32 v = 0; v < shaderDesc.NumVariables; ++v)
- {
- bool VariableFound = false;
- const auto* VarName = shaderDesc.VariableDesc[v].Name;
- auto VarType = shaderDesc.VariableDesc[v].Type;
-
- for (Uint32 res = 0; res < GetTotalResources(); ++res)
- {
- const auto& ResAttribs = GetResource(res);
- if (strcmp(ResAttribs.Name, VarName) == 0)
- {
- VariableFound = true;
- break;
- }
- }
- if (!VariableFound)
- {
- LOG_WARNING_MESSAGE("Variable '", VarName, "' labeled as ", GetShaderVariableTypeLiteralName(VarType), " is not found in shader '", shaderDesc.Name, "'");
- }
- }
- }
-
- if (shaderDesc.NumStaticSamplers != 0)
- {
- for (Uint32 s = 0; s < shaderDesc.NumStaticSamplers; ++s)
- {
- const auto* SamName = shaderDesc.StaticSamplers[s].SamplerOrTextureName;
- bool SamplerFound = false;
-
- // Irrespective of whether HLSL-style combined image samplers are used,
- // a static sampler can be assigned to GLSL sampled image (i.e. sampler2D g_tex)
- for (Uint32 i = 0; i < GetNumSmpldImgs(); ++i)
- {
- const auto& SmplImg = GetSmpldImg(i);
- SamplerFound = (strcmp(SmplImg.Name, SamName) == 0);
- if (SamplerFound)
- break;
- }
-
- if (!SamplerFound)
- {
- // Check if static sampler is assigned to a separate sampler or
- // separate image depending on whether HLSL-style combined samplers
- // are used
- for (Uint32 i = 0; i < GetNumSepSmplrs(); ++i)
- {
- const auto& SepSmpl = GetSepSmplr(i);
- SamplerFound = StreqSuff(SepSmpl.Name, SamName, CombinedSamplerSuffix);
- if (SamplerFound)
- break;
- }
- }
-
- if (!SamplerFound)
- {
- LOG_WARNING_MESSAGE("Static sampler '", SamName, "' is not found in shader '", shaderDesc.Name, "'");
- }
- }
- }
-
- if (CombinedSamplerSuffix != nullptr)
- {
- for (Uint32 n=0; n < GetNumSepSmplrs(); ++n)
- {
- const auto& SepSmplr = GetSepSmplr(n);
- if (!SepSmplr.IsValidSepImageAssigned())
- LOG_ERROR_MESSAGE("Shader '", shaderDesc.Name, "' uses combined texture samplers, but separate sampler '", SepSmplr.Name, "' is not assigned to any texture");
- }
- }
-#endif
}
void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
const ResourceCounters& Counters,
- Uint32 NumImmutableSamplers,
Uint32 NumShaderStageInputs,
size_t ResourceNamesPoolSize)
{
@@ -539,16 +418,11 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
m_SeparateImageOffset = AdvanceOffset(Counters.NumSepImgs);
m_TotalResources = AdvanceOffset(0);
- VERIFY(NumImmutableSamplers <= MaxOffset, "Max offset exceeded");
- m_NumImmutableSamplers = static_cast<OffsetType>(NumImmutableSamplers);
-
VERIFY(NumShaderStageInputs <= MaxOffset, "Max offset exceeded");
m_NumShaderStageInputs = static_cast<OffsetType>(NumShaderStageInputs);
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_NumImmutableSamplers * sizeof(SamplerPtrType) +
m_NumShaderStageInputs * sizeof(SPIRVShaderStageInputAttribs) +
ResourceNamesPoolSize * sizeof(char);
@@ -562,11 +436,10 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator,
if (MemorySize)
{
- auto *pRawMem = Allocator.Allocate(MemorySize, "Memory for shader resources", __FILE__, __LINE__);
+ auto* pRawMem = Allocator.Allocate(MemorySize, "Memory for shader resources", __FILE__, __LINE__);
m_MemoryBuffer = std::unique_ptr<void, STDDeleterRawMem<void>>(pRawMem, Allocator);
char* NamesPool = reinterpret_cast<char*>(m_MemoryBuffer.get()) +
m_TotalResources * sizeof(SPIRVShaderResourceAttribs) +
- m_NumImmutableSamplers * sizeof(SamplerPtrType) +
m_NumShaderStageInputs * sizeof(SPIRVShaderStageInputAttribs);
m_ResourceNames.AssignMemory(NamesPool, ResourceNamesPoolSize);
}
@@ -595,67 +468,11 @@ SPIRVShaderResources::~SPIRVShaderResources()
for (Uint32 n = 0; n < GetNumSepImgs(); ++n)
GetSepImg(n).~SPIRVShaderResourceAttribs();
- for (Uint32 n = 0; n < GetNumImmutableSamplers(); ++n)
- GetImmutableSampler(n).~SamplerPtrType();
-
for (Uint32 n = 0; n < GetNumShaderStageInputs(); ++n)
GetShaderStageInputAttribs(n).~SPIRVShaderStageInputAttribs();
}
-SPIRVShaderResources::ResourceCounters SPIRVShaderResources::CountResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes)const noexcept
-{
- Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); (void)AllowedTypeBits;
- ResourceCounters Counters;
- ProcessResources(
- AllowedVarTypes, NumAllowedTypes,
-
- [&](const SPIRVShaderResourceAttribs& UB, Uint32)
- {
- VERIFY_EXPR(UB.Type == SPIRVShaderResourceAttribs::ResourceType::UniformBuffer);
- VERIFY_EXPR(IsAllowedType(UB.VarType, AllowedTypeBits));
- ++Counters.NumUBs;
- },
- [&](const SPIRVShaderResourceAttribs& SB, Uint32)
- {
- VERIFY_EXPR(SB.Type == SPIRVShaderResourceAttribs::ResourceType::StorageBuffer);
- VERIFY_EXPR(IsAllowedType(SB.VarType, AllowedTypeBits));
- ++Counters.NumSBs;
- },
- [&](const SPIRVShaderResourceAttribs& Img, Uint32)
- {
- VERIFY_EXPR(Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage || Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer);
- VERIFY_EXPR(IsAllowedType(Img.VarType, AllowedTypeBits));
- ++Counters.NumImgs;
- },
- [&](const SPIRVShaderResourceAttribs& SmplImg, Uint32)
- {
- VERIFY_EXPR(SmplImg.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage || SmplImg.Type == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer);
- VERIFY_EXPR(IsAllowedType(SmplImg.VarType, AllowedTypeBits));
- ++Counters.NumSmpldImgs;
- },
- [&](const SPIRVShaderResourceAttribs& AC, Uint32)
- {
- VERIFY_EXPR(AC.Type == SPIRVShaderResourceAttribs::ResourceType::AtomicCounter);
- VERIFY_EXPR(IsAllowedType(AC.VarType, AllowedTypeBits));
- ++Counters.NumACs;
- },
- [&](const SPIRVShaderResourceAttribs& SepSmpl, Uint32)
- {
- VERIFY_EXPR(SepSmpl.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler);
- VERIFY_EXPR(IsAllowedType(SepSmpl.VarType, AllowedTypeBits));
- ++Counters.NumSepSmplrs;
- },
- [&](const SPIRVShaderResourceAttribs& SepImg, Uint32)
- {
- VERIFY_EXPR(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage);
- VERIFY_EXPR(IsAllowedType(SepImg.VarType, AllowedTypeBits));
- ++Counters.NumSepImgs;
- }
- );
- return Counters;
-}
std::string SPIRVShaderResources::DumpResources()
{
@@ -663,7 +480,7 @@ std::string SPIRVShaderResources::DumpResources()
ss << "Resource counters (" << GetTotalResources() << " total):" << std::endl << "UBs: " << GetNumUBs() << "; SBs: "
<< GetNumSBs() << "; Imgs: " << GetNumImgs() << "; Smpl Imgs: " << GetNumSmpldImgs() << "; ACs: " << GetNumACs()
<< "; Sep Imgs: " << GetNumSepImgs() << "; Sep Smpls: " << GetNumSepSmplrs() << '.' << std::endl
- << "Num Static Samplers: " << GetNumImmutableSamplers() << std::endl << "Resources:";
+ << "Resources:";
Uint32 ResNum = 0;
auto DumpResource = [&ss, &ResNum](const SPIRVShaderResourceAttribs& Res)
@@ -674,16 +491,20 @@ std::string SPIRVShaderResources::DumpResources()
FullResNameSS << '[' << Res.ArraySize << ']';
FullResNameSS << '\'';
ss << std::setw(32) << FullResNameSS.str();
- ss << " (" << GetShaderVariableTypeLiteralName(Res.VarType) << ")";
-
- if (Res.IsImmutableSamplerAssigned())
+
+ if (Res.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage && Res.IsValidSepSamplerAssigned())
{
- ss << " Immutable sampler: " << Res.GetImmutableSamplerInd();
+ ss << " Assigned sep sampler ind: " << Res.GetAssignedSepSamplerInd();
}
+ else if (Res.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler && Res.IsValidSepImageAssigned())
+ {
+ ss << " Assigned sep image ind: " << Res.GetAssignedSepImageInd();
+ }
+
++ResNum;
};
- ProcessResources(nullptr, 0,
+ ProcessResources(
[&](const SPIRVShaderResourceAttribs &UB, Uint32)
{
VERIFY(UB.Type == SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, "Unexpected resource type");
@@ -750,13 +571,12 @@ bool SPIRVShaderResources::IsCompatibleWith(const SPIRVShaderResources& Resource
GetNumSmpldImgs() != Resources.GetNumSmpldImgs() ||
GetNumACs() != Resources.GetNumACs() ||
GetNumSepImgs() != Resources.GetNumSepImgs() ||
- GetNumSepSmplrs() != Resources.GetNumSepSmplrs() ||
- GetNumImmutableSamplers() != Resources.GetNumImmutableSamplers())
+ GetNumSepSmplrs() != Resources.GetNumSepSmplrs())
return false;
VERIFY_EXPR(GetTotalResources() == Resources.GetTotalResources());
bool IsCompatible = true;
- ProcessResources(nullptr, 0,
+ ProcessResources(
[&](const SPIRVShaderResourceAttribs& Res, Uint32 n)
{
const auto& Res2 = Resources.GetResource(n);