Skip to content

Shaders: a compute shader samples at level 0, not with derivatives (735 programs) - #2027

Closed
fiestorra wants to merge 2 commits into
Marvisak:mainfrom
fiestorra:fix/compute-sample-level
Closed

fiestorra wants to merge 2 commits into
Marvisak:mainfrom
fiestorra:fix/compute-sample-level

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

A compute shader has no derivatives to sample with: 735 programs, all Cs, all refused for it — and sampleLevel at level 0 fixes them

The next class after #1987, and this time the reason was in the run I had already made: the validator's note: line said

Function: main: error: Entry function performs some operation that is incompatible with the shader stage or other entry properties.
Function: main: error: Function uses features incompatible with the shader stage (cs) of the entry function.

735 programs, every one of them a compute shader (735 x Cs, no other stage). I dumped three of them (VICTORY_EMIT_DUMP) and disassembled with dxc -dumpbin:

billboard_nobump:CS_RaytracingResolve_a56bfb9c_Wrapped   Cs   threads (32,1,1), wave 32
  dx.op.sample (implicit)   3
  dx.op.sampleLevel       129
  dx.op.sampleCmpLevelZero  +
cloth_default:CS_RaytracingResolve_b1139868_Wrapped      Cs   threads (32,1,1)
  dx.op.sample (implicit)   3
  dx.op.sampleLevel       130

Three implicit dx.op.sample next to hundreds of explicit ones, in a stage that has no neighbours to take derivatives from. dx.op.sample is not a legal operation for cs — no shader model makes it one without the mesh/amplification derivatives feature — and the console's image_sample in that stage has no derivatives either: level 0 is what the instruction means there.

So the lowering now asks the stage: a compute program samples at level 0 with sampleLevel (62) and keeps sample (60) everywhere the implicit form is legal. The choice is sample_op(compute), and the test pins the pair.

Measured on the offline census over the same local 1.0.2.1 archive (26,503 containers), validator SDK 10.0.26100 dxil.dll 1.9:

build incompatible with the shader stage validated
main 940d32f 735 23,918
this branch 0 24,653
this branch + #2016 0 25,520

25,520 is 1,602 more programs than main: the 868 vertex programs of #1987 and these 735, minus the one that was in both classes.

One caveat worth stating, because it is the difference between "valid" and "right": the console program samples with whatever filter and coordinate the shader computed, and level 0 is the honest reading of "implicit level in a stage with no derivatives". If a title's compute shader relied on something else — a derivative register the console keeps per lane — this would change what it samples. That is worth a picture comparison on the raytracing resolve passes, which are the ones in this class, and I have not run the title to look at them.

Recipe: cargo test -p victory-shader --locked --lib 249 passed, 3 ignored; cargo test --workspace --locked 26 suites with the one failure main also has in a session without a desktop; clippy --workspace --all-targets with and without --all-features clean under -D warnings; rustfmt --check with the same 19 hunks main already has in lower.rs and no others.

No game data is involved: program names, counts, operation names and thread-group sizes.

Written with an AI assistant.

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Split the overlapping flag change and verify sampling semantics (6a16a66)

Evidence

Checks and limits

  • The reported census gain establishes validator acceptance. The added sample_op test checks an opcode pair; it does not emit a container or distinguish actual mip selection. I reviewed the source and existing evidence without rerunning the census or a GPU test.

Next step

This verification was AI-assisted.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 6a16a66. victory-shader: 246 passed, 3 failed, 3 ignored; the new a_compute_shader_samples_at_level_zero passes. The 3 are #1744's NVIDIA failures on main. Same as main on this hardware. Not run: a title.

Overlap, from reading: #1237 (quad-lane gradients to sampleGrad) and #1065 (validator 1.8 compute derivatives) fix the same 735 compute programs, and wildheathen compared the two on 70564ae in #1237. #1409 made the same level-0 change outside pixel shaders, and triage closed it as going against main's deliberate implicit-LOD samples in compute. Level 0 and the console's quad derivatives give the same result only where the coordinates move about one texel per lane. They differ where a program minifies, such as a downsample.

AI-assisted (Claude Code).

@fiestorra

Copy link
Copy Markdown
Contributor Author

Checked both fixes against the title itself: identical to main for the first 70 s, and that is the expected answer

