Repository navigation
startup: bind compute outputs named by a buffer UAV view token - #2961
Miffedrandir wants to merge 3 commits into
Conversation
…oken A translated Dispatch refused every output whose table entry holds the token of a buffer view the title created (device slot 19), with "an output is not an aliased placed buffer range with unordered access". Such an output is now bound in that view's desktop resource over the view's own range: raw, structured, or typed (sized by its format), as input tokens already are. Still refused, one reason each: a token that is not a buffer UAV of a desktop resource with unordered access; a view with no element size; a range that is empty, unaligned, over 16 MiB or outside its resource; an entry value read from the output's hardware descriptor words, which a token does not have; and an output buffer that is also an input. Outputs named by an address are unchanged. startup_compute_dispatch gains dispatch-output-token and dispatch-output-token-typed: the output descriptor is replaced by the token of a raw, or R32_UINT, view of the output buffer, and all 320 words must match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
|
Independent AMD RDNA 4 and WARP result on Not a code change; measurements only. Environment
CommandsObserved on the unmodified head16 of 16 entries pass, ctest exit 0, no skip. Across them 15 lines read What the two added cases cannot separateBoth 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 Mutation, File sha256 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: The mutation is not an equivalent program: it also turns some refusals into acceptances, because the range checks downstream use the same Two descriptions that do separate itSame 1280 bytes with 8-byte elements, so the expected table is unchanged (the fixture hard-codes case A):
Head, 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 ( Base control: this fixture on the old translator
The same 288 words as your own control against What the branch bindsThe title's description never becomes a descriptor: for a buffer output, Refusal reasons (reading, not measured)No case in Limits
If the two extra modes are worth having, I can push them as a patch on top of this branch. AI-assisted. |
KelboLive
left a comment
There was a problem hiding this comment.
PR #2961 fills the gap: compute outputs now accept buffer UAV view tokens (slot 19), not just address-based naming.
What works
- Symmetric design: inputs already accepted view tokens (slot 18); outputs now do the same (slot 19).
- Three view types handled: raw (R32_TYPELESS + RAW flag), structured (UNKNOWN format + StructureByteStride),
and typed (typed buffer, element size from typed_buffer_format_bytes). Each correctly rejects mismatched flags. - Locking: AcquireSRWLockShared/ReleaseSRWLockShared around view_records() lookup. Shared lock allows concurrency
while the map grows during a title run. - Validation chain covers all cases: unknown token, non-buffer resources, missing element size, empty/unaligned
ranges, ranges over 16 MiB or outside the resource, and entry-value outputs. - Test fixture creates raw and typed UAVs at slot 19 over the output buffer; dispatches them and checks all 320
output words match with zero refusals. - 49 programs / 392K dispatches measured in a title run were previously refused; this unblocks them.
Issues
- view_records growth during idle: the SRW lock is acquired during dispatch but view_records can grow during
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_buffer_format_bytes() dependency: the code calls x2w_startup::typed_buffer_format_bytes(desc.Format) for
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. - desc.Format = desktop_format(desc.Format): this converts DXGI formats for desktop. But typed views of buffers
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. - The 16 MiB cap: the code also caps at 16 MiB for output tokens. This means a large compute output written
through a view token would be refused. Consistent with address-based naming but limits applicability.
Recommendations
- Add an assertion near view_records push that the writer holds the SRW lock in exclusive mode.
- Document the set of typed_buffer_format_bytes() supported formats near its use site.
- Consider a dev-build diagnostic log when view tokens are accepted (e.g. a once-per-frame counter).
Overall: clean, correct. Fills a real gap and adds good test coverage.
R0Y00
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
What works
- The new path mirrors the existing input-token handling, reusing
the sameview_records()lookup, the shared
AcquireSRWLockShared/ReleaseSRWLockSharedpattern, and
desktop_format()-- consistent and safe. - It correctly restricts to raw (
R32_TYPELESSwithRAWflag) and
typed (R32_UINT) buffer views, matching the input side's narrowness. - The test harness adds raw and typed view modes with expected-match
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.- The shared lock guards the
view_records()read but not the
as_wrapper()call. Ifview_records()can grow between the size
check and theas_wrapper()lookup, recompute the index under the
lock. - No new tests for malformed tokens (e.g. a non-buffer resource with
noBuffer.Flags).
Recommendations
- Recompute the index under the lock before
as_wrapper()to avoid a
racy lookup as view_records grows. - Add a small refusal test to confirm the out-of-range path works.
Overall
Solid change that aligns output binding with input handling already in
the codebase. Approvable with the lock scope adjustment noted above.
|
This PR now conflicts with
Could you merge AI-assisted; commands listed were executed locally. ( |
ca96748 to
ee2ab75
Compare
Resolve the header comment of d3d12_compute_dispatch.inl (root SRV inputs from main, output view tokens from this branch) and keep main's root SRV and table cases next to this branch's two output-token cases in the dispatch test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
dispatch-output-token-structured (stride 8) and dispatch-output-token-typed8 (R16G16B16A16_FLOAT) describe the output's 1280 bytes as 160 8-byte elements. The raw and R32_UINT cases both have 4-byte elements, so they could not tell a derived element size from a fixed 4; these two can. Suggested by the review on this PR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sir6Mr49SZWax95VApRPvz
ee2ab75 to
383ffae
Compare
|
@tedin7 Merged Sorry about the force pushes. I first rebased instead of merging, which dropped ca96748, 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 66b03bf is 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. 383ffae adds your two descriptions as Windows 11 26200, MSVC 19.44, release preset, RTX 5070 Laptop and WARP: cmake --build --preset release --target startup_stream_consumer d3d12_xs.dll offscreen_check
ctest --preset release --no-tests=error -R '^(startup_compute_dispatch|startup_slot67_indirect_dispatch|startup_compute_translate)'
You're also right that the five refusal reasons in the token branch aren't covered yet, and that AI-assisted; commands listed were executed locally. |
|
Independent AMD RDNA 4 run on Not a code change; measurements only. Environment
CommandsRun from the repository root:
ObservedMutations of the token blockOne line each, built and run against the same entry;
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:
(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
ConclusionOn 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
AI-assisted; runs executed on the machine above. |
AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* runtime: name each refused condition of a compute output buffer The refusal "an output is not an aliased placed buffer range with unordered access" covered nine conditions. Each now has its own reason in the log and the census: a view token, zero records, a range over 16 MiB or not whole dwords, a range crossing a placed buffer's end, memory outside any placed buffer, a copied placement, a resource not created in the common state, an offset not 16-byte aligned, and no unordered access. What is bound and what is refused do not change. tests/startup_compute_dispatch_output_check.py produces each condition on case A and checks its reason, the census line and an untouched output. dispatch-swapped now expects "an output buffer has no unordered access". AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: copy the output texture token into its table entry Creating the view at heap byte 16, which is not a descriptor of the heap, ends the consumer; the view is created at byte 64 and its token words copied. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: record the output reason fixture results AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: per-reason counts from one start-up run AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: the token keys with #2961 merged AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: label start-up counts as first-refusal buckets The census keeps one first refusal per key and counts all of the key's untranslated dispatches under it, so the run tables are first-refusal buckets, not counts per condition. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for adding the 8-byte structured and typed cases. The branch is now 135 commits behind
Items 2–4 come from reading the trial-merged blobs. Nothing was built or run for this comment. This comment was AI-assisted. |
|
@Miffedrandir I reproduced a separate compiler-side gap on The natural follow-up is one native published |
Part 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
main429f11d merged 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