REVIEW RESPONSE, 15 Sep 2026
THE GATE NEVER PERFORMED A DEPTH COMPARISON, AND THE ACCURACY WIN WAS THE FIXTURE

Written against REVIEW_2026-09-15_WHAT_TO_TRUST_AND_WHAT_TO_CHECK.txt, working
through its section 6 list. Read section 1 of that file first; this is the
reply to it.

Changed in the working tree, uncommitted:
    diagnostics/jsrf_first_fault/metal_batch_test.c    phase F, and the fixture
    diagnostics/jsrf_first_fault/metal_hw_check.sh     two phases, three arms
    src/nv2a/nv2a_metal.m                              one crash fix

ctest 30/30. metal_hw_check PASS. metal_batch_check IDENTICAL. Full build clean.


1. THE HEADLINE FOR THE REVIEWED
=================================
The handover asked me to satisfy myself that a gate passing on a broken
renderer is the finding rather than the tool. It is both, and worse than
stated: metal_batch_test has never performed a depth COMPARISON, on either
path, in any phase.

Two fixture defects, each hiding the other:

  * Every phase sets `s.depth_func = 4`. That is a D3D-style D3DCMP_LESSEQUAL;
    the NV2A encodes compare functions in the 0x200 range, so
    nv2a_metal_compare_func returns -1 and BOTH paths fall back to ALWAYS. The
    code comment at nv2a_metal.m:982 says this outright. Nobody connected it
    to the gate that reads the test's output.

  * base_state() builds the state with memset(0), leaving
    z_clip_min == z_clip_max == 0. The software path clamps every fragment
    into that range when z_cull is off, so ALL of its depth was zero.
    nv2a_texture_copy.c:76 normalises that pair back to [0, 16777215] when it
    decodes the guest registers, so no real draw can reach the backend with
    it. Only a fixture filling the struct by hand could.

With no depth to compare and no comparison to make, the depth half of the gate
measured nothing. The proof is a negative control: injecting
`d.depthCompareFunction = MTLCompareFunctionAlways` into hw_depth_state_for --
breaking depth testing outright on the hardware path -- produced a PASS with
numbers identical to the last digit.

WHICH MEANS THE ACCURACY CLAIM WAS THE ARTIFACT. metal_hw_check.sh's own
comment reads:

    software state    1 of 65536 pixels,  54091 of 262144 depth bytes differ
    hardware state    1 of 65536 pixels,     25 of 262144 depth bytes differ

and concludes the hardware path "is the BETTER approximation" because it "takes
z from the rasteriser's own depth interpolation, which is what the NV2A does".
The 54091 is the software path being fed a depth range it clamps everything
into. Give the fixture a legal range and the same two arms read:

    software state    24 of 262144 depth bytes differ
    hardware state    25 of 262144 depth bytes differ

deterministic over three runs each. The gap is one byte, the other way. The
hardware path may still be the better approximation for the reason given, but
this measurement has never shown it and the sentence should not survive.


2. WHAT THE GATE ACTUALLY MISSED, WHICH IS NOT WHAT SECTION 5 GUESSED
=====================================================================
Section 1 of the handover said "NOTHING SCORED A FRAME FROM A REAL RUN". True,
and there is a smaller, cheaper statement inside it: nothing scored a surface
swap either, and the reason is not the one recorded.

The handover says "the synthetic test changes surface once". It does not.
metal_batch_test phase D alternates two render targets forty times, on purpose,
with a comment explaining why. What is missing is the SCORE: the only oracle
comparison in the program is phase A, and phase A never changes surface. D is
compared batched-against-per-draw, which is orthogonal to whether either is
right. metal_hw_check.sh reads phase A's numbers, so the swap was invisible to
it.

Second hole, not noticed anywhere: metal_hw_check.sh never set
RECOMP_METAL_565. The configuration reported broken is HW=1 AND 565=1 -- a
different attachment format, a different upload path and a different readback
path -- and the gate scored neither arm of it.

Both are now closed. Phase F draws 120 triangles across THREE alternating
surfaces (the count the title holds) with a real guest LEQUAL, scored against
the rasteriser; metal_hw_check.sh scores phase A and phase F across three arms.


3. THE RESULT, WHICH DOES NOT SUPPORT THE LEADING HYPOTHESIS
=============================================================
                        pixels    beyond one   worst    depth
                        differ    step         step     bytes
    phase A, one surface
      software state         1         0          1        24
      hardware state         1         0          1        25
      hardware + 565       697         0          1        25
    phase F, three surfaces
      software state        29        29         52       109
      hardware state        29        29         52       109
      hardware + 565      1513        29         52       109

Three genuinely distinct arms -- and that took two attempts, because zsh does
not word-split an unquoted variable, so my first sweep ran the same
configuration in two of the three arms and produced identical numbers I nearly
reported. The same defect the handover documents twice, in the tooling built to
catch it.

Read it as follows.

  * THE THREE-SURFACE SWAP DOES NOT REPRODUCE IT. Every arm scores the same 29
    pixels beyond one channel step and the same 109 depth bytes. The retained-
    surface machinery is shared by both state paths, and it behaves the same in
    both. Section 5 item 1's first suspect is not supported by this test.

  * 565's EXTRA PIXELS CONFORM. 697 and 1513 pixels differ, and every one of
    them is within one RGB565 channel step -- the rule the D3D11 backend was
    admitted under. A count-based gate would have failed the format for being
    the guest's own format. This is why the rule is now magnitude.

  * THE 29 PIXELS ARE NOT A SWAP DEFECT. They are scattered singletons across
    all three surfaces (10/14/22), present with blending off, present with
    depth testing off, and present with ONE surface. They scale with the number
    of triangle edges drawn, which is what a rasteriser coverage disagreement
    does.

So the wrong image at a real mission is still unexplained, and the surface
swap is now evidence against rather than a lead. What this gate STILL does not
exercise, and a real mission does: register combiners, alpha test, stencil,
multi-texture. That is where I would look next.


4. SECTION 5 ITEM 1's SECOND SUSPECT IS VOID -- DO NOT SPEND A BOOT ON IT
=========================================================================
"setDepthClipMode:MTLDepthClipModeClamp at the draw site ... added
speculatively ... Revert it first and re-test."

