--- a/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Optimizations/GlobalToStorage.cs @@ -960,11 +960,16 @@ private static Operand GenerateAtomicCasLoop(EmitterContext context, Operand wordOffset, int binding, Func opCallback) { + // NX2NAVI: the word is loaded once; a failed compare-and-swap returns the word's current value, which becomes + // the next attempt's expected value. A plain load in every attempt could keep returning a stale cached copy + // (seen on AMD), so an invocation that lost the race never matched again and the loop did not end. Operand lblLoopHead = Label(); + Operand oldValue = Local(); + context.Copy(oldValue, context.Load(StorageKind.StorageBuffer, binding, Const(0), wordOffset)); + context.MarkLabel(lblLoopHead); - Operand oldValue = context.Load(StorageKind.StorageBuffer, binding, Const(0), wordOffset); Operand newValue = opCallback(oldValue); Operand casResult = context.AtomicCompareAndSwap( @@ -977,6 +982,7 @@ Operand casFail = context.ICompareNotEqual(casResult, oldValue); + context.Copy(oldValue, casResult); context.BranchIfTrue(lblLoopHead, casFail); return oldValue;