2019-06-29 03:54:21 +03:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <variant>
|
|
|
|
|
|
|
|
#include "video_core/shader/expr.h"
|
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
2019-10-05 15:17:32 +03:00
|
|
|
namespace {
|
|
|
|
bool ExprIsBoolean(const Expr& expr) {
|
|
|
|
return std::holds_alternative<ExprBoolean>(*expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExprBooleanGet(const Expr& expr) {
|
|
|
|
return std::get_if<ExprBoolean>(expr.get())->value;
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
2019-06-29 03:54:21 +03:00
|
|
|
|
|
|
|
bool ExprAnd::operator==(const ExprAnd& b) const {
|
|
|
|
return (*operand1 == *b.operand1) && (*operand2 == *b.operand2);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:37:39 +03:00
|
|
|
bool ExprAnd::operator!=(const ExprAnd& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-06-29 03:54:21 +03:00
|
|
|
bool ExprOr::operator==(const ExprOr& b) const {
|
|
|
|
return (*operand1 == *b.operand1) && (*operand2 == *b.operand2);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:37:39 +03:00
|
|
|
bool ExprOr::operator!=(const ExprOr& b) const {
|
|
|
|
return !operator==(b);
|
|
|
|
}
|
|
|
|
|
2019-06-29 03:54:21 +03:00
|
|
|
bool ExprNot::operator==(const ExprNot& b) const {
|
2019-10-05 15:37:39 +03:00
|
|
|
return *operand1 == *b.operand1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExprNot::operator!=(const ExprNot& b) const {
|
|
|
|
return !operator==(b);
|
2019-06-29 03:54:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr MakeExprNot(Expr first) {
|
|
|
|
if (std::holds_alternative<ExprNot>(*first)) {
|
|
|
|
return std::get_if<ExprNot>(first.get())->operand1;
|
|
|
|
}
|
2019-10-05 15:17:32 +03:00
|
|
|
return MakeExpr<ExprNot>(std::move(first));
|
2019-06-29 03:54:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr MakeExprAnd(Expr first, Expr second) {
|
|
|
|
if (ExprIsBoolean(first)) {
|
|
|
|
return ExprBooleanGet(first) ? second : first;
|
|
|
|
}
|
|
|
|
if (ExprIsBoolean(second)) {
|
|
|
|
return ExprBooleanGet(second) ? first : second;
|
|
|
|
}
|
2019-10-05 15:17:32 +03:00
|
|
|
return MakeExpr<ExprAnd>(std::move(first), std::move(second));
|
2019-06-29 03:54:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Expr MakeExprOr(Expr first, Expr second) {
|
|
|
|
if (ExprIsBoolean(first)) {
|
|
|
|
return ExprBooleanGet(first) ? first : second;
|
|
|
|
}
|
|
|
|
if (ExprIsBoolean(second)) {
|
|
|
|
return ExprBooleanGet(second) ? second : first;
|
|
|
|
}
|
2019-10-05 15:17:32 +03:00
|
|
|
return MakeExpr<ExprOr>(std::move(first), std::move(second));
|
2019-06-29 03:54:21 +03:00
|
|
|
}
|
|
|
|
|
2019-10-05 15:17:32 +03:00
|
|
|
bool ExprAreEqual(const Expr& first, const Expr& second) {
|
2019-06-29 03:54:21 +03:00
|
|
|
return (*first) == (*second);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:17:32 +03:00
|
|
|
bool ExprAreOpposite(const Expr& first, const Expr& second) {
|
2019-06-29 03:54:21 +03:00
|
|
|
if (std::holds_alternative<ExprNot>(*first)) {
|
|
|
|
return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second);
|
|
|
|
}
|
|
|
|
if (std::holds_alternative<ExprNot>(*second)) {
|
|
|
|
return ExprAreEqual(std::get_if<ExprNot>(second.get())->operand1, first);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:17:32 +03:00
|
|
|
bool ExprIsTrue(const Expr& first) {
|
2019-06-29 08:44:07 +03:00
|
|
|
if (ExprIsBoolean(first)) {
|
|
|
|
return ExprBooleanGet(first);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-29 03:54:21 +03:00
|
|
|
} // namespace VideoCommon::Shader
|