mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-23 15:22:45 +01:00
glsl: Implement fswzadd
and wip nv thread shuffle impl
This commit is contained in:
parent
c542204113
commit
8bb8bbf4ae
5 changed files with 45 additions and 5 deletions
|
@ -306,6 +306,7 @@ EmitContext::EmitContext(IR::Program& program, Bindings& bindings, const Profile
|
|||
SetupImages(bindings);
|
||||
SetupTextures(bindings);
|
||||
DefineHelperFunctions();
|
||||
DefineConstants();
|
||||
}
|
||||
|
||||
void EmitContext::SetupExtensions(std::string&) {
|
||||
|
@ -339,6 +340,9 @@ void EmitContext::SetupExtensions(std::string&) {
|
|||
if (!info.uses_int64) {
|
||||
header += "#extension GL_ARB_gpu_shader_int64 : enable\n";
|
||||
}
|
||||
if (profile.support_gl_warp_intrinsics) {
|
||||
header += "#extension GL_NV_shader_thread_shuffle : enable\n";
|
||||
}
|
||||
}
|
||||
if (info.stores_viewport_index && profile.support_viewport_index_layer_non_geometry &&
|
||||
stage != Stage::Geometry) {
|
||||
|
@ -605,4 +609,11 @@ void EmitContext::SetupTextures(Bindings& bindings) {
|
|||
}
|
||||
}
|
||||
|
||||
void EmitContext::DefineConstants() {
|
||||
if (info.uses_fswzadd) {
|
||||
header += "const float FSWZ_A[]=float[4](-1.f,1.f,-1.f,0.f);"
|
||||
"const float FSWZ_B[]=float[4](-1.f,-1.f,1.f,-1.f);";
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Shader::Backend::GLSL
|
||||
|
|
|
@ -167,6 +167,7 @@ private:
|
|||
void DefineStorageBuffers(Bindings& bindings);
|
||||
void DefineGenericOutput(size_t index, u32 invocations);
|
||||
void DefineHelperFunctions();
|
||||
void DefineConstants();
|
||||
std::string DefineGlobalMemoryFunctions();
|
||||
void SetupImages(Bindings& bindings);
|
||||
void SetupTextures(Bindings& bindings);
|
||||
|
|
|
@ -35,9 +35,17 @@ std::string GetMaxThreadId(std::string_view thread_id, std::string_view clamp,
|
|||
const auto min_thread_id{ComputeMinThreadId(thread_id, segmentation_mask)};
|
||||
return ComputeMaxThreadId(min_thread_id, clamp, not_seg_mask);
|
||||
}
|
||||
|
||||
void UseShuffleNv(EmitContext& ctx, IR::Inst& inst, std::string_view shfl_op,
|
||||
std::string_view value, std::string_view index,
|
||||
[[maybe_unused]] std::string_view clamp, std::string_view segmentation_mask) {
|
||||
const auto width{fmt::format("32u>>(bitCount({}&31u))", segmentation_mask)};
|
||||
ctx.AddU32("{}={}({},{},{},shfl_in_bounds);", inst, shfl_op, value, index, width);
|
||||
SetInBoundsFlag(ctx, inst);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void EmitLaneId([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) {
|
||||
void EmitLaneId(EmitContext& ctx, IR::Inst& inst) {
|
||||
ctx.AddU32("{}=gl_SubGroupInvocationARB&31u;", inst);
|
||||
}
|
||||
|
||||
|
@ -103,6 +111,10 @@ void EmitSubgroupGeMask(EmitContext& ctx, IR::Inst& inst) {
|
|||
void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleNV", value, index, clamp, segmentation_mask);
|
||||
return;
|
||||
}
|
||||
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)};
|
||||
|
@ -117,6 +129,10 @@ void EmitShuffleIndex(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
|||
|
||||
void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std::string_view index,
|
||||
std::string_view clamp, std::string_view segmentation_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleUpNV", value, index, clamp, segmentation_mask);
|
||||
return;
|
||||
}
|
||||
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)};
|
||||
|
@ -128,6 +144,10 @@ void EmitShuffleUp(EmitContext& ctx, IR::Inst& inst, std::string_view value, std
|
|||
void EmitShuffleDown(EmitContext& ctx, IR::Inst& inst, std::string_view value,
|
||||
std::string_view index, std::string_view clamp,
|
||||
std::string_view segmentation_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleDownNV", value, index, clamp, segmentation_mask);
|
||||
return;
|
||||
}
|
||||
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)};
|
||||
|
@ -139,6 +159,10 @@ void EmitShuffleDown(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 segmentation_mask) {
|
||||
if (ctx.profile.support_gl_warp_intrinsics) {
|
||||
UseShuffleNv(ctx, inst, "shuffleXorNV", value, index, clamp, segmentation_mask);
|
||||
return;
|
||||
}
|
||||
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)};
|
||||
|
@ -147,10 +171,12 @@ void EmitShuffleButterfly(EmitContext& ctx, IR::Inst& inst, std::string_view val
|
|||
ctx.AddU32("{}=shfl_in_bounds?readInvocationARB({},{}):{};", inst, value, src_thread_id, value);
|
||||
}
|
||||
|
||||
void EmitFSwizzleAdd([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst,
|
||||
[[maybe_unused]] std::string_view op_a, [[maybe_unused]] std::string_view op_b,
|
||||
[[maybe_unused]] std::string_view swizzle) {
|
||||
NotImplemented();
|
||||
void EmitFSwizzleAdd(EmitContext& ctx, IR::Inst& inst, std::string_view op_a, std::string_view op_b,
|
||||
std::string_view swizzle) {
|
||||
const auto mask{fmt::format("({}>>((gl_SubGroupInvocationARB&3)<<1))&3", swizzle)};
|
||||
const std::string modifier_a = fmt::format("FSWZ_A[{}]", mask);
|
||||
const std::string modifier_b = fmt::format("FSWZ_B[{}]", mask);
|
||||
ctx.AddF32("{}=({}*{})+({}*{});", inst, op_a, modifier_a, op_b, modifier_b);
|
||||
}
|
||||
|
||||
void EmitDPdxFine(EmitContext& ctx, IR::Inst& inst, std::string_view op_a) {
|
||||
|
|
|
@ -86,6 +86,7 @@ struct Profile {
|
|||
bool support_gl_nv_gpu_shader_5{};
|
||||
bool support_gl_amd_gpu_shader_half_float{};
|
||||
bool support_gl_texture_shadow_lod{};
|
||||
bool support_gl_warp_intrinsics{};
|
||||
|
||||
bool warp_size_potentially_larger_than_guest{};
|
||||
|
||||
|
|
|
@ -226,6 +226,7 @@ ShaderCache::ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindo
|
|||
.support_gl_nv_gpu_shader_5 = device.HasNvGpuShader5(),
|
||||
.support_gl_amd_gpu_shader_half_float = device.HasAmdShaderHalfFloat(),
|
||||
.support_gl_texture_shadow_lod = device.HasTextureShadowLod(),
|
||||
.support_gl_warp_intrinsics = false,
|
||||
|
||||
.warp_size_potentially_larger_than_guest = device.IsWarpSizePotentiallyLargerThanGuest(),
|
||||
|
||||
|
|
Loading…
Reference in a new issue