Skip to content

startup: name the causes of a refused placed build and accept PERFORM_UPDATE with a source structure - #1943

Open
tedin7 wants to merge 11 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-placed-update
Open

tedin7 wants to merge 11 commits into
R0Y00:mainfrom
tedin7:x2w-frontier-placed-update

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1758 (and #870); no Fixes.

What this unblocks: a refused placed acceleration-structure build now says why (six causes were one opaque E_INVALIDARG), and a placed PERFORM_UPDATE with a source structure is accepted through the same placement lookup as the build.

Source: DirectX-Specs, Raytracing, "Acceleration structure update" (PERFORM_UPDATE, ALLOW_UPDATE, SourceAccelerationStructureData, UpdateScratchDataSizeInBytes from GetRaytracingAccelerationStructurePrebuildInfo); Direct3D 12 documentation, D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS; and the earlier placed-build code of this repository (placed_build.h).

resolve_placed_build collapsed six different refusals into one opaque E_INVALIDARG and refused every update build. This names the causes and accepts PERFORM_UPDATE with a source structure. d3d12_memory_srv.inl and placed_buffer_range are untouched.

Reply to the 2026-11-24 review

The requested update path is covered by check_placed_update (tests/dxr_check.cpp:512), called at the end of check_dxr_placed_build (tests/dxr_check.cpp:581), so it runs in dxr_placed_build_warp and dxr_placed_build_hardware.

  • Source built with ALLOW_UPDATE: the fixture builds the BLAS and TLAS with ALLOW_UPDATE (tests/dxr_check.cpp:231) through the placed resolver.
  • Update through the placed path: placedScene->resolve_update re-resolves the BLAS and the TLAS as in-place PERFORM_UPDATE builds (tests/dxr_check.cpp:384-386, tests/dxr_placed_build.h:246) and the translated builds are recorded after UAV barriers (:387-390).
  • Changed ray result: the instances move and the geometry changes, rays are traced and read back after a UAV barrier, a queue signal and a fence wait (submit_and_wait, tests/desktop_gpu.cpp:81-91). The test requires the result to differ from the pre-update result (tests/dxr_check.cpp:532), to carry the expected hit instance IDs per ray (:534-538), and to equal both the same update on desktop addresses and a fresh placed build of the updated scene (:530-531).
  • Refusal controls stay: every resolver refusal is asserted by cause in the same test (tests/dxr_placed_build.h), including an update whose source was built without ALLOW_UPDATE (source_not_updatable) and one never built (source_not_built).
  • Precondition: documented in docs/experiments.md and now enforced by the resolver (it records ALLOW_UPDATE per build and refuses an update without it).

Changes

  • src/startup_stubs/placed_build.h: a standard-C++-only part with PlacedBuildCause (ok, unaligned, not_placed, wrong_state, range, update_without_source, source_without_update, source_unaligned, source_not_placed, source_wrong_state, source_range, source_dest_partial_overlap, source_not_built, source_not_updatable), cause_name, ranges_overlap, check_update_shape, gpu_range_cause and PlacedBuildLedger. The Windows declarations stay below, under _WIN32.
  • resolve_placed_build returns the same E_INVALIDARG and still publishes nothing on a refusal, and now logs x2w-dxr placed build refused: <cause> (<dest|scratch|source> at title 0x...) once per cause.
  • With PERFORM_UPDATE, the source goes through the same placement lookup as the destination, unchanged (a live placed buffer in the acceleration-structure state, 256-byte aligned). The scratch is sized by UpdateScratchDataSizeInBytes. The update may run in place (source == destination) or write another structure; a source that partly overlaps the destination is refused. Nothing is published unless all three addresses resolve. The resolver records the ALLOW_UPDATE flag of every build it publishes (keyed by the structure's title address; a later build over the same memory replaces the record) and refuses an update whose source was recorded without it (source_not_updatable) or never seen built (source_not_built). resolve_placed_build reports its cause through an optional out parameter.
  • tests/placed_build_causes_check.cpp (registered as placed_build_causes): the device-free rules, including both aliasing outcomes and the boundaries. tests/dxr_placed_build.h (used by dxr_placed_build_{hardware,warp}): six refused updates (no source, source without the flag, unaligned, unmapped, wrong state, partial overlap), an in-place update and an out-of-place one with its interior offset kept.
  • Notes in docs/experiments.md.

Verified (Linux)

Verification (Windows Server 2025, D3D12 WARP, head 5a79add, after merging current main)

  • Debug: cmake --build --preset dev --target placed_build_causes_check offscreen_check -- -j 2, then ctest --preset dev -R '^(placed_build_causes|dxr_placed_build_|dxr_slot70_as_|dxr_update)' --no-tests=error --output-on-failure: 9/9 passed (placed_build_causes, dxr_placed_build_{warp,hardware}, dxr_slot70_as_{warp,hardware}, dxr_update_{warp,hardware}, dxr_update_pipeline_{warp,hardware}).
  • Release /O2: the same build and ctest commands with --preset release: 9/9 passed, same nine tests.
  • Linux: g++ -std=c++17 -O2 -Wall -Wextra -fsanitize=address,undefined tests/placed_build_causes_check.cpp passes; eight mutations of placed_build.h (allow-update ignored, unknown source accepted, overlap record not dropped, flag forced on, three variants of the address rule, a missing name) each fail the check.
  • The device tests require the named cause for every refusal a device can trigger (destination and scratch not placed, unaligned, wrong state; no source, source without the flag, unaligned, not placed, wrong state, one stride past the destination, never built, built without ALLOW_UPDATE). range and source_range cannot be triggered on a real device (buffers are placed 64 KB aligned), so the address rule is checked by value in placed_build_causes.

Not verified

  • An out-of-place update is resolved but not dispatched. The in-place PERFORM_UPDATE of the placed BLAS and TLAS (built with ALLOW_UPDATE) is recorded and read back in dxr_placed_build_{hardware,warp}.
  • The ledger records builds that go through this resolver; a structure built another way has no record and an update from it is refused.

AI-assisted; commands listed were executed locally.


Replaces closed draft #1799 (rebased cleanly on origin/main and verified on Win2025: 3/3 Debug + 3/3 Release).
AI-assisted; commands listed were executed locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-26T11:49:41.635633Z
We couldn’t complete this review. Comment @codex review to try again.
5a79add Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refusal diagnostics can land independently. The new accepted PERFORM_UPDATE cases currently stop at resolve_placed_build. Before accepting production updates, please build the source with ALLOW_UPDATE, record and submit at least one update through the placed path, then read back a changed ray result with the normal barriers and fence. Keep the existing resolver refusal controls. Also document the caller precondition for an update-capable source, or reject an initial build without it if the shim can track that provenance. D3D12 build flags

…LOW_UPDATE precondition

Part of R0Y00#870, R0Y00#1758. Build the placed BLAS and TLAS with ALLOW_UPDATE, record the in-place update of both through resolve_placed_build, and read back four rays: the hit IDs change and equal the direct-address update and a fresh placed build.
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Part of #870, #1758. Addressed the review in 8e402dc and 1c5de00 (head 1c5de00).

  • dxr_placed_build_{hardware,warp} now builds the placed BLAS and TLAS with ALLOW_UPDATE, records an in-place PERFORM_UPDATE of both through resolve_placed_build (source = the title address of the initial build), and reads back four rays after the normal UAV barriers and fence. The hit instance IDs change from 7, 11, 0, 0 to 0, 0, 7, 11, and the rows equal the same update on desktop addresses and a fresh placed build of the updated scene. The resolver refusal controls are unchanged.
  • Found by the new test: WARP reports UpdateScratchDataSizeInBytes = 0, and the resolver refused that as an unplaced scratch. A null scratch is now accepted when no update scratch is needed, and a scratch that is passed anyway must still be a placed buffer. Covered by new controls in the fixture.
  • docs/experiments.md now states the caller precondition: the shim does not track provenance, so a source structure must have been built with ALLOW_UPDATE.
  • Out-of-place updates are resolved but not dispatched.

Verification (Win2025 node, x2w_pipe.py win2025 1943 --regex '^(placed_build_causes|dxr_)' at 1c5de00): placed_build_causes, dxr_placed_build_warp, dxr_placed_build_hardware and the other dxr_* WARP tests pass (20/21). dxr_opacity_hardware fails (candidate handling vs CPU reference). That test does not use the placed path, and I did not run it on main to confirm it was already failing.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 requested a review from R0Y00 November 25, 2026 11:18
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

@tedin7 tedin7 closed this Nov 25, 2026
@tedin7 tedin7 reopened this Nov 26, 2026
@tedin7
tedin7 marked this pull request as draft November 26, 2026 10:37
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Reopened and brought to date: main is merged into the branch (merge commit, no force push, head 047f6f0c). One conflict, in tests/dxr_placed_build.h, where main added the slot-70 acceleration-structure view publishing and this branch the update checks; both are kept.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 047f6f0cc35aca3f34df5dff87d253053e7bf5a0:

  • Debug (--preset dev): cmake --build --preset dev --target placed_build_causes_check offscreen_check -- -j 2, then ctest --preset dev -R '^(placed_build_causes|dxr_placed_build_|dxr_slot70_as_)' --no-tests=error --output-on-failure: 5/5 passed (placed_build_causes, dxr_placed_build_warp, dxr_placed_build_hardware, dxr_slot70_as_warp, dxr_slot70_as_hardware).
  • Release /O2 (--preset release): the same build and ctest commands: 5/5 passed, same five tests.
  • Linux: g++ -std=c++17 -Wall -Wextra tests/placed_build_causes_check.cpp passes; git diff --check is clean.

The earlier review round (build the source with ALLOW_UPDATE, record and read back an update, document the caller precondition) was already addressed on this branch before the merge. The PR body now has the Source: line and the verification above. An independent Stage-2 review is requested; this stays a Draft until it passes.

AI-assisted; commands listed were executed locally.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

The three gate findings are fixed (head 5a79addf, main merged, no force push).

  1. ALLOW_UPDATE provenance: the resolver records the flag of every build it publishes and refuses an update whose source was built without it (source_not_updatable) or that it never saw built (source_not_built; unknown provenance is refused). A refused call records nothing; a later build over the same memory replaces the record, and an update's destination is recorded with the update's flags.
  2. Named causes at device level: resolve_placed_build reports its cause through an optional out parameter, and every refusal in dxr_placed_build_{warp,hardware} now requires the exact cause, not only E_INVALIDARG.
  3. A triggering control for each cause a device can reach: destination and scratch (not placed, unaligned, wrong state), and for an update no source, a source without the flag, an unaligned, not placed or wrong-state source, a source one stride past the destination (partial overlap on a device that sizes the structure over 256 bytes), a source never built, and a source built without ALLOW_UPDATE. range and source_range cannot be triggered on a real device (buffers are placed 64 KB aligned), so the translated-address rule is checked by value in placed_build_causes, with the ledger rules; eight mutations of placed_build.h each fail that check.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 5a79addf711b8934ee45a77906fd4be1be98f8ad:

  • Debug (--preset dev): cmake --build --preset dev --target placed_build_causes_check offscreen_check -- -j 2, then ctest --preset dev -R '^(placed_build_causes|dxr_placed_build_|dxr_slot70_as_|dxr_update)' --no-tests=error --output-on-failure: 9/9 passed (placed_build_causes, dxr_placed_build_{warp,hardware}, dxr_slot70_as_{warp,hardware}, dxr_update_{warp,hardware}, dxr_update_pipeline_{warp,hardware}).
  • Release /O2 (--preset release): the same build and ctest commands: 9/9 passed, same nine tests.
  • Linux: the device-free check passes under address and undefined-behaviour sanitizers; git diff --check and the docs link check are clean.

Stage-2 re-gate requested. This stays a Draft until it passes.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 26, 2026 11:49
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Independent re-review of head 5a79add: PASS.

Verification (Windows Server 2025, D3D12 WARP, build and tests on the PR head, run through the repository's Win2025 pipeline on its own host):

  • ctest -R '^(placed_build_causes|dxr_placed_build_|dxr_slot70_as_|dxr_update)': dev 9/9 and release 9/9 (placed_build_causes, dxr_placed_build_warp, dxr_placed_build_hardware, dxr_slot70_as_warp, dxr_slot70_as_hardware, dxr_update_warp, dxr_update_hardware, dxr_update_pipeline_warp, dxr_update_pipeline_hardware).
  • Extra control, run on top of the head: the TLAS rebuilt without ALLOW_UPDATE is refused as source_not_updatable for an in-place update, and the same update is accepted after the TLAS is rebuilt with ALLOW_UPDATE (dxr_placed_build_warp 1/1).
  • Linux: g++ -std=c++17 -O2 -Wall -Wextra -fsanitize=address,undefined tests/placed_build_causes_check.cpp: no warnings, passes; git diff --check origin/main...HEAD clean.
  • Each refusal control now asserts the named cause, not only E_INVALIDARG. range / source_range are checked by value through gpu_range_cause only, because a real device places buffers 64 KB aligned (stated in the header).

AI-assisted; commands listed were executed locally.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@MasterDomino #1943 is tested and Ready as well (Win2025 dev 9/9 + release 9/9 at 5a79add).

R0Y00's change request is covered: check_placed_update (tests/dxr_check.cpp:512, run from dxr_placed_build_warp and _hardware) builds with ALLOW_UPDATE, submits a placed PERFORM_UPDATE of the BLAS and TLAS through the resolver, and reads back a changed ray result with UAV barriers and a fence, compared with a direct update and a fresh build. The resolver refusal controls are kept, and an update of a source built without ALLOW_UPDATE is now refused as source_not_updatable. Details are in the PR body.

Full merge order from our side: #1408, #1251, #1939, #1940, #1943, #2782, #2794, #2766.

tedin7 pushed a commit to tedin7/Xbox2Windows that referenced this pull request Nov 26, 2026
tedin7 pushed a commit to tedin7/Xbox2Windows that referenced this pull request Nov 26, 2026
@SimSalabimse

Copy link
Copy Markdown
Contributor

Hardware result for head 5a79addf711b8934ee45a77906fd4be1be98f8ad: two NVIDIA tests fail on a check in tests/dxr_placed_build.h. WARP passes. Part of #870.

Environment: Windows 11 25H2 (26200), MSVC 19.42, dev preset, NVIDIA GeForce RTX 4070 Ti, driver 621.35 (32.0.16.2135), D3D12 debug layer enabled (0 errors, 0 warnings in the hardware runs). Tests run serially, one ctest process.

Command

ctest --preset dev --no-tests=error -R "dxr_placed_build|dxr_update|dxr_slot70" --output-on-failure

Result (measured): 6/8 passed.

  • Passed: dxr_placed_build_warp, dxr_slot70_as_warp, dxr_update_warp, dxr_update_pipeline_warp, dxr_update_hardware, dxr_update_pipeline_hardware.
  • Failed (about 0.3 s each): dxr_placed_build_hardware and dxr_slot70_as_hardware. dxr_placed_build_hardware failed on every one of 5 runs with the same message; dxr_slot70_as_hardware failed in the full run above (it uses the same scene).
x2w-dxr placed build refused: not_placed (dest at title 0x1000)
x2w-dxr placed build refused: unaligned (dest at title 0x...210)
DXR build refusal names the wrong cause (not_placed for destination in a buffer that is not an acceleration structure, expected wrong_state)
backend=hardware debug_layer=enabled
driver=32.0.16.2135
debug_errors=0 debug_warnings=0

On main at 7256cecf the same 8 tests pass (8/8, a clean build of that commit on the same machine). That tree does not have this control (must_reject(ts, tlas, Cause::wrong_state, ...), tests/dxr_placed_build.h:109), so this does not show a regression in the resolver, only that the new control does not hold on this adapter.

Where it fails (measured): the failing check passes the TLAS scratch buffer as the destination. I printed the sizes once in a throwaway local copy (not part of the PR):

TLAS ResultDataMaxSizeInBytes bytes left in the scratch buffer from ts
NVIDIA RTX 4070 Ti 2048 768
WARP 168 to 372 212 to 436

On WARP the TLAS result size fits in the scratch buffer. On NVIDIA it does not.

Likely cause (hypothesis, from reading the code): translate() in resolve_placed_build (d3d12_xs_device.cpp, around line 7092) calls placed_buffer_range(address, ResultDataMaxSizeInBytes) before it looks at the buffer's state. placed_buffer_range rejects a range that runs past the end of the buffer (d3d12_capture.inl, around line 330), so the destination is refused as not_placed and the wrong_state test is never reached. The scratch buffer is only 768 + scratch size bytes, which is smaller than the NVIDIA TLAS result. If that is right, the resolver refuses in the order it was written and the fixture's scratch buffer is too small for this adapter's sizes. I did not change or test the resolver itself.

Possible fix (tested only as a local patch): make the TLAS scratch buffer at least as large as the TLAS result, like the earlier change for big_as_:

-const auto ts = place(3, scratch_offset + scratch_bytes(top_size), scratch_state) + scratch_offset;
+const auto ts = place(3, scratch_offset + (std::max)(scratch_bytes(top_size), top_size.ResultDataMaxSizeInBytes), scratch_state) + scratch_offset;

With that one line, the same command gives 8/8 on this machine (hardware and WARP). The other must_reject controls that take a buffer as the destination may need the same care on other adapters.

This is one physical adapter on one driver. An AMD or Intel result would show whether the sizes differ per vendor.

AI-Assisted

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@SimSalabimse thank you for running this on NVIDIA and for the careful write-up. The size table and the place where it fails make the cause clear: the wrong_state control uses the TLAS scratch buffer as the destination, and on your adapter that buffer is smaller than the TLAS result, so the resolver stops earlier with not_placed.

A fix is coming on this PR. It sizes the scratch buffer so the control reaches the state check on every adapter, along the lines you proposed. We will post the new head and the results here. A rerun of the same ctest command on your RTX 4070 Ti after that would be very welcome.

AI-assisted; commands listed were executed locally.

…e sizes

The controls that name a scratch buffer as a destination, use an acceleration-structure buffer as scratch, or read a
256-byte view at the scratch address sized those buffers to the minimum of one device (WARP). A GPU that reports a result
size larger than the scratch size made the range check fail first, so the build named not_placed instead of wrong_state.
The decoy buffers now cover the result size, the scratch size and the view.
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@SimSalabimse the fix is on this PR now: head b09ac9ddb7085b09d704d12a230ef7eca3172087 (test-only change in tests/dxr_placed_build.h, no src/ change).

What changed: the decoy buffers in the fixture (the scratch buffer used as a destination in the wrong_state control, the scratch buffer behind the slot 70 view, and the buffer used as scratch) were sized to one device minimum. They are now sized from the device's own prebuild sizes, so on a GPU whose TLAS result is larger than its scratch the range check no longer fires first and each control reaches the cause it names.

Results on the new head:

  • Windows Server 2025, dev and release presets: dxr_placed_build_warp, dxr_placed_build_hardware, dxr_slot70_as_warp, dxr_slot70_as_hardware: 4/4 passed in each preset.
  • RTX 3090 through vkd3d-proton (Linux): dxr_placed_build_hardware failed on the old head 5a79addf7 with the same "expected wrong_state" message you saw, and passes on b09ac9ddb: 4/4.
  • CI on the new head: green.

Could you rerun the same command on your RTX 4070 Ti when you have a moment?

ctest --preset dev --no-tests=error -R "dxr_placed_build|dxr_update|dxr_slot70" --output-on-failure

AI-assisted; commands listed were executed locally.

@SimSalabimse

Copy link
Copy Markdown
Contributor

Rerun on head b09ac9ddb7085b09d704d12a230ef7eca3172087: all 8 pass on the RTX 4070 Ti, 3 runs out of 3.

Environment: same as before. Windows 11 25H2 (26200), MSVC 19.42, dev preset (incremental build of the earlier tree, fresh out/pe-env), NVIDIA GeForce RTX 4070 Ti, driver 621.35 (32.0.16.2135). Tests run serially.

Command

ctest --preset dev --no-tests=error -R "dxr_placed_build|dxr_update|dxr_slot70" --output-on-failure -j 1

Result (measured): 8/8 passed, ctest exit 0, in each of 3 runs. That includes dxr_placed_build_hardware and dxr_slot70_as_hardware, which failed on 5a79addf with expected wrong_state.

Negative control: the old head 5a79addf failed those two tests on this machine (my earlier comment), so the change in tests/dxr_placed_build.h is what makes them pass here.

AI-Assisted

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@SimSalabimse thank you for the rerun and for the negative control on the old head. 8/8 on the RTX 4070 Ti, 3 runs out of 3, confirms the fixture fix on b09ac9ddb on a second NVIDIA adapter. No further change is planned on this PR; it is waiting for maintainer review.

AI-assisted; commands listed were executed locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants