mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-23 08:50:57 +01:00
glsl: Rework Shuffle emit instructions to align with SPIR-V
This commit is contained in:
parent
8ba814efb2
commit
b98de76ea8
1 changed files with 40 additions and 19 deletions
|
@ -14,51 +14,72 @@ void SetInBoundsFlag(EmitContext& ctx, IR::Inst& inst) {
|
||||||
if (!in_bounds) {
|
if (!in_bounds) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.AddU1("{}=shfl_in_bounds;", *in_bounds);
|
ctx.AddU1("{}=shfl_in_bounds;", *in_bounds);
|
||||||
in_bounds->Invalidate();
|
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
|
} // namespace
|
||||||
|
|
||||||
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||||
std::string_view index, std::string_view clamp,
|
std::string_view index, std::string_view clamp,
|
||||||
std::string_view segmentation_mask) {
|
std::string_view segmentation_mask) {
|
||||||
ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}"
|
const auto not_seg_mask{fmt::format("(~{})", segmentation_mask)};
|
||||||
"&~{}));",
|
const auto thread_id{"gl_SubGroupInvocationARB"};
|
||||||
index, segmentation_mask, clamp, segmentation_mask);
|
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);
|
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,
|
void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index,
|
||||||
std::string_view clamp, std::string_view segmentation_mask) {
|
std::string_view clamp, std::string_view segmentation_mask) {
|
||||||
ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}"
|
const auto thread_id{"gl_SubGroupInvocationARB"};
|
||||||
"&~{}));",
|
const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)};
|
||||||
index, segmentation_mask, 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);
|
SetInBoundsFlag(ctx, inst);
|
||||||
ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},gl_SubGroupInvocationARB-{}):"
|
ctx.AddU32("{}=shfl_in_bounds?{}:{};", inst, value, src_thread_id);
|
||||||
"{};",
|
|
||||||
inst, value, index, value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||||
std::string_view index, std::string_view clamp,
|
std::string_view index, std::string_view clamp,
|
||||||
std::string_view segmentation_mask) {
|
std::string_view segmentation_mask) {
|
||||||
ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}"
|
const auto thread_id{"gl_SubGroupInvocationARB"};
|
||||||
"&~{}));",
|
const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)};
|
||||||
index, segmentation_mask, 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);
|
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,
|
void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||||
std::string_view index, std::string_view clamp,
|
std::string_view index, std::string_view clamp,
|
||||||
std::string_view segmentation_mask) {
|
std::string_view segmentation_mask) {
|
||||||
ctx.Add("shfl_in_bounds=int(gl_SubGroupInvocationARB-{})>=int((gl_SubGroupInvocationARB&{})|({}"
|
const auto thread_id{"gl_SubGroupInvocationARB"};
|
||||||
"&~{}));",
|
const auto max_thread_id{GetMaxThreadId(thread_id, clamp, segmentation_mask)};
|
||||||
index, segmentation_mask, 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);
|
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,
|
void EmitFSwizzleAdd([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||||
|
|
Loading…
Reference in a new issue