diff options
| author | 2021-05-01 14:56:25 +0200 | |
|---|---|---|
| committer | 2021-07-22 21:51:29 -0400 | |
| commit | c49d56c931471f21d475a31272164fbfae5ea64a (patch) | |
| tree | 71642406f4df7963ea78c55acf622bdf5b85a595 | |
| parent | shader: Implement VertexA stage (diff) | |
| download | yuzu-c49d56c931471f21d475a31272164fbfae5ea64a.tar.gz yuzu-c49d56c931471f21d475a31272164fbfae5ea64a.tar.xz yuzu-c49d56c931471f21d475a31272164fbfae5ea64a.zip | |
shader: Address feedback
5 files changed, 42 insertions, 44 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 | ||
| 153 | IR::Program MergeDualVertexPrograms(IR::Program& vertex_a, IR::Program& vertex_b, | 153 | IR::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 | ||
| 42 | void VertexBTransformPass(IR::Program& program) { | 40 | void 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 | ||
| 52 | void DualVertexJoinPass(IR::Program& program) { | 50 | void 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 |
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 638475251..634bbb450 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -288,32 +288,32 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline( | |||
| 288 | LOG_INFO(Render_Vulkan, "0x{:016x}", key.Hash()); | 288 | LOG_INFO(Render_Vulkan, "0x{:016x}", key.Hash()); |
| 289 | size_t env_index{0}; | 289 | size_t env_index{0}; |
| 290 | std::array<Shader::IR::Program, Maxwell::MaxShaderProgram> programs; | 290 | std::array<Shader::IR::Program, Maxwell::MaxShaderProgram> programs; |
| 291 | bool uses_vertex_a{}; | 291 | const bool uses_vertex_a{key.unique_hashes[0] != 0}; |
| 292 | std::size_t start_value_processing{}; | 292 | const bool uses_vertex_b{key.unique_hashes[1] != 0}; |
| 293 | for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) { | 293 | for (size_t index = 0; index < Maxwell::MaxShaderProgram; ++index) { |
| 294 | if (key.unique_hashes[index] == 0) { | 294 | if (key.unique_hashes[index] == 0) { |
| 295 | continue; | 295 | continue; |
| 296 | } | 296 | } |
| 297 | uses_vertex_a |= index == 0; | ||
| 298 | Shader::Environment& env{*envs[env_index]}; | 297 | Shader::Environment& env{*envs[env_index]}; |
| 299 | ++env_index; | 298 | ++env_index; |
| 300 | 299 | ||
| 301 | const u32 cfg_offset{static_cast<u32>(env.StartAddress() + sizeof(Shader::ProgramHeader))}; | 300 | const u32 cfg_offset{static_cast<u32>(env.StartAddress() + sizeof(Shader::ProgramHeader))}; |
| 302 | Shader::Maxwell::Flow::CFG cfg(env, pools.flow_block, cfg_offset, index == 0); | 301 | Shader::Maxwell::Flow::CFG cfg(env, pools.flow_block, cfg_offset, index == 0); |
| 303 | if (!uses_vertex_a || index != 1) { | 302 | if (!uses_vertex_a || index != 1) { |
| 303 | // Normal path | ||
| 304 | programs[index] = TranslateProgram(pools.inst, pools.block, env, cfg); | 304 | programs[index] = TranslateProgram(pools.inst, pools.block, env, cfg); |
| 305 | continue; | 305 | } else { |
| 306 | // VertexB path when VertexA is present. | ||
| 307 | Shader::IR::Program& program_va{programs[0]}; | ||
| 308 | Shader::IR::Program program_vb{TranslateProgram(pools.inst, pools.block, env, cfg)}; | ||
| 309 | programs[index] = MergeDualVertexPrograms(program_va, program_vb, env); | ||
| 306 | } | 310 | } |
| 307 | Shader::IR::Program& program_va{programs[0]}; | ||
| 308 | Shader::IR::Program program_vb{TranslateProgram(pools.inst, pools.block, env, cfg)}; | ||
| 309 | programs[index] = MergeDualVertexPrograms(program_va, program_vb, env); | ||
| 310 | start_value_processing = 1; | ||
| 311 | } | 311 | } |
| 312 | std::array<const Shader::Info*, Maxwell::MaxShaderStage> infos{}; | 312 | std::array<const Shader::Info*, Maxwell::MaxShaderStage> infos{}; |
| 313 | std::array<vk::ShaderModule, Maxwell::MaxShaderStage> modules; | 313 | std::array<vk::ShaderModule, Maxwell::MaxShaderStage> modules; |
| 314 | 314 | ||
| 315 | u32 binding{0}; | 315 | u32 binding{0}; |
| 316 | for (size_t index = start_value_processing; index < Maxwell::MaxShaderProgram; ++index) { | 316 | for (size_t index = uses_vertex_a && uses_vertex_b ? 1 : 0; index < Maxwell::MaxShaderProgram; ++index) { |
| 317 | if (key.unique_hashes[index] == 0) { | 317 | if (key.unique_hashes[index] == 0) { |
| 318 | continue; | 318 | continue; |
| 319 | } | 319 | } |