================================================================================
ROUTE B - NEXT STEPS
Getting JSRF to render on macOS by executing its own NV2A command ring
================================================================================
Companion to CODEX_HANDOVER.txt, which holds the measurements this plan rests
on. Sections (y), (z), (aa), (ab) and (ac) there are the evidence; this file is
only the forward plan. Where the two disagree, the handover is the record of
what was measured and this file is the guess about what to do next.


================================================================================
0. WHERE THIS STANDS
================================================================================
THE APP RUNS. It boots, initialises DirectSound and the APU, walks its media
tree, loads assets from D:, creates its worker threads, connects its
interrupts, and runs its frame loop at 60Hz. A window is open, backed by
OpenGL 4.1 on Apple's Metal-backed driver.

IT DOES NOT DRAW YET. The window is blank.

The command ring is parsed and dispatched: 3,939 dwords, 2,731 methods, zero
unparseable headers, frame loop unregressed. What is missing is the handlers
those methods land in -- 1,448 of 2,731 are still declined by PGRAPH.

DECIDED, and the reasoning is in handover (y): the ring route rather than ~85
title-specific D3D8 overrides. JSRF inlines its D3D8 into game code, so there
is barely an API surface to override; ring work is generic and carries to
every other Xbox title.


================================================================================
1. P1 - FIRST FRAME  (clear the screen and show it)
================================================================================
GOAL: a cleared, flipping surface in the window at 60Hz, in the colour
NV097_SET_COLOR_CLEAR_VALUE asks for.

TWELVE METHODS TO WRITE. All are emitted by JSRF today; counts are from the
captured ring. The other six of the eighteen needed already work.

    NEED  SET_CONTEXT_DMA_COLOR       2    which DMA object the colour
                                           surface lives in
    NEED  SET_CONTEXT_DMA_ZETA        2    ditto for depth/stencil
    NEED  SET_SURFACE_FORMAT         13    colour + zeta format, dimensions
    NEED  SET_SURFACE_PITCH          26    row stride, colour and zeta packed
                                           in one dword
    NEED  SET_SURFACE_COLOR_OFFSET   26    colour surface base
    NEED  SET_SURFACE_ZETA_OFFSET    26    depth surface base
    NEED  SET_ZSTENCIL_CLEAR_VALUE   19    depth/stencil clear value
    NEED  FLIP_STALL                  4    wait for the flip to retire
    NEED  FLIP_INCREMENT_WRITE        4    advance the flip counter
    NEED  WAIT_FOR_IDLE              85    pipeline barrier
    NEED  NO_OPERATION              170    no-op; must return handled
    NEED  SET_CONTROL0               16    depth format / colour-space control

    HAVE  SET_SURFACE_CLIP_HORIZONTAL / _VERTICAL
    HAVE  SET_COLOR_CLEAR_VALUE
    HAVE  SET_CLEAR_RECT_HORIZONTAL / _VERTICAL
    HAVE  CLEAR_SURFACE

Most are plain state stores into the PGRAPH struct. WAIT_FOR_IDLE and
NO_OPERATION are no-ops that only need to return 1 so they stop being counted
as misses -- between them they are 255 of the 1,448.

THE REAL WORK IN P1 IS NOT THE METHODS. It is these three:

  1. PRESENT IS NOT WIRED. d3d8_PresentFrame() exists and nothing calls it.
     A flip has to reach it or the window never updates.

  2. CONTEXT OWNERSHIP. Only one thread may hold the GL context. The pusher
     thread claims it today (xbox_d3d8_make_current), so Present must happen
     on the pusher thread too, or the drawing must move off it. Decide this
     deliberately -- it is what crashed the first run of P0.

  3. macOS WANTS WINDOW EVENTS ON THE MAIN THREAD. SDL_PollEvent and window
     resize belong there, not on the pusher. Expect to split "issue GL" from
     "service the window".

EXIT CRITERION: the window shows the clear colour, changing when the guest
changes it, at ~60Hz. Screenshot it.

STATUS: THE PATH WORKS, THE CADENCE DOES NOT. Measured with the twelve methods
in and Present wired: clears=9, flips=4, presented=4, unhandled 1448 -> 1329,
zero bad headers, frame loop unregressed. So ring -> pusher -> PGRAPH -> Clear
-> flush -> Present runs end to end and the window is swapped. What is missing
is repetition: the guest stops submitting after its startup burst. See
section 7.

RISK TO WATCH: the pusher's counters are STATIC after startup -- JSRF emits a
burst of ~3,900 dwords and then stops. Either the title is waiting on
something rendering-related, or it has finished initialising and will not
submit again until it advances further. If the counters are still static once
P1 lands, that is the next thing to chase, and it is more important than any
remaining method.


================================================================================
2. P2 - GEOMETRY
================================================================================
GOAL: recognisable geometry on screen.

    SET_VERTEX_DATA_ARRAY_FORMAT / _OFFSET   vertex stream layout
    SET_BEGIN_END variants                    primitive type
    DRAW_ARRAYS / ARRAY_ELEMENT16 / _32       indexed and non-indexed draws
    INLINE_ARRAY                              already handled
    SET_VIEWPORT_OFFSET / _SCALE              already handled
    SET_CULL_FACE, polygon mode
    SET_TRANSFORM_PROGRAM      24 per slot, 32 slots -- vertex microcode
    SET_TRANSFORM_PROGRAM_LOAD / _START
    SET_TRANSFORM_CONSTANT / _CONSTANT_LOAD
    SET_TRANSFORM_EXECUTION_MODE

