Skip to content

runtime: bind indexed atomic UAVs in the direct compute runtime path - #3417

Merged
JohnConnorNPC merged 3 commits into
R0Y00:mainfrom
Ammmae0x:runtime/compute-indexed-atomic-uav
Nov 29, 2026
Merged

JohnConnorNPC merged 3 commits into
R0Y00:mainfrom
Ammmae0x:runtime/compute-indexed-atomic-uav

Conversation

@Ammmae0x

@Ammmae0x Ammmae0x commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Refs #3224, #2935

ComputeViewKind::indexed_atomic_uav previously had no runtime manifest, so compile_dxil reported compiled, no runtime manifest: UAV kind indexed_atomic_uav and the dispatch path never bound it. This change publishes and binds it in the direct compute runtime path.

  • src/direct_compute_cache.cpp: format_compute_runtime_manifest publishes a single 4-byte view as uav <register> atomic table <parameter> <byte>. Any other shape (descriptor array, required_bytes != 4) stays refused by name as UAV kind indexed_atomic_uav.
  • src/startup_stubs/d3d12_compute_dispatch.inl: parses the atomic line and builds a root signature with one extra 32-bit-constants parameter per indexed atomic UAV, after the view table and in UAV order, with ShaderRegister = uav register + 1 and two values, matching NativeComputePipeline. The in-process native translation classifies the binding as an output the same way.
  • Binding is token-only: the output must be a slot-19 token view. The shared native_buffer_store_view check derives {stride, count} from that view (structured stride multiple of 4 and at most 2048, raw R32_TYPELESS, typed R32_UINT/R32_SINT) and rewrites it to the raw R32_TYPELESS view the atomic operates on; failures refuse as an indexed atomic output view has an unsupported stride or range. A hardware-descriptor atomic refuses as an indexed atomic output needs a slot-19 token view.
  • src/startup_stubs/translated_sampler_bindings.h: create_translated_root takes the atomic UAV registers (defaulted, other callers unchanged); the sampler-heap table follows the atomic parameters.
  • Tests: tests/startup_compute_indexed_atomic_uav_check.py (_controls, _warp, _hardware, SKIP_RETURN_CODE 77) publishes the synthetic program through compile_dxil, dispatches it through the stand-in list (raw, structured stride-8 and typed R32_UINT token views, each with its own addressed dwords), checks four token shapes and a hardware descriptor that must each refuse with their own reason and leave the output untouched, and checks the native in-process translation of the same program. tests/native_compute_manifest_reasons.cpp gains the accept case and the array/required_bytes refusals. Contract documented in docs/experiments/compute-indexed-atomic-uav.md.

WIN-VERIFY round 1 (9895ec1c): native_compute_manifest_reasons, native_compute_manifest_reasons_requests and startup_compute_indexed_atomic_uav_controls passed; _warp skipped (77); _hardware failed after the raw bound run passed, with device removed (DXGI_ERROR_DEVICE_HUNG) in slot 19. Three negative-control UAV descs were invalid for D3D12 CreateUnorderedAccessView on the 1280-byte buffer (a 4096-byte structured stride, a RAW-flagged R32_UINT view, a 1284-byte view), so the device was removed before the dispatch could refuse them; and the --shader-wave32 gate in main() exited 77 on WARP, skipping the published runs even though only the native translator needs 32-lane waves.

Fix in this head (fa269a85): every negative view is now creatable in D3D12 on its buffer — the 4096-stride view runs on the 16 MiB + 64 KiB committed buffer (dispatch-uav-token-large), the unaligned view uses WORDS - 1 elements, and the two uncreatable shapes (RAW with a non-R32_TYPELESS format, a view past the end of its buffer) stay out. controls() now checks every negative view fits its buffer and that the two uncreatable shapes fail that check. main() no longer probes --shader-wave32; native_check() probes it directly so a skip there does not discard the published results.

Linux verification (this host has no Windows toolchain, so the GPU tests are pending below):

  • python -B tests/startup_compute_indexed_atomic_uav_check.py: controls pass (program encoding, table loads, idxen atomic, per-shape expectations, token views, creatable negative views).
  • python -B tests/form_coverage_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py: pass.
  • py_compile on the touched Python file: pass.
  • 6 spot-mutations on temporary copies in /tmp (cleared idxen, raw stride 1 to 4, structured stride 8 to 16, mutated refusal reason, dropped glc from the expected decode, reintroduced the 1284-byte unaligned view): each fails the controls, unmutated base passes.
  • All four refusal reasons in the new test appear verbatim in d3d12_compute_dispatch.inl.

Windows Verification (10d7d41)

