Repository navigation
native: translate GPU-selected heap textures through view tokens in compute - #3544
Conversation
…ompute A compute program that loads a texture with s_load_dwordx8 from the directly indexed resource heap at an SGPR offset chosen by GPU data is now translated when every use of the eight words is the T# of a supported image instruction (1D, 2D or 2D-array load, load_mip, sample_l, sample_lz, 2D gather4_lz, get_resinfo). The shader reads the 32-byte view token at the guest byte address, checks the magic, the view id range and the dimension recorded for the id, and samples ResourceDescriptorHeap[base(dimension) + id] (a null slot otherwise, counting one miss per wave). The manifest names the runtime- provided views and words (heaptok, heaptokdims, heaptokmiss, five heaptok words); the runtime reader still refuses them by name, so dispatch behaviour is unchanged. Not independently design-approved: see the PR description. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed ec7318d8 by reading the diff; not built or run.
Verdict: approve. Translator-only: both runtime routes still refuse these programs. No MUST; the SHOULDs can follow here or in PR 2.
- SHOULD The miss counter ignores EXEC (
src/gfx1013_direct_compute.inl:1086-1088). The image op is predicated onactive()(:1546), butmissedis only!valid && waveIsFirstLane. A wave that reaches the instruction with no active guest lanes still counts a miss. Gate it on an active lane or emit it inside the image predicate. The fixture only runs full waves. - SHOULD The native-only route does not refuse these by name. With
native_shaders_only(),load_compute_translationreturns before the manifest reader (src/startup_stubs/d3d12_compute_dispatch.inl:280). It then translates in process and throwsview kind 29 is not bound for a natively translated program(:559). Oneheap_token_wordscheck before the bindings loop would give triage the same text on both routes. - SHOULD Say why
native_compute_output_revisiongoes to 2 (src/native_compute_output.h:8). The bump marks every published compute manifestanother compiler revision; rebuild it, although per A3 the existing ones differ only in that line. If the goal is retrying refused requests, say so in the doc. - NIT
conservative_sgpr_reads(src/gfx1013_compute_native.cpp:1745-1777): its comment says unknown reads "read everything", butdefault:reads nothing. VOP3 mask/carry SGPR pairs (v_cndmask_b32,v_addc_co_u32) count as one register. The eligibility proof depends on this list. - Checked, no finding: the
encode/decodechange is safe (the cache key hashesdirect_compute_cache.cpp);dx_kind1/2/7 is right; content tokens failid < count;count == 0stays invalid.
Tests: _controls reaches the pre-pass refusals, the manifest writer and the module shape. _hardware checks the token check and the miss count, with full EXEC only. CI ran none of the new or changed tests (none is in the Windows pr filter), so the hardware results come only from the author's RTX 3080 run.
…e-only refusal, SGPR reads)
- Count a token miss only when the wave has an active guest lane (ballot of EXEC), not for a
wave that reaches the instruction with EXEC = 0. The hardware fixture gains two modes: EXEC
limited to the upper 16 lanes (lane 0 inactive) and EXEC = 0.
- The native-only route refuses a program with token words with the manifest reader's text
("heap token textures are not bound yet") instead of "view kind N is not bound". Covered by
startup_compute_dispatch_native.
- conservative_sgpr_reads: encodings without a case now read every SGPR (control flow, LDS,
export and interpolation are listed as reading none), and the v_cndmask_b32 lane mask counts
as a pair. Control in native_heap_token_texture_controls (mask_pair vs. a mask clear of the T#).
- Say why native_compute_output_revision is 2 (header and doc).
AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts in src/direct_compute_cache.cpp (token words before the sampler heap line), tests/native_compute_manifest_reasons.cpp and tests/startup_compute_dispatch_native_check.py: both sides kept. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@lukaslw-lab thanks for the review. Addressed in 9917aa9, then merged main (cf0f40b):
The main merge keeps both the heap token words and the sampler-heap cache fields; encode and decode are symmetric. AI-assisted. |
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed cf0f40be by reading the diff; not built or run.
Verdict: approve. Translator only, and both runtime routes still refuse these programs. 9917aa9c handles our three SHOULDs. No MUST, no SHOULD.
- Checked, no finding:
- Miss count (
src/gfx1013_direct_compute.inl:1176-1178): the miss branch now also needsballot(active()) != 0. Ballot component 0 is enough because the route needs 32-lane host waves, and a wave64 guest runs as two of them, each with its ownactive()half. - Native-only refusal (
src/startup_stubs/d3d12_compute_dispatch.inl:557): the check comes after both the pack branch and the in-process branch. The pack decode restoresheap_token_words(src/direct_compute_cache.cpp:162), so a packed program is refused with the same text.triage_run.pylists the reason. conservative_sgpr_reads: an unknown encoding now reads s0..s105, so the check fails closed.
- Miss count (
- NIT The VOP3 carry-in of
v_add_co_ci_u32,v_sub_co_ci_u32andv_subrev_co_ci_u32(src2) is still counted as one SGPR. A wave64 guest reads a pair there, the same case as thev_cndmask_b32line added atsrc/gfx1013_compute_native.cpp:1891. - NIT For a wave64 guest, the miss counter adds one per 32-lane half that has an active lane. The doc says "one count per wave". The fixture runs wave32 only.
Tests: tex2d_execnone covers the EXEC case, and heap_token_refusal covers the native-only text with a control. No CI run exists at this head yet. The last run (ec7318d8) failed only startup_triage_run_check, on a reason from main that #3542 fixed, and the merged head includes that fix. The new hardware and controls tests are not in the pr filter, so the RTX 3080 run is still the only hardware evidence.
…extures Conflicts and how they were resolved: tests/native_compute_manifest_reasons.cpp kept both new cases (our heap token views and words, upstream's root buffer SRV) and the summed case count (+9). CMakePresets.json: native_heap_token_texture added to the pr build preset so the native_.*_controls test filter finds its executable. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Friendly note: this is approved, but it currently conflicts with |
Conflicts came from main moving the frontend cache to the field visitor and the stride words to stride_sources; the new field joins the visitor, the cache round-trip fixture and validate_shader. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Leyukaka merged Local, RTX 3080: AI-assisted. |
The heap token offset check now names gfx1013::reg::null, as main does since R0Y00#3830. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
R0Y00
left a comment
There was a problem hiding this comment.
On bb37d7f, independent MSVC Debug passed the heap-token controls, hardware readback, native cache round-trip and manifest controls (4 passes). WARP returned capability skip 77 for the wave32 fixture. Hardware was RTX 4060 Laptop, driver 32.0.16.1656, Windows 11 build 26300. After #3500 landed, the trial merge conflicts in the frontend cache visitor, NativeComputeShader, direct lowering, manifest-reason and round-trip fixtures. Please keep both image_fields and the heap-token fields in the visitor/round trip, retain each feature's runtime refusals, and rerun the two focused suites after rebasing.
R0Y00#3500 adds image_fields at the same places as heap_token_words. The b0 words are now: root constants, stride words, image field words, heap token words, in the translator, the manifest and the cache visitor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Leyukaka main moved again, including #3500, which adds its image field words at the same places as the heap token words. Merged in f7a54aa (this PR) and 26d1c53 (#3631). The b0 words are now root constants, stride words, image field words, then heap token words, in the translator, the manifest and the cache visitor. Both branches merge cleanly into Local, RTX 3080: If it conflicts again by the time you check, feel free to resolve it yourselves. We're fine with that, as you offered. AI-assisted. |
R0Y00
left a comment
There was a problem hiding this comment.
Re-reviewed f7a54aa, including the #3500 conflict resolution. The translator, manifest and cache visitor agree on root constants, stride, image fields, then heap-token words. The current runtime still refuses the token bindings as intended. Independent Windows 11 26300/MSVC Debug ctest --preset dev --no-tests=error -j 1 -V -R '^native_heap_token_texture_(controls|warp|hardware)$|^native_direct_cache_controls$|^native_compute_manifest_reasons$|^startup_compute_dispatch_image_fields_(controls|warp|hardware)$' gave 7 passes and one capability skip (wave32 heap-token WARP, code 77). The RTX 4060 Laptop ran heap-token readback and both adapters ran the #3500 regression. Linux reports the shared export-catalog mismatch addressed by #3885.
R0Y00
left a comment
There was a problem hiding this comment.
Revalidated 539bd0e with the #3885 baseline. The files owned by this PR are unchanged. Independent MSVC Debug on Windows 11 build 26300 passed seven tests: the heap-token controls and RTX 4060 Laptop readback, cache and manifest checks, and all three #3500 image-field regressions. The WARP heap-token case returned capability skip 77 for wave32. python -B tests/standin_exports_check.py passed 476 checks including all six mutation controls.
…nslator) (#3631) * native: translate GPU-selected heap raw buffers through view tokens in compute Refs #3023 #3224. Builds on the heap token textures of #3544. A raw buffer V# loaded with s_load_dwordx4 from the directly indexed resource heap at a GPU-selected byte offset (an SGPR offset, or an address formed by s_add_u32) is read through the view token the title keeps at that address, like the token textures. Reads of that V# in the byte-window form (buffer_load_dword{,x2,x3,x4} with OFFEN, the s_bfe/s_max/s_mul/s_and/s_or rewrite) and scalar buffer loads from it are translated; every other use keeps today's path and refusal text. - Each s_load_dwordx4 candidate is judged on its own; a candidate that fails is dropped and does not take the texture route off the program. An s_add_u32 heap address that is not an eligible candidate keeps the old rejection. - The shader checks magic, id range and the dimension table entry 0x20 (raw buffer view) on every execution and reads ResourceDescriptorHeap[baseraw + id], or the null raw view with one counted miss per wave. - A program with an eligible buffer load publishes seven token words (baseraw and nullraw after the five of the textures): NativeComputeShader:: heap_token_word_count replaces heap_token_words. Texture-only programs keep five words and byte-identical modules and manifests (revision line aside). - native_compute_output_revision 2 -> 3. - The dispatch reader names baseraw and nullraw and still refuses every heaptok line: programs of this change stay refused at dispatch until the runtime binds the views (PR 2). Tests: native_heap_token_texture_controls (eligible forms, controls with today's text, address shapes, loop, mixed texture and buffer), native_heap_token_texture_{warp,hardware} (rawbuf, rawbuf_waterfall, sbuf), native_compute_manifest_reasons, startup_compute_dispatch_texture. The design was frozen by the owner without independent approval (see the PR). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * native: judge the heap raw buffer address shape in the analysis Review fixes for the heap token buffer route. - heap_token_buffer_eligible now checks the address the lowering needs, on the state at the load: heap pointer high word is the constant 0, imm % 32 == 0, proven 32-byte aligned SGPR offset, no offset + imm overflow; on an added address imm == 0 and a masked offset. It also compares the V# words symbol for symbol as heap_token_buffer does. A candidate that fails is dropped (an added address keeps the old program-wide rejection) and keeps today's text. The lowering refusals stay as a safeguard. - When no buffer load is eligible, the textures are judged again on the analysis without the byte window, as before the route knew buffers. - Document the carry assumption of an added address (heap-relative model of the existing heap_offset path, no runtime carry check). - Tests: address-shape controls expect the heap contract text of the dropped load; new controls for overflow, a non-constant high word, an unread candidate next to a texture, and an accepted wide mask. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * native: drop heap buffer candidates the lowering would refuse (loop, word budget) Review fixes, round 2. - A byte window load inside a loop is dropped by the analysis with the same query the lowering uses, instead of failing the whole program (textures included) at lowering. - When the seven token words do not fit the 32-word entry layout next to the descriptor strides and root constants (the strides are known only while lowering), the program is translated again with the buffer route off, so the buffer loads keep today's path and text. - Document that words 2 and 3 of the title's V# are not read and that PR 2 must make the raw view's range equal it (A1). - Tests: loop and texture + loop controls now expect today's text; 25 strides compile next to seven token words, 26 are refused with today's text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * native: signal the heap token word budget by exception type, tidy comments - The budget retry in translate_program catches HeapTokenWordBudget (thrown by prepare_heap_tokens with the same text) instead of matching the message. - Exact root signature match for the user SGPR count in the test, comments wrapped to 120 columns, doc line for the seven-word form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * native: rejoin a wrapped comment on the heap token budget retry Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: keep the revision 2 note next to revision 3 for heap token loads Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Royoo <3230853833@qq.com>
Change
#3023 stage 3, PR 1: translator only. A compute program can load a texture with
s_load_dwordx8from the directly indexed resource heap at an SGPR offset that comes from GPU data. Such a program is now translated, provided every use of the eight words is the T# of a supported image instruction. Supported: 1D, 2D or 2D-arrayimage_load,load_mip,sample_l,sample_lz,get_resinfo, and 2Dgather4_lz; samplers literal, or fixed-index from the sampler heap forsample_l/_lz.The shader reads the 32-byte view token in title heap memory at the guest's own byte address (
so + imm, 4-byte aligned, overflow refused). It checks:0x56573258;id < count;dims[min(id, count - 1)] == 1 + dim.It then samples
ResourceDescriptorHeap[base(dim) + id]. Otherwise it reads a null slot and counts one miss per wave (waveIsFirstLane+ atomic add). There is no slot mirror and no per-dispatch heap scan. The heap measured in #3023 has about 1.25 M logical descriptors, of which about 15.5 k hold tokens.The manifest names the runtime-provided views and words:
srv N heaptok,srv N heaptokdims,uav N heaptokmiss, and fiveudsrc K heaptok …words. The runtime reader still refuses them by name (heap token textures are not bound yet), so dispatch behaviour is unchanged. Binding them is PR 2, which needs R0Y00's agreement on the outline in #3023.A load with any other use is not eligible. That covers a copy, a numeric read, an image field read, a read after a join with a path that skipped the load, a partial T#, or a mix with an
s_add_u32heap address. Such a program keeps exactly today's symbols, DXIL and refusal text (two-pass analysis).Design status, stated openly: the design went through four Elephant/Goldfish rounds with fresh critic and readiness reviewers, and they did not reach agreement. After the third revision the remaining points were decided by the author, documented point by point, and the design was frozen. A fresh precommit review then checked the code against it, and its findings (join loss, a
logic_errorinstead of a refusal) are fixed here. So this is not an independently approved design. Please review it with that in mind.Refs #3023, #3224. Prerequisites up: #3500, #3524, #3526, #3540.
Verification
Build on
2ff74a6a(Windows 11, NVIDIA GeForce RTX 3080).native_heap_token_texture_hardware(30 assertions):_warpexits 77 (no 32-lane waves).native_heap_token_texture_controls(DXIL validator):s_and_b32, image field read, join, join plus copy, numeric read after a join, partial T#, heap-address mix;native_compute_manifest_reasons(6 refusals, 1 publish) andstartup_compute_dispatch_texture_check.py(4 reader refusals).ctest -R "native_heap_token|native_compute_manifest|native_global_srv_heap|startup_compute|native_direct|native_sampler|native_compile_dxil|native_startup_request|startup_triage": 222 pass, 0 fail. Baseline 211, 0 fail.Revert (
src/back to2ff74a6a, the build succeeds): the new tests fail on assertions (tex2d: compiles,fixture mode tex2d exits 0). Before the join fix,join,join_copyandnumeric_joingave other refusal texts.native_compute_output_revisiongoes from 1 to 2. Three tests that hard-codednative 1now read the revision fromsrc/native_compute_output.h; their assertions are the same.Evidence and follow-up
All fixtures are source-built. No game data.
Local census on my 2,689 slot-67 compute requests (counts only,
compile_dxil --refusals), against the samemainwithout the change:direct resource-heap load requires the selected GPU slot and its view typegoes from 1332 to 1323;A3: the 828 manifests that existed before are byte-identical apart from the
nativerevision line. This was measured on the first revision; the review fixes only make more loads ineligible. Most token loads are not eligible yet. An earlier note here named image field reads as the main reason; that was wrong. A follow-up branch that makes field reads eligible moves 0 requests in the same census, so the remaining loads fail other eligibility rules, which I still have to break down.Not covered: the cache decode of the new kinds and of
heap_token_words(only throughprepare_direct_compute); gather4, sample_l, load_mip and resinfo at run time (compile only, validator passes); a null slot that every dimension may read (PR 2 must provide one).Checklist
docs/experiments/native-heap-token-textures.md)AI-assisted.
🤖 Generated with Claude Code