Skip to content

help wanted: GPU translation, part 4 (compute shaders) #2022

Backlog

Description

@denn0x

Compute programs (gfx1013) that the startup compute translator still refuses. Each row is an independent piece of work for one pull request with a source-built or hand-assembled fixture. Counts are aggregate numbers from a private run (dispatches skipped per 300 frames of one scene / distinct programs); they only rank the items.

Items (pick one, say so in a comment)

Item What is refused today Weight Notes
A Formatted buffer load through a descriptor taken from a heap at run time (buffer_load_format_x and wider, indexed) about 104,000 / 204 The format, stride and size come from the descriptor words, which are only known at run time. Needs the descriptor words available to the shader (for example a side buffer of descriptor words per view) and a load that switches on the format field. The same gap exists for vertex and mesh stages. Related: #1542, #1143.
B Formatted buffer store through a heap descriptor (buffer_store_format_xyzw, d16 forms) about 7,200 / 7 Related: #1542.
C Scalar holding a descriptor word used numerically (v_writelane_b32, s_cselect_b32, s_cmp_eq_i32 on a descriptor word or descriptor count) about 16,000 / 72 The value tracker treats descriptor words as opaque. Needs a model of which fields may be read as numbers.
D v_bcnt_u32_b32 about 7,500 / 4 Population count plus addend.
E image_gather4_l about 7,200 / 3 Related: #1802 (gather needs view and mip state).
F s_ff1_i32_b32 / s_ff1_i32_b64 of a general scalar (not exec) about 4,100 / 12
G Smaller ALU and compare gaps: v_cmp_ne_i32 in some operand forms, s_bcnt1, v_mbcnt over a mask, a vcc_hi operand about 3,000 / 20 One pull request each is fine. Related: #1546.
H Image forms: cube images, image atomics (or, compare-swap), ds_append small Related: #1545, #1541.

What a pull request needs

  • One item per pull request.
  • A source-built or hand-assembled fixture (no bytes from any retail software) with buffer or image read-back and a negative control that fails when the lowering is disabled.
  • LLVM / Mesa semantics cited for each instruction.
  • Refuse precisely what the change does not cover. A wrong culling or argument-building pass hides every draw that depends on it, so a refusal that stays is better than a wrong translation.

Existing issues cover neighbouring areas and are not repeated here: #1541 (LDS and barriers), #1543 (DPP and cross-lane), #1544 (entry layout), #1545 (image stores and atomics), #1546 (lane-pattern masks), #1412 (running compute pipelines).

Other parts: #1996 (pixel shaders), #1998 (mesh shaders), #1999 (render state and indirect draws).