THE VERTEX SHADER IS ALREADY WRITTEN. d3d8_vsh.c (1,470 lines) takes RAW NV2A
MICROCODE -- d3d8_vsh_create_shader(const DWORD *microcode, int num_insns) --
which is exactly what SET_TRANSFORM_PROGRAM streams. Accumulate the program
into a buffer at _PROGRAM_LOAD offsets and hand the buffer over; do not write
a second translator.

EXIT CRITERION: geometry that moves with the camera and is recognisably the
game rather than noise.


================================================================================
3. P3 - TEXTURES AND SHADING
================================================================================
GOAL: textured, correctly shaded output.

    SET_TEXTURE_OFFSET / _FORMAT / _CONTROL0 / _CONTROL1 / _IMAGE_RECT
        (+0x40 per stage, four stages)
    SET_COMBINER_COLOR_ICW / _OCW, _ALPHA_ICW / _OCW, _FACTOR0 / _FACTOR1,
    SET_COMBINER_CONTROL, SET_SHADER_STAGE_PROGRAM, SET_SHADER_OTHER_STAGE_INPUT
    SET_TEXGEN_S / _T / _R / _Q

BOTH HARD PARTS ARE ALREADY WRITTEN AND ARE NV2A-LEVEL, NOT D3D8-LEVEL:
    d3d8_combiners.c  1,057 lines  consumes combiner ICW/OCW register words,
                                   which is exactly what SET_COMBINER_* carries
    d3d8_swizzle.h      246 lines  Morton unswizzle
    d3d8_resources.c               texture format mapping

EXIT CRITERION: textures appear with correct colours and no swizzle artefacts.


================================================================================
4. P4 - METAL
================================================================================
GOAL: a native Metal backend.

THE ATTACH BOUNDARY IS THE IDirect3DDevice8 VTABLE, and it is already proven:
nv2a_pgraph_d3d11.c contains ZERO ID3D11 references -- all 34 of its emit
calls go through dev->lpVtbl->. It is a PGRAPH-to-D3D8 translator, not a D3D11
one, and the file name misleads. So d3d8_metal.m is a third sibling of
d3d8_device.c (D3D11) and d3d8_gl.c (GL). Nothing in the PGRAPH path changes.

NOT URGENT. Apple's GL driver reports itself as "GL 4.1 Metal - 90.5", so the
existing GL backend is already running on Metal. P4 is a deprecation hedge and
an optimisation, not a prerequisite for pixels. Do P1-P3 first.

For shaders there is a choice: retarget d3d8_vsh.c and d3d8_combiners.c to
emit MSL, or keep them emitting HLSL and run it through Apple's Metal Shader
Converter. The converter is the one piece of Apple's toolkit that fits this
project -- Game Porting Toolkit does not, since it targets Windows PE binaries
under Wine and this is a native arm64 Mach-O.


================================================================================
5. STANDING CONSTRAINTS
================================================================================
* THE PUSHER STAYS IN src/nv2a. If it drifts into diagnostics/, the route
  stops being generic and the whole argument for choosing it collapses.

* RING DISCOVERY IS THE ONE TITLE-SPECIFIC PART, and it is one constant, not
  eighty-five functions. JSRF publishes its ring through D3D8 globals at
  device +0x00 / +0x04 (0x0019B200 / 0x0019B204), not the PFIFO USER area at
  0xFD800040/44. Deriving it from the channel/DMA object setup would remove
  even that; worth doing when a second title needs it, not before.

* nv2a_regs.h IS THE AUTHORITY ON METHOD OFFSETS. Eight constants shadowed it
  and were wrong, which silently mis-wired the entire clear path and applied
  JSRF's stencil writes as depth and cull state. Do not redefine NV097_* in a
  translator.

* AN UNHANDLED METHOD MUST STAY COUNTED. nv2a_pusher ranks declines by
  frequency every five seconds. A silently dropped method is indistinguishable
  from one that never arrived -- which is exactly how this effort previously
  lost time to a histogram that was never printed being read as a histogram of
  zeroes.

* nv2a_pb_replay.c IS INERT. nv2a_pb_replay_frame() is defined and never
  called. It also carries Burnout 3 menu data and literal method offsets, one
  of which (0x1B08 for TEXTURE_CONTROL0) is now wrong. Fix the literals if it
  is ever revived; ignore it otherwise.


================================================================================
6. HOW TO MEASURE, AT EVERY STEP
================================================================================
    cd build-macos/jsrf-first-fault/build && ./jsrf_first_fault

    [PUSHER] runs=N dwords=N methods=N unhandled=N bad_headers=N
    [PUSHER] unhandled methods: 0xNNNN=count ...      (ranked, every 5s)

  bad_headers > 0            the ring range is wrong, not the parser
  methods static after boot  the title has stopped submitting -- chase that
                             before writing more handlers
  unhandled falling          the handlers are landing

  [ADX] tick ~60/s           the frame loop is alive; "STUCK at N" means it
                             is not, and nothing else matters until it is

  JSRF_PB_CAPTURE=1          dump the ring to jsrf_pushbuffer.bin for offline
                             parsing

  timeout does not exist on macOS. Bound a run with:
      ./jsrf_first_fault > out 2> err & P=$!
      sample $P 25 -f /dev/null
      kill -0 $P && echo "still running" || echo "exited"


