diff options
| author | 2021-05-14 00:40:54 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:31 -0400 | |
| commit | d54d7de40e7295827b0e4e4026441b53d3fc9569 (patch) | |
| tree | 29b5074f851292dace7aeb5da7716675544b3735 /src/shader_recompiler/frontend/maxwell/program.cpp | |
| parent | glasm: Implement Storage atomics (diff) | |
| download | yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.tar.gz yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.tar.xz yuzu-d54d7de40e7295827b0e4e4026441b53d3fc9569.zip | |
glasm: Rework control flow introducing a syntax list
This commit regresses VertexA shaders, their transformation pass has to
be adapted to the new control flow.
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/program.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/program.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/program.cpp b/src/shader_recompiler/frontend/maxwell/program.cpp index 0d3f00699..017c4b8fd 100644 --- a/src/shader_recompiler/frontend/maxwell/program.cpp +++ b/src/shader_recompiler/frontend/maxwell/program.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <ranges> | ||
| 7 | #include <vector> | 8 | #include <vector> |
| 8 | 9 | ||
| 9 | #include "shader_recompiler/frontend/ir/basic_block.h" | 10 | #include "shader_recompiler/frontend/ir/basic_block.h" |
| @@ -15,6 +16,16 @@ | |||
| 15 | 16 | ||
| 16 | namespace Shader::Maxwell { | 17 | namespace Shader::Maxwell { |
| 17 | namespace { | 18 | namespace { |
| 19 | IR::BlockList GenerateBlocks(const IR::AbstractSyntaxList& syntax_list) { | ||
| 20 | auto syntax_blocks{syntax_list | std::views::filter([](const auto& node) { | ||
| 21 | return node.type == IR::AbstractSyntaxNode::Type::Block; | ||
| 22 | })}; | ||
| 23 | IR::BlockList blocks(std::ranges::distance(syntax_blocks)); | ||
| 24 | std::ranges::transform(syntax_blocks, blocks.begin(), | ||
| 25 | [](const IR::AbstractSyntaxNode& node) { return node.block; }); | ||
| 26 | return blocks; | ||
| 27 | } | ||
| 28 | |||
| 18 | void RemoveUnreachableBlocks(IR::Program& program) { | 29 | void RemoveUnreachableBlocks(IR::Program& program) { |
| 19 | // Some blocks might be unreachable if a function call exists unconditionally | 30 | // Some blocks might be unreachable if a function call exists unconditionally |
| 20 | // If this happens the number of blocks and post order blocks will mismatch | 31 | // If this happens the number of blocks and post order blocks will mismatch |
| @@ -23,7 +34,7 @@ void RemoveUnreachableBlocks(IR::Program& program) { | |||
| 23 | } | 34 | } |
| 24 | const auto begin{program.blocks.begin() + 1}; | 35 | const auto begin{program.blocks.begin() + 1}; |
| 25 | const auto end{program.blocks.end()}; | 36 | const auto end{program.blocks.end()}; |
| 26 | const auto pred{[](IR::Block* block) { return block->ImmediatePredecessors().empty(); }}; | 37 | const auto pred{[](IR::Block* block) { return block->ImmPredecessors().empty(); }}; |
| 27 | program.blocks.erase(std::remove_if(begin, end, pred), end); | 38 | program.blocks.erase(std::remove_if(begin, end, pred), end); |
| 28 | } | 39 | } |
| 29 | 40 | ||
| @@ -110,8 +121,9 @@ void AddNVNStorageBuffers(IR::Program& program) { | |||
| 110 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, | 121 | IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Block>& block_pool, |
| 111 | Environment& env, Flow::CFG& cfg) { | 122 | Environment& env, Flow::CFG& cfg) { |
| 112 | IR::Program program; | 123 | IR::Program program; |
| 113 | program.blocks = VisitAST(inst_pool, block_pool, env, cfg); | 124 | program.syntax_list = BuildASL(inst_pool, block_pool, env, cfg); |
| 114 | program.post_order_blocks = PostOrder(program.blocks); | 125 | program.blocks = GenerateBlocks(program.syntax_list); |
| 126 | program.post_order_blocks = PostOrder(program.syntax_list.front()); | ||
| 115 | program.stage = env.ShaderStage(); | 127 | program.stage = env.ShaderStage(); |
| 116 | program.local_memory_size = env.LocalMemorySize(); | 128 | program.local_memory_size = env.LocalMemorySize(); |
| 117 | switch (program.stage) { | 129 | switch (program.stage) { |
| @@ -159,9 +171,7 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b | |||
| 159 | Optimization::VertexATransformPass(vertex_a); | 171 | Optimization::VertexATransformPass(vertex_a); |
| 160 | Optimization::VertexBTransformPass(vertex_b); | 172 | Optimization::VertexBTransformPass(vertex_b); |
| 161 | std::swap(result.blocks, vertex_a.blocks); | 173 | std::swap(result.blocks, vertex_a.blocks); |
| 162 | for (IR::Block* block : vertex_b.blocks) { | 174 | result.blocks.insert(result.blocks.end(), vertex_b.blocks.begin(), vertex_b.blocks.end()); |
| 163 | result.blocks.push_back(block); | ||
| 164 | } | ||
| 165 | result.stage = Stage::VertexB; | 175 | result.stage = Stage::VertexB; |
| 166 | result.info = vertex_a.info; | 176 | result.info = vertex_a.info; |
| 167 | result.local_memory_size = std::max(vertex_a.local_memory_size, vertex_b.local_memory_size); | 177 | result.local_memory_size = std::max(vertex_a.local_memory_size, vertex_b.local_memory_size); |
| @@ -173,7 +183,7 @@ IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b | |||
| 173 | Optimization::JoinTextureInfo(result.info, vertex_b.info); | 183 | Optimization::JoinTextureInfo(result.info, vertex_b.info); |
| 174 | Optimization::JoinStorageInfo(result.info, vertex_b.info); | 184 | Optimization::JoinStorageInfo(result.info, vertex_b.info); |
| 175 | Optimization::DualVertexJoinPass(result); | 185 | Optimization::DualVertexJoinPass(result); |
| 176 | result.post_order_blocks = PostOrder(result.blocks); | 186 | result.post_order_blocks = PostOrder(result.syntax_list.front()); |
| 177 | Optimization::DeadCodeEliminationPass(result); | 187 | Optimization::DeadCodeEliminationPass(result); |
| 178 | Optimization::VerificationPass(result); | 188 | Optimization::VerificationPass(result); |
| 179 | Optimization::CollectShaderInfoPass(env_vertex_b, result); | 189 | Optimization::CollectShaderInfoPass(env_vertex_b, result); |