diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-02 19:25:02 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-02 19:25:02 +0000 |
| commit | 95491dc230f022aca641e9fcc79e8e61b850cd3a (patch) | |
| tree | 0f7a8d588635db0263d452685aab8bd2fb507d49 /Graphics/GLSLTools | |
| parent | Minor update (diff) | |
| download | DiligentCore-95491dc230f022aca641e9fcc79e8e61b850cd3a.tar.gz DiligentCore-95491dc230f022aca641e9fcc79e8e61b850cd3a.zip | |
Some minor (mostly cosmetic) changes to SPIRVShaderResources
Diffstat (limited to 'Graphics/GLSLTools')
| -rw-r--r-- | Graphics/GLSLTools/include/SPIRVShaderResources.h | 20 | ||||
| -rw-r--r-- | Graphics/GLSLTools/src/SPIRVShaderResources.cpp | 52 |
2 files changed, 37 insertions, 35 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.h b/Graphics/GLSLTools/include/SPIRVShaderResources.h index 4809bb71..523ccc29 100644 --- a/Graphics/GLSLTools/include/SPIRVShaderResources.h +++ b/Graphics/GLSLTools/include/SPIRVShaderResources.h @@ -70,18 +70,19 @@ struct SPIRVShaderResourceAttribs static constexpr const Uint32 InvalidSepSmplrOrImgInd = static_cast<Uint32>(-1); -/* 0 */const char* const Name; -/* 8 */const Uint16 ArraySize; -/*10 */const ResourceType Type; +/* 0 */const char* const Name; +/* 8 */const Uint16 ArraySize; +/* 10 */const ResourceType Type; +/* 11 */ // unused private: - // Defines mapping between separate samplers and seperate images when HLSL-style + // 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; +/* 12 */ Uint32 SepSmplrOrImgInd = InvalidSepSmplrOrImgInd; 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; - +/* 16 */const uint32_t BindingDecorationOffset; +/* 20 */const uint32_t DescriptorSetDecorationOffset; +/* 24 */ // End of structure SPIRVShaderResourceAttribs(const spirv_cross::Compiler& Compiler, const spirv_cross::Resource& Res, @@ -147,6 +148,7 @@ public: }; static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of SPIRVShaderResourceAttribs struct must be multiple of sizeof(void*)" ); +// sizeof(SPIRVShaderResourceAttribs) == 16, msvc x64 struct SPIRVShaderStageInputAttribs { SPIRVShaderStageInputAttribs(const char* _Semantic, uint32_t _LocationDecorationOffset) : @@ -290,8 +292,6 @@ public: bool IsCompatibleWith(const SPIRVShaderResources& Resources)const; - //size_t GetHash()const; - const char* GetCombinedSamplerSuffix() const { return m_CombinedSamplerSuffix; } const char* GetShaderName() const { return m_ShaderName; } bool IsUsingCombinedSamplers() const { return m_CombinedSamplerSuffix != nullptr; } diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp index 50bebf47..7289e9fd 100644 --- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp +++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp @@ -52,7 +52,7 @@ static uint32_t GetDecorationOffset(const spirv_cross::Compiler& Compiler, const spirv_cross::Resource& Res, spv::Decoration Decoration) { - VERIFY(Compiler.has_decoration(Res.id, Decoration), "Res \'", Res.name, "\' has no requested decoration"); + VERIFY(Compiler.has_decoration(Res.id, Decoration), "Resource \'", Res.name, "\' has no requested decoration"); uint32_t offset = 0; auto declared = Compiler.get_binary_offset_for_decoration(Res.id, Decoration, offset); VERIFY(declared, "Requested decoration is not declared"); (void)declared; @@ -71,8 +71,9 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const spirv_cross::Compil BindingDecorationOffset (GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationBinding)), DescriptorSetDecorationOffset(GetDecorationOffset(Compiler, Res, spv::Decoration::DecorationDescriptorSet)) { - VERIFY(_SepSmplrOrImgInd == SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd || _Type == ResourceType::SeparateSampler || - _Type == ResourceType::SeparateImage, "Only separate images or separate samplers can be assinged valid SepSmplrOrImgInd value"); + VERIFY(_SepSmplrOrImgInd == SPIRVShaderResourceAttribs::InvalidSepSmplrOrImgInd || + (_Type == ResourceType::SeparateSampler || _Type == ResourceType::SeparateImage), + "Only separate images or separate samplers can be assinged valid SepSmplrOrImgInd value"); } @@ -170,9 +171,9 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, spirv_cross::ShaderResources resources = Compiler.get_shader_resources(); size_t ResourceNamesPoolSize = 0; - for(const auto &ub : resources.uniform_buffers) + for (const auto& ub : resources.uniform_buffers) ResourceNamesPoolSize += GetUBName(Compiler, ub, ParsedIRSource).length() + 1; - for(auto *pResType : + for (auto* pResType : { &resources.storage_buffers, &resources.storage_images, @@ -182,7 +183,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, &resources.separate_samplers }) { - for(const auto &res : *pResType) + for(const auto& res : *pResType) ResourceNamesPoolSize += res.name.length() + 1; } @@ -191,6 +192,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, ResourceNamesPoolSize += strlen(CombinedSamplerSuffix) + 1; } + VERIFY_EXPR(shaderDesc.Name != nullptr); ResourceNamesPoolSize += strlen(shaderDesc.Name) + 1; Uint32 NumShaderStageInputs = 0; @@ -246,10 +248,10 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, { Uint32 CurrUB = 0; - for (const auto &UB : resources.uniform_buffers) + for (const auto& UB : resources.uniform_buffers) { const auto& name = GetUBName(Compiler, UB, ParsedIRSource); - new (&GetUB(CurrUB++)) + new (&GetUB(CurrUB++)) SPIRVShaderResourceAttribs(Compiler, UB, m_ResourceNames.CopyString(name), @@ -260,7 +262,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, { Uint32 CurrSB = 0; - for (const auto &SB : resources.storage_buffers) + for (const auto& SB : resources.storage_buffers) { new (&GetSB(CurrSB++)) SPIRVShaderResourceAttribs(Compiler, @@ -273,13 +275,13 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, { Uint32 CurrSmplImg = 0; - for (const auto &SmplImg : resources.sampled_images) + for (const auto& SmplImg : resources.sampled_images) { const auto& type = Compiler.get_type(SmplImg.type_id); auto ResType = type.image.dim == spv::DimBuffer ? SPIRVShaderResourceAttribs::ResourceType::UniformTexelBuffer : SPIRVShaderResourceAttribs::ResourceType::SampledImage; - new (&GetSmpldImg(CurrSmplImg++)) + new (&GetSmpldImg(CurrSmplImg++)) SPIRVShaderResourceAttribs(Compiler, SmplImg, m_ResourceNames.CopyString(SmplImg.name), @@ -296,7 +298,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, auto ResType = type.image.dim == spv::DimBuffer ? SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer : SPIRVShaderResourceAttribs::ResourceType::StorageImage; - new (&GetImg(CurrImg++)) + new (&GetImg(CurrImg++)) SPIRVShaderResourceAttribs(Compiler, Img, m_ResourceNames.CopyString(Img.name), @@ -386,7 +388,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, if (Compiler.has_decoration(Input.id, spv::Decoration::DecorationHlslSemanticGOOGLE)) { const auto& Semantic = Compiler.get_decoration_string(Input.id, spv::Decoration::DecorationHlslSemanticGOOGLE); - new (&GetShaderStageInputAttribs(CurrStageInput++)) + new (&GetShaderStageInputAttribs(CurrStageInput++)) SPIRVShaderStageInputAttribs(m_ResourceNames.CopyString(Semantic), GetDecorationOffset(Compiler, Input, spv::Decoration::DecorationLocation)); } } @@ -419,7 +421,7 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator, constexpr Uint32 MaxOffset = std::numeric_limits<OffsetType>::max(); auto AdvanceOffset = [&CurrentOffset, MaxOffset](Uint32 NumResources) { - VERIFY(CurrentOffset <= MaxOffset, "Current offser (", CurrentOffset, ") exceeds max allowed value (", MaxOffset, ")"); (void)MaxOffset; + VERIFY(CurrentOffset <= MaxOffset, "Current offset (", CurrentOffset, ") exceeds max allowed value (", MaxOffset, ")"); (void)MaxOffset; auto Offset = static_cast<OffsetType>(CurrentOffset); CurrentOffset += NumResources; return Offset; @@ -493,10 +495,10 @@ SPIRVShaderResources::~SPIRVShaderResources() std::string SPIRVShaderResources::DumpResources() { std::stringstream ss; - 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 - << "Resources:"; + ss << "Shader '" << m_ShaderName << "' resource stats: total resources: " << GetTotalResources() << ":" << std::endl + << "UBs: " << GetNumUBs() << "; SBs: " << GetNumSBs() << "; Imgs: " << GetNumImgs() << "; Smpl Imgs: " << GetNumSmpldImgs() + << "; ACs: " << GetNumACs() << "; Sep Imgs: " << GetNumSepImgs() << "; Sep Smpls: " << GetNumSepSmplrs() << '.' << std::endl + << "Resources:"; Uint32 ResNum = 0; auto DumpResource = [&ss, &ResNum](const SPIRVShaderResourceAttribs& Res) @@ -521,7 +523,7 @@ std::string SPIRVShaderResources::DumpResources() }; ProcessResources( - [&](const SPIRVShaderResourceAttribs &UB, Uint32) + [&](const SPIRVShaderResourceAttribs& UB, Uint32) { VERIFY(UB.Type == SPIRVShaderResourceAttribs::ResourceType::UniformBuffer, "Unexpected resource type"); ss << std::endl << std::setw(3) << ResNum << " Uniform Buffer "; @@ -533,9 +535,9 @@ std::string SPIRVShaderResources::DumpResources() ss << std::endl << std::setw(3) << ResNum << " Storage Buffer "; DumpResource(SB); }, - [&](const SPIRVShaderResourceAttribs &Img, Uint32) + [&](const SPIRVShaderResourceAttribs& Img, Uint32) { - if(Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage) + if (Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageImage) ss << std::endl << std::setw(3) << ResNum << " Storage Image "; else if(Img.Type == SPIRVShaderResourceAttribs::ResourceType::StorageTexelBuffer) ss << std::endl << std::setw(3) << ResNum << " Storage Txl Buff"; @@ -543,7 +545,7 @@ std::string SPIRVShaderResources::DumpResources() UNEXPECTED("Unexpected resource type"); DumpResource(Img); }, - [&](const SPIRVShaderResourceAttribs &SmplImg, Uint32) + [&](const SPIRVShaderResourceAttribs& SmplImg, Uint32) { if (SmplImg.Type == SPIRVShaderResourceAttribs::ResourceType::SampledImage) ss << std::endl << std::setw(3) << ResNum << " Sampled Image "; @@ -553,19 +555,19 @@ std::string SPIRVShaderResources::DumpResources() UNEXPECTED("Unexpected resource type"); DumpResource(SmplImg); }, - [&](const SPIRVShaderResourceAttribs &AC, Uint32) + [&](const SPIRVShaderResourceAttribs& AC, Uint32) { VERIFY(AC.Type == SPIRVShaderResourceAttribs::ResourceType::AtomicCounter, "Unexpected resource type"); ss << std::endl << std::setw(3) << ResNum << " Atomic Cntr "; DumpResource(AC); }, - [&](const SPIRVShaderResourceAttribs &SepSmpl, Uint32) + [&](const SPIRVShaderResourceAttribs& SepSmpl, Uint32) { VERIFY(SepSmpl.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateSampler, "Unexpected resource type"); ss << std::endl << std::setw(3) << ResNum << " Separate Smpl "; DumpResource(SepSmpl); }, - [&](const SPIRVShaderResourceAttribs &SepImg, Uint32) + [&](const SPIRVShaderResourceAttribs& SepImg, Uint32) { VERIFY(SepImg.Type == SPIRVShaderResourceAttribs::ResourceType::SeparateImage, "Unexpected resource type"); ss << std::endl << std::setw(3) << ResNum << " Separate Img "; |
