diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-08-04 21:05:42 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-08-04 21:05:42 +0000 |
| commit | 86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea (patch) | |
| tree | e4d8d6f4f90a4805d6d230d6fd7f49390be4cdab /Graphics/GLSLTools | |
| parent | Added render pass MS resolve test (diff) | |
| download | DiligentCore-86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea.tar.gz DiligentCore-86bd2d7175d3e2d0f5c1c313a802a22c9f95b4ea.zip | |
Implemented input attachments in Vulkan backend; added test
Diffstat (limited to 'Graphics/GLSLTools')
| -rw-r--r-- | Graphics/GLSLTools/include/SPIRVShaderResources.hpp | 22 | ||||
| -rw-r--r-- | Graphics/GLSLTools/src/SPIRVShaderResources.cpp | 40 |
2 files changed, 55 insertions, 7 deletions
diff --git a/Graphics/GLSLTools/include/SPIRVShaderResources.hpp b/Graphics/GLSLTools/include/SPIRVShaderResources.hpp index 96e778a0..7a1b93ce 100644 --- a/Graphics/GLSLTools/include/SPIRVShaderResources.hpp +++ b/Graphics/GLSLTools/include/SPIRVShaderResources.hpp @@ -70,6 +70,7 @@ struct SPIRVShaderResourceAttribs AtomicCounter, SeparateImage, SeparateSampler, + InputAttachment, NumResourceTypes }; @@ -205,7 +206,8 @@ public: Uint32 GetNumSmpldImgs()const noexcept{ return (m_AtomicCounterOffset - m_SampledImageOffset); } Uint32 GetNumACs ()const noexcept{ return (m_SeparateSamplerOffset - m_AtomicCounterOffset); } Uint32 GetNumSepSmplrs()const noexcept{ return (m_SeparateImageOffset - m_SeparateSamplerOffset);} - Uint32 GetNumSepImgs ()const noexcept{ return (m_TotalResources - m_SeparateImageOffset); } + Uint32 GetNumSepImgs ()const noexcept{ return (m_InputAttachmentOffset - m_SeparateImageOffset); } + Uint32 GetNumInptAtts ()const noexcept{ return (m_TotalResources - m_InputAttachmentOffset);} Uint32 GetTotalResources() const noexcept { return m_TotalResources; } Uint32 GetNumShaderStageInputs()const noexcept { return m_NumShaderStageInputs; } @@ -216,6 +218,7 @@ public: const SPIRVShaderResourceAttribs& GetAC (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumACs(), m_AtomicCounterOffset ); } const SPIRVShaderResourceAttribs& GetSepSmplr(Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSepSmplrs(), m_SeparateSamplerOffset); } const SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); } + const SPIRVShaderResourceAttribs& GetInptAtt (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumInptAtts(), m_InputAttachmentOffset); } const SPIRVShaderResourceAttribs& GetResource(Uint32 n)const noexcept{ return GetResAttribs(n, GetTotalResources(), 0 ); } // clang-format on @@ -243,6 +246,7 @@ public: Uint32 NumACs = 0; Uint32 NumSepSmplrs = 0; Uint32 NumSepImgs = 0; + Uint32 NumInptAtts = 0; }; SHADER_TYPE GetShaderType() const noexcept { return m_ShaderType; } @@ -254,14 +258,16 @@ public: typename THandleSmplImg, typename THandleAC, typename THandleSepSmpl, - typename THandleSepImg> + typename THandleSepImg, + typename THandleInptAtt> void ProcessResources(THandleUB HandleUB, THandleSB HandleSB, THandleImg HandleImg, THandleSmplImg HandleSmplImg, THandleAC HandleAC, THandleSepSmpl HandleSepSmpl, - THandleSepImg HandleSepImg) const + THandleSepImg HandleSepImg, + THandleInptAtt HandleInptAtt) const { for (Uint32 n = 0; n < GetNumUBs(); ++n) { @@ -304,6 +310,14 @@ public: const auto& SepImg = GetSepImg(n); HandleSepImg(SepImg, n); } + + for (Uint32 n = 0; n < GetNumInptAtts(); ++n) + { + const auto& InptAtt = GetInptAtt(n); + HandleInptAtt(InptAtt, n); + } + + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type here, if needed"); } template <typename THandler> @@ -359,6 +373,7 @@ private: SPIRVShaderResourceAttribs& GetAC (Uint32 n)noexcept{ return GetResAttribs(n, GetNumACs(), m_AtomicCounterOffset ); } SPIRVShaderResourceAttribs& GetSepSmplr(Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepSmplrs(), m_SeparateSamplerOffset); } SPIRVShaderResourceAttribs& GetSepImg (Uint32 n)noexcept{ return GetResAttribs(n, GetNumSepImgs(), m_SeparateImageOffset ); } + SPIRVShaderResourceAttribs& GetInptAtt (Uint32 n)noexcept{ return GetResAttribs(n, GetNumInptAtts(), m_InputAttachmentOffset); } SPIRVShaderResourceAttribs& GetResource(Uint32 n)noexcept{ return GetResAttribs(n, GetTotalResources(), 0 ); } // clang-format on @@ -384,6 +399,7 @@ private: OffsetType m_AtomicCounterOffset = 0; OffsetType m_SeparateSamplerOffset = 0; OffsetType m_SeparateImageOffset = 0; + OffsetType m_InputAttachmentOffset = 0; OffsetType m_TotalResources = 0; OffsetType m_NumShaderStageInputs = 0; diff --git a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp index 46705ace..0dd3e4ae 100644 --- a/Graphics/GLSLTools/src/SPIRVShaderResources.cpp +++ b/Graphics/GLSLTools/src/SPIRVShaderResources.cpp @@ -91,7 +91,7 @@ ShaderResourceDesc SPIRVShaderResourceAttribs::GetResourceDesc() const ResourceDesc.Name = Name; ResourceDesc.ArraySize = ArraySize; - static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 10, "Please update switch statement below"); + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please handle the new resource type below"); switch (Type) { case SPIRVShaderResourceAttribs::ResourceType::UniformBuffer: @@ -137,6 +137,10 @@ ShaderResourceDesc SPIRVShaderResourceAttribs::GetResourceDesc() const ResourceDesc.Type = SHADER_RESOURCE_TYPE_SAMPLER; break; + case SPIRVShaderResourceAttribs::ResourceType::InputAttachment: + ResourceDesc.Type = SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT; + break; + default: UNEXPECTED("Unknown SPIRV resource type"); } @@ -245,6 +249,7 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, size_t ResourceNamesPoolSize = 0; for (const auto& ub : resources.uniform_buffers) ResourceNamesPoolSize += GetUBName(Compiler, ub, ParsedIRSource).length() + 1; + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please account for the new resource type below"); for (auto* pResType : { &resources.storage_buffers, @@ -252,10 +257,11 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, &resources.sampled_images, &resources.atomic_counters, &resources.separate_images, - &resources.separate_samplers - //clang-format off + &resources.separate_samplers, + &resources.subpass_inputs + // clang-format off }) - //clang-format on + // clang-format on { for (const auto& res : *pResType) ResourceNamesPoolSize += res.name.length() + 1; @@ -322,6 +328,8 @@ 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()); + ResCounters.NumInptAtts = static_cast<Uint32>(resources.subpass_inputs.size()); + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please set the new resource type counter here"); Initialize(Allocator, ResCounters, NumShaderStageInputs, ResourceNamesPoolSize); { @@ -469,6 +477,21 @@ SPIRVShaderResources::SPIRVShaderResources(IMemoryAllocator& Allocator, VERIFY_EXPR(CurrSepImg == GetNumSepImgs()); } + { + Uint32 CurrSubpassInput = 0; + for (const auto& SubpassInput : resources.subpass_inputs) + { + new (&GetInptAtt(CurrSubpassInput++)) + SPIRVShaderResourceAttribs(Compiler, + SubpassInput, + m_ResourceNames.CopyString(SubpassInput.name), + SPIRVShaderResourceAttribs::ResourceType::InputAttachment); + } + VERIFY_EXPR(CurrSubpassInput == GetNumInptAtts()); + } + + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please initialize SPIRVShaderResourceAttribs for the new resource type here"); + if (CombinedSamplerSuffix != nullptr) { m_CombinedSamplerSuffix = m_ResourceNames.CopyString(CombinedSamplerSuffix); @@ -531,7 +554,9 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator, m_AtomicCounterOffset = AdvanceOffset(Counters.NumACs); m_SeparateSamplerOffset = AdvanceOffset(Counters.NumSepSmplrs); m_SeparateImageOffset = AdvanceOffset(Counters.NumSepImgs); + m_InputAttachmentOffset = AdvanceOffset(Counters.NumInptAtts); m_TotalResources = AdvanceOffset(0); + static_assert(SPIRVShaderResourceAttribs::ResourceType::NumResourceTypes == 11, "Please update the new resource type offset"); VERIFY(NumShaderStageInputs <= MaxOffset, "Max offset exceeded"); m_NumShaderStageInputs = static_cast<OffsetType>(NumShaderStageInputs); @@ -692,6 +717,13 @@ std::string SPIRVShaderResources::DumpResources() ss << std::endl << std::setw(3) << ResNum << " Separate Img "; DumpResource(SepImg); + }, + [&](const SPIRVShaderResourceAttribs& InptAtt, Uint32) // + { + VERIFY(InptAtt.Type == SPIRVShaderResourceAttribs::ResourceType::InputAttachment, "Unexpected resource type"); + ss << std::endl + << std::setw(3) << ResNum << " Input Attachment "; + DumpResource(InptAtt); } // ); VERIFY_EXPR(ResNum == GetTotalResources()); |
