diff options
author | ameerj <52414509+ameerj@users.noreply.github.com> | 2021-05-29 03:58:26 +0200 |
---|---|---|
committer | ameerj <52414509+ameerj@users.noreply.github.com> | 2021-07-23 03:51:36 +0200 |
commit | b98de76ea8c8d159f1c44edac20c9a3390da1f40 (patch) | |
tree | 0cc7f4855f02b2fa9ae40687d52f55eb61999fa7 /src/shader_recompiler/backend/glsl | |
parent | glsl: Better Storage access and wip warps (diff) | |
download | yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.tar yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.tar.gz yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.tar.bz2 yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.tar.lz yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.tar.xz yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.tar.zst yuzu-b98de76ea8c8d159f1c44edac20c9a3390da1f40.zip |
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp | 59 |
1 files changed, 40 insertions, 19 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp index 0a488188b..0b85aaba2 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp @@ -14,51 +14,72 @@ void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) { if (!in_bounds) { return; } - ctx.AddU1("{}=shfl_in_bounds;", *in_bounds); in_bounds->Invalidate(); } + +std::string ComputeMinThreadId(std::string_view thread_id, std::string_view segmentation_mask) { + return fmt::format("({}&{})", thread_id, segmentation_mask); +} + +std::string ComputeMaxThreadId(std::string_view min_thread_id, std::string_view clamp, + std::string_view not_seg_mask) { + return fmt::format("({})|({}&{})", min_thread_id, clamp, not_seg_mask); +} + +std::string GetMaxThreadId(std::string_view thread_id, std::string_view clamp, + std::string_view segmentation_mask) { + const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)}; + const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)}; + return ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask); +} } // namespace void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, std::string_view clamp, std::string_view segmentation_mask) { - ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}" - "&~{}));", - index, segmentation_mask, clamp, segmentation_mask); + const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)}; + const auto thread_id{"gl_SubGroupInvocationARB"}; + const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)}; + const auto max_thread_id{ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask)}; + + const auto lhs{fmt::format("({}&{})", index, not_seg_mask)}; + const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)}; + ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); SetInBoundsFlag(ctx, inst); - ctx.AddU32("{}=shfl_in_bounds?{}:gl_SubGroupInvocationARB-{};", inst, value, index); + ctx.AddU32("{}=shfl_in_bounds?{}:{};", inst, value, src_thread_id); } void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, std::string_view clamp, std::string_view segmentation_mask) { - ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}" - "&~{}));", - index, segmentation_mask, clamp, segmentation_mask); + const auto thread_id{"gl_SubGroupInvocationARB"}; + const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; + const auto src_thread_id{fmt::format("({}-{})", thread_id, index)}; + ctx.Add("shfl_in_bounds=int({})>=int({});", src_thread_id, max_thread_id); SetInBoundsFlag(ctx, inst); - ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},gl_SubGroupInvocationARB-{}):" - "{};", - inst, value, index, value); + ctx.AddU32("{}=shfl_in_bounds?{}:{};", inst, value, src_thread_id); } void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, std::string_view clamp, std::string_view segmentation_mask) { - ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}" - "&~{}));", - index, segmentation_mask, clamp, segmentation_mask); + const auto thread_id{"gl_SubGroupInvocationARB"}; + const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; + const auto src_thread_id{fmt::format("({}+{})", thread_id, index)}; + ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); SetInBoundsFlag(ctx, inst); - ctx.AddU32("{}=shfl_in_bounds?{}:gl_SubGroupInvocationARB-{};", inst, value, index); + ctx.AddU32("{}=shfl_in_bounds?{}:{};", inst, value, src_thread_id); } void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, std::string_view clamp, std::string_view segmentation_mask) { - ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}" - "&~{}));", - index, segmentation_mask, clamp, segmentation_mask); + const auto thread_id{"gl_SubGroupInvocationARB"}; + const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; + const auto src_thread_id{fmt::format("({}^{})", thread_id, index)}; + ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); SetInBoundsFlag(ctx, inst); - ctx.AddU32("{}=shfl_in_bounds?{}:gl_SubGroupInvocationARB-{};", inst, value, index); + ctx.AddU32("{}=shfl_in_bounds?{}:{};", inst, value, src_thread_id); } void EmitFSwizzleAdd([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst, |