Commit: 10d7d41b77d4278d53297b792098ad02811b9988 (Windows 11 build 26100.26100)
Adapter: NVIDIA GeForce RTX 4050 Laptop GPU (10de:28e1), driver 32.0.15.9186 (D3D12 debug layer unavailable); inbox WARP 10.0.26100.7309 (4..4 lanes)
dev:
  cmake --build --preset dev --target compile_dxil startup_stream_consumer offscreen_check native_compute_manifest_reasons
  $env:XBOX2WINDOWS_ADAPTER='NVIDIA'; ctest --preset dev --no-tests=error -R '^(startup_compute_indexed_atomic_uav_|native_compute_manifest_reasons)' --output-on-failure
  -> 4/5 passed, 0 failed, 1 skipped (24.77s; _hardware passed on RTX 4050; _warp skipped 77 on 4-lane inbox WARP)
release:
  cmake --build --preset release --target compile_dxil startup_stream_consumer offscreen_check native_compute_manifest_reasons
  $env:XBOX2WINDOWS_ADAPTER='NVIDIA'; ctest --preset release --no-tests=error -R '^(startup_compute_indexed_atomic_uav_|native_compute_manifest_reasons)' -E "cpu_native_archive_" --output-on-failure
  -> 4/5 passed, 0 failed, 1 skipped (22.08s; _hardware passed on RTX 4050; _warp skipped 77 on 4-lane inbox WARP)
Repo checks: form_coverage_check, docs_links_check, bidi_controls_check -> 3/3 passed
AI-assisted.

Publish ComputeViewKind::indexed_atomic_uav in format_compute_runtime_manifest
as 'uav <register> atomic table <parameter> <byte>' for a single 4-byte view,
and bind it in the startup dispatch path from a slot-19 token view, with the
view's {stride, count} as root constants at b(register + 1), matching
NativeComputePipeline. Hardware-descriptor atomics and unsupported token
shapes stay refused by name. Refs R0Y00#3224, R0Y00#2935
…ithout wave32

WIN-VERIFY round 1: on hardware, three negative-control UAV descs were
invalid for D3D12 CreateUnorderedAccessView on the 1280-byte buffer (a
4096-byte structured stride, a RAW-flagged R32_UINT view, a 1284-byte view),
so slot 19 removed the device before the dispatch could refuse them. Keep
every negative view creatable: the 4096-stride view now runs on the 16 MiB +
64 KiB committed buffer, the unaligned view uses WORDS - 1 elements, and
the two uncreatable shapes stay out (a RAW view needs R32_TYPELESS; a view
past the end of its buffer cannot be created). controls() now checks every
negative view fits its buffer and that the two uncreatable shapes fail that
check. On WARP, the --shader-wave32 gate exited 77, skipping the published
raw/structured/typed runs even though only the native translator needs
32-lane waves: main() no longer probes wave32, and native_check() probes
it directly so a skip there does not discard the published results.

Refs R0Y00#3224, R0Y00#2935
@Ammmae0x
Ammmae0x marked this pull request as ready for review November 29, 2026 00:53

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 10d7d41b by reading the diff against main 212d4b5f. No local build or run. git merge-tree against main is clean.

Formatter (src/direct_compute_cache.cpp:990-996): indexed_atomic_uav is published only with array_count == 1 and required_bytes == 4, which is the width the translator always records for the binding (src/gfx1013_direct_compute.inl:456-457). Other shapes fall through to view_shape, so an array refuses as UAV kind indexed_atomic_uav array (:911), as the new case expects.

Runtime (src/startup_stubs/d3d12_compute_dispatch.inl):

  • The root signature matches what the program reads. The translator reads b0 (gfx1013_direct_compute.inl:323) and, per indexed atomic, {stride, count} from b(register + 1) (:460-468); it creates no other CBV handle. create_translated_root adds one 2-value constants parameter per atomic UAV at ShaderRegister = register + 1 after the view table (translated_sampler_bindings.h:146-152), the same as NativeComputePipeline (src/native_compute_pipeline.cpp:92-97). The register is the UAV index, which equals the manifest register because each uav line must have i == tr.uavs.size() (:229-230); the in-process path has the same check on shader_register.
  • Sizes: at most 8 UAVs (:275, :378), so at most 2 + 8 + 1 = 11 parameters (parameters[11]) and a root cost of at most 32 + 1 + 16 + 1 = 50 DWORDs.
  • Binding (:864-871, :889-901): the token view goes through native_buffer_store_view from main (src/native_buffer_store_view.h:17-54, unchanged here). That accepts raw R32_TYPELESS, structured with a stride that is a multiple of 4 and at most 2048, or typed R32_UINT/R32_SINT, rejects counters, a range outside the resource and a start that is not 16-byte aligned, then rewrites the view to raw R32_TYPELESS. A hardware descriptor refuses before the hardware path (:898-901). The constants are set in UAV order with atomic_parameter++ (:1069-1074), the same order create_compute_pipeline built (:117-119).
  • The op set (add/sub/and/or/xor/smin/smax/umin/umax/swap/cmpswap) is what buffer_atomic already lowers on main (gfx1013_direct_compute.inl:443-452). This PR only adds the binding.

