diff options
Diffstat (limited to 'src/video_core/shader/expr.h')
| -rw-r--r-- | src/video_core/shader/expr.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h new file mode 100644 index 000000000..4c399cef9 --- /dev/null +++ b/src/video_core/shader/expr.h | |||
| @@ -0,0 +1,120 @@ | |||
| 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/engines/shader_bytecode.h" | ||
| 11 | |||
| 12 | namespace VideoCommon::Shader { | ||
| 13 | |||
| 14 | using Tegra::Shader::ConditionCode; | ||
| 15 | using Tegra::Shader::Pred; | ||
| 16 | |||
| 17 | class ExprAnd; | ||
| 18 | class ExprOr; | ||
| 19 | class ExprNot; | ||
| 20 | class ExprPredicate; | ||
| 21 | class ExprCondCode; | ||
| 22 | class ExprVar; | ||
| 23 | class ExprBoolean; | ||
| 24 | |||
| 25 | using ExprData = | ||
| 26 | std::variant<ExprVar, ExprCondCode, ExprPredicate, ExprNot, ExprOr, ExprAnd, ExprBoolean>; | ||
| 27 | using Expr = std::shared_ptr<ExprData>; | ||
| 28 | |||
| 29 | class ExprAnd final { | ||
| 30 | public: | ||
| 31 | explicit ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} | ||
| 32 | |||
| 33 | bool operator==(const ExprAnd& b) const; | ||
| 34 | |||
| 35 | Expr operand1; | ||
| 36 | Expr operand2; | ||
| 37 | }; | ||
| 38 | |||
| 39 | class ExprOr final { | ||
| 40 | public: | ||
| 41 | explicit ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} | ||
| 42 | |||
| 43 | bool operator==(const ExprOr& b) const; | ||
| 44 | |||
| 45 | Expr operand1; | ||
| 46 | Expr operand2; | ||
| 47 | }; | ||
| 48 | |||
| 49 | class ExprNot final { | ||
| 50 | public: | ||
| 51 | explicit ExprNot(Expr a) : operand1{a} {} | ||
| 52 | |||
| 53 | bool operator==(const ExprNot& b) const; | ||
| 54 | |||
| 55 | Expr operand1; | ||
| 56 | }; | ||
| 57 | |||
| 58 | class ExprVar final { | ||
| 59 | public: | ||
| 60 | explicit ExprVar(u32 index) : var_index{index} {} | ||
| 61 | |||
| 62 | bool operator==(const ExprVar& b) const { | ||
| 63 | return var_index == b.var_index; | ||
| 64 | } | ||
| 65 | |||
| 66 | u32 var_index; | ||
| 67 | }; | ||
| 68 | |||
| 69 | class ExprPredicate final { | ||
| 70 | public: | ||
| 71 | explicit ExprPredicate(u32 predicate) : predicate{predicate} {} | ||
| 72 | |||
| 73 | bool operator==(const ExprPredicate& b) const { | ||
| 74 | return predicate == b.predicate; | ||
| 75 | } | ||
| 76 | |||
| 77 | u32 predicate; | ||
| 78 | }; | ||
| 79 | |||
| 80 | class ExprCondCode final { | ||
| 81 | public: | ||
| 82 | explicit ExprCondCode(ConditionCode cc) : cc{cc} {} | ||
| 83 | |||
| 84 | bool operator==(const ExprCondCode& b) const { | ||
| 85 | return cc == b.cc; | ||
| 86 | } | ||
| 87 | |||
| 88 | ConditionCode cc; | ||
| 89 | }; | ||
| 90 | |||
| 91 | class ExprBoolean final { | ||
| 92 | public: | ||
| 93 | explicit ExprBoolean(bool val) : value{val} {} | ||
| 94 | |||
| 95 | bool operator==(const ExprBoolean& b) const { | ||
| 96 | return value == b.value; | ||
| 97 | } | ||
| 98 | |||
| 99 | bool value; | ||
| 100 | }; | ||
| 101 | |||
| 102 | template <typename T, typename... Args> | ||
| 103 | Expr MakeExpr(Args&&... args) { | ||
| 104 | static_assert(std::is_convertible_v<T, ExprData>); | ||
| 105 | return std::make_shared<ExprData>(T(std::forward<Args>(args)...)); | ||
| 106 | } | ||
| 107 | |||
| 108 | bool ExprAreEqual(Expr first, Expr second); | ||
| 109 | |||
| 110 | bool ExprAreOpposite(Expr first, Expr second); | ||
| 111 | |||
| 112 | Expr MakeExprNot(Expr first); | ||
| 113 | |||
| 114 | Expr MakeExprAnd(Expr first, Expr second); | ||
| 115 | |||
| 116 | Expr MakeExprOr(Expr first, Expr second); | ||
| 117 | |||
| 118 | bool ExprIsTrue(Expr first); | ||
| 119 | |||
| 120 | } // namespace VideoCommon::Shader | ||