From c17953978b16f82a3b2049f8b961275020c73dd0 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Thu, 27 Jun 2019 00:39:40 -0400 Subject: shader_ir: Initial Decompile Setup --- src/video_core/shader/expr.h | 86 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/video_core/shader/expr.h (limited to 'src/video_core/shader/expr.h') diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h new file mode 100644 index 000000000..94678f09a --- /dev/null +++ b/src/video_core/shader/expr.h @@ -0,0 +1,86 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#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; +using Expr = std::shared_ptr; + +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 +Expr MakeExpr(Args&&... args) { + static_assert(std::is_convertible_v); + return std::make_shared(T(std::forward(args)...)); +} + +} // namespace VideoCommon::Shader -- cgit v1.2.3 From 8be6e1c5221066a49b6ad27efbd20a999a7c16b3 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Fri, 28 Jun 2019 20:54:21 -0400 Subject: shader_ir: Corrections to outward movements and misc stuffs --- src/video_core/shader/expr.h | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/video_core/shader/expr.h') diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h index 94678f09a..f012f6fcf 100644 --- a/src/video_core/shader/expr.h +++ b/src/video_core/shader/expr.h @@ -30,6 +30,8 @@ class ExprAnd final { public: ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} + bool operator==(const ExprAnd& b) const; + Expr operand1; Expr operand2; }; @@ -38,6 +40,8 @@ class ExprOr final { public: ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} + bool operator==(const ExprOr& b) const; + Expr operand1; Expr operand2; }; @@ -46,6 +50,8 @@ class ExprNot final { public: ExprNot(Expr a) : operand1{a} {} + bool operator==(const ExprNot& b) const; + Expr operand1; }; @@ -53,20 +59,32 @@ class ExprVar final { public: ExprVar(u32 index) : var_index{index} {} + bool operator==(const ExprVar& b) const { + return var_index == b.var_index; + } + u32 var_index; }; class ExprPredicate final { public: - ExprPredicate(Pred predicate) : predicate{predicate} {} + ExprPredicate(u32 predicate) : predicate{predicate} {} + + bool operator==(const ExprPredicate& b) const { + return predicate == b.predicate; + } - Pred predicate; + u32 predicate; }; class ExprCondCode final { public: ExprCondCode(ConditionCode cc) : cc{cc} {} + bool operator==(const ExprCondCode& b) const { + return cc == b.cc; + } + ConditionCode cc; }; @@ -74,6 +92,10 @@ class ExprBoolean final { public: ExprBoolean(bool val) : value{val} {} + bool operator==(const ExprBoolean& b) const { + return value == b.value; + } + bool value; }; @@ -83,4 +105,14 @@ Expr MakeExpr(Args&&... args) { return std::make_shared(T(std::forward(args)...)); } +bool ExprAreEqual(Expr first, Expr second); + +bool ExprAreOpposite(Expr first, Expr second); + +Expr MakeExprNot(Expr first); + +Expr MakeExprAnd(Expr first, Expr second); + +Expr MakeExprOr(Expr first, Expr second); + } // namespace VideoCommon::Shader -- cgit v1.2.3 From 38fc995f6cc2c2af29abc976ddb45b72873b2cc4 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 29 Jun 2019 01:44:07 -0400 Subject: gl_shader_decompiler: Implement AST decompiling --- src/video_core/shader/expr.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/video_core/shader/expr.h') diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h index f012f6fcf..b954cffb0 100644 --- a/src/video_core/shader/expr.h +++ b/src/video_core/shader/expr.h @@ -115,4 +115,6 @@ Expr MakeExprAnd(Expr first, Expr second); Expr MakeExprOr(Expr first, Expr second); +bool ExprIsTrue(Expr first); + } // namespace VideoCommon::Shader -- cgit v1.2.3 From b3c46d694846c8ea4fbdcfccda8a41a9f88622f9 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 21 Sep 2019 13:07:02 -0400 Subject: Shader_IR: corrections and clang-format --- src/video_core/shader/expr.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/video_core/shader/expr.h') diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h index b954cffb0..60598977a 100644 --- a/src/video_core/shader/expr.h +++ b/src/video_core/shader/expr.h @@ -4,8 +4,8 @@ #pragma once -#include #include +#include #include "video_core/engines/shader_bytecode.h" -- cgit v1.2.3 From 3c09d9abe6d268ada063fd67c08d09fc0fcad613 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 28 Sep 2019 15:16:19 -0400 Subject: Shader_Ir: Address Feedback and clang format. --- src/video_core/shader/expr.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/video_core/shader/expr.h') diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h index 60598977a..4c399cef9 100644 --- a/src/video_core/shader/expr.h +++ b/src/video_core/shader/expr.h @@ -28,7 +28,7 @@ using Expr = std::shared_ptr; class ExprAnd final { public: - ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} + explicit ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} bool operator==(const ExprAnd& b) const; @@ -38,7 +38,7 @@ public: class ExprOr final { public: - ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} + explicit ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} bool operator==(const ExprOr& b) const; @@ -48,7 +48,7 @@ public: class ExprNot final { public: - ExprNot(Expr a) : operand1{a} {} + explicit ExprNot(Expr a) : operand1{a} {} bool operator==(const ExprNot& b) const; @@ -57,7 +57,7 @@ public: class ExprVar final { public: - ExprVar(u32 index) : var_index{index} {} + explicit ExprVar(u32 index) : var_index{index} {} bool operator==(const ExprVar& b) const { return var_index == b.var_index; @@ -68,7 +68,7 @@ public: class ExprPredicate final { public: - ExprPredicate(u32 predicate) : predicate{predicate} {} + explicit ExprPredicate(u32 predicate) : predicate{predicate} {} bool operator==(const ExprPredicate& b) const { return predicate == b.predicate; @@ -79,7 +79,7 @@ public: class ExprCondCode final { public: - ExprCondCode(ConditionCode cc) : cc{cc} {} + explicit ExprCondCode(ConditionCode cc) : cc{cc} {} bool operator==(const ExprCondCode& b) const { return cc == b.cc; @@ -90,7 +90,7 @@ public: class ExprBoolean final { public: - ExprBoolean(bool val) : value{val} {} + explicit ExprBoolean(bool val) : value{val} {} bool operator==(const ExprBoolean& b) const { return value == b.value; -- cgit v1.2.3