Shaders: ds_sub_u32 and ds_sub_rtn_u32 as a compare-exchange loop, which the card takes #1623
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!1623
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1623"
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?
@mizzied on GitHub · 2026-11-28 22:34 UTC · original
mizzied:up/ds-sub-cmpxchg→main· +101 −2 · 4 files · 1 commits · merged 2026-11-29 08:16 UTCWhat was wrong.
ds_sub_u32andds_sub_rtn_u32were lowered to an atomic subtract on LDS. On NVIDIA the driver's compiler refuses it withE_OUTOFMEMORY, so the pipeline was dropped and its draws or dispatches were lost.The fix. Both are now written as a compare-exchange loop (
Lower::lds_sub), which the card takes.Rmw::Subis removed, so nothing can emit an LDS atomic subtract again.How it was tested. RTX 5070, Windows 11. New card tests cover the subtraction (with and without the returned value) and buffer atomic add of negated data. The subtraction test fails on the old lowering.
cargo test --workspacepasses apart fromrepository_passes_policy, which already fails onmain:lower.rsis over the 640 KiB file-size limit there (#1493 raises it). Clippy reports only the 16 findings already onmain, none on lines this PR changes. Thevictory-gpuwatch::tests are flaky on this machine in files this PR does not touch, and pass on a rerun.@upipibi on GitHub · 2026-11-28 23:12 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, and WARP reports 4-4. Every lowered program here declaresWaveSize=32.f1e81b431, merged onto maind4b5d5170(--no-ff, clean, no conflicts). The PR's base isd4b5d5170, which is current main. The merge changes the same 4 files by the same +101/-2 as the PR. The head was stillf1e81b431and main stilld4b5d5170when I finished.The 3070 on driver 616.56 does not refuse main's lowering. With main's code, the LDS atomic subtraction builds a pipeline (
CreateComputePipelineStatereturnsS_OK), and every case gives the right value. So on this card,an_lds_subtraction_takes_the_data_off_and_runs_on_the_cardpasses on main's code too. It does not fail on the old lowering here. I saw noE_OUTOFMEMORYand no other refusal. TheE_OUTOFMEMORYin the description may be specific to the RTX 5070 or to its driver. That is a hypothesis: I have only this card.The PR's compare-exchange loop also runs correctly on the 3070. It is also correct with 64 threads subtracting from the same dword at once. On WARP, main's subtraction under contention removes the device, and the PR's loop does not (see the second probe below).
The tests
The two filters match exactly the PR's two tests,
emit::valu_tests::an_lds_subtraction_takes_the_data_off_and_runs_on_the_cardandemit::valu_tests::a_buffer_atomic_addition_of_negated_data_runs_on_the_card.Default, 3 runs: 2 passed, 0 failed, 0 ignored each (1.56 to 1.67 s). Neither test printed a skip line.
VICTORY_WARP=1, 3 runs: 1 passed, 1 failed, 0 ignored each. The buffer test passes. The LDS test fails in all three runs atvalu_tests.rs:231:The LDS test is hardware-only by design. It asks for
Host::new(false)alone, with the comment "one thread with LDS: WaveSize(32), which WARP refuses". ButHost::newhonoursVICTORY_WARP=1(emit/host.rs:175), so in that mode the "hardware" device is WARP, and WARP refuses theWaveSize(32)pipeline (HRESULT0x80070057, below). Main'sds_min_max_f32_order_floats_and_return_the_old_valuealready fails on WARP the same way, so this is a known WARP limit, not a regression. Still, the new test adds one more failure to aVICTORY_WARP=1run. The test could skip when the adapter it opened is the software one.The buffer test uses
run_cases, so each run dispatches on both the 3070 and WARP.Adapters
A temporary probe test (below) prints
GetDesc1of the adapter behinddevice.GetAdapterLuid()and theD3D12_OPTIONS1wave lane counts:Host::newfalse10de:24840x0true1414:008c0x2(software)VICTORY_WARP=1falseandtrue1414:008c0x2(software)Probe 1: the PR test's programs, the HRESULT and the values
I appended a temporary test to
valu_tests.rs. It builds the PR test's three one-thread programs (ds_sub_u32;ds_sub_rtn_u32then a read;ds_sub_rtn_u32returning the old value), plusds_add_u32ofbandds_add_u32of-b(v_sub_nc_u32 v2, 0, v2first). It uses the test's ownbuild_cs(.., 1, 512), so the DXIL passed the validator each time. It callsCreateComputePipelineStatedirectly and prints the raw HRESULT. When a pipeline is made, it dispatches the PR's four cases 5 times each and prints the results. I disassembled the DXIL with the Windows SDK'sdxc -dumpbin:atomicrmw sub i32 addrspace(3)* ... seq_cst;phiandcmpxchg i32 addrspace(3)* ... seq_cst seq_cstloop;ds_add_u32in both trees:atomicrmw add i32 addrspace(3)*.Each of the following ran 3 times, with identical output every time:
ds_subprogramsS_OK; 0 of 20 dispatches wrong each0x80070057"The parameter is incorrect."ds_subprograms (atomicrmw sub)S_OK; 0 of 20 dispatches wrong each0x80070057ds_add_u32ofbS_OK; 0 of 20 wrong0x80070057ds_add_u32of-bS_OK; 0 of 20 wrong0x80070057For example, main's lowering on the 3070 gave
0xa - 0x3 = 0x7,0x3 - 0xa = 0xfffffff9,0x0 - 0x1 = 0xffffffffand0x80000000 - 0xffffffff = 0x80000001. The old-value form returnedaeach time. The PR's lowering gave the same values.The commit message also says that "an atomic addition of the negated data is refused the same way on LDS". On the 3070 it is not refused:
ds_add_u32of-bon LDS makes a pipeline and givesa - b. So here, the PR's comments inlower.rs,memory.rsandbitcode.rs, and the test's doc comment, describe a refusal that this card does not make.Negative control: main's lowering, PR's tests
I checked out main's
lower.rsandbitcode.rsand removedlower/memory.rs. I kept the PR's tests (and the probes). This builds, with main's single warning.VICTORY_D3D12_DEBUG=1(debug layer on), the LDS test alone: 1 passed, 0 failed, 0 ignored. No message.VICTORY_WARP=1, 3 runs: 1 passed, 1 failed, 0 ignored each. The LDS test fails exactly as on the merge (compute_pipeline failed: The parameter is incorrect.,valu_tests.rs:231). That failure is theWaveSize(32)refusal, not the subtraction, so the WARP run tells the two lowerings apart no better.So on this card, neither of the PR's tests catches a return to main's lowering.
Probe 2: 64 threads on one dword
The PR's test uses one thread, so it never exercises the loop's retry. A second temporary test runs 64 threads (two Wave32 host waves). It sets
LDS[0] = a, thens_barrier, then every thread runsds_sub_u32(ords_sub_rtn_u32) ofb, thens_barrierand a read. The expected result isa - 64 b. There are 4 cases, among them a wrapping one (0x80000000,b = 0xffffffff) and one withb = 0x01000001. It runs 5 rounds, on both adapters throughrun_cases. These 64-thread pipelines build on WARP too.Merge, 3 runs: 80 results per run (2 ops x 4 cases x 5 rounds x 2 adapters), 0 wrong on the 3070 and on WARP.
Control (main's
atomicrmw sub), hardware only (I edited the probe torun_cases_on(.., &[("hardware", false)], ..)), 3 runs: 40 results per run on the 3070, 0 wrong.Control on WARP, 3 runs plus 1 with
VICTORY_D3D12_DEBUG=1: the first WARP dispatch ofds_sub_u32fails every time, after the 3070 has given its 4 correct results:That is the system text of
DXGI_ERROR_DEVICE_REMOVED. The probe did not print the HRESULT of the dispatch or the device-removed reason. In a WARP-only run, the same 64-thread program withds_add_u32(atomicrmw add) gave 20 of 20 correct results first, and then theds_sub_u32program removed the device again. So on WARP, it is the LDSatomicrmw subunder contention that fails, not LDS atomics in general.This is the one place on this machine where main's lowering fails and the PR's works. It is on WARP, not on the card, and no test in the PR or on main checks it.
I removed both probes before the lib suites.
cargo test -p victory-shader --lib --locked(default, once each)d4b5d5170: 350 passed, 0 failed, 8 ignored (327 s).d4b5d5170: 348 passed, 0 failed, 8 ignored (282 s).The PR adds no compiler warnings. Both builds print only main's unused
colour(lower.rs:13901on the merge).CI
gh pr checks 1623: only thelabelcheck (pass). I did not run clippy orcargo xtask policy. The PR has no comments or reviews yet.Overlap
63b902feand names no PR above #1373. It has no LDS-subtraction orE_OUTOFMEMORYitem.lower/memory.rs,Lower::lds_sub, or changesRmw::Subor the"sub_u32"arm. #733 maps"ds_sub" => "sub"in a list of its own, but it already conflicts with main.git merge-treeof the merge against the 40 other open PRs that changebitcode.rs,lower.rs,valu_tests.rsor a file underlower/. 21 are clean with both main and the merge. 17 already conflict with main. 2 merge cleanly with main but conflict with #1623, both by the same author and both mechanical: one region each, the module line aftermod intersect;inlower.rs.mod minmax;where #1623 addsmod memory;.pub(super) mod pair;at the same place.docs/asset-policy.mdandxtask/src/policy.rs, and does not overlap.Not tested
E_OUTOFMEMORYor check that the PR fixes it there. An RTX 40 or 50 series card, or another NVIDIA driver, would be needed.ds_sub_u32/ds_sub_rtn_u32, or whether their pipelines were lost.ds_sub_*.buffer_atomic_subis refused by the translator, as the description says).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.
@amazedturnip on GitHub · 2026-11-29 05:38 UTC · original
Tested on RTX 5070 Ti (driver 621.24, full 25,777-shader pretranslation + 20+ min live sessions). Cleanly eliminates NVIDIA ds_sub_u32 E_OUTOFMEMORY pipeline refusals with zero visual or compute regressions.