forked from ShuriZma/suyu
1
0
Fork 0

glsl: Add boolean reference workaround

This commit is contained in:
ameerj 2021-12-29 18:55:42 -05:00
parent b84d429c2e
commit 8c907c620d
6 changed files with 15 additions and 2 deletions

View File

@ -7,6 +7,7 @@
#include "shader_recompiler/backend/glsl/emit_glsl_instructions.h" #include "shader_recompiler/backend/glsl/emit_glsl_instructions.h"
#include "shader_recompiler/backend/glsl/glsl_emit_context.h" #include "shader_recompiler/backend/glsl/glsl_emit_context.h"
#include "shader_recompiler/frontend/ir/value.h" #include "shader_recompiler/frontend/ir/value.h"
#include "shader_recompiler/profile.h"
namespace Shader::Backend::GLSL { namespace Shader::Backend::GLSL {
namespace { namespace {
@ -30,8 +31,9 @@ void EmitConditionRef(EmitContext& ctx, IR::Inst& inst, const IR::Value& value)
inst.DestructiveAddUsage(1); inst.DestructiveAddUsage(1);
const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U1)}; const auto ret{ctx.var_alloc.Define(inst, GlslVarType::U1)};
const auto input{ctx.var_alloc.Consume(value)}; const auto input{ctx.var_alloc.Consume(value)};
const auto suffix{ctx.profile.has_gl_bool_ref_bug ? "?true:false" : ""};
if (ret != input) { if (ret != input) {
ctx.Add("{}={};", ret, input); ctx.Add("{}={}{};", ret, input, suffix);
} }
} }

View File

@ -90,7 +90,9 @@ void EmitPhiMove(EmitContext& ctx, const IR::Value& phi_value, const IR::Value&
if (phi_reg == val_reg) { if (phi_reg == val_reg) {
return; return;
} }
ctx.Add("{}={};", phi_reg, val_reg); const bool needs_workaround{ctx.profile.has_gl_bool_ref_bug && phi_type == IR::Type::U1};
const auto suffix{needs_workaround ? "?true:false" : ""};
ctx.Add("{}={}{};", phi_reg, val_reg, suffix);
} }
void EmitPrologue(EmitContext& ctx) { void EmitPrologue(EmitContext& ctx) {

View File

@ -67,6 +67,8 @@ struct Profile {
bool has_gl_precise_bug{}; bool has_gl_precise_bug{};
/// Some drivers do not properly support floatBitsToUint when used on cbufs /// Some drivers do not properly support floatBitsToUint when used on cbufs
bool has_gl_cbuf_ftou_bug{}; bool has_gl_cbuf_ftou_bug{};
/// Some drivers poorly optimize boolean variable references
bool has_gl_bool_ref_bug{};
/// Ignores SPIR-V ordered vs unordered using GLSL semantics /// Ignores SPIR-V ordered vs unordered using GLSL semantics
bool ignore_nan_fp_comparisons{}; bool ignore_nan_fp_comparisons{};

View File

@ -188,6 +188,7 @@ Device::Device() {
std::atoi(driver_version.substr(0, driver_version.find(".")).data()); std::atoi(driver_version.substr(0, driver_version.find(".")).data());
if (version_major >= 495) { if (version_major >= 495) {
has_cbuf_ftou_bug = true; has_cbuf_ftou_bug = true;
has_bool_ref_bug = true;
} }
} }

View File

@ -156,6 +156,10 @@ public:
return has_cbuf_ftou_bug; return has_cbuf_ftou_bug;
} }
bool HasBoolRefBug() const {
return has_bool_ref_bug;
}
Settings::ShaderBackend GetShaderBackend() const { Settings::ShaderBackend GetShaderBackend() const {
return shader_backend; return shader_backend;
} }
@ -205,6 +209,7 @@ private:
bool warp_size_potentially_larger_than_guest{}; bool warp_size_potentially_larger_than_guest{};
bool need_fastmath_off{}; bool need_fastmath_off{};
bool has_cbuf_ftou_bug{}; bool has_cbuf_ftou_bug{};
bool has_bool_ref_bug{};
std::string vendor_name; std::string vendor_name;
}; };

View File

@ -215,6 +215,7 @@ ShaderCache::ShaderCache(RasterizerOpenGL& rasterizer_, Core::Frontend::EmuWindo
.has_gl_component_indexing_bug = device.HasComponentIndexingBug(), .has_gl_component_indexing_bug = device.HasComponentIndexingBug(),
.has_gl_precise_bug = device.HasPreciseBug(), .has_gl_precise_bug = device.HasPreciseBug(),
.has_gl_cbuf_ftou_bug = device.HasCbufFtouBug(), .has_gl_cbuf_ftou_bug = device.HasCbufFtouBug(),
.has_gl_bool_ref_bug = device.HasBoolRefBug(),
.ignore_nan_fp_comparisons = true, .ignore_nan_fp_comparisons = true,
.gl_max_compute_smem_size = device.GetMaxComputeSharedMemorySize(), .gl_max_compute_smem_size = device.GetMaxComputeSharedMemorySize(),
}, },