diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp | 60 |
1 files changed, 36 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 ffbb83352..cd285e2c8 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_warp.cpp | |||
| @@ -123,18 +123,22 @@ void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) { | |||
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 125 | void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, |
| 126 | std::string_view index, std::string_view clamp, | 126 | std::string_view index, std::string_view clamp, std::string_view seg_mask) { |
| 127 | std::string_view segmentation_mask) { | ||
| 128 | if (ctx.profile.support_gl_warp_intrinsics) { | 127 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 129 | UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, segmentation_mask); | 128 | UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, seg_mask); |
| 130 | return; | 129 | return; |
| 131 | } | 130 | } |
| 132 | const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)}; | 131 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 133 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 132 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 134 | const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)}; | 133 | const auto upper_index{fmt::format("{}?{}+32:{}", is_upper_partition, index, index)}; |
| 135 | const auto max_thread_id{ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask)}; | 134 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 135 | |||
| 136 | const auto not_seg_mask{fmt::format("(~{})", seg_mask)}; | ||
| 137 | const auto min_thread_id{ComputeMinThreadId(THREAD_ID, seg_mask)}; | ||
| 138 | const auto max_thread_id{ | ||
| 139 | ComputeMaxThreadId(min_thread_id, big_warp ? upper_clamp : clamp, not_seg_mask)}; | ||
| 136 | 140 | ||
| 137 | const auto lhs{fmt::format("({}&{})", index, not_seg_mask)}; | 141 | const auto lhs{fmt::format("({}&{})", big_warp ? upper_index : index, not_seg_mask)}; |
| 138 | const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)}; | 142 | const auto src_thread_id{fmt::format("({})|({})", lhs, min_thread_id)}; |
| 139 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); | 143 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); |
| 140 | SetInBoundsFlag(ctx, inst); | 144 | SetInBoundsFlag(ctx, inst); |
| @@ -142,29 +146,34 @@ void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value, | |||
| 142 | } | 146 | } |
| 143 | 147 | ||
| 144 | void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, | 148 | void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index, |
| 145 | std::string_view clamp, std::string_view segmentation_mask) { | 149 | std::string_view clamp, std::string_view seg_mask) { |
| 146 | if (ctx.profile.support_gl_warp_intrinsics) { | 150 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 147 | UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, segmentation_mask); | 151 | UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, seg_mask); |
| 148 | return; | 152 | return; |
| 149 | } | 153 | } |
| 150 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 154 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 151 | const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; | 155 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 152 | const auto src_thread_id{fmt::format("({}-{})", thread_id, index)}; | 156 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 157 | |||
| 158 | const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)}; | ||
| 159 | const auto src_thread_id{fmt::format("({}-{})", THREAD_ID, index)}; | ||
| 153 | ctx.Add("shfl_in_bounds=int({})>=int({});", src_thread_id, max_thread_id); | 160 | ctx.Add("shfl_in_bounds=int({})>=int({});", src_thread_id, max_thread_id); |
| 154 | SetInBoundsFlag(ctx, inst); | 161 | SetInBoundsFlag(ctx, inst); |
| 155 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); | 162 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); |
| 156 | } | 163 | } |
| 157 | 164 | ||
| 158 | void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 165 | void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, |
| 159 | std::string_view index, std::string_view clamp, | 166 | std::string_view index, std::string_view clamp, std::string_view seg_mask) { |
| 160 | std::string_view segmentation_mask) { | ||
| 161 | if (ctx.profile.support_gl_warp_intrinsics) { | 167 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 162 | UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, segmentation_mask); | 168 | UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, seg_mask); |
| 163 | return; | 169 | return; |
| 164 | } | 170 | } |
| 165 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 171 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 166 | const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; | 172 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 167 | const auto src_thread_id{fmt::format("({}+{})", thread_id, index)}; | 173 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 174 | |||
| 175 | const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)}; | ||
| 176 | const auto src_thread_id{fmt::format("({}+{})", THREAD_ID, index)}; | ||
| 168 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); | 177 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); |
| 169 | SetInBoundsFlag(ctx, inst); | 178 | SetInBoundsFlag(ctx, inst); |
| 170 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); | 179 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); |
| @@ -172,14 +181,17 @@ void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value, | |||
| 172 | 181 | ||
| 173 | void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, | 182 | void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value, |
| 174 | std::string_view index, std::string_view clamp, | 183 | std::string_view index, std::string_view clamp, |
| 175 | std::string_view segmentation_mask) { | 184 | std::string_view seg_mask) { |
| 176 | if (ctx.profile.support_gl_warp_intrinsics) { | 185 | if (ctx.profile.support_gl_warp_intrinsics) { |
| 177 | UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, segmentation_mask); | 186 | UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, seg_mask); |
| 178 | return; | 187 | return; |
| 179 | } | 188 | } |
| 180 | const auto thread_id{"gl_SubGroupInvocationARB"}; | 189 | const bool big_warp{ctx.profile.warp_size_potentially_larger_than_guest}; |
| 181 | const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)}; | 190 | const auto is_upper_partition{"int(gl_SubGroupInvocationARB)>=32"}; |
| 182 | const auto src_thread_id{fmt::format("({}^{})", thread_id, index)}; | 191 | const auto upper_clamp{fmt::format("{}?{}+32:{}", is_upper_partition, clamp, clamp)}; |
| 192 | |||
| 193 | const auto max_thread_id{GetMaxThreadId(THREAD_ID, big_warp ? upper_clamp : clamp, seg_mask)}; | ||
| 194 | const auto src_thread_id{fmt::format("({}^{})", THREAD_ID, index)}; | ||
| 183 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); | 195 | ctx.Add("shfl_in_bounds=int({})<=int({});", src_thread_id, max_thread_id); |
| 184 | SetInBoundsFlag(ctx, inst); | 196 | SetInBoundsFlag(ctx, inst); |
| 185 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); | 197 | ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value); |