================================================================================
7. OPEN QUESTIONS
================================================================================
* ANSWERED IN PART: why submission stops after ~3,900 dwords. THE TITLE IS NOT
  HUNG. Sampled with the P1 build, the main guest thread is running a 60Hz
  poll loop -- sub_00013F80 calls sub_000659C0 and then sleeps 16ms through
  sub_00145CA6/sub_00145C28 -- which is a normal main loop, not a deadlock.
  The 14,955 samples inside bridge_KeDelayExecutionThread are that sleep, not
  a spin. The alertable-retry path in sub_00145C28 (retry while the result is
  0x101 STATUS_ALERTED) was investigated and is NOT firing: the only
  QueueUserAPC producer is xbox_KeAlertThread, and ordinal 93 is unrouted.

  So the game is alive and ticking and simply never re-enters its render path.
  RULED OUT SINCE, each by measurement:
    - STUCK LOADING. Ordinals 277/294 freeze at 607 because they are
      RtlEnter/LeaveCriticalSection and init finished. No file-I/O ordinal
      appears in the hot set at all; the growing ordinals are purely frame
      loop and thread churn (224/231 resume/suspend, 159 wait, 119 DPC,
      99 delay, 143/124 priority).
    - RING FLOW CONTROL. The index pair the guest waits on reads put=23
      get=23 -- already equal, so it is not waiting for the GPU to catch up.
      The ring cursor at device +0x00 is frozen at 0x010E0DA4: the guest has
      simply stopped writing.
    - A DRAW-SUBMISSION BUG. draws=0 is correct, not broken: INLINE_ARRAY
      carried 48 dwords across 4 BEGIN/END pairs, about 2.4 vertices each at
      stride 5, so submit_draw's "num_verts < 3" guard rightly declined. That
      burst was GPU INITIALISATION, not a frame.
    - THE GPU->CPU FENCE. BACK_END_WRITE_SEMAPHORE_RELEASE is the last
      meaningful command before the guest goes quiet, which looked decisive.
      Implemented it; SET_SEMAPHORE_OFFSET is 0, so the guest never nominated
      a fence location and there is nothing to signal. The handler stays --
      it is correct and a later title will need it -- but it is not this
      blocker.

  WHAT THE GUEST DID LAST, decoded from the pusher's recent-method ring:
      SURFACE_CLIP_H/V, CONTROL0, DEPTH_TEST_ENABLE, STENCIL_TEST_ENABLE,
      SURFACE_FORMAT, WINDOW_CLIP_TYPE/H/V, VIEWPORT_OFFSET x4,
      CLIP_MIN, CLIP_MAX, TEXTURE_CONTROL0, ZSTENCIL_CLEAR_VALUE,
      BACK_END_WRITE_SEMAPHORE_RELEASE, COLOR_CLEAR_VALUE x2
  -- and that whole render-target setup block appears TWICE. This is the tail
  of a completed D3D device initialisation, not a stalled frame. The title
  finished setting up its GPU and never entered a render path.

  SO THE REMAINING BLOCKER IS GAME STATE, NOT GRAPHICS PLUMBING. The next
  technique is different in kind: trace what gates the render call inside
  sub_000659C0 (the 60Hz tick), rather than adding NV2A methods. Use
  --trace-functions on sub_000659C0's callees and find the branch that never
  goes the drawing way.

  SUPERSEDED HYPOTHESIS, kept for the reasoning: the flip acknowledge. The guest raised
  FLIP_INCREMENT_WRITE and FLIP_STALL four times and then stopped, which is
  what a title does when it is waiting for the display to report the flip
  retired. Nothing in this runtime advances a flip-read counter.
  NEXT: find what the guest polls to decide a flip completed -- SET_FLIP_READ
  (0x0120) / SET_FLIP_WRITE (0x0124) / SET_FLIP_MODULO (0x0128) are the
  candidates, plus any notifier written back to guest memory -- and make it
  follow flip_write. That is a graphics-domain question and belongs in P1.

* Does JSRF ever wrap the ring? The bounds at device +0x24/+0x28 were accepted
  (0x010DD000-0x0115D000, cursor inside), and wrap handling is written, but it
  has not yet been observed firing.

* Present timing. On hardware the flip is paced by the vblank the runtime
  already delivers at 60Hz. Whether to drive Present from FLIP_STALL, from the
  vblank, or from both is undecided.


================================================================================
8. UPSTREAM (sp00nznet/xboxrecomp) - WHAT IT HAS THAT WE DO NOT
================================================================================
Checked 2026-09-02. We are 9 commits ahead of origin/main and 11 behind, and
there is a large active branch, origin/work/v0.7.0-non-local (65 files,
+8,692 lines), which is where the interesting work is.