Tests: no test, tool or doc on main expects UAV kind indexed_atomic_uav from compile_dxil. Reading the tests against the code:

  • native_compute_manifest_reasons: dropping the array_count or required_bytes condition fails a new case. Dropping the clause fails the accept block.
  • startup_compute_indexed_atomic_uav_*: the three positive shapes write different dwords (raw 0..31, stride 8 0,8,..,248, typed 0,4,..,124), so a wrong stride constant or a wrong rewrite fails. Dropping the slot-19 refusal fails dispatch-records32. Wrong parameter indices or a wrong ShaderRegister fail the positive runs.

Not covered:

  • count is never the deciding bound: the largest index is 124 and the smallest count is 160. Setting atomic_count to ~0u at :894 passes every test. A smaller NumElements alone may not catch it either, since the rewritten raw view has the same extent. Suggestion: an index that wraps under the multiply, which is what the count test guards (gfx1013_direct_compute.inl:461), for example stride 8 with index 0x20000000 + lane, expecting an untouched output.
  • Only u0 is atomic, with no other UAV, so push_back(i) -> push_back(0) at :119 survives. Suggestion: a mixed layout, for example u0 raw and u1 atomic, which reads b2.
  • The 4096-stride negative runs on dispatch-uav-token-large, which views a committed buffer while the readback is of the placed output buffer, so its "untouched output" check does not read the buffer it views. The refusal text still pins that case.
  • CI does not run these tests. PR CI uses the pr presets, whose build targets include neither compile_dxil nor startup_stream_consumer and whose filter matches none of the new tests. The new controls are not in tests/checks/python-linux. The evidence is the log in the description, where _warp skips with 77 and only _hardware dispatches.
  • Wording: the comments at :587 and :1067 say "parameter 2 + its UAV index". The code uses 2 + the rank among atomic UAVs, which is correct. The description still says main() no longer probes --shader-wave32; at this head it does (test :256), and the re-probe in native_check cannot skip.

Overlap: #3398 rewrites the same classification block in translate_compute_natively and conflicts here; whichever lands second adds atomic to output and to supported. The tests/native_compute_manifest_reasons.cpp changes merge cleanly with #3427 and #3398.

Approve 10d7d41b.

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 10d7d41b7740bb176e1cf6c5360cf6e3c9c92a2f:

Running the PR's tests on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) failed in both Debug and Release:

  • ctest --preset dev -R '^(startup_compute_indexed_atomic_uav_|native_compute_manifest_reasons$)' --parallel 3 --no-tests=error --output-on-failure: 1/4 passed, 3 failed (native_compute_manifest_reasons passed; startup_compute_indexed_atomic_uav_controls, startup_compute_indexed_atomic_uav_warp, and startup_compute_indexed_atomic_uav_hardware all failed in compile_dxil with no_manifest input=req_f05f4f5cbdd73cc3.c67 unsupported startup runtime manifest bindings: UAV kind indexed_atomic_uav).
  • ctest --preset release -R '^(startup_compute_indexed_atomic_uav_|native_compute_manifest_reasons$)' --parallel 3 --no-tests=error --output-on-failure: 1/4 passed, 3 failed (same failure).

AI-assisted; commands listed were executed locally.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-checked head 10d7d41b against the report above, by reading only; nothing built or run. Our approval stays until the cause is known.

  • compile_dxil has no kind list of its own: it prefixes the reason returned by format_compute_runtime_manifest (tools/startup/compile_dxil.cpp:328-329, :1561).
  • The reported text is what the formatter at the base 0614f68c emits for this binding. Without the branch this PR adds, a one-element indexed_atomic_uav reaches refuse(view_shape("UAV", b)), which gives exactly UAV kind indexed_atomic_uav.
  • At this head, src/direct_compute_cache.cpp:990-996 publishes that kind when array_count == 1 && required_bytes == 4. With one element, the same text can then only come from required_bytes != 4. The translator creates this kind in one place, with 4 bytes (src/gfx1013_direct_compute.inl:456-457).
  • native_compute_manifest_reasons links the same x2w_shader_compiler library as compile_dxil (CMakeLists.txt:31-32, tests/cmake/native_compute_manifest_reasons.cmake:5-6). Its new block (tests/native_compute_manifest_reasons.cpp:128-143) requires uav 0 atomic table 1 32 for exactly that shape, and the report shows it passing.

