Shaders: declare SamplerComparisonState for immediate comparison samplers and add GPU test #1492
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by piyonchu on 2026-11-24T18:26:19Z.
Summary
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.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T18:42:20Z.
Review: CHANGES_REQUESTED
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.
Imported from Marvisak/VIctory. Originally posted by piyonchu on 2026-11-24T18:56:38Z.
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.Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:14:22Z.
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 head0308b8dontomainffe310e. 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).Imported from Marvisak/VIctory. Originally posted by piyonchu on 2026-11-24T20:33:25Z.
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.)Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-24T23:27:59Z.
This PR doesn't compile against the new main (
70564ae0), so I ported it and ran it on AMD. The fix itself,lower.rsandshader.rsatcc0f47a, 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).
Imported from Marvisak/VIctory. Originally posted by piyonchu on 2026-11-25T00:00:52Z.
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.[PR #1493] Shaders: key immediate samplers by comparison modeto [PR #1493] Shaders: declare SamplerComparisonState for immediate comparison samplers and add GPU testImported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:28:50Z.
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
Imported from Marvisak/VIctory. Originally posted by piyonchu on 2026-11-25T03:58:56Z.
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).Imported from Marvisak/VIctory. Originally posted by piyonchu on 2026-11-25T19:46:16Z.
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).Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T17:23:04Z.
Review: APPROVED
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.Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-26T20:59:39Z.
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).
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-27T00:31:29Z.
Review: APPROVED
LGTM — verified on Windows (RTX 5090 + WARP):
cargo test -p victory-shader --lib emit::tests::passed (18/18, including the newimmediate_sampler_used_with_and_without_comparison_validates_and_runsacross bothcmp_firstorders with DXIL validation + RTX 5090 and WARP readback)struct.SamplerComparisonStatefor immediate comparison samplers inshader.rsmatches the DXIL sampler resource metadata cleanlycargo clippy -p victory-shader --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (191 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T15:29:58Z.
I tested #1493 with #2983 and #1687 on
63bcca4. Combined branchdf14503preserves the original commits. The test calls the production emitter to build its static samplers and uses the existing R32_FLOAT depth-view fixture.The six cases cover both declaration orders with Standard, Minimum and Maximum reduction. The ordinary texture sample returns 0.5, 0.125 and 0.875 respectively. The comparison sample returns 0.5 in every case on app-local WARP 1.0.22. With only the old filter operation restored, the same test sees
0x194where the comparison slot should contain0x94. The ordinary slot retains its original reduction.Both immediate-sampler tests and all three comparison-gather tests passed with DXIL validation. Strict shader Clippy and asset policy passed. A serial full rerun was 335 passed, 4 failed, 3 ignored, versus 334/4/3 on the earlier combined branch. The four failing tests agree on the paired rerun. An initial run also hit the intermittent divergent permute test.
Imported from Marvisak/VIctory. Originally posted by UncommonDLL on 2026-11-27T16:14:19Z.
We tested combined commit
df145031b521bfd4c1b663b1228e7e132dda077eon a physical RTX 5070 Ti with NVIDIA driver 621.40. In both declaration orders, the ordinary sample returned 0.5 for Standard, 0.125 for Minimum and 0.875 for Maximum. The comparison sample returned 0.5 in all six cases. WARP passed the same six cases separately. DXIL validation passed for every shader, with zero cases skipped on either adapter.OpenAI Codex added observation logging and ran the Windows test with the original assertions intact. Libtest reported one pass. The wrapper did not retain the numeric exit code.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.