diff options
| author | 2021-09-28 21:37:54 -0400 | |
|---|---|---|
| committer | 2021-11-16 22:11:30 +0100 | |
| commit | 99eec162da567ce08a7ab6ce4d1f4b5fa8b5af5e (patch) | |
| tree | 791ff097b6f90cba269794a75f3d8ac2e2d8bc33 /src/shader_recompiler | |
| parent | rescaling_pass: Scale ImageFetch offset if it exists (diff) | |
| download | yuzu-99eec162da567ce08a7ab6ce4d1f4b5fa8b5af5e.tar.gz yuzu-99eec162da567ce08a7ab6ce4d1f4b5fa8b5af5e.tar.xz yuzu-99eec162da567ce08a7ab6ce4d1f4b5fa8b5af5e.zip | |
rescaling_pass: Logic simplification and minor style cleanup
Diffstat (limited to 'src/shader_recompiler')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate_program.cpp | 1 | ||||
| -rw-r--r-- | src/shader_recompiler/ir_opt/rescaling_pass.cpp | 49 |
2 files changed, 17 insertions, 33 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp index 743fb2420..267ebe4af 100644 --- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp | |||
| @@ -183,7 +183,6 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo | |||
| 183 | if (Settings::values.resolution_info.active) { | 183 | if (Settings::values.resolution_info.active) { |
| 184 | Optimization::RescalingPass(program); | 184 | Optimization::RescalingPass(program); |
| 185 | } | 185 | } |
| 186 | |||
| 187 | Optimization::DeadCodeEliminationPass(program); | 186 | Optimization::DeadCodeEliminationPass(program); |
| 188 | if (Settings::values.renderer_debug) { | 187 | if (Settings::values.renderer_debug) { |
| 189 | Optimization::VerificationPass(program); | 188 | Optimization::VerificationPass(program); |
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp index 2aa9c31dc..0d642dd0d 100644 --- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp +++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp | |||
| @@ -14,11 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | namespace Shader::Optimization { | 15 | namespace Shader::Optimization { |
| 16 | namespace { | 16 | namespace { |
| 17 | void VisitMark(const IR::Program& program, const IR::Inst& inst) { | 17 | void VisitMark(const IR::Inst& inst) { |
| 18 | const bool is_fragment_shader{program.stage == Stage::Fragment}; | ||
| 19 | if (!is_fragment_shader) { | ||
| 20 | return; | ||
| 21 | } | ||
| 22 | switch (inst.GetOpcode()) { | 18 | switch (inst.GetOpcode()) { |
| 23 | case IR::Opcode::ShuffleIndex: | 19 | case IR::Opcode::ShuffleIndex: |
| 24 | case IR::Opcode::ShuffleUp: | 20 | case IR::Opcode::ShuffleUp: |
| @@ -54,6 +50,7 @@ void VisitMark(const IR::Program& program, const IR::Inst& inst) { | |||
| 54 | break; | 50 | break; |
| 55 | } | 51 | } |
| 56 | } | 52 | } |
| 53 | |||
| 57 | void PatchFragCoord(IR::Block& block, IR::Inst& inst) { | 54 | void PatchFragCoord(IR::Block& block, IR::Inst& inst) { |
| 58 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | 55 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; |
| 59 | const IR::F32 down_factor{ir.ResolutionDownFactor()}; | 56 | const IR::F32 down_factor{ir.ResolutionDownFactor()}; |
| @@ -64,50 +61,35 @@ void PatchFragCoord(IR::Block& block, IR::Inst& inst) { | |||
| 64 | 61 | ||
| 65 | [[nodiscard]] IR::U32 Scale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value) { | 62 | [[nodiscard]] IR::U32 Scale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value) { |
| 66 | IR::U32 scaled_value{value}; | 63 | IR::U32 scaled_value{value}; |
| 67 | bool changed{}; | ||
| 68 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { | 64 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { |
| 69 | scaled_value = ir.IMul(scaled_value, ir.Imm32(up_scale)); | 65 | scaled_value = ir.IMul(scaled_value, ir.Imm32(up_scale)); |
| 70 | changed = true; | ||
| 71 | } | 66 | } |
| 72 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { | 67 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { |
| 73 | scaled_value = ir.ShiftRightArithmetic(scaled_value, ir.Imm32(down_shift)); | 68 | scaled_value = ir.ShiftRightArithmetic(scaled_value, ir.Imm32(down_shift)); |
| 74 | changed = true; | ||
| 75 | } | ||
| 76 | if (changed) { | ||
| 77 | return IR::U32{ir.Select(is_scaled, scaled_value, value)}; | ||
| 78 | } else { | ||
| 79 | return value; | ||
| 80 | } | 69 | } |
| 70 | return IR::U32{ir.Select(is_scaled, scaled_value, value)}; | ||
| 81 | } | 71 | } |
| 82 | 72 | ||
| 83 | [[nodiscard]] IR::U32 SubScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value, | 73 | [[nodiscard]] IR::U32 SubScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value, |
| 84 | const IR::Attribute attrib) { | 74 | const IR::Attribute attrib) { |
| 85 | const IR::F32 opt1{ir.Imm32(Settings::values.resolution_info.up_factor)}; | 75 | const IR::F32 up_factor{ir.Imm32(Settings::values.resolution_info.up_factor)}; |
| 86 | const IR::F32 base{ir.FPMul(ir.ConvertUToF(32, 32, value), opt1)}; | 76 | const IR::F32 base{ir.FPMul(ir.ConvertUToF(32, 32, value), up_factor)}; |
| 87 | const IR::F32 frag_coord{ir.GetAttribute(attrib)}; | 77 | const IR::F32 frag_coord{ir.GetAttribute(attrib)}; |
| 88 | const IR::F32 opt2{ir.Imm32(Settings::values.resolution_info.down_factor)}; | 78 | const IR::F32 down_factor{ir.Imm32(Settings::values.resolution_info.down_factor)}; |
| 89 | const IR::F32 floor{ir.FPMul(opt1, ir.FPFloor(ir.FPMul(frag_coord, opt2)))}; | 79 | const IR::F32 floor{ir.FPMul(up_factor, ir.FPFloor(ir.FPMul(frag_coord, down_factor)))}; |
| 90 | const IR::U32 deviation{ | 80 | const IR::F16F32F64 deviation{ir.FPAdd(base, ir.FPAdd(frag_coord, ir.FPNeg(floor)))}; |
| 91 | ir.ConvertFToU(32, ir.FPAdd(base, ir.FPAdd(frag_coord, ir.FPNeg(floor))))}; | 81 | return IR::U32{ir.Select(is_scaled, ir.ConvertFToU(32, deviation), value)}; |
| 92 | return IR::U32{ir.Select(is_scaled, deviation, value)}; | ||
| 93 | } | 82 | } |
| 94 | 83 | ||
| 95 | [[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, const IR::U1& is_scaled, IR::U32 value) { | 84 | [[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value) { |
| 96 | IR::U32 scaled_value{value}; | 85 | IR::U32 scaled_value{value}; |
| 97 | bool changed{}; | ||
| 98 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { | 86 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { |
| 99 | scaled_value = ir.ShiftLeftLogical(scaled_value, ir.Imm32(down_shift)); | 87 | scaled_value = ir.ShiftLeftLogical(scaled_value, ir.Imm32(down_shift)); |
| 100 | changed = true; | ||
| 101 | } | 88 | } |
| 102 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { | 89 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { |
| 103 | scaled_value = ir.IDiv(scaled_value, ir.Imm32(up_scale)); | 90 | scaled_value = ir.IDiv(scaled_value, ir.Imm32(up_scale)); |
| 104 | changed = true; | ||
| 105 | } | ||
| 106 | if (changed) { | ||
| 107 | return IR::U32{ir.Select(is_scaled, scaled_value, value)}; | ||
| 108 | } else { | ||
| 109 | return value; | ||
| 110 | } | 91 | } |
| 92 | return IR::U32{ir.Select(is_scaled, scaled_value, value)}; | ||
| 111 | } | 93 | } |
| 112 | 94 | ||
| 113 | void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) { | 95 | void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) { |
| @@ -267,9 +249,12 @@ void Visit(const IR::Program& program, IR::Block& block, IR::Inst& inst) { | |||
| 267 | } // Anonymous namespace | 249 | } // Anonymous namespace |
| 268 | 250 | ||
| 269 | void RescalingPass(IR::Program& program) { | 251 | void RescalingPass(IR::Program& program) { |
| 270 | for (IR::Block* const block : program.post_order_blocks) { | 252 | const bool is_fragment_shader{program.stage == Stage::Fragment}; |
| 271 | for (IR::Inst& inst : block->Instructions()) { | 253 | if (is_fragment_shader) { |
| 272 | VisitMark(program, inst); | 254 | for (IR::Block* const block : program.post_order_blocks) { |
| 255 | for (IR::Inst& inst : block->Instructions()) { | ||
| 256 | VisitMark(inst); | ||
| 257 | } | ||
| 273 | } | 258 | } |
| 274 | } | 259 | } |
| 275 | for (IR::Block* const block : program.post_order_blocks) { | 260 | for (IR::Block* const block : program.post_order_blocks) { |