GPU: an opt-in constant takes the place of a named program that does not run (VICTORY_STAND_IN) #2620

Open
github-bot wants to merge 5 commits from github-bot/gh-2620 into main AGit
Owner

@⁠r4tedx on GitHub · 2026-11-25 16:58 UTC · original
r4tedx:gpu/shadow-stand-in-main → main · +1693 −13 · 6 files · 5 commits · open

Stacked on #2619 (VICTORY_AMBIENT), which is stacked on #2871 (clears of one view share one dynamic slot). Only the last commit is new here; merge order is #2871, #2619, then this.

A program can be held back (one walking acceleration structures the builder has not built yet), dropped, or left without a host pipeline (it does not translate). Its outputs then keep whatever the memory held, and the passes that read them see garbage: a shadow mask nothing writes can read as "in shadow" everywhere. This adds a run-time switch that clears the views a named program would have written, in place of a dispatch of it that did not run.

Opt-in, off by default. Nothing happens while VICTORY_STAND_IN is unset, and only named programs are touched. No title program names or hashes appear in the code: the user names the program by the shader hash the log already prints.

Syntax

VICTORY_STAND_IN=<program>:<view>:<value>, rules separated by ;, written exactly as for VICTORY_AMBIENT:

  • <program>: the 16-hex-digit shader hash the log prints for the compute program.
  • <view>: root parameter and table offset in dwords, s1+0 or 1+0.
  • <value>: r,g,b[,a], optionally rgb9e5= / r11g11b10= / rgba16f= for an integer view; or 0x..., mask, zero.

Example (a "lit" R16_FLOAT mask and an all-ones R8_UINT one): VICTORY_STAND_IN=0123456789abcdef:s1+0:1,1,1;0123456789abcdef:s1+8:mask. An integer view whose format does not say how a colour packs takes a raw word (0x..., mask, zero).

What it does

  • Where a dispatch of a named program, direct or indirect, does not run, its named views are cleared to the values in its place. None of the program runs, so it needs no translation, walks no structure, and holds back nothing that is held back now.
  • dispatch() and execute_indirect() become thin wrappers over their old bodies (run_dispatch() / run_indirect()), so every way a dispatch does not run reaches the stand-in. A direct dispatch records in the list state whether it ran, so an early return of any kind (skipped, held back, no host pipeline, tables not made) leaves the flag unset. An indirect dispatch returns false. Indirect draws are left alone.
  • The program's hash comes from the title pipeline without asking for a translation (pipeline::compute_hash). The program's views are not known when it does not run, so the rules are not checked against them. The first match logs the view, formats and value (with ran = false), as for VICTORY_AMBIENT.
  • The clears use the same path as VICTORY_AMBIENT, including its one dynamic slot per view per list.

Tests

