shader: Add pools and rename files
This commit is contained in:
parent
be94ee88d2
commit
16cb00c521
30 changed files with 255 additions and 108 deletions
|
@ -5,6 +5,7 @@
|
|||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include "shader_recompiler/frontend/ir/basic_block.h"
|
||||
#include "shader_recompiler/frontend/maxwell/program.h"
|
||||
#include "shader_recompiler/frontend/maxwell/termination_code.h"
|
||||
#include "shader_recompiler/frontend/maxwell/translate/translate.h"
|
||||
|
@ -12,17 +13,18 @@
|
|||
|
||||
namespace Shader::Maxwell {
|
||||
namespace {
|
||||
void TranslateCode(Environment& env, const Flow::Function& cfg_function, IR::Function& function,
|
||||
std::span<IR::Block*> block_map, IR::Block* block_memory) {
|
||||
void TranslateCode(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
|
||||
Environment& env, const Flow::Function& cfg_function, IR::Function& function,
|
||||
std::span<IR::Block*> block_map) {
|
||||
const size_t num_blocks{cfg_function.blocks.size()};
|
||||
function.blocks.reserve(num_blocks);
|
||||
|
||||
for (const Flow::BlockId block_id : cfg_function.blocks) {
|
||||
const Flow::Block& flow_block{cfg_function.blocks_data[block_id]};
|
||||
|
||||
function.blocks.emplace_back(std::construct_at(block_memory, Translate(env, flow_block)));
|
||||
block_map[flow_block.id] = function.blocks.back().get();
|
||||
++block_memory;
|
||||
IR::Block* const ir_block{block_pool.Create(Translate(inst_pool, env, flow_block))};
|
||||
block_map[flow_block.id] = ir_block;
|
||||
function.blocks.emplace_back(ir_block);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,21 +36,24 @@ void EmitTerminationInsts(const Flow::Function& cfg_function,
|
|||
}
|
||||
}
|
||||
|
||||
void TranslateFunction(Environment& env, const Flow::Function& cfg_function, IR::Function& function,
|
||||
IR::Block* block_memory) {
|
||||
void TranslateFunction(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
|
||||
Environment& env, const Flow::Function& cfg_function,
|
||||
IR::Function& function) {
|
||||
std::vector<IR::Block*> block_map;
|
||||
block_map.resize(cfg_function.blocks_data.size());
|
||||
|
||||
TranslateCode(env, cfg_function, function, block_map, block_memory);
|
||||
TranslateCode(inst_pool, block_pool, env, cfg_function, function, block_map);
|
||||
EmitTerminationInsts(cfg_function, block_map);
|
||||
}
|
||||
} // Anonymous namespace
|
||||
|
||||
Program::Program(Environment& env, const Flow::CFG& cfg) {
|
||||
IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool,
|
||||
Environment& env, const Flow::CFG& cfg) {
|
||||
IR::Program program;
|
||||
auto& functions{program.functions};
|
||||
functions.reserve(cfg.Functions().size());
|
||||
for (const Flow::Function& cfg_function : cfg.Functions()) {
|
||||
TranslateFunction(env, cfg_function, functions.emplace_back(),
|
||||
block_alloc_pool.allocate(cfg_function.blocks.size()));
|
||||
TranslateFunction(inst_pool, block_pool, env, cfg_function, functions.emplace_back());
|
||||
}
|
||||
std::ranges::for_each(functions, Optimization::SsaRewritePass);
|
||||
for (IR::Function& function : functions) {
|
||||
|
@ -59,27 +64,7 @@ Program::Program(Environment& env, const Flow::CFG& cfg) {
|
|||
Optimization::VerificationPass(function);
|
||||
}
|
||||
//*/
|
||||
}
|
||||
|
||||
std::string DumpProgram(const Program& program) {
|
||||
size_t index{0};
|
||||
std::map<const IR::Inst*, size_t> inst_to_index;
|
||||
std::map<const IR::Block*, size_t> block_to_index;
|
||||
|
||||
for (const IR::Function& function : program.functions) {
|
||||
for (const auto& block : function.blocks) {
|
||||
block_to_index.emplace(block.get(), index);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
std::string ret;
|
||||
for (const IR::Function& function : program.functions) {
|
||||
ret += fmt::format("Function\n");
|
||||
for (const auto& block : function.blocks) {
|
||||
ret += IR::DumpBlock(*block, block_to_index, inst_to_index, index) + '\n';
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return program;
|
||||
}
|
||||
|
||||
} // namespace Shader::Maxwell
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue