summaryrefslogtreecommitdiff
path: root/src/shader_recompiler
diff options
context:
space:
mode:
authorGravatar FernandoS272021-05-01 14:56:25 +0200
committerGravatar ameerj2021-07-22 21:51:29 -0400
commitc49d56c931471f21d475a31272164fbfae5ea64a (patch)
tree71642406f4df7963ea78c55acf622bdf5b85a595 /src/shader_recompiler
parentshader: Implement VertexA stage (diff)
downloadyuzu-c49d56c931471f21d475a31272164fbfae5ea64a.tar.gz
yuzu-c49d56c931471f21d475a31272164fbfae5ea64a.tar.xz
yuzu-c49d56c931471f21d475a31272164fbfae5ea64a.zip
shader: Address feedback
Diffstat (limited to 'src/shader_recompiler')
-rw-r--r--src/shader_recompiler/frontend/maxwell/control_flow.cpp10
-rw-r--r--src/shader_recompiler/frontend/maxwell/program.cpp37
-rw-r--r--src/shader_recompiler/frontend/maxwell/program.h1
-rw-r--r--src/shader_recompiler/ir_opt/dual_vertex_pass.cpp20
4 files changed, 33 insertions, 35 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/control_flow.cpp b/src/shader_recompiler/frontend/maxwell/control_flow.cpp
index 298faa03e..e7abea82f 100644
--- a/src/shader_recompiler/frontend/maxwell/control_flow.cpp
+++ b/src/shader_recompiler/frontend/maxwell/control_flow.cpp
@@ -209,9 +209,9 @@ CFG::CFG(Environment& env_, ObjectPool<Block>& block_pool_, Location start_addre
209 } 209 }
210 } 210 }
211 if (exits_to_dispatcher) { 211 if (exits_to_dispatcher) {
212 const auto it = functions[0].blocks.rbegin(); 212 const auto last_block{functions[0].blocks.rbegin()};
213 dispatch_block->begin = it->end + 1; 213 dispatch_block->begin = last_block->end + 1;
214 dispatch_block->end = it->end + 1; 214 dispatch_block->end = last_block->end + 1;
215 functions[0].blocks.insert(*dispatch_block); 215 functions[0].blocks.insert(*dispatch_block);
216 } 216 }
217} 217}
@@ -481,7 +481,7 @@ CFG::AnalysisState CFG::AnalyzeEXIT(Block* block, FunctionId function_id, Locati
481 return AnalysisState::Continue; 481 return AnalysisState::Continue;
482 } 482 }
483 if (exits_to_dispatcher && function_id != 0) { 483 if (exits_to_dispatcher && function_id != 0) {
484 throw NotImplementedException("Dispatch EXIT on external function."); 484 throw NotImplementedException("Dispatch EXIT on external function");
485 } 485 }
486 if (pred != Predicate{true} || flow_test != IR::FlowTest::T) { 486 if (pred != Predicate{true} || flow_test != IR::FlowTest::T) {
487 if (block->stack.Peek(Token::PEXIT).has_value()) { 487 if (block->stack.Peek(Token::PEXIT).has_value()) {
@@ -490,9 +490,9 @@ CFG::AnalysisState CFG::AnalyzeEXIT(Block* block, FunctionId function_id, Locati
490 const IR::Condition cond{flow_test, static_cast<IR::Pred>(pred.index), pred.negated}; 490 const IR::Condition cond{flow_test, static_cast<IR::Pred>(pred.index), pred.negated};
491 if (exits_to_dispatcher) { 491 if (exits_to_dispatcher) {
492 block->end = pc; 492 block->end = pc;
493 block->branch_true = dispatch_block;
494 block->end_class = EndClass::Branch; 493 block->end_class = EndClass::Branch;
495 block->cond = cond; 494 block->cond = cond;
495 block->branch_true = dispatch_block;
496 block->branch_false = AddLabel(block, block->stack, pc + 1, function_id); 496 block->branch_false = AddLabel(block, block->stack, pc + 1, function_id);
497 return AnalysisState::Branch; 497 return AnalysisState::Branch;
498 } 498 }
diff --git a/src/shader_recompiler/frontend/maxwell/program.cpp b/src/shader_recompiler/frontend/maxwell/program.cpp
index 59897cb3e..a4fa4319d 100644
--- a/src/shader_recompiler/frontend/maxwell/program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/program.cpp
@@ -151,31 +151,30 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo
151} 151}
152 152
153IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b, 153IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b,
154 Environment& env2) { 154 Environment& env_vertex_b) {
155 IR::Program program{}; 155 IR::Program result{};
156 Optimization::VertexATransformPass(vertex_a); 156 Optimization::VertexATransformPass(vertex_a);
157 Optimization::VertexBTransformPass(vertex_b); 157 Optimization::VertexBTransformPass(vertex_b);
158 program.blocks.swap(vertex_a.blocks); 158 std::swap(result.blocks, vertex_a.blocks);
159 for (IR::Block* block : vertex_b.blocks) { 159 for (IR::Block* block : vertex_b.blocks) {
160 program.blocks.push_back(block); 160 result.blocks.push_back(block);
161 } 161 }
162 program.stage = Stage::VertexB; 162 result.stage = Stage::VertexB;
163 program.info = vertex_a.info; 163 result.info = vertex_a.info;
164 program.local_memory_size = std::max(vertex_a.local_memory_size, vertex_b.local_memory_size); 164 result.local_memory_size = std::max(vertex_a.local_memory_size, vertex_b.local_memory_size);
165 165
166 for (size_t index = 0; index < 32; index++) { 166 for (size_t index = 0; index < 32; ++index) {
167 program.info.input_generics[index].used |= vertex_b.info.input_generics[index].used; 167 result.info.input_generics[index].used |= vertex_b.info.input_generics[index].used;
168 program.info.stores_generics[index] |= vertex_b.info.stores_generics[index]; 168 result.info.stores_generics[index] |= vertex_b.info.stores_generics[index];
169 } 169 }
170 Optimization::JoinTextureInfo(program.info, vertex_b.info); 170 Optimization::JoinTextureInfo(result.info, vertex_b.info);
171 Optimization::JoinStorageInfo(program.info, vertex_b.info); 171 Optimization::JoinStorageInfo(result.info, vertex_b.info);
172 Optimization::DualVertexJoinPass(program); 172 Optimization::DualVertexJoinPass(result);
173 program.post_order_blocks = PostOrder(program.blocks); 173 result.post_order_blocks = PostOrder(result.blocks);
174 Optimization::DeadCodeEliminationPass(program); 174 Optimization::DeadCodeEliminationPass(result);
175 Optimization::IdentityRemovalPass(program); 175 Optimization::VerificationPass(result);
176 Optimization::VerificationPass(program); 176 Optimization::CollectShaderInfoPass(env_vertex_b, result);
177 Optimization::CollectShaderInfoPass(env2, program); 177 return result;
178 return program;
179} 178}
180 179
181} // namespace Shader::Maxwell 180} // namespace Shader::Maxwell
diff --git a/src/shader_recompiler/frontend/maxwell/program.h b/src/shader_recompiler/frontend/maxwell/program.h
index 6e5d5ddd0..f7f5930e4 100644
--- a/src/shader_recompiler/frontend/maxwell/program.h
+++ b/src/shader_recompiler/frontend/maxwell/program.h
@@ -23,4 +23,5 @@ namespace Shader::Maxwell {
23 23
24[[nodiscard]] IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b, 24[[nodiscard]] IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b,
25 Environment& env_vertex_b); 25 Environment& env_vertex_b);
26
26} // namespace Shader::Maxwell 27} // namespace Shader::Maxwell
diff --git a/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp b/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp
index f35c6478a..f2d7db0e6 100644
--- a/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp
+++ b/src/shader_recompiler/ir_opt/dual_vertex_pass.cpp
@@ -4,8 +4,6 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include <ranges> 6#include <ranges>
7#include <tuple>
8#include <type_traits>
9 7
10#include "common/bit_cast.h" 8#include "common/bit_cast.h"
11#include "common/bit_util.h" 9#include "common/bit_util.h"
@@ -40,7 +38,7 @@ void VertexATransformPass(IR::Program& program) {
40} 38}
41 39
42void VertexBTransformPass(IR::Program& program) { 40void VertexBTransformPass(IR::Program& program) {
43 for (IR::Block* const block : program.post_order_blocks | std::views::reverse) { 41 for (IR::Block* const block : program.blocks) {
44 for (IR::Inst& inst : block->Instructions()) { 42 for (IR::Inst& inst : block->Instructions()) {
45 if (inst.GetOpcode() == IR::Opcode::Prologue) { 43 if (inst.GetOpcode() == IR::Opcode::Prologue) {
46 return inst.Invalidate(); 44 return inst.Invalidate();
@@ -51,24 +49,24 @@ void VertexBTransformPass(IR::Program& program) {
51 49
52void DualVertexJoinPass(IR::Program& program) { 50void DualVertexJoinPass(IR::Program& program) {
53 const auto& blocks = program.blocks; 51 const auto& blocks = program.blocks;
54 s64 s = static_cast<s64>(blocks.size()) - 1; 52 const s64 sub_size = static_cast<s64>(blocks.size()) - 1;
55 if (s < 1) { 53 if (sub_size < 1) {
56 throw NotImplementedException("Dual Vertex Join pass failed, expected atleast 2 blocks!"); 54 throw LogicError("Dual Vertex Join pass failed, expected atleast 2 blocks");
57 } 55 }
58 for (s64 index = 0; index < s; index++) { 56 for (s64 index = 0; index < sub_size; ++index) {
59 IR::Block* const current_block = blocks[index]; 57 IR::Block* const current_block{blocks[index]};
60 IR::Block* const next_block = blocks[index + 1]; 58 IR::Block* const next_block{blocks[index + 1]};
61 for (IR::Inst& inst : current_block->Instructions()) { 59 for (IR::Inst& inst : current_block->Instructions()) {
62 if (inst.GetOpcode() == IR::Opcode::Join) { 60 if (inst.GetOpcode() == IR::Opcode::Join) {
63 IR::IREmitter ir{*current_block, IR::Block::InstructionList::s_iterator_to(inst)}; 61 IR::IREmitter ir{*current_block, IR::Block::InstructionList::s_iterator_to(inst)};
64 ir.Branch(next_block); 62 ir.Branch(next_block);
65 inst.Invalidate(); 63 inst.Invalidate();
66 // only 1 join should exist 64 // Only 1 join should exist
67 return; 65 return;
68 } 66 }
69 } 67 }
70 } 68 }
71 throw NotImplementedException("Dual Vertex Join pass failed, no join present!"); 69 throw LogicError("Dual Vertex Join pass failed, no join present");
72} 70}
73 71
74} // namespace Shader::Optimization 72} // namespace Shader::Optimization