Shader_Ir: Address Feedback and clang format.
This commit is contained in:
parent
507a9c6a40
commit
3c09d9abe6
4 changed files with 68 additions and 68 deletions
|
@ -1646,34 +1646,34 @@ private:
|
||||||
|
|
||||||
class ExprDecompiler {
|
class ExprDecompiler {
|
||||||
public:
|
public:
|
||||||
ExprDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
|
explicit ExprDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprAnd& expr) {
|
Id operator()(VideoCommon::Shader::ExprAnd& expr) {
|
||||||
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
||||||
const Id op1 = Visit(expr.operand1);
|
const Id op1 = Visit(expr.operand1);
|
||||||
const Id op2 = Visit(expr.operand2);
|
const Id op2 = Visit(expr.operand2);
|
||||||
current_id = decomp.Emit(decomp.OpLogicalAnd(type_def, op1, op2));
|
return decomp.Emit(decomp.OpLogicalAnd(type_def, op1, op2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprOr& expr) {
|
Id operator()(VideoCommon::Shader::ExprOr& expr) {
|
||||||
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
||||||
const Id op1 = Visit(expr.operand1);
|
const Id op1 = Visit(expr.operand1);
|
||||||
const Id op2 = Visit(expr.operand2);
|
const Id op2 = Visit(expr.operand2);
|
||||||
current_id = decomp.Emit(decomp.OpLogicalOr(type_def, op1, op2));
|
return decomp.Emit(decomp.OpLogicalOr(type_def, op1, op2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprNot& expr) {
|
Id operator()(VideoCommon::Shader::ExprNot& expr) {
|
||||||
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
const Id type_def = decomp.GetTypeDefinition(Type::Bool);
|
||||||
const Id op1 = Visit(expr.operand1);
|
const Id op1 = Visit(expr.operand1);
|
||||||
current_id = decomp.Emit(decomp.OpLogicalNot(type_def, op1));
|
return decomp.Emit(decomp.OpLogicalNot(type_def, op1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprPredicate& expr) {
|
Id operator()(VideoCommon::Shader::ExprPredicate& expr) {
|
||||||
const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate);
|
const auto pred = static_cast<Tegra::Shader::Pred>(expr.predicate);
|
||||||
current_id = decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.predicates.at(pred)));
|
return decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.predicates.at(pred)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprCondCode& expr) {
|
Id operator()(VideoCommon::Shader::ExprCondCode& expr) {
|
||||||
const Node cc = decomp.ir.GetConditionCode(expr.cc);
|
const Node cc = decomp.ir.GetConditionCode(expr.cc);
|
||||||
Id target;
|
Id target;
|
||||||
|
|
||||||
|
@ -1690,35 +1690,28 @@ public:
|
||||||
} else if (const auto flag = std::get_if<InternalFlagNode>(&*cc)) {
|
} else if (const auto flag = std::get_if<InternalFlagNode>(&*cc)) {
|
||||||
target = decomp.internal_flags.at(static_cast<u32>(flag->GetFlag()));
|
target = decomp.internal_flags.at(static_cast<u32>(flag->GetFlag()));
|
||||||
}
|
}
|
||||||
current_id = decomp.Emit(decomp.OpLoad(decomp.t_bool, target));
|
return decomp.Emit(decomp.OpLoad(decomp.t_bool, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprVar& expr) {
|
Id operator()(VideoCommon::Shader::ExprVar& expr) {
|
||||||
current_id =
|
return decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
|
||||||
decomp.Emit(decomp.OpLoad(decomp.t_bool, decomp.flow_variables.at(expr.var_index)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ExprBoolean& expr) {
|
Id operator()(VideoCommon::Shader::ExprBoolean& expr) {
|
||||||
current_id = expr.value ? decomp.v_true : decomp.v_false;
|
return expr.value ? decomp.v_true : decomp.v_false;
|
||||||
}
|
|
||||||
|
|
||||||
Id GetResult() {
|
|
||||||
return current_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Id Visit(VideoCommon::Shader::Expr& node) {
|
Id Visit(VideoCommon::Shader::Expr& node) {
|
||||||
std::visit(*this, *node);
|
return std::visit(*this, *node);
|
||||||
return current_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Id current_id;
|
|
||||||
SPIRVDecompiler& decomp;
|
SPIRVDecompiler& decomp;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTDecompiler {
|
class ASTDecompiler {
|
||||||
public:
|
public:
|
||||||
ASTDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
|
explicit ASTDecompiler(SPIRVDecompiler& decomp) : decomp{decomp} {}
|
||||||
|
|
||||||
void operator()(VideoCommon::Shader::ASTProgram& ast) {
|
void operator()(VideoCommon::Shader::ASTProgram& ast) {
|
||||||
ASTNode current = ast.nodes.GetFirst();
|
ASTNode current = ast.nodes.GetFirst();
|
||||||
|
@ -1850,7 +1843,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SPIRVDecompiler& decomp;
|
SPIRVDecompiler& decomp;
|
||||||
Id current_loop_exit;
|
Id current_loop_exit{};
|
||||||
};
|
};
|
||||||
|
|
||||||
void SPIRVDecompiler::DecompileAST() {
|
void SPIRVDecompiler::DecompileAST() {
|
||||||
|
|
|
@ -442,8 +442,11 @@ void ASTManager::Decompile() {
|
||||||
auto it = gotos.begin();
|
auto it = gotos.begin();
|
||||||
while (it != gotos.end()) {
|
while (it != gotos.end()) {
|
||||||
const ASTNode goto_node = *it;
|
const ASTNode goto_node = *it;
|
||||||
const u32 label_index = goto_node->GetGotoLabel();
|
const auto label_index = goto_node->GetGotoLabel();
|
||||||
const ASTNode label = labels[label_index];
|
if (!label_index) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ASTNode label = labels[*label_index];
|
||||||
if (!full_decompile) {
|
if (!full_decompile) {
|
||||||
// We only decompile backward jumps
|
// We only decompile backward jumps
|
||||||
if (!IsBackwardsJump(goto_node, label)) {
|
if (!IsBackwardsJump(goto_node, label)) {
|
||||||
|
@ -498,8 +501,11 @@ void ASTManager::Decompile() {
|
||||||
bool can_remove = true;
|
bool can_remove = true;
|
||||||
ASTNode label = *it;
|
ASTNode label = *it;
|
||||||
for (const ASTNode goto_node : gotos) {
|
for (const ASTNode goto_node : gotos) {
|
||||||
const u32 label_index = goto_node->GetGotoLabel();
|
const auto label_index = goto_node->GetGotoLabel();
|
||||||
ASTNode glabel = labels[label_index];
|
if (!label_index) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ASTNode glabel = labels[*label_index];
|
||||||
if (glabel == label) {
|
if (glabel == label) {
|
||||||
can_remove = false;
|
can_remove = false;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -44,7 +44,7 @@ enum class ASTZipperType : u32 {
|
||||||
|
|
||||||
class ASTZipper final {
|
class ASTZipper final {
|
||||||
public:
|
public:
|
||||||
ASTZipper();
|
explicit ASTZipper();
|
||||||
|
|
||||||
void Init(ASTNode first, ASTNode parent);
|
void Init(ASTNode first, ASTNode parent);
|
||||||
|
|
||||||
|
@ -71,74 +71,74 @@ public:
|
||||||
|
|
||||||
class ASTProgram {
|
class ASTProgram {
|
||||||
public:
|
public:
|
||||||
ASTProgram() : nodes{} {};
|
explicit ASTProgram() = default;
|
||||||
ASTZipper nodes;
|
ASTZipper nodes{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTIfThen {
|
class ASTIfThen {
|
||||||
public:
|
public:
|
||||||
ASTIfThen(Expr condition) : condition(condition), nodes{} {}
|
explicit ASTIfThen(Expr condition) : condition(condition) {}
|
||||||
Expr condition;
|
Expr condition;
|
||||||
ASTZipper nodes;
|
ASTZipper nodes{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTIfElse {
|
class ASTIfElse {
|
||||||
public:
|
public:
|
||||||
ASTIfElse() : nodes{} {}
|
explicit ASTIfElse() = default;
|
||||||
ASTZipper nodes;
|
ASTZipper nodes{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTBlockEncoded {
|
class ASTBlockEncoded {
|
||||||
public:
|
public:
|
||||||
ASTBlockEncoded(u32 start, u32 end) : start{start}, end{end} {}
|
explicit ASTBlockEncoded(u32 start, u32 end) : start{start}, end{end} {}
|
||||||
u32 start;
|
u32 start;
|
||||||
u32 end;
|
u32 end;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTBlockDecoded {
|
class ASTBlockDecoded {
|
||||||
public:
|
public:
|
||||||
ASTBlockDecoded(NodeBlock& new_nodes) : nodes(std::move(new_nodes)) {}
|
explicit ASTBlockDecoded(NodeBlock& new_nodes) : nodes(std::move(new_nodes)) {}
|
||||||
NodeBlock nodes;
|
NodeBlock nodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTVarSet {
|
class ASTVarSet {
|
||||||
public:
|
public:
|
||||||
ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {}
|
explicit ASTVarSet(u32 index, Expr condition) : index{index}, condition{condition} {}
|
||||||
u32 index;
|
u32 index;
|
||||||
Expr condition;
|
Expr condition;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTLabel {
|
class ASTLabel {
|
||||||
public:
|
public:
|
||||||
ASTLabel(u32 index) : index{index} {}
|
explicit ASTLabel(u32 index) : index{index} {}
|
||||||
u32 index;
|
u32 index;
|
||||||
bool unused{};
|
bool unused{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTGoto {
|
class ASTGoto {
|
||||||
public:
|
public:
|
||||||
ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {}
|
explicit ASTGoto(Expr condition, u32 label) : condition{condition}, label{label} {}
|
||||||
Expr condition;
|
Expr condition;
|
||||||
u32 label;
|
u32 label;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTDoWhile {
|
class ASTDoWhile {
|
||||||
public:
|
public:
|
||||||
ASTDoWhile(Expr condition) : condition(condition), nodes{} {}
|
explicit ASTDoWhile(Expr condition) : condition(condition) {}
|
||||||
Expr condition;
|
Expr condition;
|
||||||
ASTZipper nodes;
|
ASTZipper nodes{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTReturn {
|
class ASTReturn {
|
||||||
public:
|
public:
|
||||||
ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {}
|
explicit ASTReturn(Expr condition, bool kills) : condition{condition}, kills{kills} {}
|
||||||
Expr condition;
|
Expr condition;
|
||||||
bool kills;
|
bool kills;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ASTBreak {
|
class ASTBreak {
|
||||||
public:
|
public:
|
||||||
ASTBreak(Expr condition) : condition{condition} {}
|
explicit ASTBreak(Expr condition) : condition{condition} {}
|
||||||
Expr condition;
|
Expr condition;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -177,11 +177,11 @@ public:
|
||||||
return &data;
|
return &data;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTNode GetNext() {
|
ASTNode GetNext() const {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASTNode GetPrevious() {
|
ASTNode GetPrevious() const {
|
||||||
return previous;
|
return previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,12 +189,12 @@ public:
|
||||||
return *manager;
|
return *manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetGotoLabel() const {
|
std::optional<u32> GetGotoLabel() const {
|
||||||
auto inner = std::get_if<ASTGoto>(&data);
|
auto inner = std::get_if<ASTGoto>(&data);
|
||||||
if (inner) {
|
if (inner) {
|
||||||
return inner->label;
|
return {inner->label};
|
||||||
}
|
}
|
||||||
return -1;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Expr GetGotoCondition() const {
|
Expr GetGotoCondition() const {
|
||||||
|
@ -220,12 +220,12 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GetLabelIndex() const {
|
std::optional<u32> GetLabelIndex() const {
|
||||||
auto inner = std::get_if<ASTLabel>(&data);
|
auto inner = std::get_if<ASTLabel>(&data);
|
||||||
if (inner) {
|
if (inner) {
|
||||||
return inner->index;
|
return {inner->index};
|
||||||
}
|
}
|
||||||
return -1;
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Expr GetIfCondition() const {
|
Expr GetIfCondition() const {
|
||||||
|
@ -290,7 +290,7 @@ private:
|
||||||
friend class ASTZipper;
|
friend class ASTZipper;
|
||||||
|
|
||||||
ASTData data;
|
ASTData data;
|
||||||
ASTNode parent;
|
ASTNode parent{};
|
||||||
ASTNode next{};
|
ASTNode next{};
|
||||||
ASTNode previous{};
|
ASTNode previous{};
|
||||||
ASTZipper* manager{};
|
ASTZipper* manager{};
|
||||||
|
@ -327,13 +327,18 @@ public:
|
||||||
|
|
||||||
void SanityCheck();
|
void SanityCheck();
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
bool IsFullyDecompiled() const {
|
bool IsFullyDecompiled() const {
|
||||||
if (full_decompile) {
|
if (full_decompile) {
|
||||||
return gotos.size() == 0;
|
return gotos.size() == 0;
|
||||||
} else {
|
} else {
|
||||||
for (ASTNode goto_node : gotos) {
|
for (ASTNode goto_node : gotos) {
|
||||||
u32 label_index = goto_node->GetGotoLabel();
|
auto label_index = goto_node->GetGotoLabel();
|
||||||
ASTNode glabel = labels[label_index];
|
if (!label_index) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
ASTNode glabel = labels[*label_index];
|
||||||
if (IsBackwardsJump(goto_node, glabel)) {
|
if (IsBackwardsJump(goto_node, glabel)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -346,8 +351,6 @@ public:
|
||||||
return main_node;
|
return main_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
u32 GetVariables() const {
|
u32 GetVariables() const {
|
||||||
return variables;
|
return variables;
|
||||||
}
|
}
|
||||||
|
@ -372,9 +375,7 @@ private:
|
||||||
void MoveOutward(ASTNode goto_node);
|
void MoveOutward(ASTNode goto_node);
|
||||||
|
|
||||||
u32 NewVariable() {
|
u32 NewVariable() {
|
||||||
u32 new_var = variables;
|
return variables++;
|
||||||
variables++;
|
|
||||||
return new_var;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool full_decompile{};
|
bool full_decompile{};
|
||||||
|
|
|
@ -28,7 +28,7 @@ using Expr = std::shared_ptr<ExprData>;
|
||||||
|
|
||||||
class ExprAnd final {
|
class ExprAnd final {
|
||||||
public:
|
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;
|
bool operator==(const ExprAnd& b) const;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public:
|
||||||
|
|
||||||
class ExprOr final {
|
class ExprOr final {
|
||||||
public:
|
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;
|
bool operator==(const ExprOr& b) const;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public:
|
||||||
|
|
||||||
class ExprNot final {
|
class ExprNot final {
|
||||||
public:
|
public:
|
||||||
ExprNot(Expr a) : operand1{a} {}
|
explicit ExprNot(Expr a) : operand1{a} {}
|
||||||
|
|
||||||
bool operator==(const ExprNot& b) const;
|
bool operator==(const ExprNot& b) const;
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ public:
|
||||||
|
|
||||||
class ExprVar final {
|
class ExprVar final {
|
||||||
public:
|
public:
|
||||||
ExprVar(u32 index) : var_index{index} {}
|
explicit ExprVar(u32 index) : var_index{index} {}
|
||||||
|
|
||||||
bool operator==(const ExprVar& b) const {
|
bool operator==(const ExprVar& b) const {
|
||||||
return var_index == b.var_index;
|
return var_index == b.var_index;
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
|
|
||||||
class ExprPredicate final {
|
class ExprPredicate final {
|
||||||
public:
|
public:
|
||||||
ExprPredicate(u32 predicate) : predicate{predicate} {}
|
explicit ExprPredicate(u32 predicate) : predicate{predicate} {}
|
||||||
|
|
||||||
bool operator==(const ExprPredicate& b) const {
|
bool operator==(const ExprPredicate& b) const {
|
||||||
return predicate == b.predicate;
|
return predicate == b.predicate;
|
||||||
|
@ -79,7 +79,7 @@ public:
|
||||||
|
|
||||||
class ExprCondCode final {
|
class ExprCondCode final {
|
||||||
public:
|
public:
|
||||||
ExprCondCode(ConditionCode cc) : cc{cc} {}
|
explicit ExprCondCode(ConditionCode cc) : cc{cc} {}
|
||||||
|
|
||||||
bool operator==(const ExprCondCode& b) const {
|
bool operator==(const ExprCondCode& b) const {
|
||||||
return cc == b.cc;
|
return cc == b.cc;
|
||||||
|
@ -90,7 +90,7 @@ public:
|
||||||
|
|
||||||
class ExprBoolean final {
|
class ExprBoolean final {
|
||||||
public:
|
public:
|
||||||
ExprBoolean(bool val) : value{val} {}
|
explicit ExprBoolean(bool val) : value{val} {}
|
||||||
|
|
||||||
bool operator==(const ExprBoolean& b) const {
|
bool operator==(const ExprBoolean& b) const {
|
||||||
return value == b.value;
|
return value == b.value;
|
||||||
|
|
Loading…
Reference in a new issue