summaryrefslogtreecommitdiffstats
path: root/Graphics/ShaderTools
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2021-01-26 07:13:38 +0000
committerazhirnov <zh1dron@gmail.com>2021-01-26 07:13:38 +0000
commite540eca4582ee3cea2388d7b6dd274d7c605021b (patch)
tree577e845effd1bc2993708719a20b6cf1e233d37b /Graphics/ShaderTools
parentadded immutable samplers to descriptor set layout, fixed PRS tests (diff)
downloadDiligentCore-e540eca4582ee3cea2388d7b6dd274d7c605021b.tar.gz
DiligentCore-e540eca4582ee3cea2388d7b6dd274d7c605021b.zip
remove assigned samplers from SPIRV resources
Diffstat (limited to 'Graphics/ShaderTools')
-rw-r--r--Graphics/ShaderTools/include/SPIRVShaderResources.hpp76
-rw-r--r--Graphics/ShaderTools/src/SPIRVShaderResources.cpp101
2 files changed, 10 insertions, 167 deletions
diff --git a/Graphics/ShaderTools/include/SPIRVShaderResources.hpp b/Graphics/ShaderTools/include/SPIRVShaderResources.hpp
index 67dd31be..2565e44e 100644
--- a/Graphics/ShaderTools/include/SPIRVShaderResources.hpp
+++ b/Graphics/ShaderTools/include/SPIRVShaderResources.hpp
@@ -79,25 +79,18 @@ struct SPIRVShaderResourceAttribs
// clang-format off
- static constexpr const Uint32 InvalidSepSmplrOrImgInd = static_cast<Uint32>(-1);
-
/* 0 */const char* const Name;
/* 8 */const Uint16 ArraySize;
/* 10 */const ResourceType Type;
/* 11.0*/const Uint8 ResourceDim : 7;
/* 11.7*/const Uint8 IsMS : 1;
-private:
- // Defines the 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; // AZ TODO: remove
-public:
// Offset in SPIRV words (uint32_t) of binding & descriptor set decorations in SPIRV binary
-/* 16 */const uint32_t BindingDecorationOffset;
-/* 20 */const uint32_t DescriptorSetDecorationOffset;
+/* 12 */const uint32_t BindingDecorationOffset;
+/* 16 */const uint32_t DescriptorSetDecorationOffset;
-/* 24 */const Uint32 BufferStaticSize;
-/* 28 */const Uint32 BufferStride;
-/* 32 */ // End of structure
+/* 20 */const Uint32 BufferStaticSize;
+/* 24 */const Uint32 BufferStride;
+/* 28 */ // End of structure
// clang-format on
@@ -105,54 +98,8 @@ public:
const diligent_spirv_cross::Resource& Res,
const char* _Name,
ResourceType _Type,
- Uint32 _SamplerOrSepImgInd = InvalidSepSmplrOrImgInd,
- Uint32 _BufferStaticSize = 0,
- Uint32 _BufferStride = 0) noexcept;
-
- bool IsValidSepSamplerAssigned() const
- {
- VERIFY_EXPR(Type == ResourceType::SeparateImage);
- return SepSmplrOrImgInd != InvalidSepSmplrOrImgInd;
- }
-
- bool IsValidSepImageAssigned() const
- {
- VERIFY_EXPR(Type == ResourceType::SeparateSampler);
- return SepSmplrOrImgInd != InvalidSepSmplrOrImgInd;
- }
-
- Uint32 GetAssignedSepSamplerInd() const
- {
- VERIFY_EXPR(Type == ResourceType::SeparateImage);
- return SepSmplrOrImgInd;
- }
-
- Uint32 GetAssignedSepImageInd() const
- {
- VERIFY_EXPR(Type == ResourceType::SeparateSampler);
- return SepSmplrOrImgInd;
- }
-
- void AssignSeparateSampler(Uint32 SemSamplerInd)
- {
- VERIFY_EXPR(Type == ResourceType::SeparateImage);
- SepSmplrOrImgInd = SemSamplerInd;
- }
-
- void AssignSeparateImage(Uint32 SepImageInd)
- {
- VERIFY_EXPR(Type == ResourceType::SeparateSampler);
- SepSmplrOrImgInd = SepImageInd;
- }
-
- bool IsCompatibleWith(const SPIRVShaderResourceAttribs& Attribs) const
- {
- // clang-format off
- return ArraySize == Attribs.ArraySize &&
- Type == Attribs.Type &&
- SepSmplrOrImgInd == Attribs.SepSmplrOrImgInd;
- // clang-format on
- }
+ Uint32 _BufferStaticSize = 0,
+ Uint32 _BufferStride = 0) noexcept;
ShaderResourceDesc GetResourceDesc() const
{
@@ -241,13 +188,6 @@ public:
return reinterpret_cast<const SPIRVShaderStageInputAttribs*>(ResourceMemoryEnd)[n];
}
- const SPIRVShaderResourceAttribs& GetAssignedSepSampler(const SPIRVShaderResourceAttribs& SepImg) const
- {
- VERIFY(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage, "Separate samplers can only be assigned to separate images");
- VERIFY(SepImg.IsValidSepSamplerAssigned(), "This separate image is not assigned a separate sampler");
- return GetSepSmplr(SepImg.GetAssignedSepSamplerInd());
- }
-
struct ResourceCounters
{
Uint32 NumUBs = 0;
@@ -352,8 +292,6 @@ public:
std::string DumpResources();
- bool IsCompatibleWith(const SPIRVShaderResources& Resources) const;
-
// clang-format off
const char* GetCombinedSamplerSuffix() const { return m_CombinedSamplerSuffix; }
diff --git a/Graphics/ShaderTools/src/SPIRVShaderResources.cpp b/Graphics/ShaderTools/src/SPIRVShaderResources.cpp
index 47a25e8a..32844192 100644
--- a/Graphics/ShaderTools/src/SPIRVShaderResources.cpp
+++ b/Graphics/ShaderTools/src/SPIRVShaderResources.cpp
@@ -109,7 +109,6 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const diligent_spirv_cros
const diligent_spirv_cross::Resource& Res,
const char* _Name,
ResourceType _Type,
- Uint32 _SepSmplrOrImgInd,
Uint32 _BufferStaticSize,
Uint32 _BufferStride) noexcept :
// clang-format off
@@ -118,17 +117,12 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const diligent_spirv_cros
Type {_Type},
ResourceDim {Diligent::GetResourceDimension(Compiler, Res)},
IsMS {Diligent::IsMultisample(Compiler, Res) ? Uint8{1} : Uint8{0}},
- SepSmplrOrImgInd {_SepSmplrOrImgInd},
BindingDecorationOffset {GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationBinding)},
DescriptorSetDecorationOffset {GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationDescriptorSet)},
BufferStaticSize {_BufferStaticSize},
BufferStride {_BufferStride}
// clang-format on
-{
- VERIFY(_SepSmplrOrImgInd == SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd ||
- (_Type == ResourceType::SeparateSampler || _Type == ResourceType::SeparateImage),
- "Only separate images or separate samplers can be assinged valid SepSmplrOrImgInd value");
-}
+{}
SHADER_RESOURCE_TYPE SPIRVShaderResourceAttribs::GetShaderResourceType(ResourceType Type)
@@ -389,7 +383,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
UB,
ResourceNamesPool.CopyString(name),
SPIRVShaderResourceAttribs::ResourceType::UniformBuffer,
- SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd,
static_cast<Uint32>(Size));
}
VERIFY_EXPR(CurrUB == GetNumUBs());
@@ -412,7 +405,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SB,
ResourceNamesPool.CopyString(SB.name),
ResType,
- SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd,
static_cast<Uint32>(Size),
static_cast<Uint32>(Stride));
}
@@ -488,46 +480,11 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer :
SPIRVShaderResourceAttribs::ResourceType::SeparateImage;
- Uint32 SamplerInd = SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd; // AZ TODO: remove
- if (CombinedSamplerSuffix != nullptr)
- {
- auto NumSepSmpls = GetNumSepSmplrs();
- for (SamplerInd = 0; SamplerInd < NumSepSmpls; ++SamplerInd)
- {
- auto& SepSmplr = GetSepSmplr(SamplerInd);
- if (StreqSuff(SepSmplr.Name, SepImg.name.c_str(), CombinedSamplerSuffix))
- {
- SepSmplr.AssignSeparateImage(CurrSepImg);
- break;
- }
- }
- if (SamplerInd == NumSepSmpls)
- SamplerInd = SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd;
- else
- {
- if (ResType == SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer)
- {
- LOG_WARNING_MESSAGE("Combined image sampler assigned to uniform texel buffer '", SepImg.name, "' will be ignored");
- SamplerInd = SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd;
- }
- }
- }
- auto* pNewSepImg = new (&GetSepImg(CurrSepImg++))
+ new (&GetSepImg(CurrSepImg++))
SPIRVShaderResourceAttribs(Compiler,
SepImg,
ResourceNamesPool.CopyString(SepImg.name),
- ResType,
- SamplerInd);
- if (ResType == SPIRVShaderResourceAttribs::ResourceType::SeparateImage && pNewSepImg->IsValidSepSamplerAssigned())
- {
-#ifdef DILIGENT_DEVELOPMENT
- const auto& SepSmplr = GetSepSmplr(pNewSepImg->GetAssignedSepSamplerInd());
- DEV_CHECK_ERR(SepSmplr.ArraySize == 1 || SepSmplr.ArraySize == pNewSepImg->ArraySize,
- "Array size (", SepSmplr.ArraySize, ") of separate sampler variable '",
- SepSmplr.Name, "' must be equal to 1 or be the same as the array size (", pNewSepImg->ArraySize,
- ") of separate image variable '", pNewSepImg->Name, "' it is assigned to");
-#endif
- }
+ ResType);
}
VERIFY_EXPR(CurrSepImg == GetNumSepImgs());
}
@@ -585,18 +542,6 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator,
VERIFY(ResourceNamesPool.GetRemainingSize() == 0, "Names pool must be empty");
//LOG_INFO_MESSAGE(DumpResources());
-
-#ifdef DILIGENT_DEVELOPMENT
- 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,
@@ -715,16 +660,6 @@ std::string SPIRVShaderResources::DumpResources()
FullResNameSS << '[' << Res.ArraySize << ']';
FullResNameSS << '\'';
ss << std::setw(32) << FullResNameSS.str();
-
- if (Res.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage && Res.IsValidSepSamplerAssigned())
- {
- ss << " Assigned sep sampler ind: " << Res.GetAssignedSepSamplerInd();
- }
- else if (Res.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler && Res.IsValidSepImageAssigned())
- {
- ss << " Assigned sep image ind: " << Res.GetAssignedSepImageInd();
- }
-
++ResNum;
};
@@ -819,34 +754,4 @@ std::string SPIRVShaderResources::DumpResources()
return ss.str();
}
-
-
-bool SPIRVShaderResources::IsCompatibleWith(const SPIRVShaderResources& Resources) const
-{
- // clang-format off
- if( GetNumUBs() != Resources.GetNumUBs() ||
- GetNumSBs() != Resources.GetNumSBs() ||
- GetNumImgs() != Resources.GetNumImgs() ||
- GetNumSmpldImgs() != Resources.GetNumSmpldImgs() ||
- GetNumACs() != Resources.GetNumACs() ||
- GetNumSepImgs() != Resources.GetNumSepImgs() ||
- GetNumSepSmplrs() != Resources.GetNumSepSmplrs() ||
- GetNumInptAtts() != Resources.GetNumInptAtts() ||
- GetNumAccelStructs() != Resources.GetNumAccelStructs())
- return false;
- // clang-format on
- VERIFY_EXPR(GetTotalResources() == Resources.GetTotalResources());
- static_assert(Uint32{SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes} == 12, "Please update comparison with the new resource");
-
- bool IsCompatible = true;
- ProcessResources(
- [&](const SPIRVShaderResourceAttribs& Res, Uint32 n) {
- const auto& Res2 = Resources.GetResource(n);
- if (!Res.IsCompatibleWith(Res2))
- IsCompatible = false;
- });
-
- return IsCompatible;
-}
-
} // namespace Diligent