test(shader): initialize Root UAV buffers before dispatch #1912

Closed
github-bot wants to merge 1 commit from gh-pr/1912/head into gh-pr/1912/base
Owner

@⁠Damokles2 on GitHub · 2026-11-25 00:45 UTC · original
Damokles2:fix-shader-uav-bitmap-init → main · +55 −9 · 2 files · 1 commits · closed without merging

Summary

Explicitly initialize Root::Uav buffers in the shader test host before dispatch, ensuring deterministic contents for shaders that update page bitmaps using atomic OR.

The change is limited to the shader test host and a synthetic regression test. Production shader lowering and GPU runtime behavior are unchanged.

Changes

  • Initialize DEFAULT-heap UAV buffers to zero using an upload buffer and CopyBufferRegion.
  • Transition resources from COPY_DEST to UNORDERED_ACCESS before dispatch.
  • Preserve existing readback synchronization and retain upload resources through fence completion.
  • Add a synthetic regression that pre-fills the same 256-dword bitmap with nonzero values and verifies that only the three expected pages remain marked after dispatch.

Regression evidence

The seeded regression was tested with initialization deliberately disabled as a negative control:

  • Without initialization: 259 marked pages instead of 3 on both the default D3D12 device and WARP.
  • With initialization: exactly 3 expected pages on both paths.

This confirms that the test host clears pre-existing bitmap contents before shader execution.

Verification

  • Memory tests: 3 passed with default adapter selection.
  • Memory tests with VICTORY_WARP=1: 3 passed.
  • BVH tests with VICTORY_WARP=1: 14 passed.
  • BVH tests with default adapter selection: 11 passed, 3 failed. The three failures reproduce existing baseline 1-ULP floating-point mismatches and are unchanged by this patch.
  • Strict Clippy: passed on retry.
  • git diff --check: passed.
  • cargo fmt -p victory-shader -- --check: reports pre-existing formatting differences; no new formatter differences were introduced in the modified files.

The default D3D12 adapter model was not independently verified. An initial build attempt was blocked by Windows Application Control (OS error 4551), but the subsequent regular build and test runs succeeded without security-policy changes.

Related issue

Related to #1882.

This patch establishes deterministic UAV initialization and prevents stale bitmap bits from surviving into shader execution. Whether uninitialized contents caused the original intermittent failure reported in #1882 remains unconfirmed.

AI-assisted using OpenAI Codex.

**@⁠Damokles2** on GitHub · 2026-11-25 00:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/1912) `Damokles2:fix-shader-uav-bitmap-init` → `main` · +55 −9 · 2 files · 1 commits · closed without merging **Summary** Explicitly initialize `Root::Uav` buffers in the shader test host before dispatch, ensuring deterministic contents for shaders that update page bitmaps using atomic OR. The change is limited to the shader test host and a synthetic regression test. Production shader lowering and GPU runtime behavior are unchanged. **Changes** - Initialize DEFAULT-heap UAV buffers to zero using an upload buffer and `CopyBufferRegion`. - Transition resources from `COPY_DEST` to `UNORDERED_ACCESS` before dispatch. - Preserve existing readback synchronization and retain upload resources through fence completion. - Add a synthetic regression that pre-fills the same 256-dword bitmap with nonzero values and verifies that only the three expected pages remain marked after dispatch. **Regression evidence** The seeded regression was tested with initialization deliberately disabled as a negative control: - Without initialization: **259 marked pages instead of 3** on both the default D3D12 device and WARP. - With initialization: **exactly 3 expected pages** on both paths. This confirms that the test host clears pre-existing bitmap contents before shader execution. **Verification** - Memory tests: **3 passed** with default adapter selection. - Memory tests with `VICTORY_WARP=1`: **3 passed**. - BVH tests with `VICTORY_WARP=1`: **14 passed**. - BVH tests with default adapter selection: **11 passed, 3 failed**. The three failures reproduce existing baseline 1-ULP floating-point mismatches and are unchanged by this patch. - Strict Clippy: passed on retry. - `git diff --check`: passed. - `cargo fmt -p victory-shader -- --check`: reports pre-existing formatting differences; no new formatter differences were introduced in the modified files. The default D3D12 adapter model was not independently verified. An initial build attempt was blocked by Windows Application Control (OS error 4551), but the subsequent regular build and test runs succeeded without security-policy changes. **Related issue** Related to #1882. This patch establishes deterministic UAV initialization and prevents stale bitmap bits from surviving into shader execution. Whether uninitialized contents caused the original intermittent failure reported in #1882 remains unconfirmed. AI-assisted using OpenAI Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:48:34 +00:00
github-bot closed this pull request 2026-11-26 04:48:34 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:51 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 0ababf5: cargo test -p victory-shader --locked gives 244 passed, 3 failed, 3 ignored. The new dirty_page_bitmap_is_zeroed_before_dispatch passes. The 3 failures are #1744's NVIDIA ones on main (the two stride_tests heap-buffer reads and gathers_at_a_level_match_the_hardware), so there is nothing new on this hardware.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/1912#issuecomment-7148965532) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `0ababf5`: `cargo test -p victory-shader --locked` gives 244 passed, 3 failed, 3 ignored. The new `dirty_page_bitmap_is_zeroed_before_dispatch` passes. The 3 failures are #1744's NVIDIA ones on `main` (the two `stride_tests` heap-buffer reads and `gathers_at_a_level_match_the_hardware`), so there is nothing new on this hardware. AI-assisted (Claude Code).
Author
Owner

