From ce04ab38bbcd3b33ef9860b7631c7de8f9f2ebc2 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 May 2019 04:01:59 -0400 Subject: [PATCH 1/5] shader/shader_ir: Place implementations of constructor and destructor in cpp file Given the class contains quite a lot of non-trivial types, place the constructor and destructor within the cpp file to avoid inlining construction and destruction code everywhere the class is used. --- src/video_core/shader/shader_ir.cpp | 7 +++++++ src/video_core/shader/shader_ir.h | 7 ++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/video_core/shader/shader_ir.cpp b/src/video_core/shader/shader_ir.cpp index e4eb0dfd9..196235e5d 100644 --- a/src/video_core/shader/shader_ir.cpp +++ b/src/video_core/shader/shader_ir.cpp @@ -21,6 +21,13 @@ using Tegra::Shader::PredCondition; using Tegra::Shader::PredOperation; using Tegra::Shader::Register; +ShaderIR::ShaderIR(const ProgramCode& program_code, u32 main_offset) + : program_code{program_code}, main_offset{main_offset} { + Decode(); +} + +ShaderIR::~ShaderIR() = default; + Node ShaderIR::StoreNode(NodeData&& node_data) { auto store = std::make_unique(node_data); const Node node = store.get(); diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 65f1e1de9..3fab404f4 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -567,11 +567,8 @@ private: class ShaderIR final { public: - explicit ShaderIR(const ProgramCode& program_code, u32 main_offset) - : program_code{program_code}, main_offset{main_offset} { - - Decode(); - } + explicit ShaderIR(const ProgramCode& program_code, u32 main_offset); + ~ShaderIR(); const std::map& GetBasicBlocks() const { return basic_blocks; From e09ee0ff23bc70069277df87698f86cc07fb8785 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 May 2019 04:10:32 -0400 Subject: [PATCH 2/5] shader/shader_ir: Mark tracking functions as const member functions These don't actually modify instance state, so they can be marked as const member functions --- src/video_core/shader/shader_ir.h | 7 ++++--- src/video_core/shader/track.cpp | 12 +++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 3fab404f4..02db2c087 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -811,11 +811,12 @@ private: void WriteLop3Instruction(NodeBlock& bb, Tegra::Shader::Register dest, Node op_a, Node op_b, Node op_c, Node imm_lut, bool sets_cc); - Node TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor); + Node TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) const; - std::optional TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor); + std::optional TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) const; - std::pair TrackRegister(const GprNode* tracked, const NodeBlock& code, s64 cursor); + std::pair TrackRegister(const GprNode* tracked, const NodeBlock& code, + s64 cursor) const; std::tuple TrackAndGetGlobalMemory(NodeBlock& bb, Node addr_register, diff --git a/src/video_core/shader/track.cpp b/src/video_core/shader/track.cpp index 4505667ff..19ede1eb9 100644 --- a/src/video_core/shader/track.cpp +++ b/src/video_core/shader/track.cpp @@ -17,22 +17,24 @@ std::pair FindOperation(const NodeBlock& code, s64 cursor, for (; cursor >= 0; --cursor) { const Node node = code.at(cursor); if (const auto operation = std::get_if(node)) { - if (operation->GetCode() == operation_code) + if (operation->GetCode() == operation_code) { return {node, cursor}; + } } if (const auto conditional = std::get_if(node)) { const auto& conditional_code = conditional->GetCode(); const auto [found, internal_cursor] = FindOperation( conditional_code, static_cast(conditional_code.size() - 1), operation_code); - if (found) + if (found) { return {found, cursor}; + } } } return {}; } } // namespace -Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) { +Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) const { if (const auto cbuf = std::get_if(tracked)) { // Cbuf found, but it has to be immediate return std::holds_alternative(*cbuf->GetOffset()) ? tracked : nullptr; @@ -65,7 +67,7 @@ Node ShaderIR::TrackCbuf(Node tracked, const NodeBlock& code, s64 cursor) { return nullptr; } -std::optional ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) { +std::optional ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, s64 cursor) const { // Reduce the cursor in one to avoid infinite loops when the instruction sets the same register // that it uses as operand const auto [found, found_cursor] = @@ -80,7 +82,7 @@ std::optional ShaderIR::TrackImmediate(Node tracked, const NodeBlock& code, } std::pair ShaderIR::TrackRegister(const GprNode* tracked, const NodeBlock& code, - s64 cursor) { + s64 cursor) const { for (; cursor >= 0; --cursor) { const auto [found_node, new_cursor] = FindOperation(code, cursor, OperationCode::Assign); if (!found_node) { From 81e7e63080b5686dd8a4d061f71ac3f0ddc6d89f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 May 2019 04:15:24 -0400 Subject: [PATCH 3/5] shader/shader_ir: Remove unnecessary template parameter packs from Operation() overloads where applicable These overloads don't actually make use of the parameter pack, so they can be turned into regular non-template function overloads. --- src/video_core/shader/shader_ir.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 02db2c087..5f3aef7ce 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -833,12 +833,10 @@ private: return StoreNode(OperationNode(code, std::move(meta), operands...)); } - template Node Operation(OperationCode code, std::vector&& operands) { return StoreNode(OperationNode(code, std::move(operands))); } - template Node Operation(OperationCode code, Meta&& meta, std::vector&& operands) { return StoreNode(OperationNode(code, std::move(meta), std::move(operands))); } From 212b148923f1d2d193d79e75dde565cedc095252 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 May 2019 04:47:00 -0400 Subject: [PATCH 4/5] shader/shader_ir: Simplify constructors for OperationNode Many of these constructors don't even need to be templated. The only ones that need to be templated are the ones that actually make use of the parameter pack. Even then, since std::vector accepts an initializer list, we can supply the parameter pack directly to it instead of creating our own copy of the list, then copying it again into the std::vector. --- src/video_core/shader/shader_ir.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index 5f3aef7ce..b93cde71a 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -336,32 +336,23 @@ using Meta = std::variant; /// Holds any kind of operation that can be done in the IR class OperationNode final { public: - template - explicit constexpr OperationNode(OperationCode code) : code{code}, meta{} {} + explicit OperationNode(OperationCode code) : code{code} {} + + explicit OperationNode(OperationCode code, Meta&& meta) : code{code}, meta{std::move(meta)} {} template - explicit constexpr OperationNode(OperationCode code, Meta&& meta) - : code{code}, meta{std::move(meta)} {} - - template - explicit constexpr OperationNode(OperationCode code, const T*... operands) + explicit OperationNode(OperationCode code, const T*... operands) : OperationNode(code, {}, operands...) {} template - explicit constexpr OperationNode(OperationCode code, Meta&& meta, const T*... operands_) - : code{code}, meta{std::move(meta)} { - - auto operands_list = {operands_...}; - for (auto& operand : operands_list) { - operands.push_back(operand); - } - } + explicit OperationNode(OperationCode code, Meta&& meta, const T*... operands_) + : code{code}, meta{std::move(meta)}, operands{operands_...} {} explicit OperationNode(OperationCode code, Meta&& meta, std::vector&& operands) : code{code}, meta{meta}, operands{std::move(operands)} {} explicit OperationNode(OperationCode code, std::vector&& operands) - : code{code}, meta{}, operands{std::move(operands)} {} + : code{code}, operands{std::move(operands)} {} OperationCode GetCode() const { return code; From e310d943b8eaea2e06166a593ef8ded26256acf4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 19 May 2019 04:55:27 -0400 Subject: [PATCH 5/5] shader/shader_ir: Remove unnecessary inline specifiers constexpr internally links by default, so the inline specifier is unnecessary. --- src/video_core/shader/shader_ir.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video_core/shader/shader_ir.h b/src/video_core/shader/shader_ir.h index b93cde71a..e4253fdb3 100644 --- a/src/video_core/shader/shader_ir.h +++ b/src/video_core/shader/shader_ir.h @@ -328,8 +328,8 @@ struct MetaTexture { u32 element{}; }; -inline constexpr MetaArithmetic PRECISE = {true}; -inline constexpr MetaArithmetic NO_PRECISE = {false}; +constexpr MetaArithmetic PRECISE = {true}; +constexpr MetaArithmetic NO_PRECISE = {false}; using Meta = std::variant;