Skip to content

iPhone Duo work: D3D11 event-query parking, per-encoder GPU timing, shader-miss figures, archive-only lookups, pso-warm pacing - #58

Draft
Dragooon wants to merge 6 commits into
willfaust:ios-portfrom
Dragooon:duo-all
Draft

Dragooon wants to merge 6 commits into
willfaust:ios-portfrom
Dragooon:duo-all

Conversation

@Dragooon

@Dragooon Dragooon commented Nov 22, 2026 •

Copy link
Copy Markdown

Impact

No run compared this branch with an unmodified dxmt at matched content, so this PR claims no overall figure. Measured on an iPhone with Path of Exile 2, per change:

  • Event-query parking: Path of Exile 2 polls an event query up to about 130,000 times a frame. With parking on, each burst parks on the queue's event instead. On in every session since 4 Nov 2026, with no hangs or missed signals seen. The CPU saved was not isolated.
  • Archive-only lookup: what makes Madeira's pso-create-block = 2 possible. With block 1, MapMire held the game's loading thread for 315 s over 1,100 archive misses; with 2 a miss goes to the background builders.
  • pso-warm yields and saves by age, hit counting: no isolated measurement.
  • gpu-pass-timing, shader-miss figures: diagnostics. gpu-pass-timing gave the per-encoder GPU times behind the Madeira PR's GPU findings.

Commits

  1. 3dacbe5b d3d11: opt-in parking of burst GetData polls on event queries (MADEIRA_D3D11_QUERY_PARK). Once the polls of one event query come in a burst (less than 250 us apart, after 2 of them), GetData parks the caller on the queue's shared event until the value is signalled, at most 1 ms, and then answers. A one-off poll never waits. It only parks once the chunk holding the signal has been committed, and it does the flush GetData would do anyway first. The [gpu-perf] line gains parked polls and time parked per frame.
  2. fdbf684b winemetal: opt-in per-encoder GPU timing (gpu-pass-timing).
  3. 95db7f41 winemetal: shader-miss figures for the performance overlay.
  4. 694f7686 winemetal: archive-only pipeline lookup when the caller asks to fail on a miss.
  5. fe0ba66a winemetal: pso-warm yields to the game's compiles; archive saves by age.
  6. 03d4720d winemetal: pso-warm counts a warm-up as a hit when the saved chunks had it.

