diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 64 | ||||
| -rw-r--r-- | src/video_core/shader/node.h | 2 |
2 files changed, 32 insertions, 34 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 6a610a3bc..a3524a6a9 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -1148,7 +1148,7 @@ private: | |||
| 1148 | for (const auto& variant : extras) { | 1148 | for (const auto& variant : extras) { |
| 1149 | if (const auto argument = std::get_if<TextureArgument>(&variant)) { | 1149 | if (const auto argument = std::get_if<TextureArgument>(&variant)) { |
| 1150 | expr += GenerateTextureArgument(*argument); | 1150 | expr += GenerateTextureArgument(*argument); |
| 1151 | } else if (std::get_if<TextureAoffi>(&variant)) { | 1151 | } else if (std::holds_alternative<TextureAoffi>(variant)) { |
| 1152 | expr += GenerateTextureAoffi(meta->aoffi); | 1152 | expr += GenerateTextureAoffi(meta->aoffi); |
| 1153 | } else { | 1153 | } else { |
| 1154 | UNREACHABLE(); | 1154 | UNREACHABLE(); |
| @@ -1158,8 +1158,8 @@ private: | |||
| 1158 | return expr + ')'; | 1158 | return expr + ')'; |
| 1159 | } | 1159 | } |
| 1160 | 1160 | ||
| 1161 | std::string GenerateTextureArgument(TextureArgument argument) { | 1161 | std::string GenerateTextureArgument(const TextureArgument& argument) { |
| 1162 | const auto [type, operand] = argument; | 1162 | const auto& [type, operand] = argument; |
| 1163 | if (operand == nullptr) { | 1163 | if (operand == nullptr) { |
| 1164 | return {}; | 1164 | return {}; |
| 1165 | } | 1165 | } |
| @@ -1235,7 +1235,7 @@ private: | |||
| 1235 | 1235 | ||
| 1236 | std::string BuildImageValues(Operation operation) { | 1236 | std::string BuildImageValues(Operation operation) { |
| 1237 | constexpr std::array constructors{"uint", "uvec2", "uvec3", "uvec4"}; | 1237 | constexpr std::array constructors{"uint", "uvec2", "uvec3", "uvec4"}; |
| 1238 | const auto meta{std::get<MetaImage>(operation.GetMeta())}; | 1238 | const auto& meta{std::get<MetaImage>(operation.GetMeta())}; |
| 1239 | 1239 | ||
| 1240 | const std::size_t values_count{meta.values.size()}; | 1240 | const std::size_t values_count{meta.values.size()}; |
| 1241 | std::string expr = fmt::format("{}(", constructors.at(values_count - 1)); | 1241 | std::string expr = fmt::format("{}(", constructors.at(values_count - 1)); |
| @@ -1780,14 +1780,14 @@ private: | |||
| 1780 | return {"0", Type::Int}; | 1780 | return {"0", Type::Int}; |
| 1781 | } | 1781 | } |
| 1782 | 1782 | ||
| 1783 | const auto meta{std::get<MetaImage>(operation.GetMeta())}; | 1783 | const auto& meta{std::get<MetaImage>(operation.GetMeta())}; |
| 1784 | return {fmt::format("imageLoad({}, {}){}", GetImage(meta.image), | 1784 | return {fmt::format("imageLoad({}, {}){}", GetImage(meta.image), |
| 1785 | BuildIntegerCoordinates(operation), GetSwizzle(meta.element)), | 1785 | BuildIntegerCoordinates(operation), GetSwizzle(meta.element)), |
| 1786 | Type::Uint}; | 1786 | Type::Uint}; |
| 1787 | } | 1787 | } |
| 1788 | 1788 | ||
| 1789 | Expression ImageStore(Operation operation) { | 1789 | Expression ImageStore(Operation operation) { |
| 1790 | const auto meta{std::get<MetaImage>(operation.GetMeta())}; | 1790 | const auto& meta{std::get<MetaImage>(operation.GetMeta())}; |
| 1791 | code.AddLine("imageStore({}, {}, {});", GetImage(meta.image), | 1791 | code.AddLine("imageStore({}, {}, {});", GetImage(meta.image), |
| 1792 | BuildIntegerCoordinates(operation), BuildImageValues(operation)); | 1792 | BuildIntegerCoordinates(operation), BuildImageValues(operation)); |
| 1793 | return {}; | 1793 | return {}; |
| @@ -1795,7 +1795,7 @@ private: | |||
| 1795 | 1795 | ||
| 1796 | template <const std::string_view& opname> | 1796 | template <const std::string_view& opname> |
| 1797 | Expression AtomicImage(Operation operation) { | 1797 | Expression AtomicImage(Operation operation) { |
| 1798 | const auto meta{std::get<MetaImage>(operation.GetMeta())}; | 1798 | const auto& meta{std::get<MetaImage>(operation.GetMeta())}; |
| 1799 | ASSERT(meta.values.size() == 1); | 1799 | ASSERT(meta.values.size() == 1); |
| 1800 | 1800 | ||
| 1801 | return {fmt::format("imageAtomic{}({}, {}, {})", opname, GetImage(meta.image), | 1801 | return {fmt::format("imageAtomic{}({}, {}, {})", opname, GetImage(meta.image), |
| @@ -2246,7 +2246,7 @@ private: | |||
| 2246 | code.AddLine("#ifdef SAMPLER_{}_IS_BUFFER", sampler.GetIndex()); | 2246 | code.AddLine("#ifdef SAMPLER_{}_IS_BUFFER", sampler.GetIndex()); |
| 2247 | } | 2247 | } |
| 2248 | 2248 | ||
| 2249 | std::string GetDeclarationWithSuffix(u32 index, const std::string& name) const { | 2249 | std::string GetDeclarationWithSuffix(u32 index, std::string_view name) const { |
| 2250 | return fmt::format("{}_{}_{}", name, index, suffix); | 2250 | return fmt::format("{}_{}_{}", name, index, suffix); |
| 2251 | } | 2251 | } |
| 2252 | 2252 | ||
| @@ -2271,17 +2271,15 @@ private: | |||
| 2271 | ShaderWriter code; | 2271 | ShaderWriter code; |
| 2272 | }; | 2272 | }; |
| 2273 | 2273 | ||
| 2274 | static constexpr std::string_view flow_var = "flow_var_"; | ||
| 2275 | |||
| 2276 | std::string GetFlowVariable(u32 i) { | 2274 | std::string GetFlowVariable(u32 i) { |
| 2277 | return fmt::format("{}{}", flow_var, i); | 2275 | return fmt::format("flow_var_{}", i); |
| 2278 | } | 2276 | } |
| 2279 | 2277 | ||
| 2280 | class ExprDecompiler { | 2278 | class ExprDecompiler { |
| 2281 | public: | 2279 | public: |
| 2282 | explicit ExprDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} | 2280 | explicit ExprDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} |
| 2283 | 2281 | ||
| 2284 | void operator()(VideoCommon::Shader::ExprAnd& expr) { | 2282 | void operator()(const ExprAnd& expr) { |
| 2285 | inner += "( "; | 2283 | inner += "( "; |
| 2286 | std::visit(*this, *expr.operand1); | 2284 | std::visit(*this, *expr.operand1); |
| 2287 | inner += " && "; | 2285 | inner += " && "; |
| @@ -2289,7 +2287,7 @@ public: | |||
| 2289 | inner += ')'; | 2287 | inner += ')'; |
| 2290 | } | 2288 | } |
| 2291 | 2289 | ||
| 2292 | void operator()(VideoCommon::Shader::ExprOr& expr) { | 2290 | void operator()(const ExprOr& expr) { |
| 2293 | inner += "( "; | 2291 | inner += "( "; |
| 2294 | std::visit(*this, *expr.operand1); | 2292 | std::visit(*this, *expr.operand1); |
| 2295 | inner += " || "; | 2293 | inner += " || "; |
| @@ -2297,17 +2295,17 @@ public: | |||
| 2297 | inner += ')'; | 2295 | inner += ')'; |
| 2298 | } | 2296 | } |
| 2299 | 2297 | ||
| 2300 | void operator()(VideoCommon::Shader::ExprNot& expr) { | 2298 | void operator()(const ExprNot& expr) { |
| 2301 | inner += '!'; | 2299 | inner += '!'; |
| 2302 | std::visit(*this, *expr.operand1); | 2300 | std::visit(*this, *expr.operand1); |
| 2303 | } | 2301 | } |
| 2304 | 2302 | ||
| 2305 | void operator()(VideoCommon::Shader::ExprPredicate& expr) { | 2303 | void operator()(const ExprPredicate& expr) { |
| 2306 | const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate); | 2304 | const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate); |
| 2307 | inner += decomp.GetPredicate(pred); | 2305 | inner += decomp.GetPredicate(pred); |
| 2308 | } | 2306 | } |
| 2309 | 2307 | ||
| 2310 | void operator()(VideoCommon::Shader::ExprCondCode& expr) { | 2308 | void operator()(const ExprCondCode& expr) { |
| 2311 | const Node cc = decomp.ir.GetConditionCode(expr.cc); | 2309 | const Node cc = decomp.ir.GetConditionCode(expr.cc); |
| 2312 | std::string target; | 2310 | std::string target; |
| 2313 | 2311 | ||
| @@ -2329,15 +2327,15 @@ public: | |||
| 2329 | inner += target; | 2327 | inner += target; |
| 2330 | } | 2328 | } |
| 2331 | 2329 | ||
| 2332 | void operator()(VideoCommon::Shader::ExprVar& expr) { | 2330 | void operator()(const ExprVar& expr) { |
| 2333 | inner += GetFlowVariable(expr.var_index); | 2331 | inner += GetFlowVariable(expr.var_index); |
| 2334 | } | 2332 | } |
| 2335 | 2333 | ||
| 2336 | void operator()(VideoCommon::Shader::ExprBoolean& expr) { | 2334 | void operator()(const ExprBoolean& expr) { |
| 2337 | inner += expr.value ? "true" : "false"; | 2335 | inner += expr.value ? "true" : "false"; |
| 2338 | } | 2336 | } |
| 2339 | 2337 | ||
| 2340 | std::string& GetResult() { | 2338 | const std::string& GetResult() const { |
| 2341 | return inner; | 2339 | return inner; |
| 2342 | } | 2340 | } |
| 2343 | 2341 | ||
| @@ -2350,7 +2348,7 @@ class ASTDecompiler { | |||
| 2350 | public: | 2348 | public: |
| 2351 | explicit ASTDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} | 2349 | explicit ASTDecompiler(GLSLDecompiler& decomp) : decomp{decomp} {} |
| 2352 | 2350 | ||
| 2353 | void operator()(VideoCommon::Shader::ASTProgram& ast) { | 2351 | void operator()(const ASTProgram& ast) { |
| 2354 | ASTNode current = ast.nodes.GetFirst(); | 2352 | ASTNode current = ast.nodes.GetFirst(); |
| 2355 | while (current) { | 2353 | while (current) { |
| 2356 | Visit(current); | 2354 | Visit(current); |
| @@ -2358,7 +2356,7 @@ public: | |||
| 2358 | } | 2356 | } |
| 2359 | } | 2357 | } |
| 2360 | 2358 | ||
| 2361 | void operator()(VideoCommon::Shader::ASTIfThen& ast) { | 2359 | void operator()(const ASTIfThen& ast) { |
| 2362 | ExprDecompiler expr_parser{decomp}; | 2360 | ExprDecompiler expr_parser{decomp}; |
| 2363 | std::visit(expr_parser, *ast.condition); | 2361 | std::visit(expr_parser, *ast.condition); |
| 2364 | decomp.code.AddLine("if ({}) {{", expr_parser.GetResult()); | 2362 | decomp.code.AddLine("if ({}) {{", expr_parser.GetResult()); |
| @@ -2372,7 +2370,7 @@ public: | |||
| 2372 | decomp.code.AddLine("}}"); | 2370 | decomp.code.AddLine("}}"); |
| 2373 | } | 2371 | } |
| 2374 | 2372 | ||
| 2375 | void operator()(VideoCommon::Shader::ASTIfElse& ast) { | 2373 | void operator()(const ASTIfElse& ast) { |
| 2376 | decomp.code.AddLine("else {{"); | 2374 | decomp.code.AddLine("else {{"); |
| 2377 | decomp.code.scope++; | 2375 | decomp.code.scope++; |
| 2378 | ASTNode current = ast.nodes.GetFirst(); | 2376 | ASTNode current = ast.nodes.GetFirst(); |
| @@ -2384,29 +2382,29 @@ public: | |||
| 2384 | decomp.code.AddLine("}}"); | 2382 | decomp.code.AddLine("}}"); |
| 2385 | } | 2383 | } |
| 2386 | 2384 | ||
| 2387 | void operator()(VideoCommon::Shader::ASTBlockEncoded& ast) { | 2385 | void operator()([[maybe_unused]] const ASTBlockEncoded& ast) { |
| 2388 | UNREACHABLE(); | 2386 | UNREACHABLE(); |
| 2389 | } | 2387 | } |
| 2390 | 2388 | ||
| 2391 | void operator()(VideoCommon::Shader::ASTBlockDecoded& ast) { | 2389 | void operator()(const ASTBlockDecoded& ast) { |
| 2392 | decomp.VisitBlock(ast.nodes); | 2390 | decomp.VisitBlock(ast.nodes); |
| 2393 | } | 2391 | } |
| 2394 | 2392 | ||
| 2395 | void operator()(VideoCommon::Shader::ASTVarSet& ast) { | 2393 | void operator()(const ASTVarSet& ast) { |
| 2396 | ExprDecompiler expr_parser{decomp}; | 2394 | ExprDecompiler expr_parser{decomp}; |
| 2397 | std::visit(expr_parser, *ast.condition); | 2395 | std::visit(expr_parser, *ast.condition); |
| 2398 | decomp.code.AddLine("{} = {};", GetFlowVariable(ast.index), expr_parser.GetResult()); | 2396 | decomp.code.AddLine("{} = {};", GetFlowVariable(ast.index), expr_parser.GetResult()); |
| 2399 | } | 2397 | } |
| 2400 | 2398 | ||
| 2401 | void operator()(VideoCommon::Shader::ASTLabel& ast) { | 2399 | void operator()(const ASTLabel& ast) { |
| 2402 | decomp.code.AddLine("// Label_{}:", ast.index); | 2400 | decomp.code.AddLine("// Label_{}:", ast.index); |
| 2403 | } | 2401 | } |
| 2404 | 2402 | ||
| 2405 | void operator()(VideoCommon::Shader::ASTGoto& ast) { | 2403 | void operator()([[maybe_unused]] const ASTGoto& ast) { |
| 2406 | UNREACHABLE(); | 2404 | UNREACHABLE(); |
| 2407 | } | 2405 | } |
| 2408 | 2406 | ||
| 2409 | void operator()(VideoCommon::Shader::ASTDoWhile& ast) { | 2407 | void operator()(const ASTDoWhile& ast) { |
| 2410 | ExprDecompiler expr_parser{decomp}; | 2408 | ExprDecompiler expr_parser{decomp}; |
| 2411 | std::visit(expr_parser, *ast.condition); | 2409 | std::visit(expr_parser, *ast.condition); |
| 2412 | decomp.code.AddLine("do {{"); | 2410 | decomp.code.AddLine("do {{"); |
| @@ -2420,7 +2418,7 @@ public: | |||
| 2420 | decomp.code.AddLine("}} while({});", expr_parser.GetResult()); | 2418 | decomp.code.AddLine("}} while({});", expr_parser.GetResult()); |
| 2421 | } | 2419 | } |
| 2422 | 2420 | ||
| 2423 | void operator()(VideoCommon::Shader::ASTReturn& ast) { | 2421 | void operator()(const ASTReturn& ast) { |
| 2424 | const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); | 2422 | const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); |
| 2425 | if (!is_true) { | 2423 | if (!is_true) { |
| 2426 | ExprDecompiler expr_parser{decomp}; | 2424 | ExprDecompiler expr_parser{decomp}; |
| @@ -2440,7 +2438,7 @@ public: | |||
| 2440 | } | 2438 | } |
| 2441 | } | 2439 | } |
| 2442 | 2440 | ||
| 2443 | void operator()(VideoCommon::Shader::ASTBreak& ast) { | 2441 | void operator()(const ASTBreak& ast) { |
| 2444 | const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); | 2442 | const bool is_true = VideoCommon::Shader::ExprIsTrue(ast.condition); |
| 2445 | if (!is_true) { | 2443 | if (!is_true) { |
| 2446 | ExprDecompiler expr_parser{decomp}; | 2444 | ExprDecompiler expr_parser{decomp}; |
| @@ -2455,7 +2453,7 @@ public: | |||
| 2455 | } | 2453 | } |
| 2456 | } | 2454 | } |
| 2457 | 2455 | ||
| 2458 | void Visit(VideoCommon::Shader::ASTNode& node) { | 2456 | void Visit(const ASTNode& node) { |
| 2459 | std::visit(*this, *node->GetInnerData()); | 2457 | std::visit(*this, *node->GetInnerData()); |
| 2460 | } | 2458 | } |
| 2461 | 2459 | ||
| @@ -2468,9 +2466,9 @@ void GLSLDecompiler::DecompileAST() { | |||
| 2468 | for (u32 i = 0; i < num_flow_variables; i++) { | 2466 | for (u32 i = 0; i < num_flow_variables; i++) { |
| 2469 | code.AddLine("bool {} = false;", GetFlowVariable(i)); | 2467 | code.AddLine("bool {} = false;", GetFlowVariable(i)); |
| 2470 | } | 2468 | } |
| 2469 | |||
| 2471 | ASTDecompiler decompiler{*this}; | 2470 | ASTDecompiler decompiler{*this}; |
| 2472 | VideoCommon::Shader::ASTNode program = ir.GetASTProgram(); | 2471 | decompiler.Visit(ir.GetASTProgram()); |
| 2473 | decompiler.Visit(program); | ||
| 2474 | } | 2472 | } |
| 2475 | 2473 | ||
| 2476 | } // Anonymous namespace | 2474 | } // Anonymous namespace |
diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 338bab17c..447fb5c1d 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h | |||
| @@ -410,7 +410,7 @@ public: | |||
| 410 | explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {} | 410 | explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {} |
| 411 | 411 | ||
| 412 | explicit OperationNode(OperationCode code, Meta meta) | 412 | explicit OperationNode(OperationCode code, Meta meta) |
| 413 | : OperationNode(code, meta, std::vector<Node>{}) {} | 413 | : OperationNode(code, std::move(meta), std::vector<Node>{}) {} |
| 414 | 414 | ||
| 415 | explicit OperationNode(OperationCode code, std::vector<Node> operands) | 415 | explicit OperationNode(OperationCode code, std::vector<Node> operands) |
| 416 | : OperationNode(code, Meta{}, std::move(operands)) {} | 416 | : OperationNode(code, Meta{}, std::move(operands)) {} |