diff options
| author | 2019-06-28 20:54:21 -0400 | |
|---|---|---|
| committer | 2019-10-04 18:52:48 -0400 | |
| commit | 8be6e1c5221066a49b6ad27efbd20a999a7c16b3 (patch) | |
| tree | a00263eb962503bec08ec4bc870a9546c3b80d22 /src/video_core/shader/expr.cpp | |
| parent | shader_ir: Add basic goto elimination (diff) | |
| download | yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.gz yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.tar.xz yuzu-8be6e1c5221066a49b6ad27efbd20a999a7c16b3.zip | |
shader_ir: Corrections to outward movements and misc stuffs
Diffstat (limited to 'src/video_core/shader/expr.cpp')
| -rw-r--r-- | src/video_core/shader/expr.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/video_core/shader/expr.cpp b/src/video_core/shader/expr.cpp new file mode 100644 index 000000000..ebce6339b --- /dev/null +++ b/src/video_core/shader/expr.cpp | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <variant> | ||
| 9 | |||
| 10 | #include "video_core/shader/expr.h" | ||
| 11 | |||
| 12 | namespace VideoCommon::Shader { | ||
| 13 | |||
| 14 | bool ExprAnd::operator==(const ExprAnd& b) const { | ||
| 15 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); | ||
| 16 | } | ||
| 17 | |||
| 18 | bool ExprOr::operator==(const ExprOr& b) const { | ||
| 19 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); | ||
| 20 | } | ||
| 21 | |||
| 22 | bool ExprNot::operator==(const ExprNot& b) const { | ||
| 23 | return (*operand1 == *b.operand1); | ||
| 24 | } | ||
| 25 | |||
| 26 | bool ExprIsBoolean(Expr expr) { | ||
| 27 | return std::holds_alternative<ExprBoolean>(*expr); | ||
| 28 | } | ||
| 29 | |||
| 30 | bool ExprBooleanGet(Expr expr) { | ||
| 31 | return std::get_if<ExprBoolean>(expr.get())->value; | ||
| 32 | } | ||
| 33 | |||
| 34 | Expr MakeExprNot(Expr first) { | ||
| 35 | if (std::holds_alternative<ExprNot>(*first)) { | ||
| 36 | return std::get_if<ExprNot>(first.get())->operand1; | ||
| 37 | } | ||
| 38 | return MakeExpr<ExprNot>(first); | ||
| 39 | } | ||
| 40 | |||
| 41 | Expr MakeExprAnd(Expr first, Expr second) { | ||
| 42 | if (ExprIsBoolean(first)) { | ||
| 43 | return ExprBooleanGet(first) ? second : first; | ||
| 44 | } | ||
| 45 | if (ExprIsBoolean(second)) { | ||
| 46 | return ExprBooleanGet(second) ? first : second; | ||
| 47 | } | ||
| 48 | return MakeExpr<ExprAnd>(first, second); | ||
| 49 | } | ||
| 50 | |||
| 51 | Expr MakeExprOr(Expr first, Expr second) { | ||
| 52 | if (ExprIsBoolean(first)) { | ||
| 53 | return ExprBooleanGet(first) ? first : second; | ||
| 54 | } | ||
| 55 | if (ExprIsBoolean(second)) { | ||
| 56 | return ExprBooleanGet(second) ? second : first; | ||
| 57 | } | ||
| 58 | return MakeExpr<ExprOr>(first, second); | ||
| 59 | } | ||
| 60 | |||
| 61 | bool ExprAreEqual(Expr first, Expr second) { | ||
| 62 | return (*first) == (*second); | ||
| 63 | } | ||
| 64 | |||
| 65 | bool ExprAreOpposite(Expr first, Expr second) { | ||
| 66 | if (std::holds_alternative<ExprNot>(*first)) { | ||
| 67 | return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second); | ||
| 68 | } | ||
| 69 | if (std::holds_alternative<ExprNot>(*second)) { | ||
| 70 | return ExprAreEqual(std::get_if<ExprNot>(second.get())->operand1, first); | ||
| 71 | } | ||
| 72 | return false; | ||
| 73 | } | ||
| 74 | |||
| 75 | } // namespace VideoCommon::Shader | ||