summaryrefslogtreecommitdiffstats
path: root/src/shader_recompiler/ir_opt/rescaling_pass.cpp
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2021-08-07 02:59:05 +0200
committerFernando Sahmkow <fsahmkow27@gmail.com>2021-11-16 22:11:29 +0100
commitdfa82915262ca26d0884528b7bdae791554332ca (patch)
treeb6e3c6a16cbcfc8952fa0afe5347e13628ce6bdd /src/shader_recompiler/ir_opt/rescaling_pass.cpp
parentTexture Cache: Correctly fix Blits Rescaling. (diff)
downloadyuzu-dfa82915262ca26d0884528b7bdae791554332ca.tar
yuzu-dfa82915262ca26d0884528b7bdae791554332ca.tar.gz
yuzu-dfa82915262ca26d0884528b7bdae791554332ca.tar.bz2
yuzu-dfa82915262ca26d0884528b7bdae791554332ca.tar.lz
yuzu-dfa82915262ca26d0884528b7bdae791554332ca.tar.xz
yuzu-dfa82915262ca26d0884528b7bdae791554332ca.tar.zst
yuzu-dfa82915262ca26d0884528b7bdae791554332ca.zip
Diffstat (limited to 'src/shader_recompiler/ir_opt/rescaling_pass.cpp')
-rw-r--r--src/shader_recompiler/ir_opt/rescaling_pass.cpp100
1 files changed, 97 insertions, 3 deletions
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp
index b94273aa5..71c9d9e6f 100644
--- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp
+++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp
@@ -40,6 +40,22 @@ void PatchFragCoord(IR::Block& block, IR::Inst& inst) {
}
}
+[[nodiscard]] IR::U32 SubScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value,
+ const IR::Attribute attrib) {
+ if (Settings::values.resolution_info.active) {
+ const IR::F32 opt1{ir.Imm32(Settings::values.resolution_info.up_factor)};
+ const IR::F32 base{ir.FPMul(ir.ConvertUToF(32, 32, value), opt1)};
+ const IR::F32 frag_coord{ir.GetAttribute(attrib)};
+ const IR::F32 opt2{ir.Imm32(Settings::values.resolution_info.down_factor)};
+ const IR::F32 floor{ir.FPMul(opt1, ir.FPFloor(ir.FPMul(frag_coord, opt2)))};
+ const IR::U32 deviation{
+ ir.ConvertFToU(32, ir.FPAdd(base, ir.FPAdd(frag_coord, ir.FPNeg(floor))))};
+ return IR::U32{ir.Select(is_scaled, deviation, value)};
+ } else {
+ return value;
+ }
+}
+
[[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, const IR::U1& is_scaled, IR::U32 value) {
IR::U32 scaled_value{value};
bool changed{};
@@ -113,6 +129,74 @@ void ScaleIntegerCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scale
}
}
+void SubScaleImageFetch(IR::Block& block, IR::Inst& inst) {
+ IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
+ const auto info{inst.Flags<IR::TextureInstInfo>()};
+ const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))};
+ const IR::Value coord{inst.Arg(1)};
+ switch (info.type) {
+ case TextureType::Color2D: {
+ const IR::U32 x{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)},
+ IR::Attribute::PositionX)};
+ const IR::U32 y{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)},
+ IR::Attribute::PositionY)};
+ inst.SetArg(1, ir.CompositeConstruct(x, y));
+ break;
+ }
+ case TextureType::ColorArray2D: {
+ const IR::U32 x{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)},
+ IR::Attribute::PositionX)};
+ const IR::U32 y{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)},
+ IR::Attribute::PositionY)};
+ const IR::U32 z{ir.CompositeExtract(coord, 2)};
+ inst.SetArg(1, ir.CompositeConstruct(x, y, z));
+ break;
+ }
+ case TextureType::Color1D:
+ case TextureType::ColorArray1D:
+ case TextureType::Color3D:
+ case TextureType::ColorCube:
+ case TextureType::ColorArrayCube:
+ case TextureType::Buffer:
+ // Nothing to patch here
+ break;
+ }
+}
+
+void SubScaleImageRead(IR::Block& block, IR::Inst& inst) {
+ IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
+ const auto info{inst.Flags<IR::TextureInstInfo>()};
+ const IR::U1 is_scaled{ir.IsImageScaled(ir.Imm32(info.descriptor_index))};
+ const IR::Value coord{inst.Arg(1)};
+ switch (info.type) {
+ case TextureType::Color2D: {
+ const IR::U32 x{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)},
+ IR::Attribute::PositionX)};
+ const IR::U32 y{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)},
+ IR::Attribute::PositionY)};
+ inst.SetArg(1, ir.CompositeConstruct(x, y));
+ break;
+ }
+ case TextureType::ColorArray2D: {
+ const IR::U32 x{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)},
+ IR::Attribute::PositionX)};
+ const IR::U32 y{SubScale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)},
+ IR::Attribute::PositionY)};
+ const IR::U32 z{ir.CompositeExtract(coord, 2)};
+ inst.SetArg(1, ir.CompositeConstruct(x, y, z));
+ break;
+ }
+ case TextureType::Color1D:
+ case TextureType::ColorArray1D:
+ case TextureType::Color3D:
+ case TextureType::ColorCube:
+ case TextureType::ColorArrayCube:
+ case TextureType::Buffer:
+ // Nothing to patch here
+ break;
+ }
+}
+
void PatchImageFetch(IR::Block& block, IR::Inst& inst) {
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
const auto info{inst.Flags<IR::TextureInstInfo>()};
@@ -145,13 +229,23 @@ void Visit(const IR::Program& program, IR::Block& block, IR::Inst& inst) {
break;
}
case IR::Opcode::ImageQueryDimensions:
- PatchImageQueryDimensions(block, inst);
+ if (program.stage == Stage::Compute) {
+ PatchImageQueryDimensions(block, inst);
+ }
break;
case IR::Opcode::ImageFetch:
- PatchImageFetch(block, inst);
+ if (is_fragment_shader) {
+ SubScaleImageFetch(block, inst);
+ } else if (program.stage == Stage::Compute) {
+ PatchImageFetch(block, inst);
+ }
break;
case IR::Opcode::ImageRead:
- PatchImageRead(block, inst);
+ if (is_fragment_shader) {
+ SubScaleImageRead(block, inst);
+ } else if (program.stage == Stage::Compute) {
+ PatchImageRead(block, inst);
+ }
break;
default:
break;