summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glsl
diff options
context:
space:
mode:
authorGravatar ameerj2021-05-28 15:51:50 -0400
committerGravatar ameerj2021-07-22 21:51:36 -0400
commit21797efa548598692a82a25959865236bd9e7116 (patch)
tree2d5b629fbbe67ff11f908b9d019a7e653451a2a0 /src/shader_recompiler/backend/glsl
parentglsl: SSBO access fixes and wip SampleExplicitLod implementation. (diff)
downloadyuzu-21797efa548598692a82a25959865236bd9e7116.tar.gz
yuzu-21797efa548598692a82a25959865236bd9e7116.tar.xz
yuzu-21797efa548598692a82a25959865236bd9e7116.zip
glsl: Implement IADD CC
Diffstat (limited to 'src/shader_recompiler/backend/glsl')
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl.cpp2
-rw-r--r--src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp17
2 files changed, 17 insertions, 2 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp
index feb3ede1a..992e4b82e 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp
@@ -183,6 +183,8 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR
183 for (size_t index = 0; index < ctx.reg_alloc.num_used_registers; ++index) { 183 for (size_t index = 0; index < ctx.reg_alloc.num_used_registers; ++index) {
184 ctx.header += fmt::format("{} R{};", ctx.reg_alloc.reg_types[index], index); 184 ctx.header += fmt::format("{} R{};", ctx.reg_alloc.reg_types[index], index);
185 } 185 }
186 // TODO: track CC usage
187 ctx.header += "uint carry;";
186 ctx.code.insert(0, ctx.header); 188 ctx.code.insert(0, ctx.header);
187 ctx.code += "}"; 189 ctx.code += "}";
188 fmt::print("\n{}\n", ctx.code); 190 fmt::print("\n{}\n", ctx.code);
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
index 6654fce81..6ff0f9248 100644
--- a/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
+++ b/src/shader_recompiler/backend/glsl/emit_glsl_integer.cpp
@@ -29,9 +29,22 @@ void SetSignFlag(EmitContext& ctx, IR::Inst& inst, std::string_view result) {
29} // Anonymous namespace 29} // Anonymous namespace
30void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { 30void EmitIAdd32(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
31 const auto result{ctx.reg_alloc.Define(inst, Type::U32)}; 31 const auto result{ctx.reg_alloc.Define(inst, Type::U32)};
32 ctx.Add("{}={}+{};", result, a, b); 32 if (IR::Inst* const carry{inst.GetAssociatedPseudoOperation(IR::Opcode::GetCarryFromOp)}) {
33 ctx.Add("{}=uaddCarry({},{},carry);", result, a, b);
34 ctx.AddU1("{}=carry!=0;", *carry, result);
35 carry->Invalidate();
36 } else {
37 ctx.Add("{}={}+{};", result, a, b);
38 }
33 SetZeroFlag(ctx, inst, result); 39 SetZeroFlag(ctx, inst, result);
34 SetSignFlag(ctx, inst, result); 40 SetSignFlag(ctx, inst, result);
41 if (IR::Inst * overflow{inst.GetAssociatedPseudoOperation(IR::Opcode::GetOverflowFromOp)}) {
42 // https://stackoverflow.com/questions/55468823/how-to-detect-integer-overflow-in-c
43 constexpr u32 s32_max{static_cast<u32>(std::numeric_limits<s32>::max())};
44 ctx.AddU1("{}=int({})>=0?int({})>int({}-{}):int({})<int({}-{});", *overflow, a, b, s32_max,
45 a, b, s32_max, a);
46 overflow->Invalidate();
47 }
35} 48}
36 49
37void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) { 50void EmitIAdd64(EmitContext& ctx, IR::Inst& inst, std::string_view a, std::string_view b) {
@@ -179,7 +192,7 @@ void EmitSLessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::
179} 192}
180 193
181void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { 194void EmitULessThan(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {
182 ctx.AddU1("{}=uint({})<uint({)};", inst, lhs, rhs); 195 ctx.AddU1("{}=uint({})<uint({});", inst, lhs, rhs);
183} 196}
184 197
185void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) { 198void EmitIEqual(EmitContext& ctx, IR::Inst& inst, std::string_view lhs, std::string_view rhs) {