From 244184d34e9470b191640cd20540a8ed939242d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Sun, 13 Dec 2020 13:12:24 -0800 Subject: [PATCH] Updated spirv-cross. --- 3rdparty/spirv-cross/spirv_glsl.cpp | 38 +++++++++++++++++++++++------ 3rdparty/spirv-cross/spirv_glsl.hpp | 33 +++++++++++++------------ 3rdparty/spirv-cross/spirv_hlsl.cpp | 6 +++++ 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/3rdparty/spirv-cross/spirv_glsl.cpp b/3rdparty/spirv-cross/spirv_glsl.cpp index f1653e221..ca68e87f5 100644 --- a/3rdparty/spirv-cross/spirv_glsl.cpp +++ b/3rdparty/spirv-cross/spirv_glsl.cpp @@ -502,6 +502,10 @@ void CompilerGLSL::find_static_extensions() } break; + case CapabilityVariablePointers: + case CapabilityVariablePointersStorageBuffer: + SPIRV_CROSS_THROW("VariablePointers capability is not supported in GLSL."); + default: break; } @@ -3565,9 +3569,9 @@ void CompilerGLSL::emit_extension_workarounds(spv::ExecutionModel model) statement(""); } - if (shader_subgroup_supporter.is_feature_requested(Supp::SubgroupBrodcast_First)) + if (shader_subgroup_supporter.is_feature_requested(Supp::SubgroupBroadcast_First)) { - auto exts = Supp::get_candidates_for_feature(Supp::SubgroupBrodcast_First, result); + auto exts = Supp::get_candidates_for_feature(Supp::SubgroupBroadcast_First, result); for (auto &e : exts) { @@ -6169,6 +6173,7 @@ std::string CompilerGLSL::to_texture_op(const Instruction &i, bool sparse, bool bool gather = false; bool proj = false; bool fetch = false; + bool nonuniform_expression = false; const uint32_t *opt = nullptr; auto &result_type = get(result_type_id); @@ -6177,7 +6182,17 @@ std::string CompilerGLSL::to_texture_op(const Instruction &i, bool sparse, bool // Make sure non-uniform decoration is back-propagated to where it needs to be. if (has_decoration(img, DecorationNonUniformEXT)) - propagate_nonuniform_qualifier(img); + { + // In Vulkan GLSL, we cannot back-propgate nonuniform qualifiers if we + // use a combined image sampler constructor. + // We're only interested in back-propagating if we can trace back through access chains. + // If not, we will apply nonuniform to the sampled image expression itself. + auto *backing = maybe_get_backing_variable(img); + if (backing) + propagate_nonuniform_qualifier(img); + else + nonuniform_expression = true; + } switch (op) { @@ -6362,6 +6377,7 @@ std::string CompilerGLSL::to_texture_op(const Instruction &i, bool sparse, bool args.sample = sample; args.sparse_texel = sparse_texel_id; args.min_lod = minlod; + args.nonuniform_expression = nonuniform_expression; expr += to_function_args(args, forward); expr += ")"; @@ -6550,6 +6566,12 @@ string CompilerGLSL::to_function_args(const TextureFunctionArguments &args, bool else farg_str = to_expression(img); + if (args.nonuniform_expression && farg_str.find_first_of('[') != string::npos) + { + // Only emit nonuniformEXT() wrapper if the underlying expression is arrayed in some way. + farg_str = join(backend.nonuniform_qualifier, "(", farg_str, ")"); + } + bool swizz_func = backend.swizzle_is_function; auto swizzle = [swizz_func](uint32_t comps, uint32_t in_comps) -> const char * { if (comps == in_comps) @@ -7358,7 +7380,7 @@ void CompilerGLSL::emit_subgroup_op(const Instruction &i) case OpGroupNonUniformBroadcast: case OpGroupNonUniformBroadcastFirst: - request_subgroup_feature(ShaderSubgroupSupportHelper::SubgroupBrodcast_First); + request_subgroup_feature(ShaderSubgroupSupportHelper::SubgroupBroadcast_First); break; case OpGroupNonUniformShuffle: @@ -15128,7 +15150,7 @@ CompilerGLSL::ShaderSubgroupSupportHelper::FeatureVector CompilerGLSL::ShaderSub switch (feature) { case SubgroupAllEqualT: - return { SubgroupBrodcast_First, SubgroupAll_Any_AllEqualBool }; + return { SubgroupBroadcast_First, SubgroupAll_Any_AllEqualBool }; case SubgroupElect: return { SubgroupBallotFindLSB_MSB, SubgroupBallot, SubgroupInvocationID }; case SubgroupInverseBallot_InclBitCount_ExclBitCout: @@ -15163,8 +15185,8 @@ CompilerGLSL::ShaderSubgroupSupportHelper::Candidate CompilerGLSL::ShaderSubgrou static const Candidate extensions[FeatureCount] = { KHR_shader_subgroup_ballot, KHR_shader_subgroup_basic, KHR_shader_subgroup_basic, KHR_shader_subgroup_basic, KHR_shader_subgroup_basic, KHR_shader_subgroup_ballot, KHR_shader_subgroup_ballot, KHR_shader_subgroup_vote, - KHR_shader_subgroup_vote, KHR_shader_subgroup_basic, KHR_shader_subgroup_ballot, KHR_shader_subgroup_basic, - KHR_shader_subgroup_basic, KHR_shader_subgroup_ballot, KHR_shader_subgroup_ballot, KHR_shader_subgroup_ballot + KHR_shader_subgroup_vote, KHR_shader_subgroup_basic, KHR_shader_subgroup_basic, KHR_shader_subgroup_basic, + KHR_shader_subgroup_ballot, KHR_shader_subgroup_ballot, KHR_shader_subgroup_ballot, KHR_shader_subgroup_ballot }; return extensions[feature]; @@ -15238,7 +15260,7 @@ CompilerGLSL::ShaderSubgroupSupportHelper::CandidateVector CompilerGLSL::ShaderS return { KHR_shader_subgroup_basic, NV_shader_thread_group }; case NumSubgroups: return { KHR_shader_subgroup_basic, NV_shader_thread_group }; - case SubgroupBrodcast_First: + case SubgroupBroadcast_First: return { KHR_shader_subgroup_ballot, NV_shader_thread_shuffle, ARB_shader_ballot }; case SubgroupBallotFindLSB_MSB: return { KHR_shader_subgroup_ballot, NV_shader_thread_group }; diff --git a/3rdparty/spirv-cross/spirv_glsl.hpp b/3rdparty/spirv-cross/spirv_glsl.hpp index 3c41efef7..c382db678 100644 --- a/3rdparty/spirv-cross/spirv_glsl.hpp +++ b/3rdparty/spirv-cross/spirv_glsl.hpp @@ -275,22 +275,22 @@ protected: enum Feature { - SubgroupMask, - SubgroupSize, - SubgroupInvocationID, - SubgroupID, - NumSubgroups, - SubgroupBrodcast_First, - SubgroupBallotFindLSB_MSB, - SubgroupAll_Any_AllEqualBool, - SubgroupAllEqualT, - SubgroupElect, - SubgroupBarrier, - SubgroupMemBarrier, - SubgroupBallot, - SubgroupInverseBallot_InclBitCount_ExclBitCout, - SubgroupBallotBitExtract, - SubgroupBallotBitCount, + SubgroupMask = 0, + SubgroupSize = 1, + SubgroupInvocationID = 2, + SubgroupID = 3, + NumSubgroups = 4, + SubgroupBroadcast_First = 5, + SubgroupBallotFindLSB_MSB = 6, + SubgroupAll_Any_AllEqualBool = 7, + SubgroupAllEqualT = 8, + SubgroupElect = 9, + SubgroupBarrier = 10, + SubgroupMemBarrier = 11, + SubgroupBallot = 12, + SubgroupInverseBallot_InclBitCount_ExclBitCout = 13, + SubgroupBallotBitExtract = 14, + SubgroupBallotBitCount = 15, FeatureCount }; @@ -405,6 +405,7 @@ protected: uint32_t coord = 0, coord_components = 0, dref = 0; uint32_t grad_x = 0, grad_y = 0, lod = 0, coffset = 0, offset = 0; uint32_t bias = 0, component = 0, sample = 0, sparse_texel = 0, min_lod = 0; + bool nonuniform_expression = false; }; virtual std::string to_function_args(const TextureFunctionArguments &args, bool *p_forward); diff --git a/3rdparty/spirv-cross/spirv_hlsl.cpp b/3rdparty/spirv-cross/spirv_hlsl.cpp index 94210e73c..f79e2be7a 100644 --- a/3rdparty/spirv-cross/spirv_hlsl.cpp +++ b/3rdparty/spirv-cross/spirv_hlsl.cpp @@ -5616,6 +5616,12 @@ void CompilerHLSL::validate_shader_model() if (hlsl_options.shader_model < 51) SPIRV_CROSS_THROW( "Shader model 5.1 or higher is required to use bindless resources or NonUniformResourceIndex."); + break; + + case CapabilityVariablePointers: + case CapabilityVariablePointersStorageBuffer: + SPIRV_CROSS_THROW("VariablePointers capability is not supported in HLSL."); + default: break; }