diff options
| author | 2021-02-05 23:11:23 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:21 -0400 | |
| commit | 16cb00c521cae6e93ec49d10e15b575b7bc4857e (patch) | |
| tree | 3b283895510af56fced7e62031c6beda999c0a1c /src/shader_recompiler/frontend/maxwell | |
| parent | shader: Make typed IR (diff) | |
| download | yuzu-16cb00c521cae6e93ec49d10e15b575b7bc4857e.tar.gz yuzu-16cb00c521cae6e93ec49d10e15b575b7bc4857e.tar.xz yuzu-16cb00c521cae6e93ec49d10e15b575b7bc4857e.zip | |
shader: Add pools and rename files
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell')
15 files changed, 40 insertions, 63 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/control_flow.h b/src/shader_recompiler/frontend/maxwell/control_flow.h index 20ada8afd..49b369282 100644 --- a/src/shader_recompiler/frontend/maxwell/control_flow.h +++ b/src/shader_recompiler/frontend/maxwell/control_flow.h | |||
| @@ -16,7 +16,7 @@ | |||
| 16 | #include "shader_recompiler/frontend/ir/condition.h" | 16 | #include "shader_recompiler/frontend/ir/condition.h" |
| 17 | #include "shader_recompiler/frontend/maxwell/instruction.h" | 17 | #include "shader_recompiler/frontend/maxwell/instruction.h" |
| 18 | #include "shader_recompiler/frontend/maxwell/location.h" | 18 | #include "shader_recompiler/frontend/maxwell/location.h" |
| 19 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 19 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 20 | 20 | ||
| 21 | namespace Shader::Maxwell::Flow { | 21 | namespace Shader::Maxwell::Flow { |
| 22 | 22 | ||
diff --git a/src/shader_recompiler/frontend/maxwell/decode.cpp b/src/shader_recompiler/frontend/maxwell/decode.cpp index ab1cc6c8d..bd85afa1e 100644 --- a/src/shader_recompiler/frontend/maxwell/decode.cpp +++ b/src/shader_recompiler/frontend/maxwell/decode.cpp | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | #include "common/common_types.h" | 11 | #include "common/common_types.h" |
| 12 | #include "shader_recompiler/exception.h" | 12 | #include "shader_recompiler/exception.h" |
| 13 | #include "shader_recompiler/frontend/maxwell/decode.h" | 13 | #include "shader_recompiler/frontend/maxwell/decode.h" |
| 14 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 14 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 15 | 15 | ||
| 16 | namespace Shader::Maxwell { | 16 | namespace Shader::Maxwell { |
| 17 | namespace { | 17 | namespace { |
diff --git a/src/shader_recompiler/frontend/maxwell/decode.h b/src/shader_recompiler/frontend/maxwell/decode.h index 2a3dd28e8..b4f080fd7 100644 --- a/src/shader_recompiler/frontend/maxwell/decode.h +++ b/src/shader_recompiler/frontend/maxwell/decode.h | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 9 | 9 | ||
| 10 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
| 11 | 11 | ||
diff --git a/src/shader_recompiler/frontend/maxwell/opcode.cpp b/src/shader_recompiler/frontend/maxwell/opcodes.cpp index 8a7bdb611..12ddf2ac9 100644 --- a/src/shader_recompiler/frontend/maxwell/opcode.cpp +++ b/src/shader_recompiler/frontend/maxwell/opcodes.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include <array> | 5 | #include <array> |
| 6 | 6 | ||
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 9 | 9 | ||
| 10 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
| 11 | namespace { | 11 | namespace { |
diff --git a/src/shader_recompiler/frontend/maxwell/opcode.h b/src/shader_recompiler/frontend/maxwell/opcodes.h index cd574f29d..cd574f29d 100644 --- a/src/shader_recompiler/frontend/maxwell/opcode.h +++ b/src/shader_recompiler/frontend/maxwell/opcodes.h | |||
diff --git a/src/shader_recompiler/frontend/maxwell/program.cpp b/src/shader_recompiler/frontend/maxwell/program.cpp index b3f2de852..8cdd20804 100644 --- a/src/shader_recompiler/frontend/maxwell/program.cpp +++ b/src/shader_recompiler/frontend/maxwell/program.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | 7 | ||
| 8 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/program.h" | 9 | #include "shader_recompiler/frontend/maxwell/program.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/termination_code.h" | 10 | #include "shader_recompiler/frontend/maxwell/termination_code.h" |
| 10 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" | 11 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" |
| @@ -12,17 +13,18 @@ | |||
| 12 | 13 | ||
| 13 | namespace Shader::Maxwell { | 14 | namespace Shader::Maxwell { |
| 14 | namespace { | 15 | namespace { |
| 15 | void TranslateCode(Environment& env, const Flow::Function& cfg_function, IR::Function& function, | 16 | void TranslateCode(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| 16 | std::span<IR::Block*> block_map, IR::Block* block_memory) { | 17 | Environment& env, const Flow::Function& cfg_function, IR::Function& function, |
| 18 | std::span<IR::Block*> block_map) { | ||
| 17 | const size_t num_blocks{cfg_function.blocks.size()}; | 19 | const size_t num_blocks{cfg_function.blocks.size()}; |
| 18 | function.blocks.reserve(num_blocks); | 20 | function.blocks.reserve(num_blocks); |
| 19 | 21 | ||
| 20 | for (const Flow::BlockId block_id : cfg_function.blocks) { | 22 | for (const Flow::BlockId block_id : cfg_function.blocks) { |
| 21 | const Flow::Block& flow_block{cfg_function.blocks_data[block_id]}; | 23 | const Flow::Block& flow_block{cfg_function.blocks_data[block_id]}; |
| 22 | 24 | ||
| 23 | function.blocks.emplace_back(std::construct_at(block_memory, Translate(env, flow_block))); | 25 | IR::Block* const ir_block{block_pool.Create(Translate(inst_pool, env, flow_block))}; |
| 24 | block_map[flow_block.id] = function.blocks.back().get(); | 26 | block_map[flow_block.id] = ir_block; |
| 25 | ++block_memory; | 27 | function.blocks.emplace_back(ir_block); |
| 26 | } | 28 | } |
| 27 | } | 29 | } |
| 28 | 30 | ||
| @@ -34,21 +36,24 @@ void EmitTerminationInsts(const Flow::Function& cfg_function, | |||
| 34 | } | 36 | } |
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | void TranslateFunction(Environment& env, const Flow::Function& cfg_function, IR::Function& function, | 39 | void TranslateFunction(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| 38 | IR::Block* block_memory) { | 40 | Environment& env, const Flow::Function& cfg_function, |
| 41 | IR::Function& function) { | ||
| 39 | std::vector<IR::Block*> block_map; | 42 | std::vector<IR::Block*> block_map; |
| 40 | block_map.resize(cfg_function.blocks_data.size()); | 43 | block_map.resize(cfg_function.blocks_data.size()); |
| 41 | 44 | ||
| 42 | TranslateCode(env, cfg_function, function, block_map, block_memory); | 45 | TranslateCode(inst_pool, block_pool, env, cfg_function, function, block_map); |
| 43 | EmitTerminationInsts(cfg_function, block_map); | 46 | EmitTerminationInsts(cfg_function, block_map); |
| 44 | } | 47 | } |
| 45 | } // Anonymous namespace | 48 | } // Anonymous namespace |
| 46 | 49 | ||
| 47 | Program::Program(Environment& env, const Flow::CFG& cfg) { | 50 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| 51 | Environment& env, const Flow::CFG& cfg) { | ||
| 52 | IR::Program program; | ||
| 53 | auto& functions{program.functions}; | ||
| 48 | functions.reserve(cfg.Functions().size()); | 54 | functions.reserve(cfg.Functions().size()); |
| 49 | for (const Flow::Function& cfg_function : cfg.Functions()) { | 55 | for (const Flow::Function& cfg_function : cfg.Functions()) { |
| 50 | TranslateFunction(env, cfg_function, functions.emplace_back(), | 56 | TranslateFunction(inst_pool, block_pool, env, cfg_function, functions.emplace_back()); |
| 51 | block_alloc_pool.allocate(cfg_function.blocks.size())); | ||
| 52 | } | 57 | } |
| 53 | std::ranges::for_each(functions, Optimization::SsaRewritePass); | 58 | std::ranges::for_each(functions, Optimization::SsaRewritePass); |
| 54 | for (IR::Function& function : functions) { | 59 | for (IR::Function& function : functions) { |
| @@ -59,27 +64,7 @@ Program::Program(Environment& env, const Flow::CFG& cfg) { | |||
| 59 | Optimization::VerificationPass(function); | 64 | Optimization::VerificationPass(function); |
| 60 | } | 65 | } |
| 61 | //*/ | 66 | //*/ |
| 62 | } | 67 | return program; |
| 63 | |||
| 64 | std::string DumpProgram(const Program& program) { | ||
| 65 | size_t index{0}; | ||
| 66 | std::map<const IR::Inst*, size_t> inst_to_index; | ||
| 67 | std::map<const IR::Block*, size_t> block_to_index; | ||
| 68 | |||
| 69 | for (const IR::Function& function : program.functions) { | ||
| 70 | for (const auto& block : function.blocks) { | ||
| 71 | block_to_index.emplace(block.get(), index); | ||
| 72 | ++index; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | std::string ret; | ||
| 76 | for (const IR::Function& function : program.functions) { | ||
| 77 | ret += fmt::format("Function\n"); | ||
| 78 | for (const auto& block : function.blocks) { | ||
| 79 | ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n'; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | return ret; | ||
| 83 | } | 68 | } |
| 84 | 69 | ||
| 85 | } // namespace Shader::Maxwell | 70 | } // namespace Shader::Maxwell |
diff --git a/src/shader_recompiler/frontend/maxwell/program.h b/src/shader_recompiler/frontend/maxwell/program.h index 36e678a9e..3355ab129 100644 --- a/src/shader_recompiler/frontend/maxwell/program.h +++ b/src/shader_recompiler/frontend/maxwell/program.h | |||
| @@ -9,28 +9,16 @@ | |||
| 9 | #include <vector> | 9 | #include <vector> |
| 10 | 10 | ||
| 11 | #include <boost/container/small_vector.hpp> | 11 | #include <boost/container/small_vector.hpp> |
| 12 | #include <boost/pool/pool_alloc.hpp> | ||
| 13 | 12 | ||
| 14 | #include "shader_recompiler/environment.h" | 13 | #include "shader_recompiler/environment.h" |
| 15 | #include "shader_recompiler/frontend/ir/basic_block.h" | 14 | #include "shader_recompiler/frontend/ir/program.h" |
| 16 | #include "shader_recompiler/frontend/ir/function.h" | ||
| 17 | #include "shader_recompiler/frontend/maxwell/control_flow.h" | 15 | #include "shader_recompiler/frontend/maxwell/control_flow.h" |
| 16 | #include "shader_recompiler/object_pool.h" | ||
| 18 | 17 | ||
| 19 | namespace Shader::Maxwell { | 18 | namespace Shader::Maxwell { |
| 20 | 19 | ||
| 21 | class Program { | 20 | [[nodiscard]] IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, |
| 22 | friend std::string DumpProgram(const Program& program); | 21 | ObjectPool<IR::Block>& block_pool, Environment& env, |
| 23 | 22 | const Flow::CFG& cfg); | |
| 24 | public: | ||
| 25 | explicit Program(Environment& env, const Flow::CFG& cfg); | ||
| 26 | |||
| 27 | private: | ||
| 28 | boost::pool_allocator<IR::Block, boost::default_user_allocator_new_delete, | ||
| 29 | boost::details::pool::null_mutex> | ||
| 30 | block_alloc_pool; | ||
| 31 | boost::container::small_vector<IR::Function, 1> functions; | ||
| 32 | }; | ||
| 33 | |||
| 34 | [[nodiscard]] std::string DumpProgram(const Program& program); | ||
| 35 | 23 | ||
| 36 | } // namespace Shader::Maxwell | 24 | } // namespace Shader::Maxwell |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp index acd8445ad..3d0c48457 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_conversion_integer.cpp | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 6 | #include "shader_recompiler/exception.h" | 6 | #include "shader_recompiler/exception.h" |
| 7 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 7 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 9 | 9 | ||
| 10 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp index 90cddb18b..ba005fbf4 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/floating_point_multi_function.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 10 | ||
| 11 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp index de65173e8..ad97786d4 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_attribute.cpp | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/ir/ir_emitter.h" | 8 | #include "shader_recompiler/frontend/ir/ir_emitter.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 9 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 10 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 10 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 11 | 11 | ||
| 12 | namespace Shader::Maxwell { | 12 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp index 9f1570479..727524284 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/load_store_memory.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 10 | ||
| 11 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp index 1711d3f48..1f83d1068 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/move_register.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | #include "common/bit_field.h" | 5 | #include "common/bit_field.h" |
| 6 | #include "common/common_types.h" | 6 | #include "common/common_types.h" |
| 7 | #include "shader_recompiler/exception.h" | 7 | #include "shader_recompiler/exception.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 8 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 10 | 10 | ||
| 11 | namespace Shader::Maxwell { | 11 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp index d70399f6b..1bb160acb 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/not_implemented.cpp | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 6 | #include "shader_recompiler/exception.h" | 6 | #include "shader_recompiler/exception.h" |
| 7 | #include "shader_recompiler/frontend/maxwell/opcode.h" | 7 | #include "shader_recompiler/frontend/maxwell/opcodes.h" |
| 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | 8 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" |
| 9 | 9 | ||
| 10 | namespace Shader::Maxwell { | 10 | namespace Shader::Maxwell { |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/translate.cpp b/src/shader_recompiler/frontend/maxwell/translate/translate.cpp index 66a306745..dcc3f6c0e 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/translate.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/translate.cpp | |||
| @@ -23,8 +23,9 @@ static void Invoke(TranslatorVisitor& visitor, Location pc, u64 insn) { | |||
| 23 | } | 23 | } |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | IR::Block Translate(Environment& env, const Flow::Block& flow_block) { | 26 | IR::Block Translate(ObjectPool<IR::Inst>& inst_pool, Environment& env, |
| 27 | IR::Block block{flow_block.begin.Offset(), flow_block.end.Offset()}; | 27 | const Flow::Block& flow_block) { |
| 28 | IR::Block block{inst_pool, flow_block.begin.Offset(), flow_block.end.Offset()}; | ||
| 28 | TranslatorVisitor visitor{env, block}; | 29 | TranslatorVisitor visitor{env, block}; |
| 29 | 30 | ||
| 30 | const Location pc_end{flow_block.end}; | 31 | const Location pc_end{flow_block.end}; |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/translate.h b/src/shader_recompiler/frontend/maxwell/translate/translate.h index 788742dea..c1c21b278 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/translate.h +++ b/src/shader_recompiler/frontend/maxwell/translate/translate.h | |||
| @@ -6,11 +6,14 @@ | |||
| 6 | 6 | ||
| 7 | #include "shader_recompiler/environment.h" | 7 | #include "shader_recompiler/environment.h" |
| 8 | #include "shader_recompiler/frontend/ir/basic_block.h" | 8 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| 9 | #include "shader_recompiler/frontend/maxwell/location.h" | 9 | #include "shader_recompiler/frontend/ir/microinstruction.h" |
| 10 | #include "shader_recompiler/frontend/maxwell/control_flow.h" | 10 | #include "shader_recompiler/frontend/maxwell/control_flow.h" |
| 11 | #include "shader_recompiler/frontend/maxwell/location.h" | ||
| 12 | #include "shader_recompiler/object_pool.h" | ||
| 11 | 13 | ||
| 12 | namespace Shader::Maxwell { | 14 | namespace Shader::Maxwell { |
| 13 | 15 | ||
| 14 | [[nodiscard]] IR::Block Translate(Environment& env, const Flow::Block& flow_block); | 16 | [[nodiscard]] IR::Block Translate(ObjectPool<IR::Inst>& inst_pool, Environment& env, |
| 17 | const Flow::Block& flow_block); | ||
| 15 | 18 | ||
| 16 | } // namespace Shader::Maxwell | 19 | } // namespace Shader::Maxwell |