diff options
Diffstat (limited to '')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/program.cpp | 49 |
1 files changed, 17 insertions, 32 deletions
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 |