@⁠Headache3318 on GitHub · 2026-11-25 02:06 UTC · original

Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head 0ababf5 applied cleanly onto current main ccfb029.

  • cargo test -p victory-shader --locked: 144 passed, 0 failed, 2 ignored. All tests pass. The new UAV initialization test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on main ccfb029). The PR introduces no new clippy warnings.

Not tested: Windows MSVC build, the title itself. AI-assisted.

**@⁠Headache3318** on GitHub · 2026-11-25 02:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/1912#issuecomment-7150318419) Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head `0ababf5` applied cleanly onto current `main` `ccfb029`. - `cargo test -p victory-shader --locked`: 144 passed, 0 failed, 2 ignored. All tests pass. The new UAV initialization test is GPU-specific (requires dxil.dll/WARP) and is skipped on Linux. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 4 pre-existing errors in test code (fail identically on main `ccfb029`). The PR introduces no new clippy warnings. Not tested: Windows MSVC build, the title itself. AI-assisted.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:16 UTC · original

Automated triage for the maintainers.

Needs work.

  • Premise: in Host::dispatch (crates/victory-shader/src/emit/host.rs) the root UAV buffers come from CreateCommittedResource with D3D12_HEAP_FLAG_NONE, and D3D12 zeroes committed resources unless D3D12_HEAP_FLAG_CREATE_NOT_ZEROED is passed. So on main these buffers already start at zero, which the Root::Uav doc comment says too. The extra zero copy does no harm, but the PR doesn't show a case where the buffers held anything else, and the body says itself that the link to #1882 is unconfirmed.
  • The new test dirty_page_bitmap_is_zeroed_before_dispatch writes a seed with the new Root::SeededUav and then checks that the host's own zero copy overwrote it. That only tests the test host against itself. It can't catch a real regression in shader lowering.
  • title_memory_is_read_and_written_at_computed_addresses now uses hard-coded [1360, 5200, 5201] in place of values derived from far and TITLE. They're numerically the same, but the derivation was the documentation. The test also leaves an eprintln! behind.
  • CI: check fails in synthetic_tests (gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out). This PR doesn't touch those tests, so the failure doesn't look like it comes from this change.

What would change the verdict: a run on main where a root UAV starts non-zero (for example the #1882 failure reproduced, then gone with this change). Without that evidence, consider dropping the seeded test and keeping the derived expected values.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/1912#issuecomment-7156822063) <!-- victory-triage v1 head=0ababf50f7525fdf1540107c794157fea812822a verdict=needs-work at=2026-11-25T08:16:12Z --> Automated triage for the maintainers. **Needs work.** - Premise: in `Host::dispatch` (`crates/victory-shader/src/emit/host.rs`) the root UAV buffers come from `CreateCommittedResource` with `D3D12_HEAP_FLAG_NONE`, and D3D12 zeroes committed resources unless `D3D12_HEAP_FLAG_CREATE_NOT_ZEROED` is passed. So on `main` these buffers already start at zero, which the `Root::Uav` doc comment says too. The extra zero copy does no harm, but the PR doesn't show a case where the buffers held anything else, and the body says itself that the link to #1882 is unconfirmed. - The new test `dirty_page_bitmap_is_zeroed_before_dispatch` writes a seed with the new `Root::SeededUav` and then checks that the host's own zero copy overwrote it. That only tests the test host against itself. It can't catch a real regression in shader lowering. - `title_memory_is_read_and_written_at_computed_addresses` now uses hard-coded `[1360, 5200, 5201]` in place of values derived from `far` and `TITLE`. They're numerically the same, but the derivation was the documentation. The test also leaves an `eprintln!` behind. - CI: `check` fails in `synthetic_tests` (`gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`). This PR doesn't touch those tests, so the failure doesn't look like it comes from this change. What would change the verdict: a run on `main` where a root UAV starts non-zero (for example the #1882 failure reproduced, then gone with this change). Without that evidence, consider dropping the seeded test and keeping the derived expected values. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Damokles2 on GitHub · 2026-11-25 09:28 UTC · original

Thanks for the detailed review. After reassessing the D3D12 allocation behavior and the regression test, I agree that the current patch does not establish a real initialization defect.

The seeded test demonstrates that the additional zero copy works, but it does not reproduce the original intermittent failure in #1882 or show that ordinary Root::Uav allocations contain stale data.

I'll close this PR in its current form and leave #1882 open for further investigation with a reproducible failure.

Thanks to everyone who reviewed and tested the change.

AI-assisted using OpenAI Codex.

**@⁠Damokles2** on GitHub · 2026-11-25 09:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1912#issuecomment-7158375154) Thanks for the detailed review. After reassessing the D3D12 allocation behavior and the regression test, I agree that the current patch does not establish a real initialization defect. The seeded test demonstrates that the additional zero copy works, but it does not reproduce the original intermittent failure in #1882 or show that ordinary Root::Uav allocations contain stale data. I'll close this PR in its current form and leave #1882 open for further investigation with a reproducible failure. Thanks to everyone who reviewed and tested the change. AI-assisted using OpenAI Codex.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1912
No description provided.