native: read GPU-selected heap slots raw and typed in one program #3063
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!3063
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3063"
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?
@JB2WIN on GitHub · 2026-11-27 13:21 UTC · original
JB2WIN:native/heap-mixed-raw-typed→cpp-migration· +450 −86 · 9 files · 3 commits · closed without mergingChange
Target branch
cpp-migration. Refs #3023. Follow-up to #3042 (merged asa0f67731).Programs that read some GPU-selected heap slots raw and others with a one-channel typed load were refused under both heap view contracts:
raw_bufferrefuses the typed load ("a GPU-selected heap slot is read as a raw buffer SRV only"),typed_dwordthe raw load ("… read as a typed dword buffer SRV only"). This adds a third contract class for that mixed case.src/gfx1013_compute_native.h:HeapViewContract::raw_and_typed_dword, with its caller guarantee in the comment. The old clause "a program with two heap loads from different selectors is outside what one captured selection covers" is replaced by an explicit limit for every contract.src/gfx1013_direct_compute.inl,heap_resource: under the new contract the kind of each heap load picks the path.buffer_load_format_*(typed_buffer_srv) follows thetyped_dwordrules, including the one-channel limit. Every other kind,tbuffer_load_format_*through a plain or rewritten descriptor included, follows theraw_bufferrules: raw handle, byte windows and the loop guard. One line of logic changed; refusal texts are unchanged.src/gfx1013_compute_native.cpp: the byte-address rewrite of a heap descriptor is tracked underraw_bufferandraw_and_typed_dword.src/direct_compute_cache.cpp: cache identity/heap-view/raw_and_typed_dword.src/startup_stubs/native_global_srv.h:.viewsgains zero or morealso <slot> <type>lines, each a further selection of the same dispatch. Selector word k is selection k (select/needfirst). The header stays version 2; an older decoder refuses such a file withunknown line 'also'.slot N selected with two view types).refuse_global_srv_selections()checks every selection in order.global_srv_contract()returnsraw_and_typed_dwordwhen raw and typed selections are both present.tools/startup/compile_dxil.cpp: maps the contract with aswitchand uses the plural check at both sites. The report line gainsalso=<slot>:<type>.tests/native_global_srv_heap_replay.cpp:record … [--also SELECTOR TYPE]writes selector word 1.N+Mreference in replay).type_from_argumenthelper is shared by--needand--also.Why this step: on a local start-up capture (
compile_dxil --refusals, 2,689 slot 67 requests, counts only), 895 of the 906 programs with a typed heap load also read another heap slot raw. With this contract forced by an uncommitted switch, compiled requests go from 392 to 397. The others now stop at general refusals: 717unbound numeric SGPR sN, 460direct indexed descriptor load shape, 291direct descriptor address outside bound table. That is an upper bound for what translation allows. No runtime producesalsolines or binds heap slots under a contract yet; that is stage 3 of #3023.Verification
Environment: Windows 11 build 26200, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), MSVC 14.51.36231, Windows SDK 10.0.26100 DXC. Base
cpp-migrationa0f67731.native_global_srv_heap_replay_hardware: passed, 196 assertions (122 before), 12.5 s (11.25 s before). New section 11 uses a source-built mixed program: two selector words, a rawbuffer_load_dwordthrough one heap descriptor and abuffer_load_format_x idxenthrough another, with the sum stored..viewshasalso 3 typed_buffer.compile_dxil --requestswith a fresh frontend cache: compiled withfrontend_cache_hit=0, then=1with the same.cso..cso: the mixed program under the raw-only and the typed-only.views;alsowith a texture, wrong type, unknown slot, unreadable line, or a trailing field; a slot named with two types (the selected slot and analsoslot); a secondalsoof another type than its slot; a texture secondalso; a missingdwordline; a two-channel typed load.also, analsonaming the selected slot again with the same type, the samealsotwice, a byte window bybuffer_load_dword, one bytbuffer_load_format_x, and atbuffer_load_format_xthrough a plain heap descriptor.compile_dxiland the fixture built ata0f67731passes the 122 earlier assertions and fails at the first mixed record (the old fixture has no--also).compile_dxilrefuses a mixed.viewswithunknown line 'also'; the new one compiles it.typedset to false): the first mixed record fails.native_cvt_pk_u8_hardware,native_sdwa_f16_ir,native_sdwa_f16_hardware).compile_dxil --refusalson the local capture without a contract: identical to the base.Evidence and follow-up
clang -cc1as -triple amdgcn-amd-amdhsa -target-cpu gfx1013 -show-encoding); fixtures are source-built.docs/experiments/native-global-srv-heap-replay.md):raw_bufferconditions for every slot a raw load can select, and thetyped_dwordconditions for every slot a typed load can select.tbuffercounts as raw.Checklist
AI-assisted.
🤖 Generated with Claude Code
@R0Y00 on GitHub · 2026-11-27 13:27 UTC · original
Thanks for documenting the dependency on #3042. New translator PRs target
main, but changing this base today would pull #3034 and #3042 into the same diff. Atmainff04a75e, the typed-dword heap contract from #3042 is still absent. Please leave the base here while those prerequisites are carried tomainin order, then we can retarget this PR and verify the mixed raw/typed fixture against the new base. The pending runtime capture work stays tracked in #3023.@JB2WIN on GitHub · 2026-11-27 13:28 UTC · original
Understood, leaving the base on
cpp-migration. Once #3034 and #3042 are onmain, I will retarget, rebase and rerun the mixed raw/typed fixture (native_global_srv_heap_replay_hardware) plus the regression set against the new base, and report the results here.AI-assisted.
@JohnConnorNPC on GitHub · 2026-11-27 17:27 UTC · original
Thanks, the contract split by load kind reads cleanly, and the limits are written down. I checked this from Linux
only: a header harness over
native_global_srv.hwith mutants, llvm-mc over the new words, and the affected Pythonchecks on the head and on a merge with current
main(clean, all pass). I did not run the GPU fixture.Duplicate slots vs selector-word order. Selection k is selector word k, but the decoder refuses a slot named
twice even with the same type, and the doc says "a producer deduplicates". A dispatch whose two words pick the
same raw slot then has no valid
.views. Deduplicating drops word 1, andreplaywrites 0 there, so it replays adifferent selection.
recordwrites such a file without complaint: its in-memory request passesrefuse_global_srv_selections, anddecode_global_srv_requestrefuses what it wrote ("duplicate selected slot0"). Could the decoder accept a repeated slot when the type is the same (and refuse only a slot named with two
types)? Or could the doc say the capture refuses such a dispatch, with
recordrefusing it too?Untested rules. With
native_global_srv.hmutated, each of the following still gives the same outcome onevery
.viewsthat section 11 feeds the decoder:alsolines;refuse_global_srv_selectionsorglobal_srv_contractchecking only the firstalso.Four negatives would pin them:
also 0 raw_buffer, a secondalso 3 typed_buffer,also 2 raw_bufferas thesecond
also, andalso 2 textureas the secondalso.Coverage note. PR CI builds the
prpreset, which does not include this fixture, and the_warpvariantskips by design. So the green checks don't execute section 11. Could you add the head commit you tested and the
debug-layer status to the GPU report?
Small items.
gfx1013_direct_compute.inlnames two contracts.typed_dwordalso admitsthe heap descriptor load and reaches that refusal.
--alsoselector throws before thetry(exit 3 under MSVC); returning 2 would match the usage path.alsoline accepts trailing fields.This comment was AI-assisted.
@JB2WIN on GitHub · 2026-11-27 22:47 UTC · original
Thanks. Working on all four points now; update with a new commit soon.
AI-assisted.
@JB2WIN on GitHub · 2026-11-27 22:54 UTC · original
Done in
64513f26.recordoutput now always decodes. New raw+raw case:record --also 0 raw_buffer, compile,replay 0+0matches,replay 0+1mismatches.also 2 raw_buffer(selection refusal), secondalso 2 texture(contract refusal),also 0 typed_bufferandalso 3 raw_bufferafteralso 3 typed_buffer(two types). Positives:also 0 raw_buffer, secondalso 3 typed_buffer. Mutation check:refuse_global_srv_selectionsstopping after the firstalsofails the second-alsocase.64513f26, RTX 3080 (driver 32.0.16.2124),native_global_srv_heap_replay_hardware196 checks pass, 12.5 s. Debug layer not enabled in the fixture. Regression (native_|startup_compute_dispatch|compute_heap): 147 tests, the same 3 failures as the base.--alsoselector returns 2;alsowith trailing fields is unreadable.AI-assisted.
@R0Y00 on GitHub · 2026-11-27 23:17 UTC · original · reviewed
Independently tested
64513f26oncpp-migrationa0f67731(clean trial tree80c5c815). I builtcompile_dxil native_global_srv_heap_replayand ranctest --test-dir <build> --no-tests=error -j1 -V -R '^native_global_srv_heap_replay_(warp|hardware)$'in Debug and Release /O2. Each build passed all 196 assertions on RTX 4060 Laptop (driver 32.0.16.1656, Windows 11 26200.9974, debug layer off). Inbox WARP 10.0.26100.9818 returned 77 for lack of wave32. The repeated0+0selector round-trips,0+1gives the required mismatch, and the secondalsoand conflicting-type controls refuse. Please update the old duplicate-slot wording in the PR body to reflect the new same-type behavior. Thetyped_dwordcontract still lives on the migration branch, so the previously agreed #3034/#3042 port order still determines when this can targetmain.@pigalot on GitHub · 2026-11-27 23:18 UTC · original · approved these changes
Independently reviewed
64513f26integrated overcpp-migrationa0f67731(tree80c5c815), the PR's base. The merge is clean andgit diff --cached --check origin/cpp-migrationis clean.What I traced.
native_global_srv.h, selection 0 isselect/needand selection k is the k-thalsoline, in file order..views.refuse_global_srv_selectionschecks every selection, and the first refusal wins.global_srv_contractreturnsraw_and_typed_dwordonly when at least one selection is raw and one is typed. Every captured typed slot must still be a one-channel 32-bit buffer.heap_resource,raw_and_typed_dwordtakes the typed path only fortyped_buffer_srvloads. Every other kind stays raw, and the byte-window tracking applies as underraw_buffer.JohnConnorNPC's findings, checked at this head.
--also 0 raw_buffer, decodes and compiles.mismatch word 0: got 0x40000000 expected 0x50000000 (reference slot 0+1).--alsoselector exits 2.alsoline with a trailing field is refused.What I ran. I built
native_global_srv_heap_replay compile_dxilindevandrelease, then ran:native_global_srv_heap_replay_hardwarepasses in Debug and Release/O2on the RTX 5090 ("all checks passed", about 11 s). The output includesmixed_also_same_slot,mixed_also_twiceand "record with a non-numeric --also selector exits 2".native_global_srv_heap_replay_warpreports a capability skip (77) in both presets, by design.ctest --test-dir out/build/dev --no-tests=error -j 1 -R '(native_|startup_compute_dispatch|compute_heap)'. 147 tests in Debug.native_comparison_pso_warp,native_heap_handle_probe_warp,native_global_srv_heap_replay_warpandstartup_compute_dispatch_native_warp.native_cvt_pk_u8_hardware,native_sdwa_f16_irandnative_sdwa_f16_hardware. All three also fail oncpp-migrationa0f67731built alone, so they come from the base, not from this PR.Mutants in
src/startup_stubs/native_global_srv.h. Each was applied alone, the targets rebuilt indev, the_hardwaretest run, and the source restored afterwards (git diff --quietclean).mixed_also_same_slot: refused instead of compiledmixed_two_types: not refused with "slot 0 selected with two view types"select/needmixed_two_types_also: not refused with "slot 3 selected with two view types"refuse_global_srv_selectionschecks only the firstalsomixed_second_also_wrong_type: not refused with "slot 2 has view type texture"global_srv_contractchecks only the firstalsomixed_second_also_texture: not refused with "view type texture is not raw_buffer or typed_buffer"alsoline acceptedmixed_trailing_field: not refused with "unreadable also line"Verdict: approve on
64513f26. The base iscpp-migration, so this is a review only. I am not merging, and R0Y00's plan to retarget after #3034 and #3042 reachmainstands.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088 and WARP, Windows 11 25H2 build 26200.9974, MSVC 19.52.37029; the debug layer is off in the fixture.
CI:
Build and test on Windows,Assemble and translate gfx1013 fixturesandRun platform-independent Python checks on Linuxpass on64513f26.This reply was AI-assisted.
@RonLogic on GitHub · 2026-11-28 00:20 UTC · original
I tested a clean local trial of
64513f26on a main-based stack:7fcde81f, #3034 as6fb2316c(now #3234), #3042 as43312821, then both #3063 commits throughd484785f. The carry keeps main’s raw-address CPU-reference cases and the optional expected-word input to the replay tool.Release on Windows 11 26300.10075, DXC 1.9.2602.17, RTX 4070 (32.0.16.2124) and app-local WARP 1.0.22 with Agility 1.620.2:
All four tests passed. Each heap replay emitted 217 passing assertions including the raw+typed selections 0+3 and 1+3, repeated 0+0, cold/warm identical DXIL, and the metadata refusals. On both adapters, the deliberate 0+1 reference for the 0+0 dispatch failed at word 0 (0x40000000 vs 0x50000000). This verifies the source-built compiler/replay stack on a main-based tree. The live heap contract remains tracked in #3023.
@JohnConnorNPC on GitHub · 2026-11-28 08:05 UTC · original
Thanks for the quick turnaround on
64513f26. All four points from my earlier comment are addressed, and I think this is ready to merge intocpp-migration. It is a fast-forward there:git rev-list --count 64513f26..a0f67731→0. I found nothing blocking, only one body fix and three small notes.It can't target
mainyet.git merge-tree --write-tree --name-only 1f07b2c1 64513f26exits 1 with 6 conflicting files. The basea0f67731already conflicts in 5 of them, and this PR addssrc/gfx1013_compute_native.cpp. #3234 (the #3034 port) is open with changes requested, and no #3042 port is open yet.Should fix: the duplicate-slot wording that R0Y00 asked to update on the review is still in the body ("The decoder refuses a slot named twice, even with the same type"). GraphQL
lastEditedAtis stillnull. The body's counts are also behind the doc: "174 assertions", "Nine compile refusals" and "Four compile-only cases", where the doc now says 196 assertions, thirteen refusals and six compile-only cases.Notes, none blocking:
src/startup_stubs/native_global_srv.hsays the dispatch is refused "when the selected slot holds another type than the one the shader reads". Underraw_and_typed_dword, each word's type comes from the capture (need/also), not from the shader. From reading the code (not run),select 3 need typed_bufferwithalso 0 raw_bufferon the MIXED program passes the guard, and the typed view is then read through the raw handle. TheHeapViewContractcomment and the doc's Limits already call this a caller guarantee. One sentence in the header saying the guard is necessary but not sufficient would match them.return raw ? GlobalSrvContract::raw_and_typed_dword : GlobalSrvContract::typed_dwordor for the new/heap-view/raw_and_typed_dwordcache-identity line. From reading the code, section 10's typed refusals andmixed_raw_views/mixed_typed_viewsshould catch both, but that is not measured.otherrefusal insrc/gfx1013_direct_compute.inl, "is not raw_buffer; only raw buffer heap reads are translated", has been out of date since #3042 addedtyped_dword.Opcodes: the diff adds no DXIL op (
grep -cE '^\+.*(dx\.op|createHandleFromHeap|annotateHandle)'→0). Loads reuseraw ? 139 : 68, and handles reuse kinds 11 and 10 (5 + 1 * 256), chosen per instruction.llvm-mc-19 --disassemble -mcpu=gfx1013of the MIXED words matches each comment (LLVM 19 prints the zero SMEM offset asnull). CI's Windows job ranctest --preset pr(100% tests passed out of 41) with nonative_global_srvtest. So section 11 rests on the GPU runs posted here: RTX 3080, RTX 4060 Laptop and RTX 5090 on this base, and RTX 4070 plus WARP on a main-based stack. The three runs that report the debug layer had it off.This comment was AI-assisted.
@JB2WIN on GitHub · 2026-11-28 14:32 UTC · original
Thanks. Done:
2534937aadds the sentence to the top ofnative_global_srv.h(comment only).otherrefusal text predates this PR and would be its own small change.AI-assisted.
@JB2WIN on GitHub · 2026-11-28 23:51 UTC · original
Carried to
mainin #3417, stacked on #3411 (which brings #3034 and #3042 over, taking over #3234).AI-assisted.
@JB2WIN on GitHub · 2026-11-29 09:33 UTC · original
Closing: the same three commits reached
mainthrough #3417 (merged as1341bd6b). AI-assisted.Pull request closed