yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

rescaling_pass: Logic simplification and minor style cleanup

This commit is contained in:
ameerj 2021-09-28 21:37:54 -04:00 committed by Fernando Sahmkow
parent 276565973f
commit 99eec162da
2 changed files with 17 additions and 33 deletions

View File

@ -183,7 +183,6 @@ IR::Program TranslateProgram(ObjectPool<IR::Inst>& inst_pool, ObjectPool<IR::Blo
if (Settings::values.resolution_info.active) { if (Settings::values.resolution_info.active) {
Optimization::RescalingPass(program); Optimization::RescalingPass(program);
} }
Optimization::DeadCodeEliminationPass(program); Optimization::DeadCodeEliminationPass(program);
if (Settings::values.renderer_debug) { if (Settings::values.renderer_debug) {
Optimization::VerificationPass(program); Optimization::VerificationPass(program);

View File

@ -14,11 +14,7 @@
namespace Shader::Optimization { namespace Shader::Optimization {
namespace { namespace {
void VisitMark(const IR::Program& program, const IR::Inst& inst) { void VisitMark(const IR::Inst& inst) {
const bool is_fragment_shader{program.stage == Stage::Fragment};
if (!is_fragment_shader) {
return;
}
switch (inst.GetOpcode()) { switch (inst.GetOpcode()) {
case IR::Opcode::ShuffleIndex: case IR::Opcode::ShuffleIndex:
case IR::Opcode::ShuffleUp: case IR::Opcode::ShuffleUp:
@ -54,6 +50,7 @@ void VisitMark(const IR::Program& program, const IR::Inst& inst) {
break; break;
} }
} }
void PatchFragCoord(IR::Block& block, IR::Inst& inst) { void PatchFragCoord(IR::Block& block, IR::Inst& inst) {
IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)}; IR::IREmitter ir{block, IR::Block::InstructionList::s_iterator_to(inst)};
const IR::F32 down_factor{ir.ResolutionDownFactor()}; const IR::F32 down_factor{ir.ResolutionDownFactor()};
@ -64,50 +61,35 @@ void PatchFragCoord(IR::Block& block, IR::Inst& inst) {
[[nodiscard]] IR::U32 Scale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value) { [[nodiscard]] IR::U32 Scale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value) {
IR::U32 scaled_value{value}; IR::U32 scaled_value{value};
bool changed{};
if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) {
scaled_value = ir.IMul(scaled_value, ir.Imm32(up_scale)); scaled_value = ir.IMul(scaled_value, ir.Imm32(up_scale));
changed = true;
} }
if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) {
scaled_value = ir.ShiftRightArithmetic(scaled_value, ir.Imm32(down_shift)); scaled_value = ir.ShiftRightArithmetic(scaled_value, ir.Imm32(down_shift));
changed = true;
} }
if (changed) {
return IR::U32{ir.Select(is_scaled, scaled_value, value)}; return IR::U32{ir.Select(is_scaled, scaled_value, value)};
} else {
return value;
}
} }
[[nodiscard]] IR::U32 SubScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value, [[nodiscard]] IR::U32 SubScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value,
const IR::Attribute attrib) { const IR::Attribute attrib) {
const IR::F32 opt1{ir.Imm32(Settings::values.resolution_info.up_factor)}; const IR::F32 up_factor{ir.Imm32(Settings::values.resolution_info.up_factor)};
const IR::F32 base{ir.FPMul(ir.ConvertUToF(32, 32, value), opt1)}; const IR::F32 base{ir.FPMul(ir.ConvertUToF(32, 32, value), up_factor)};
const IR::F32 frag_coord{ir.GetAttribute(attrib)}; const IR::F32 frag_coord{ir.GetAttribute(attrib)};
const IR::F32 opt2{ir.Imm32(Settings::values.resolution_info.down_factor)}; const IR::F32 down_factor{ir.Imm32(Settings::values.resolution_info.down_factor)};
const IR::F32 floor{ir.FPMul(opt1, ir.FPFloor(ir.FPMul(frag_coord, opt2)))}; const IR::F32 floor{ir.FPMul(up_factor, ir.FPFloor(ir.FPMul(frag_coord, down_factor)))};
const IR::U32 deviation{ const IR::F16F32F64 deviation{ir.FPAdd(base, ir.FPAdd(frag_coord, ir.FPNeg(floor)))};
ir.ConvertFToU(32, ir.FPAdd(base, ir.FPAdd(frag_coord, ir.FPNeg(floor))))}; return IR::U32{ir.Select(is_scaled, ir.ConvertFToU(32, deviation), value)};
return IR::U32{ir.Select(is_scaled, deviation, value)};
} }
[[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, const IR::U1& is_scaled, IR::U32 value) { [[nodiscard]] IR::U32 DownScale(IR::IREmitter& ir, const IR::U1& is_scaled, const IR::U32& value) {
IR::U32 scaled_value{value}; IR::U32 scaled_value{value};
bool changed{};
if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) { if (const u32 down_shift = Settings::values.resolution_info.down_shift; down_shift != 0) {
scaled_value = ir.ShiftLeftLogical(scaled_value, ir.Imm32(down_shift)); scaled_value = ir.ShiftLeftLogical(scaled_value, ir.Imm32(down_shift));
changed = true;
} }
if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) { if (const u32 up_scale = Settings::values.resolution_info.up_scale; up_scale != 1) {
scaled_value = ir.IDiv(scaled_value, ir.Imm32(up_scale)); scaled_value = ir.IDiv(scaled_value, ir.Imm32(up_scale));
changed = true;
} }
if (changed) {
return IR::U32{ir.Select(is_scaled, scaled_value, value)}; return IR::U32{ir.Select(is_scaled, scaled_value, value)};
} else {
return value;
}
} }
void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) { void PatchImageQueryDimensions(IR::Block& block, IR::Inst& inst) {
@ -267,9 +249,12 @@ void Visit(const IR::Program& program, IR::Block& block, IR::Inst& inst) {
} // Anonymous namespace } // Anonymous namespace
void RescalingPass(IR::Program& program) { void RescalingPass(IR::Program& program) {
const bool is_fragment_shader{program.stage == Stage::Fragment};
if (is_fragment_shader) {
for (IR::Block* const block : program.post_order_blocks) { for (IR::Block* const block : program.post_order_blocks) {
for (IR::Inst& inst : block->Instructions()) { for (IR::Inst& inst : block->Instructions()) {
VisitMark(program, inst); VisitMark(inst);
}
} }
} }
for (IR::Block* const block : program.post_order_blocks) { for (IR::Block* const block : program.post_order_blocks) {