diff options
| author | 2019-09-22 12:33:13 -0400 | |
|---|---|---|
| committer | 2019-10-04 18:52:53 -0400 | |
| commit | 189a50bc2addbf43824be396f205e900af7523b3 (patch) | |
| tree | a90f376dece470233b110c16d12fb58ce03f6385 /src | |
| parent | Shader_IR: corrections and clang-format (diff) | |
| download | yuzu-189a50bc2addbf43824be396f205e900af7523b3.tar.gz yuzu-189a50bc2addbf43824be396f205e900af7523b3.tar.xz yuzu-189a50bc2addbf43824be396f205e900af7523b3.zip | |
gl_shader_decompiler: Refactor and address feedback.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index b8c3442bc..572fae353 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -355,7 +355,7 @@ public: | |||
| 355 | if (!ir.IsFlowStackDisabled()) { | 355 | if (!ir.IsFlowStackDisabled()) { |
| 356 | for (const auto stack : std::array{MetaStackClass::Ssy, MetaStackClass::Pbk}) { | 356 | for (const auto stack : std::array{MetaStackClass::Ssy, MetaStackClass::Pbk}) { |
| 357 | code.AddLine("uint {}[{}];", FlowStackName(stack), FLOW_STACK_SIZE); | 357 | code.AddLine("uint {}[{}];", FlowStackName(stack), FLOW_STACK_SIZE); |
| 358 | code.AddLine("uint {} = 0u;", FlowStackTopName(stack)); | 358 | code.AddLine("uint {} = 0U;", FlowStackTopName(stack)); |
| 359 | } | 359 | } |
| 360 | } | 360 | } |
| 361 | 361 | ||
| @@ -1837,10 +1837,9 @@ private: | |||
| 1837 | return {}; | 1837 | return {}; |
| 1838 | } | 1838 | } |
| 1839 | 1839 | ||
| 1840 | Expression WriteExit() { | 1840 | void PreExit() { |
| 1841 | if (stage != ProgramType::Fragment) { | 1841 | if (stage != ProgramType::Fragment) { |
| 1842 | code.AddLine("return;"); | 1842 | return; |
| 1843 | return {}; | ||
| 1844 | } | 1843 | } |
| 1845 | const auto& used_registers = ir.GetRegisters(); | 1844 | const auto& used_registers = ir.GetRegisters(); |
| 1846 | const auto SafeGetRegister = [&](u32 reg) -> Expression { | 1845 | const auto SafeGetRegister = [&](u32 reg) -> Expression { |
| @@ -1872,13 +1871,12 @@ private: | |||
| 1872 | // already contains one past the last color register. | 1871 | // already contains one past the last color register. |
| 1873 | code.AddLine("gl_FragDepth = {};", SafeGetRegister(current_reg + 1).AsFloat()); | 1872 | code.AddLine("gl_FragDepth = {};", SafeGetRegister(current_reg + 1).AsFloat()); |
| 1874 | } | 1873 | } |
| 1875 | |||
| 1876 | code.AddLine("return;"); | ||
| 1877 | return {}; | ||
| 1878 | } | 1874 | } |
| 1879 | 1875 | ||
| 1880 | Expression Exit(Operation operation) { | 1876 | Expression Exit(Operation operation) { |
| 1881 | return WriteExit(); | 1877 | PreExit(); |
| 1878 | code.AddLine("return;"); | ||
| 1879 | return {}; | ||
| 1882 | } | 1880 | } |
| 1883 | 1881 | ||
| 1884 | Expression Discard(Operation operation) { | 1882 | Expression Discard(Operation operation) { |
| @@ -2277,7 +2275,7 @@ const std::string flow_var = "flow_var_"; | |||
| 2277 | 2275 | ||
| 2278 | class ExprDecompiler { | 2276 | class ExprDecompiler { |
| 2279 | public: | 2277 | public: |
| 2280 | ExprDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} | 2278 | explicit ExprDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} |
| 2281 | 2279 | ||
| 2282 | void operator()(VideoCommon::Shader::ExprAnd& expr) { | 2280 | void operator()(VideoCommon::Shader::ExprAnd& expr) { |
| 2283 | inner += "( "; | 2281 | inner += "( "; |
| @@ -2301,12 +2299,12 @@ public: | |||
| 2301 | } | 2299 | } |
| 2302 | 2300 | ||
| 2303 | void operator()(VideoCommon::Shader::ExprPredicate& expr) { | 2301 | void operator()(VideoCommon::Shader::ExprPredicate& expr) { |
| 2304 | auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate); | 2302 | const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate); |
| 2305 | inner += decomp.GetPredicate(pred); | 2303 | inner += decomp.GetPredicate(pred); |
| 2306 | } | 2304 | } |
| 2307 | 2305 | ||
| 2308 | void operator()(VideoCommon::Shader::ExprCondCode& expr) { | 2306 | void operator()(VideoCommon::Shader::ExprCondCode& expr) { |
| 2309 | Node cc = decomp.ir.GetConditionCode(expr.cc); | 2307 | const Node cc = decomp.ir.GetConditionCode(expr.cc); |
| 2310 | std::string target; | 2308 | std::string target; |
| 2311 | 2309 | ||
| 2312 | if (const auto pred = std::get_if<PredicateNode>(&*cc)) { | 2310 | if (const auto pred = std::get_if<PredicateNode>(&*cc)) { |
| @@ -2321,6 +2319,8 @@ public: | |||
| 2321 | } | 2319 | } |
| 2322 | } else if (const auto flag = std::get_if<InternalFlagNode>(&*cc)) { | 2320 | } else if (const auto flag = std::get_if<InternalFlagNode>(&*cc)) { |
| 2323 | target = decomp.GetInternalFlag(flag->GetFlag()); | 2321 | target = decomp.GetInternalFlag(flag->GetFlag()); |
| 2322 | } else { | ||
| 2323 | UNREACHABLE(); | ||
| 2324 | } | 2324 | } |
| 2325 | inner += target; | 2325 | inner += target; |
| 2326 | } | 2326 | } |
| @@ -2338,13 +2338,13 @@ public: | |||
| 2338 | } | 2338 | } |
| 2339 | 2339 | ||
| 2340 | private: | 2340 | private: |
| 2341 | std::string inner{}; | 2341 | std::string inner; |
| 2342 | GLSLDecompiler& decomp; | 2342 | GLSLDecompiler& decomp; |
| 2343 | }; | 2343 | }; |
| 2344 | 2344 | ||
| 2345 | class ASTDecompiler { | 2345 | class ASTDecompiler { |
| 2346 | public: | 2346 | public: |
| 2347 | ASTDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} | 2347 | explicit ASTDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} |
| 2348 | 2348 | ||
| 2349 | void operator()(VideoCommon::Shader::ASTProgram& ast) { | 2349 | void operator()(VideoCommon::Shader::ASTProgram& ast) { |
| 2350 | ASTNode current = ast.nodes.GetFirst(); | 2350 | ASTNode current = ast.nodes.GetFirst(); |
| @@ -2417,7 +2417,7 @@ public: | |||
| 2417 | } | 2417 | } |
| 2418 | 2418 | ||
| 2419 | void operator()(VideoCommon::Shader::ASTReturn& ast) { | 2419 | void operator()(VideoCommon::Shader::ASTReturn& ast) { |
| 2420 | bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); | 2420 | const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); |
| 2421 | if (!is_true) { | 2421 | if (!is_true) { |
| 2422 | ExprDecompiler expr_parser{decomp}; | 2422 | ExprDecompiler expr_parser{decomp}; |
| 2423 | std::visit(expr_parser, *ast.condition); | 2423 | std::visit(expr_parser, *ast.condition); |
| @@ -2427,7 +2427,8 @@ public: | |||
| 2427 | if (ast.kills) { | 2427 | if (ast.kills) { |
| 2428 | decomp.code.AddLine("discard;"); | 2428 | decomp.code.AddLine("discard;"); |
| 2429 | } else { | 2429 | } else { |
| 2430 | decomp.WriteExit(); | 2430 | decomp.PreExit(); |
| 2431 | decomp.code.AddLine("return;"); | ||
| 2431 | } | 2432 | } |
| 2432 | if (!is_true) { | 2433 | if (!is_true) { |
| 2433 | decomp.code.scope--; | 2434 | decomp.code.scope--; |
| @@ -2436,7 +2437,7 @@ public: | |||
| 2436 | } | 2437 | } |
| 2437 | 2438 | ||
| 2438 | void operator()(VideoCommon::Shader::ASTBreak& ast) { | 2439 | void operator()(VideoCommon::Shader::ASTBreak& ast) { |
| 2439 | bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); | 2440 | const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); |
| 2440 | if (!is_true) { | 2441 | if (!is_true) { |
| 2441 | ExprDecompiler expr_parser{decomp}; | 2442 | ExprDecompiler expr_parser{decomp}; |
| 2442 | std::visit(expr_parser, *ast.condition); | 2443 | std::visit(expr_parser, *ast.condition); |
| @@ -2459,7 +2460,7 @@ private: | |||
| 2459 | }; | 2460 | }; |
| 2460 | 2461 | ||
| 2461 | void GLSLDecompiler::DecompileAST() { | 2462 | void GLSLDecompiler::DecompileAST() { |
| 2462 | u32 num_flow_variables = ir.GetASTNumVariables(); | 2463 | const u32 num_flow_variables = ir.GetASTNumVariables(); |
| 2463 | for (u32 i = 0; i < num_flow_variables; i++) { | 2464 | for (u32 i = 0; i < num_flow_variables; i++) { |
| 2464 | code.AddLine("bool {}{} = false;", flow_var, i); | 2465 | code.AddLine("bool {}{} = false;", flow_var, i); |
| 2465 | } | 2466 | } |