diff options
| author | azhirnov <zh1dron@gmail.com> | 2020-10-21 22:15:55 +0000 |
|---|---|---|
| committer | azhirnov <zh1dron@gmail.com> | 2020-10-25 10:50:53 +0000 |
| commit | 42217cc1ec7f81c028dcc5c1f845a2fc3b3da497 (patch) | |
| tree | 2efcb7c0fdeae582ecb5c8d13c7bedd593ab9a3c /Graphics/ShaderTools | |
| parent | Fixed Mac/iOS build (diff) | |
| parent | Updated Metal testing environment (diff) | |
| download | DiligentCore-42217cc1ec7f81c028dcc5c1f845a2fc3b3da497.tar.gz DiligentCore-42217cc1ec7f81c028dcc5c1f845a2fc3b3da497.zip | |
Merge branch 'master' into ray_tracing
# Conflicts:
# Graphics/GraphicsEngine/interface/PipelineState.h
# Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp
# Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp
# Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp
Diffstat (limited to 'Graphics/ShaderTools')
| -rw-r--r-- | Graphics/ShaderTools/include/SPIRVShaderResources.hpp | 19 | ||||
| -rw-r--r-- | Graphics/ShaderTools/src/SPIRVShaderResources.cpp | 49 |
2 files changed, 63 insertions, 5 deletions
diff --git a/Graphics/ShaderTools/include/SPIRVShaderResources.hpp b/Graphics/ShaderTools/include/SPIRVShaderResources.hpp index 5c35de33..091e2343 100644 --- a/Graphics/ShaderTools/include/SPIRVShaderResources.hpp +++ b/Graphics/ShaderTools/include/SPIRVShaderResources.hpp @@ -78,10 +78,11 @@ struct SPIRVShaderResourceAttribs static constexpr const Uint32 InvalidSepSmplrOrImgInd = static_cast<Uint32>(-1); -/* 0 */const char* const Name; -/* 8 */const Uint16 ArraySize; -/* 10 */const ResourceType Type; -/* 11 */ // unused +/* 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). @@ -159,6 +160,16 @@ public: } ShaderResourceDesc GetResourceDesc() const; + + RESOURCE_DIMENSION GetResourceDimension() const + { + return static_cast<RESOURCE_DIMENSION>(ResourceDim); + } + + bool IsMultisample() const + { + return IsMS != 0; + } }; static_assert(sizeof(SPIRVShaderResourceAttribs) % sizeof(void*) == 0, "Size of SPIRVShaderResourceAttribs struct must be multiple of sizeof(void*)"); diff --git a/Graphics/ShaderTools/src/SPIRVShaderResources.cpp b/Graphics/ShaderTools/src/SPIRVShaderResources.cpp index dbdc81bc..cda18772 100644 --- a/Graphics/ShaderTools/src/SPIRVShaderResources.cpp +++ b/Graphics/ShaderTools/src/SPIRVShaderResources.cpp @@ -53,6 +53,46 @@ Type GetResourceArraySize(const diligent_spirv_cross::Compiler& Compiler, return static_cast<Type>(arrSize); } +static RESOURCE_DIMENSION GetResourceDimension(const diligent_spirv_cross::Compiler& Compiler, + const diligent_spirv_cross::Resource& Res) +{ + const auto& type = Compiler.get_type(Res.type_id); + if (type.basetype == diligent_spirv_cross::SPIRType::BaseType::Image || + type.basetype == diligent_spirv_cross::SPIRType::BaseType::SampledImage) + { + switch (type.image.dim) + { + // clang-format off + case spv::Dim1D: return type.image.arrayed ? RESOURCE_DIM_TEX_1D_ARRAY : RESOURCE_DIM_TEX_1D; + case spv::Dim2D: return type.image.arrayed ? RESOURCE_DIM_TEX_2D_ARRAY : RESOURCE_DIM_TEX_2D; + case spv::Dim3D: return RESOURCE_DIM_TEX_3D; + case spv::DimCube: return type.image.arrayed ? RESOURCE_DIM_TEX_CUBE_ARRAY : RESOURCE_DIM_TEX_CUBE; + case spv::DimBuffer: return RESOURCE_DIM_BUFFER; + // clang-format on + default: return RESOURCE_DIM_UNDEFINED; + } + } + else + { + return RESOURCE_DIM_UNDEFINED; + } +} + +static bool IsMultisample(const diligent_spirv_cross::Compiler& Compiler, + const diligent_spirv_cross::Resource& Res) +{ + const auto& type = Compiler.get_type(Res.type_id); + if (type.basetype == diligent_spirv_cross::SPIRType::BaseType::Image || + type.basetype == diligent_spirv_cross::SPIRType::BaseType::SampledImage) + { + return type.image.ms; + } + else + { + return RESOURCE_DIM_UNDEFINED; + } +} + static uint32_t GetDecorationOffset(const diligent_spirv_cross::Compiler& Compiler, const diligent_spirv_cross::Resource& Res, spv::Decoration Decoration) @@ -74,6 +114,8 @@ SPIRVShaderResourceAttribs::SPIRVShaderResourceAttribs(const diligent_spirv_cros Name {_Name}, ArraySize {GetResourceArraySize<decltype(ArraySize)>(Compiler, Res)}, 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)} @@ -588,6 +630,7 @@ void SPIRVShaderResources::Initialize(IMemoryAllocator& Allocator, VERIFY_EXPR(GetNumACs() == Counters.NumACs); VERIFY_EXPR(GetNumSepSmplrs() == Counters.NumSepSmplrs); VERIFY_EXPR(GetNumSepImgs() == Counters.NumSepImgs); + VERIFY_EXPR(GetNumInptAtts() == Counters.NumInptAtts); // clang-format on if (MemorySize) @@ -624,6 +667,9 @@ SPIRVShaderResources::~SPIRVShaderResources() for (Uint32 n = 0; n < GetNumSepImgs(); ++n) GetSepImg(n).~SPIRVShaderResourceAttribs(); + for (Uint32 n = 0; n < GetNumInptAtts(); ++n) + GetInptAtt(n).~SPIRVShaderResourceAttribs(); + for (Uint32 n = 0; n < GetNumShaderStageInputs(); ++n) GetShaderStageInputAttribs(n).~SPIRVShaderStageInputAttribs(); } @@ -754,7 +800,8 @@ bool SPIRVShaderResources::IsCompatibleWith(const SPIRVShaderResources& Resource GetNumSmpldImgs() != Resources.GetNumSmpldImgs() || GetNumACs() != Resources.GetNumACs() || GetNumSepImgs() != Resources.GetNumSepImgs() || - GetNumSepSmplrs() != Resources.GetNumSepSmplrs()) + GetNumSepSmplrs() != Resources.GetNumSepSmplrs() || + GetNumInptAtts() != Resources.GetNumInptAtts()) return false; // clang-format on VERIFY_EXPR(GetTotalResources() == Resources.GetTotalResources()); |
