diff options
| author | 2019-10-04 17:23:16 -0400 | |
|---|---|---|
| committer | 2019-10-04 18:52:57 -0400 | |
| commit | e6eae4b815bf4bc480d62677fdf9bdbf5d6cba82 (patch) | |
| tree | 8d5aefe385e6dd88a8f91092dd1d5b347fc4725c /src | |
| parent | Shader_Ir: Address Feedback and clang format. (diff) | |
| download | yuzu-e6eae4b815bf4bc480d62677fdf9bdbf5d6cba82.tar.gz yuzu-e6eae4b815bf4bc480d62677fdf9bdbf5d6cba82.tar.xz yuzu-e6eae4b815bf4bc480d62677fdf9bdbf5d6cba82.zip | |
Shader_ir: Address feedback
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 12 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 13 | ||||
| -rw-r--r-- | src/video_core/shader/ast.cpp | 48 | ||||
| -rw-r--r-- | src/video_core/shader/ast.h | 12 | ||||
| -rw-r--r-- | src/video_core/shader/control_flow.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/shader/decode.cpp | 2 |
6 files changed, 24 insertions, 65 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index bff1067a4..6a610a3bc 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -2271,7 +2271,11 @@ private: | |||
| 2271 | ShaderWriter code; | 2271 | ShaderWriter code; |
| 2272 | }; | 2272 | }; |
| 2273 | 2273 | ||
| 2274 | const std::string flow_var = "flow_var_"; | 2274 | static constexpr std::string_view flow_var = "flow_var_"; |
| 2275 | |||
| 2276 | std::string GetFlowVariable(u32 i) { | ||
| 2277 | return fmt::format("{}{}", flow_var, i); | ||
| 2278 | } | ||
| 2275 | 2279 | ||
| 2276 | class ExprDecompiler { | 2280 | class ExprDecompiler { |
| 2277 | public: | 2281 | public: |
| @@ -2326,7 +2330,7 @@ public: | |||
| 2326 | } | 2330 | } |
| 2327 | 2331 | ||
| 2328 | void operator()(VideoCommon::Shader::ExprVar& expr) { | 2332 | void operator()(VideoCommon::Shader::ExprVar& expr) { |
| 2329 | inner += flow_var + std::to_string(expr.var_index); | 2333 | inner += GetFlowVariable(expr.var_index); |
| 2330 | } | 2334 | } |
| 2331 | 2335 | ||
| 2332 | void operator()(VideoCommon::Shader::ExprBoolean& expr) { | 2336 | void operator()(VideoCommon::Shader::ExprBoolean& expr) { |
| @@ -2391,7 +2395,7 @@ public: | |||
| 2391 | void operator()(VideoCommon::Shader::ASTVarSet& ast) { | 2395 | void operator()(VideoCommon::Shader::ASTVarSet& ast) { |
| 2392 | ExprDecompiler expr_parser{decomp}; | 2396 | ExprDecompiler expr_parser{decomp}; |
| 2393 | std::visit(expr_parser, *ast.condition); | 2397 | std::visit(expr_parser, *ast.condition); |
| 2394 | decomp.code.AddLine("{}{} = {};", flow_var, ast.index, expr_parser.GetResult()); | 2398 | decomp.code.AddLine("{} = {};", GetFlowVariable(ast.index), expr_parser.GetResult()); |
| 2395 | } | 2399 | } |
| 2396 | 2400 | ||
| 2397 | void operator()(VideoCommon::Shader::ASTLabel& ast) { | 2401 | void operator()(VideoCommon::Shader::ASTLabel& ast) { |
| @@ -2462,7 +2466,7 @@ private: | |||
| 2462 | void GLSLDecompiler::DecompileAST() { | 2466 | void GLSLDecompiler::DecompileAST() { |
| 2463 | const u32 num_flow_variables = ir.GetASTNumVariables(); | 2467 | const u32 num_flow_variables = ir.GetASTNumVariables(); |
| 2464 | for (u32 i = 0; i < num_flow_variables; i++) { | 2468 | for (u32 i = 0; i < num_flow_variables; i++) { |
| 2465 | code.AddLine("bool {}{} = false;", flow_var, i); | 2469 | code.AddLine("bool {} = false;", GetFlowVariable(i)); |
| 2466 | } | 2470 | } |
| 2467 | ASTDecompiler decompiler{*this}; | 2471 | ASTDecompiler decompiler{*this}; |
| 2468 | VideoCommon::Shader::ASTNode program = ir.GetASTProgram(); | 2472 | VideoCommon::Shader::ASTNode program = ir.GetASTProgram(); |
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 72a49ebdc..b5a43e79e 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -19,6 +19,8 @@ using VideoCommon::Shader::ShaderIR; | |||
| 19 | static constexpr u32 PROGRAM_OFFSET = 10; | 19 | static constexpr u32 PROGRAM_OFFSET = 10; |
| 20 | static constexpr u32 COMPUTE_OFFSET = 0; | 20 | static constexpr u32 COMPUTE_OFFSET = 0; |
| 21 | 21 | ||
| 22 | static constexpr CompilerSettings settings{CompileDepth::NoFlowStack, true}; | ||
| 23 | |||
| 22 | ProgramResult GenerateVertexShader(const Device& device, const ShaderSetup& setup) { | 24 | ProgramResult GenerateVertexShader(const Device& device, const ShaderSetup& setup) { |
| 23 | const std::string id = fmt::format("{:016x}", setup.program.unique_identifier); | 25 | const std::string id = fmt::format("{:016x}", setup.program.unique_identifier); |
| 24 | 26 | ||
| @@ -33,9 +35,6 @@ layout (std140, binding = EMULATION_UBO_BINDING) uniform vs_config { | |||
| 33 | 35 | ||
| 34 | )"; | 36 | )"; |
| 35 | 37 | ||
| 36 | CompilerSettings settings; | ||
| 37 | settings.depth = CompileDepth::NoFlowStack; | ||
| 38 | |||
| 39 | const ShaderIR program_ir(setup.program.code, PROGRAM_OFFSET, setup.program.size_a, settings); | 38 | const ShaderIR program_ir(setup.program.code, PROGRAM_OFFSET, setup.program.size_a, settings); |
| 40 | const auto stage = setup.IsDualProgram() ? ProgramType::VertexA : ProgramType::VertexB; | 39 | const auto stage = setup.IsDualProgram() ? ProgramType::VertexA : ProgramType::VertexB; |
| 41 | ProgramResult program = Decompile(device, program_ir, stage, "vertex"); | 40 | ProgramResult program = Decompile(device, program_ir, stage, "vertex"); |
| @@ -86,9 +85,6 @@ layout (std140, binding = EMULATION_UBO_BINDING) uniform gs_config { | |||
| 86 | 85 | ||
| 87 | )"; | 86 | )"; |
| 88 | 87 | ||
| 89 | CompilerSettings settings; | ||
| 90 | settings.depth = CompileDepth::NoFlowStack; | ||
| 91 | |||
| 92 | const ShaderIR program_ir(setup.program.code, PROGRAM_OFFSET, setup.program.size_a, settings); | 88 | const ShaderIR program_ir(setup.program.code, PROGRAM_OFFSET, setup.program.size_a, settings); |
| 93 | ProgramResult program = Decompile(device, program_ir, ProgramType::Geometry, "geometry"); | 89 | ProgramResult program = Decompile(device, program_ir, ProgramType::Geometry, "geometry"); |
| 94 | out += program.first; | 90 | out += program.first; |
| @@ -123,8 +119,6 @@ layout (std140, binding = EMULATION_UBO_BINDING) uniform fs_config { | |||
| 123 | }; | 119 | }; |
| 124 | 120 | ||
| 125 | )"; | 121 | )"; |
| 126 | CompilerSettings settings; | ||
| 127 | settings.depth = CompileDepth::NoFlowStack; | ||
| 128 | 122 | ||
| 129 | const ShaderIR program_ir(setup.program.code, PROGRAM_OFFSET, setup.program.size_a, settings); | 123 | const ShaderIR program_ir(setup.program.code, PROGRAM_OFFSET, setup.program.size_a, settings); |
| 130 | ProgramResult program = Decompile(device, program_ir, ProgramType::Fragment, "fragment"); | 124 | ProgramResult program = Decompile(device, program_ir, ProgramType::Fragment, "fragment"); |
| @@ -145,9 +139,6 @@ ProgramResult GenerateComputeShader(const Device& device, const ShaderSetup& set | |||
| 145 | std::string out = "// Shader Unique Id: CS" + id + "\n\n"; | 139 | std::string out = "// Shader Unique Id: CS" + id + "\n\n"; |
| 146 | out += GetCommonDeclarations(); | 140 | out += GetCommonDeclarations(); |
| 147 | 141 | ||
| 148 | CompilerSettings settings; | ||
| 149 | settings.depth = CompileDepth::NoFlowStack; | ||
| 150 | |||
| 151 | const ShaderIR program_ir(setup.program.code, COMPUTE_OFFSET, setup.program.size_a, settings); | 142 | const ShaderIR program_ir(setup.program.code, COMPUTE_OFFSET, setup.program.size_a, settings); |
| 152 | ProgramResult program = Decompile(device, program_ir, ProgramType::Compute, "compute"); | 143 | ProgramResult program = Decompile(device, program_ir, ProgramType::Compute, "compute"); |
| 153 | out += program.first; | 144 | out += program.first; |
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp index c4548f0bc..2eb065c3d 100644 --- a/src/video_core/shader/ast.cpp +++ b/src/video_core/shader/ast.cpp | |||
| @@ -376,7 +376,7 @@ void ASTManager::Init() { | |||
| 376 | false_condition = MakeExpr<ExprBoolean>(false); | 376 | false_condition = MakeExpr<ExprBoolean>(false); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | ASTManager::ASTManager(ASTManager&& other) | 379 | ASTManager::ASTManager(ASTManager&& other) noexcept |
| 380 | : labels_map(std::move(other.labels_map)), labels_count{other.labels_count}, | 380 | : labels_map(std::move(other.labels_map)), labels_count{other.labels_count}, |
| 381 | gotos(std::move(other.gotos)), labels(std::move(other.labels)), variables{other.variables}, | 381 | gotos(std::move(other.gotos)), labels(std::move(other.labels)), variables{other.variables}, |
| 382 | program{other.program}, main_node{other.main_node}, false_condition{other.false_condition}, | 382 | program{other.program}, main_node{other.main_node}, false_condition{other.false_condition}, |
| @@ -384,7 +384,7 @@ ASTManager::ASTManager(ASTManager&& other) | |||
| 384 | other.main_node.reset(); | 384 | other.main_node.reset(); |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | ASTManager& ASTManager::operator=(ASTManager&& other) { | 387 | ASTManager& ASTManager::operator=(ASTManager&& other) noexcept { |
| 388 | full_decompile = other.full_decompile; | 388 | full_decompile = other.full_decompile; |
| 389 | labels_map = std::move(other.labels_map); | 389 | labels_map = std::move(other.labels_map); |
| 390 | labels_count = other.labels_count; | 390 | labels_count = other.labels_count; |
| @@ -490,7 +490,7 @@ void ASTManager::Decompile() { | |||
| 490 | it++; | 490 | it++; |
| 491 | } | 491 | } |
| 492 | if (full_decompile) { | 492 | if (full_decompile) { |
| 493 | for (const ASTNode label : labels) { | 493 | for (const ASTNode& label : labels) { |
| 494 | auto& manager = label->GetManager(); | 494 | auto& manager = label->GetManager(); |
| 495 | manager.Remove(label); | 495 | manager.Remove(label); |
| 496 | } | 496 | } |
| @@ -500,12 +500,12 @@ void ASTManager::Decompile() { | |||
| 500 | while (it != labels.end()) { | 500 | while (it != labels.end()) { |
| 501 | bool can_remove = true; | 501 | bool can_remove = true; |
| 502 | ASTNode label = *it; | 502 | ASTNode label = *it; |
| 503 | for (const ASTNode goto_node : gotos) { | 503 | for (const ASTNode& goto_node : gotos) { |
| 504 | const auto label_index = goto_node->GetGotoLabel(); | 504 | const auto label_index = goto_node->GetGotoLabel(); |
| 505 | if (!label_index) { | 505 | if (!label_index) { |
| 506 | return; | 506 | return; |
| 507 | } | 507 | } |
| 508 | ASTNode glabel = labels[*label_index]; | 508 | ASTNode& glabel = labels[*label_index]; |
| 509 | if (glabel == label) { | 509 | if (glabel == label) { |
| 510 | can_remove = false; | 510 | can_remove = false; |
| 511 | break; | 511 | break; |
| @@ -543,40 +543,6 @@ bool ASTManager::IsBackwardsJump(ASTNode goto_node, ASTNode label_node) const { | |||
| 543 | return false; | 543 | return false; |
| 544 | } | 544 | } |
| 545 | 545 | ||
| 546 | ASTNode CommonParent(ASTNode first, ASTNode second) { | ||
| 547 | if (first->GetParent() == second->GetParent()) { | ||
| 548 | return first->GetParent(); | ||
| 549 | } | ||
| 550 | const u32 first_level = first->GetLevel(); | ||
| 551 | const u32 second_level = second->GetLevel(); | ||
| 552 | u32 min_level; | ||
| 553 | u32 max_level; | ||
| 554 | ASTNode max; | ||
| 555 | ASTNode min; | ||
| 556 | if (first_level > second_level) { | ||
| 557 | min_level = second_level; | ||
| 558 | min = second; | ||
| 559 | max_level = first_level; | ||
| 560 | max = first; | ||
| 561 | } else { | ||
| 562 | min_level = first_level; | ||
| 563 | min = first; | ||
| 564 | max_level = second_level; | ||
| 565 | max = second; | ||
| 566 | } | ||
| 567 | |||
| 568 | while (max_level > min_level) { | ||
| 569 | max_level--; | ||
| 570 | max = max->GetParent(); | ||
| 571 | } | ||
| 572 | |||
| 573 | while (min->GetParent() != max->GetParent()) { | ||
| 574 | min = min->GetParent(); | ||
| 575 | max = max->GetParent(); | ||
| 576 | } | ||
| 577 | return min->GetParent(); | ||
| 578 | } | ||
| 579 | |||
| 580 | bool ASTManager::IndirectlyRelated(ASTNode first, ASTNode second) { | 546 | bool ASTManager::IndirectlyRelated(ASTNode first, ASTNode second) { |
| 581 | return !(first->GetParent() == second->GetParent() || DirectlyRelated(first, second)); | 547 | return !(first->GetParent() == second->GetParent() || DirectlyRelated(first, second)); |
| 582 | } | 548 | } |
| @@ -608,7 +574,7 @@ bool ASTManager::DirectlyRelated(ASTNode first, ASTNode second) { | |||
| 608 | max = max->GetParent(); | 574 | max = max->GetParent(); |
| 609 | } | 575 | } |
| 610 | 576 | ||
| 611 | return (min->GetParent() == max->GetParent()); | 577 | return min->GetParent() == max->GetParent(); |
| 612 | } | 578 | } |
| 613 | 579 | ||
| 614 | void ASTManager::ShowCurrentState(std::string state) { | 580 | void ASTManager::ShowCurrentState(std::string state) { |
| @@ -617,7 +583,7 @@ void ASTManager::ShowCurrentState(std::string state) { | |||
| 617 | } | 583 | } |
| 618 | 584 | ||
| 619 | void ASTManager::SanityCheck() { | 585 | void ASTManager::SanityCheck() { |
| 620 | for (auto label : labels) { | 586 | for (auto& label : labels) { |
| 621 | if (!label->GetParent()) { | 587 | if (!label->GetParent()) { |
| 622 | LOG_CRITICAL(HW_GPU, "Sanity Check Failed"); | 588 | LOG_CRITICAL(HW_GPU, "Sanity Check Failed"); |
| 623 | } | 589 | } |
diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index 8efd4c147..ba234138e 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h | |||
| @@ -97,7 +97,7 @@ public: | |||
| 97 | 97 | ||
| 98 | class ASTBlockDecoded { | 98 | class ASTBlockDecoded { |
| 99 | public: | 99 | public: |
| 100 | explicit ASTBlockDecoded(NodeBlock& new_nodes) : nodes(std::move(new_nodes)) {} | 100 | explicit ASTBlockDecoded(NodeBlock&& new_nodes) : nodes(std::move(new_nodes)) {} |
| 101 | NodeBlock nodes; | 101 | NodeBlock nodes; |
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| @@ -255,8 +255,8 @@ public: | |||
| 255 | return std::holds_alternative<ASTBlockEncoded>(data); | 255 | return std::holds_alternative<ASTBlockEncoded>(data); |
| 256 | } | 256 | } |
| 257 | 257 | ||
| 258 | void TransformBlockEncoded(NodeBlock& nodes) { | 258 | void TransformBlockEncoded(NodeBlock&& nodes) { |
| 259 | data = ASTBlockDecoded(nodes); | 259 | data = ASTBlockDecoded(std::move(nodes)); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | bool IsLoop() const { | 262 | bool IsLoop() const { |
| @@ -304,8 +304,8 @@ public: | |||
| 304 | ASTManager(const ASTManager& o) = delete; | 304 | ASTManager(const ASTManager& o) = delete; |
| 305 | ASTManager& operator=(const ASTManager& other) = delete; | 305 | ASTManager& operator=(const ASTManager& other) = delete; |
| 306 | 306 | ||
| 307 | ASTManager(ASTManager&& other); | 307 | ASTManager(ASTManager&& other) noexcept; |
| 308 | ASTManager& operator=(ASTManager&& other); | 308 | ASTManager& operator=(ASTManager&& other) noexcept; |
| 309 | 309 | ||
| 310 | void Init(); | 310 | void Init(); |
| 311 | 311 | ||
| @@ -362,8 +362,6 @@ public: | |||
| 362 | private: | 362 | private: |
| 363 | bool IsBackwardsJump(ASTNode goto_node, ASTNode label_node) const; | 363 | bool IsBackwardsJump(ASTNode goto_node, ASTNode label_node) const; |
| 364 | 364 | ||
| 365 | ASTNode CommonParent(ASTNode first, ASTNode second); | ||
| 366 | |||
| 367 | bool IndirectlyRelated(ASTNode first, ASTNode second); | 365 | bool IndirectlyRelated(ASTNode first, ASTNode second); |
| 368 | 366 | ||
| 369 | bool DirectlyRelated(ASTNode first, ASTNode second); | 367 | bool DirectlyRelated(ASTNode first, ASTNode second); |
diff --git a/src/video_core/shader/control_flow.cpp b/src/video_core/shader/control_flow.cpp index c2fa734e7..3c3a41ba6 100644 --- a/src/video_core/shader/control_flow.cpp +++ b/src/video_core/shader/control_flow.cpp | |||
| @@ -58,7 +58,7 @@ struct BlockInfo { | |||
| 58 | struct CFGRebuildState { | 58 | struct CFGRebuildState { |
| 59 | explicit CFGRebuildState(const ProgramCode& program_code, const std::size_t program_size, | 59 | explicit CFGRebuildState(const ProgramCode& program_code, const std::size_t program_size, |
| 60 | const u32 start) | 60 | const u32 start) |
| 61 | : program_code{program_code}, program_size{program_size}, start{start} {} | 61 | : start{start}, program_code{program_code}, program_size{program_size} {} |
| 62 | 62 | ||
| 63 | u32 start{}; | 63 | u32 start{}; |
| 64 | std::vector<BlockInfo> block_info{}; | 64 | std::vector<BlockInfo> block_info{}; |
diff --git a/src/video_core/shader/decode.cpp b/src/video_core/shader/decode.cpp index 6d4359295..2626b1616 100644 --- a/src/video_core/shader/decode.cpp +++ b/src/video_core/shader/decode.cpp | |||
| @@ -90,7 +90,7 @@ public: | |||
| 90 | if (node->IsBlockEncoded()) { | 90 | if (node->IsBlockEncoded()) { |
| 91 | auto block = std::get_if<ASTBlockEncoded>(node->GetInnerData()); | 91 | auto block = std::get_if<ASTBlockEncoded>(node->GetInnerData()); |
| 92 | NodeBlock bb = ir.DecodeRange(block->start, block->end); | 92 | NodeBlock bb = ir.DecodeRange(block->start, block->end); |
| 93 | node->TransformBlockEncoded(bb); | 93 | node->TransformBlockEncoded(std::move(bb)); |
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||