Sample mask: masked draws discard the pixels OMSetSampleMaskX leaves out (LOD crossfade) #1407
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!1407
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1407"
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?
@atk3001 on GitHub · 2026-11-28 19:15 UTC · original
atk3001:pr/sample-mask→main· +424 −16 · 10 files · 1 commits · closed without mergingWhat
GTA calls
OMSetSampleMaskX(newer list slot 142, 0x470) to fade between an object's levels of detail. The old and the new level are drawn with complementary masks over each 2x2 quad: 25/50/75 % of the quad, e.g.0x0000ffffffff0000/0xffff00000000ffff. All of these are mesh draws, across about 20 shader pairs in a few seconds of play. Until now slot 142 wasignored_state, so both levels drew every pixel during a fade.with_pixel_maskmakes a second translation of a pixel program. At entry it finds the pixel's place in its quad fromSV_Position; when the signature has noSV_Position, it adds one. It reads its bit from a new host user-data dword,USER_PIXEL_MASK(0x108), and discards the pixel when the bit is clear. That translation also drops the early depth test, so a discarded pixel writes no depth.State::set_sample_mask).Shader::masked, whose hash ends in-mask, so it has its own cache entry and pipeline-library entry.GraphicsState: Clone(the input names are re-pointed) andmake::made_or_start.Tests
a_pixel_mask_draws_only_its_pixels_of_each_quad. On hardware and WARP, with and withoutSV_Positionin the signature, each mask draws exactly its pixels, and the complementary pairs cover every pixel once.victory-shaderlib: 294 passed.victory-gpulib: 454 passed.is_multiple_ofwarning.xtask policyfails only on main's ownbindings.ini.Limits
🤖 Generated with Claude Code
0938dd9b07to74daaa0d5e@upipibi on GitHub · 2026-11-28 22:49 UTC · original
Tested on Ampere: RTX 3070 (
10de:2484), driver 616.56, native Windows 11 Pro 10.0.26100, rustc 1.98.1. Debug test profile. The system WARP is the one that ships with Windows. Wave sizes tested: 32 lanes only (the 3070 reportsWaveLaneCountMin/Max32-32; WARP reports 4-4). The PR's program is a pixel shader, so the wave width does not enter its test.74daaa0d5, merged onto maind4b5d5170(--no-ff, clean, no conflicts). The PR's base is923e38cc, 3 commits behind main (the README, the issue forms and the label bot; none of them touch these files). The merge changes the same 10 files by the same +424/-16 as the PR. The head was still74daaa0d5and main stilld4b5d5170when I finished.On the 3070, main's code draws every pixel under every mask. With the PR, each mask draws exactly its pixels of each quad. The PR's test renders on the device: a mesh triangle and a pixel program on a 16x16 target, on the 3070 and on WARP in the same run. It is not a CPU replay. Both controls below fail it on both adapters.
The test
The filter matches only the new test,
emit::tests::a_pixel_mask_draws_only_its_pixels_of_each_quad.VICTORY_WARP=1, 3 runs: 1 passed, 0 failed, 0 ignored each (0.10 s).The test loops over
Host::new(false)andHost::new(true)itself. It moves on to the next adapter with a barecontinuewhenHost::newfails, and to the next mask whenroot_signature_forfails. It printsno device with mesh shaders; skippedonly when nothing at all was drawn. So a pass does not by itself show that both adapters drew. It printed nothing in any run here. The temporary probe below shows that both adapters drew every mask.With
VICTORY_WARP=1,Host::new(false)opens WARP too, so those runs draw on WARP twice and never on the 3070.Adapters and wave sizes
A temporary probe test (below) prints
GetDesc1of the adapter behinddevice.GetAdapterLuid(), theD3D12_OPTIONS1wave lane counts and theD3D12_OPTIONS7mesh shader tier:Host::newfalse10de:24840x0true1414:008c0x2(software)VICTORY_WARP=1falseandtrue1414:008c0x2(software)The pixels drawn (temporary probe)
I added a temporary test beside the PR's in
emit/mod.rs. It makes the same draws for the same masks and both signatures, 3 rounds each. Instead of asserting, it prints the lit pixel count out of 256, the pixels that differ from the mask's quad pattern (x & 1 | (y & 1) << 1), whether the mask's user-data dword is there, and one lit and one dark texel. The DXIL passed the validator for every translation. I removed the probe before the lib suites.Merge, on the 3070 and on WARP alike, with and without
SV_Positionin the signature, and the same in all 3 rounds:0b11110b01100b10010b00010b11100b0000Lit texels read
[1.0, 1.0, 1.0, 1.0]and dark texels[0.0, 0.0, 0.0, 0.0].Negative control A: main's lowering, PR's tests
I deleted only the three lines in
Lower::lowerthat callself.pixel_mask().with_pixel_maskthen sets a flag that nothing reads, as if the translator were main's. It builds, with one extra warning (pixel_maskis never used).VICTORY_WARP=1, 3 runs: 0 passed, 1 failed, 0 ignored each.All six failed the same way, at
emit/mod.rs:2429, before any draw:So the test's own failure on main's code is the missing user-data dword, not a pixel. The probe (3 runs on this control, 3 rounds each) shows what the 3070 draws then. Every masked draw lights all 256 of 256 pixels, on the 3070 and on WARP alike, with and without
SV_Position. Wrong pixels: 128 for0b0110and0b1001, 192 for0b0001, 64 for0b1110and 256 for0b0000. No texel is dark. That is the double draw the description gives for the LOD fades.Negative control B: the PR's dword, no discard
I deleted only the
discardop inpixel_mask()and kept theSV_Positioninput, the user-data dword and the dropped early-depth flag. It builds, with one extra warning (killunused).VICTORY_WARP=1, 3 runs: 0 passed, 1 failed, 0 ignored each.All six failed at
emit/mod.rs:2463, on the first pixel check:The probe on this control shows the dword at index 0 and again 256 of 256 pixels lit for every mask on the 3070. So the test's pixel check, not only its dword check, catches a translation that does not discard.
Lib suites (default features unless named; once each, except the
diagnosticsWARP row)d4b5d5170cargo test -p victory-shader --lib --lockedcargo test -p victory-gpu --lib --lockedVICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --locked --features diagnosticsThe extra victory-shader pass is the new test. The PR adds no victory-gpu tests, so those counts match.
The
diagnosticsWARP failures look like flakes in code the PR does not touch, but they came only on the merge. I ran that suite 7 times on the merge and 5 times on main. Main was clean every time. The merge was clean 5 times, and twice one test failed, a different one each time:watch::tests::what_is_put_in_beside_the_guards_is_told_at_every_view(watch.rs:4789,assertion failed: published(two, two + BLOCK));descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes(descriptor/host.rs:6935,left: 6291456,right: 65536).Neither file is in the PR. Run alone, the watch test passed 10 of 10 on the merge and 10 of 10 on main. Our earlier main baseline on this card already lists flaky descriptor::host tests. I did not find a way the PR's changes could reach either test, but 2 failures in 7 runs against 0 in 5 is not enough to rule it out.
VICTORY_D3D12_WARP=1takes effect only in a--features diagnosticsbuild: the shared test devicehost()(host.rs:893) checks it athost.rs:957. It changes nothing for the PR's own test, which is in victory-shader and readsVICTORY_WARP(emit/host.rs:175).The PR adds no compiler warnings. Both builds print the same warnings: in victory-shader, main's unused
colour; in victory-gpu,gpunever read,let_goandhost_pressure_reclaimednever used, and threedropof a reference.What the tests do not reach
The new test covers the translator only:
with_pixel_maskand thepixel_mask()prologue. No test calls any of the victory-gpu side: slot 142 (sample_mask_x, in both the plain table andthin.rs),State::set_sample_maskandState::pixel_mask(the 64-bit mask to 4 pixel bits), theUSER_PIXEL_MASKuser-data value,host_pipeline_masked,make::made_or_start,Shader::masked,host_shader_maskedwith its separate cache key, andGraphicsState::clonewith its re-pointed semantic names. I only read that code. By reading, the description's example masks0x0000ffffffff0000and0xffff00000000ffffbecome0b0110and0b1001, two of the masks the test draws.The test has no depth target, so it does not check that a discarded pixel writes no depth (the dropped early-depth flag).
CI
gh pr checks 1407: no checks reported on the branch. I did not run clippy orcargo xtask policy. The PR has no comments or reviews yet.Overlap
63b902feand names no PR above #1373. It does not list #1407 or any sample-mask or LOD-fade item.sample_mask_xinlist.rs. That one only logs the first eight distinct masks ("a quad sample mask the host does not apply") and has a test,sample_masks_are_noted_once_each.git merge-treeshows one conflict region, theNEWER_METHODSdoc comment. The identical(142, sample_mask_x ...)lines merge silently, but the result would definesample_mask_xtwice. Whichever lands second has to drop or rename its function. #1510 also lists 0x470 in a table of named methods.git merge-treeof #1407 against the 121 other open PRs that change any of its 10 files. 61 are clean with both main and the merge, and 51 already conflict with main. 9 merge cleanly with main but conflict with #1407:pipeline.rs, 3 regions, andemit/mod.rs, 1 region. Both PRs givetranslatea secondbool, #1407maskedand #1555as_compute. #1555's newShader::oursbuilds aShaderwithout #1407'smaskedandmasked_twinfields, so it will not compile until they are added. Thepub use lower::{...}lines conflict too.shader_cache.rs, 3 regions. Both replacehost_shaderwith a variant function (host_shader_as(masked)againstshader_variant(link)), and the cache key and translate closure collide.pipeline.rstranslate, thehost_shadercall beside the store classification. Mechanical.VICTORY_HELD_FRAME_MS): one region each inpipeline.rs, at thetranslatecall and next tohost_pipeline_masked. Mechanical.pub use shader::{...}list inemit/mod.rs(both add a name). Mechanical.draw.rs, where both add aStatemethod at the same place. Mechanical.OMSetSampleMask.Not tested
VICTORY_SHADER_OPT, clippy,cargo xtask policy, the release build, and the rest of the workspace.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
@trustno1-coder on GitHub · 2026-11-29 00:25 UTC · original
Merged into main as
f798bde2("Merge pull request #1407"), which brought in your commit0938dd9b. The branch was rebased afterwards, so GitHub doesn't mark it as merged by itself. It's in main as off9dfb76f. Thanks!Pull request closed