Android: NaN-free float color outputs against the top-of-screen flicker blocks; TBDR clears; mprotect ENOMEM fix

- Shader translator (Vulkan pack only): pixel shaders store 0 instead of NaN in
  float color outputs (XLATE_NAN_OUT=0 disables). ps_foliage occasionally writes
  NaN pixels on Adreno; the downsample / bloom chain spread them into blocks.
  Float min/max/clamp use NMin/NMax/NClamp like Maxwell FMNMX / .SAT
  (XLATE_NAN_MINMAX=0 disables).
- Vulkan backend: pending full clears become loadOp=CLEAR (DM_NVN_TBDR=0
  disables); TBDR / store profile stats; per-batch command pools and query reset.
- Trace diagnostics: NaN / Inf scan of float targets (DM_VK_NANSCAN_PS,
  DM_VK_NANSCAN_BOX), burst readback of the top rows (DM_VK_BURST*).
- nvn_dirty: protection unit max(pagesize, 16K) to stay under the VMA limit
  (mprotect ENOMEM crash); log the process mapping count.
- Upload-MB stat underflow fix; t_vk_perf test fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-14 19:36:26 +09:00
co-authored by Claude Opus 5.5
parent 3c25cd89fc
commit 1ceeeaba77
12 changed files with 396 additions and 24 deletions
@@ -333,6 +333,13 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
private static OperationResult GenerateClamp(CodeGenContext context, AstOperation operation)
{
// NaN 安全:Maxwell 的 .SAT / FMNMX 遇 NaN 取另一操作数(饱和得 0),GLSL FClamp/FMax/FMin 遇 NaN 未定义(Adreno 原样传出 NaN)
// NaN-safe: Maxwell .SAT / FMNMX take the other operand on NaN (saturate gives 0); GLSL FClamp/FMax/FMin are undefined on NaN (Adreno passes the NaN through)
if (context.HostCapabilities.NanSafeMinMax)
{
return GenerateTernary(context, operation, context.GlslNClamp, context.Delegates.GlslSClamp);
}
return GenerateTernary(context, operation, context.Delegates.GlslFClamp, context.Delegates.GlslSClamp);
}
@@ -953,6 +960,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
private static OperationResult GenerateMaximum(CodeGenContext context, AstOperation operation)
{
if (context.HostCapabilities.NanSafeMinMax)
{
return GenerateBinary(context, operation, context.GlslNMax, context.Delegates.GlslSMax);
}
return GenerateBinary(context, operation, context.Delegates.GlslFMax, context.Delegates.GlslSMax);
}
@@ -969,6 +981,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
private static OperationResult GenerateMinimum(CodeGenContext context, AstOperation operation)
{
if (context.HostCapabilities.NanSafeMinMax)
{
return GenerateBinary(context, operation, context.GlslNMin, context.Delegates.GlslSMin);
}
return GenerateBinary(context, operation, context.Delegates.GlslFMin, context.Delegates.GlslSMin);
}
@@ -1678,7 +1695,21 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
if (isStore)
{
context.Store(pointer, context.Get(varType, operation.GetSource(operation.SourcesCount - 1)));
SpvInstruction value = context.Get(varType, operation.GetSource(operation.SourcesCount - 1));
// 浮点颜色输出里的 NaN 换成 0(主机要求时):浮点目标里一个 NaN 像素会被降采样 / bloom 链扩成一整块
// NaN in float color outputs becomes 0 (when the host asks): one NaN pixel in a float target is spread into a whole block by downsample / bloom chains
if (context.HostCapabilities.NanFreeColorOutput &&
varType == AggregateType.FP32 &&
operation.StorageKind == StorageKind.Output &&
operation.GetSource(0) is AstOperand { Type: OperandType.Constant } ioId &&
(IoVariable)ioId.Value == IoVariable.FragmentOutputColor)
{
SpvInstruction isNan = context.IsNan(context.TypeBool(), value);
value = context.Select(context.TypeFP32(), isNan, context.Constant(context.TypeFP32(), 0f), value);
}
context.Store(pointer, value);
return OperationResult.Invalid;
}
else
@@ -184,6 +184,24 @@ namespace Ryujinx.Graphics.Shader
return false;
}
/// <summary>
/// Queries host about whether float min/max/clamp must use NaN-aware semantics (Maxwell FMNMX and .SAT never return NaN when the other operand is a number).
/// </summary>
/// <returns>True to emit NMin/NMax/NClamp instead of FMin/FMax/FClamp, false otherwise</returns>
bool QueryHostNanSafeMinMax()
{
return false;
}
/// <summary>
/// Queries host about whether NaN written to a float fragment color output must be replaced by zero (a NaN pixel in a float target is spread into a block by downsample / bloom chains).
/// </summary>
/// <returns>True to store zero instead of NaN in float fragment color outputs, false otherwise</returns>
bool QueryHostNanFreeColorOutput()
{
return false;
}
/// <summary>
/// Queries host about the presence of the FrontFacing built-in variable bug.
/// </summary>
@@ -3,6 +3,8 @@ namespace Ryujinx.Graphics.Shader.Translation
class HostCapabilities
{
public readonly bool ReducedPrecision;
public bool NanSafeMinMax;
public bool NanFreeColorOutput;
public readonly bool SupportsFragmentShaderInterlock;
public readonly bool SupportsFragmentShaderOrderingIntel;
public readonly bool SupportsGeometryShaderPassthrough;
@@ -368,6 +368,9 @@ namespace Ryujinx.Graphics.Shader.Translation
GpuAccessor.QueryHostSupportsTextureShadowLod(),
GpuAccessor.QueryHostSupportsViewportMask());
hostCapabilities.NanSafeMinMax = GpuAccessor.QueryHostNanSafeMinMax();
hostCapabilities.NanFreeColorOutput = GpuAccessor.QueryHostNanFreeColorOutput();
CodeGenParameters parameters = new CodeGenParameters(attributeUsage, definitions, resourceManager.Properties, hostCapabilities, GpuAccessor, Options.TargetApi);
return Options.TargetLanguage switch