startup: bind compute outputs named by a buffer UAV view token #2961
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2961
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2961"
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?
@Miffedrandir on GitHub · 2026-11-26 23:39 UTC · original
Miffedrandir:startup/compute-output-view-token→main· +80 −4 · 3 files · 3 commits · openPart of #870
Problem
A translated Dispatch refuses any output whose table entry holds the token of a buffer view the title created (device slot 19). The refusal reads "an output is not an aliased placed buffer range with unordered access". The code calls this out as a shortcut: "view tokens and copied placements are refused, add them with their first user". Inputs already take tokens (slot 18).
To measure it, I split that one refusal reason into its separate conditions locally and ran a 10-minute title run. Counts only:
Change
src/startup_stubs/d3d12_compute_dispatch.inl: an output named by a token is now bound in that view's desktop resource, over the view's own range. Raw, structured and typed views are accepted; a typed view's range is sized by its format, as typed input tokens already are.These are still refused, one reason each:
Outputs named by an address are unchanged.
Tests
startup_compute_dispatchgains four cases. In each, the output descriptor is replaced by the token of a buffer view of the output buffer:dispatch-output-token: a raw view;dispatch-output-token-typed: an R32_UINT view;dispatch-output-token-structured: a structured view with stride 8, 160 elements;dispatch-output-token-typed8: an R16G16B16A16_FLOAT view, 160 elements.The last two were added after review: they describe the same 1280 bytes with 8-byte elements, so they catch an element size taken as 4.
In all four, all 320 output words must match the expected values and nothing may be refused.
Windows 11 26200, MSVC 19.44, release preset, RTX 5070 Laptop and WARP:
ctest: 100% of 27 passed, with
main429f11d5merged in (startup_compute_dispatch_native_warpreports itself skipped).Control: the new cases against
main'sd3d12_compute_dispatch.inlfail on both adapters withdispatch-output-token: 288 words differ, because the output is refused. With the element size fixed at 4 instead,dispatch-output-token-structuredfails on both adapters with 128 words differ.Title run, counts only
10 minutes each, same settings, translated compute dispatches:
No device removal or debug-layer error was logged. The largest remaining token refusals are the entry-value case (18 programs) and one program whose view range fails the size check.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
@thepatrickworld on GitHub · 2026-11-27 00:16 UTC · original
Independent AMD RDNA 4 and WARP result on
ca96748f: neither case this PR adds can tell the element size from a constant 4Not a code change; measurements only.
Environment
10.0.26200.9974, MSVC 19.44.35230 (VCToolsVersion 14.44.35207), Windows SDK 10.0.26100dxc.exe1.9.2602.17,fxc.exe10.0.26100.94571002:7550), driver 32.0.32029.2010 (2026-11-18); WARP (1414:008c), driver 10.0.26100.9818devpreset, worktree atca96748f,git status --porcelain --untracked-files=noempty before the local edits below and after reverting them. The D3D12 debug layer is not installed on this machine (debug layer: unavailable), so nothing below is a validation-layer result.Commands
Observed on the unmodified head
16 of 16 entries pass, ctest exit 0, no skip. Across them 15 lines read
adapter=AMD Radeon RX 9070 XT driver=32.0.32029.2010and 15 readadapter=Microsoft Basic Render Driver driver=10.0.26100.9818. The two entries that carry the new cases (#1272 and #1282):What the two added cases cannot separate
Both describe 320 elements of 4 bytes, i.e. 1280 bytes — the exact size of case A's output buffer. In both, the derivation already yields
element = 4(raw → 4; typedR32_UINT→typed_buffer_format_bytes→ 4), so neither can tell the derivation apart from a hard-coded 4. What they do catch is a wrongful refusal, not a wrong size.Mutation,
src/startup_stubs/d3d12_compute_dispatch.inl:365-366:File sha256
9941c248f60a7602e0a4b9d0294a0b16467eb15ded7294713a522712b5377aebat the head,96dac53607486eb2720cd64153caeb566650c5e7db56c773f9697cba42420b91with the mutation, and9941c248…7aebagain aftergit checkout --.Under that mutation both entries this PR adds still pass, on both adapters, and so does the whole compute family:
Those two only needed their targets. Built and re-run under the same mutation:
100% tests passed out of 2. So every one of the 151 entries passes with the element size fixed at 4 — 149 in one run, the last two once their executables existed.The mutation is not an equivalent program: it also turns some refusals into acceptances, because the range checks downstream use the same
element(with stride 8 and 200 elements over a 1280-byte resource, the head computes 1600 bytes and refuses, the mutation computes 800 and accepts). That is arithmetic on the two expressions, not a run. It is a probe of "is this size derived", not a second implementation.Two descriptions that do separate it
Same 1280 bytes with 8-byte elements, so the expected table is unchanged (the fixture hard-codes case A):
dispatch-output-token-structured:Format UNKNOWN,Flags NONE,StructureByteStride 8,NumElements 160dispatch-output-token-typed8:Format R16G16B16A16_FLOAT,Flags NONE,NumElements 160Head, both adapters:
Same build under the mutation, both adapters:
128 and not 160 because the last 32 words of the expected table are the sentinel itself (
WORDS=320 EXPECTED_NON_SENTINEL=288): with a 640-byte range the writes stop at word 160. 288 of the 320 words can distinguish "written" from "not written", not 320.Base control: this fixture on the old translator
main'sd3d12_compute_dispatch.inlat6ee878d8(still carryingshortcut: view tokens and copied placements are refused), with the consumer and the two modes from this head, same probe, both adapters:The same 288 words as your own control against
main, reached independently. Adispatchbaseline on that build still matches (differ=0), so the probe is sensitive to the change itself and not only to my mutation.What the branch binds
The title's description never becomes a descriptor: for a buffer output,
d3d12_compute_dispatch.inl:479-487always creates a rawR32_TYPELESSUAV overFirstElement = offset / 4,NumElements = bytes / 4. The format and the stride of the title's view therefore only decide the byte range, and both extra modes exercise the same raw binding as the two cases in the PR.Refusal reasons (reading, not measured)
No case in
tests/startup_compute_dispatch_check.pyreaches the token branch with a refused view: all six refusal cases name the output by an address. The five reasons that branch can log (not a buffer UAV of a desktop resource,no element size,range is empty, unaligned or outside its resource,an entry value reads the descriptor,also an input) are therefore untested there. I did not sweep the whole suite for an entry that would.Limits
StructureByteStrideand of a typed format's byte width, not on this run.FirstElementis 0 in every case here, so the alignment check, theresource.Width - offsetterm and the 16 MiB cap are not exercised;ALLOW_UNORDERED_ACCESSis always set; only three descriptions are covered (rawR32_TYPELESS,R32_UINT,R16G16B16A16_FLOAT).If the two extra modes are worth having, I can push them as a patch on top of this branch.
AI-assisted.
@KelboLive on GitHub · 2026-11-27 04:29 UTC · original · reviewed
PR #2961 fills the gap: compute outputs now accept buffer UAV view tokens (slot 19), not just address-based naming.
What works
and typed (typed buffer, element size from typed_buffer_format_bytes). Each correctly rejects mismatched flags.
while the map grows during a title run.
ranges, ranges over 16 MiB or outside the resource, and entry-value outputs.
output words match with zero refusals.
Issues
the title run. Since it is a std::vector, concurrent access from multiple dispatch threads could cause issues.
The AcquireSRWLockShared helps with reader concurrency but vector pushes (from the view creation path, slot 19)
need an exclusive writer. Verify that the slot 19 path uses AcquireSRWLockExclusive when appending.
typed UAVs. Ensure this function covers all formats that compute outputs use; missing formats would fall through
to element=0 and get refused. A comment listing supported formats would help.
rarely use typed formats (they use UNKNOWN). The conversion may be unnecessary for structured views.
Worth keeping but verify it does not mis-convert UINT formats during the typed path.
through a view token would be refused. Consistent with address-based naming but limits applicability.
Recommendations
Overall: clean, correct. Fills a real gap and adds good test coverage.
@R0Y00 on GitHub · 2026-11-27 04:41 UTC · original · reviewed
The independent fixed-stride mutation passes the current raw and R32_UINT cases, so those fixtures cannot distinguish the new element-size calculation from a constant 4. Please bring in the tested 8-byte structured and typed cases from the review, and add a refused token-range case with untouched sentinels. An out-of-bounds range using the 8-byte stride would exercise the validation that the existing address-based controls miss.
@KelboLive on GitHub · 2026-11-27 05:36 UTC · original · reviewed
What works
the same
view_records()lookup, the sharedAcquireSRWLockShared/ReleaseSRWLockSharedpattern, anddesktop_format()-- consistent and safe.R32_TYPELESSwithRAWflag) andtyped (
R32_UINT) buffer views, matching the input side's narrowness.validation in the same harness.
Issues
record_transferred_dispatchrefuses tokens outright for copies;this PR only touches dispatch. The refusal TODO
(
view tokens and copied placements are refused, add them with their first user) should be addressed in a follow-up PR.view_records()read but not theas_wrapper()call. Ifview_records()can grow between the sizecheck and the
as_wrapper()lookup, recompute the index under thelock.
no
Buffer.Flags).Recommendations
as_wrapper()to avoid aracy lookup as view_records grows.
Overall
Solid change that aligns output binding with input handling already in
the codebase. Approvable with the lock scope adjustment noted above.
@tedin7 on GitHub · 2026-11-27 09:36 UTC · original
This PR now conflicts with
main. Conflicting files:src/startup_stubs/d3d12_compute_dispatch.inltests/startup_compute_dispatch_check.pytests/startup_stream_consumer.cppCould you merge
maininto your branch (a merge commit, no force push needed) and resolve these? Thank you.AI-assisted; commands listed were executed locally. (
git merge-tree origin/main <head>)ca96748fddtoee2ab75f93ee2ab75f93to383ffaeb0a@Miffedrandir on GitHub · 2026-11-27 18:37 UTC · original
@tedin7 Merged
main(429f11d5) in as66b03bf0. Only the header comment ofd3d12_compute_dispatch.inlneeded hand resolution. In the two test files, main's root SRV and table cases stay and the token cases come after them.Sorry about the force pushes. I first rebased instead of merging, which dropped
ca96748f, the commit thepatrickworld reviewed. I've pushed once more to put it back:That push was a force push, the last one; any further updates will be normal pushes. The tree at
66b03bf0is identical to the rebased one that was tested.@thepatrickworld Thanks, you're right: raw and R32_UINT both give 4-byte elements, so neither case could tell a derived size from a fixed 4.
383ffaebadds your two descriptions asdispatch-output-token-structured(stride 8, 160 elements) anddispatch-output-token-typed8(R16G16B16A16_FLOAT, 160 elements). Same 1280 bytes, so the expected table is unchanged.Windows 11 26200, MSVC 19.44, release preset, RTX 5070 Laptop and WARP:
startup_compute_dispatch_native_warpreports itself skipped). All four token cases match all 320 words on both adapters.const UINT element = (raw || structured || typed) ? 4 : 0;):startup_compute_dispatchfails on both adapters withdispatch-output-token-structured: 128 words differ from the CPU reference, the same 128 you measured.You're also right that the five refusal reasons in the token branch aren't covered yet, and that
FirstElementis always 0 here. I've left them out of this PR to keep it to one behavior, and can follow up if wanted.AI-assisted; commands listed were executed locally.
@thepatrickworld on GitHub · 2026-11-27 19:18 UTC · original
Independent AMD RDNA 4 run on
383ffaeb: the four token cases pass, and three one-line mutants of the same block pass with themNot a code change; measurements only.
Environment
dev,debug layer: unavailable383ffaeb0a65dd37b873f83a4de3ce91a76b65c4,git status --porcelain --untracked-files=noemptyCommands
Run from the repository root:
d3d12_xs.dllin your command block is not a build target here (ninja: error: unknown target 'd3d12_xs');startup_stream_consumerlinksd3d12_xs_shim, so the shim is built as a dependency.Observed
Mutations of the token block
One line each, built and run against the same entry;
git checkout --between runs, and the file hashes back to481cc91c…(sha256of the head blob with CRLF, verified equal).element = (raw || structured || typed) ? 4 : 0(yours) → fails atdispatch-output-token-structured: 128 words differ. The fixture asserts per mode inside the loop, so it stops there and-typed8never runs.structured ? 4→ fails at the same case; with the entry's mode tuple narrowed to-typed8alone, the same build passes. The typed8 case does not see the structured branch.typed ? 4→-token,-typedand-structuredpass,-typed8fails with 128 words. The structured case does not see the typed branch.So each 8-byte case catches a mutant of its own branch and is blind to the other's, and your mutant (1) cannot stand in for (3).
Three mutants of the same block that all four cases still pass:
structured ? 8instead ofdesc.Buffer.StructureByteStride→ the only structured case is stride 8, so the field's value is never read. A case at stride 16 with 80 elements describes the same 1280 bytes, keeps the expected table, and dies here.bytes = resource.Width - offsetinstead ofu64{NumElements} * element→ every case covers the whole buffer at offset 0, so the element count is never read. A view covering half the buffer (stride 8, 80 elements) separates it; its expectation is not the plain table, the second half must stay at the sentinel.if (desc.Format) desc.Format = desktop_format(desc.Format);from the token block → none of the four formats is in the range that function rewrites (116..120,src/startup_stubs/d3d12_xs_device.cpp:765). A token whose format maps, e.g. 116 →R10G10B10A2_UNORMwith 4-byte elements, would see it.(4) and (5) are the ones the two new cases look like they cover and do not; each is one line, and each is killed by a case that keeps the 1280-byte span.
Regression
^startup_compute_dispatch: 19 passed / 1 skipped (native_warp) / 0 failed. CTest prints100% tests passed out of 20because the skipped entry stays in the percentage.Conclusion
On this adapter the four token cases bind the view's own range and the readback matches all 320 words; each 8-byte case pins one of the two non-raw branches of the element derivation. What none of them pins is the stride value, the element count, and the desktop-format mapping.
Limits
expected('A'), last written index 287), so a 160-word bound range differs on 128.FirstElementare not exercised, as you said.AI-assisted; runs executed on the machine above.
@JohnConnorNPC on GitHub · 2026-11-28 07:33 UTC · original
Thanks for adding the 8-byte structured and typed cases. The branch is now 135 commits behind
main(c3204a9c) and has conflicts. Three things that landed onmainsince then interact with the token branch, and a plain conflict resolution won't catch them. Could you look at these when you merge?git merge-tree --write-tree --name-only c3204a9c 383ffaebexits 1 withCONFLICT (content)insrc/startup_stubs/d3d12_compute_dispatch.inlandtests/startup_compute_dispatch_check.py. Both sides add docstring item 8, so yours could become item 9.main,tests/startup_compute_dispatch_output_check.pyexpects('dispatch-output-texture-token', None, 'an output buffer descriptor is a view token'). In the trial-merged tree (git show <tree>:src/startup_stubs/d3d12_compute_dispatch.inl | grep -n 'view token'), the new branch comes first and refuses a texture token withan output view token is not a buffer UAV of a desktop resource. Reason 1 is never reached.docs/experiments/compute-output-buffer-reasons.mdalready says "with it, reason 1 is not reached". Could you repoint that control at the new reason, drop the dead reason-1 line and update the doc?desc_bytesuses the desktop size.git grep -n desc_bytes 383ffaeb -- src/startup_stubs/d3d12_compute_dispatch.inlshowsrecord.desc_bytes >= sizeof(desc)and< sizeof(desc)onD3D12_UNORDERED_ACCESS_VIEW_DESC. #3225 replaced that comparison withViewRecord::uav_desc_bytes(40). The reason is indocs/experiments/agility-compute-views.md: the Agility SDK 1.620.2 header "reports 40 for an SRV and 48 for a" UAV. With Agility headers, every output token would be refused as "not a buffer UAV". UsingViewRecord::uav_desc_bytes, asmain's texture branch does, would fix it.uav <i> bufhalf ...outputs (slot.half_buffer_bytes), which bind a typed UAV withviews[i].described = true. The token branch runs before that and setsviews[i] = {buffer, offset, bytes, true}, sodescribedstays false. The binder then creates aDXGI_FORMAT_R32_TYPELESS/D3D12_BUFFER_UAV_FLAG_RAWview for a typed half store. Todaymainrefuses this case at reason 1. Refusinghalf_bytesin the token branch, or describing the view, would keep that behavior.bytes = resource.Width - offsetmutant from the RDNA 4 run on383ffaeb.Items 2–4 come from reading the trial-merged blobs. Nothing was built or run for this comment.
This comment was AI-assisted.
@RonLogic on GitHub · 2026-11-28 12:09 UTC · original
@Miffedrandir I reproduced a separate compiler-side gap on
052abe6fwith a source-built one-componentbuffer_store_format_x. The native compiler validates the DXIL (u0, one 4-byte element), then reportsunsupported startup runtime manifest bindings: UAV kind typed_buffer_uav. There is no published manifest for the runtime to consume.The natural follow-up is one native published
R32_UINTUAV with a nonzeroFirstElement, a shifted-window control, and unchanged guards on wrong-format or out-of-range refusals. I'd like to use your slot-19 token path for that fixture once the interface lands. Are you planning to cover this native case in #2961, or should I keep it for a dependent follow-up? I can also run the refreshed token tests on RTX 4070 and WARP.@Leyukaka on GitHub · 2026-11-29 06:14 UTC · original · reviewed
383ffaebagainstmain(212d4b5f), by reading both sides; nothing built or run.mainalready binds outputs named by a slot-19 buffer view token.71844ba0addedcompute_token_output(nowsrc/startup_stubs/d3d12_compute_dispatch.inl:471-563, called at:828), with the same raw/structured/typed element sizes as this PR (:520-526) and the same entry-value and output-also-input refusals (:849-853).89b1a3a2gave each refused interval its own reason (:532-537).mainis stricter than this PR: the view must be materialized and counterless (:506), and its backing must uniquely alias the guest byte interval or sit on the default heap (:538-557). Tokens this PR would bind outside those conditions stay refused onmain.main:dispatch-uav-token-{raw,structured,typed}bound and{wrong-slot,copied}refused intests/native_compute_pack_check.py:77-91(structured: stride 8, FirstElement 2, half the elements); three refused intervals with an untouched output intests/startup_compute_token_interval_check.py.git merge-tree --write-tree origin/main 383ffaebexits 1 with conflicts insrc/startup_stubs/d3d12_compute_dispatch.inlandtests/startup_compute_dispatch_check.py.main's branch at:828ends incontinuefor every token, so a second token branch has nothing left to handle.main: a bound typed view with elements wider than 4 bytes. Its typed cases are R32_UINT bound (tests/startup_stream_consumer.cpp:425-428) and a one-element R16_UINT refused.dispatch-output-token-typed8(R16G16B16A16_FLOAT) would add it as adispatch-uav-token-*mode.Superseded by
71844ba0. Suggest closing, or reducing this to the 8-byte typed case on top ofmain's token modes.@JohnConnorNPC on GitHub · 2026-11-29 12:40 UTC · original
Update to my 11-28 comment on
383ffaeb. I checked againstmain77d1ba4d.I agree with the 06:14 review:
mainalready binds token-named outputs.compute_token_outputis called atreason = compute_token_output(self, words, token);inrecord_translated_dispatch, from71844ba0(git merge-base --is-ancestor 71844ba0 origin/main→ true). Its branch covers raw, structured and typed element sizes, and it usesViewRecord::uav_desc_bytes. So items 2–4 of my earlier comment (thedispatch-output-texture-tokencontrol, thesizeof(desc)comparison and the half-buffer raw view) no longer need work here. Please disregard them.MUST
git merge-tree --write-tree --name-only origin/main 383ffaebexits 1 insrc/startup_stubs/d3d12_compute_dispatch.inlandtests/startup_compute_dispatch_check.py, and the second token branch would never be reached. The new part is the bound 8-byte typed case (dispatch-output-token-typed8, R16G16B16A16_FLOAT). Please reduce the PR to that case as adispatch-uav-token-*mode onmain's path, or close it.AI-assisted.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.