Validation fixes are easy to ship without ever asking whether they change the executable, so I ran the title with both branches merged (this one and #2016), on this machine, in the same scenario I always use: session 1 (interactive desktop), RTX 4090, driver 32.0.16.2124, release build, empty cache, 70 s:

main 940d32f these two fixes
host view heap capped at 1000000 1 1
title slot past the host heap 310,720 310,720
no host texture … 2560x1440 format 115 1 1
host GPU device removed 2 2
last frame presented 64 64
Flags must match usage 0 0
incompatible with the shader stage 0 0

Identical, line for line. That is what I expected and it is worth saying why: the run dies at frame 64, before the title reaches the passes that use the 735 compute programs and the 868 vertex programs, so neither fix can show up in this window. The values on the two validator lines were already 0 because the runtime path does not validate at all — the fixes matter to translate --validate and to any report that counts validated programs, and they will matter to the title only once the heap cap (#1779), the texture ladder (#1630) and the removal (#1832) stop it from dying at frame 64.

So: no regression in what the title does today, and no improvement either. I would rather write that down than let a green check on the census imply the game changed.

The caveat from the pull request stands and is the one thing I still owe: the level-0 sampling in sampleLevel for compute is the honest reading of an implicit sample in a stage with no derivatives, but nothing here proves the raytracing resolve passes look the same — they are past the point this run reaches. A picture comparison over those passes needs a build that boots further, which is the #1779 + #1630 + #1832 chain.

No game data is involved: counts and warnings.

Written with an AI assistant.

@ghost

ghost commented Nov 25, 2026

Copy link
Copy Markdown

Independent synthetic comparison on Windows, RTX 3080 and WARP. I tested each head separately on upstream 940d32f. The same plain compute image_sample read a 32×32 texture whose texels encode their mip number. Each column below is the readback for constant coordinates, then quad coordinate spacings of 1/16 and 1/4, respectively.

Tree DXC 1.7 validator DXC 1.8 validator Mip readbacks on both backends
Upstream Accepted Rejected, incompatible stage 0, 1, 3
With #1065 (e198449) Rejected, container requires validator 1.8 Accepted 0, 1, 3
With #2027 (6a16a66) Accepted Accepted 0, 0, 0

Both runtime adapters created the pipelines and returned the same values across all 32 lanes, in two runs per tree. This shows the level-zero path changes observable host sampling for the same synthetic input, while the 1.8 metadata change preserves the existing host readback. Microsoft documents quad-based compute derivatives in Shader Model 6.6. The test does not establish which result matches the console for this instruction. All inputs were synthetic. No game files were used.

AI-assisted (OpenAI Codex).

@Calvix2k

Copy link
Copy Markdown
Contributor

Corpus measurement on the real shaders.rpf (1.0.2.1), victory translate … --validate --list --jobs 10, Windows 10 / RX 7800 XT, SDK dxil.dll 1.7 (default_path's pick here), release build of this head 6a16a66:

build validated incompatible with the shader stage Flags must match usage
main 940d32f 23,918 736 lines (735 programs) 868 lines (867 programs)
this head 25,520 0 0

+1,602 = 735 compute (this PR) + 867 vertex (the UAV flag commit that is also in this branch). Worth stating in the body: the branch carries two commits — 3d6a54f "a vertex shader that declares a UAV says so…" (#2016) and 6a16a66 the compute change — so merging this lands both, and #2016 becomes redundant. That is fine, but reviewers should know, and the two flag PRs are #1989/#2016 with the mesh caveat on #2016's predicate (Dathinel's fixture).

One good sign for the compute half on an older validator: these modules still validate with the SDK 1.7 dxil.dll, so the change does not declare a newer validator version — a 1.7-only machine does not lose the 735 to “validator version not supported”.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib a_compute_shader_samples_at_level_zero — passed
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fix lowering compute shader samples at level 0 instead of implicit derivatives, plus matching shader feature flags. Looks good.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

146 passed / 0 failed / 2 ignored. Compute shader samples at level 0, not with derivatives (+2 tests; references 735 affected programs) — fixes a real-world translation regression class; mixed apps+shader, apps half Windows-only.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Rebased so this pull request no longer carries #2016's commit, and measured alone: 23,918 → 24,653

When I opened this I had stacked it on #2016 (the vertex UAV flags), so the branch contained that commit and the two could not be merged in either order without a resolution in apps/victory/src/translate.rs. That was my convenience, not the repository's: the change here has nothing to do with the UAV flag, and being stacked made two otherwise-independent pull requests into a sequence.

It is now rebased onto main 940d32f alone, with only its own commit, and measured on its own over the same archive (26,503 containers, validator SDK 10.0.26100 dxil.dll 1.9):

build incompatible with the shader stage validated
main 940d32f 735 23,918
this, alone 0 24,653

and with #2016 also applied the pair reaches 25,520, which is the number I quoted before — the arithmetic was right, only the dependency was wrong.

Re-checked after the rebase: cargo test -p victory-shader --locked --lib 248 passed, 3 ignored; clippy --workspace --all-targets with -D warnings clean; rustfmt --check on lower.rs shows the same 19 hunks main already has and no others.

No game data is involved: counts and error text.

Written with an AI assistant.

@zed6000

zed6000 commented Nov 25, 2026

Copy link
Copy Markdown

Measured offline on the title's shaders (the method in #1247): merged onto main 940d32f (a clean merge) and compared program by program (victory translate --validate --list, shaders.rpf 1.0.2.1, dxil.dll 1.8.2502).

Build Change vs 940d32f cargo test -p victory-shader --lib (RX 7900 XTX)
+ this PR (34d0b4e) +735, 0 lost 248 passed, 0 failed
+ #1065 (e198449) +735, 0 lost 250 passed, 0 failed

It is the same 735 programs in both cases: all of main's "Entry function performs some operation that is incompatible with the shader stage" rejections. The two PRs merge cleanly with each other, but they are alternatives that reach the result in different ways:

The offline counts can't tell which one renders as the console does. Where those samples relied on derivative-based mip selection, level 0 would always read the top mip. The choice probably comes down to that behaviour, or to the host-runtime question raised on #1065, rather than to the counts. Offline counts only; no program names or data.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Proposed close (unchanged). The new commit only adds the missing closing brace of the test before a_compute_shader_samples_at_level_zero in crates/victory-shader/src/emit/lower.rs. The change itself is the same: sample_op makes every implicit-LOD image_sample in a compute shader into sampleLevel at level 0. That changes what those programs sample. The synthetic mip test on this PR showed mips 1 and 3 read as 0. The new test only pins sample_op's return values, not sampling behaviour.

What would change this verdict: evidence that the console's image_sample in a compute stage reads level 0 (an ISA reference or a hardware measurement), not evidence that the validator accepts the module.

This PR will be closed in 48 hours unless the author pushes a change that addresses this or a maintainer removes the label.

CI: passing (check).


Generated by Claude Code

Machad3x referenced this pull request in Machad3x/VIctory-nvidia Nov 25, 2026
…ced after it

Compiled code sets a descriptor, or the high half of the table address
it loads one through, inside a region that `s_cbranch_execz` skips when
no lane would run it, and reads it after the region. The phi where the
region ends joins the region's words with what the skip leaves in the
registers (an EXEC save, a lane mask), and tracking refused the read
("a descriptor neither loaded nor built", then "an address into a
descriptor heap with an untracked high half").

Scalar writes are the whole wave's: a lane that reaches the end without
running the region reads what another lane's run set, so the per-lane
branch structurisation makes of the skip does not hold for them. Where
every edge that fails to trace is such a skip and the other edges agree,
the read is of the region's source, provided its handle can be made
where the region ends: a constant, or a load or built descriptor whose
address only reads values that dominate that point. A table address's
high half set in such a region counts as set. Reads that trace today
are unchanged. The rule is in the module notes and docs/architecture.md;
a skip's edge holding a descriptor tracking cannot follow is a shortcut.

Offline `translate --validate` over the title's 25,982 programs: the
three "a descriptor neither loaded nor built" refusals are gone; two of
them validate, the third now reaches the validator's compute-derivative
check (the class #2027 addresses). No other program's outcome changes.
`dx.op.sample` takes derivatives, and a compute shader has none: the
validator refuses the module with "Function uses features incompatible with
the shader stage (cs) of the entry function". Measured on the offline census
over a local 1.0.2.1 shader archive (26,503 containers), validator SDK
10.0.26100 dxil.dll 1.9, the class is 735 programs, every one of them a
compute shader, and the ones dumped all carry three uses of the implicit
`sample` next to hundreds of explicit `sampleLevel`:

  billboard_nobump:CS_RaytracingResolve_a56bfb9c_Wrapped   Cs
  cloth_default:CS_RaytracingResolve_b1139868_Wrapped       Cs
  threads (32,1,1), wave 32, no shader flags declared

The console's `image_sample` in that stage has no derivatives to take either,
so level 0 is what it means; emitting `sampleLevel` with 0 keeps the meaning
and makes the module valid.

Census before and after, same archive, same validator:

  before   incompatibles 735, validated 23,918
  after    incompatibles   0, validated 24,653
  stacked on Marvisak#2016 (the vertex UAV flags): 25,520 validated, from 23,918 on main.

The choice of operation is `sample_op`, which is also what the test pins:
`("sampleLevel.f32", 62)` for a compute stage, `("sample.f32", 60)` elsewhere.
@fiestorra
fiestorra force-pushed the fix/compute-sample-level branch from 34d0b4e to 34f3cc5 Compare November 25, 2026 22:46
@wwwwwwww3333333

Copy link
Copy Markdown
Contributor

For the choice between this, #1065 and #1237: #2999 adds a GPU test that tells them apart, an [8, 8, 1] group whose lane quads (the console's) give level 1 and whose 2x2 tiles give level 3. On an RX 6750 XT, main, #1065 and #1237 read 3. #2999 reads 1 on every lane, on hardware and WARP, wave32 and wave64. This PR samples level 0 by design, so it would read 0 there (I did not run it with this test). I have not run the shader census on #2999.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Accepted: without ISA evidence this is a semantic guess, and I am measuring it

The verdict is fair. What the PR has is "the validator refuses sample.f32 in a compute stage with functions incompatible with the shader stage (cs), and 735 programs of the pack hit it" — that says a choice must be made, not which one. Choosing level 0 is a guess, and if the console's instruction is image_sample_l with its own LOD operand, sampleLevel at 0 is worse than the guess: it is wrong data.

The measurement I am running before touching this again: take the containers of the programs that fail, decode the image instruction's opcode field with our own decoder (gfx10/opcodes.rs has image_sample 0x20, _l 0x24, _lz 0x27 and the rest), and count which one those programs actually carry.

  • If they carry _l, the lowering must use the LOD the instruction names, not zero, and this PR is the wrong shape: it would become a lowering that passes the LOD operand through, which is a different change.
  • If they carry _lz, then level 0 is what the console asks for and the evidence is the instruction encoding itself, with the count of programs, not the validator's verdict.
  • If they carry plain image_sample in a compute stage, the ISA question becomes why the title has an instruction the hardware cannot run there, and I would not push a lowering until that is answered.

Until one of those is measured, this branch stays as it is and the 48-hour close should take it. I would rather have it closed than merged on a guess.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor Author

Closing it: the pack names its LOD explicitly, and this would guess for 1,838 instructions

I measured what I said I would, and the answer is that this branch should not land.

Decoding every container of the title's shader pack and counting the image-sample instruction each program actually carries, per stage:

stage image_sample _l _lz _c_lz
compute 1,838 20,392 88,254 4,717
pixel 91,531 20,593 73,942 10,356
vertex 0 212 2,144 10
mesh 0 1,818 17,484 0

So the compute programs are not short of LOD information: the overwhelming majority carry _l (an explicit LOD operand) or _lz (level zero), and the lowering already maps both to sampleLevel. What this branch changes is the 1,838 plain image_sample instructions, and it changes them to level 0 on a guess. The count is the counter-argument: 1,838 is small enough to be a decoder gap or dead code and far too large to be safe to reinterpret silently.

Three outcomes were possible when I started; the data points away from the one this branch assumed. If the plain form is a decoding gap (a variant our table does not carry), the fix is in the decoder and those instructions never reach the lowering. If it is what the console compiler emitted, the hardware has no derivative source there either, and what it does is an ISA question — not something to settle by making the validator accept the module.

I would rather close this than merge a semantic change on 1,838 instructions. The measurement that would reopen it: an ISA reference or a hardware test showing what plain image_sample reads in a compute stage.

Thanks for holding it — the 48-hour close was the right call.

Written with an AI assistant.

@fiestorra fiestorra closed this Nov 26, 2026
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…ompute follow the console's lane quads (Marvisak#2027, on Marvisak#1237)

# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026
…ompute follow the console's lane quads (Marvisak#2027, on Marvisak#1237)

# Conflicts:
#	crates/victory-shader/src/emit/lower.rs
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.

9 participants