summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorameerj <52414509+ameerj@users.noreply.github.com>2021-09-29 03:29:17 +0200
committerFernando Sahmkow <fsahmkow27@gmail.com>2021-11-16 22:11:30 +0100
commit276565973f373b2dbf7f19a68a6d0304803dc2c3 (patch)
treeb9e37f425e3768fed4c45ad8c26a58e7e40948b9
parentrescaling_pass: Enable PatchImageQueryDimensions on fragment stages (diff)
downloadyuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.tar
yuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.tar.gz
yuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.tar.bz2
yuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.tar.lz
yuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.tar.xz
yuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.tar.zst
yuzu-276565973f373b2dbf7f19a68a6d0304803dc2c3.zip
Diffstat (limited to '')
-rw-r--r--src/shader_recompiler/ir_opt/rescaling_pass.cpp96
1 files changed, 37 insertions, 59 deletions
diff --git a/src/shader_recompiler/ir_opt/rescaling_pass.cpp b/src/shader_recompiler/ir_opt/rescaling_pass.cpp
index 51125f45a..2aa9c31dc 100644
--- a/src/shader_recompiler/ir_opt/rescaling_pass.cpp
+++ b/src/shader_recompiler/ir_opt/rescaling_pass.cpp
@@ -137,21 +137,22 @@ void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) {
}
}
-void ScaleIntegerCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled) {
+void ScaleIntegerComposite(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled,
+ size_t index) {
+ const IR::Value composite{inst.Arg(index)};
+ if (composite.IsEmpty()) {
+ return;
+ }
const auto info{inst.Flags<IR::TextureInstInfo>()};
- const IR::Value coord{inst.Arg(1)};
+ const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(composite, 0)})};
+ const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(composite, 1)})};
switch (info.type) {
- case TextureType::Color2D: {
- const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)})};
- const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)})};
- inst.SetArg(1, ir.CompositeConstruct(x, y));
+ case TextureType::Color2D:
+ inst.SetArg(index, ir.CompositeConstruct(x, y));
break;
- }
case TextureType::ColorArray2D: {
- const IR::U32 x{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 0)})};
- const IR::U32 y{Scale(ir, is_scaled, IR::U32{ir.CompositeExtract(coord, 1)})};
- const IR::U32 z{ir.CompositeExtract(coord, 2)};
- inst.SetArg(1, ir.CompositeConstruct(x, y, z));
+ const IR::U32 z{ir.CompositeExtract(composite, 2)};
+ inst.SetArg(index, ir.CompositeConstruct(x, y, z));
break;
}
case TextureType::Color1D:
@@ -165,27 +166,21 @@ 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)};
+void SubScaleCoord(IR::IREmitter& ir, IR::Inst& inst, const IR::U1& is_scaled) {
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)};
+ const IR::U32 coord_x{ir.CompositeExtract(coord, 0)};
+ const IR::U32 coord_y{ir.CompositeExtract(coord, 1)};
+
+ const IR::U32 scaled_x{SubScale(ir, is_scaled, coord_x, IR::Attribute::PositionX)};
+ const IR::U32 scaled_y{SubScale(ir, is_scaled, coord_y, IR::Attribute::PositionY)};
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));
+ case TextureType::Color2D:
+ inst.SetArg(1, ir.CompositeConstruct(scaled_x, scaled_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));
+ inst.SetArg(1, ir.CompositeConstruct(scaled_x, scaled_y, z));
break;
}
case TextureType::Color1D:
@@ -199,57 +194,40 @@ void SubScaleImageFetch(IR::Block& block, IR::Inst& inst) {
}
}
+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))};
+ SubScaleCoord(ir, inst, is_scaled);
+ // Scale ImageFetch offset
+ ScaleIntegerComposite(ir, inst, is_scaled, 2);
+}
+
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;
- }
+ SubScaleCoord(ir, inst, is_scaled);
}
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>()};
const IR::U1 is_scaled{ir.IsTextureScaled(ir.Imm32(info.descriptor_index))};
- ScaleIntegerCoord(ir, inst, is_scaled);
+ ScaleIntegerComposite(ir, inst, is_scaled, 1);
+ // Scale ImageFetch offset
+ ScaleIntegerComposite(ir, inst, is_scaled, 2);
}
void PatchImageRead(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))};
- ScaleIntegerCoord(ir, inst, is_scaled);
+ ScaleIntegerComposite(ir, inst, is_scaled, 1);
}
void Visit(const IR::Program& program, IR::Block& block, IR::Inst& inst) {
const bool is_fragment_shader{program.stage == Stage::Fragment};
- const bool is_compute_shader{program.stage == Stage::Compute};
switch (inst.GetOpcode()) {
case IR::Opcode::GetAttribute: {
const IR::Attribute attr{inst.Arg(0).Attribute()};
@@ -271,14 +249,14 @@ void Visit(const IR::Program& program, IR::Block& block, IR::Inst& inst) {
case IR::Opcode::ImageFetch:
if (is_fragment_shader) {
SubScaleImageFetch(block, inst);
- } else if (is_compute_shader) {
+ } else {
PatchImageFetch(block, inst);
}
break;
case IR::Opcode::ImageRead:
if (is_fragment_shader) {
SubScaleImageRead(block, inst);
- } else if (is_compute_shader) {
+ } else {
PatchImageRead(block, inst);
}
break;