Defaults

  • Opt-in: event-query parking (MADEIRA_D3D11_QUERY_PARK=1), gpu-pass-timing.
  • The archive-only lookup only runs when the caller asks for it (Madeira's pso-create-block = 2).

Left out

  • MadeiraCtl ops 30-32 (MetalFX frame interpolation fed by the game's motion vectors and depth). They go with Madeira's frame generation, which waits for a later PR.

Other branches

  • No branch of willfaust/dxmt already has any of these commits (checked by patch id on 22 Nov).
  • codex/dxmt-upstream-port (the dxmt that codex/dxmt-upstream-build-port pins) conflicts with two hunks: the query header (ID3D11Query1 there) and the render-encoder creation (tile size there). The same six commits rebased onto it, with both kept, are on Dragooon:duo-all-upstream-port (e3b2223..6f57b0a). Every symbol they use exists on that branch; it was not compiled.
  • The other active branches (codex/dxmt-consolidation, codex/graphics-common, codex/vulkan-dxgi, playport/*) merge with this one cleanly.

Testing

  • Every change has run on the phone, with query parking on since 4 Nov and the rest added between 11 and 18 Nov.
  • The only difference from the device build is query parking's default (on there, opt-in here: four lines). Not compiled here after that change.

🤖 Generated with Claude Code

ShitizZip and others added 6 commits November 22, 2026 17:07
…A_D3D11_QUERY_PARK)

Games build a GPU fence out of while (GetData(event) == S_FALSE) {}. Path
of Exile 2 does it every frame, up to about 130,000 polls a frame. Under
emulation every poll is an x64 -> ARM64EC round trip plus a Metal call, and
the polling thread keeps a performance core busy for nothing, which on a
phone is heat that throttles the threads doing real work.

With MADEIRA_D3D11_QUERY_PARK=1, once the polls of one event query come in
a burst (pending polls less than 250 us apart, after 2 of them), GetData
parks the caller on the queue's shared event until the query's value is
signaled, at most 1 ms (Metal's wait timeout is in milliseconds), and then
answers. A one-off poll, such as a query read once a frame after it was
issued, never waits. It only parks once the chunk holding the signal has
been committed, since no wait could see it complete before that, and it
does the flush GetData would do anyway (no DONOTFLUSH) first. This is the
same idea as D3D9's WaitCPUFenceBounded parking, on the D3D11 event value. A
[query-park] line at the first event query says the switch is on.

The [gpu-perf] line gains the parked event polls per frame and the time
parked per frame.

Off by default. Tested on an iPhone with it on in every session since 4 Nov
2026 (Path of Exile 2 on D3D11 and D3D12, Steam): no hangs or missed
signals seen.

Signed-off-by: Shitiz Garg <mail@shitiz.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was no way to see which passes cost GPU time on an iPhone that cannot
be attached to Instruments. madeira.cfg gpu-pass-timing = P (seconds, 0 =
off, the default) times every Metal encoder for one second in every P with
an MTLCounterSampleBuffer per command buffer: vertex and fragment start/end
samples for render passes, start/end for compute and blit encoders (through
pass descriptors, so the dispatch type is kept). Each encoder's label is
kept with its samples.

Once per window it logs [gpu-pass]: GPU busy per frame, the union of the
encoder intervals (what is left are gaps where no encoder ran: fence waits,
scheduling), the overlap between encoders, and the passes ranked by GPU
time with their vertex and fragment split, keyed by the encoder label.
Every gpu-pass-dump-s seconds (default 30) the next three command buffers
are listed encoder by encoder with start offsets ([gpu-pass-dump]). Off,
nothing is attached and each encoder costs one relaxed load; remote (wmtr)
command buffers are never timed.

On an iOS 27 iPhone the timestamps came at 1.0 ns per tick with no missing
samples. Labels come from the D3D side (encoder-labels in madeira-d3d12).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Shitiz Garg <mail@shitiz.me>
The overlay had no way to show why a stretch hitches or monsters stay invisible:
shader conversions, pipeline compiles that missed the pso-archive, and the
pso-async backlog only appear in log lines written every few hundred events.

madeira_shader_overlay_stats() gives the overlay, once per tick:
- shader_misses: madeira-d3d12's count of stages its shader cache did not have,
  read from the counter block it already publishes with MadeiraCtl op 5 (its
  overlay fields sit at byte 184, after struct ios_xp_pe and ios_xp_pe_cap);
- pipeline_misses: pipelines the pso-archive's saved chunks did not have and
  that were compiled for the game (inline add, queued add, or a plain create
  once the archive is full). pso-warm's own background compiles are left out
  through a thread-local flag;
- pso_queue / pso_background: the pso-async queue draws wait on (queued or
  being built) and the create-time queue behind it, from the same block;
- flags: block present, shader cache on, pso-async on, archive in use.

The block is the game process's memory, gone once the game exits while Steam
stays, so it is read with vm_read_overwrite (as server_ios.c reads guest memory):
a stale address gives no figures instead of a fault.

Counting costs one relaxed atomic add on a path that is compiling a pipeline
anyway; nothing runs per frame. An older madeira-d3d12 (shorter block) gives
zeros and no "block present" flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Shitiz Garg <mail@shitiz.me>
…on a miss

A render or compute pipeline created with fail_on_binary_archive_miss and no
archives of the caller's own now looks only in the pso-archive's saved chunks:
a miss returns no pipeline and no error and compiles nothing. madeira-d3d12
uses it (pso-create-block = 2) to take a pipeline from the archive inside the
game's create call and leave misses to its background builders. Nothing set
the flag without archives before, so other callers are unchanged.

Signed-off-by: Shitiz Garg <mail@shitiz.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pso-warm's background compiles share Metal's compiler with the pipelines
the game waits for. A warm-up that missed the saved chunks now waits
before compiling until no compile for the game is running and the last
ended 500 ms ago; archive hits go straight through.
MADEIRA_PSO_WARM_YIELD=0 turns the wait off.

The effect of the wait on frame time was not isolated. The [pso-warm]
line that suggested hundreds of competing warm compiles a session classed
a warm-up by its wall time and counted cache hits that waited for a core
as compiles; the next commit fixes that count. In Path of Exile 2 the
warm-ups that really compile are about 57 a session.

The open archives were saved when full (128) or after 10 s without an
add. In a map the adds never pause that long, so a session that ended
there lost up to five part-filled archives (50-228 pipelines a session in
the logs) and the next visit compiled them again. They are now also saved
once their oldest unsaved add is MADEIRA_PSO_ARCHIVE_MAX_AGE seconds old
(default 20; the check runs every 5 s).

[pso-archive] lines give the inline adds made for the game apart from
pso-warm's; [pso-warm] lines how often and how long warm-ups waited.

Signed-off-by: Shitiz Garg <mail@shitiz.me>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ad it

[pso-warm] classed a warm-up by its wall time: under 3 ms a cache hit,
anything longer a compile. The warm-ups run on utility-QoS queues, and
while a game saturates the cores a utility thread waits seconds for one,
so lookups the saved chunks answered were reported as compiles. Path of
Exile 2, 18 Nov 2026: "488 compiled (avg 1045.9 ms)" in a session where
the archive's own counters show about 57 pipelines pso-warm really had to
add (295 misses, 238 of them for the game). The figure read as hundreds
of compute pipelines compiled again every session, which they are not.

A warm-up is now a hit when the saved-chunk lookup returned its pipeline
(a thread-local set by madeira_arch_note_hit around the warm-up's own
create). With no saved chunks in use the 3 ms rule stays. No behaviour
change; the [pso-warm] line keeps its wording.

Signed-off-by: Shitiz Garg <mail@shitiz.me>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants