summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp62
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
12namespace Shader::Backend::GLSL { 12namespace Shader::Backend::GLSL {
13namespace { 13namespace {
14constexpr char THREAD_ID[]{"gl_SubGroupInvocationARB"};
15
14void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) { 16void 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
49std::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
56std::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
48void EmitLaneId(EmitContext& ctx, IR::Inst& inst) { 62void EmitLaneId(EmitContext& ctx, IR::Inst& inst) {
49 ctx.AddU32("{}=gl_SubGroupInvocationARB&31u;", inst); 63 ctx.AddU32("{}={}&31u;", inst, THREAD_ID);
50} 64}
51 65
52void EmitVoteAll(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { 66void 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
62void EmitVoteAny(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { 77void 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
72void EmitVoteEqual(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { 88void 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
83void EmitSubgroupBallot(EmitContext& ctx, IR::Inst& inst, std::string_view pred) { 100void 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
91void EmitSubgroupEqMask(EmitContext& ctx, IR::Inst& inst) { 105void 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
95void EmitSubgroupLtMask(EmitContext& ctx, IR::Inst& inst) { 109void 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
99void EmitSubgroupLeMask(EmitContext& ctx, IR::Inst& inst) { 113void 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
103void EmitSubgroupGtMask(EmitContext& ctx, IR::Inst& inst) { 117void 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
107void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) { 121void 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
111void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, 125void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,