startup: a compute buffer load in gfx2hlsl ignores an edit to word 1–3 of its descriptor #2901

Closed
opened 2026-11-26 17:36:20 +00:00 by Not-Saii · 0 comments
Not-Saii commented 2026-11-26 17:36:20 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-26T17:36:20Z.


Summary

In tools/startup/gfx2hlsl.py, a compute buffer_load_dword … offen resolves its descriptor operand with Stage.descriptor, which reads only the symbol of the first register. If an earlier scalar instruction has replaced or edited word 1, 2 or 3 (for example NUM_RECORDS in word 2), the load still translates as a read of the unmodified buffer, and the edit is dropped. A buffer store through the same edited descriptor is refused (buffer store through a modified descriptor), so the two paths disagree.

This matters when the edit changes what the load returns. On RDNA 2, a raw buffer with NUM_RECORDS = 0 returns zeros for every offen load. The translation instead reads the bound buffer.

For in-place edits this is a known choice. The descriptor-data path in Stage.scalar says "Keep the resource identity for loads; stores refuse the unproved value". But that choice also covers a word replaced with a different value, and a size word set to 0.

Reproduction (upstream main b505c32b, source-built, no capture input)

Case A of tests/startup_gfx2hlsl_compute_check.py loads buffer_load_dword v5, v4, s[12:15], 0 offen and stores buffer_store_dword v5, v4, s[16:19], 0 offen, with both descriptors from one s_load_dwordx8. Splice each edit below just before the load (on s[12:15]), and the same edit just before the store (on s[16:19]), then translate. Run from the repository root:

import struct, sys
sys.path[:0] = ['tests', 'tools/startup']
import gfx2hlsl as G
import startup_gfx2hlsl_compute_check as C

def sop2(op, d, a, b): return struct.pack('<I', 0x80000000 | op << 23 | d << 16 | b << 8 | a)
def sop1(op, d, a): return struct.pack('<I', 0xbe800000 | d << 16 | op << 8 | a)

W = C.WORDS_A
SITES = {'load': (W.index(bytes.fromhex('001030e004050380')), 12), 'store': (C.STORE_A, 16)}
EDITS = {  # r = first register of the descriptor; word 2 is NUM_RECORDS
    'descnum copy w1': lambda r: sop2(0x20, 21, r + 2, 130) + sop1(0x03, r + 1, 21),
    'descnum copy w2': lambda r: sop2(0x20, 21, r + 2, 130) + sop1(0x03, r + 2, 21),
    'descnum copy w3': lambda r: sop2(0x20, 21, r + 2, 130) + sop1(0x03, r + 3, 21),
    'descnum alu w2': lambda r: sop2(0x20, 21, r + 2, 130) + sop2(0x20, r + 2, 21, 128),
    'in-place and 0 w2': lambda r: sop2(0x0e, r + 2, r + 2, 128),
    'constant 0 w2': lambda r: sop1(0x03, r + 2, 128),
}
hlsl = lambda code: G.ComputePipeline(code, C.root_blob(), C.CASES['A'][2], (2, 3, 4)).hlsl_cs()
for label, edit in EDITS.items():
    for where, (at, r) in SITES.items():
        try:
            hlsl(W[:at] + edit(r) + W[at:]); print(where, label, 'translated')
        except G.Unsupported as e:
            print(where, label, 'refused:', e)

Observed

Edit (shown on the load descriptor s[12:15]) Load Store (same edit on s[16:19])
s_lshr_b32 s21, s14, 2 / s_mov_b32 s13, s21 (word 1) translated refused: buffer store through a modified descriptor
s_lshr_b32 s21, s14, 2 / s_mov_b32 s14, s21 (word 2) translated refused: same
s_lshr_b32 s21, s14, 2 / s_mov_b32 s15, s21 (word 3) translated refused: same
s_lshr_b32 s21, s14, 2 / s_lshr_b32 s14, s21, 0 (word 2, ALU result) translated refused: same
s_and_b32 s14, s14, 0 (word 2 zeroed in place) translated refused: same
s_mov_b32 s14, 0 (word 2 set to 0) translated refused: same

For the five descriptor-derived edits, the translated HLSL is byte-identical to unedited case A. For s_mov_b32 s14, 0, the only difference is a dead s14 = 0x00000000u; assignment. In every case the load line is v5 = r0.Load(a + 0);, as in case A.

Expected

A buffer load whose descriptor has an edited or replaced word 1–3 should refuse, as the store does, unless the edit is one a proof accepts. Two examples:

  • The stride clear, which doesn't change offen addressing of a raw view.
  • A NUM_RECORDS change that the lowering honours with a bounds check, so out-of-range lanes read 0.

