Skip to content

GPU: an opt-in constant stands in for one view a named program writes (VICTORY_AMBIENT) - #2619

Open
r4tedx wants to merge 4 commits into
Marvisak:mainfrom
r4tedx:gpu/ambient-stand-in-main
Open

r4tedx wants to merge 4 commits into
Marvisak:mainfrom
r4tedx:gpu/ambient-stand-in-main

Conversation

@r4tedx

@r4tedx r4tedx commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Some outputs depend on 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 every shaded surface that reads it goes dark. This adds a run-time switch that clears one unordered view to a constant after every dispatch of one program the user names.

Opt-in, off by default. Nothing runs while VICTORY_AMBIENT is unset. 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_AMBIENT=<program>:<view>:<value>, rules separated by ;

  • <program>: the 16-hex-digit shader hash the log prints for the compute program (compute 0123456789abcdef).
  • <view>: the unordered view as the console shader addresses it: root parameter and table offset in dwords, s1+176 or 1+176 (the notation of the diagnostics' table listings). The address comes from the console code, so it holds across translator versions. An n-th-view index would shift as the translator finds more views.
  • <value>: a colour r,g,b[,a] (alpha 1 if left out). A float or normalized view takes it as it is (ClearUnorderedAccessViewFloat). An integer view takes it packed by the texture's format, or as named: rgb9e5=, r11g11b10= (into a 32-bit word) or rgba16f= (into R16G16B16A16_UINT / R32G32_UINT). A raw word is 0x..., mask (all ones) or zero, for an integer view of any width (zero clears float views too).

Example: VICTORY_AMBIENT=0123456789abcdef:s1+176:rgb9e5=0.3,0.294,0.282

(Level 0.3 per @tippythetaidum's measurement against Series X footage in three prison shots, where 0.6 came out 12-16 display-luma steps too bright: #2619 (comment). The right level depends on the scene; it is a stand-in, not the title's lighting.)

What it does

Tests

The title was not used in these tests.

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.

(VICTORY_STAND_IN is the follow-up PR, stacked on this one.)

Credits

  • The idea, and R9G9B9E5 held as 32-bit words, come from the Belobug fork (Belobug/VIctory-Belobug-AMD, 0603123 and 4f45ab8, GPL-3.0-or-later). That fork 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 (ZigZagBoi1/ScarlettPort, runtime/victory/crates/victory-shader/src/emit/stand_in.rs, GPL-3.0-or-later).

🤖 Generated with Claude Code

@DrDarkDK

Copy link
Copy Markdown

An indirect dispatch can have a valid pipeline and a zero count-buffer value. In that case ExecuteIndirect runs zero commands, but the success path still calls stand_ins and clears the named UAV. That can overwrite an output the title expected to keep. D3D12 command-count semantics

Should the clear run even when the indirect call executes zero commands? If it should only run after shader work, a focused regression test could seed the UAV with a sentinel, issue the indirect call with max = 1 and a zero count buffer, and verify that the sentinel survives.

Static review only.

AI-assisted with Codex.

@kotekompotek

Copy link
Copy Markdown

Reviewed together with #2620: this is the same new ambient.rs; #2620 is the superset (adds VICTORY_STAND_IN for programs that never run, ~250 more lines of docs + logic). If #2620 lands, this one is subsumed — the docs here are accurate on the spec (per-dispatch UAV clear between barriers, view addressed by console root-param + dword offset so it survives translator changes). Opt-in, off by default. CI green.

r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 25, 2026
…ords ran

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 Marvisak#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 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@DrDarkDK, thanks, good catch. An indirect dispatch with a zero count ran nothing, but the stand-in still cleared the view. Fixed in the new commit on this branch (head 67320f31):

  • With at most zero records, nothing is cleared.
  • With a count buffer, the clear is predicated on the count (D3D12_PREDICATION_OP_EQUAL_ZERO), so a zero count skips it 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 first copied into the low half of a zeroed 8-byte word the list owns. The copy is recorded just before ExecuteIndirect, at the point where the execution reads the count: after the count's host copy is refreshed and after the argument clamp's UAV barrier. Only the Clear call itself is predicated.
  • With no count buffer, it clears as before.

Regression test on WARP, as you suggested: the_ambient_stand_in_follows_only_indirect_dispatches_that_ran_records. It seeds the view with a sentinel and runs a host ExecuteIndirect with at most one record and a zero count, placed at an unaligned offset with a non-zero word after it. The sentinel survives. A count of one clears it, at most zero records keeps it, and no count clears it.

The same commit fixes a test flake: ambient::filled() now counts per calling thread under test, so stand-in tests running side by side no longer change each other's counts. The run-wide count in the log is unchanged.

clippy, both ways victory-gpu --lib, WARP, --test-threads=1 stand-in tests at --test-threads=4, 5 rounds
this PR, 67320f31 clean 205 passed, 0 failed, 1 ignored 7 of 7 each round
#2620, af1973b2 clean 207 passed, 0 failed, 1 ignored 9 of 9 each round

#2620 (VICTORY_STAND_IN) is rebased on this head and has the same fix for dispatches that don't run.

@kotekompotek, thanks for reviewing both. Yes, #2620 is stacked on this one by design: this PR is the smaller, self-contained VICTORY_AMBIENT part, and #2620 adds only its last commit on top. If the maintainers prefer one PR, merging #2620 takes both.

The title was not used in these tests.

AI-assisted

@Venom2054

Venom2054 commented Nov 25, 2026 •

Copy link
Copy Markdown

I tested the two switches separately on an RTX 5070 Ti in the prison-window shot. I used the same local integration of #2619 (11012ead) and #2620 (9d73ed65), executable, initial save, starting caches, input sequence and SDR settings for all three runs. Character textures were present in the material buffer in every run.

Enabled switch Back of head Shirt Sky
Neither 1.33 0.36 220.01
Ambient only (#2619) 32.77 40.02 238.64
Four distant-shadow masks only (#2620) 1.31 0.37 219.84

Values are displayed SDR luma on a 0–255 scale, averaged within each region and then summarized by the median of three camera-matched frames per run. With ambient alone, the shirt lettering and seams became readable. Before lighting, the shirt's median RGB stayed within two code values per channel across all runs.

The captured screen-probe dispatch was direct (320×360×1). The ambient rule filled the 2560×1440 packed screen-probe output. In the shadow-only run, all four held-back passes reported a successful fill on their 1280×720 R16_UINT masks. The last counters were 197 ambient fills and 693 shadow fills respectively, with zero skipped in both runs.

This isolates a visible contribution from ambient in this shot. Filling the four distant-shadow masks with all ones on its own produced no appreciable change on the character here. Mask polarity and interaction with ambient remain open. The ambient result still looks flat, especially around the hair.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@Venom2054, thanks. The three runs on matched frames make this easy to read: ambient alone takes the back of the head from 1.33 to 32.77 and the shirt from 0.36 to 40.02, while the four distant-shadow masks alone change nothing measurable.

Two notes on the heads you tested:

  • 11012ead / 9d73ed65 predate the zero-count fix (DrDarkDK's report above). The current heads are 67320f31 (this PR) and af1973b2 (GPU: an opt-in constant takes the place of a named program that does not run (VICTORY_STAND_IN) #2620). The fix only matters for indirect dispatches whose count is zero, so your runs should come out the same; your screen-probe dispatch was direct anyway.
  • "Flat" is what the ambient stand-in gives by design. It writes one constant into the packed screen-probe output in place of the probe GI the host doesn't produce yet: no direction, no occlusion. Detail around the hair would need the real probe and irradiance-cache passes, which are still refused on a 32-lane host.

On polarity: mask fills all ones. If those R16_UINT masks mean "1 = in shadow" in this title, all ones would keep the character shadowed, which looks the same as before. Two cheap checks on the same shot:

  1. the same four rules with zero in place of mask;
  2. ambient plus the masks together, once with mask and once with zero.

If zero brightens the character, the masks are "1 = shadowed". If neither moves it, those four distant passes aren't what darkens a close-up. The near cascades (cascadeshadows_rendering CS_ShadowRenderTiledCascades*) don't translate on a 32-lane host on main 940d32f (see my note on #1962), so a stand-in for one of them would need its own rule.

AI-assisted

@Venom2054

Copy link
Copy Markdown

I ran the three follow-ups from your reply on the same RTX 5070 Ti using the same executable, initial state and camera-matching method as the earlier report. One run per setting, three matched window frames per run. The values are median displayed luma on the same 0–255 scale.

Distant-shadow setting Ambient Back of head Shirt Sky
Four masks set to zero Off 2.17 0.46 219.26
Four masks set to all ones On 32.89 39.92 238.81
Four masks set to zero On 32.94 41.61 236.76

For reference, ambient alone was 32.77 / 40.02 / 238.64. Each of the four 1280×720 R16_UINT outputs accepted the requested fill in each run. The last combined counters showed 928 fills for ambient + ones and 1,002 for ambient + zeros, with zero skipped in either run.

Changing the masks to zero without ambient left the character a silhouette. With ambient on, the lettering and collar stayed visible with either mask value. I could see individual strands at the right edge of the head in both the ambient-only and ambient-plus-ones frames, but no additional rim lighting or ponytail detail from the distant masks. This closes the interaction check for this close-up on these revisions. The small differences do not establish mask polarity elsewhere.

@tippythetaidum

tippythetaidum commented Nov 25, 2026 •

Copy link
Copy Markdown

Calibration data for the example value, measured against Series X footage instead of by eye.

On victory-fork (its own version of this switch, VICTORY_AMBIENT=<level>, written as level × (1.0, 0.98, 0.94) into the same screen-probe resolve output), level 0.6 is exactly this PR's example rgb9e5=0.6,0.588,0.564. I compared two 600 s runs on an RTX 5080 (Series X profile, ray-tracing structure builder off, otherwise the same build and settings) shot by shot with console footage of the same scenes. The numbers are the mean display luma of the whole frame (0-255, Rec. 709 weights, 240×135 downscale); the footage is a YouTube capture of the console:

shot Series X level 0.6 level 0.3
cell, Yolanda at the table (gameplay) 90 106 94
corridor with the guard (gameplay) 86 100 88
Lucia at the cell window (cutscene) 85 97 81

So 0.6 sits 12-16 above the console in these shots and 0.3 within 2-4. The rooms also lost their flat look at 0.3: ceilings and corners darker, closer to the footage. It's still one constant everywhere, so it can't give the console's falloff. The common room, about 52 in the footage, measured 86 at 0.6; I don't have a 0.3 shot of it yet. Most of the console's light there comes from the windows, which a constant can't follow.

Caveats: one machine, one capture of the footage (YouTube's encode and levels sit between the console and these numbers), and the shots are matched by camera, not frame-exact. If the example is meant as a sensible default, 0.3,0.294,0.282 measured closer here.

AI-assisted (Claude Code, Claude Opus 5.5): runs, captures, the measurement and this text. Numbers only; no frames attached.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@tippythetaidum, thanks for measuring it against console footage. Three matched shots, with 0.6 at 12-16 over and 0.3 within 2-4, is enough to change the example. The PR description now suggests rgb9e5=0.3,0.294,0.282 and links your comment. The values in the tests stay as they are, because they check the parser, not a level.

Your caveat on the common room (about 52 on the console, 86 at 0.6) fits what the switch is: one constant for every pixel in place of probe lighting, so it can't match both a lit cell and a dim room. The real fix is getting the probe passes themselves to run, and the stand-in only bridges that gap.

AI-assisted

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs the maintainer's decision. The switch is opt-in, names no title program in code, and handles the zero-count indirect case raised in review (predicated clear).

On your reply: thanks for splitting the slot sharing out into #2871. That resolves the second point of the earlier triage. This branch still carries #2871's two commits (e7169ee, d3f9b11) under the stand-in's own (8d9a25b, a83bdc1), so it can only land after #2871. The scope question is still open and isn't something triage can settle. VICTORY_AMBIENT (crates/victory-gpu/src/ambient.rs, plus the dispatch hooks in draw.rs) overwrites a program's output with a hand-tuned constant in place of lighting the host doesn't produce. Whether VIctory wants user-configured per-program stand-ins of this kind is up to the maintainer. CI check is passing.


Generated by 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 Marvisak#2619 at the maintainer's triage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
r4tedx and others added 3 commits November 26, 2026 01:08
…held

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 Marvisak#2871.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (VICTORY_AMBIENT)

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 <noreply@anthropic.com>
…ords ran

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 Marvisak#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 <noreply@anthropic.com>
@r4tedx
r4tedx force-pushed the gpu/ambient-stand-in-main branch from 67320f3 to a83bdc1 Compare November 25, 2026 23:28
@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Following triage: the slot sharing (the old second commit, 11012ea) is now its own PR, #2871. It was adapted to main there, and a cut test was added in review. This PR is rebased on top of it, so its head a83bdc1 is #2871's two commits plus the stand-in's two (8d9a25b, a83bdc1). Please merge #2871 first. The stand-in code itself is unchanged; the only difference from the previous head is the rebase and #2871's added test.

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

AI-assisted

Steenax6 added a commit to Steenax6/VIctory-NVID that referenced this pull request Nov 26, 2026
…ght (VICTORY_AMBIENT, on by default at 0.3)

The title fills its indirect diffuse light from screen probes it traces
rays for; without the structure builder (off by default) the program
that resolves them leaves next to nothing or garbage, and whatever the
sun does not reach directly is black. Now, while the builder may not run:

- after each dispatch of the resolve (six variants), a pass of ours
  replaces its output (R9G9B9E5 as R32_UINT, table 1 dword 176) with a
  level times a warm white, shaded in creases and under objects from the
  depth the resolve read (table 0 dword 464);
- after the specular denoiser's history update (table 1 dword 40) the
  reflections are held to half of that light (without rays indoor floors
  mirrored the open sky five to ten times brighter than the room);
- the program that asks the probes for rays is left out;
- `VICTORY_AMBIENT=sky` has the level follow the sky dome the title
  draws, held as the dome alone (Belobug e48eb83).

The programs are known by the first 16 hex digits of their hash, as the
tree knows the decoration bake and culling programs;
VICTORY_AMBIENT_PROGRAMS names others. The default level 0.3 is the one
compared against console footage (Marvisak/VIctory PR Marvisak#2619, same scale:
the R9G9B9E5 value before the surfaces' colours); tint, shading,
reflection parts and the sky's curve are tunable. The pass's own heap,
root signature and pipeline are dropped from the bound state after it,
so the next draw or dispatch binds the title's again; the sky dome's host
copy is held and its state tracked per list (HostList::transition_copy).

From Belobug/VIctory-Belobug-AMD ambient.rs (0603123 to 4f62c2a, e48eb83,
44dcd43, c3bd561, 6986a57; GPL-3.0) as fxceless/victory-fork PR Marvisak#1093
wired it, with the level of Marvisak/VIctory PR Marvisak#2619.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants