diff options
| author | 2021-03-21 21:56:27 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:24 -0400 | |
| commit | 2be5c7eff40647344da7951dc5e20a7deebf78aa (patch) | |
| tree | 50a0ba9e2b1cedccfceadf6b73f4b14743a33a60 /src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |
| parent | shader: Better but still partial interpolation support (diff) | |
| download | yuzu-2be5c7eff40647344da7951dc5e20a7deebf78aa.tar.gz yuzu-2be5c7eff40647344da7951dc5e20a7deebf78aa.tar.xz yuzu-2be5c7eff40647344da7951dc5e20a7deebf78aa.zip | |
shader: Fold interpolation multiplications
Diffstat (limited to 'src/shader_recompiler/ir_opt/constant_propagation_pass.cpp')
| -rw-r--r-- | src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp index ef7766d22..3dab424f6 100644 --- a/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir_opt/constant_propagation_pass.cpp | |||
| @@ -236,6 +236,38 @@ void FoldSelect(IR::Inst& inst) { | |||
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | void FoldFPMul32(IR::Inst& inst) { | ||
| 240 | const auto control{inst.Flags<IR::FpControl>()}; | ||
| 241 | if (control.no_contraction) { | ||
| 242 | return; | ||
| 243 | } | ||
| 244 | // Fold interpolation operations | ||
| 245 | const IR::Value lhs_value{inst.Arg(0)}; | ||
| 246 | const IR::Value rhs_value{inst.Arg(1)}; | ||
| 247 | if (lhs_value.IsImmediate() || rhs_value.IsImmediate()) { | ||
| 248 | return; | ||
| 249 | } | ||
| 250 | IR::Inst* const lhs_op{lhs_value.InstRecursive()}; | ||
| 251 | IR::Inst* const rhs_op{rhs_value.InstRecursive()}; | ||
| 252 | if (lhs_op->Opcode() != IR::Opcode::FPMul32 || rhs_op->Opcode() != IR::Opcode::FPRecip32) { | ||
| 253 | return; | ||
| 254 | } | ||
| 255 | const IR::Value recip_source{rhs_op->Arg(0)}; | ||
| 256 | const IR::Value lhs_mul_source{lhs_op->Arg(1).Resolve()}; | ||
| 257 | if (recip_source.IsImmediate() || lhs_mul_source.IsImmediate()) { | ||
| 258 | return; | ||
| 259 | } | ||
| 260 | IR::Inst* const attr_a{recip_source.InstRecursive()}; | ||
| 261 | IR::Inst* const attr_b{lhs_mul_source.InstRecursive()}; | ||
| 262 | if (attr_a->Opcode() != IR::Opcode::GetAttribute || | ||
| 263 | attr_b->Opcode() != IR::Opcode::GetAttribute) { | ||
| 264 | return; | ||
| 265 | } | ||
| 266 | if (attr_a->Arg(0).Attribute() == attr_b->Arg(0).Attribute()) { | ||
| 267 | inst.ReplaceUsesWith(lhs_op->Arg(0)); | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 239 | void FoldLogicalAnd(IR::Inst& inst) { | 271 | void FoldLogicalAnd(IR::Inst& inst) { |
| 240 | if (!FoldCommutative<bool>(inst, [](bool a, bool b) { return a && b; })) { | 272 | if (!FoldCommutative<bool>(inst, [](bool a, bool b) { return a && b; })) { |
| 241 | return; | 273 | return; |
| @@ -348,6 +380,8 @@ void ConstantPropagation(IR::Block& block, IR::Inst& inst) { | |||
| 348 | case IR::Opcode::SelectF32: | 380 | case IR::Opcode::SelectF32: |
| 349 | case IR::Opcode::SelectF64: | 381 | case IR::Opcode::SelectF64: |
| 350 | return FoldSelect(inst); | 382 | return FoldSelect(inst); |
| 383 | case IR::Opcode::FPMul32: | ||
| 384 | return FoldFPMul32(inst); | ||
| 351 | case IR::Opcode::LogicalAnd: | 385 | case IR::Opcode::LogicalAnd: |
| 352 | return FoldLogicalAnd(inst); | 386 | return FoldLogicalAnd(inst); |
| 353 | case IR::Opcode::LogicalOr: | 387 | case IR::Opcode::LogicalOr: |