Repository navigation
Description
Problem
Part of #2274 (section A, the v_readfirstlane proof item). Refs #1723.
In one local run of the compute path, v_readfirstlane_b32 requires a proven uniform source was the first translator refusal of 19 compute programs, 938,948 dispatches. The source of the read was classified for each of them (counts only; not reproducible from the repository):
| Source of the refused read | Programs | Dispatches |
|---|---|---|
| Per-lane resource index in a "waterfall" loop | 10 | 613,550 |
Uniform scalar chain through v_log_f32 / v_ceil_f32 |
1 | 262,757 |
image_load at uniform coordinates through a uniform descriptor |
5 | 53,709 |
Thread-id bits rearranged (v_and_or, v_bfe) before the shift |
2 | 8,926 |
| Scalar float conversion past a join | 1 | 6 |
The largest group is not a uniform source at all, so no extension of the uniformity proof (#2198, #2446, #2454, #2607, #2455) covers it. It is the loop a compiler emits for a non-uniform resource index:
head:
v_readfirstlane_b32 sI, vI ; index of the first active lane
v_cmpx_eq_i32 sI, vI ; exec = the lanes with that same index
s_add_u32 sA, sHeap, sI ; record address, low word
s_add_u32 sB, 0, src_scc ; carry into the high word
s_load_dwordx4 s[D:D+3], s[A:B], 0
... ; descriptor fix-up, buffer loads through s[D:D+3]
s_andn2_wrexec_b32 sK, sK ; exec = lanes not served yet; sK keeps them
s_cbranch_scc1 head
vI is a per-lane word read from a buffer and shifted left by 5 (a heap record index). sK is a copy of exec made just before the loop. Each pass serves the lanes that share one index.
Proposal
Lower this loop in the one-lane model as a single pass for the lane's own index. In the wave, a lane is active in exactly one pass, the one where sI equals its own vI, and in that pass every scalar the body derives from sI is the value for that lane. So the model can run the body once with sI set to its own lane's vI, provided the shape is proven. Three separate pieces, each claimable on its own:
- T1: the loop shape and its proof. Accept
v_readfirstlane sI, vIat a loop head only when: the next instruction isv_cmpx_eq_i32 sI, vI; the loop is closed bys_andn2_wrexec_b32 sK, sKthens_cbranch_scc1to the head;sKis a copy of exec made before the loop with no write between; the body is straight-line with no store, no LDS write and no loop-carried scalar; every scalar the body writes is dead at the loop exit;sIis not read before the compare. Anything else keeps a named refusal. Hand-assembled fixture with two lanes on different indices and two on the same one, plus near-misses (a store in the body, a scalar live at the exit,sKwritten in between). - T2: the carry of the 64-bit record address.
s_add_u32 sB, 0, src_sccafters_add_u32 sA, sHeap, sIis refused today assrc_scc with unverified SCCin 8 of the 10 programs once T1 is forced. Check whether startup: keep src_scc proven at a branch target one uniform SCC write reaches #2577 already covers a carry from the instruction directly before it; if not, extend it for that adjacent form only. - T3: a per-lane heap record index. The record loaded by
s_load_dwordx4is selected by a per-lane value, which in HLSL is a non-uniform resource index. startup: bind a compute heap record whose index is read from a table buffer #2580 covers an index read from a table buffer at a dispatch-constant position; this needs the per-lane form (2 of the 10 programs stop on the heaps_loadoffset refusal once T1 is forced). Runtime side: the bound heap range must cover every index a lane can produce, or the Dispatch is refused.
The smaller groups, for whoever wants them:
- T4:
v_log_f32andv_ceil_f32of a uniform operand are uniform (same argument asv_med3_f32in startup: prove v_med3_f32 results uniform for v_readfirstlane_b32 #2198). A local change with accepted and refused cases exists; the one program it lets through then stops atbuffer store through a modified descriptor, so it translates nothing on its own. - T5:
image_loadat uniform coordinates through a uniform descriptor: needs a proof that the image is not written in the dispatch. - T6: startup: prove uniform shifts of masked and extracted thread IDs #2769 proves the bounded local-X shift after literal-mask v_and_or_b32 or literal v_bfe_u32. Its fixtures cover surviving thread-ID bits and missing group bounds, with WARP, Intel UHD 770 and RTX readback. Waterfall and per-lane resource binding remain open.
Alternatives
- Treat the read as uniform: unsound, the index differs per lane by construction.
- Translate the loop literally with wave intrinsics (
WaveReadLaneFirst, a mask loop): possible, but it leaves the one-lane model for the whole program, and bvh_wave64_warp: WARP 1.0.22 misroutes non-uniform WaveReadLaneAt reads across lane blocks at forced widths above 8 #145 records a WARP defect on non-uniform lane reads.
Verification
- T1: the fixture's output words match values computed independently per lane; each near-miss is refused with its own reason; with the change reverted the accepted case is refused with today's reason.
- T2, T3: same pattern, one accepted form and one near-miss each; T3 additionally with a D3D12 read-back on WARP and hardware once the runtime binds the range.
- Measured so far: only the classification above, in one local run. That the 10 programs translate after T1 to T3 is a hypothesis; a probe that forces T1 shows T2 and T3 as the next refusals, and nothing beyond that was observed.
Checklist
- I checked for an existing issue or pull request for this change.
- I did not include game files, dumps, distribution links or credentials.
🤖 Generated with Claude Code
Activity
RavenCurseBurg commentedon Nov 26, 2026
I’ll check T2 against current main, #1821 and the exact #2577 head. I’ll use a synthetic adjacent low-word add and high-word carry, exercise both carry values, and check an intervening SCC writer separately. I’ll post the first translation result or refusal for each revision so T1 and T3 can use a concrete dependency. This claim covers the T2 verification.
RavenCurseBurg commentedon Nov 26, 2026
T2 is still needed for the adjacent pair. I fed synthetic SOP2 words through
gfx2hlsl.ComputePipeline(...).hlsl_cs()(one-thread group) on three independent checkouts. The decoded pair wass_add_u32 s20, s4, s5followed immediately bys_add_u32 s21, 0, src_scc.8972929coperand 'src_scc'e09daaa0src_scc with unverified SCC1530d637I also used literal low adds to distinguish the boundaries:
0xfffffffe + 1should give low0xffffffff, high 0, and0xffffffff + 1should give low 0, high 1. Both had the same refusal on each revision. Replacing the high input with an ordinary inline integer translated on all three. On both PR heads an intervenings_cmp_eq_u32made the high add read the compare's SCC; an intervenings_sub_u32kept the refusal. This locates the missing behavior at the low add's carry production. #2577's branch-target rule does not supply that carry.For reproduction, the register-input pair and terminator are the little-endian bytes
04 05 14 80 80 fd 15 80 00 00 81 bf. I’ll work on the adjacent compute address-pair case with independent low/high readbacks and intervening-writer controls. The waterfall selection and the resource lookup remain tracked under T1 and T3.RavenCurseBurg commentedon Nov 26, 2026
With T2 merged in #2658, I’ll take the source-built fixture and independent per-lane reference for T1. I’ll assemble the
readfirstlane / cmpx / andn2_wrexec / cbranch_scc1loop with LLVM 15, compare a wave-mask interpreter against the per-lane result for repeated and different indices, and record current main’s first refusal. I’ll also check the body’s access to the active mask and scalar state at exit. This fixture work can proceed independently of T3’s heap binding.The host reference and active-mask counterexample are ready. I’m following through on the bounded numeric and fixed raw-buffer body in
gfx2hlsl.Stagewith the existing compute readfirstlane test entry points. I’ll exercise partial incoming EXEC, scalar liveness on exit paths and the first wrong readback word before proposing it upstream. T3’s resource selection and runtime bounds remain available as separate work.The T1 change and its three-adapter readbacks are in #2694. I’ll take the independent bounded-resource reference for T3. My 120-byte source-built program uses a four-record heap, masks each key with 3, then loads the record at
key << 5through the resource-heap pointer. The uniform control publishessrv 0 buf heap rootconst 0 2. The varying case reaches T1’s bound-range refusal. I’ll check it against four distinct D3D12 buffers and an independently written CPU reference, including a shader that always uses the first lane’s key. The runtime binding implementation is still available.RavenCurseBurg commentedon Nov 26, 2026
I assembled a numeric T1 control and four near-misses as gfx1013 wave32 code with LLVM 15.0.7. On
f06646ba, all five reachv_readfirstlane_b32 requires a proven uniform sourcethroughComputePipeline(four threads, one group). The positive control is 84 bytes, SHA-256 prefixadc9be2b068f. Its input and output are raw buffers, so this exercises T1 independently of the T3 binding.After loading each lane’s key into
v5, with lane number inv0, the positive part is:A host-side wave-mask interpreter stepped the decoded loop. With keys
[64, 32, 64, 96], it served masks0x5, 0x2, 0x8and produced words[81, 48, 83, 114]. I checked all 81 four-lane tuples drawn from{0, 32, 0xffffffe0}against all 15 nonempty incoming masks. All 1,215 outputs and untouched inactive lanes agreed with(key + 17) XOR lanein uint32 arithmetic.There is another near-miss worth keeping in the proof. Replacing the two arithmetic instructions with just
v_mbcnt_lo_u32_b32 v7, exec_lo, 0makes the body depend on which other lanes share the index. The example then writes[0, 0, 1, 0]. An independent singleton execution would give[0, 0, 0, 0]. The two disagree in 495 of the 1,215 configurations. The currentv_mbcnthandler already requires a known mask. The T1 lowering should preserve that refusal and keep the grouped EXEC unavailable to instructions that use it as data. I also assembled the three specified near-misses (store inside the body,s23read after the exit, saveds21overwritten before the head). These are host-model results. The accepted translation and GPU readback remain to be demonstrated.R0Y00 commentedon Nov 26, 2026
The numeric and fixed-raw-buffer part of T1 landed in #2694 (d382863). I independently ran the host controls and Windows draws on WARP and RTX 4060 Laptop. Repeated and distinct keys, partial incoming masks, and the fixed-buffer loads matched. The wrong-reference controls produced the expected mismatches. Per-lane descriptor selection and mask-observing bodies are still outside this proof.
RavenCurseBurg commentedon Nov 26, 2026
I ran the bounded four-record reference with four physically separate D3D12 buffers on Intel UHD 770, RTX 4060 and WARP. The synthesized guest assembly, HLSL and C++ runner are available for the T3 implementation.
The 120-byte gfx1013 program reads the key from the input buffer, masks it with 3, and loads the 32-byte heap record at
key << 5through the resource-heap pointer. The T1 translator in #2694 refuses this at its bound-range guard. The 68-byte root-constant control publishessrv 0 buf heap rootconst 0 2anduav 0 table 1 16. LLVM 15.0.7 assembled both. Their binary SHA-256 prefixes aref32e1bfb3fc72454and25e2a001e9bb7f4c.The desktop reference binds one keys buffer and four SRVs. Each record stores
1000*(record+1)+17*lane. Five key tuples (forward, reversed, repeated, masked high bits and uniform) crossed with zero through four active lanes give 25 cases. The CPU independently checks all 320 words, including the inactive value 13 and 316 trailing sentinels.DXC emits
nonUniformIndex=truefor the marked dynamic handle andfalsewhen the intrinsic is removed. The fourth row is a device observation; the differing-key fixture still needs an explicit non-uniform resource index. This directly checks the desktop numeric reference. Guest heap range validation, resolving the four guest records, and actual guest-to-desktop binding in the runtime remain open.Windows 11 26100.9711, Intel
8086:a780(32.0.101.5973), NVIDIA10de:2882(32.0.15.9579), in-box WARP1414:008c(10.0.26100.9711), DXC 1.9.2609.5,cs_6_0, debug layer not enabled. The four public HLSL builds produced byte-identical DXIL to the programs used for the readbacks. Build the runner with the repository'stests/desktop_gpu.cpp,-Itests, D3D12 and DXGI; compilebounded.hlslasreference.cso,static-switch.cso(-DSTATIC_SWITCH),first-active.cso(-DFIRST_ACTIVE) andno-marker.cso(-DNO_MARKER). Run e.g.probe.exe Intel referencein the shader directory. Each invocation saves its hardware ID and result counts in a .receipt file.AI-assisted (Codex, GPT-6.2 Astra xhigh).
R0Y00 commentedon Nov 26, 2026
Please keep the four-record oracle from the linked commit for T3. The 12/25 first-active mismatches distinguish lane-local selection from a wave-uniform shortcut. For the integrated runtime fixture, add one short-range control that omits the highest record and refuses before dispatch. Keep the independent DXIL handle check as well: on these three adapters dropping NonUniformResourceIndex did not change the bytes, so that mutation needs the nonUniformIndex metadata assertion.
triggered02 commentedon Nov 26, 2026
Measured census data for this task list, from a diagnostic run of a source-built v_sad_hi_u8/v_msad_u8-era
main(fd033046) with the shader translator writing per-request status lines. Counts only; no game data, paths or shader text are included.Total requests seen: 3,162 — 51
ok, 3,111unsupported(2,683 of those are a cache-key mismatch, see below, so the shader-code refusals are ~428).The
readfirstlanefamily, exactly as this issue describes it:v_readfirstlane_b32 requires a proven uniform sourcecompute readfirstlane waterfall: body instruction s_bfe_u32 is not proven lane-localSo the waterfall shape (
compute: lower the readfirstlane waterfall loop of a per-lane resource index) is real at this census scale: 29 programs hit it as the primary refusal after a waterfall was detected, and 76 more are refused before that because the source was not proven uniform. Both are in the compute path.What would let me take a slice: the waterfall recognizer currently rejects a body whose
s_bfe_u32is not proven lane-local. If the intended scope is to admits_bfe_u32when its operands come from the lane-local saved masks (the same masks the loop already replays), that is a narrow addition with a synthetic fixture; if the scope is broader (any lane-local ALU in the body), it needs the lane-locality proof written down first. Say which, and I will build the fixture for it.AI-assisted; counts from the run's translate log.
RavenCurseBurg commentedon Nov 26, 2026
I will take T6 for the two integer forms named here, v_and_or_b32 and v_bfe_u32 before a logical shift of a thread ID. I will check when the group bounds remove every varying bit, include nearby nonuniform refusal cases and run source-built fixtures on Intel UHD 770, RTX 4060 and WARP. This work starts from e3cf6a9 and is separate from the waterfall and generic wave-intrinsic changes.
AI-assisted with Codex.
stan495 commentedon Nov 26, 2026
Claiming T4 (
v_log_f32andv_ceil_f32of a uniform operand inUNIFORM_VALU) from the proposal.Plan:
v_log_f32andv_ceil_f32toUNIFORM_VALUintools/startup/gfx2hlsl.py(with existingVEC_Fmodifier checks and non-uniform source refusals intact).tests/startup_gfx2hlsl_readfirstlane_uniform_check.py(including source-modifier and non-uniform source controls) and add a source-built GPU dispatch readback check on WARP andAMD Radeon RX 7900 XTX(32.0.32029.2010) intests/startup_compute_readfirstlane_check.py.AI-assisted; I review and run all checks locally.
shader: prove v_log_f32 and v_ceil_f32 results uniform for v_readfirs…
R0D4X commentedon Nov 26, 2026
Claiming T5 (image_load at uniform coordinates through a uniform descriptor, proven unwritten in the dispatch).
Plan:
AI-assisted; source-built fixtures only.
stan495 commentedon Nov 26, 2026
Claiming T5 (
image_loadat uniform coordinates through a uniform descriptor, proven read-only in the dispatch).Plan:
tools/startup/gfx2hlsl.py, extend the compute uniform-load proof (UNIFORM_LOADS/loads_after_exec_write/uniform_load_temps) toimage_load(kind == 'cs',exec_known, valid fixed unmodified table image descriptor with all 8 words intact and not inpipe.modified/other_modified/stored_images(), noimage_store/image_atomicin the dispatch, supported modifiers/dimensions withoutd16, and all coordinate VGPRsuniform_source).image_storein the dispatch, graphics stage, narrowed/loopEXEC, post-load join, and disabling theimage_loadproof).dxc+offscreen_check) with negative controls and verify readback on WARP and AMD Radeon RX 7900 XTX.shader: prove uniform compute image_load results uniform for v_readfi…
stan495 commentedon Nov 26, 2026
Claiming T3 (per-lane resource heap record index inside a compute
v_readfirstlane_b32waterfall loop).Plan:
tools/startup/gfx2hlsl.py: compute sound per-lane VGPR index upper bounds in CFG (v_and_b32,v_min_u32,v_bfe_u32,v_lshlrev_b32 ..., 5), allow a boundedresheaprecord load (s_lshl_b32 ..., 5+s_load_dwordx4 s[...], s[heap:0], offsetas well as the adjacent 64-bits_add_u32+s_add_u32 ..., 0, src_scc/s_addc_u32pointer-add form) inside proven compute waterfall loops, emitByteAddressBuffer rh[N] : register(t0, space2);withrh[NonUniformResourceIndex(...)], and publishresheap <N> 2in the compute manifest while keeping unbounded / non-heap / store / modified-descriptor forms refused.src/startup_stubs/translated_sampler_bindings.h&src/startup_stubs/d3d12_compute_dispatch.inl: parseresheap <N> 2intocreate_translated_root(t0..t{N-1}, space2) and verify every record0..N-1inpass.title_view_heap(resizing the dispatch view array cleanly and refusing beforeDispatchwhen the bound heap range omits any reachable record or holds an invalid descriptor).12/25first-active mismatches), add independent DXCcs_6_0DXILnonUniformIndexmetadata checks (NonUniformResourceIndexpresent vs omitted), translator/CFG negative controls, and an end-to-end stand-inDispatchfixture including the short-range negative control omitting the highest record onWARPandAMD Radeon RX 7900 XTX(with D3D12 debug layer enabled).Not-Saii commentedon Nov 26, 2026
Census of the
v_readfirstlane_b32 requires a proven uniform sourcerefusals on currentmain(5a41adba), from one local set of slot 67 compute requests re-keyed to this revision. Counts only; the inputs are private and not attached.511 of 2,689 compute requests stop first at this refusal. I classified each one by the last instruction that writes the source VGPR before the read:
v_add_nc_u32 vN, vN, vNafterbuffer_load_dwordandv_and_b32(record word masked to 24 bits, plus a small per-lane term)v_mov_b32 vN, -1in one arm of an exec-masked if/else, where the other arm writes the same masked record wordbuffer_load_format_x(idxen)v_cvt_u32_f32/v_cvt_i32_f32image_load(T5 shape, #2842 / #2866)The first two rows are one source construct, 419 requests (82%):
0xffffff,-1on the other arm.After the arms rejoin and exec is restored, the program runs:
There is no
v_cmpx_eq/s_andn2_wrexecloop after the read, so this is not the T1/T3 waterfall. The compiler takes the first active lane's value as the index into 116-byte constant-buffer records. Nothing in the program makes that value uniform: it comes from per-lane loads, and one arm substitutes-1. I expect it is uniform in the data the title actually supplies, not provably so.So no extension of the uniformity proof covers this group. The options I see, none of them a small slice:
WaveReadLaneFirstin a wave-level lowering for this one shape. This leaves the one-lane model, the desktop wave is not the guest wave, and bvh_wave64_warp: WARP 1.0.22 misroutes non-uniform WaveReadLaneAt reads across lane blocks at forced widths above 8 #145 records a WARP defect on non-uniform lane reads.readfirstlane of a per-lane record word used as a constant-buffer index, so the census separates it from the proof gaps.Which of these, if any, is in scope? Option 3 is a small diagnostic change I can take on its own.
AI-assisted (Claude Code).
shader: lower bounded per-lane heap record indices in compute waterfa…
Not-Saii commentedon Dec 1, 2026
#3692 extends the uniform-load proof behind
v_readfirstlane_b32 requires a proven uniform source.What it changes: a uniform compute buffer load past the entry block is now also recomputed when EXEC is narrowed but proven nonempty on every path. That covers the fallthrough of
s_cbranch_execz, the taken edge ofs_cbranch_execnz, and the entry mask carried around a narrowing. Under a narrowed EXEC the address VGPR still needs its recomputable expression. The PR has accepted cases, refusal controls (including a lane-varying address) and a control with the proof disabled.What it leaves alone: the per-lane record word read as a constant-buffer index, described in the census comment above, is not uniform and stays refused. It is still most of this refusal.
Local census (counts only):
The replay of the 223 already-translated requests showed unchanged results and manifests. Not measured: a GPU readback of the new path.
AI-assisted (Claude Code).
shader: recompute uniform compute loads under a proven nonempty EXEC
SimSalabimse commentedon Dec 1, 2026
I'll take the leftover first-refusal group on #2644: a lone
v_readfirstlane_b32of a per-lane record word, thens_and_b32/s_mulk_i32/s_buffer_load_dword*through a bound buffer, with nov_cmpx_eq/s_andn2_wrexecloop. On the console every active lane gets the first active guest lane's index and loads that one record, so I'll lower it as that exact broadcast (WaveReadLaneAtof the VGPR atfirstbitlowof guest EXEC, including the wave64 half exchange where needed). After the broadcast the key is wave-uniform. If the host wave cannot be proven to match the guest wave, or the offset, descriptor or uses cannot be proven, it stays refused with a named reason — not a per-lane approximation. Source-built fixtures only, including two lanes on different indices (both must see the first active lane's record), a case where the first lane is inactive in EXEC, and those refusals.AI-Assisted