2019-06-27 00:39:40 -04:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2019-09-21 13:07:02 -04:00
|
|
|
#include <variant>
|
2019-06-27 00:39:40 -04:00
|
|
|
|
|
|
|
#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:
|
2019-10-05 08:17:32 -04:00
|
|
|
explicit ExprAnd(Expr a, Expr b) : operand1{std::move(a)}, operand2{std::move(b)} {}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
bool operator==(const ExprAnd& b) const;
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprAnd& b) const;
|
2019-06-28 20:54:21 -04:00
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
Expr operand1;
|
|
|
|
Expr operand2;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExprOr final {
|
|
|
|
public:
|
2019-10-05 08:17:32 -04:00
|
|
|
explicit ExprOr(Expr a, Expr b) : operand1{std::move(a)}, operand2{std::move(b)} {}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
bool operator==(const ExprOr& b) const;
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprOr& b) const;
|
2019-06-28 20:54:21 -04:00
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
Expr operand1;
|
|
|
|
Expr operand2;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExprNot final {
|
|
|
|
public:
|
2019-10-05 08:17:32 -04:00
|
|
|
explicit ExprNot(Expr a) : operand1{std::move(a)} {}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
bool operator==(const ExprNot& b) const;
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprNot& b) const;
|
2019-06-28 20:54:21 -04:00
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
Expr operand1;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExprVar final {
|
|
|
|
public:
|
2019-09-28 15:16:19 -04:00
|
|
|
explicit ExprVar(u32 index) : var_index{index} {}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
bool operator==(const ExprVar& b) const {
|
|
|
|
return var_index == b.var_index;
|
|
|
|
}
|
|
|
|
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprVar& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
u32 var_index;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExprPredicate final {
|
|
|
|
public:
|
2019-09-28 15:16:19 -04:00
|
|
|
explicit ExprPredicate(u32 predicate) : predicate{predicate} {}
|
2019-06-28 20:54:21 -04:00
|
|
|
|
|
|
|
bool operator==(const ExprPredicate& b) const {
|
|
|
|
return predicate == b.predicate;
|
|
|
|
}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprPredicate& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
u32 predicate;
|
2019-06-27 00:39:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ExprCondCode final {
|
|
|
|
public:
|
2019-09-28 15:16:19 -04:00
|
|
|
explicit ExprCondCode(ConditionCode cc) : cc{cc} {}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
bool operator==(const ExprCondCode& b) const {
|
|
|
|
return cc == b.cc;
|
|
|
|
}
|
|
|
|
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprCondCode& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
ConditionCode cc;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ExprBoolean final {
|
|
|
|
public:
|
2019-09-28 15:16:19 -04:00
|
|
|
explicit ExprBoolean(bool val) : value{val} {}
|
2019-06-27 00:39:40 -04:00
|
|
|
|
2019-06-28 20:54:21 -04:00
|
|
|
bool operator==(const ExprBoolean& b) const {
|
|
|
|
return value == b.value;
|
|
|
|
}
|
|
|
|
|
2019-10-05 08:37:39 -04:00
|
|
|
bool operator!=(const ExprBoolean& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
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)...));
|
|
|
|
}
|
|
|
|
|
2019-10-05 08:17:32 -04:00
|
|
|
bool ExprAreEqual(const Expr& first, const Expr& second);
|
2019-06-28 20:54:21 -04:00
|
|
|
|
2019-10-05 08:17:32 -04:00
|
|
|
bool ExprAreOpposite(const Expr& first, const Expr& second);
|
2019-06-28 20:54:21 -04:00
|
|
|
|
|
|
|
Expr MakeExprNot(Expr first);
|
|
|
|
|
|
|
|
Expr MakeExprAnd(Expr first, Expr second);
|
|
|
|
|
|
|
|
Expr MakeExprOr(Expr first, Expr second);
|
|
|
|
|
2019-10-05 08:17:32 -04:00
|
|
|
bool ExprIsTrue(const Expr& first);
|
2019-06-29 01:44:07 -04:00
|
|
|
|
2019-06-27 00:39:40 -04:00
|
|
|
} // namespace VideoCommon::Shader
|