diff options
author | Fernando Sahmkow <fsahmkow27@gmail.com> | 2019-09-28 21:16:19 +0200 |
---|---|---|
committer | FernandoS27 <fsahmkow27@gmail.com> | 2019-10-05 00:52:57 +0200 |
commit | 3c09d9abe6d268ada063fd67c08d09fc0fcad613 (patch) | |
tree | 27f1442ec1ee8390850dd5099ed3642f1d3f59db /src/video_core/shader | |
parent | vk_shader_decompiler: Correct Branches inside conditionals. (diff) | |
download | yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.gz yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.bz2 yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.lz yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.xz yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.zst yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.zip |
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() { auto it = gotos.begin(); while (it != gotos.end()) { const ASTNode goto_node = *it; - const u32 label_index = goto_node->GetGotoLabel(); - const ASTNode label = labels[label_index]; + const auto label_index = goto_node->GetGotoLabel(); + if (!label_index) { + return; + } + const ASTNode label = labels[*label_index]; if (!full_decompile) { // We only decompile backward jumps if (!IsBackwardsJump(goto_node, label)) { @@ -498,8 +501,11 @@ void ASTManager::Decompile() { bool can_remove = true; ASTNode label = *it; for (const ASTNode goto_node : gotos) { - const u32 label_index = goto_node->GetGotoLabel(); - ASTNode glabel = labels[label_index]; + const auto label_index = goto_node->GetGotoLabel(); + if (!label_index) { + return; + } + ASTNode glabel = labels[*label_index]; if (glabel == label) { can_remove = false; 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 { class ASTZipper final { public: - ASTZipper(); + explicit ASTZipper(); void Init(ASTNode first, ASTNode parent); @@ -71,74 +71,74 @@ public: class ASTProgram { public: - ASTProgram() : nodes{} {}; - ASTZipper nodes; + explicit ASTProgram() = default; + ASTZipper nodes{}; }; class ASTIfThen { public: - ASTIfThen(Expr condition) : condition(condition), nodes{} {} + explicit ASTIfThen(Expr condition) : condition(condition) {} Expr condition; - ASTZipper nodes; + ASTZipper nodes{}; }; class ASTIfElse { public: - ASTIfElse() : nodes{} {} - ASTZipper nodes; + explicit ASTIfElse() = default; + ASTZipper nodes{}; }; class ASTBlockEncoded { public: - ASTBlockEncoded(u32 start, u32 end) : start{start}, end{end} {} + explicit ASTBlockEncoded(u32 start, u32 end) : start{start}, end{end} {} u32 start; u32 end; }; class ASTBlockDecoded { public: - ASTBlockDecoded(NodeBlock& new_nodes) : nodes(std::move(new_nodes)) {} + explicit ASTBlockDecoded(NodeBlock& new_nodes) : nodes(std::move(new_nodes)) {} NodeBlock nodes; }; class ASTVarSet { public: - ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {} + explicit ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {} u32 index; Expr condition; }; class ASTLabel { public: - ASTLabel(u32 index) : index{index} {} + explicit ASTLabel(u32 index) : index{index} {} u32 index; bool unused{}; }; class ASTGoto { public: - ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {} + explicit ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {} Expr condition; u32 label; }; class ASTDoWhile { public: - ASTDoWhile(Expr condition) : condition(condition), nodes{} {} + explicit ASTDoWhile(Expr condition) : condition(condition) {} Expr condition; - ASTZipper nodes; + ASTZipper nodes{}; }; class ASTReturn { public: - ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {} + explicit ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {} Expr condition; bool kills; }; class ASTBreak { public: - ASTBreak(Expr condition) : condition{condition} {} + explicit ASTBreak(Expr condition) : condition{condition} {} Expr condition; }; @@ -177,11 +177,11 @@ public: return &data; } - ASTNode GetNext() { + ASTNode GetNext() const { return next; } - ASTNode GetPrevious() { + ASTNode GetPrevious() const { return previous; } @@ -189,12 +189,12 @@ public: return *manager; } - u32 GetGotoLabel() const { + std::optional<u32> GetGotoLabel() const { auto inner = std::get_if<ASTGoto>(&data); if (inner) { - return inner->label; + return {inner->label}; } - return -1; + return {}; } Expr GetGotoCondition() const { @@ -220,12 +220,12 @@ public: return true; } - u32 GetLabelIndex() const { + std::optional<u32> GetLabelIndex() const { auto inner = std::get_if<ASTLabel>(&data); if (inner) { - return inner->index; + return {inner->index}; } - return -1; + return {}; } Expr GetIfCondition() const { @@ -290,7 +290,7 @@ private: friend class ASTZipper; ASTData data; - ASTNode parent; + ASTNode parent{}; ASTNode next{}; ASTNode previous{}; ASTZipper* manager{}; @@ -327,13 +327,18 @@ public: void SanityCheck(); + void Clear(); + bool IsFullyDecompiled() const { if (full_decompile) { return gotos.size() == 0; } else { for (ASTNode goto_node : gotos) { - u32 label_index = goto_node->GetGotoLabel(); - ASTNode glabel = labels[label_index]; + auto label_index = goto_node->GetGotoLabel(); + if (!label_index) { + return false; + } + ASTNode glabel = labels[*label_index]; if (IsBackwardsJump(goto_node, glabel)) { return false; } @@ -346,8 +351,6 @@ public: return main_node; } - void Clear(); - u32 GetVariables() const { return variables; } @@ -372,9 +375,7 @@ private: void MoveOutward(ASTNode goto_node); u32 NewVariable() { - u32 new_var = variables; - variables++; - return new_var; + return variables++; } 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>; class ExprAnd final { public: - ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} + explicit ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} bool operator==(const ExprAnd& b) const; @@ -38,7 +38,7 @@ public: class ExprOr final { public: - ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} + explicit ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} bool operator==(const ExprOr& b) const; @@ -48,7 +48,7 @@ public: class ExprNot final { public: - ExprNot(Expr a) : operand1{a} {} + explicit ExprNot(Expr a) : operand1{a} {} bool operator==(const ExprNot& b) const; @@ -57,7 +57,7 @@ public: class ExprVar final { public: - ExprVar(u32 index) : var_index{index} {} + explicit ExprVar(u32 index) : var_index{index} {} bool operator==(const ExprVar& b) const { return var_index == b.var_index; @@ -68,7 +68,7 @@ public: class ExprPredicate final { public: - ExprPredicate(u32 predicate) : predicate{predicate} {} + explicit ExprPredicate(u32 predicate) : predicate{predicate} {} bool operator==(const ExprPredicate& b) const { return predicate == b.predicate; @@ -79,7 +79,7 @@ public: class ExprCondCode final { public: - ExprCondCode(ConditionCode cc) : cc{cc} {} + explicit ExprCondCode(ConditionCode cc) : cc{cc} {} bool operator==(const ExprCondCode& b) const { return cc == b.cc; @@ -90,7 +90,7 @@ public: class ExprBoolean final { public: - ExprBoolean(bool val) : value{val} {} + explicit ExprBoolean(bool val) : value{val} {} bool operator==(const ExprBoolean& b) const { return value == b.value; |