summaryrefslogtreecommitdiffstats
path: root/src/video_core/shader/expr.h
blob: 94678f09a262d8c0ab1189ad87bf83c16d6b6a06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.

#pragma once

#include <variant>
#include <memory>

#include "video_core/engines/shader_bytecode.h"

namespace VideoCommon::Shader {

using Tegra::Shader::ConditionCode;
using Tegra::Shader::Pred;

class ExprAnd;
class ExprOr;
class ExprNot;
class ExprPredicate;
class ExprCondCode;
class ExprVar;
class ExprBoolean;

using ExprData =
    std::variant<ExprVar, ExprCondCode, ExprPredicate, ExprNot, ExprOr, ExprAnd, ExprBoolean>;
using Expr = std::shared_ptr<ExprData>;

class ExprAnd final {
public:
    ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {}

    Expr operand1;
    Expr operand2;
};

class ExprOr final {
public:
    ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {}

    Expr operand1;
    Expr operand2;
};

class ExprNot final {
public:
    ExprNot(Expr a) : operand1{a} {}

    Expr operand1;
};

class ExprVar final {
public:
    ExprVar(u32 index) : var_index{index} {}

    u32 var_index;
};

class ExprPredicate final {
public:
    ExprPredicate(Pred predicate) : predicate{predicate} {}

    Pred predicate;
};

class ExprCondCode final {
public:
    ExprCondCode(ConditionCode cc) : cc{cc} {}

    ConditionCode cc;
};

class ExprBoolean final {
public:
    ExprBoolean(bool val) : value{val} {}

    bool value;
};

template <typename T, typename... Args>
Expr MakeExpr(Args&&... args) {
    static_assert(std::is_convertible_v<T, ExprData>);
    return std::make_shared<ExprData>(T(std::forward<Args>(args)...));
}

} // namespace VideoCommon::Shader