It cannot be the difference, and reverting it cannot change anything, because
the clamp is already applied to BOTH paths. nv2a_metal.m:2064 sets it
unconditionally on the encoder, before the `if(hw)` branch, and has since the
13 Sep depth-clipping retraction -- with a paragraph explaining that the
fragment shader now owns the guest's SET_CLIP_MIN/MAX policy and hardware
clipping would pre-empt it. The call inside the hw branch is a SECOND call, on
the same encoder object, setting the same value. It is dead code.

Removing the hw-path call: no behavioural change. Removing the unconditional
one: changes both paths equally, so it still cannot explain a difference
between them.


5. A REAL CRASH, FOUND AND FIXED
=================================
    RECOMP_METAL_HW=1 RECOMP_METAL_BATCH=1 jsrf_metal_batch_test   ->  SIGSEGV

nv2a_metal_draw bound `encoder` to the open batch encoder, then -- eighty lines
later, after already issuing setDepthClipMode on it -- called batch_flush() to
honour "a batch encoder is opened from ONE pass descriptor". batch_flush() ends
the encoder, commits its command buffer and nils batch_encoder. The local
`encoder` still pointed at it, so every setRenderPipelineState, setVertexBuffer
and drawPrimitives below went to an encoder that was already ended.

It fires on the FIRST hardware draw of any process, every time:
batch_encoder_hw is a static initialised to 0, hw is 1, so the very first
hardware draw always takes the flush branch.

Nothing saw it because no gate combines the two switches. metal_batch_check.sh
runs RECOMP_METAL_BATCH with the hardware path off; metal_hw_check.sh runs
RECOMP_METAL_HW with batching off.

Fixed by moving the check above the encoder acquisition, where the comment
always said it belonged ("batch_flush() BEFORE switching"). After the fix the
batched hardware path runs clean and its dump is byte-identical to the per-draw
hardware path.


6. THE getenv SWEEP
====================
37 distinct variables are tested for PRESENCE with `getenv("RECOMP_...") ? 1 : 0`.
26 are traces, audits, reports and dumps, where presence is the correct test
and a value would be meaningless. Eleven change what the program DOES, and for
those a value is required:

    RECOMP_PB_EXEC              nv2a_pusher.c:78        the pushbuffer executor
    RECOMP_PB_EXEC_NOCLIPTEST   nv2a_pb_exec.c:2880     suppresses a draw guard
    RECOMP_LEGACY_ZCLAMP        nv2a_metal.m:2019       forces the old z policy
    RECOMP_FB_LIVE              nv2a_pb_exec.c:1222     which framebuffer is read
    RECOMP_HEAP_NO_FREE         xbox_memory_layout.c:5865  disables heap free
    RECOMP_D3D11_RESIDENT_CLEARS nv2a_d3d11.c:375
    RECOMP_D3D11_SYNC_EACH      nv2a_d3d11.c:1869
    RECOMP_IRQ_THREAD_GPU       kernel_bridge.c:3633
    RECOMP_FAKE_PAD             xinput_device.c:512
    RECOMP_PAD_INJECT           main.c:1857
    RECOMP_OHCI_MIE             xbox_memory_layout.c:553

RECOMP_PB_EXEC is the one that matters. It is the master switch for the whole
NV2A executor, it appears as `RECOMP_PB_EXEC=1` in CLAUDE.md's own run line,
and `RECOMP_PB_EXEC=0` would leave it ON -- a control arm that is not a
control, on the most load-bearing switch in the project.

RECOMP_OHCI_MIE is the sharpest trap: the comment beside it literally reads
"RECOMP_OHCI_MIE=1 also sets MasterInterruptEnable", and =0 sets it too.