TWO LIFTER CORRECTNESS BUGS ON THAT BRANCH ARE THE BEST LEAD WE HAVE.
Both are the silent-corruption class this effort keeps losing time to -- the
game runs, takes a wrong branch, and never announces anything:

    aaf5eca  lifter: cmp must set the carry flag
             A cmp that leaves CF wrong makes every jb/jae/ja/jbe/setb after
             it wrong. Unsigned comparisons are everywhere in a game loop.
    5156919  lifter: the direction flag decides which way a string instruction
             walks. We already lost a week to string instructions once (the
             repe cmpsd GUID compare, handover 4e).

These fit our symptom exactly: a title that ticks at 60Hz, is not blocked on
anything, and never enters its render path, is a title taking a branch the
wrong way. TRY THESE BEFORE ANY MORE NV2A WORK.

ALSO WORTH TAKING:
    b010c42  recomp: don't rewind an icall's failure path over saved registers
             THE SAME BUG WE FOUND INDEPENDENTLY (handover (t)). Two
             independent discoveries of one defect is good evidence both are
             right; reconcile rather than pick blind, and keep whichever
             test suite is stricter.
    008a7a6  lifter: bit scan -- we have our own (handover 4b). Pick one.
    c2ec923  lifter: xlat -- JSRF emits none, verified. Free correctness.
    3655761  fence_readable must accept the contiguous window. Directly fixes
             the blind spot in our BACK_END_WRITE_SEMAPHORE_RELEASE bounds
             check, which rejects anything above 0x08000000 -- and a fence
             lives at XBOX_CONTIG_BASE 0x80000000 by definition, because
             MmAllocateContiguousMemory is what allocates it.
    c572d5a  worker stacks reclaimed; NtReleaseMutant routed (routing one half
             of a lock pair is a deadlock generator).
    b523cbb / 162e72b  memory layout: thread stacks off the image, heap serving
             the mapped range.

NEW TOOLING, all upstream-only:
    tools/symbolize.py, tools/stackwalk.py   answer the handover's "lldb is
             effectively UNUSABLE on this binary" gotcha directly.
    tools/seed_from_log/                     automates OPEN ITEM 2 -- seeding
             function pointers stored in structures from a runtime log, which
             we have been doing by hand.
    tools/rtti/                              RTTI-based identification.

ONE UPSTREAM FINDING TESTED AND REJECTED FOR THIS TITLE:
    c572d5a says DMA_PUT holds a PHYSICAL address -- D3D writes VA &
    0x0FFFFFFF and reads position back as GET | 0x80000000 -- and that reading
    it raw walks unrelated memory that merely decodes, producing the false
    conclusion "this title submits no methods". That is exactly the conclusion
    we had reached, so it looked decisive. It is not true here: feeding the
    pusher from `cursor | XBOX_CONTIG_BASE` yields 3,939 dwords and ZERO
    methods, while the raw address yields 2,734 with no bad headers. JSRF
    publishes its ring through D3D8 globals, not the PFIFO USER channel, so
    the cursor is a plain guest VA. Recorded so nobody re-tries it.

ORDER OF WORK
    1. Merge origin/main (11 commits). Conflicts expected in lifter.py,
       translator.py and test_call_retaddr.py, all in code we changed.
       Reconcile bit-scan and the icall failure path deliberately.
    2. Regenerate, rerun, re-measure. Nothing should move; this is the
       baseline that makes step 3 interpretable.
    3. DONE, AND THE ANSWER IS NO. Both fixes are in and both are live -- the
       regenerated code carries 4,233 _cf assignments and 864
       RECOMP_DF_STEP sites, JSRF's five `std` instructions now set g_df, and
       the binary is newer than the sources. Discovery is unchanged at
       9406/9407 functions, 0 failed.

       Runtime is BYTE-IDENTICAL to before: dwords=3945, methods=2734,
       clears=9, flips=4, draws=0, still frozen after the startup burst, still
       ticking at 60Hz.

       So the lead was wrong. JSRF's exposure was real -- 5 std sites, 318
       sbb/adc reading CF -- but none of it is on the path that gates
       rendering. The fixes are kept because they are correct and would bite
       later; they are not progress on this blocker. Recorded rather than
       quietly dropped, because "we tried the obvious thing and it did
       nothing" is the expensive fact to rediscover.

    4. NEXT, and now the only route left: trace what gates the render call
       inside sub_000659C0. Adopt tools/seed_from_log and tools/symbolize from
       the work branch first -- they exist to make exactly this tractable, and
       the handover's "lldb is effectively UNUSABLE on this binary" gotcha is
       what makes doing it by hand slow.

       The shape of the question: sub_000659C0 is the 60Hz tick and it runs a
       lot of code every frame without ever reaching the push primitive. Use
       --trace-functions on its callees and find the branch that never goes
       the drawing way. That is title-specific reverse engineering, not
       generic ring work, and it should be costed as such.


================================================================================
9. THE RENDER PATH, TRACED  (call-graph bisect against what actually executes)
================================================================================
Done by intersecting the static call graph with the functions a `sample` shows
live, walking up from the push primitive. Cheap -- no regeneration, no tracing
build -- and it found the boundary in one pass.

    level 1  17 direct callers of the push primitive sub_0018E930   NONE live
    level 2  7 callers of those                                     sub_00155380 LIVE
    level 3                                                         sub_00192090 live