Activity

  1. SimSalabimse commented on Nov 24, 2026

    @SimSalabimse
    Contributor

    I'd like to take item F from this list: s_ff1_i32_b32 / s_ff1_i32_b64 of a general scalar (not exec) in the startup compute translator.

    • Scope: lower those bit-scan forms when the source is a tracked general scalar, with LLVM/Mesa cited semantics. Keep exec-only cases, untracked sources, and anything this slice does not cover refused.
    • Evidence: a source-built or hand-assembled fixture (no retail bytes) with a negative control that fails when the lowering is disabled. Python/LLVM 15 checks first; Windows ctest on WARP and an RTX 4070 Ti.

    AI-Assisted

  2. archielcqp-a11y commented on Nov 25, 2026

    @archielcqp-a11y
    Contributor

    I'd like to take item A, formatted buffer loads through a heap descriptor, in tools/compute_store_aot.py. Before writing code, here is the scope I propose. Please correct it if it is not the cut you want.

    There are two separate gaps. The compute profile resolves a descriptor only at a static table offset. Its formatted loads are gfx1030 only, with the format stated by the caller (--source-format). Item A needs both of these to become run-time values. I'd split them into two pull requests.

    Slice 1 (first PR): the format switch. This mirrors the store path from #1542 (--descriptor-format-constant, store_descriptor_format).

    • Forms: gfx1013 buffer_load_format_{x,xy,xyz,xyzw} and the d16_ forms, idxen only, through the existing static t0 source binding with its stated stride.

    • Format input: V# word 3 comes from a ready s_buffer_load constant word that the caller names, one per formatted load, in program order.

    • Decode: one HLSL load_descriptor_format(formatWord, addr, channels, d16) reads FORMAT (bits 18:12) and accepts the same fixed bits as the store path: the GFX10 identity 0x01000FAC and the legacy DFMT/NFMT identity 0x00000FAC. It handles the same format set as the stores:

      • 32-bit UINT and FLOAT, 1 to 4 channels;
      • 8_8_8_8_UNORM, 16_16_UNORM and 10_10_10_2_UNORM;
      • 16_16_FLOAT and 16_16_16_16_FLOAT;
      • 16-bit UNORM, SNORM, UINT, SINT and FLOAT.
    • Conversion:

      • UNORM is x / (2^n - 1);
      • SNORM is max(x / (2^(n-1) - 1), -1);
      • FLOAT16 is f16tof32;
      • 16-bit UINT and SINT are zero-extended and sign-extended;
      • d16 packs each result back to binary16, two per VGPR.

      I'll cite the RDNA 2 ISA (§8.1.4 and §8.1.8) and Mesa's ac_build_buffer_load_format / ac_nir lowering for each rule. The PR will name any rule I cannot tie to a source.

    • Open question, opcode wider than the format (for example xyzw on 32_FLOAT). D3D and Vulkan fill missing components with (0, 0, 0, 1). I have not found an RDNA statement of what the format unit returns. My proposal is that the slice handles only opcode widths no larger than the format, plus fixed bits and formats from the table. Anything else returns 0 in every component, and the docs list that zero result as a known gap, not as hardware behaviour. If you would rather have the (0, 0, 0, 1) fill with a citation, or the dispatch treated as invalid, I'll do that instead.

    • Fixture: source-built gfx1013 assembly in LLVM 15 spelling, with readback on WARP and hardware. It loads every format through each opcode width it accepts, with record bytes that put sign bits, tie values and denormal halves in each field.

      • Wrong references must fail on the GPU: a UNORM divisor off by one, SNORM without the clamp, an unsigned 16-bit SINT, the d16 halves swapped and a legacy format field misread.
      • Translation controls refuse gfx1030 with a constant format, a missing or unready format word, offen, a format word left unused, and the existing static-format flags combined with this one.
      • With the decode removed, the controls fail.

    Slice 2 (later PR, design only for now): the descriptor from the heap. The 204 programs take the descriptor itself from the heap at run time, so slice 1 alone unblocks none of them. Slice 2 needs:

    • a side buffer of guest V# words per heap view, filled by the runtime when it writes the view;
    • the desktop view through ResourceDescriptorHeap[index] (SM 6.6);
    • stride from word 1 and num_records from word 2, with out-of-range indices returning 0.

    This overlaps the dynamic heap indexing in #1143, so I'd coordinate with that work before starting, and keep slice 2 out of the first PR.

  3. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Picking up Item A (buffer_load_format from runtime heap descriptor in compute) with WARP readback tests.

  4. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    Two item A claims came in. Please split them along the existing proposal: @archielcqp-a11y can take the format decoder on one static t0 binding first, and @tedin7 can take the heap-descriptor retrieval and its bounds/lifetime controls, building on that decoder instead of duplicating it. Please confirm that split here. For the first slice, start with matching format/opcode widths and ordinary word results. An unsupported format or over-wide opcode must be refused or report a distinct invalid outcome before any valid-looking output is published. Zero data from a valid read needs to remain distinguishable. D16 can follow with integer versus float handling and a format-specific rounding or conversion control. Keep the existing static and gfx1030 paths as regressions. Neither slice alone should be counted as application coverage until it is used in a real dispatch.

  5. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Yielding Item A (slice 1) to @archielcqp-a11y who claimed it 3 minutes earlier — we have not opened a PR for it.

  6. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Confirmed on Item A split: we will wait for @archielcqp-a11y Slice 1 static format decoder before building Slice 2 (heap-descriptor retrieval + bounds/lifetime controls) on top of it. Meanwhile picking up Item G (compute ALU & compare gaps: v_cmp_ne_i32, s_bcnt1, v_mbcnt, vcc_hi) with WARP readback tests.

  7. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Also picking up Item C (scalar holding a descriptor word used numerically in compute_store_aot) as a separate PR with WARP readback tests.

  8. archielcqp-a11y commented on Nov 25, 2026

    @archielcqp-a11y
    Contributor

    Confirming the split, @R0Y00, and thanks @tedin7 for yielding. I keep the format decoder on one static t0 binding. tedin7 builds the heap-descriptor retrieval and its bounds and lifetime controls on top of it.

    Slice 1 is #2150. It is now updated to the rules above (95d75de):

    • Widths: only an opcode that reads exactly the format's channel count is valid.
    • Invalid loads: an unknown format, other fixed bits (including DST_SEL), or a narrower or wider opcode makes the load invalid. Every load is staged before the first store, and an invalid load returns before any store. So u0 stays unwritten, and a valid read of zero data stays distinguishable. Four GPU runs check this on WARP and an RTX 3080, with zero-fill and (0, 0, 0, 1)-fill references that must fail.
    • d16: not in this slice.
    • Existing paths: the gfx1030 caller-format path and the static raw reads are unchanged, and a control checks the gfx1030 one.
    • Coverage: the docs and the PR say this is not application coverage until the heap slice is used in a real dispatch.

    @tedin7, the decoder is load_descriptor_format(formatWord, addr, channels, out bool valid), from descriptor_load_hlsl() in tools/compute_store_aot.py. The heap slice can pass the view's word 3 where this slice passes the constant word.

  9. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    Item A slice 1 landed in #2150 (c118f56). The exact candidate passed Windows Release controls, WARP and RTX 4060 Laptop. Wrong format, mismatched opcode width and unsupported fixed bits leave the output sentinel untouched. A valid zero-valued load writes its result. @tedin7 can now build the agreed heap-descriptor lookup and range/lifetime controls on this static decoder. Tests and commands

  10. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    #2150 merged; starting Item A Slice 2: runtime heap-descriptor retrieval + bounds/lifetime controls for formatted buffer loads.

  11. 26 remaining items

  12. Ybucaille commented on Nov 26, 2026

    @Ybucaille
    Contributor

    Fresh compute refusal counts on main 0827f43c, and a claim: SGPR spills in compute

    One local 300 s run (Windows 11, RTX 2070, run.ps1 -Render -Translate -HostCpu -MemoryGiB 12, no crash, ExecuteIndirect calls all 0), then gfx2hlsl.py --pending over the cache. First refusal reason per slot-67 compute request, 2,575 requests:

    requests first refusal existing work
    400 v_readfirstlane_b32 requires a proven uniform source #2607 and the other readfirstlane proofs
    341 v_cmp_gt_i32_e64 in an execz block: vcc live at the join #2723
    333 s_andn2_b32 in an execz block: lane mask live at the join #2723
    158 s_load of a resource-heap record whose index is read from a buffer #2580
    85 LDS exchange needs a 1D group and a bounded allocation #1541 / #1566
    85 TG_SIZE_EN requires at most N threads per group #2432
    68 image_store dmask #2661
    68 v_writelane_b32 is lowered in pixel and mesh stages only none: #2712 covers wave64 and vertex stages
    59 (translated)
    50 LDS in straight-line code only
    50 s_mov_b32 in an execz block
    45 s_bfm_b64 #2007
    38 src_scc not proven #2577 merged since
    37 SCC from descriptor data
    35 image_store on a non-2D view

    These are first reasons only: a request refused here may hit others behind it.

    Claim: constant-lane SGPR spills (v_writelane_b32 / v_readlane_b32) in compute, stacked on @tedin7's #2712 (same spill_operands lines; I will build on it rather than conflict, and only after it settles). The 68 requests come from 68 distinct wave32 programs with branches and loops, constant lanes only. Accepting cs alone wins nothing, because every one of them spills a descriptor, a pointer or a lane mask, not a plain number. Measured on a scratch copy:

    • cs allowed: 65 then refused on "source holds lane mask or descriptor", 2 on a heap-record s_load, 1 on lane ≥ 32;
    • descriptors, pointers and lane masks also carried through the spill: 0 fully translated yet. 33 stop at "formatted buffer load requires descriptor words proven in the entry block" (the provenance is lost at the reload), and 32 at s_nand_b32 on a lane mask (shader: lower s_nor_b32 and s_nand_b32 on lane mask in gfx2hlsl (Part of #1723) #2030).

    Plan, one PR each: (1) cs spills of descriptor and pointer words, keeping the tracked symbol across the reload with the existing write-before-read proof, so that the reloaded descriptor still counts as proven for the formatted load; (2) lane-mask spills, the reload restoring the mask. Source-built gfx1013 fixtures with negative controls; WARP and RTX 2070 runs on my side.

    AI-assisted (Claude Code).

  13. Leyukaka commented on Nov 26, 2026

    @Leyukaka
    Collaborator

    Claiming a new compute item: image_store on SQ_RSRC_IMG_3D and SQ_RSRC_IMG_1D, translator plus runtime binding. Today tools/startup/gfx2hlsl.py refuses both with image_store on SQ_RSRC_IMG_3D|1D: only 2D images are lowered.

    Measured on a local capture (counts and instruction shape only):

    • Offline census at main b505c32: 29 requests stop at the 3D form and 7 at the 1D form.
    • One 600 s start-up run at main 6ee878d8, no inputs. Every graphics pipeline the runtime looked up was translated. Seven compute keys dispatch with no translation. The three most dispatched account for 18,172 of those 18,187 dispatches:
      • one 16,798 times, about once per presented frame;
      • two 687 times each.
    • Their first refusals are these two forms, each image_store v[8:11], <address>, s[..] dmask:0xf ... unorm. The address is v[2:4] for the 3D image and v0 for the 1D images. The 3D program's other image accesses are two image_load on 2D images; the 1D programs have none.
    • In an earlier run at b505c32, the 3D refusal was hit 16 times over 15 requests: 13 with dmask:0xf (7 tuple address, 6 NSA), 3 with partial dmasks (2 of them d16). Partial dmasks stay refused here.

    Plan, translator:

    • Lower image_store with dmask:0xf on a 3D image to RWTexture3D<float4> with a 3-component address, and on a 1D image to RWTexture1D<float4> with one component.
    • Reuse the 2D compute path (op_image_store: format, unorm, address tuple or NSA form, fixed-table descriptor), add the two kinds to the UAV declarations, and emit uav N tex3d|tex1d ... in the manifest.
    • Partial dmasks stay refused, including the two d16 forms seen.

    Plan, runtime:

    • Parse uav N tex3d|tex1d in src/startup_stubs/d3d12_compute_dispatch.inl. The slot needs a dimension kind, not only the array flag.
    • Bind D3D12_UAV_DIMENSION_TEXTURE3D / TEXTURE1D next to the 2D and 2D-array branches, checking the resource dimension, the mip and, for 3D, the W range.

    Tests:

    • refusal controls for the kept refusals;
    • translator checks of the emitted HLSL and manifest lines;
    • a source-built dispatch that stores to a 3D and a 1D image, read back on WARP and hardware against a CPU reference;
    • mutants that drop the third address component or map 1D to 2D, which must fail.

    Prior art in the offline tool tools/compute_store_aot.py: 3D stores (#1649) and the 1D slice claimed in #1545. tests/compute_check.cpp already reads back 1D and 3D UAVs. I will reuse that readback.

    @NiiRoZz, binding tex3d and tex1d UAVs is part of your "Texture UAVs" item in #2274 (uav N tex1d|tex2d|tex2da|tex3d). The 2D and 2D-array views are on main through #2532, and I found no PR, commit or comment on tex3d/tex1d. I am taking over that part since there has been no activity on it for 2 h; I will hand it back if you resume.

    AI-assisted.

  14. Leyukaka commented on Nov 26, 2026

    @Leyukaka
    Collaborator

    Claiming a new item for tools/startup/gfx2hlsl.py: v_pk_max_f16 and v_pk_min_f16, which have no handler today. They are refused by name.

    Measured on a local capture (counts and instruction shape only):

    • Offline census at main 6ee878d8 plus startup: lower compute image_store to 1D and 3D texture UAVs (Part of #2022) #2902: 4 requests stop at v_pk_max_f16 and 2 at v_pk_min_f16.
    • 600 s start-up run: two compute pipelines that the title dispatched 5,363 times stop at v_pk_max_f16. The run reports them as untranslated, and the offline translator names the instruction.
    • Each refused form has exactly one non-VGPR source:
      • v_pk_max_f16 vN, vN, 0 op_sel_hi:[..];
      • v_pk_max_f16 vN, <literal>, vN;
      • v_pk_max_f16 vN, vN, sN;
      • v_pk_min_f16 vN, <literal>, vN.

    Plan:

    • Handlers: add both through the existing packed_half helper, per lane, with the min/max rule tools/pixel_aot.py already uses (minmax16_num, added to the gfx2hlsl preamble): one NaN returns the other operand, and mixed zeros give -0 for min and +0 for max. NaN is tested on the binary16 encoding, not with a float isnan().

    • Sources: accept the kinds the real forms use, with the packed-source rule that pixel_aot.py implements in vop3p_f16_word:

      • an integer inline 0;
      • a hex literal as a full 32-bit word;
      • a numeric SGPR as a full word.

      Sources are whitelisted (single VGPR, sN, 0x…, 0) before they are read. op_sel picks the low or high half for the low result, and op_sel_hi for the high result.

    • What is new ground: pixel_aot's draw fixture covers a literal only with default selectors and SGPRs only on add and fma. A non-default selector on a literal or SGPR is not yet covered, and the tests below cover it. The PR also updates the packed_half docstring, which today calls these sources unproven.

    • Kept refused:

      • nonzero inline integers;
      • inline floats;
      • neg_lo/neg_hi/clamp;
      • any source the translator cannot read as a whole word.

      The existing non-VGPR refusal stays for v_pk_add/mul/fma_f16.

    • Tests:

      • translator checks for each accepted source kind with both selector values, and refusal controls for the kept refusals;
      • a source-built draw or dispatch read back on WARP and hardware against a CPU reference. It covers both zero orders, a single NaN, both operands NaN (or that case stated as untested), and a selector flip on a literal and on an SGPR.
      • mutants: one that swaps the op_sel/op_sel_hi roles, and one that uses max for min. Both must change the result.

    AI-assisted.

  15. Leyukaka commented on Nov 26, 2026

    @Leyukaka
    Collaborator

    Follow-up claim to #2927: let v_pk_add_f16, v_pk_mul_f16 and v_pk_fma_f16 take the same non-VGPR sources that #2927 accepts for min and max:

    • a numeric SGPR;
    • a hex literal of up to 8 digits, read as a full 32-bit word, so a short literal has a zero high half;
    • the inline 0.

    The half that op_sel / op_sel_hi selects follows the vop3p_f16_word rule in tools/pixel_aot.py.

    Measured on a local capture (counts and instruction shape only):

    Plan:

    • Gate the new sources on the same whitelist and lane-mask refusal as startup: lower v_pk_max_f16 and v_pk_min_f16 in gfx2hlsl (Part of #2022) #2927. The arithmetic itself is unchanged: f16tof32 of the selected half, f16rn of the result.
    • Keep refused:
      • inline floats (1 census request on v_pk_fma_f16);
      • nonzero inline integers;
      • neg_lo/neg_hi (3 census requests on v_pk_add_f16, a separate item);
      • clamp and other modifiers.
    • Stacked on startup: lower v_pk_max_f16 and v_pk_min_f16 in gfx2hlsl (Part of #2022) #2927.
    • Tests:
      • translator checks for each source kind with both selector values;
      • a draw read back on WARP and hardware against a CPU reference, with a literal and an SGPR source under default and flipped selectors for each of add, mul and fma;
      • a mutant that swaps the selector roles.

    AI-assisted.

  16. SimSalabimse commented on Nov 27, 2026

    @SimSalabimse
    Contributor

    I'm taking the remaining pixel-stage case where a heap image descriptor word is read as a number. #2161 already covers compute raw num_records, and this is the image-word slice that's still refused. I'll add a source-built fixture in tools/startup/gfx2hlsl.py, keep every other descriptor word refused, and open a PR against main.

    AI-Assisted

  17. Leyukaka commented on Nov 29, 2026

    @Leyukaka
    Collaborator

    Releasing my claim of 2026-11-26 on SGPR, hex and inline 0 sources for v_pk_add_f16, v_pk_mul_f16 and v_pk_fma_f16; draft #2930 is closed.

  18. Leyukaka commented on Nov 29, 2026

    @Leyukaka
    Collaborator

    Taking back one part of the claim I released above: v_pk_mul_f16 with a 32-bit literal source in tools/startup/gfx2hlsl.py.

    • Today packed_half refuses it with operand ... is not a single VGPR (tools/startup/gfx2hlsl.py:10116-10117 on main 26df1826). The native compute frontend already accepts a literal there (src/gfx1013_direct_compute.inl:1684-1691).
    • One long local run of the application, with only the Python path active: one compute program with this source accounted for about 847,000 dispatches, none translated.
    • Scope: the source operand only, 32-bit literal, with the existing half selection and rounding; SGPR and inline 0 sources, v_pk_add_f16 and v_pk_fma_f16 stay refused, with controls. One small PR, referencing startup: accept SGPR, hex and inline 0 sources in packed f16 add, mul and fma #2930.

    I'm working on this.

  19. added
    priority: P0
    on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: P0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions