Skip to content

fix(gpu): keep a flight's undeclared shader writes on pages the title writes meanwhile - #592

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
hackgods:fix/flight1-unarmed-writes
Nov 28, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
hackgods:fix/flight1-unarmed-writes

Conversation

@hackgods

Copy link
Copy Markdown
Contributor

Branch: fork fix/flight1-unarmed-writes (one commit on main d1609d9).

What. Before a Flight-1 flight (VICTORY_FLIGHT1=1, #447) is given to the host GPU, the pages its shaders may write with no list declaring them are armed (Shadow::arm_undeclared):

  • the copies its heaps view for unordered access (the bindless path), over the ranges those views reach;
  • every copy the page tables of its title-memory programs name.

The first title write to such a page during the flight then saves the page's bytes from before, and the copy-back (copy_back_marked) merges both writers' bytes, as it already does for a declared marked write (Shadow::writing). After the landing the copies are disarmed again, unless a list still declares writes there. Only the Flight-1 path changes; without VICTORY_FLIGHT1 nothing is armed.

Why. On #447, earpjonathan reported that VICTORY_FLIGHT1=1 alone makes the first indoor area after the opening much darker: median luma 13/255 against 39 without the switch.

Shaders that write through a heap's unordered views, or through title-memory programs, declare nothing. Their writes are marked in the write-mark bitmap and go back by the pages marked, but those pages were never armed. So a title write to one before the copy-back saved nothing. The copy-back then kept the title's page whole and dropped the shader's bytes on it (counted as MarkedKept).

Waited for, as without the switch, the submitting thread cannot write meanwhile. A flight lets it go on, and the title writes the next frame's data into pages the GPU writes too. On the console both land, byte by byte, because the GPU writes title memory itself. Here the GPU's results on those pages were lost: luminance, for one, which matches the darker picture.

Tests

  • New: draw::tests::flight::a_heap_view_write_and_a_title_write_on_one_page_during_a_flight_both_land.
    • A compute shader stores a dword through a heap's unordered view (marked, declared by no list) into a write-watched page.
    • The flight is held in the air by a test gate: the host queue waits on a fence of the test's (host::flight::Gate, test-only, with a 2 s watchdog).
    • Meanwhile the test writes another dword of the same 64 KiB page from the CPU, as the title's render thread does.
    • After the landing, both dwords must be in title memory.
    • Without the fix it fails: the shader's dword comes back as its old value (0x11111111 instead of 0xDEADBEEF), 3 of 3 runs on main d1609d9 under Wine + D3DMetal (M5 Pro). With the fix it passes, 3 of 3 runs.
  • Flight and marked tests with the fix (flight, marked, write_marks, copy_back filters): 23 passed, 0 failed.
  • Native cargo test --workspace: passed. gnullvm clippy --workspace --all-targets -D warnings, with and without --all-features: clean. cargo xtask policy: ok.

In game. Not measured on this branch. On our own build (with more changes), the Flight-1 arm was not darker than the arm without it in the first cell. The loss needs the title to write such a page while the flight is in the air, so it depends on the scene and on timing. A re-test in the scene of the report would confirm it. With a diagnostics build, MarkedKept in the copy report should drop to the level of a run without VICTORY_FLIGHT1.

🤖 Generated with Claude Code

… writes meanwhile

With VICTORY_FLIGHT1=1 the first indoor area after the opening renders
much darker (pragyaangaur#447: median luma 13/255 against 39 without the switch).

Shaders that write through a heap's unordered views (the bindless path)
or through title-memory programs declare nothing. Their writes are marked
in the write-mark bitmap and copied back by the pages marked
(copy_back_marked), but those pages were never armed. So a title write to
one before the copy-back saved nothing, and the copy-back kept the
title's page whole and dropped the shader's bytes there. Waited for, the
submitting thread cannot write meanwhile. A flight lets it go on, and it
writes the next frame's data into pages the GPU writes too (on the
console both land, byte by byte), so GPU-written results are lost.

Before a flight is given to the host GPU, the unordered views of its heaps
and the copies its title-memory programs' page tables name are now armed
(Shadow::arm_undeclared). The first title write to such a page during the
flight saves the page's bytes from before, and the copy-back merges both
writers' bytes, as for a declared marked write. Once the flight has landed
they are disarmed, unless a list still declares writes there. Only the
Flight-1 path changes.

The test a_heap_view_write_and_a_title_write_on_one_page_during_a_flight_both_land
makes a heap-view write and a title write on one page while the flight is
held in the air (a test gate: the host queue waits on a fence of the
test's). It fails without the fix (the shader's dword comes back as the
old value) and passes with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pragyaangaur
pragyaangaur merged commit 2dcd372 into pragyaangaur:main Nov 28, 2026
1 check passed
Nick233x pushed a commit to Nick233x/VIctory-macOS that referenced this pull request Nov 28, 2026
main's pragyaangaur#592 keeps a flight's undeclared shader writes armed until it
lands (InFlight.armed, disarmed at landing): kept, beside the prep-ahead
probe's landing record. flight.rs imports host's list Step as ListStep,
apart from its own Step of flight times. host re-exports flight's Gate
(main) and probe_marked (here).

Co-Authored-By: Claude Opus 5.5 <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