So sub_00155380 runs every frame and its call to sub_001564B0 -- one of the
render-state setters -- never happens. Its opening is:

    eax = [0x2650DC]; test eax,eax; je  continue
    eax = [0x2650E0]; test eax,eax; jne continue
    return 0x800401F1              ; an HRESULT failure, no drawing

CAREFUL, AND I GOT THIS WRONG FIRST TIME: [0x2650E0] is not persistent state.
sub_00155050 sets it to 1, calls through a vtable slot [ecx+0x18], and clears
it to 0 on the way out. It is a scoped "currently inside the render call"
guard. Reading it as 0 from another thread says only that the scope is not
active right now, which is exactly what a probe outside the scope must see.
The gate is not broken; it is reporting that rendering is not in progress.

THE REAL FINDING IS ONE LEVEL UP. sub_00155050 is the render entry -- it takes
the scope, calls the virtual method, releases it -- and:

    * it is NEVER executed, and
    * it has ZERO callers in the static call graph.

Which means it is reached only through an indirect call. That is the defect
class this contract already names in OPEN ITEM 2: a function pointer stored in
a structure, invisible to every discovery pass because there is no call site.

NEXT, and it is now a narrow question rather than an open one:
    Find which vtable slot or structure field holds 0x00155050, and which
    object should be dispatching it. Two tools exist for this and neither has
    been pointed at it yet -- the RECOMP_ICALL feedback database, which records
    indirect targets observed at runtime, and upstream's tools/rtti, which
    recovers class layouts. The question is no longer "why does JSRF not
    render" but "who was supposed to call sub_00155050".


================================================================================
10. THE RENDERER CLASS, LOCATED  (and two of my own conclusions corrected)
================================================================================
DURABLE FACTS, worth having whoever picks this up next:

    vtable            0x001E0F00, 121 slots
    constructor       sub_0014CDB0 (installed by sub_0014CFB0; also written by
                      sub_0014CF80 and sub_0014CFB0 on reset paths)
    slot  6  +0x18    sub_00155380   the guarded entry
    slot 10  +0x28    sub_00155050   the render entry: takes the scope flag,
                                     calls the object's virtual method, releases
    slots 98-104      sub_00151200 / 00151330 / 001511B0 / 001515D0 / 00151520 /
                      00151670 ... the render-state setters that push NV2A
                      methods through sub_0018E930

That identification is solid: the class contains every render-state function
the NV2A-method identifier found independently, which is two unrelated methods
agreeing.

NEITHER sub_00155380 NOR sub_00155050 HAS A STATIC CALLER. The whole class is
dispatched through its vtable, so the call graph cannot see who drives it --
the OPEN ITEM 2 defect class again, at class scale rather than one pointer.

TWO CORRECTIONS TO EARLIER CONCLUSIONS IN THIS FILE. Both were mine and both
looked convincing at the time:

  1. "The gate fails, returning 0x800401F1." It does not. [0x2650E0] is a
     SCOPED guard -- sub_00155050 sets it to 1, calls the virtual method, and
     clears it to 0 on the way out -- so a probe reading it from another thread
     sees 0 whenever rendering is not in progress, which from outside is
     always. Reading a scoped flag out of scope tells you nothing.

  2. "The render path is never entered." It is entered -- during INIT. A live
     stack caught it:
         sub_0005F2C0 -> sub_00155380 (+4944, deep in the body, past the early
         return) -> sub_00156AB0 -> sub_0018E460
     and sub_0018E460 is D3D device creation: it writes the device global
     [0x19DCE0] = 0x19B200 and calls sub_00192090. So the gate passes and real
     D3D work happens.

  Whether it RECURS was then tested rather than assumed: three consecutive
  6-second samples, and device creation plus the gate appear in the FIRST only.
  Not a retry loop -- one-time initialisation. After init the renderer is never
  dispatched again.

WHERE THAT LEAVES THE BLOCKER: unchanged in substance but much better located.
The game's 60Hz tick does not dispatch the renderer object it built. The next
question is narrow and answerable: which object holds a pointer to the
0x001E0F00 instance, and what decides whether the tick calls slot 10 on it.
The RECOMP_ICALL feedback database records indirect targets observed at
runtime and is the tool for that; it has still not been pointed at this.


================================================================================
11. THE RENDER CHAIN, END TO END  (and why RTTI could not help here)
================================================================================
TOOLS.RTTI WAS THE OBVIOUS CUE AND IT IS A DEAD END FOR THIS TITLE. Pulled
tools/rtti across from the work branch and ran it: JSRF has 4 type descriptors
and ZERO vtables. RTTI is disabled in this build, which the tool documents as a
normal result. Kept, because it is generic and other titles will need it, but
it names nothing here.

So the chain was recovered by scanning memory instead. An instance carries its
vtable address in the first word, so guest RAM can be searched for it.

    ONE live instance of the renderer, at 0x0105C870.
    Referenced from three globals: 0x00251D6C, 0x002650D8, 0x00265110.
    Note 0x002650D8 sits immediately before the gate flags 0x2650DC and
    0x2650E0 -- that is one structure, {renderer*, flag, scope}.

