diff options
| author | 2021-05-25 20:55:06 -0400 | |
|---|---|---|
| committer | 2021-07-22 21:51:36 -0400 | |
| commit | b95716e5431e7ddb05239c31080c01aab24a13ac (patch) | |
| tree | 0de79d8166ee7ebbdb10bcc3a830bf0580d0de3d /src/shader_recompiler/backend/glsl/emit_glsl.cpp | |
| parent | glsl: Fix floating point compare ops (diff) | |
| download | yuzu-b95716e5431e7ddb05239c31080c01aab24a13ac.tar.gz yuzu-b95716e5431e7ddb05239c31080c01aab24a13ac.tar.xz yuzu-b95716e5431e7ddb05239c31080c01aab24a13ac.zip | |
glsl: Update phi node management
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl.cpp | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp index e5aaf81a7..a8e53cf66 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp | |||
| @@ -98,18 +98,33 @@ void EmitInst(EmitContext& ctx, IR::Inst* inst) { | |||
| 98 | throw LogicError("Invalid opcode {}", inst->GetOpcode()); | 98 | throw LogicError("Invalid opcode {}", inst->GetOpcode()); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | void Precolor(EmitContext& ctx, const IR::Program& program) { | 101 | bool IsReference(IR::Inst& inst) { |
| 102 | return inst.GetOpcode() == IR::Opcode::Reference; | ||
| 103 | } | ||
| 104 | |||
| 105 | void PrecolorInst(IR::Inst& phi) { | ||
| 106 | // Insert phi moves before references to avoid overwritting other phis | ||
| 107 | const size_t num_args{phi.NumArgs()}; | ||
| 108 | for (size_t i = 0; i < num_args; ++i) { | ||
| 109 | IR::Block& phi_block{*phi.PhiBlock(i)}; | ||
| 110 | auto it{std::find_if_not(phi_block.rbegin(), phi_block.rend(), IsReference).base()}; | ||
| 111 | IR::IREmitter ir{phi_block, it}; | ||
| 112 | const IR::Value arg{phi.Arg(i)}; | ||
| 113 | if (arg.IsImmediate()) { | ||
| 114 | ir.PhiMove(phi, arg); | ||
| 115 | } else { | ||
| 116 | ir.PhiMove(phi, IR::Value{&RegAlloc::AliasInst(*arg.Inst())}); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | for (size_t i = 0; i < num_args; ++i) { | ||
| 120 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | void Precolor(const IR::Program& program) { | ||
| 102 | for (IR::Block* const block : program.blocks) { | 125 | for (IR::Block* const block : program.blocks) { |
| 103 | for (IR::Inst& phi : block->Instructions() | std::views::take_while(IR::IsPhi)) { | 126 | for (IR::Inst& phi : block->Instructions() | std::views::take_while(IR::IsPhi)) { |
| 104 | ctx.Add("{};", ctx.reg_alloc.Define(phi, phi.Arg(0).Type())); | 127 | PrecolorInst(phi); |
| 105 | const size_t num_args{phi.NumArgs()}; | ||
| 106 | for (size_t i = 0; i < num_args; ++i) { | ||
| 107 | IR::IREmitter{*phi.PhiBlock(i)}.PhiMove(phi, phi.Arg(i)); | ||
| 108 | } | ||
| 109 | // Add reference to the phi node on the phi predecessor to avoid overwritting it | ||
| 110 | for (size_t i = 0; i < num_args; ++i) { | ||
| 111 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); | ||
| 112 | } | ||
| 113 | } | 128 | } |
| 114 | } | 129 | } |
| 115 | } | 130 | } |
| @@ -158,7 +173,7 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 158 | std::string EmitGLSL(const Profile& profile, const RuntimeInfo&, IR::Program& program, | 173 | std::string EmitGLSL(const Profile& profile, const RuntimeInfo&, IR::Program& program, |
| 159 | Bindings& bindings) { | 174 | Bindings& bindings) { |
| 160 | EmitContext ctx{program, bindings, profile}; | 175 | EmitContext ctx{program, bindings, profile}; |
| 161 | Precolor(ctx, program); | 176 | Precolor(program); |
| 162 | EmitCode(ctx, program); | 177 | EmitCode(ctx, program); |
| 163 | return ctx.code; | 178 | return ctx.code; |
| 164 | } | 179 | } |