mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 17:59:58 -04:00
58 lines
2.8 KiB
Diff
58 lines
2.8 KiB
Diff
--- a/src/Ryujinx.Graphics.Shader/StructuredIr/AstOptimizer.cs
|
|
+++ b/src/Ryujinx.Graphics.Shader/StructuredIr/AstOptimizer.cs
|
|
@@ -22,7 +22,12 @@
|
|
{
|
|
if (node is AstAssignment assignment && assignment.Destination is AstOperand propVar)
|
|
{
|
|
- bool isWorthPropagating = propVar.Uses.Count == 1 || IsWorthPropagating(assignment.Source);
|
|
+ // NX2NAVI (2026-10-16): an atomic / call / image atomic whose result is unused (Maxwell RED, ATOM with
|
|
+ // an RZ destination) stays a statement in place: propagating it would move the side effect to its
|
|
+ // use, and removing the assignment removed the operation itself (the reduction kernel c7830fac
|
|
+ // lost its atomicMin on 2026-10-13; every translation ran in DebugMode since, to avoid this).
|
|
+ bool sideEffects = HasSideEffects(assignment.Source);
|
|
+ bool isWorthPropagating = !sideEffects && (propVar.Uses.Count == 1 || IsWorthPropagating(assignment.Source));
|
|
|
|
// NX2NAVI: SPIR-V passes call arguments by pointer to a variable (StructuredProgram copies them
|
|
// into temporaries); folding an expression into a call argument breaks GenerateCall.
|
|
@@ -33,7 +38,7 @@
|
|
PropagateExpression(propVar, assignment.Source);
|
|
}
|
|
|
|
- if (propVar.Type == OperandType.LocalVariable && propVar.Uses.Count == 0)
|
|
+ if (propVar.Type == OperandType.LocalVariable && propVar.Uses.Count == 0 && !sideEffects)
|
|
{
|
|
visitor.Block.Remove(assignment);
|
|
|
|
@@ -46,6 +51,31 @@
|
|
RemoveEmptyBlocks(mainBlock);
|
|
}
|
|
|
|
+ private static bool HasSideEffects(IAstNode source)
|
|
+ {
|
|
+ if (source is AstOperation op)
|
|
+ {
|
|
+ switch (op.Inst & Instruction.Mask)
|
|
+ {
|
|
+ case Instruction.AtomicAdd:
|
|
+ case Instruction.AtomicAnd:
|
|
+ case Instruction.AtomicCompareAndSwap:
|
|
+ case Instruction.AtomicMaxS32:
|
|
+ case Instruction.AtomicMaxU32:
|
|
+ case Instruction.AtomicMinS32:
|
|
+ case Instruction.AtomicMinU32:
|
|
+ case Instruction.AtomicOr:
|
|
+ case Instruction.AtomicSwap:
|
|
+ case Instruction.AtomicXor:
|
|
+ case Instruction.Call:
|
|
+ case Instruction.ImageAtomic:
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return false;
|
|
+ }
|
|
+
|
|
private static bool IsWorthPropagating(IAstNode source)
|
|
{
|
|
if (source is not AstOperation srcOp)
|