Cross-referencing "reads one of those globals" with "dispatches through +0x28"
gave exactly one function, and it is unmistakably the render dispatcher:

    sub_001596B0:
        eax = [0x265110]              ; the owner
        call [eax_vtbl + 0x6C](eax, 6, -1, ...)
        esi = the renderer instance
        call [esi_vtbl + 0x24](esi)   ; renderer slot  9  sub_00155150
        call [esi_vtbl + 0x20](esi,0) ; renderer slot  8  sub_00154DC0
        call [esi_vtbl + 0x28](esi)   ; renderer slot 10  sub_00155050  DRAWS

THE FULL CHAIN, and every link is a vtable slot, which is why the static call
graph sees none of it:

    ??? --slot 23 (+0x5C) of vtable 0x001E1640 (26 slots)-->
        sub_001596B0  --slot 10 (+0x28) of vtable 0x001E0F00 (121 slots)-->
            sub_00155050  --> render-state setters --> sub_0018E930 --> ring

sub_001596B0 is not live, has no static caller, and is stored exactly once, at
0x001E169C -- slot 23 of a 26-slot vtable at 0x001E1640. So the question is now
one link further up and still narrow: WHO CALLS SLOT 23 OF THE 0x001E1640
CLASS, and does that object exist at runtime.

NEXT STEP, and static analysis is exhausted so it has to be runtime:
    Turn on the RECOMP_ICALL feedback (RECOMP_ICALL_OBSERVE is already compiled
    in behind RECOMP_ICALL_FEEDBACK) and record every indirect target actually
    dispatched. That answers directly whether slot 23 is ever called, and if it
    is, what calls it. Scanning for a live instance of vtable 0x001E1640 the
    same way as above is the cheaper half and worth doing first.


================================================================================
12. NEXT STEPS, ORDERED
================================================================================
Two tracks. They are independent, and the second is the one that produces a
picture, so do not let the first block it.


TRACK A -- FINISH THE DISPATCH QUESTION  (cheap first, then runtime)

  A1. SCAN FOR A LIVE INSTANCE OF VTABLE 0x001E1640, exactly as was done for
      the renderer: read guest RAM looking for the vtable address in an
      object's first word, then look for pointers to whatever is found.
      Reuses jsrf_find_renderer with one constant changed, so it is minutes.
      IF THERE IS NO INSTANCE, that is the answer and it is upstream of
      everything else: the object that owns the render dispatcher was never
      constructed, and the question becomes why. If there is one, its owning
      global names the next link.

  A2. TURN ON RECOMP_ICALL_FEEDBACK. RECOMP_ICALL_OBSERVE is already compiled
      into the macros behind that define and is a no-op without it. With it on,
      every indirect target actually dispatched is recorded, which answers
      directly whether slot 23 of 0x001E1640 is ever called and from where.
      Static analysis is exhausted; this is the only instrument that sees
      vtable dispatch.

  A3. EXPECT THE ANSWER TO BE "THE GAME IS IN A STATE THAT DOES NOT RENDER",
      and be ready for it. A 26-slot class whose slot 23 renders looks like a
      scene or task object in a state machine. If the current state simply is
      not the in-game one, the chain is working as designed and the real
      question moves again -- to what the state machine is waiting for. Say so
      plainly at that point rather than continuing to walk vtables; it would be
      a different investigation with a different cost.


