Shaders: declare SamplerComparisonState for immediate comparison samplers and add GPU test #1493
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1493
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1493"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@piyonchu on GitHub · 2026-11-24 18:26 UTC · original
piyonchu:fix/immediate-sampler-cmp-key→main· +253 −5 · 3 files · 1 commits · openSummary
Declares immediate comparison samplers with
%struct.SamplerComparisonState*in DXILdx.resourcesmetadata and adds aView::RedTexture(R32_FLOAT) host/GPU execution test covering both declaration orders (cmp_first = falseandtrue).(Note: keying immediate samplers by
(words, is_comparison)is already onmainvia#1477.)Changes
crates/victory-shader/src/emit/shader.rs:%struct.SamplerComparisonState*undef handles whenself.cmp_samplers >> n & 1 != 0, and%struct.SamplerState*when plain, for DXILdx.resourcesmetadata (samplerlist).cmp_samplersbit flag (0x8000) when creatingdx.op.createHandleForLib/ sampler heap indexing.crates/victory-shader/src/emit/host.rs:View::RedTexture(u32, u32, &[f32])(DXGI_FORMAT_R32_FLOATSRV) so compute tests can exercise comparison sampling cleanly.crates/victory-shader/src/emit/mod.rs:immediate_sampler_used_with_and_without_comparison_validates_and_runsvalidating DXIL (dxil.dll) and executing both plain (image_sample_lz) and comparison (image_sample_c_lz) sampling across both sampler declaration orders on hardware/WARP (view_marks: false).Verification
Rebased onto
main(940d32f, commit4f32381):cargo clippy -p victory-shader --all-targets -- -D warnings -A clippy::needless_range_loop -A deprecated: pass.cargo test -p victory-shader --lib immediate_sampler_: 2 passed, 0 failed.cargo test -p xtask: 6 passed, 0 failed (repository_passes_policypasses).git diff --check upstream/main..HEAD: clean.AI-assisted; no proprietary game files used.
@piyonchu on GitHub · 2026-11-24 18:56 UTC · original · edited 2026-11-24 19:45 UTC
Added
#[cfg(windows)]onimmediate_sampler_used_with_and_without_comparison_validates_and_runsin0308b8dso non-Windows builds do not referencevalidator,valu_tests, orhost(also verifiedcargo test -p victory-shader --locked -- --skip v_med3_f32_matches_rdna2_with_nanandclippy --workspace --locked -- -D warnings). Also noted #1477 addresses the same issue.@sinan-cmyk on GitHub · 2026-11-24 20:14 UTC · original
The new test fails on NVIDIA (Ada) and passes on WARP
Result:
immediate_sampler_used_with_and_without_comparison_validates_and_runsfails on NVIDIA and passes on WARP. I merged head 0308b8d ontomainffe310e. The test fails 2 out of 2 times on the RTX 4070 SUPER and passes withVICTORY_WARP=1.0.5 instead of 1.0 is what a comparison sample returns when the driver filters the comparison results (PCF-style averaging of passing and failing texels) instead of returning one texel's comparison. So on NVIDIA, either the sampler's filter is not point for the comparison case, or the texel layout in the test puts the sample position between a passing and a failing texel. WARP returns 1.0.
Offline. I merged the head onto
mainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11, compared program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost, no failure reason changed. That is expected for a fix whose instructions sit behind earlier failures.Machine: RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter; Windows 11 25H2; Rust 1.98.1. The rest of
cargo test --locked -p victory-shader --libpasses. No game data. AI-assisted (Claude Code).@piyonchu on GitHub · 2026-11-24 20:33 UTC · original
Thanks for running that on Ada (
32.0.16.1088), @sinan-cmyk.With a
1x1texture (texel = 0.5) and Wrap/Mirror/Clamp addressing, any comparison filter (0.25 <= 0.5) can only evaluate to1.0, so getting0.5meanssampleCmpLevelZeroread the raw texel without applying comparison (falling back to the plainSamplerStatemode whencmp_first = false).Inspecting the emitted DXIL against
dxc -T cs_6_6showedshader.rswas declaring comparison immediate samplers (kind == 1) indx.resourceswith%struct.SamplerState*instead of%struct.SamplerComparisonState*. Updatedcrates/victory-shader/src/emit/shader.rsin the latest commit to emit%struct.SamplerComparisonState*whencmp_samplerssets bitn, re-verified DXIL validation (dxil.dll), RTX 4060 + WARP execution (120 passed; 0 failed; 1 ignored),clippy(default and--all-features), andxtaskpolicy checks. Would you mind re-testing on32.0.16.1088? (Also fine if maintainers prefer#1477since it addresses the same sampler-keying bug.)@wwwwwwww3333333 on GitHub · 2026-11-24 23:27 UTC · original
This PR doesn't compile against the new main (
70564ae0), so I ported it and ran it on AMD. The fix itself,lower.rsandshader.rsat cc0f47a, merges as is. The test needed two changes:HostShadergainedroot_uavs,memory,memory_writes,view_addresses,heapandheap_writes, so the test's initializer now fills them fromlowered.View::RedTexture(an R32_FLOAT SRV) to the test harness and switched the test to it, with the same texel 0.5.Result on
70564ae0+ this, RX 6750 XT (RDNA2), Windows 11, Rust 1.98.1 MSVC:immediate_sampler_used_with_and_without_comparison_validates_and_runspasses on the hardware adapter and WARP, with DXIL validation. Plain sample 0.5, comparison 1.0, both orders.cargo clippy -p victory-shader --all-targets -- -D warningsis clean.This removes main's
shortcut: one sampler used with and without comparison would need two static samplers; it becomes a comparison one, which matters for shadow-map sampling.Patch against
70564ae0(the PR's lowering + the ported test + the R32_FLOAT view)Unit tests only, no game files. AI-assisted (Claude ported it; I ran it on my machine).
@piyonchu on GitHub · 2026-11-25 00:00 UTC · original
Thanks for diagnosing the
RGBA32Fcomparison-sampling requirement and porting the test against70564ae, @wwwwwwww3333333 (and thanks again for catching it on Ada, @sinan-cmyk)!Rebased
#1493ontomain(70564ae), kept theSamplerComparisonStatechange incrates/victory-shader/src/emit/shader.rs, updatedimmediate_sampler_used_with_and_without_comparison_validates_and_runsforrange::buildand the newHostShaderfields, and addedView::RedTexture(DXGI_FORMAT_R32_FLOAT) incrates/victory-shader/src/emit/host.rsfor the test. Re-verifiedimmediate_sampler_used_with_and_without_comparison_validates_and_runs(DXIL validation + RTX 4060 + WARP), workspaceclippy(--all-targetsand--all-features), andxtaskpolicy checks.@Marvisak on GitHub · 2026-11-25 03:28 UTC · original · edited 2026-11-25 20:19 UTC
Automated triage for the maintainers.
The rebased head merges cleanly. In
crates/victory-shader/src/emit/shader.rs, thedx.resourcessampler list now gives comparison samplers a%struct.SamplerComparisonState*undef and plain samplers a%struct.SamplerState*undef. That matches what dxc emits and agrees with the kind field (1) thatmainalready writes.emit/mod.rsadds a GPU test that runs one immediate sampler with and without comparison, in both orders, on hardware and WARP, using a newView::RedTexture(R32_FLOAT) inemit/host.rs. This gives the comparison keying thatmaingained with #1477 real execution coverage. Two notes, neither blocking. The NVIDIA 0.5 result traced back to the RGBA32F test texture, so the test probably passes onmainwithout the metadata change and does not pin it on its own.tested_ordersis counted and then discarded. CI passes.Reply to the author: thanks for the rebase. I reviewed the current head
7b68a8b. TheRedTexture/TypedUavconflict is resolved without changingTypedUav.Generated by Claude Code
@piyonchu on GitHub · 2026-11-25 03:58 UTC · original
Updated
#1493(4f32381):n < 64guards incrates/victory-shader/src/emit/shader.rsandcrates/victory-shader/src/emit/mod.rs.main(940d32f) to pick upview_marksand the headless GPU test skip fixes (ccfb029/42363ab) so CIcheckruns cleanly.cargo clippy,cargo test -p victory-shader --lib immediate_sampler_2/2 passed,cargo test -p xtask6/6 passed).@piyonchu on GitHub · 2026-11-25 19:46 UTC · original
Rebased onto
main(13f91ca, commit7b68a8b) resolving theView::RedTexture/View::TypedUavconflict incrates/victory-shader/src/emit/host.rs, and re-verified (cargo clippy,cargo test -p victory-shader --lib immediate_sampler_2/2 passed,cargo test -p xtask6/6 passed).@catminou4 on GitHub · 2026-11-24 18:42 UTC · original · requested changes
This breaks
cargo test -p victory-shaderon macOS/Linux — verified locally on the PR head merged into main (ffe310e):The new test in
emit/mod.rs::testsreferencessuper::validator(#[cfg(windows)]),super::host(#[cfg(all(windows, any(test, feature = "host")))]) andsuper::valu_tests(#[cfg(all(test, windows))]), but the test itself is only#[cfg(test)]via the module. Gate the test with#[cfg(all(test, windows))](or move it next to the other host-execution tests) and macOS goes green again.Also note: #1477 fixes the same immediate-sampler comparison-mode problem and is mergeable as-is (with an in-tree test); whichever lands second will need to rebase.
@fuzeofficlal on GitHub · 2026-11-26 17:23 UTC · original · approved these changes
Verified head
7b68a8bf501956bac671861e35c18939cc444d64merged ontomain(63bcca43) on Windows 11 (RTX 5090 + WARP, Rust 1.98.1 MSVC, SDKdxil.dll,dxc.exe, and D3D12 Debug Layer).main(and clean co-merge with#1734inemit/host.rs).cargo xtask policy(191 files ok),cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features), andimmediate_sampler_tests (2/2) all pass.dxc -dumpbinacross plain-only, comparison-only, plain-first, and comparison-first shaders:emit/shader.rs:753-777lazily emits only%struct.SamplerState(kind0) or%struct.SamplerComparisonState(kind1) as needed, matchingannotateHandleproperties and passingdxil.dllvalidation.2x2View::RedTexture(DXGI_FORMAT_R32_FLOAT, verifying non-1x1 row-pitch upload) with both passing (ref = 0.25 < 0.5 -> 1.0) and failing (ref = 0.75 < 0.5 -> 0.0) comparison outcomes alongside plain sampling (0.5): both RTX 5090 and WARP passed with zero new D3D12 Debug Layer warnings/errors (ID3D12InfoQueueshowed onlymain's pre-existingID=1328warning fromView::RawUav).Minor non-blocking nit:
tested_ordersatemit/mod.rs:1795, 1967, 1970is incremented and then discarded withlet _ = tested_orders;— it could either be asserted (> 0) or dropped.@upipibi on GitHub · 2026-11-26 20:59 UTC · original
RTX 3070 8 GB (Ampere, wave32), driver 616.56, Windows 11, rustc 1.98.1. PR head
7b68a8bvs main63bcca4, each in its own tree and target dir,--locked,--test-threads=1.-p victory-shader --lib)immediate_sampler_used_with_and_without_comparison_validates_and_runs, 3 runsimmediate_sampler_filterThe earlier 0.5 vs 1.0 failure on the RTX 4070 does not reproduce here on this head. Failures also on main, not caused by the PR:
heap_direct_texture_reads_mark_their_heap_indexkills the test process (STATUS_ACCESS_VIOLATION), see #2571.a_heap_buffer_read_by_element_takes_the_views_strideanda_heap_buffer_read_where_no_buffer_view_is_reads_zerosfail on NVIDIA's structured-buffer reads, see #1835.gathers_at_a_level_match_the_hardware, see #2323. No nvlddmkm resets.AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.