mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-24 21:55:57 +00:00
SPIR-V leaves a register read before any write undefined and Mesa folds undefined values freely. The unconditional patch 0014 guarded against that and was taken out in #701 because the whole picture shook with DLSS on NVIDIA. Patch 0016 brings the zero start back behind a zero_locals job flag, which vk_caps_driver turns on for RADV, ANV and NVK. TOTK_ZERO_LOCALS overrides it, and gfx_shader_set_host mixes it into the translator identity so the variant has its own cache keys. FXAA_FS gains the flag-on hash of the game's FXAA shader, so vk_dlaa_skip_draw knows it on Mesa too. A game run with TOTK_ZERO_LOCALS=1 on an RX 9070 produced that hash; a TOTK_FXAA=0 run logged no skip with either hash, so the switch itself is not confirmed. All 29736 stored 1.4.3 inputs translate with the flag off and on, 0 spirv-val failures. FXAA hashes to 5c43ae18948d52cb with the flag off and aad42238801d31d8 with it on. Flag-on output matches the old translator byte for byte on a sample of 312 shaders. Not run on a Mesa driver. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
3.8 KiB
Diff
72 lines
3.8 KiB
Diff
--- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs
|
|
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Declarations.cs
|
|
@@ -33,8 +33,14 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
|
|
{
|
|
foreach (AstOperand local in function.Locals)
|
|
{
|
|
- SpvInstruction localPointerType = context.TypePointer(StorageClass.Function, context.GetType(local.VarType));
|
|
- SpvInstruction spvLocal = context.Variable(localPointerType, StorageClass.Function);
|
|
+ SpvInstruction localType = context.GetType(local.VarType);
|
|
+ SpvInstruction localPointerType = context.TypePointer(StorageClass.Function, localType);
|
|
+
|
|
+ // TOTK: on hosts that ask for it (Mesa's compilers fold undefined values freely), a register read on a
|
|
+ // path that did not write it reads 0 instead of an undefined value.
|
|
+ SpvInstruction spvLocal = context.HostCapabilities.ZeroLocals
|
|
+ ? context.Variable(localPointerType, StorageClass.Function, context.ConstantNull(localType))
|
|
+ : context.Variable(localPointerType, StorageClass.Function);
|
|
|
|
context.AddLocalVariable(spvLocal);
|
|
context.DeclareLocal(local, spvLocal);
|
|
--- a/src/Ryujinx.Graphics.Shader/IGpuAccessor.cs
|
|
+++ b/src/Ryujinx.Graphics.Shader/IGpuAccessor.cs
|
|
@@ -188,6 +188,9 @@ namespace Ryujinx.Graphics.Shader
|
|
// the user output location it went to (-1: none) and the banks the position depends on (bit n: cn).
|
|
bool QueryMotionPrevious() => false;
|
|
|
|
+ // TOTK: true when function-local variables start at 0 (CodeGen/Spirv/Declarations.cs DeclareLocals).
|
|
+ bool QueryZeroLocals() => false;
|
|
+
|
|
void ReportMotionPrevious(int location, int banks)
|
|
{
|
|
}
|
|
--- a/src/Ryujinx.Graphics.Shader/Translation/HostCapabilities.cs
|
|
+++ b/src/Ryujinx.Graphics.Shader/Translation/HostCapabilities.cs
|
|
@@ -12,6 +12,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|
public readonly bool SupportsShaderNonUniformIndexing;
|
|
public readonly bool SupportsTextureShadowLod;
|
|
public readonly bool SupportsViewportMask;
|
|
+ public readonly bool ZeroLocals;
|
|
|
|
public HostCapabilities(
|
|
bool reducedPrecision,
|
|
@@ -23,7 +24,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|
bool supportsShaderFloat64,
|
|
bool supportsShaderNonUniformIndexing,
|
|
bool supportsTextureShadowLod,
|
|
- bool supportsViewportMask)
|
|
+ bool supportsViewportMask,
|
|
+ bool zeroLocals)
|
|
{
|
|
ReducedPrecision = reducedPrecision;
|
|
SupportsFragmentShaderInterlock = supportsFragmentShaderInterlock;
|
|
@@ -35,6 +37,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|
SupportsShaderNonUniformIndexing = supportsShaderNonUniformIndexing;
|
|
SupportsTextureShadowLod = supportsTextureShadowLod;
|
|
SupportsViewportMask = supportsViewportMask;
|
|
+ ZeroLocals = zeroLocals;
|
|
}
|
|
}
|
|
}
|
|
--- a/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
|
|
+++ b/src/Ryujinx.Graphics.Shader/Translation/TranslatorContext.cs
|
|
@@ -372,7 +372,8 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|
GpuAccessor.QueryHostSupportsShaderFloat64(),
|
|
GpuAccessor.QueryHostSupportsShaderNonUniformIndexing(),
|
|
GpuAccessor.QueryHostSupportsTextureShadowLod(),
|
|
- GpuAccessor.QueryHostSupportsViewportMask());
|
|
+ GpuAccessor.QueryHostSupportsViewportMask(),
|
|
+ GpuAccessor.QueryZeroLocals());
|
|
|
|
CodeGenParameters parameters = new CodeGenParameters(attributeUsage, definitions, resourceManager.Properties, hostCapabilities, GpuAccessor, Options.TargetApi);
|
|
|