The title was not used in these tests.

  • stand_ins_take_the_place_of_dispatches_that_do_not_run (WARP): three programs that do not translate, so they get no host pipeline, the same gate a held-back program meets. A named program's direct dispatch clears its two views (R16_FLOAT to 1, R8_UINT to a mask). A named program's indirect dispatch clears its view (0.5). An indirect draw, and a program no rule names, clear nothing, and no dispatch runs. Read back after the list: 1.0, 0xff, 0.5.
  • Results at 33df0691 (on #2619 a83bdc1d, #2871 d3f9b11e, main f3578e38, WARP): cargo clippy -p victory-gpu --all-targets --locked -- -D warnings and the same with --all-features, both clean; VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked: 253 passed, 0 failed, 1 ignored (an existing benchmark).

In game

In our play build (RTX 5070, local title data used for the in-game measurement; only log lines and a description of the picture are reported), with #2311 holding back the BVH walks:

  • With VICTORY_AMBIENT on the screen-probe resolve's R9G9B9E5 output, the prison cell scene was fully lit and textured. Earlier builds without it showed that scene dark, but they also lacked other changes, so this switch's share of the difference is not isolated.
  • VICTORY_STAND_IN filled the four held-back distant-shadow programs' 1280x720 R16_UINT masks: each logged fill=Ok on first use, and the combined fill count for both switches went 11 -> 348 over 2 min, 0 skipped. Whether all-ones is the right "lit" value for those masks still needs an A/B.

Credits

  • The idea of standing in for a ray-traced shadow pass with "lit" comes from ScarlettPort's shadow-mask stand-in (ZigZagBoi1/ScarlettPort, runtime/victory/crates/victory-shader/src/emit/stand_in.rs, GPL-3.0-or-later). That version rewrites the program's stores at translation. Here the program does not run at all.
  • The rule format, value packing and clear path are from #2619, whose idea comes from the Belobug fork (Belobug/VIctory-Belobug-AMD, 0603123 and 4f45ab8, GPL-3.0-or-later).

🤖 Generated with Claude Code

**@⁠r4tedx** on GitHub · 2026-11-25 16:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2620) `r4tedx:gpu/shadow-stand-in-main` → `main` · +1693 −13 · 6 files · 5 commits · open Stacked on #2619 (VICTORY_AMBIENT), which is stacked on #2871 (clears of one view share one dynamic slot). Only the last commit is new here; merge order is #2871, #2619, then this. A program can be held back (one walking acceleration structures the builder has not built yet), dropped, or left without a host pipeline (it does not translate). Its outputs then keep whatever the memory held, and the passes that read them see garbage: a shadow mask nothing writes can read as "in shadow" everywhere. This adds a run-time switch that clears the views a named program would have written, in place of a dispatch of it that did not run. **Opt-in, off by default.** Nothing happens while `VICTORY_STAND_IN` is unset, and only named programs are touched. No title program names or hashes appear in the code: the user names the program by the shader hash the log already prints. ### Syntax `VICTORY_STAND_IN=<program>:<view>:<value>`, rules separated by `;`, written exactly as for `VICTORY_AMBIENT`: - `<program>`: the 16-hex-digit shader hash the log prints for the compute program. - `<view>`: root parameter and table offset in dwords, `s1+0` or `1+0`. - `<value>`: `r,g,b[,a]`, optionally `rgb9e5=` / `r11g11b10=` / `rgba16f=` for an integer view; or `0x...`, `mask`, `zero`. Example (a "lit" R16_FLOAT mask and an all-ones R8_UINT one): `VICTORY_STAND_IN=0123456789abcdef:s1+0:1,1,1;0123456789abcdef:s1+8:mask`. An integer view whose format does not say how a colour packs takes a raw word (`0x...`, `mask`, `zero`). ### What it does - Where a dispatch of a named program, direct or indirect, does not run, its named views are cleared to the values in its place. None of the program runs, so it needs no translation, walks no structure, and holds back nothing that is held back now. - `dispatch()` and `execute_indirect()` become thin wrappers over their old bodies (`run_dispatch()` / `run_indirect()`), so every way a dispatch does not run reaches the stand-in. A direct dispatch records in the list state whether it ran, so an early return of any kind (skipped, held back, no host pipeline, tables not made) leaves the flag unset. An indirect dispatch returns false. Indirect draws are left alone. - The program's hash comes from the title pipeline without asking for a translation (`pipeline::compute_hash`). The program's views are not known when it does not run, so the rules are not checked against them. The first match logs the view, formats and value (with `ran = false`), as for `VICTORY_AMBIENT`. - The clears use the same path as `VICTORY_AMBIENT`, including its one dynamic slot per view per list. ### Tests The title was not used in these tests. - `stand_ins_take_the_place_of_dispatches_that_do_not_run` (WARP): three programs that do not translate, so they get no host pipeline, the same gate a held-back program meets. A named program's direct dispatch clears its two views (R16_FLOAT to 1, R8_UINT to a mask). A named program's indirect dispatch clears its view (0.5). An indirect draw, and a program no rule names, clear nothing, and no dispatch runs. Read back after the list: 1.0, 0xff, 0.5. - Results at 33df0691 (on #2619 a83bdc1d, #2871 d3f9b11e, `main` f3578e38, WARP): `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` and the same with `--all-features`, both clean; `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked`: 253 passed, 0 failed, 1 ignored (an existing benchmark). ### In game In our play build (RTX 5070, local title data used for the in-game measurement; only log lines and a description of the picture are reported), with #2311 holding back the BVH walks: - With VICTORY_AMBIENT on the screen-probe resolve's R9G9B9E5 output, the prison cell scene was fully lit and textured. Earlier builds without it showed that scene dark, but they also lacked other changes, so this switch's share of the difference is not isolated. - VICTORY_STAND_IN filled the four held-back distant-shadow programs' 1280x720 R16_UINT masks: each logged fill=Ok on first use, and the combined fill count for both switches went 11 -> 348 over 2 min, 0 skipped. Whether all-ones is the right "lit" value for those masks still needs an A/B. ### Credits - The idea of standing in for a ray-traced shadow pass with "lit" comes from ScarlettPort's shadow-mask stand-in ([ZigZagBoi1/ScarlettPort](https://github.com/ZigZagBoi1/ScarlettPort), `runtime/victory/crates/victory-shader/src/emit/stand_in.rs`, GPL-3.0-or-later). That version rewrites the program's stores at translation. Here the program does not run at all. - The rule format, value packing and clear path are from #2619, whose idea comes from the Belobug fork ([Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD), 0603123 and 4f45ab8, GPL-3.0-or-later). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
clear_unordered took a dynamic slot of the bound view heap on every call
and held it until the list was reset, so a list that clears the same
view many times (a per-frame clear inside a loop of passes, say) took one
slot per clear from the capped heap; when the pool runs out, later draws
and dispatches that need dynamic slots are dropped. The list's draw state
now keeps the slot it made per view (view heap, view, host resource) and
clears of that view reuse it. The cache lives with the slots: it goes
when the list is reset (or released) and at a cut of the list, where root
views are made again too. The host resource in the key is one the list
keeps, so its address names no other while the slot is held. The view is
now made before a slot is taken, so a view the host cannot make takes
none.

