diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp index a982dd8a2..ffbb83352 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | 11 | ||
| 12 | namespace Shader::Backend::GLSL { | 12 | namespace Shader::Backend::GLSL { |
| 13 | namespace { | 13 | namespace { |
| 14 | constexpr char THREAD_ID[]{"gl_SubGroupInvocationARB"}; | ||
| 15 | |||
| 14 | void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) { | 16 | void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) { |
| 15 | IR::Inst* const in_bounds{inst.GetAssociatedPseudoOperation(IR::Opcode::GetInBoundsFromOp)}; | 17 | IR::Inst* const in_bounds{inst.GetAssociatedPseudoOperation(IR::Opcode::GetInBoundsFromOp)}; |
| 16 | if (!in_bounds) { | 18 | if (!in_bounds) { |
| @@ -43,69 +45,81 @@ void UseShuffleNv(EmitContext& ctx, IR::Inst& inst, std::string_view shfl_op, | |||
| 43 | ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width); | 45 | ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width); |
| 44 | SetInBoundsFlag(ctx, inst); | 46 | SetInBoundsFlag(ctx, inst); |
| 45 | } | 47 | } |
| 48 | |||
| 49 | std::string_view BallotIndex(EmitContext& ctx) { | ||
| 50 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | ||
| 51 | return ".x"; | ||
| 52 | } | ||
| 53 | return "[gl_SubGroupInvocationARB>>5]"; | ||
| 54 | } | ||
| 55 | |||
| 56 | std::string GetMask(EmitContext& ctx, std::string_view mask) { | ||
| 57 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 58 | return fmt::format("uint(uvec2({}){})", mask, ballot_index); | ||
| 59 | } | ||
| 46 | } // Anonymous namespace | 60 | } // Anonymous namespace |
| 47 | 61 | ||
| 48 | void EmitLaneId(EmitContext& ctx, IR::Inst& inst) { | 62 | void EmitLaneId(EmitContext& ctx, IR::Inst& inst) { |
| 49 | ctx.AddU32("{}=gl_SubGroupInvocationARB&31u;", inst); | 63 | ctx.AddU32("{}={}&31u;", inst, THREAD_ID); |
| 50 | } | 64 | } |
| 51 | 65 | ||
| 52 | void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 66 | void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 53 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 67 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 54 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); | 68 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); |
| 55 | } else { | 69 | return; |
| 56 | const auto active_mask{fmt::format("uvec2(ballotARB(true))[gl_SubGroupInvocationARB]")}; | ||
| 57 | const auto ballot{fmt::format("uvec2(ballotARB({}))[gl_SubGroupInvocationARB]", pred)}; | ||
| 58 | ctx.AddU1("{}=({}&{})=={};", inst, ballot, active_mask, active_mask); | ||
| 59 | } | 70 | } |
| 71 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 72 | const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)}; | ||
| 73 | const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)}; | ||
| 74 | ctx.AddU1("{}=({}&{})=={};", inst, ballot, active_mask, active_mask); | ||
| 60 | } | 75 | } |
| 61 | 76 | ||
| 62 | void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 77 | void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 63 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 78 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 64 | ctx.AddU1("{}=anyInvocationARB({});", inst, pred); | 79 | ctx.AddU1("{}=anyInvocationARB({});", inst, pred); |
| 65 | } else { | 80 | return; |
| 66 | const auto active_mask{fmt::format("uvec2(ballotARB(true))[gl_SubGroupInvocationARB]")}; | ||
| 67 | const auto ballot{fmt::format("uvec2(ballotARB({}))[gl_SubGroupInvocationARB]", pred)}; | ||
| 68 | ctx.AddU1("{}=({}&{})!=0u;", inst, ballot, active_mask, active_mask); | ||
| 69 | } | 81 | } |
| 82 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 83 | const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)}; | ||
| 84 | const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)}; | ||
| 85 | ctx.AddU1("{}=({}&{})!=0u;", inst, ballot, active_mask, active_mask); | ||
| 70 | } | 86 | } |
| 71 | 87 | ||
| 72 | void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 88 | void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 73 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 89 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { |
| 74 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); | 90 | ctx.AddU1("{}=allInvocationsEqualARB({});", inst, pred); |
| 75 | } else { | 91 | return; |
| 76 | const auto active_mask{fmt::format("uvec2(ballotARB(true))[gl_SubGroupInvocationARB]")}; | ||
| 77 | const auto ballot{fmt::format("uvec2(ballotARB({}))[gl_SubGroupInvocationARB]", pred)}; | ||
| 78 | const auto value{fmt::format("({}^{})", ballot, active_mask)}; | ||
| 79 | ctx.AddU1("{}=({}==0)||({}=={});", inst, value, value, active_mask); | ||
| 80 | } | 92 | } |
| 93 | const auto ballot_index{BallotIndex(ctx)}; | ||
| 94 | const auto active_mask{fmt::format("uvec2(ballotARB(true)){}", ballot_index)}; | ||
| 95 | const auto ballot{fmt::format("uvec2(ballotARB({})){}", pred, ballot_index)}; | ||
| 96 | const auto value{fmt::format("({}^{})", ballot, active_mask)}; | ||
| 97 | ctx.AddU1("{}=({}==0)||({}=={});", inst, value, value, active_mask); | ||
| 81 | } | 98 | } |
| 82 | 99 | ||
| 83 | void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { | 100 | void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { |
| 84 | if (!ctx.profile.warp_size_potentially_larger_than_guest) { | 101 | const auto ballot_index{BallotIndex(ctx)}; |
| 85 | ctx.AddU32("{}=uvec2(ballotARB({})).x;", inst, pred); | 102 | ctx.AddU32("{}=uvec2(ballotARB({})){};", inst, pred, ballot_index); |
| 86 | } else { | ||
| 87 | ctx.AddU32("{}=uvec2(ballotARB({}))[gl_SubGroupInvocationARB];", inst, pred); | ||
| 88 | } | ||
| 89 | } | 103 | } |
| 90 | 104 | ||
| 91 | void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) { | 105 | void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) { |
| 92 | ctx.AddU32("{}=uint(gl_SubGroupEqMaskARB.x);", inst); | 106 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupEqMaskARB")); |
| 93 | } | 107 | } |
| 94 | 108 | ||
| 95 | void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) { | 109 | void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) { |
| 96 | ctx.AddU32("{}=uint(gl_SubGroupLtMaskARB.x);", inst); | 110 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupLtMaskARB")); |
| 97 | } | 111 | } |
| 98 | 112 | ||
| 99 | void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) { | 113 | void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) { |
| 100 | ctx.AddU32("{}=uint(gl_SubGroupLeMaskARB.x);", inst); | 114 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupLeMaskARB")); |
| 101 | } | 115 | } |
| 102 | 116 | ||
| 103 | void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) { | 117 | void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) { |
| 104 | ctx.AddU32("{}=uint(gl_SubGroupGtMaskARB.x);", inst); | 118 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupGtMaskARB")); |
| 105 | } | 119 | } |
| 106 | 120 | ||
| 107 | void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) { | 121 | void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) { |
| 108 | ctx.AddU32("{}=uint(gl_SubGroupGeMaskARB.x);", inst); | 122 | ctx.AddU32("{}={};", inst, GetMask(ctx, "gl_SubGroupGeMaskARB")); |
| 109 | } | 123 | } |
| 110 | 124 | ||
| 111 | void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 125 | void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, |