summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/backend/glasm/emit_glasm.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-05-10 19:20:44 -0300
committerGravatar ameerj2021-07-22 21:51:31 -0400
commitc917290497b313abe2f9ad6983050703615b1888 (patch)
tree1631f4cebc8cc845fb01fe23f84705675396863b /src/shader_recompiler/backend/glasm/emit_glasm.cpp
parentglasm: Review all GLASM insts to be aware of register aliasing (diff)
downloadyuzu-c917290497b313abe2f9ad6983050703615b1888.tar.gz
yuzu-c917290497b313abe2f9ad6983050703615b1888.tar.xz
yuzu-c917290497b313abe2f9ad6983050703615b1888.zip
glasm: Enable unintentionally disabled register aliasing on GLASM
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm.cpp')
-rw-r--r--src/shader_recompiler/backend/glasm/emit_glasm.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
index 8b42cbf79..c90b80e48 100644
--- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp
+++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp
@@ -29,9 +29,9 @@ struct FuncTraits<ReturnType_ (*)(Args...)> {
29 29
30template <typename T> 30template <typename T>
31struct Identity { 31struct Identity {
32 Identity(const T& data_) : data{data_} {} 32 Identity(T data_) : data{data_} {}
33 33
34 const T& Extract() { 34 T Extract() {
35 return data; 35 return data;
36 } 36 }
37 37
@@ -71,15 +71,12 @@ public:
71 } 71 }
72 } 72 }
73 73
74 ~RegWrapper() { 74 auto Extract() {
75 if (inst) { 75 if (inst) {
76 reg_alloc.Unref(*inst); 76 reg_alloc.Unref(*inst);
77 } else { 77 } else {
78 reg_alloc.FreeReg(reg); 78 reg_alloc.FreeReg(reg);
79 } 79 }
80 }
81
82 auto Extract() {
83 return std::conditional_t<scalar, ScalarRegister, Register>{Value{reg}}; 80 return std::conditional_t<scalar, ScalarRegister, Register>{Value{reg}};
84 } 81 }
85 82
@@ -95,13 +92,10 @@ public:
95 ValueWrapper(EmitContext& ctx, const IR::Value& ir_value_) 92 ValueWrapper(EmitContext& ctx, const IR::Value& ir_value_)
96 : reg_alloc{ctx.reg_alloc}, ir_value{ir_value_}, value{reg_alloc.Peek(ir_value)} {} 93 : reg_alloc{ctx.reg_alloc}, ir_value{ir_value_}, value{reg_alloc.Peek(ir_value)} {}
97 94
98 ~ValueWrapper() { 95 ArgType Extract() {
99 if (!ir_value.IsImmediate()) { 96 if (!ir_value.IsImmediate()) {
100 reg_alloc.Unref(*ir_value.InstRecursive()); 97 reg_alloc.Unref(*ir_value.InstRecursive());
101 } 98 }
102 }
103
104 ArgType Extract() {
105 return value; 99 return value;
106 } 100 }
107 101
@@ -120,7 +114,7 @@ auto Arg(EmitContext& ctx, const IR::Value& arg) {
120 } else if constexpr (std::is_base_of_v<Value, ArgType>) { 114 } else if constexpr (std::is_base_of_v<Value, ArgType>) {
121 return ValueWrapper<ArgType>{ctx, arg}; 115 return ValueWrapper<ArgType>{ctx, arg};
122 } else if constexpr (std::is_same_v<ArgType, const IR::Value&>) { 116 } else if constexpr (std::is_same_v<ArgType, const IR::Value&>) {
123 return Identity{arg}; 117 return Identity<const IR::Value&>{arg};
124 } else if constexpr (std::is_same_v<ArgType, u32>) { 118 } else if constexpr (std::is_same_v<ArgType, u32>) {
125 return Identity{arg.U32()}; 119 return Identity{arg.U32()};
126 } else if constexpr (std::is_same_v<ArgType, IR::Block*>) { 120 } else if constexpr (std::is_same_v<ArgType, IR::Block*>) {
@@ -137,9 +131,9 @@ auto Arg(EmitContext& ctx, const IR::Value& arg) {
137template <auto func, bool is_first_arg_inst, typename... Args> 131template <auto func, bool is_first_arg_inst, typename... Args>
138void InvokeCall(EmitContext& ctx, IR::Inst* inst, Args&&... args) { 132void InvokeCall(EmitContext& ctx, IR::Inst* inst, Args&&... args) {
139 if constexpr (is_first_arg_inst) { 133 if constexpr (is_first_arg_inst) {
140 func(ctx, *inst, std::forward<Args>(args.Extract())...); 134 func(ctx, *inst, args.Extract()...);
141 } else { 135 } else {
142 func(ctx, std::forward<Args>(args.Extract())...); 136 func(ctx, args.Extract()...);
143 } 137 }
144} 138}
145 139
@@ -147,10 +141,11 @@ template <auto func, bool is_first_arg_inst, size_t... I>
147void Invoke(EmitContext& ctx, IR::Inst* inst, std::index_sequence<I...>) { 141void Invoke(EmitContext& ctx, IR::Inst* inst, std::index_sequence<I...>) {
148 using Traits = FuncTraits<decltype(func)>; 142 using Traits = FuncTraits<decltype(func)>;
149 if constexpr (is_first_arg_inst) { 143 if constexpr (is_first_arg_inst) {
150 func(ctx, *inst, 144 InvokeCall<func, is_first_arg_inst>(
151 Arg<typename Traits::template ArgType<I + 2>>(ctx, inst->Arg(I)).Extract()...); 145 ctx, inst, Arg<typename Traits::template ArgType<I + 2>>(ctx, inst->Arg(I))...);
152 } else { 146 } else {
153 func(ctx, Arg<typename Traits::template ArgType<I + 1>>(ctx, inst->Arg(I)).Extract()...); 147 InvokeCall<func, is_first_arg_inst>(
148 ctx, inst, Arg<typename Traits::template ArgType<I + 1>>(ctx, inst->Arg(I))...);
154 } 149 }
155} 150}
156 151