forked from ShuriZma/suyu
Shader_IR: Address Feedback
This commit is contained in:
parent
b3371ed09e
commit
3dd6b55851
|
@ -751,10 +751,8 @@ private:
|
||||||
|
|
||||||
Expression Visit(const Node& node) {
|
Expression Visit(const Node& node) {
|
||||||
if (const auto operation = std::get_if<OperationNode>(&*node)) {
|
if (const auto operation = std::get_if<OperationNode>(&*node)) {
|
||||||
auto amend_index = operation->GetAmendIndex();
|
if (const auto amend_index = operation->GetAmendIndex()) {
|
||||||
if (amend_index) {
|
Visit(ir.GetAmendNode(*amend_index)).CheckVoid();
|
||||||
const Node& amend_node = ir.GetAmendNode(*amend_index);
|
|
||||||
Visit(amend_node).CheckVoid();
|
|
||||||
}
|
}
|
||||||
const auto operation_index = static_cast<std::size_t>(operation->GetCode());
|
const auto operation_index = static_cast<std::size_t>(operation->GetCode());
|
||||||
if (operation_index >= operation_decompilers.size()) {
|
if (operation_index >= operation_decompilers.size()) {
|
||||||
|
@ -877,10 +875,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto conditional = std::get_if<ConditionalNode>(&*node)) {
|
if (const auto conditional = std::get_if<ConditionalNode>(&*node)) {
|
||||||
auto amend_index = conditional->GetAmendIndex();
|
if (const auto amend_index = conditional->GetAmendIndex()) {
|
||||||
if (amend_index) {
|
Visit(ir.GetAmendNode(*amend_index)).CheckVoid();
|
||||||
const Node& amend_node = ir.GetAmendNode(*amend_index);
|
|
||||||
Visit(amend_node).CheckVoid();
|
|
||||||
}
|
}
|
||||||
// It's invalid to call conditional on nested nodes, use an operation instead
|
// It's invalid to call conditional on nested nodes, use an operation instead
|
||||||
code.AddLine("if ({}) {{", Visit(conditional->GetCondition()).AsBool());
|
code.AddLine("if ({}) {{", Visit(conditional->GetCondition()).AsBool());
|
||||||
|
@ -894,11 +890,6 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto comment = std::get_if<CommentNode>(&*node)) {
|
if (const auto comment = std::get_if<CommentNode>(&*node)) {
|
||||||
auto amend_index = comment->GetAmendIndex();
|
|
||||||
if (amend_index) {
|
|
||||||
const Node& amend_node = ir.GetAmendNode(*amend_index);
|
|
||||||
Visit(amend_node).CheckVoid();
|
|
||||||
}
|
|
||||||
code.AddLine("// " + comment->GetText());
|
code.AddLine("// " + comment->GetText());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -954,10 +954,8 @@ private:
|
||||||
|
|
||||||
Expression Visit(const Node& node) {
|
Expression Visit(const Node& node) {
|
||||||
if (const auto operation = std::get_if<OperationNode>(&*node)) {
|
if (const auto operation = std::get_if<OperationNode>(&*node)) {
|
||||||
auto amend_index = operation->GetAmendIndex();
|
if (const auto amend_index = operation->GetAmendIndex()) {
|
||||||
if (amend_index) {
|
[[maybe_unused]] const Type type = Visit(ir.GetAmendNode(*amend_index)).type;
|
||||||
const Node& amend_node = ir.GetAmendNode(*amend_index);
|
|
||||||
[[maybe_unused]] const Type type = Visit(amend_node).type;
|
|
||||||
ASSERT(type == Type::Void);
|
ASSERT(type == Type::Void);
|
||||||
}
|
}
|
||||||
const auto operation_index = static_cast<std::size_t>(operation->GetCode());
|
const auto operation_index = static_cast<std::size_t>(operation->GetCode());
|
||||||
|
@ -1148,10 +1146,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto conditional = std::get_if<ConditionalNode>(&*node)) {
|
if (const auto conditional = std::get_if<ConditionalNode>(&*node)) {
|
||||||
auto amend_index = conditional->GetAmendIndex();
|
if (const auto amend_index = conditional->GetAmendIndex()) {
|
||||||
if (amend_index) {
|
[[maybe_unused]] const Type type = Visit(ir.GetAmendNode(*amend_index)).type;
|
||||||
const Node& amend_node = ir.GetAmendNode(*amend_index);
|
|
||||||
[[maybe_unused]] const Type type = Visit(amend_node).type;
|
|
||||||
ASSERT(type == Type::Void);
|
ASSERT(type == Type::Void);
|
||||||
}
|
}
|
||||||
// It's invalid to call conditional on nested nodes, use an operation instead
|
// It's invalid to call conditional on nested nodes, use an operation instead
|
||||||
|
@ -1176,12 +1172,6 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (const auto comment = std::get_if<CommentNode>(&*node)) {
|
if (const auto comment = std::get_if<CommentNode>(&*node)) {
|
||||||
auto amend_index = comment->GetAmendIndex();
|
|
||||||
if (amend_index) {
|
|
||||||
const Node& amend_node = ir.GetAmendNode(*amend_index);
|
|
||||||
[[maybe_unused]] const Type type = Visit(amend_node).type;
|
|
||||||
ASSERT(type == Type::Void);
|
|
||||||
}
|
|
||||||
Name(OpUndef(t_void), comment->GetText());
|
Name(OpUndef(t_void), comment->GetText());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -394,14 +394,14 @@ using Meta =
|
||||||
|
|
||||||
class AmendNode {
|
class AmendNode {
|
||||||
public:
|
public:
|
||||||
std::optional<u32> GetAmendIndex() const {
|
std::optional<std::size_t> GetAmendIndex() const {
|
||||||
if (amend_index == amend_null_index) {
|
if (amend_index == amend_null_index) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
return {amend_index};
|
return {amend_index};
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetAmendIndex(u32 index) {
|
void SetAmendIndex(std::size_t index) {
|
||||||
amend_index = index;
|
amend_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +410,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr u32 amend_null_index = 0xFFFFFFFF;
|
static constexpr std::size_t amend_null_index = 0xFFFFFFFFFFFFFFFFULL;
|
||||||
u32 amend_index{amend_null_index};
|
std::size_t amend_index{amend_null_index};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Holds any kind of operation that can be done in the IR
|
/// Holds any kind of operation that can be done in the IR
|
||||||
|
@ -652,7 +652,7 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Commentary, can be dropped
|
/// Commentary, can be dropped
|
||||||
class CommentNode final : public AmendNode {
|
class CommentNode final {
|
||||||
public:
|
public:
|
||||||
explicit CommentNode(std::string text) : text{std::move(text)} {}
|
explicit CommentNode(std::string text) : text{std::move(text)} {}
|
||||||
|
|
||||||
|
|
|
@ -446,8 +446,8 @@ Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) {
|
||||||
Immediate(bits));
|
Immediate(bits));
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ShaderIR::DeclareAmend(Node new_amend) {
|
std::size_t ShaderIR::DeclareAmend(Node new_amend) {
|
||||||
const u32 id = static_cast<u32>(amend_code.size());
|
const std::size_t id = amend_code.size();
|
||||||
amend_code.push_back(new_amend);
|
amend_code.push_back(new_amend);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ public:
|
||||||
/// Returns a condition code evaluated from internal flags
|
/// Returns a condition code evaluated from internal flags
|
||||||
Node GetConditionCode(Tegra::Shader::ConditionCode cc) const;
|
Node GetConditionCode(Tegra::Shader::ConditionCode cc) const;
|
||||||
|
|
||||||
const Node& GetAmendNode(u32 index) const {
|
const Node& GetAmendNode(std::size_t index) const {
|
||||||
return amend_code[index];
|
return amend_code[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -396,8 +396,8 @@ private:
|
||||||
Tegra::Shader::Instruction instr,
|
Tegra::Shader::Instruction instr,
|
||||||
bool is_write);
|
bool is_write);
|
||||||
|
|
||||||
/// Amends
|
/// Register new amending code and obtain the reference id.
|
||||||
u32 DeclareAmend(Node new_amend);
|
std::size_t DeclareAmend(Node new_amend);
|
||||||
|
|
||||||
const ProgramCode& program_code;
|
const ProgramCode& program_code;
|
||||||
const u32 main_offset;
|
const u32 main_offset;
|
||||||
|
@ -413,7 +413,7 @@ private:
|
||||||
std::map<u32, NodeBlock> basic_blocks;
|
std::map<u32, NodeBlock> basic_blocks;
|
||||||
NodeBlock global_code;
|
NodeBlock global_code;
|
||||||
ASTManager program_manager{true, true};
|
ASTManager program_manager{true, true};
|
||||||
NodeBlock amend_code;
|
std::vector<Node> amend_code;
|
||||||
|
|
||||||
std::set<u32> used_registers;
|
std::set<u32> used_registers;
|
||||||
std::set<Tegra::Shader::Pred> used_predicates;
|
std::set<Tegra::Shader::Pred> used_predicates;
|
||||||
|
|
Loading…
Reference in New Issue