TRACK B -- MAKE THE PIXELS THAT ARE ALREADY BEING ASKED FOR

  B1. CONFIRM THE WINDOW ACTUALLY SHOWS THE CLEAR COLOUR. This has never been
      checked visually. The guest issues 9 clears and 4 flips during init, the
      pusher dispatches them, CLEAR_SURFACE reaches the backend and Present
      swaps -- but nobody has looked at the window. P1's exit criterion was
      "the window shows the clear colour" and it is still formally unmet.
      If it is black, there is a bug in the clear path that is independent of
      the whole dispatch question, and it is cheap to find.

  B2. ADOPT nv2a_pb_exec FROM THE WORK BRANCH (f193457, "rasterise screen-space
      geometry into the guest framebuffer"). Upstream has already built a
      rasteriser for the ring route. It is worth having whether or not Track A
      lands, because when the game does render there has to be something to
      draw with, and building a second one here would be waste.


STRATEGIC -- THE DIVERGENCE IS NOW COSTING REAL WORK

  Three separate fixes have been discovered independently on both sides:
  the icall failure-path rewind, deriving XDK section ranges from the XBE
  rather than Burnout 3's constants, and bit-scan lifting. That is three times
  the same work done twice, and the branch is 47 commits ahead with things we
  want -- the rasteriser, seed_from_log, symbolize/stackwalk, the kernel memory
  fixes, the APU doorbell.

  Recommend merging origin/work/v0.7.0-non-local properly rather than
  continuing to cherry-pick from it. It will conflict in lifter.py,
  translator.py and the kernel, all places both sides have edited, so it is a
  session's work on its own -- but the alternative is discovering a fourth and
  fifth duplicate.


================================================================================
13. B1 AND A1 ANSWERED
================================================================================
B1 -- DOES THE WINDOW SHOW THE CLEAR COLOUR? YES, AND THE COLOUR IS BLACK.
Answered with a glReadPixels at Present rather than by looking, which also
works where looking does not. The centre pixel is 00 00 00 00 at every
present -- and the guest asked for exactly that:

    [PGRAPH] clear 1: param=0x00000003 flags=0x6 colour=0x00000000
    [PGRAPH] clear 2: param=0x000000F3 flags=0x7 colour=0x00000000

param 0xF3 sets D3DCLEAR_TARGET, so the colour buffer really is being cleared,
to black, because that is the value in SET_COLOR_CLEAR_VALUE. There is no bug
in the clear path. P1's exit criterion is met: the window shows the clear
colour. It is simply that the clear colour is black, which looks identical to
nothing happening -- which is why this needed a number rather than a glance.

A1 -- DOES THE DISPATCHER'S CLASS EXIST AT RUNTIME? YES, THREE INSTANCES.

    DISPATCHER class 0x001E1640: 3 live instances, first 0x0183E0A0,
        referenced from 0x01064824 and 0x0183DFF4   (both heap)
    RENDERER   class 0x001E0F00: 1 live instance, 0x0105C870,
        referenced from 0x00251D6C, 0x002650D8, 0x00265110  (all .data globals)

So nothing is missing. Both classes are constructed, the renderer is reachable
from three globals, and the dispatcher objects are owned by other heap objects
rather than by globals -- they sit in a container, which is what a scene or
task list looks like.

THAT MAKES A3 THE LIVE OUTCOME. The chain is intact and simply is not being
driven: the game is in a state whose slot 23 is never called. Not a missing
object, not a dropped pointer, not a broken clear.

TWO SCANNING MISTAKES WORTH NOT REPEATING, both mine, both caught by the
numbers disagreeing with themselves:
  * Scanning the IMAGE for instances finds the vtable address as an immediate
    inside the constructor that installs it. The first run reported an
    "instance" at 0x00159DF0, which is .text. Instances live on the heap.
  * Scanning only the HEAP for references loses them all, because the global
    that owns an object is in .data. The renderer went from three references
    to zero. The two scans need different ranges and it is not symmetric.

NEXT IS A2 AND NOTHING ELSE: turn on RECOMP_ICALL_FEEDBACK and find out
whether slot 23 of 0x001E1640 is ever dispatched. If it is, something inside
sub_001596B0 declines and that is readable. If it is not, the question is what
selects the state -- and that is a game state machine, which should be costed
as its own piece of work rather than continued on momentum.


================================================================================
14. SECOND UPSTREAM SWEEP  (two new commits; three hazards tested, all negative)
================================================================================
origin/work/v0.7.0-non-local moved to 342eb1f, two commits on:
    342eb1f  Map flash, open the window from the executor, and arm the watchdog
    31e120e  disasm: a mid-instruction seed that is a prologue means the sweep
             drifted

THE ONE ACTIONABLE CLUE, and it is a warning that saves a wasted cycle on A2.
From bdaecf3:

    "The indirect-call feedback dump never fired for a title that gave up
     during boot. The firmware-exit path ends in ExitProcess, which does not
     run atexit, so the host's registered dump was dead code exactly where the
     header says it matters most. Dump from the bridge instead."

Every run here is bounded with `sample` and then `kill -9`, so an atexit dump
would never fire for us either -- for a different reason and with the same
result. WHEN A2 IS DONE, DUMP THE ICALL FEEDBACK PERIODICALLY OR FROM THE
BRIDGE, never at exit. Had this not been read first, A2 would have produced an
empty file and looked like "no indirect calls observed", which is the same
false conclusion this contract has already drawn twice from a missing
instrument.

THREE HAZARDS TESTED AGAINST JSRF, ALL NEGATIVE. Worth recording so nobody
re-tests them:

  * ec9564a, switch tables discarded because the table read overran into the
    next function. Our lifter still has the exact `all(func_start <= t <
    func_end)` test upstream fixed, so the exposure is real in principle. It
    does not bite here: 210 indexed-jump sites, 210 resolved switches, ZERO
    discarded. (55 report "entries != targets", which is shared arms
    deduplicating, not an overrun.)

  * 31e120e, a rejected seed leaving a call target stubbed, whose stub returns
    without the callee's `ret N` -- esp walks off, and an object pointer slides
    out from under the vtable its constructor wrote. JSRF has 319 unresolved
    stubs and they pop the return address but NOT arguments, so the hazard is
    real in principle here too. Instrumented all 319: ZERO are reached at
    runtime. Not our bug.

  * 963b425, indirect calls silently dropped as not-code. Already tested in
    section 13's commit: zero skips.

So the last three "it is secretly corrupting something" explanations are gone,
which leaves the reading from section 13 standing on its own: the chain is
intact and simply is not driven.


================================================================================
15. A2 ANSWERED DEFINITIVELY -- THE GAME NEVER ASKS FOR A SCENE
================================================================================
RECOMP_ICALL_FEEDBACK is now on for this target (and for xbox_kernel, which is
where g_icall_seen actually lives -- defining it only for the executable gives
an undefined symbol). It records every indirect-branch target dispatched, which
is the only instrument that can see a chain made entirely of vtable slots.

DUMPED PERIODICALLY, NEVER FROM atexit, on upstream's warning in bdaecf3. That
mattered: every run here ends in kill -9, and the dump landed anyway -- 266
targets. An atexit dump would have produced an empty file reading as "no
indirect calls observed".

THE ANSWER:

    dispatcher sub_001596B0 (slot 23)  ->  NEVER dispatched
    render     sub_00155050 (slot 10)  ->  NEVER dispatched

AND THE PART THAT SETTLES IT. Both objects are being actively driven:

    DISPATCHER class 0x001E1640:  3 of 26 slots dispatched (0, 1, 3)
    RENDERER   class 0x001E0F00: 39 of 121 slots dispatched
        0 1 6 7 8 11 14 16 17 18 20 21 22 24 25 27 30 31 33 34 35 42 44 45 46
        54 55 56 60 61 68 73 78 81 82 83 88 113 114

    render entry slot 10:            NOT among them
    render-state setters slots 98-104: NONE among them

So the renderer is alive and used for thirty-nine different things -- setup,
queries, resources -- and never once asked to draw. The state setters are
never called either, which is exactly why the command ring stops growing after
initialisation. Every piece of evidence now agrees.

THIS CLOSES THE GRAPHICS INVESTIGATION. It is not a missing object, a dropped
pointer, a discarded switch, a drifting stub, a silently skipped indirect call,
a broken clear, a starved interrupt, or a lifter defect. All of those were
tested and are negative. The renderer works and the game does not ask it to
render.

WHAT IS LEFT IS A GAME STATE MACHINE, and it should be costed as its own piece
of work rather than continued on momentum from here. The shape of it:

    Something decides which scene or task object is current. That decision has
    not selected one whose slot 23 draws. Finding out what it is waiting for
    means reading JSRF's own logic -- sub_000659C0's tick and whatever feeds
    the container at 0x01064824 / 0x0183DFF4 that holds the dispatcher objects
    -- rather than fixing a runtime gap.

    It is title-specific reverse engineering. Nothing learned from it carries
    to the next Xbox title, which is the opposite of everything in sections
    1-14. That is not an argument against doing it; it is an argument for
    deciding to do it deliberately.

THE ALTERNATIVE WORTH WEIGHING FIRST: adopt upstream's nv2a_pb_exec (f193457)
and the rest of the work branch. That is generic, it is 49 commits of fixes
this tree keeps rediscovering independently, and it makes the renderer able to
draw when the game does ask. Route B's value was never contingent on JSRF
specifically reaching its scene.


================================================================================
16. PIXELS.  nv2a_pb_exec ADOPTED, AND THE WHOLE CHAIN IS PROVEN
================================================================================
Took upstream's CPU executor (src/kernel/nv2a_pb_exec.c, 881 lines). It decodes
NV2A methods, tracks the surface, and rasterises screen-space triangles, strips,
fans and quads straight into the GUEST framebuffer -- no device, no backend, no
window required, which is exactly what makes it a bring-up tool.

WIRED AS A SECOND SINK, not a replacement. nv2a_pusher's dispatch() feeds both
it and pgraph_d3d11_method, gated on RECOMP_PB_EXEC so the default path is
untouched. Verified: with the variable unset, the run is byte-identical to
before and writes no files.

THREE THINGS HAD TO BE PORTED:
  * ptrdiff_t needed <stddef.h>; MSVC gets it via another header.
  * strtok_s is MSVC's name for POSIX strtok_r -- same signature, so one alias
    covers both call sites.
  * xbox_FramebufferWindowSet/Start come from src/video/fb_present.c, which is
    CreateWindowExA and therefore Win32 only. Stubbed in
    src/kernel/fb_window_stub.c. STUBBING THE WINDOW DOES NOT STUB THE
    RASTERISER: the executor still draws into guest memory, and RECOMP_FB_DUMP
    writes the surface to a BMP, which answers "does it draw" without needing a
    window at all.

THE RESULT, and it is the first picture this effort has produced:

    RECOMP_PB_EXEC=1 RECOMP_RASTER_TEST=1 RECOMP_FB_DUMP=fb ./jsrf_first_fault

  writes fb000.bmp .. fbNNN.bmp, 640x480, and they contain a clean magenta
  triangle on black -- the known test triangle, undistorted and centred.

WHAT THAT ONE IMAGE PROVES, all at once:
    the ring decodes                    (it reached the executor)
    the surface ADDRESS is right        (the dump is the guest's own buffer)
    the surface PITCH is right          (a wrong pitch shears the triangle;
                                         this one is square)
    the clear works                     (black background, not garbage)
    the rasteriser works                (filled, correct winding)
    640x480 matches the guest's mode

So the path from JSRF's command ring to pixels in JSRF's framebuffer is now
proven end to end. The ONLY missing piece is the game submitting geometry --
which is section 15's state machine, and unchanged by this.

NEXT, in order of value:
  1. Blit the guest framebuffer into the existing SDL window, so this is live
     rather than a BMP. The window exists (d3d8_gl.c) and the buffer address
     and pitch are now known to be correct; it is a texture upload per frame.
  2. Wire nv2a_pb_scan.c's driver too if the ring ever grows, though our own
     pusher already covers that.
  3. The state machine (section 15) remains the only thing between this and
     JSRF's own geometry appearing.