So either the translated binding is not 4 bytes, or the compile_dxil that ran was not built from this head. Two things would settle it:

  • the u0 root=... bytes=... min_size=... line compile_dxil prints for the request the failing test publishes (tools/startup/compile_dxil.cpp:137-138; the failing assert in publish() includes its stdout);
  • whether compile_dxil was rebuilt at 10d7d41b. The full SHA quoted in the report (10d7d41b7740...) is not this head's (10d7d41b77d4...).

Separately, the PR now conflicts with main (41babe6e), in src/startup_stubs/d3d12_compute_dispatch.inl only. At the in-process slot setup, #3409 added slots.back().requires_identity_dst_sel = view.requires_identity_dst_sel; where this PR adds if (atomic) slots.back().atomic = true;. The two lines set different fields; keeping both resolves it.

CI does not run these 4 tests: PR CI uses the pr test preset, whose filter has neither startup_compute_indexed_atomic_uav_* nor native_compute_manifest_reasons.

@Leyukaka

Copy link
Copy Markdown
Collaborator

Taking this over since there has been no activity for 2 h; will hand back if you resume.

Plan: merge main (77d1ba4d) into 10d7d41b with your commits unchanged. The only conflict is in src/startup_stubs/d3d12_compute_dispatch.inl, at the slot setup; both lines are kept: main's slots.back().requires_identity_dst_sel = view.requires_identity_dst_sel; and your if (atomic) slots.back().atomic = true;.
Then run ctest -R '^(startup_compute_indexed_atomic_uav_|native_compute_manifest_reasons$)' in a fresh isolated build and post the result here, in a PR that credits you.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of 10d7d41b against main 77d1ba4d. Verdict: hold. Leyukaka has taken over the merge of main, so this only adds what affects the default launcher path.

MUST

  1. It conflicts with main in src/startup_stubs/d3d12_compute_dispatch.inl (git merge-tree --write-tree --name-only origin/main 10d7d41b → CONFLICT (content)). Leyukaka's plan above covers the resolution.
  2. There is no passing WARP run at any head, and the one Windows Server 2025 run is red and unexplained (tedin7's review: 1/4 passed, 3 failed). This matters more than usual because of where the change lands. The in-process half of the PR, translate_compute_natively (const bool atomic = view.kind == x2w::ComputeViewKind::indexed_atomic_uav;), runs on the default launcher path: since runtime: default to native shaders and Opus decoding #3449, X2W_NATIVE_SHADERS_ONLY=1 unless -Translate. There, programs with an indexed atomic now dispatch instead of being refused.
    • The test exercises that path only in native_check(), and main() calls it after the three compile_dxil shapes. So on the failing run the native dispatch never ran.
    • The only run that reached it is the author's RTX 4050. The 4-lane inbox WARP skipped with 77.
    • After the merge, please post the native: line of the _warp/_hardware output separately, along with the u0 root=... bytes=... line Leyukaka asked for.

SHOULD

  1. CI doesn't select any of the four tests. A re.search of the pr test-preset filter at this head against startup_compute_indexed_atomic_uav_controls, _warp and native_compute_manifest_reasons → False for all three. The _controls leg needs only compile_dxil and DXC, so adding it to the preset (and compile_dxil to the pr build targets) would give the PR a CI signal.

What I tried: I cross-built compile_dxil from this head (clang-cl 19) and ran the compile mode under Wine. It stops earlier, at native compute +0x0: invalid root layout, because Wine's D3D12 root-signature deserializer returns E_INVALIDARG for the test's root blob. So I couldn't reproduce or rule out the Server 2025 result here, and I'm not counting this as evidence either way.

AI-assisted.

@Leyukaka

Copy link
Copy Markdown
Collaborator

The merge of main is in #3454: your three commits (9895ec1c, fa269a85, 10d7d41b) unchanged, plus two merge commits of main (e1143678 for 77d1ba4d, 393b80eb for af1cab5c). Head is 393b80eb. Both conflict resolutions, the run result and the native: line are in its description.

You can take it back at any time: say so here and #3454 gets closed.

@JohnConnorNPC
JohnConnorNPC merged commit e114367 into R0Y00:main Nov 29, 2026
5 checks passed
JohnConnorNPC added a commit that referenced this pull request Nov 29, 2026
compute: indexed atomic UAV dispatch (takeover of #3417)
@Ammmae0x

Copy link
Copy Markdown
Contributor Author

Thanks @Leyukaka for merging #3417 forward cleanly as #3454 (c3385469) and @JohnConnorNPC for reviewing! Closing #3417 since its commits (9895ec1c, fa269a85, 10d7d41b) have landed in main via #3454.

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.

4 participants