Nothing in the tree currently passes =0 to any of the eleven, so no live
measurement is wrong because of this. Converting them to `atoi(e) != 0` is
mechanical; RECOMP_LEGACY_ZCLAMP is the urgent one because it is a documented
A/B arm ("RECOMP_LEGACY_ZCLAMP=1 forces the old saturate-instead-of-discard
policy, to A/B the change in one binary") that cannot be A/B'd.


7. RE-SCORING THE ARCHIVE
==========================
"Scoring is a pure function of a log, so every archived run can be re-scored."
True of the log. NOT true of `--summarise`, which reads RESULTS.txt -- the
OUTPUT of scoring, frozen at run time. A harvester added afterwards cannot
reach it. Re-summarising the archive reports "arms NOT verified distinct" for
runs whose arms were perfectly distinct.

Re-scored properly, from each arm's stderr.log:

  RECOMP_METAL_HW (metalhw_ab_20260915-181457)
      ARMS VERIFIED DISTINCT -- =0 reported "metal_hw OFF", =1 "metal_hw on".
      9.6%, ranges do not overlap, n=3 against n=2. The claim stands, and the
      commit names the stage column (clear 9.61/10.25/11.12 -> 5.76 ms) with a
      mechanism that predicts that column. Passes the section 6 check.

  RECOMP_METAL_565 (m565_ab_184344, m565b_ab_190437)
      STILL NOT VERIFIABLE, and not because of the summariser: the
      "[METAL] colour attachment:" line does not appear in any of the eleven
      logs. It was added after those runs. The commit says so itself, which is
      to its credit. The hardware path WAS on in every arm (hw draws 757k-976k,
      "metal_hw on"), so hw_565_on() could take effect and the switch was not
      inert -- but no evidence in the log says it did. The current binary
      prints it; one re-run closes this.

  RECOMP_METAL_BATCH (batch_ab_20260915-150600)
      THE RANGES OVERLAP. Does not separate the arms. n=3 per arm.

Incidental evidence for section 4's "sized from JSRF uses three" question: at a
real mission the logs report pipelines=4 or 5 and refusals=0, against
HW_CACHE = 16. The pipeline cache is not binding, and that is now measured
rather than assumed.


8. ONE MORE TOOLING TRAP
=========================
metal_batch_check.sh defaults to build-macos/jsrf-first-fault/build.
metal_hw_check.sh defaults to build-macos/jsrf-first-fault/build-feav.

Two sibling gates over the same binary, pointing at different build trees. It
bit me during this review: metal_batch_check.sh reported "5 phases" and the old
54091 figure from a stale binary while I was looking at a six-phase one. Pass
JSRF_BUILD, or give them the same default.


9. WHAT WAS DONE NEXT, AND WHAT IT FOUND
=========================================
Items 2, 3 and 5 below are now done and committed. Their results change the
picture again, so they are recorded here rather than left in the commits.

THE STATE COVERAGE ALREADY EXISTED, IN A TEST NOTHING RAN. Before writing a
phase G for combiners, alpha test and stencil, it was worth checking what was
already there: metal_copy_test compares the backend against the rasteriser with
an exact memcmp across combiners at one stage and two, alpha test, stencil with
real ops, multi-texture, DXT1, DXT3, mip selection, untextured draws and dither.
It is built on Apple and registered with nothing -- out of ctest because it
needs a GPU, and with no check script, unlike metal_batch_test. So the broadest
state coverage in the tree had never been executed, which is the same shape as
the phase-A-only problem in section 2.

Run across the three arms:

    software state    FAILS at line 49 -- the depth readback after a
                      depth-tested draw, known and tracked
    hardware state    exact match
    hardware + 565    exact match

That is the strongest result of this review. Combiners, alpha test, stencil and
multi-texture are BYTE-EXACT on the hardware path, and the software path is the
one that misses. It is also the evidence the retracted 54091 was standing in
for, and a stronger claim than that ever was, because it is exact equality
rather than a tolerance.

And it narrows the remaining space sharply. Every per-draw state translation a
mission uses is now known correct in isolation on the hardware path. The wrong
image is therefore NOT a mistranslated combiner, blend factor, stencil op or
compare function. What is left is behaviour over time or at scale: the retained
surface across frames, the clear/flip interaction, the presenter round trip --
none of which any device test reaches, because they all begin from
nv2a_metal_invalidate and run a few dozen draws.

THE SWITCH SWEEP HAD TO BE WIDER THAN THE PATTERN. RECOMP_PB_EXEC is read in
four places in three spellings; the `? 1 : 0` form the handover named finds one
of them. Ten behavioural switches now go through recomp_switch_on(), which
treats "0" and empty as off and everything else as on -- the conservative
conversion, so nothing that turns a switch on today changes. RECOMP_FAKE_PAD
stays on presence and is annotated to say why: its value is meaningful (1, <n>,
`a`, `always`) and an atoi() conversion would silently disable `=a`.

I also nearly filed a fourth instance that was not one. RECOMP_OHCI_ATTACH
looked presence-tested to the pattern match, and oracle_anchor.sh's
ORACLE_NO_OHCI_ATTACH writes RECOMP_OHCI_ATTACH=0 -- which looked like a live
broken control arm. Reading the predicate rather than the grep shows it already
excludes "0" and the empty string, and main.c's two `!getenv` sites are a
default-setter, not a gate. The rule that catches counters catches greps too.


10. THE CAUSE OF THE FLICKERING CHECKERBOARD
=============================================
FOUND, AND IT IS NOT A FRAME-BOUNDARY PROBLEM AT ALL. It is one draw, and the
gate could have caught it on day one if the fixture had set one field.

base_state() builds its state with memset(0), so s.dither was 0 in every phase
of the only test that scores an image. The one code path in this renderer that
produces a literal 4x4 lattice had never been executed. That is the THIRD
fixture field found this way, after depth_func = 4 and the zeroed clip range,
and it is the one that mattered.

Set it and the paths separate at once:

                        pixels differ   beyond one step   4x4 dither cells
    software state            0                0            0 / 0
    hardware state         8192               19           77 / 857
    hardware + 565         8402               19           93 / 878

The software path becomes EXACT -- 0 of 65536, worst error 0 steps, better than
the 1 pixel it scored with dither off. Dither is not noise; it is something the
oracle does and the gate was not asking about.

THE MECHANISM. The two fragment shaders apply the dither at different stages:

    fs      shade -> blend (in shader) -> dither -> store
    fs_hw   shade -> dither -> return  -> [blend unit] -> store

The NV2A dithers at the ROP, after blending. fs does that, and so does
nv2a_texture_copy.c at its store. fs_hw hands the biased colour to the
fixed-function blend unit instead, so the +/-0.5 LSB nudge is multiplied by the
source blend factor and mixed with a destination that already carries its own
baked-in bias, instead of being applied once at quantisation.

MEASURED, NOT INFERRED, and this is the part that makes it certain:

    dither ON, blending OFF     hardware scores 0 of 65536 -- exact
    dither ON, blending ON      hardware scores 8192

The error exists only where both are active. That is the ordering and nothing
else.

AND IT IS A PATTERN, NOT MORE NOISE. The emptiest and fullest of the sixteen
4x4 dither cells hold 77 and 857 differing pixels. Coverage disagreement -- the
kind every other phase carries -- fills all sixteen evenly. An order of
magnitude apart is the dither matrix's own shape, and the test now reports that
cell range so the distinction needs no image.

That is the flickering checkerboard: a 4x4 lattice error that compounds with
each overlapping blended layer, over backgrounds that are mostly overlapping
blended layers, changing frame to frame as the camera changes how many overlap.

FIXED, with the third pipeline. Metal has no ROP-stage dither and the blend
unit runs after the fragment shader, so a draw that needs dither after blend
has to do the blend in the shader. fs_hw_blend does that and nothing else
differently: it reads the destination, blends with the same bfactor() the
software path uses, dithers after it, and leaves depth and stencil in the real
attachments where the hardware path put them.

                        before                  after
    phase A   hardware  8192 differ, 19 over      0 differ, 0 over   worst 0
              hw + 565  8402 differ, 19 over    515 differ, 0 over   worst 1
    phase F   hardware 23003 differ, 186 over     29 differ, 29 over
              hw + 565 23601 differ, 196 over    932 differ, 29 over

The hardware path is now exactly as close to the rasteriser as the software
path, on both phases, and 565's remainder is entirely within one channel step.
The lattice spread goes from 77/857 to 0/0. metal_hw_check.sh passes again, and
passes because the defect is gone rather than because nobody asked -- the
fixture still sets dither.

Selected only where needed: hw_shader_blend() is blend && dither. Blending
alone keeps the blend unit; dithering alone is already correct in fs_hw,
because with nothing after it the bias IS the last step before quantisation. So
the raster_order_group(0) it re-introduces is paid by dithered blended draws
and nothing else.

Two things that would have been silent bugs. The selector had to go into the
pipeline CACHE KEY -- two draws with identical blend state but differing dither
need different pipelines now, and keying on blend alone would have served one
the other's pipeline. And HW_CACHE went 16 -> 32, because the key gaining a
dimension can double the set and a miss is not a small slowdown: the draw is
rejected and falls back to the CPU rasteriser.

The obvious shortcut was measured and is WORSE: skipping the shader dither when
blending scores 92 pixels beyond one step against the original 19, because the
oracle dithers and the hardware path then would not.

NOT MEASURED, and it gates defaulting anything on: the frame-time cost at a
mission. The serialisation is bounded to dithered blended draws, but what
fraction of a real frame those are is unknown, and the 9.6% the hardware path
was worth should be re-taken. Also unmeasured: the magnitude of the original
defect at scale -- this is 20 blended draws and a mission has far more overlap.


11. THE FRAME-BOUNDARY TRACE, AND WHAT IT FOUND
================================================
Done before the above, and it is how the search got narrow enough to look at a
single draw again. What survives a frame, all of it in nv2a_metal.m and all for
exactly ONE surface:

    surface, stencil_surface, hw_depth_tex, hw_stencil_tex   reallocated per swap
    surface_target / depth_target + geometry + valid/dirty
    hw_pso[16] / hw_dss[16]      keyed caches, never invalidated
    texture_cache[128]           keyed by address AND a full memcmp
    ring slabs, last_command, batch_*

Reset points: the upload block (any pointer or geometry change),
nv2a_metal_sync (readback), nv2a_metal_invalidate(target) (per surface), and
nv2a_metal_discard (which took no target at all -- fixed, see below).

CONFIRMED AND FIXED. nv2a_metal_discard dropped the retained surface without
reading it back and without being told which surface the guest was clearing.
s_gpu.color_offset moves on the register write, surface_target on the next
draw, so a clear in that window names one surface and drops another. Measured
at 24848 of 65536 pixels of finished rendering lost. Latent -- default off, and
the reproducing run reports "clear discards=0" -- so nothing recorded is
affected.

CONFIRMED, NOT FIXED. nv2a_gpu_sync_range(target, bytes) is
#define'd to nv2a_metal_sync() and discards its target. Benign while one
surface is retained; wrong the moment that changes. And hw_565_on() never
consults hw_depth_tex, so a depth-texture allocation failure would leave a
B5G6R5 attachment bound while draws fall to a pipeline built for RGBA32Float --
corruption instead of a clean fallback. Not reachable in any observed run.

UNVERIFIED. The presenter reads s_snap while snapshot_surface() writes it, and
snapshot_surface() can realloc it. dev_Present runs on the render thread; I
could not establish whether the pushbuffer executor is the same thread without
a run.

ELIMINATED WITH EVIDENCE, all of which I had first proposed as causes:
  * clip-origin mismatch -- clip is +0+0 in all 1275 reports of every archived
    mission run
  * texture cache staleness -- a hit requires a full memcmp of the contents
  * pipeline/depth-state cache overflow -- pipelines=4..5, refusals=0, cache 16
  * the batches-vs-hw-draws gap of 7381 -- empty batches returning early, and
    the same 0.6-1.1% rate in all three arms
  * an unordered tile-memory race from dropping raster_order_group(0) --
    fs_hw returns float4 and takes no destination read, so there is nothing to
    race on

ON PROCESS. Four of the six hypotheses in this section died, two of them after
I had written them up as findings rather than as guesses. Nothing false reached
a commit, because each was checked -- but in a project whose recorded failure
mode is believing a number before reading what produced it, generating the
narration ahead of the evidence is the wrong order, and I did it while
reviewing a handover about exactly that. The dither result above is what the
right order looks like: predict, measure with a control (blending off), check
the shape (the lattice), then write it down.


12. WHAT IS STILL OPEN
=======================
  1. RE-TAKE THE FRAME TIME. The dither fix re-introduces raster_order_group(0)
     for dithered blended draws, and the 9.6% and 14.5% both predate it. No
     default should move until that is measured.
  2. Whether the checkerboard fully accounts for what was seen, or only the
     grid half of it. "Solid black rectangles" and "a large black band" are not
     obviously dither, and the [FB] sampler in fbcheck-on shows frames at
     203078 of 307200 nonzero pixels where the control shows 307152. A person
     playing it with the fix in is the cheapest answer.
  3. Watch refusals= in the [METAL] report at a mission. HW_CACHE is 32 now on
     an argument, not a measurement: pipelines=4..5 was measured before the key
     gained a dimension.
  4. RECOMP_SURFACE_AUDIT is built and NOT YET RUN. It answers how often a
     clear names a surface other than the held one, which decides how bad the
     discard defect would have been.
  5. Re-run the 565 A/B on the current binary, which now names its attachment.
  6. Re-run RECOMP_VSH_REUSE properly -- the original handover's item 3.
  7. The software path's metal_copy_test line 49 depth mismatch, now the only
     arm failing an exact comparison.
  8. ab_score.py's SWITCH_TOKEN covers seven switches; RECOMP_METAL_BATCH is an
     A/B arm that is not among them.

13. THE RENDERER REVIEW, AND WHAT THE RUNS COULD NOT REACH
===========================================================
THE DITHER FIX DID NOT FIX THE PICTURE. It is a real defect and it is measured
-- 8192 of 65536 pixels on the dither lattice, software path 0, now 0 on both
-- but a person watching the game reports the artefact unchanged with it in.
Section 10 stands as a correctness fix and is retracted as an explanation.

WHAT THE ARTEFACT ACTUALLY IS, measured from dumped frames rather than from a
description: large black regions, not a 4x4 lattice. Matched capture index,
same scene, RECOMP_FB_DUMP_FLIP:

    HW=0 (default)              165 black pixels of 307200
    HW=1, 565=0              30,705
    HW=1, 565=1              22,412
    HW=1 + depth ALWAYS      50,131
    HW=1 + no stencil        32,885
    HW=1 + all blends in-shader, ordered   20,144

So it is RECOMP_METAL_HW itself, not the 565 attachment, and it is not the
depth unit, the stencil unit, the blend unit or the fragment ordering -- each
was neutered in its own run and the regions stayed. The default path renders
the same frame essentially perfectly.

I also over-read one frame: black runs in it started on a 32-pixel boundary 27%
of the time, which I called tile alignment. The other frames read 0-7%, which
is chance. It is not tile-aligned; it is large regions.

WHAT READING FOUND THAT FIVE RUNS DID NOT. Neither defect is a stage that can
be switched off, which is why the bisect could not reach them:

  * THE DEPTH/STENCIL STATE CACHE KEYED ON NINE FIELDS AND ITS DESCRIPTOR READ
    ELEVEN. stencil_zfail feeds depthFailureOperation, stencil_func_mask feeds
    readMask, and neither was in the key, so two draws differing only in one of
    those were served whichever state was built first. Hardware path only: the
    software tail takes all eleven per draw and caches nothing. Measured at
    8056 of 65536 pixels against the software path's 5. Fixed, phase I.

  * DEPTH WRITES WERE NOT GATED ON THE DEPTH TEST. depthWriteEnabled read
    depth_write alone while the fragment tail derives depth_test && depth_write
    and depth_dirty is marked on the same pair. With the test off cmp is
    already ALWAYS, so an overlay with the mask still set stamped depth over
    everything it covered here and over nothing on the other path -- and
    depth_dirty was not set, so it was never read back and the next surface
    swap re-uploaded over it from stale guest RAM. Fixed, phase H.

A THIRD, RECORDED NOT FIXED: nv2a_texture_copy_blend_factor_supported allows
eight blend factors and the software bfactor implements exactly those eight,
but nv2a_metal_blend_factor maps three more -- DST_ALPHA, ONE_MINUS_DST_ALPHA
and SRC_ALPHA_SATURATED. Not reachable today, because the accept test refuses
them before the sink sees them. It is a drift hazard rather than a bug: widen
the accept test and the hardware path will blend against an alpha channel that
holds the shaded alpha, or depth immediately after an upload, or does not exist
at all under 565, while the software path's bfactor falls through to default.
nv2a_metal_state.c is deliberately standalone for upstreaming, so it should not
learn about the accept test; the two lists want a comment pointing at each
other, or one shared table.

STILL UNEXPLAINED: the black regions. All three defects above are real, all
three are fixed and pinned by a phase, and NONE of them changed the picture. A
200 s run with all three in still reports 46609 and 18613 black pixels on its
two picture frames.

THE MIXED-FRAME LEAD IS NOW DEAD TOO, and it was the best one left. The
depth-ownership comment in nv2a_metal.m describes exactly this symptom -- "every
differing pixel had software 0x000000 against hardware 0xFFFFFF" -- and the
route to it is hw_depth_upload failing, which drops hw to 0 and sends draws down
the software tail without reject() ever seeing it, so refusals= stays 0 and
proves nothing. Counted in a real run:

    MIXED draws (software tail while hw on) = 0
    depth uploads failed                    = 0
    hw draws 518122, batches 522245, refusals 0, fallbacks 0, pipelines 5

Every draw took the hardware branch and no upload ever failed. The 4123 gap
between batches and hw draws is the empty-batch early return, at the same
~0.8% seen in all three arms in section 11.

WHAT IS LEFT, with everything above eliminated. Not the depth unit, the stencil
unit, the blend unit, the fragment ordering, the attachment format, the state
caches, the mixed frame, or any per-draw state translation -- metal_copy_test
puts the hardware path byte-exact against the rasteriser across combiners,
alpha test, stencil, multi-texture, DXT and mips. Every device test agrees
exactly, and a real frame does not.

That gap is the finding. Something the hardware path does is invisible to a
test that submits a few hundred draws to one retained surface and reads it back
immediately, and shows up in a frame of ~40,000 draws across three surfaces
with ~15,000 clears. The next instrument should measure the FRAME rather than
the draw: dump the surface at intervals WITHIN one frame -- RECOMP_FB_DUMP_DRAW
already exists for that -- and find the draw index at which a region that was
correct becomes black. That localises it in the guest's own draw order, which
no synthetic phase can do.


14. WHAT THE PIXELS SAY, WHICH IS NOT WHAT I HAD ASSUMED
=========================================================
The artefact is not missing draws. It is draws that RUN AND OUTPUT BLACK.

Read out of a dumped frame at native RGB565, sky rows 40-43, across a damaged
band at x=52..70 and a clean band at x=300..322:

    clean   74D1 7CF2 74D1 7CF2 ...   sky colour, alternating by one step
    damaged 0000 0000 0800 0000 ...   zero, with 0800 at some positions

0x800 is one step of red and nothing else. Its positions have period 4 in x on
one row, period 2 on the next, and none on the rows between -- which is the 4x4
Bayer matrix. So a draw covered those columns, shaded them to approximately
zero, and the ordered dither then biased some of them up by one step. Geometry
that never rendered would carry no dither at all.

THE SHAPE IS A PICKET FENCE, and that is the "grid". Columns that are >=95%
black run x = 53,55,57...69 and 165,167...201 and 225: one pixel wide, spaced
exactly two apart, every ODD column, in bands. At a distance a one-on
one-off column pattern reads as a grid, which is what a person watching it
called it. It is not tile-aligned and it is not 32-pixel anything -- I claimed
that from one frame in section 13 and the measurement here supersedes it.

WHAT THAT RULES IN. shade() is shared between the two fragment tails, byte for
byte, and so are the Params it reads and the texture buffers it samples. So
either a DIFFERENT draw covers those columns on the hardware path -- a
visibility difference -- or shade()'s inputs differ. Every visibility stage has
been neutered in its own run and the bands survived each: depth compare,
stencil, blend unit, fragment ordering, attachment format.

WHAT IS STILL UNMEASURED, and is where I would look next:

  * WHICH DRAW paints them. RECOMP_FB_DUMP_DRAW captures within a frame but
    counts batches from process start, so it cannot be aimed at a scene 170 s
    in. It needs a start offset -- a few lines -- and then consecutive captures
    either side of the damaged band name the draw in the guest's own order.
  * z_cull. fs() clamps zg into [z_clip_min, z_clip_max] when z_cull is OFF and
    fs_hw does not, so the depth those two store diverges for any draw with
    ZMIN_MAX_CONTROL set to CLAMP. JSRF is recorded as using CULL, but that is
    a whole-title statement and this is a per-draw register. Counting draws with
    z_cull == 0 is one counter and has never been done.
  * Thin geometry and sample_lod. The bands sit where the scene has thin
    vertical structures, and LOD comes from dfdx/dfdy of uv. Both tails compute
    shade() before any discard_fragment(), so the derivatives ought to match --
    but fs_hw discards where fs returns the untouched destination, and that is
    the one place the two differ in a way a quad of fragments can see.

I do not know the cause. Three defects found this session are real, fixed and
pinned, and none of them is this one.


15. THE ARTEFACT, MEASURED AT GAMEPLAY AGAINST A MATCHED CONTROL
=================================================================
TWO EARLIER MEASUREMENTS IN THIS NOTE WERE OF THE WRONG THING, and a person
watching the screen caught both. Sections 13 and 14 counted "black pixels" in
frames that were the intro and a cutscene: the black bars in the intro are
GRAPHIC ELEMENTS and the black bars in a cutscene are LETTERBOXING. The 105,000
black pixels in the 65%-non-blank frames are letterbox, entirely legitimate.
The picket-fence columns in section 14 are intro art. Neither was the bug, and
every conclusion drawn from those counts is void.

The artefact is obvious at GAMEPLAY and barely present anywhere else, which is
why 200 s runs that stop at the cutscene kept missing it. Two 280 s runs, same
pad, same capture stride, same capture indices:

    DEFAULT path   clean. A gameplay frame -- player, chain-link fence,
                   buildings, HUD, ground -- is pixel-correct.
    HARDWARE path  the ground plane is cut into rectangular blocks: some black,
                   some displaced, and the magenta-and-grey HUD meter appears
                   down in the ground.

Counting strong vertical discontinuities that land on a multiple of 64 and span
at least a third of the screen:

    hardware path, all three fixes in   66 over 11 frames   6.0 per frame
    default path                         3 over  5 frames   0.6 per frame

SO THE THREE DEFECTS FIXED IN THIS SESSION ARE NOT THIS ONE. They are real,
they are pinned by phases, and the picture is unchanged.

WHAT THE SHAPE SAYS. The blocks are axis-aligned in SCREEN space while the
ground they corrupt is perspective-projected, so the corruption is in the
surface, not in the geometry. The boundaries recur at {64, 128, 192, 256, 320,
384, 448, 512, 576} -- every multiple of 64 across a 640-wide surface, in every
frame. At RGBA32Float that is exactly 1024 bytes per band; at the guest's two
bytes it is 128. And blocks carry content from ELSEWHERE in the same frame --
the HUD meter in the ground is the clearest instance -- so this is misaddressed
copying rather than lost drawing.

WHAT IS STILL NOT KNOWN: which operation misaddresses it. The upload, the
readback and the depth paths all index with the pitch the surface was captured
with, and metal_copy_test puts every per-draw state byte-exact against the
rasteriser. The 64-pixel period is the strongest clue in this whole
investigation and it has not been explained.

WHAT I WOULD DO NEXT, in order:
  1. Score a GAMEPLAY frame, not the title screen. Every gate in this tree
     scores a synthetic surface or an intro frame, which is why all of them
     pass while the game is visibly wrong. metal_hw_check.sh cannot see this.
  2. Find the source of a displaced block: cross-correlate a corrupted 64-wide
     band against the rest of the frame and read off the offset. The offset in
     pixels, or in bytes, names the addressing error directly.
  3. Only then look for the code. Three sessions of reading have not found it
     and one measurement of the offset would.


16. FOUND: ONE RENDER PASS PER DRAW, RACING ON TILE MEMORY
============================================================
THE ARTEFACT IS A 64x64 TILE MOSAIC, and RECOMP_METAL_BATCH=1 removes it.

Measured on a real gameplay recording rather than a synthetic surface. Strong
seams found by an UNRESTRICTED search -- the earlier 64-alignment claim in
section 15 came from a search that only looked at multiples of 64 and could
only find what it was looking for, which is a methodological error and is
corrected here by counting all seams and comparing against chance:

                                frames  seams  on x%64==0  expected  enrichment
    hardware, per-draw (default)    11    248       66        3.9      17.0x
    hardware, BATCHED                7     29        0        0.5       0.0x
    software control                 5    227        3        3.5       0.8x

And in a recording the seams are on a 64 grid in BOTH axes, consistently over
three frames: vertical at game x = 0, 64, 192, 256, 320, 384, 448, 640, and
horizontal at y = 128, 256, 384. That is a tile grid, not a column artefact.

THE MECHANISM. With batching off -- the default -- every draw is its own render
pass and its own command buffer: load the whole surface into tile memory, draw
one batch, store it back. A gameplay frame issues tens of thousands of those
against the same texture, and RECOMP_METAL_CB_GPU measures 664,933 command
buffers STARTING before the previous one ended, with out-of-order = 0. Tiles
therefore resolve independently and out of step, and each 64x64 tile of the
presented frame ends up holding whichever command buffer stored it last. The
result is a mosaic of moments -- which is exactly what a person watching it
described as the background being cut and jumbled, with elements moving in the
grid.

The player is coherent because it is drawn last, into whatever the surface then
holds.

WHY IT IS HARDWARE-PATH-ONLY, and why "slow but looked ok" before. The software
path serialises overdrawn fragments with raster_order_group(0). That keeps the
GPU shallow and the producer close behind it, so the per-draw passes rarely
overlap. Removing that serialisation is where the 9.6% came from, and it is
also what let the passes race.

WHY NO DEVICE TEST COULD SEE IT. metal_batch_test submits a few hundred draws
and reads back immediately; the GPU is never behind. Its own header says the
first version of the ring phase was "toothless" for exactly this reason -- "the
GPU was never actually behind" -- and the same sentence applies to every phase
in the file.

BATCHING WAS ALREADY BUILT, default off, and had only ever been argued about on
frame time, where its A/B ranges overlapped. It is a CORRECTNESS fix, and that
changes the case for defaulting it on. metal_batch_check.sh already gates
batched output against per-draw byte for byte.

AND IT WAS UNREACHABLE UNTIL TODAY. RECOMP_METAL_HW=1 with
RECOMP_METAL_BATCH=1 segfaulted on its first draw until the stale-encoder fix
earlier in this session: batch_flush() ran after `encoder` was bound, so the
draw encoded into an ended encoder. The configuration that fixes the artefact
could not be run before that.

STILL OPEN: a finer speckle remains on textured surfaces in the batched frames,
visible in the third recording as a more granular pattern. It is a smaller and
probably separate defect, and it is not tile-aligned.

NOT YET MEASURED: what batching costs or saves in frame time on the hardware
path, which is the question that decides the default.


17. THE FIX, THE GATE THAT WOULD HAVE CAUGHT IT, AND WHAT IS LEFT
==================================================================
FIXED: RECOMP_METAL_BATCH now defaults ON. One encoder for many draws instead
of a render pass per draw, which is the correct architecture as well as the
fast one -- loading and storing a whole surface through tile memory tens of
thousands of times per frame was never going to be right. =0 restores the
per-draw path and must keep working; it is the control for the whole result.

It is a CORRECTNESS default. Batching had been argued about only on frame time,
where its A/B ranges overlapped and nobody could call it, so it sat switched
off. metal_batch_check.sh already held the invariant that decides whether
turning it on is safe -- batched output byte-for-byte against per-draw on the
device test -- and it still passes.

NEW GATE: diagnostics/jsrf_first_fault/fb_score.py, because nothing here could
score a real frame. Two metrics:

  tile     strong edges landing on a grid boundary against what chance gives,
           reported as enrichment rather than a count so it tracks the artefact
           and not the scene's own detail
  speckle  isolated pixels disagreeing with ALL their neighbours -- granular
           noise with no straight edges, which `tile` cannot see

--selftest injects a known seam and known speckle and requires detection,
because a tool that cannot fail is not a gate. Run it on two arms of the same
scene with --compare; neither metric is a pass/fail alone.

Its first use settled an open question. The granular noise a person reported is
NOT a hardware-path artefact:

    software control      15806 /Mpx
    hardware per-draw     13282
    hardware batched      11686

Highest on the known-good path, lowest on the fixed one. It is the title's own
dithering and cel-shaded detail, and the fix neither introduces nor worsens it.

ALSO FIXED, and it is the reason the A/B below can be believed: the batching
switch now names itself in the [METAL] report in BOTH states, and ab_score.py's
SWITCH_TOKEN and METAL_SWITCH_RE know about it. Batch statistics used to print
only under RECOMP_METAL_CB_STATS and only when batching was on, so the OFF arm
said nothing and any comparison fell back to "assumes the environment took" --
the same hole that ran RECOMP_APU_SELFLINK_END and RECOMP_VSH_REUSE with the
feature enabled in both arms, on the switch that turned out to decide whether
the frame is correct.

WHAT IS LEFT

  0. THE DEFAULT FLIP ITSELF IS UNVERIFIED IN A REAL RUN. Every capture that
     showed batching clean passed RECOMP_METAL_BATCH=1 explicitly, and the
     frame-time A/B sets it explicitly in both arms, so nothing has yet
     exercised the new default with the variable UNSET. That is one run and it
     is the difference between "batching fixes it" and "the fix ships".
  1. FRAME TIME. Every performance number this renderer has -- the 9.6% for the
     hardware path and the 14.5% for 565 -- predates the batching default and
     predates the dither fix's raster_order_group(0) on dithered blended draws.
     An A/B of RECOMP_METAL_BATCH on the hardware path is running; until it
     lands, treat both figures as unverified rather than wrong.
  2. Re-run the 565 A/B, whose arms were never verifiable.
  3. Re-run RECOMP_VSH_REUSE properly.
  4. metal_copy_test line 49: the software path's depth readback is now the
     only arm failing an exact comparison.
  5. RECOMP_SURFACE_AUDIT is built and still has not been run.

WHAT THIS EPISODE SHOULD CHANGE ABOUT THE GATES. The defect needed tens of
thousands of draws before the GPU fell behind the producer, and every gate in
this tree submits a few hundred to one retained surface and reads it straight
back. metal_batch_test's own header already said the first version of its ring
phase was "toothless" because "the GPU was never actually behind" -- that
sentence was true of the whole file and nobody generalised it. A gate that
cannot get the GPU behind cannot see this class of defect at all, and the
answer is fb_score.py on frames from a real run, not another synthetic phase.


18. THE RESIDUAL IS REAL, AND THE METRIC THAT SAID OTHERWISE WAS WRONG
=======================================================================
RETRACTED: "the granular noise is NOT a hardware-path artefact". It is. That
claim came from fb_score.py's speckle metric, which ranked the known-good
software path as the noisiest of three arms -- and I reported the ranking as a
result instead of reading it as the metric being broken.

SETTLED BY LOOKING, at comparable surfaces rather than comparable scenes. A
flat wall on the batched hardware path carries small sharp BLACK fragments,
two to five pixels, scattered across it. The same kind of surface on the
software control is smooth and carries none. Magnifying one crop of each
answered in a minute what four metrics could not.

WHY THE METRICS COULD NOT. Every one compared arms that never reach the same
scene, because the two paths run at different speeds and a fixed pad schedule
lands them in different places. A single-frame noise rate then measures how
much flat area a scene happens to have. `tile` escaped this only because
enrichment is a ratio taken inside one frame against that frame's own seam
count; nothing about the speckle rate is.

THE SHAPE OF WHAT IS LEFT. Black, small, on flat surfaces -- the same kind of
loss as the tile mosaic, three orders of magnitude smaller. Batching removed
the 64x64 blocks by replacing a render pass per draw with one per batch, but a
batch still ends at every flush, and the flushes have not been counted. The
`use_zeta` churn is the suspect: next_depth is NULL for any draw that neither
depth-tests nor stencil-tests, so every alternation between a depth-using draw
and a depth-less one fails the retained-surface test, and that forces a sync, a
full readback, a texture reallocation and a re-upload -- each of which ends a
batch. If a frame alternates often, batching is still committing a great many
command buffers and the same race survives at a finer grain.

NEXT, AND IT IS A MEASUREMENT RATHER THAN A THEORY: count surface re-uploads
and batch flushes per frame at gameplay. RECOMP_METAL_RING_AUDIT already
reports surface re-uploads and RECOMP_METAL_CB_STATS reports flushes and
draws-per-flush. If flushes per frame are in the thousands, the churn is the
mechanism and the fix is to stop tearing the surface down for a draw that
simply has no depth buffer.


19. A MAGNITUDE I GOT WRONG, AND WHAT THE COUNTERS ACTUALLY SAY
================================================================
CORRECTED: "a gameplay frame issues tens of thousands of render passes". It
does not. Measured, on the per-draw path at gameplay:

    command buffers          781,703 over 9,688 frames  =  80.7 per frame
    of those, overlapping    664,933                    =  85% of them
    draws                    315,448 over the run       =  about 40 per frame
    surface re-uploads       13,543                     =  about 1.7 per frame
    ring                     267,621 reservations, 11,509 wraps,
                             0 waits, 0 fallbacks

About eighty command buffers a frame, not tens of thousands. The figure appears
in section 16, in the batch_on() comment and in two commit messages, and it is
wrong by roughly five hundred times.

THE MECHANISM IS UNAFFECTED. Eighty render passes a frame, each loading and
storing a whole surface through tile memory, with 85% of them starting before
the previous one ended, is ample to produce the tile races -- and the fix
measured 17.0x enrichment down to 0.0x. What was wrong was the scale of the
number, not the argument it supported. The two counters are also a consistency
check on each other: 781,703 command buffers at 80.7 per frame is 9,688 frames,
and 664,933 of them overlapping is the 85% above.

AND IT WEAKENS MY OWN NEXT HYPOTHESIS. Section 18 nominated the use_zeta churn
as the reason the residual specks survive batching, on the guess that a frame
alternates between depth-using and depth-less draws often enough to end a batch
constantly. It does not: surface re-uploads run at about 1.7 per frame. With
batching on, the flushes per frame should therefore be a handful, not
thousands, and a race between a handful of command buffers is a much poorer
explanation for specks scattered across a flat wall.

WHAT TO MEASURE INSTEAD, and it is one number: command buffers per frame on the
BATCHED path, from the same RECOMP_METAL_CB_STATS line. If it is a handful,
the residual is not the same race and needs its own explanation. If it is still
dozens, something is ending batches far more often than the surface churn
accounts for, and that something is the lead.


20. THE PIPELINE COMPARED STAGE BY STAGE, WHICH RULES OUT A WHOLE CLASS
========================================================================
Done because hypothesis-and-test had knocked down four mechanisms in a row and
a structural comparison finds OMISSIONS rather than bugs. Write out what an
NV2A-to-Metal translation must do, stage by stage, and ask of each stage
whether this implementation does it, refuses it, or silently ignores it. The
third category is the dangerous one.

    vertex fetch, T&L, viewport   implemented, shared vs between both paths
    clip and cull                 CPU side, shared
    texture sample, mips, DXT     implemented AND byte-exact in metal_copy_test
    register combiners            implemented, byte-exact
    alpha test                    implemented
    depth and stencil             implemented
    blend                         implemented
    dither                        implemented (stage order fixed today)
    fog                           refused
    logic op                      refused
    colour write mask             refused
    texture address modes         refused
    texture filter, format, LOD   refused
    polygon offset, window clip   refused
    multisample, shade mode       refused

THERE IS NO THIRD CATEGORY. nv2a_texture_copy_prepare refuses about thirty
distinct states by name rather than approximating any of them, which is the
right design and is why looking for a missing stage found nothing.

AND THE REFUSAL PATH NEVER FIRES HERE. Over four runs:

    [TEXTURE] prepared=750558 rejected=0
    [TEXTURE] prepared=792428 rejected=0
    [TEXTURE] prepared=440094 rejected=0
    [RASTER]  0 batches + 0 triangles on the CPU

Every draw this title issues is expressible, accepted and rendered by the sink.
Nothing is dropped, nothing falls back, nothing is approximated.

ONE REAL GAP FOUND, WHICH IS NOT THIS BUG. A draw the decoder rejects is
DROPPED, not rasterised on the CPU: nv2a_pb_exec.c:2944 logs the first eight
and returns. It is counted in neither gpu_fallbacks nor cpu_batches, which is
why both read zero and why nobody would notice. For a title that used fog or a
colour mask, geometry would simply be absent with every counter reading clean.
JSRF never triggers it, so it is a latent hazard rather than the cause.

WHAT THIS LEAVES, and it is the useful half of a negative result. The residual
cannot be a PER-DRAW problem: every stage is implemented or refused, nothing is
ignored, no draw is dropped, and the per-draw translation is verified
byte-exact against the CPU oracle across combiners, alpha test, stencil,
multi-texture, DXT and mips. So it has to be about how draws COMBINE or
PERSIST -- the retained surface across frames, or ordering between passes.

That is the same place the tile mosaic lived, which is consistent with a person
watching it saying the residual looks like the same issue. It differs in one
measured respect: the mosaic sat on a clean 64 grid and this does not. Seam
spacings in the corrupted region are 12.1, 4.3, 9.8, 12.1, 2.5, 5.6, 2.0, 1.7,
32.0 -- irregular. I had called it "the same class at finer granularity" from a
magnified image before measuring, and the measurement does not support it.
