diff options
| author | 2021-05-14 00:40:54 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:31 -0400 | |
| commit | d54d7de40e7295827b0e4e4026441b53d3fc9569 (patch) | |
| tree | 29b5074f851292dace7aeb5da7716675544b3735 /src/shader_recompiler/backend/glasm/emit_glasm.cpp | |
| parent | glasm: Implement Storage atomics (diff) | |
| download | yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.tar.gz yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.tar.xz yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.zip | |
glasm: Rework control flow introducing a syntax list
This commit regresses VertexA shaders, their transformation pass has to
be adapted to the new control flow.
Diffstat (limited to 'src/shader_recompiler/backend/glasm/emit_glasm.cpp')
| -rw-r--r-- | src/shader_recompiler/backend/glasm/emit_glasm.cpp | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp index 056d8cbf8..51ca83d18 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp | |||
| @@ -117,8 +117,6 @@ auto Arg(EmitContext& ctx, const IR::Value& arg) { | |||
| 117 | return Identity<const IR::Value&>{arg}; | 117 | return Identity<const IR::Value&>{arg}; |
| 118 | } else if constexpr (std::is_same_v<ArgType, u32>) { | 118 | } else if constexpr (std::is_same_v<ArgType, u32>) { |
| 119 | return Identity{arg.U32()}; | 119 | return Identity{arg.U32()}; |
| 120 | } else if constexpr (std::is_same_v<ArgType, IR::Block*>) { | ||
| 121 | return Identity{arg.Label()}; | ||
| 122 | } else if constexpr (std::is_same_v<ArgType, IR::Attribute>) { | 120 | } else if constexpr (std::is_same_v<ArgType, IR::Attribute>) { |
| 123 | return Identity{arg.Attribute()}; | 121 | return Identity{arg.Attribute()}; |
| 124 | } else if constexpr (std::is_same_v<ArgType, IR::Patch>) { | 122 | } else if constexpr (std::is_same_v<ArgType, IR::Patch>) { |
| @@ -177,6 +175,39 @@ void EmitInst(EmitContext& ctx, IR::Inst* inst) { | |||
| 177 | throw LogicError("Invalid opcode {}", inst->GetOpcode()); | 175 | throw LogicError("Invalid opcode {}", inst->GetOpcode()); |
| 178 | } | 176 | } |
| 179 | 177 | ||
| 178 | void EmitCode(EmitContext& ctx, const IR::Program& program) { | ||
| 179 | const auto eval{ | ||
| 180 | [&](const IR::U1& cond) { return ScalarS32{ctx.reg_alloc.Consume(IR::Value{cond})}; }}; | ||
| 181 | for (const IR::AbstractSyntaxNode& node : program.syntax_list) { | ||
| 182 | switch (node.type) { | ||
| 183 | case IR::AbstractSyntaxNode::Type::Block: | ||
| 184 | for (IR::Inst& inst : node.block->Instructions()) { | ||
| 185 | EmitInst(ctx, &inst); | ||
| 186 | } | ||
| 187 | break; | ||
| 188 | case IR::AbstractSyntaxNode::Type::If: | ||
| 189 | ctx.Add("MOV.S.CC RC,{};IF NE.x;", eval(node.if_node.cond)); | ||
| 190 | break; | ||
| 191 | case IR::AbstractSyntaxNode::Type::EndIf: | ||
| 192 | ctx.Add("ENDIF;"); | ||
| 193 | break; | ||
| 194 | case IR::AbstractSyntaxNode::Type::Loop: | ||
| 195 | ctx.Add("REP;"); | ||
| 196 | break; | ||
| 197 | case IR::AbstractSyntaxNode::Type::Repeat: | ||
| 198 | ctx.Add("MOV.S.CC RC,{};BRK NE.x;ENDREP;", eval(node.repeat.cond)); | ||
| 199 | break; | ||
| 200 | case IR::AbstractSyntaxNode::Type::Break: | ||
| 201 | ctx.Add("MOV.S.CC RC,{};BRK NE.x;", eval(node.repeat.cond)); | ||
| 202 | break; | ||
| 203 | case IR::AbstractSyntaxNode::Type::Return: | ||
| 204 | case IR::AbstractSyntaxNode::Type::Unreachable: | ||
| 205 | ctx.Add("RET;"); | ||
| 206 | break; | ||
| 207 | } | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 180 | void SetupOptions(std::string& header, Info info) { | 211 | void SetupOptions(std::string& header, Info info) { |
| 181 | if (info.uses_int64_bit_atomics) { | 212 | if (info.uses_int64_bit_atomics) { |
| 182 | header += "OPTION NV_shader_atomic_int64;"; | 213 | header += "OPTION NV_shader_atomic_int64;"; |
| @@ -201,11 +232,7 @@ void SetupOptions(std::string& header, Info info) { | |||
| 201 | 232 | ||
| 202 | std::string EmitGLASM(const Profile&, IR::Program& program, Bindings&) { | 233 | std::string EmitGLASM(const Profile&, IR::Program& program, Bindings&) { |
| 203 | EmitContext ctx{program}; | 234 | EmitContext ctx{program}; |
| 204 | for (IR::Block* const block : program.blocks) { | 235 | EmitCode(ctx, program); |
| 205 | for (IR::Inst& inst : block->Instructions()) { | ||
| 206 | EmitInst(ctx, &inst); | ||
| 207 | } | ||
| 208 | } | ||
| 209 | std::string header = "!!NVcp5.0\n" | 236 | std::string header = "!!NVcp5.0\n" |
| 210 | "OPTION NV_internal;"; | 237 | "OPTION NV_internal;"; |
| 211 | SetupOptions(header, program.info); | 238 | SetupOptions(header, program.info); |