diff options
Diffstat (limited to 'src/shader_recompiler/backend/glsl/emit_glsl.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glsl/emit_glsl.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl.cpp b/src/shader_recompiler/backend/glsl/emit_glsl.cpp index 56738bcc5..feb3ede1a 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl.cpp | |||
| @@ -83,6 +83,7 @@ void Invoke(EmitContext& ctx, IR::Inst* inst) { | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | void EmitInst(EmitContext& ctx, IR::Inst* inst) { | 85 | void EmitInst(EmitContext& ctx, IR::Inst* inst) { |
| 86 | // ctx.Add("/* {} */", inst->GetOpcode()); | ||
| 86 | switch (inst->GetOpcode()) { | 87 | switch (inst->GetOpcode()) { |
| 87 | #define OPCODE(name, result_type, ...) \ | 88 | #define OPCODE(name, result_type, ...) \ |
| 88 | case IR::Opcode::name: \ | 89 | case IR::Opcode::name: \ |
| @@ -108,12 +109,9 @@ void PrecolorInst(IR::Inst& phi) { | |||
| 108 | if (arg.IsImmediate()) { | 109 | if (arg.IsImmediate()) { |
| 109 | ir.PhiMove(phi, arg); | 110 | ir.PhiMove(phi, arg); |
| 110 | } else { | 111 | } else { |
| 111 | ir.PhiMove(phi, IR::Value{&*arg.InstRecursive()}); | 112 | ir.PhiMove(phi, IR::Value{arg.InstRecursive()}); |
| 112 | } | 113 | } |
| 113 | } | 114 | } |
| 114 | for (size_t i = 0; i < num_args; ++i) { | ||
| 115 | IR::IREmitter{*phi.PhiBlock(i)}.Reference(IR::Value{&phi}); | ||
| 116 | } | ||
| 117 | } | 115 | } |
| 118 | 116 | ||
| 119 | void Precolor(const IR::Program& program) { | 117 | void Precolor(const IR::Program& program) { |
| @@ -144,10 +142,7 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 144 | ctx.Add("break;"); | 142 | ctx.Add("break;"); |
| 145 | } | 143 | } |
| 146 | } else { | 144 | } else { |
| 147 | // TODO: implement this | 145 | ctx.Add("if({}){{break;}}", ctx.reg_alloc.Consume(node.data.break_node.cond)); |
| 148 | ctx.Add("MOV.S.CC RC,{};" | ||
| 149 | "BRK (NE.x);", | ||
| 150 | 0); | ||
| 151 | } | 146 | } |
| 152 | break; | 147 | break; |
| 153 | case IR::AbstractSyntaxNode::Type::Return: | 148 | case IR::AbstractSyntaxNode::Type::Return: |
| @@ -155,10 +150,12 @@ void EmitCode(EmitContext& ctx, const IR::Program& program) { | |||
| 155 | ctx.Add("return;"); | 150 | ctx.Add("return;"); |
| 156 | break; | 151 | break; |
| 157 | case IR::AbstractSyntaxNode::Type::Loop: | 152 | case IR::AbstractSyntaxNode::Type::Loop: |
| 158 | ctx.Add("do{{"); | 153 | ctx.Add("for(;;){{"); |
| 159 | break; | 154 | break; |
| 160 | case IR::AbstractSyntaxNode::Type::Repeat: | 155 | case IR::AbstractSyntaxNode::Type::Repeat: |
| 161 | ctx.Add("}}while({});", ctx.reg_alloc.Consume(node.data.repeat.cond)); | 156 | ctx.Add("if({}){{", ctx.reg_alloc.Consume(node.data.repeat.cond)); |
| 157 | ctx.Add("continue;\n}}else{{"); | ||
| 158 | ctx.Add("break;\n}}\n}}"); | ||
| 162 | break; | 159 | break; |
| 163 | default: | 160 | default: |
| 164 | fmt::print("{}", node.type); | 161 | fmt::print("{}", node.type); |
| @@ -182,7 +179,11 @@ std::string EmitGLSL(const Profile& profile, const RuntimeInfo& runtime_info, IR | |||
| 182 | Precolor(program); | 179 | Precolor(program); |
| 183 | EmitCode(ctx, program); | 180 | EmitCode(ctx, program); |
| 184 | const std::string version{fmt::format("#version 450{}\n", GlslVersionSpecifier(ctx))}; | 181 | const std::string version{fmt::format("#version 450{}\n", GlslVersionSpecifier(ctx))}; |
| 185 | ctx.code.insert(0, version); | 182 | ctx.header.insert(0, version); |
| 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); | ||
| 185 | } | ||
| 186 | ctx.code.insert(0, ctx.header); | ||
| 186 | ctx.code += "}"; | 187 | ctx.code += "}"; |
| 187 | fmt::print("\n{}\n", ctx.code); | 188 | fmt::print("\n{}\n", ctx.code); |
| 188 | return ctx.code; | 189 | return ctx.code; |