diff options
| author | 2020-01-04 14:40:57 -0400 | |
|---|---|---|
| committer | 2020-01-04 14:40:57 -0400 | |
| commit | 3dd6b55851978440f39487a6ad06b30b792b3b36 (patch) | |
| tree | d5019053dc20d420181443ff90207aab2ff28938 /src | |
| parent | Shader_IR: add the ability to amend code in the shader ir. (diff) | |
| download | yuzu-3dd6b55851978440f39487a6ad06b30b792b3b36.tar.gz yuzu-3dd6b55851978440f39487a6ad06b30b792b3b36.tar.xz yuzu-3dd6b55851978440f39487a6ad06b30b792b3b36.zip | |
Shader_IR: Address Feedback
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 17 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | 18 | ||||
| -rw-r--r-- | src/video_core/shader/node.h | 10 | ||||
| -rw-r--r-- | src/video_core/shader/shader_ir.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/shader/shader_ir.h | 8 |
5 files changed, 19 insertions, 38 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index e1730821f..f9f7a97b5 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -751,10 +751,8 @@ private: | |||
| 751 | 751 | ||
| 752 | Expression Visit(const Node& node) { | 752 | Expression Visit(const Node& node) { |
| 753 | if (const auto operation = std::get_if<OperationNode>(&*node)) { | 753 | if (const auto operation = std::get_if<OperationNode>(&*node)) { |
| 754 | auto amend_index = operation->GetAmendIndex(); | 754 | if (const auto amend_index = operation->GetAmendIndex()) { |
| 755 | if (amend_index) { | 755 | Visit(ir.GetAmendNode(*amend_index)).CheckVoid(); |
| 756 | const Node& amend_node = ir.GetAmendNode(*amend_index); | ||
| 757 | Visit(amend_node).CheckVoid(); | ||
| 758 | } | 756 | } |
| 759 | const auto operation_index = static_cast<std::size_t>(operation->GetCode()); | 757 | const auto operation_index = static_cast<std::size_t>(operation->GetCode()); |
| 760 | if (operation_index >= operation_decompilers.size()) { | 758 | if (operation_index >= operation_decompilers.size()) { |
| @@ -877,10 +875,8 @@ private: | |||
| 877 | } | 875 | } |
| 878 | 876 | ||
| 879 | if (const auto conditional = std::get_if<ConditionalNode>(&*node)) { | 877 | if (const auto conditional = std::get_if<ConditionalNode>(&*node)) { |
| 880 | auto amend_index = conditional->GetAmendIndex(); | 878 | if (const auto amend_index = conditional->GetAmendIndex()) { |
| 881 | if (amend_index) { | 879 | Visit(ir.GetAmendNode(*amend_index)).CheckVoid(); |
| 882 | const Node& amend_node = ir.GetAmendNode(*amend_index); | ||
| 883 | Visit(amend_node).CheckVoid(); | ||
| 884 | } | 880 | } |
| 885 | // It's invalid to call conditional on nested nodes, use an operation instead | 881 | // It's invalid to call conditional on nested nodes, use an operation instead |
| 886 | code.AddLine("if ({}) {{", Visit(conditional->GetCondition()).AsBool()); | 882 | code.AddLine("if ({}) {{", Visit(conditional->GetCondition()).AsBool()); |
| @@ -894,11 +890,6 @@ private: | |||
| 894 | } | 890 | } |
| 895 | 891 | ||
| 896 | if (const auto comment = std::get_if<CommentNode>(&*node)) { | 892 | if (const auto comment = std::get_if<CommentNode>(&*node)) { |
| 897 | auto amend_index = comment->GetAmendIndex(); | ||
| 898 | if (amend_index) { | ||
| 899 | const Node& amend_node = ir.GetAmendNode(*amend_index); | ||
| 900 | Visit(amend_node).CheckVoid(); | ||
| 901 | } | ||
| 902 | code.AddLine("// " + comment->GetText()); | 893 | code.AddLine("// " + comment->GetText()); |
| 903 | return {}; | 894 | return {}; |
| 904 | } | 895 | } |
diff --git a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp index 50feeb003..8fe852ce8 100644 --- a/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp +++ b/src/video_core/renderer_vulkan/vk_shader_decompiler.cpp | |||
| @@ -954,10 +954,8 @@ private: | |||
| 954 | 954 | ||
| 955 | Expression Visit(const Node& node) { | 955 | Expression Visit(const Node& node) { |
| 956 | if (const auto operation = std::get_if<OperationNode>(&*node)) { | 956 | if (const auto operation = std::get_if<OperationNode>(&*node)) { |
| 957 | auto amend_index = operation->GetAmendIndex(); | 957 | if (const auto amend_index = operation->GetAmendIndex()) { |
| 958 | if (amend_index) { | 958 | [[maybe_unused]] const Type type = Visit(ir.GetAmendNode(*amend_index)).type; |
| 959 | const Node& amend_node = ir.GetAmendNode(*amend_index); | ||
| 960 | [[maybe_unused]] const Type type = Visit(amend_node).type; | ||
| 961 | ASSERT(type == Type::Void); | 959 | ASSERT(type == Type::Void); |
| 962 | } | 960 | } |
| 963 | const auto operation_index = static_cast<std::size_t>(operation->GetCode()); | 961 | const auto operation_index = static_cast<std::size_t>(operation->GetCode()); |
| @@ -1148,10 +1146,8 @@ private: | |||
| 1148 | } | 1146 | } |
| 1149 | 1147 | ||
| 1150 | if (const auto conditional = std::get_if<ConditionalNode>(&*node)) { | 1148 | if (const auto conditional = std::get_if<ConditionalNode>(&*node)) { |
| 1151 | auto amend_index = conditional->GetAmendIndex(); | 1149 | if (const auto amend_index = conditional->GetAmendIndex()) { |
| 1152 | if (amend_index) { | 1150 | [[maybe_unused]] const Type type = Visit(ir.GetAmendNode(*amend_index)).type; |
| 1153 | const Node& amend_node = ir.GetAmendNode(*amend_index); | ||
| 1154 | [[maybe_unused]] const Type type = Visit(amend_node).type; | ||
| 1155 | ASSERT(type == Type::Void); | 1151 | ASSERT(type == Type::Void); |
| 1156 | } | 1152 | } |
| 1157 | // It's invalid to call conditional on nested nodes, use an operation instead | 1153 | // It's invalid to call conditional on nested nodes, use an operation instead |
| @@ -1176,12 +1172,6 @@ private: | |||
| 1176 | } | 1172 | } |
| 1177 | 1173 | ||
| 1178 | if (const auto comment = std::get_if<CommentNode>(&*node)) { | 1174 | if (const auto comment = std::get_if<CommentNode>(&*node)) { |
| 1179 | auto amend_index = comment->GetAmendIndex(); | ||
| 1180 | if (amend_index) { | ||
| 1181 | const Node& amend_node = ir.GetAmendNode(*amend_index); | ||
| 1182 | [[maybe_unused]] const Type type = Visit(amend_node).type; | ||
| 1183 | ASSERT(type == Type::Void); | ||
| 1184 | } | ||
| 1185 | Name(OpUndef(t_void), comment->GetText()); | 1175 | Name(OpUndef(t_void), comment->GetText()); |
| 1186 | return {}; | 1176 | return {}; |
| 1187 | } | 1177 | } |
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 = | |||
| 394 | 394 | ||
| 395 | class AmendNode { | 395 | class AmendNode { |
| 396 | public: | 396 | public: |
| 397 | std::optional<u32> GetAmendIndex() const { | 397 | std::optional<std::size_t> GetAmendIndex() const { |
| 398 | if (amend_index == amend_null_index) { | 398 | if (amend_index == amend_null_index) { |
| 399 | return std::nullopt; | 399 | return std::nullopt; |
| 400 | } | 400 | } |
| 401 | return {amend_index}; | 401 | return {amend_index}; |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | void SetAmendIndex(u32 index) { | 404 | void SetAmendIndex(std::size_t index) { |
| 405 | amend_index = index; | 405 | amend_index = index; |
| 406 | } | 406 | } |
| 407 | 407 | ||
| @@ -410,8 +410,8 @@ public: | |||
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | private: | 412 | private: |
| 413 | static constexpr u32 amend_null_index = 0xFFFFFFFF; | 413 | static constexpr std::size_t amend_null_index = 0xFFFFFFFFFFFFFFFFULL; |
| 414 | u32 amend_index{amend_null_index}; | 414 | std::size_t amend_index{amend_null_index}; |
| 415 | }; | 415 | }; |
| 416 | 416 | ||
| 417 | /// Holds any kind of operation that can be done in the IR | 417 | /// Holds any kind of operation that can be done in the IR |
| @@ -652,7 +652,7 @@ private: | |||
| 652 | }; | 652 | }; |
| 653 | 653 | ||
| 654 | /// Commentary, can be dropped | 654 | /// Commentary, can be dropped |
| 655 | class CommentNode final : public AmendNode { | 655 | class CommentNode final { |
| 656 | public: | 656 | public: |
| 657 | explicit CommentNode(std::string text) : text{std::move(text)} {} | 657 | explicit CommentNode(std::string text) : text{std::move(text)} {} |
| 658 | 658 | ||
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) { | |||
| 446 | Immediate(bits)); | 446 | Immediate(bits)); |
| 447 | } | 447 | } |
| 448 | 448 | ||
| 449 | u32 ShaderIR::DeclareAmend(Node new_amend) { | 449 | std::size_t ShaderIR::DeclareAmend(Node new_amend) { |
| 450 | const u32 id = static_cast<u32>(amend_code.size()); | 450 | const std::size_t id = amend_code.size(); |
| 451 | amend_code.push_back(new_amend); | 451 | amend_code.push_back(new_amend); |
| 452 | return id; | 452 | return id; |
| 453 | } | 453 | } |
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: | |||
| 176 | /// Returns a condition code evaluated from internal flags | 176 | /// Returns a condition code evaluated from internal flags |
| 177 | Node GetConditionCode(Tegra::Shader::ConditionCode cc) const; | 177 | Node GetConditionCode(Tegra::Shader::ConditionCode cc) const; |
| 178 | 178 | ||
| 179 | const Node& GetAmendNode(u32 index) const { | 179 | const Node& GetAmendNode(std::size_t index) const { |
| 180 | return amend_code[index]; | 180 | return amend_code[index]; |
| 181 | } | 181 | } |
| 182 | 182 | ||
| @@ -396,8 +396,8 @@ private: | |||
| 396 | Tegra::Shader::Instruction instr, | 396 | Tegra::Shader::Instruction instr, |
| 397 | bool is_write); | 397 | bool is_write); |
| 398 | 398 | ||
| 399 | /// Amends | 399 | /// Register new amending code and obtain the reference id. |
| 400 | u32 DeclareAmend(Node new_amend); | 400 | std::size_t DeclareAmend(Node new_amend); |
| 401 | 401 | ||
| 402 | const ProgramCode& program_code; | 402 | const ProgramCode& program_code; |
| 403 | const u32 main_offset; | 403 | const u32 main_offset; |
| @@ -413,7 +413,7 @@ private: | |||
| 413 | std::map<u32, NodeBlock> basic_blocks; | 413 | std::map<u32, NodeBlock> basic_blocks; |
| 414 | NodeBlock global_code; | 414 | NodeBlock global_code; |
| 415 | ASTManager program_manager{true, true}; | 415 | ASTManager program_manager{true, true}; |
| 416 | NodeBlock amend_code; | 416 | std::vector<Node> amend_code; |
| 417 | 417 | ||
| 418 | std::set<u32> used_registers; | 418 | std::set<u32> used_registers; |
| 419 | std::set<Tegra::Shader::Pred> used_predicates; | 419 | std::set<Tegra::Shader::Pred> used_predicates; |