The clear itself moves into State::clear_view (taking the resolved view,
returning whether it was recorded), which clear_unordered calls after it
looks the title's CPU handle up; the test drives it directly.

Test (WARP): eight clears of a view take one slot, another view one
more, a further clear of the first none; the views hold their last
clears; the slots come back at reset. HostHeap::dynamic_free (tests
only) counts the free slots.

Split from #2619 at the maintainer's triage.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A view cleared on both sides of a cut (a wait that moves the recording
on to a new host list), both segments submitted in order: the first
segment's clears share one slot, the cut gives none back, the second
segment takes one slot of its own (its view heap is bound afresh) and
shares it for its next clear, and both stay held until the list is
reset, when both come back. A read in each segment sees the last clear
recorded before it in that segment.

Suggested in review of #2871.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Some outputs have inputs the host never fills: light gathered by rays
walks structures that are not built yet, so the program that resolves it
leaves black (or whatever its memory held), and shaded surfaces read it.
VICTORY_AMBIENT=<program>:<view>:<value> clears one unordered view after
every dispatch, direct or indirect, of the program whose shader hash the
log prints, to a constant:

- the view as the console code addresses it: root parameter and table
  offset in dwords (s1+176, the diagnostics' notation). It comes from the
  shader, so it holds across translator versions; the n-th view would
  shift as the translator finds more;
- the value: r,g,b[,a]. A float or normalized view takes it as it is
  (ClearUnorderedAccessViewFloat); an integer view takes it packed:
  R9G9B9E5 or R11G11B10 into a 32-bit word, RGBA16F into
  R16G16B16A16_UINT or R32G32_UINT, by the texture's format or as named
  (rgb9e5=, r11g11b10=, rgba16f=); 0x..., mask (all ones) or zero is a
  raw word for an integer view of any width (zero clears floats too).

The clear goes through the existing UAV clear path (a dynamic slot of the
bound view heap), between UAV barriers on the resource. Nothing runs
while the variable is unset. The first dispatch of a named program logs
its table views, formats, size and the packed value; counts are logged
every 5 s.

Tests (WARP): a program writes three views of a title table; after it,
the two its rules name hold the R9G9B9E5 word and the RGBA16F colour,
the third keeps what it wrote, and a program no rule names changes
nothing. CPU: R9G9B9E5 against a reference encoder (smallest shared
exponent whose mantissas fit), small floats against a nearest-code
search, the rules' parsing and the packing chosen per format.

The idea, and R9G9B9E5 held as 32-bit words, come from the Belobug fork
(github.com/Belobug/VIctory-Belobug-AMD, 0603123 and 4f45ab8,
GPL-3.0-or-later), which matches its program by name; here the user
names it by hash, so no program is named in the code. The masks and
zeros for narrower integer outputs follow ScarlettPort's stand-in
encodings (github.com/ZigZagBoi1/ScarlettPort, emit/stand_in.rs,
GPL-3.0-or-later).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An indirect dispatch with a host pipeline and a count of zero runs no
records, but the stand-ins after it still cleared the named views, over
what the title expected them to keep (review of #2619). The stand-ins
follow shader work, so after an indirect dispatch:

- at most no records (MaxCommandCount 0): no clears;
- a record count in a buffer: the clears are predicated on it
  (SetPredication, D3D12_PREDICATION_OP_EQUAL_ZERO), so a count of zero
  skips them on the GPU. A predicate is a 64-bit value at an 8-byte
  aligned offset while the count is a 32-bit word anywhere, so the count
  is copied into the low half of the list's own predicate word (8 bytes
  of video memory, zeroed at creation, common between uses). The copy is
  recorded just before the execution, where it reads the count, so the
  word holds the count it read whatever its records then write; the
  clears after it move the word to PREDICATION and back. Only the Clear
  call is predicated, not the copies and barriers that ready its view.
  Without that word the clears are skipped and logged once;
- no count: every clear, as before.

Direct dispatches are unchanged.

Test (WARP): a view seeded with a sentinel, a host ExecuteIndirect of a
program that writes it (at most one record), then the stand-in. Count 0
(at offset 4, a nonzero word after it): the sentinel survives. Count 1:
the stand-in's value. At most no records: the sentinel. No count: the
stand-in's value.

Tests count their own stand-ins: under test, ambient::filled() is the
count of this thread (each test runs on its own), not the run's, which
the stand-in tests running alongside add to. The stand-in tests'
deltas of the shared count failed when they ran in parallel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A program can be held back (one walking acceleration structures the
builder has not built), dropped, or left without a host pipeline (it
does not translate). Whatever it would have written then holds what the
memory held, and passes that read it see garbage: a shadow mask that
nothing writes can read as "in shadow" everywhere.

VICTORY_STAND_IN takes rules written as VICTORY_AMBIENT's
(<program hash>:<view>:<value>, separated by ;). Where a dispatch of a
named program, direct or indirect, does not run, its named views are
cleared to the values in its place. Nothing of the program runs, so it
needs no translation, walks no structure, and holds back nothing that is
held back now. Only named programs are touched, and nothing happens
while the variable is unset.

Every way a dispatch does not run reaches it: dispatch() and
execute_indirect() are wrappers over their old bodies. A direct dispatch
records whether it ran in the list state, so an early return of any kind
(skipped, held back, no host pipeline, tables not made) leaves it unset;
an indirect dispatch returns false. Indirect draws are left alone. The
program's hash comes from the title pipeline without asking for a
translation (pipeline::compute_hash). Since the program's views are not
known when it does not run, the rules are not checked against them; the
first match logs the view, formats and value as before.

An indirect dispatch that does not run stands in for the records it
would have run, as VICTORY_AMBIENT does after one that runs: at most
no records, no clears; a record count in a title buffer, the clears
predicated on it (its host copy brought up to date first, as the
execution would have; a count outside title buffers skips them, logged
once); no count, every clear.

Test (WARP): three programs that do not translate (no host pipeline,
the gate a held-back program meets too). A named one's direct dispatch
clears its two views (R16_FLOAT to 1, R8_UINT to a mask), a named one's
indirect dispatch clears its view (0.5), and an indirect draw and a
program no rule names clear nothing; no dispatch runs. Read back after
the list: 1.0, 0xff, 0.5. And a program that does not translate,
dispatched indirectly over a view seeded with a sentinel: at most one
record with a count of 0 (at offset 4 of a title buffer, a nonzero
word after it) keeps the sentinel, a count of 1 clears; at most no
records keeps it, no count clears.

The idea of standing in for a ray-traced shadow pass with "lit" comes
from ScarlettPort's shadow-mask stand-in
(github.com/ZigZagBoi1/ScarlettPort, emit/stand_in.rs,
GPL-3.0-or-later), which rewrites the program's stores at translation;
here the program does not run at all.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:31 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:52 UTC · original

Reviewed: superset of #2619 — adds VICTORY_STAND_IN, where a program that cannot run (held, dropped, no pipeline) has its views cleared to the stand-in values without any code running. The distinction between the two knobs is well-drawn (ambient = program runs, view overwritten after; stand-in = program doesn't run at all, so views can't be validated). Both correctly opt-in and no-op when unset. CI green.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2620#issuecomment-7170116378) Reviewed: superset of #2619 — adds `VICTORY_STAND_IN`, where a program that cannot run (held, dropped, no pipeline) has its views cleared to the stand-in values without any code running. The distinction between the two knobs is well-drawn (ambient = program runs, view overwritten after; stand-in = program doesn't run at all, so views can't be validated). Both correctly opt-in and no-op when unset. CI green.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:18 UTC · original · edited 2026-11-26 00:24 UTC

Automated triage for the maintainers.

Needs the maintainer's decision. This PR's own commit is 33df069 (VICTORY_STAND_IN), stacked on #2619 and #2871, so it can only be decided after those two. The change isn't purely opt-in in structure. dispatch() and execute_indirect() in crates/victory-gpu/src/draw.rs become wrappers over run_dispatch() / run_indirect(), with a ran-flag in the list state, for every title, even when the variable is unset. By the in-game measurements in #2619's thread, the four shadow-mask stand-ins alone made no measurable difference, and the right mask value is still open.

On your reply: the rebase onto the split-out #2871 is noted. It doesn't change the open points: the scope decision on #2619 applies here too, and the evidence for this part is weaker. CI check is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2620#issuecomment-7176205362) · edited 2026-11-26 00:24 UTC <!-- victory-triage v1 head=33df069166e0c69275bf01aaa3c7ea761ea083ff verdict=needs-work at=2026-11-26T00:24:28Z --> Automated triage for the maintainers. Needs the maintainer's decision. This PR's own commit is `33df069` (`VICTORY_STAND_IN`), stacked on #2619 and #2871, so it can only be decided after those two. The change isn't purely opt-in in structure. `dispatch()` and `execute_indirect()` in `crates/victory-gpu/src/draw.rs` become wrappers over `run_dispatch()` / `run_indirect()`, with a ran-flag in the list state, for every title, even when the variable is unset. By the in-game measurements in #2619's thread, the four shadow-mask stand-ins alone made no measurable difference, and the right mask value is still open. On your reply: the rebase onto the split-out #2871 is noted. It doesn't change the open points: the scope decision on #2619 applies here too, and the evidence for this part is weaker. CI `check` is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 23:28 UTC · original

Rebased with #2619, which is now stacked on #2871 (the slot sharing, split out at triage). This PR's own commit is the last one, 33df0691 (the same change as af1973b2). The merge order is #2871, #2619, then this.

WARP at 33df0691 (on main f3578e38): clippy -D warnings clean with and without --all-features; victory-gpu lib 253 passed, 0 failed, 1 ignored. The description is updated. The title was not used in these tests.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 23:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2620#issuecomment-7177613640) Rebased with #2619, which is now stacked on #2871 (the slot sharing, split out at triage). This PR's own commit is the last one, 33df0691 (the same change as af1973b2). The merge order is #2871, #2619, then this. WARP at 33df0691 (on `main` f3578e38): clippy `-D warnings` clean with and without `--all-features`; victory-gpu lib 253 passed, 0 failed, 1 ignored. The description is updated. The title was not used in these tests. AI-assisted
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2620/head:github-bot/gh-2620'
git switch 'github-bot/gh-2620'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2620'
git switch 'github-bot/gh-2620'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2620'
git switch 'github-bot/gh-2620'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2620'
git switch 'main'
git merge --squash 'github-bot/gh-2620'
git switch 'main'
git merge --ff-only 'github-bot/gh-2620'
git switch 'main'
git merge 'github-bot/gh-2620'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2620
No description provided.