Scope and notes

  • Measured only for compute buffer_load_dword … offen with a descriptor loaded through a table pointer. I didn't check the idxen forms, s_buffer_load, the format loads, descriptors built from a pointer (first word ptr), or the vertex stage.
  • Found while scoping the s_cselect_b32 sX, 0, sX on descnum FIX on #2618. That change refuses its own select result in any descriptor word and doesn't fix this general gap.
  • Refs #2618, #2022.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6632087253 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2901). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-26T17:36:20Z. --- ## Summary In `tools/startup/gfx2hlsl.py`, a compute `buffer_load_dword … offen` resolves its descriptor operand with `Stage.descriptor`, which reads only the symbol of the first register. If an earlier scalar instruction has replaced or edited word 1, 2 or 3 (for example NUM_RECORDS in word 2), the load still translates as a read of the unmodified buffer, and the edit is dropped. A buffer store through the same edited descriptor is refused (`buffer store through a modified descriptor`), so the two paths disagree. This matters when the edit changes what the load returns. On RDNA 2, a raw buffer with NUM_RECORDS = 0 returns zeros for every offen load. The translation instead reads the bound buffer. For in-place edits this is a known choice. The descriptor-data path in `Stage.scalar` says "Keep the resource identity for loads; stores refuse the unproved value". But that choice also covers a word replaced with a different value, and a size word set to 0. ## Reproduction (upstream main b505c32b, source-built, no capture input) Case A of `tests/startup_gfx2hlsl_compute_check.py` loads `buffer_load_dword v5, v4, s[12:15], 0 offen` and stores `buffer_store_dword v5, v4, s[16:19], 0 offen`, with both descriptors from one `s_load_dwordx8`. Splice each edit below just before the load (on s[12:15]), and the same edit just before the store (on s[16:19]), then translate. Run from the repository root: ```python import struct, sys sys.path[:0] = ['tests', 'tools/startup'] import gfx2hlsl as G import startup_gfx2hlsl_compute_check as C def sop2(op, d, a, b): return struct.pack('<I', 0x80000000 | op << 23 | d << 16 | b << 8 | a) def sop1(op, d, a): return struct.pack('<I', 0xbe800000 | d << 16 | op << 8 | a) W = C.WORDS_A SITES = {'load': (W.index(bytes.fromhex('001030e004050380')), 12), 'store': (C.STORE_A, 16)} EDITS = { # r = first register of the descriptor; word 2 is NUM_RECORDS 'descnum copy w1': lambda r: sop2(0x20, 21, r + 2, 130) + sop1(0x03, r + 1, 21), 'descnum copy w2': lambda r: sop2(0x20, 21, r + 2, 130) + sop1(0x03, r + 2, 21), 'descnum copy w3': lambda r: sop2(0x20, 21, r + 2, 130) + sop1(0x03, r + 3, 21), 'descnum alu w2': lambda r: sop2(0x20, 21, r + 2, 130) + sop2(0x20, r + 2, 21, 128), 'in-place and 0 w2': lambda r: sop2(0x0e, r + 2, r + 2, 128), 'constant 0 w2': lambda r: sop1(0x03, r + 2, 128), } hlsl = lambda code: G.ComputePipeline(code, C.root_blob(), C.CASES['A'][2], (2, 3, 4)).hlsl_cs() for label, edit in EDITS.items(): for where, (at, r) in SITES.items(): try: hlsl(W[:at] + edit(r) + W[at:]); print(where, label, 'translated') except G.Unsupported as e: print(where, label, 'refused:', e) ``` ## Observed | Edit (shown on the load descriptor s[12:15]) | Load | Store (same edit on s[16:19]) | |---|---|---| | `s_lshr_b32 s21, s14, 2` / `s_mov_b32 s13, s21` (word 1) | translated | refused: buffer store through a modified descriptor | | `s_lshr_b32 s21, s14, 2` / `s_mov_b32 s14, s21` (word 2) | translated | refused: same | | `s_lshr_b32 s21, s14, 2` / `s_mov_b32 s15, s21` (word 3) | translated | refused: same | | `s_lshr_b32 s21, s14, 2` / `s_lshr_b32 s14, s21, 0` (word 2, ALU result) | translated | refused: same | | `s_and_b32 s14, s14, 0` (word 2 zeroed in place) | translated | refused: same | | `s_mov_b32 s14, 0` (word 2 set to 0) | translated | refused: same | For the five descriptor-derived edits, the translated HLSL is byte-identical to unedited case A. For `s_mov_b32 s14, 0`, the only difference is a dead `s14 = 0x00000000u;` assignment. In every case the load line is `v5 = r0.Load(a + 0);`, as in case A. ## Expected A buffer load whose descriptor has an edited or replaced word 1–3 should refuse, as the store does, unless the edit is one a proof accepts. Two examples: - The stride clear, which doesn't change offen addressing of a raw view. - A NUM_RECORDS change that the lowering honours with a bounds check, so out-of-range lanes read 0. ## Scope and notes - Measured only for compute `buffer_load_dword … offen` with a descriptor loaded through a table pointer. I didn't check the `idxen` forms, `s_buffer_load`, the format loads, descriptors built from a pointer (first word `ptr`), or the vertex stage. - Found while scoping the `s_cselect_b32 sX, 0, sX` on `descnum` FIX on #2618. That change refuses its own select result in any descriptor word and doesn't fix this general gap. - Refs #2618, #2022. AI-assisted (Claude Code).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#2901
No description provided.