diff options
| author | 2019-09-28 15:16:19 -0400 | |
|---|---|---|
| committer | 2019-10-04 18:52:57 -0400 | |
| commit | 3c09d9abe6d268ada063fd67c08d09fc0fcad613 (patch) | |
| tree | 27f1442ec1ee8390850dd5099ed3642f1d3f59db /src/video_core/shader | |
| parent | vk_shader_decompiler: Correct Branches inside conditionals. (diff) | |
| download | yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.gz yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.xz yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.zip | |
Shader_Ir: Address Feedback and clang format.
Diffstat (limited to 'src/video_core/shader')
| -rw-r--r-- | src/video_core/shader/ast.cpp | 14 | ||||
| -rw-r--r-- | src/video_core/shader/ast.h | 65 | ||||
| -rw-r--r-- | src/video_core/shader/expr.h | 14 |
3 files changed, 50 insertions, 43 deletions
diff --git a/src/video_core/shader/ast.cpp b/src/video_core/shader/ast.cpp index fc440526f..c4548f0bc 100644 --- a/src/video_core/shader/ast.cpp +++ b/src/video_core/shader/ast.cpp | |||
| @@ -442,8 +442,11 @@ void ASTManager::Decompile() { | |||
| 442 | auto it = gotos.begin(); | 442 | auto it = gotos.begin(); |
| 443 | while (it != gotos.end()) { | 443 | while (it != gotos.end()) { |
| 444 | const ASTNode goto_node = *it; | 444 | const ASTNode goto_node = *it; |
| 445 | const u32 label_index = goto_node->GetGotoLabel(); | 445 | const auto label_index = goto_node->GetGotoLabel(); |
| 446 | const ASTNode label = labels[label_index]; | 446 | if (!label_index) { |
| 447 | return; | ||
| 448 | } | ||
| 449 | const ASTNode label = labels[*label_index]; | ||
| 447 | if (!full_decompile) { | 450 | if (!full_decompile) { |
| 448 | // We only decompile backward jumps | 451 | // We only decompile backward jumps |
| 449 | if (!IsBackwardsJump(goto_node, label)) { | 452 | if (!IsBackwardsJump(goto_node, label)) { |
| @@ -498,8 +501,11 @@ void ASTManager::Decompile() { | |||
| 498 | bool can_remove = true; | 501 | bool can_remove = true; |
| 499 | ASTNode label = *it; | 502 | ASTNode label = *it; |
| 500 | for (const ASTNode goto_node : gotos) { | 503 | for (const ASTNode goto_node : gotos) { |
| 501 | const u32 label_index = goto_node->GetGotoLabel(); | 504 | const auto label_index = goto_node->GetGotoLabel(); |
| 502 | ASTNode glabel = labels[label_index]; | 505 | if (!label_index) { |
| 506 | return; | ||
| 507 | } | ||
| 508 | ASTNode glabel = labels[*label_index]; | ||
| 503 | if (glabel == label) { | 509 | if (glabel == label) { |
| 504 | can_remove = false; | 510 | can_remove = false; |
| 505 | break; | 511 | break; |
diff --git a/src/video_core/shader/ast.h b/src/video_core/shader/ast.h index 1b73f301f..8efd4c147 100644 --- a/src/video_core/shader/ast.h +++ b/src/video_core/shader/ast.h | |||
| @@ -44,7 +44,7 @@ enum class ASTZipperType : u32 { | |||
| 44 | 44 | ||
| 45 | class ASTZipper final { | 45 | class ASTZipper final { |
| 46 | public: | 46 | public: |
| 47 | ASTZipper(); | 47 | explicit ASTZipper(); |
| 48 | 48 | ||
| 49 | void Init(ASTNode first, ASTNode parent); | 49 | void Init(ASTNode first, ASTNode parent); |
| 50 | 50 | ||
| @@ -71,74 +71,74 @@ public: | |||
| 71 | 71 | ||
| 72 | class ASTProgram { | 72 | class ASTProgram { |
| 73 | public: | 73 | public: |
| 74 | ASTProgram() : nodes{} {}; | 74 | explicit ASTProgram() = default; |
| 75 | ASTZipper nodes; | 75 | ASTZipper nodes{}; |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | class ASTIfThen { | 78 | class ASTIfThen { |
| 79 | public: | 79 | public: |
| 80 | ASTIfThen(Expr condition) : condition(condition), nodes{} {} | 80 | explicit ASTIfThen(Expr condition) : condition(condition) {} |
| 81 | Expr condition; | 81 | Expr condition; |
| 82 | ASTZipper nodes; | 82 | ASTZipper nodes{}; |
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | class ASTIfElse { | 85 | class ASTIfElse { |
| 86 | public: | 86 | public: |
| 87 | ASTIfElse() : nodes{} {} | 87 | explicit ASTIfElse() = default; |
| 88 | ASTZipper nodes; | 88 | ASTZipper nodes{}; |
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| 91 | class ASTBlockEncoded { | 91 | class ASTBlockEncoded { |
| 92 | public: | 92 | public: |
| 93 | ASTBlockEncoded(u32 start, u32 end) : start{start}, end{end} {} | 93 | explicit ASTBlockEncoded(u32 start, u32 end) : start{start}, end{end} {} |
| 94 | u32 start; | 94 | u32 start; |
| 95 | u32 end; | 95 | u32 end; |
| 96 | }; | 96 | }; |
| 97 | 97 | ||
| 98 | class ASTBlockDecoded { | 98 | class ASTBlockDecoded { |
| 99 | public: | 99 | public: |
| 100 | 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 | ||
| 104 | class ASTVarSet { | 104 | class ASTVarSet { |
| 105 | public: | 105 | public: |
| 106 | ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {} | 106 | explicit ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {} |
| 107 | u32 index; | 107 | u32 index; |
| 108 | Expr condition; | 108 | Expr condition; |
| 109 | }; | 109 | }; |
| 110 | 110 | ||
| 111 | class ASTLabel { | 111 | class ASTLabel { |
| 112 | public: | 112 | public: |
| 113 | ASTLabel(u32 index) : index{index} {} | 113 | explicit ASTLabel(u32 index) : index{index} {} |
| 114 | u32 index; | 114 | u32 index; |
| 115 | bool unused{}; | 115 | bool unused{}; |
| 116 | }; | 116 | }; |
| 117 | 117 | ||
| 118 | class ASTGoto { | 118 | class ASTGoto { |
| 119 | public: | 119 | public: |
| 120 | ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {} | 120 | explicit ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {} |
| 121 | Expr condition; | 121 | Expr condition; |
| 122 | u32 label; | 122 | u32 label; |
| 123 | }; | 123 | }; |
| 124 | 124 | ||
| 125 | class ASTDoWhile { | 125 | class ASTDoWhile { |
| 126 | public: | 126 | public: |
| 127 | ASTDoWhile(Expr condition) : condition(condition), nodes{} {} | 127 | explicit ASTDoWhile(Expr condition) : condition(condition) {} |
| 128 | Expr condition; | 128 | Expr condition; |
| 129 | ASTZipper nodes; | 129 | ASTZipper nodes{}; |
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| 132 | class ASTReturn { | 132 | class ASTReturn { |
| 133 | public: | 133 | public: |
| 134 | ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {} | 134 | explicit ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {} |
| 135 | Expr condition; | 135 | Expr condition; |
| 136 | bool kills; | 136 | bool kills; |
| 137 | }; | 137 | }; |
| 138 | 138 | ||
| 139 | class ASTBreak { | 139 | class ASTBreak { |
| 140 | public: | 140 | public: |
| 141 | ASTBreak(Expr condition) : condition{condition} {} | 141 | explicit ASTBreak(Expr condition) : condition{condition} {} |
| 142 | Expr condition; | 142 | Expr condition; |
| 143 | }; | 143 | }; |
| 144 | 144 | ||
| @@ -177,11 +177,11 @@ public: | |||
| 177 | return &data; | 177 | return &data; |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | ASTNode GetNext() { | 180 | ASTNode GetNext() const { |
| 181 | return next; | 181 | return next; |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | ASTNode GetPrevious() { | 184 | ASTNode GetPrevious() const { |
| 185 | return previous; | 185 | return previous; |
| 186 | } | 186 | } |
| 187 | 187 | ||
| @@ -189,12 +189,12 @@ public: | |||
| 189 | return *manager; | 189 | return *manager; |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | u32 GetGotoLabel() const { | 192 | std::optional<u32> GetGotoLabel() const { |
| 193 | auto inner = std::get_if<ASTGoto>(&data); | 193 | auto inner = std::get_if<ASTGoto>(&data); |
| 194 | if (inner) { | 194 | if (inner) { |
| 195 | return inner->label; | 195 | return {inner->label}; |
| 196 | } | 196 | } |
| 197 | return -1; | 197 | return {}; |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | Expr GetGotoCondition() const { | 200 | Expr GetGotoCondition() const { |
| @@ -220,12 +220,12 @@ public: | |||
| 220 | return true; | 220 | return true; |
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | u32 GetLabelIndex() const { | 223 | std::optional<u32> GetLabelIndex() const { |
| 224 | auto inner = std::get_if<ASTLabel>(&data); | 224 | auto inner = std::get_if<ASTLabel>(&data); |
| 225 | if (inner) { | 225 | if (inner) { |
| 226 | return inner->index; | 226 | return {inner->index}; |
| 227 | } | 227 | } |
| 228 | return -1; | 228 | return {}; |
| 229 | } | 229 | } |
| 230 | 230 | ||
| 231 | Expr GetIfCondition() const { | 231 | Expr GetIfCondition() const { |
| @@ -290,7 +290,7 @@ private: | |||
| 290 | friend class ASTZipper; | 290 | friend class ASTZipper; |
| 291 | 291 | ||
| 292 | ASTData data; | 292 | ASTData data; |
| 293 | ASTNode parent; | 293 | ASTNode parent{}; |
| 294 | ASTNode next{}; | 294 | ASTNode next{}; |
| 295 | ASTNode previous{}; | 295 | ASTNode previous{}; |
| 296 | ASTZipper* manager{}; | 296 | ASTZipper* manager{}; |
| @@ -327,13 +327,18 @@ public: | |||
| 327 | 327 | ||
| 328 | void SanityCheck(); | 328 | void SanityCheck(); |
| 329 | 329 | ||
| 330 | void Clear(); | ||
| 331 | |||
| 330 | bool IsFullyDecompiled() const { | 332 | bool IsFullyDecompiled() const { |
| 331 | if (full_decompile) { | 333 | if (full_decompile) { |
| 332 | return gotos.size() == 0; | 334 | return gotos.size() == 0; |
| 333 | } else { | 335 | } else { |
| 334 | for (ASTNode goto_node : gotos) { | 336 | for (ASTNode goto_node : gotos) { |
| 335 | u32 label_index = goto_node->GetGotoLabel(); | 337 | auto label_index = goto_node->GetGotoLabel(); |
| 336 | ASTNode glabel = labels[label_index]; | 338 | if (!label_index) { |
| 339 | return false; | ||
| 340 | } | ||
| 341 | ASTNode glabel = labels[*label_index]; | ||
| 337 | if (IsBackwardsJump(goto_node, glabel)) { | 342 | if (IsBackwardsJump(goto_node, glabel)) { |
| 338 | return false; | 343 | return false; |
| 339 | } | 344 | } |
| @@ -346,8 +351,6 @@ public: | |||
| 346 | return main_node; | 351 | return main_node; |
| 347 | } | 352 | } |
| 348 | 353 | ||
| 349 | void Clear(); | ||
| 350 | |||
| 351 | u32 GetVariables() const { | 354 | u32 GetVariables() const { |
| 352 | return variables; | 355 | return variables; |
| 353 | } | 356 | } |
| @@ -372,9 +375,7 @@ private: | |||
| 372 | void MoveOutward(ASTNode goto_node); | 375 | void MoveOutward(ASTNode goto_node); |
| 373 | 376 | ||
| 374 | u32 NewVariable() { | 377 | u32 NewVariable() { |
| 375 | u32 new_var = variables; | 378 | return variables++; |
| 376 | variables++; | ||
| 377 | return new_var; | ||
| 378 | } | 379 | } |
| 379 | 380 | ||
| 380 | bool full_decompile{}; | 381 | bool full_decompile{}; |
diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h index 60598977a..4c399cef9 100644 --- a/src/video_core/shader/expr.h +++ b/src/video_core/shader/expr.h | |||
| @@ -28,7 +28,7 @@ using Expr = std::shared_ptr<ExprData>; | |||
| 28 | 28 | ||
| 29 | class ExprAnd final { | 29 | class ExprAnd final { |
| 30 | public: | 30 | public: |
| 31 | ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} | 31 | explicit ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} |
| 32 | 32 | ||
| 33 | bool operator==(const ExprAnd& b) const; | 33 | bool operator==(const ExprAnd& b) const; |
| 34 | 34 | ||
| @@ -38,7 +38,7 @@ public: | |||
| 38 | 38 | ||
| 39 | class ExprOr final { | 39 | class ExprOr final { |
| 40 | public: | 40 | public: |
| 41 | ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} | 41 | explicit ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} |
| 42 | 42 | ||
| 43 | bool operator==(const ExprOr& b) const; | 43 | bool operator==(const ExprOr& b) const; |
| 44 | 44 | ||
| @@ -48,7 +48,7 @@ public: | |||
| 48 | 48 | ||
| 49 | class ExprNot final { | 49 | class ExprNot final { |
| 50 | public: | 50 | public: |
| 51 | ExprNot(Expr a) : operand1{a} {} | 51 | explicit ExprNot(Expr a) : operand1{a} {} |
| 52 | 52 | ||
| 53 | bool operator==(const ExprNot& b) const; | 53 | bool operator==(const ExprNot& b) const; |
| 54 | 54 | ||
| @@ -57,7 +57,7 @@ public: | |||
| 57 | 57 | ||
| 58 | class ExprVar final { | 58 | class ExprVar final { |
| 59 | public: | 59 | public: |
| 60 | ExprVar(u32 index) : var_index{index} {} | 60 | explicit ExprVar(u32 index) : var_index{index} {} |
| 61 | 61 | ||
| 62 | bool operator==(const ExprVar& b) const { | 62 | bool operator==(const ExprVar& b) const { |
| 63 | return var_index == b.var_index; | 63 | return var_index == b.var_index; |
| @@ -68,7 +68,7 @@ public: | |||
| 68 | 68 | ||
| 69 | class ExprPredicate final { | 69 | class ExprPredicate final { |
| 70 | public: | 70 | public: |
| 71 | ExprPredicate(u32 predicate) : predicate{predicate} {} | 71 | explicit ExprPredicate(u32 predicate) : predicate{predicate} {} |
| 72 | 72 | ||
| 73 | bool operator==(const ExprPredicate& b) const { | 73 | bool operator==(const ExprPredicate& b) const { |
| 74 | return predicate == b.predicate; | 74 | return predicate == b.predicate; |
| @@ -79,7 +79,7 @@ public: | |||
| 79 | 79 | ||
| 80 | class ExprCondCode final { | 80 | class ExprCondCode final { |
| 81 | public: | 81 | public: |
| 82 | ExprCondCode(ConditionCode cc) : cc{cc} {} | 82 | explicit ExprCondCode(ConditionCode cc) : cc{cc} {} |
| 83 | 83 | ||
| 84 | bool operator==(const ExprCondCode& b) const { | 84 | bool operator==(const ExprCondCode& b) const { |
| 85 | return cc == b.cc; | 85 | return cc == b.cc; |
| @@ -90,7 +90,7 @@ public: | |||
| 90 | 90 | ||
| 91 | class ExprBoolean final { | 91 | class ExprBoolean final { |
| 92 | public: | 92 | public: |
| 93 | ExprBoolean(bool val) : value{val} {} | 93 | explicit ExprBoolean(bool val) : value{val} {} |
| 94 | 94 | ||
| 95 | bool operator==(const ExprBoolean& b) const { | 95 | bool operator==(const ExprBoolean& b) const { |
| 96 | return value == b.value; | 96 | return value == b.value; |