diff options
| author | 2021-08-02 01:03:15 +0200 | |
|---|---|---|
| committer | 2021-11-16 22:11:29 +0100 | |
| commit | 8f78444de35bdbdc83a709b8a822d66018bb9852 (patch) | |
| tree | da7272e8c79e9badf1588e4ce3b10a5b244d9083 /src | |
| parent | texture_cache: Disable dst_image scaling in BlitImage (diff) | |
| download | yuzu-8f78444de35bdbdc83a709b8a822d66018bb9852.tar.gz yuzu-8f78444de35bdbdc83a709b8a822d66018bb9852.tar.xz yuzu-8f78444de35bdbdc83a709b8a822d66018bb9852.zip | |
shader: Fix TextureSize check on rescaling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/shader_recompiler/ir_opt/rescaling_pass.cpp | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp index 2af12fc07..b94273aa5 100644 --- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp +++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp | |||
| @@ -26,11 +26,11 @@ void PatchFragCoord(IR::Block& block, IR::Inst& inst) { | |||
| 26 | IR::U32 scaled_value{value}; | 26 | IR::U32 scaled_value{value}; |
| 27 | bool changed{}; | 27 | bool changed{}; |
| 28 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { | 28 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { |
| 29 | scaled_value = ir.IMul(value, ir.Imm32(up_scale)); | 29 | scaled_value = ir.IMul(scaled_value, ir.Imm32(up_scale)); |
| 30 | changed = true; | 30 | changed = true; |
| 31 | } | 31 | } |
| 32 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { | 32 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { |
| 33 | scaled_value = ir.ShiftRightArithmetic(value, ir.Imm32(down_shift)); | 33 | scaled_value = ir.ShiftRightArithmetic(scaled_value, ir.Imm32(down_shift)); |
| 34 | changed = true; | 34 | changed = true; |
| 35 | } | 35 | } |
| 36 | if (changed) { | 36 | if (changed) { |
| @@ -40,41 +40,42 @@ void PatchFragCoord(IR::Block& block, IR::Inst& inst) { | |||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | [[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, IR::U32 value) { | 43 | [[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, const IR::U1& is_scaled, IR::U32 value) { |
| 44 | IR::U32 scaled_value{value}; | ||
| 45 | bool changed{}; | ||
| 44 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { | 46 | if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { |
| 45 | value = ir.ShiftLeftLogical(value, ir.Imm32(down_shift)); | 47 | scaled_value = ir.ShiftLeftLogical(scaled_value, ir.Imm32(down_shift)); |
| 48 | changed = true; | ||
| 46 | } | 49 | } |
| 47 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { | 50 | if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { |
| 48 | value = ir.IDiv(value, ir.Imm32(up_scale)); | 51 | scaled_value = ir.IDiv(scaled_value, ir.Imm32(up_scale)); |
| 52 | changed = true; | ||
| 53 | } | ||
| 54 | if (changed) { | ||
| 55 | return IR::U32{ir.Select(is_scaled, scaled_value, value)}; | ||
| 56 | } else { | ||
| 57 | return value; | ||
| 49 | } | 58 | } |
| 50 | return value; | ||
| 51 | } | 59 | } |
| 52 | 60 | ||
| 53 | void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) { | 61 | void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) { |
| 54 | const auto it{IR::Block::InstructionList::s_iterator_to(inst)}; | 62 | const auto it{IR::Block::InstructionList::s_iterator_to(inst)}; |
| 55 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; | 63 | IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; |
| 56 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 64 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 65 | const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))}; | ||
| 57 | switch (info.type) { | 66 | switch (info.type) { |
| 58 | case TextureType::Color1D: | ||
| 59 | case TextureType::ColorArray1D: { | ||
| 60 | const IR::Value new_inst{&*block.PrependNewInst(it, inst)}; | ||
| 61 | const IR::U32 width{DownScale(ir, IR::U32{ir.CompositeExtract(new_inst, 0)})}; | ||
| 62 | const IR::Value replacement{ir.CompositeConstruct(width, ir.CompositeExtract(new_inst, 1), | ||
| 63 | ir.CompositeExtract(new_inst, 2), | ||
| 64 | ir.CompositeExtract(new_inst, 3))}; | ||
| 65 | inst.ReplaceUsesWith(replacement); | ||
| 66 | break; | ||
| 67 | } | ||
| 68 | case TextureType::Color2D: | 67 | case TextureType::Color2D: |
| 69 | case TextureType::ColorArray2D: { | 68 | case TextureType::ColorArray2D: { |
| 70 | const IR::Value new_inst{&*block.PrependNewInst(it, inst)}; | 69 | const IR::Value new_inst{&*block.PrependNewInst(it, inst)}; |
| 71 | const IR::U32 width{DownScale(ir, IR::U32{ir.CompositeExtract(new_inst, 0)})}; | 70 | const IR::U32 width{DownScale(ir, is_scaled, IR::U32{ir.CompositeExtract(new_inst, 0)})}; |
| 72 | const IR::U32 height{DownScale(ir, IR::U32{ir.CompositeExtract(new_inst, 1)})}; | 71 | const IR::U32 height{DownScale(ir, is_scaled, IR::U32{ir.CompositeExtract(new_inst, 1)})}; |
| 73 | const IR::Value replacement{ir.CompositeConstruct( | 72 | const IR::Value replacement{ir.CompositeConstruct( |
| 74 | width, height, ir.CompositeExtract(new_inst, 2), ir.CompositeExtract(new_inst, 3))}; | 73 | width, height, ir.CompositeExtract(new_inst, 2), ir.CompositeExtract(new_inst, 3))}; |
| 75 | inst.ReplaceUsesWith(replacement); | 74 | inst.ReplaceUsesWith(replacement); |
| 76 | break; | 75 | break; |
| 77 | } | 76 | } |
| 77 | case TextureType::Color1D: | ||
| 78 | case TextureType::ColorArray1D: | ||
| 78 | case TextureType::Color3D: | 79 | case TextureType::Color3D: |
| 79 | case TextureType::ColorCube: | 80 | case TextureType::ColorCube: |
| 80 | case TextureType::ColorArrayCube: | 81 | case TextureType::ColorArrayCube: |
| @@ -88,15 +89,6 @@ void ScaleIntegerCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scale | |||
| 88 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 89 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 89 | const IR::Value coord{inst.Arg(1)}; | 90 | const IR::Value coord{inst.Arg(1)}; |
| 90 | switch (info.type) { | 91 | switch (info.type) { |
| 91 | case TextureType::Color1D: | ||
| 92 | inst.SetArg(1, Scale(ir, is_scaled, IR::U32{coord})); | ||
| 93 | break; | ||
| 94 | case TextureType::ColorArray1D: { | ||
| 95 | const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)})}; | ||
| 96 | const IR::U32 y{ir.CompositeExtract(coord, 1)}; | ||
| 97 | inst.SetArg(1, ir.CompositeConstruct(x, y)); | ||
| 98 | break; | ||
| 99 | } | ||
| 100 | case TextureType::Color2D: { | 92 | case TextureType::Color2D: { |
| 101 | const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)})}; | 93 | const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)})}; |
| 102 | const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)})}; | 94 | const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)})}; |
| @@ -110,6 +102,8 @@ void ScaleIntegerCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scale | |||
| 110 | inst.SetArg(1, ir.CompositeConstruct(x, y, z)); | 102 | inst.SetArg(1, ir.CompositeConstruct(x, y, z)); |
| 111 | break; | 103 | break; |
| 112 | } | 104 | } |
| 105 | case TextureType::Color1D: | ||
| 106 | case TextureType::ColorArray1D: | ||
| 113 | case TextureType::Color3D: | 107 | case TextureType::Color3D: |
| 114 | case TextureType::ColorCube: | 108 | case TextureType::ColorCube: |
| 115 | case TextureType::ColorArrayCube: | 109 | case TextureType::ColorArrayCube: |