From 3c34678627eeb1b48375cf70ec38b72691fedd1e Mon Sep 17 00:00:00 2001 From: Fernando Sahmkow Date: Tue, 7 Jan 2020 14:53:46 -0400 Subject: Shader_IR: Implement Injectable Custom Variables to the IR. --- src/video_core/shader/node.h | 17 ++++++++++++++++- src/video_core/shader/shader_ir.cpp | 9 +++++++++ src/video_core/shader/shader_ir.h | 9 +++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/video_core/shader') diff --git a/src/video_core/shader/node.h b/src/video_core/shader/node.h index 2f29b9506..db06767f6 100644 --- a/src/video_core/shader/node.h +++ b/src/video_core/shader/node.h @@ -212,6 +212,7 @@ enum class MetaStackClass { class OperationNode; class ConditionalNode; class GprNode; +class CustomVarNode; class ImmediateNode; class InternalFlagNode; class PredicateNode; @@ -223,7 +224,7 @@ class SmemNode; class GmemNode; class CommentNode; -using NodeData = std::variant; using Node = std::shared_ptr; @@ -550,6 +551,20 @@ private: Tegra::Shader::Register index{}; }; +/// A custom variable +class CustomVarNode final { +public: + explicit constexpr CustomVarNode(u32 index) : index{index} {} + + u32 GetIndex() const { + return index; + } + +private: + u32 index{}; +}; + + /// A 32-bits value that represents an immediate value class ImmediateNode final { public: diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp index a186e22b2..94972d57f 100644 --- a/src/video_core/shader/shader_ir.cpp +++ b/src/video_core/shader/shader_ir.cpp @@ -39,6 +39,10 @@ Node ShaderIR::GetRegister(Register reg) { return MakeNode(reg); } +Node ShaderIR::GetCustomVariable(u32 id) { + return MakeNode(id); +} + Node ShaderIR::GetImmediate19(Instruction instr) { return Immediate(instr.alu.GetImm20_19()); } @@ -453,4 +457,9 @@ std::size_t ShaderIR::DeclareAmend(Node new_amend) { return id; } +u32 ShaderIR::NewCustomVariable() { + const u32 id = num_custom_variables++; + return id; +} + } // namespace VideoCommon::Shader diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 121528346..2fe14e815 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -180,6 +180,10 @@ public: return amend_code[index]; } + u32 GetCustomVariablesAmount() const { + return num_custom_variables; + } + private: friend class ASTDecoder; @@ -236,6 +240,8 @@ private: /// Generates a node for a passed register. Node GetRegister(Tegra::Shader::Register reg); + /// Generates a node for a custom variable + Node GetCustomVariable(u32 id); /// Generates a node representing a 19-bit immediate value Node GetImmediate19(Tegra::Shader::Instruction instr); /// Generates a node representing a 32-bit immediate value @@ -403,6 +409,8 @@ private: /// Register new amending code and obtain the reference id. std::size_t DeclareAmend(Node new_amend); + u32 NewCustomVariable(); + const ProgramCode& program_code; const u32 main_offset; const CompilerSettings settings; @@ -418,6 +426,7 @@ private: NodeBlock global_code; ASTManager program_manager{true, true}; std::vector amend_code; + u32 num_custom_variables{}; std::set used_registers; std::set used_predicates; -- cgit v1.2.3