summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-09-28 15:16:19 -0400
committerGravatar FernandoS272019-10-04 18:52:57 -0400
commit3c09d9abe6d268ada063fd67c08d09fc0fcad613 (patch)
tree27f1442ec1ee8390850dd5099ed3642f1d3f59db /src
parentvk_shader_decompiler: Correct Branches inside conditionals. (diff)
downloadyuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.gz
yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.tar.xz
yuzu-3c09d9abe6d268ada063fd67c08d09fc0fcad613.zip
Shader_Ir: Address Feedback and clang format.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_vulkan/vk_shader_decompiler.cpp43
-rw-r--r--src/video_core/shader/ast.cpp14
-rw-r--r--src/video_core/shader/ast.h65
-rw-r--r--src/video_core/shader/expr.h14
4 files changed, 68 insertions, 68 deletions
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
index 2b55a3727..8bcd04221 100644
--- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
+++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp
@@ -1646,34 +1646,34 @@ private:
1646 1646
1647class ExprDecompiler { 1647class ExprDecompiler {
1648public: 1648public:
1649 ExprDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {} 1649 explicit ExprDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
1650 1650
1651 void operator()(VideoCommon::Shader::ExprAnd& expr) { 1651 Id operator()(VideoCommon::Shader::ExprAnd& expr) {
1652 const Id type_def = decomp.GetTypeDefinition(Type::Bool); 1652 const Id type_def = decomp.GetTypeDefinition(Type::Bool);
1653 const Id op1 = Visit(expr.operand1); 1653 const Id op1 = Visit(expr.operand1);
1654 const Id op2 = Visit(expr.operand2); 1654 const Id op2 = Visit(expr.operand2);
1655 current_id = decomp.Emit(decomp.OpLogicalAnd(type_def, op1, op2)); 1655 return decomp.Emit(decomp.OpLogicalAnd(type_def, op1, op2));
1656 } 1656 }
1657 1657
1658 void operator()(VideoCommon::Shader::ExprOr& expr) { 1658 Id operator()(VideoCommon::Shader::ExprOr& expr) {
1659 const Id type_def = decomp.GetTypeDefinition(Type::Bool); 1659 const Id type_def = decomp.GetTypeDefinition(Type::Bool);
1660 const Id op1 = Visit(expr.operand1); 1660 const Id op1 = Visit(expr.operand1);
1661 const Id op2 = Visit(expr.operand2); 1661 const Id op2 = Visit(expr.operand2);
1662 current_id = decomp.Emit(decomp.OpLogicalOr(type_def, op1, op2)); 1662 return decomp.Emit(decomp.OpLogicalOr(type_def, op1, op2));
1663 } 1663 }
1664 1664
1665 void operator()(VideoCommon::Shader::ExprNot& expr) { 1665 Id operator()(VideoCommon::Shader::ExprNot& expr) {
1666 const Id type_def = decomp.GetTypeDefinition(Type::Bool); 1666 const Id type_def = decomp.GetTypeDefinition(Type::Bool);
1667 const Id op1 = Visit(expr.operand1); 1667 const Id op1 = Visit(expr.operand1);
1668 current_id = decomp.Emit(decomp.OpLogicalNot(type_def, op1)); 1668 return decomp.Emit(decomp.OpLogicalNot(type_def, op1));
1669 } 1669 }
1670 1670
1671 void operator()(VideoCommon::Shader::ExprPredicate& expr) { 1671 Id operator()(VideoCommon::Shader::ExprPredicate& expr) {
1672 const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate); 1672 const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate);
1673 current_id = decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.predicates.at(pred))); 1673 return decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.predicates.at(pred)));
1674 } 1674 }
1675 1675
1676 void operator()(VideoCommon::Shader::ExprCondCode& expr) { 1676 Id operator()(VideoCommon::Shader::ExprCondCode& expr) {
1677 const Node cc = decomp.ir.GetConditionCode(expr.cc); 1677 const Node cc = decomp.ir.GetConditionCode(expr.cc);
1678 Id target; 1678 Id target;
1679 1679
@@ -1690,35 +1690,28 @@ public:
1690 } else if (const auto flag = std::get_if<InternalFlagNode>(&*cc)) { 1690 } else if (const auto flag = std::get_if<InternalFlagNode>(&*cc)) {
1691 target = decomp.internal_flags.at(static_cast<u32>(flag->GetFlag())); 1691 target = decomp.internal_flags.at(static_cast<u32>(flag->GetFlag()));
1692 } 1692 }
1693 current_id = decomp.Emit(decomp.OpLoad(decomp.t_bool, target)); 1693 return decomp.Emit(decomp.OpLoad(decomp.t_bool, target));
1694 } 1694 }
1695 1695
1696 void operator()(VideoCommon::Shader::ExprVar& expr) { 1696 Id operator()(VideoCommon::Shader::ExprVar& expr) {
1697 current_id = 1697 return decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
1698 decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
1699 } 1698 }
1700 1699
1701 void operator()(VideoCommon::Shader::ExprBoolean& expr) { 1700 Id operator()(VideoCommon::Shader::ExprBoolean& expr) {
1702 current_id = expr.value ? decomp.v_true : decomp.v_false; 1701 return expr.value ? decomp.v_true : decomp.v_false;
1703 }
1704
1705 Id GetResult() {
1706 return current_id;
1707 } 1702 }
1708 1703
1709 Id Visit(VideoCommon::Shader::Expr& node) { 1704 Id Visit(VideoCommon::Shader::Expr& node) {
1710 std::visit(*this, *node); 1705 return std::visit(*this, *node);
1711 return current_id;
1712 } 1706 }
1713 1707
1714private: 1708private:
1715 Id current_id;
1716 SPIRVDecompiler& decomp; 1709 SPIRVDecompiler& decomp;
1717}; 1710};
1718 1711
1719class ASTDecompiler { 1712class ASTDecompiler {
1720public: 1713public:
1721 ASTDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {} 1714 explicit ASTDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
1722 1715
1723 void operator()(VideoCommon::Shader::ASTProgram& ast) { 1716 void operator()(VideoCommon::Shader::ASTProgram& ast) {
1724 ASTNode current = ast.nodes.GetFirst(); 1717 ASTNode current = ast.nodes.GetFirst();
@@ -1850,7 +1843,7 @@ public:
1850 1843
1851private: 1844private:
1852 SPIRVDecompiler& decomp; 1845 SPIRVDecompiler& decomp;
1853 Id current_loop_exit; 1846 Id current_loop_exit{};
1854}; 1847};
1855 1848
1856void SPIRVDecompiler::DecompileAST() { 1849void SPIRVDecompiler::DecompileAST() {
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
45class ASTZipper final { 45class ASTZipper final {
46public: 46public:
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
72class ASTProgram { 72class ASTProgram {
73public: 73public:
74 ASTProgram() : nodes{} {}; 74 explicit ASTProgram() = default;
75 ASTZipper nodes; 75 ASTZipper nodes{};
76}; 76};
77 77
78class ASTIfThen { 78class ASTIfThen {
79public: 79public:
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
85class ASTIfElse { 85class ASTIfElse {
86public: 86public:
87 ASTIfElse() : nodes{} {} 87 explicit ASTIfElse() = default;
88 ASTZipper nodes; 88 ASTZipper nodes{};
89}; 89};
90 90
91class ASTBlockEncoded { 91class ASTBlockEncoded {
92public: 92public:
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
98class ASTBlockDecoded { 98class ASTBlockDecoded {
99public: 99public:
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
104class ASTVarSet { 104class ASTVarSet {
105public: 105public:
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
111class ASTLabel { 111class ASTLabel {
112public: 112public:
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
118class ASTGoto { 118class ASTGoto {
119public: 119public:
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
125class ASTDoWhile { 125class ASTDoWhile {
126public: 126public:
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
132class ASTReturn { 132class ASTReturn {
133public: 133public:
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
139class ASTBreak { 139class ASTBreak {
140public: 140public:
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
29class ExprAnd final { 29class ExprAnd final {
30public: 30public:
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
39class ExprOr final { 39class ExprOr final {
40public: 40public:
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
49class ExprNot final { 49class ExprNot final {
50public: 50public:
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
58class ExprVar final { 58class ExprVar final {
59public: 59public:
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
69class ExprPredicate final { 69class ExprPredicate final {
70public: 70public:
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
80class ExprCondCode final { 80class ExprCondCode final {
81public: 81public:
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
91class ExprBoolean final { 91class ExprBoolean final {
92public: 92public:
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;