From b3371ed09e6866e235141119f9eecc2bb962dc8d Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Mon, 30 Dec 2019 13:54:53 -0400 Subject: Shader_IR: add the ability to amend code in the shader ir. This commit introduces a mechanism by which shader IR code can be amended and extended. This useful for track algorithms where certain information can derived from before the track such as indexes to array samplers. --- src/video_core/shader/node.h | 28 +++++++++++++++++++++++++--- src/video_core/shader/shader_ir.cpp | 6 ++++++ src/video_core/shader/shader_ir.h | 8 ++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src/video_core/shader') diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 4d2f4d6a8..42e82ab74 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h @@ -392,8 +392,30 @@ struct MetaImage { using Meta = std::variant; +class AmendNode { +public: + std::optional GetAmendIndex() const { + if (amend_index == amend_null_index) { + return std::nullopt; + } + return {amend_index}; + } + + void SetAmendIndex(u32 index) { + amend_index = index; + } + + void ClearAmend() { + amend_index = amend_null_index; + } + +private: + static constexpr u32 amend_null_index = 0xFFFFFFFF; + u32 amend_index{amend_null_index}; +}; + /// Holds any kind of operation that can be done in the IR -class OperationNode final { +class OperationNode final : public AmendNode { public: explicit OperationNode(OperationCode code) : OperationNode(code, Meta{}) {} @@ -433,7 +455,7 @@ private: }; /// Encloses inside any kind of node that returns a boolean conditionally-executed code -class ConditionalNode final { +class ConditionalNode final : public AmendNode { public: explicit ConditionalNode(Node condition, std::vector&& code) : condition{std::move(condition)}, code{std::move(code)} {} @@ -630,7 +652,7 @@ private: }; /// Commentary, can be dropped -class CommentNode final { +class CommentNode final : public AmendNode { public: explicit CommentNode(std::string text) : text{std::move(text)} {} diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp index 1d9825c76..49678767c 100644 --- a/src/video_core/shader/shader_ir.cpp +++ b/src/video_core/shader/shader_ir.cpp @@ -446,4 +446,10 @@ Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) { Immediate(bits)); } +u32 ShaderIR::DeclareAmend(Node new_amend) { + const u32 id = static_cast(amend_code.size()); + amend_code.push_back(new_amend); + return id; +} + } // namespace VideoCommon::Shader diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index baed06ccd..52f130e1b 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -176,6 +176,10 @@ public: /// Returns a condition code evaluated from internal flags Node GetConditionCode(Tegra::Shader::ConditionCode cc) const; + const Node& GetAmendNode(u32 index) const { + return amend_code[index]; + } + private: friend class ASTDecoder; @@ -392,6 +396,9 @@ private: Tegra::Shader::Instruction instr, bool is_write); + /// Amends + u32 DeclareAmend(Node new_amend); + const ProgramCode& program_code; const u32 main_offset; const CompilerSettings settings; @@ -406,6 +413,7 @@ private: std::map basic_blocks; NodeBlock global_code; ASTManager program_manager{true, true}; + NodeBlock amend_code; std::set used_registers; std::set used_predicates; -- cgit v1.2.3 From 3dd6b55851978440f39487a6ad06b30b792b3b36 Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Sat, 4 Jan 2020 14:40:57 -0400 Subject: Shader_IR: Address Feedback --- src/video_core/shader/node.h | 10 +++++----- src/video_core/shader/shader_ir.cpp | 4 ++-- src/video_core/shader/shader_ir.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/video_core/shader') diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 42e82ab74..4e155542a 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h @@ -394,14 +394,14 @@ using Meta = class AmendNode { public: - std::optional GetAmendIndex() const { + std::optional GetAmendIndex() const { if (amend_index == amend_null_index) { return std::nullopt; } return {amend_index}; } - void SetAmendIndex(u32 index) { + void SetAmendIndex(std::size_t index) { amend_index = index; } @@ -410,8 +410,8 @@ public: } private: - static constexpr u32 amend_null_index = 0xFFFFFFFF; - u32 amend_index{amend_null_index}; + static constexpr std::size_t amend_null_index = 0xFFFFFFFFFFFFFFFFULL; + std::size_t amend_index{amend_null_index}; }; /// Holds any kind of operation that can be done in the IR @@ -652,7 +652,7 @@ private: }; /// Commentary, can be dropped -class CommentNode final : public AmendNode { +class CommentNode final { public: explicit CommentNode(std::string text) : text{std::move(text)} {} diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp index 49678767c..31eecb3f4 100644 --- a/src/video_core/shader/shader_ir.cpp +++ b/src/video_core/shader/shader_ir.cpp @@ -446,8 +446,8 @@ Node ShaderIR::BitfieldInsert(Node base, Node insert, u32 offset, u32 bits) { Immediate(bits)); } -u32 ShaderIR::DeclareAmend(Node new_amend) { - const u32 id = static_cast(amend_code.size()); +std::size_t ShaderIR::DeclareAmend(Node new_amend) { + const std::size_t id = amend_code.size(); amend_code.push_back(new_amend); return id; } diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 52f130e1b..aacd0a0da 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -176,7 +176,7 @@ public: /// Returns a condition code evaluated from internal flags 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]; } @@ -396,8 +396,8 @@ private: Tegra::Shader::Instruction instr, bool is_write); - /// Amends - u32 DeclareAmend(Node new_amend); + /// Register new amending code and obtain the reference id. + std::size_t DeclareAmend(Node new_amend); const ProgramCode& program_code; const u32 main_offset; @@ -413,7 +413,7 @@ private: std::map basic_blocks; NodeBlock global_code; ASTManager program_manager{true, true}; - NodeBlock amend_code; + std::vector amend_code; std::set used_registers; std::set used_predicates; -- cgit v1.2.3