cpp-migration: accept byte-window buffer descriptors for stores in the direct C++ compute path #2965

Closed
opened 2026-11-26 23:57:01 +00:00 by Leyukaka · 1 comment
Leyukaka commented 2026-11-26 23:57:01 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T23:57:01Z.


Target branch cpp-migration. Part of #2935 (instruction coverage). I am taking this; please say if you already have it locally and I will drop it.

Gap: a common idiom turns a loaded structured-buffer descriptor into a raw byte window before a buffer store:

s_load_dwordx4 s[8:11], ...
s_bfe_u32      s18, s9, 0xe0010       ; stride from word 1
s_max_u32      s18, s18, 1            ; at least 1
s_and_b32      s9,  s9,  0xc000ffff   ; stride := 0
s_mul_i32      s10, s10, s18          ; NUM_RECORDS := records * stride (bytes)
s_or_b32       s11, s11, 0x30000000   ; OOB_SELECT := 3 (raw)
buffer_store_dwordx4 v[0:3], off, s[8:11], 0

The direct compute analysis already recognises these word edits (zero_stride_word, byte_count, byte_oob in gfx1013_compute_native.cpp). Two things keep the store from using them:

  • A buffer store binds raw_buffer_uav, which expects four unmodified descriptor words. It is refused with "non-contiguous resource descriptor". Only loads relax that check, through byte_window_srv.
  • byte_oob requires word 3 to be cleared with 0xcfffffff before the OR. tools/startup/gfx2hlsl.py also accepts the OR on a plain loaded word, since OR-ing 0x30000000 sets OOB_SELECT (DW3[29:28]) to 3 whatever it held and touches no other bit.

Measured on a local capture of 2,689 compute requests (counts and instruction shape only), with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests built from cpp-migration f934df52.

  • 119 requests stop first at "non-contiguous resource descriptor" on a buffer_store_dword{,x2,x3,x4}.
  • 113 of them have exactly the sequence above, with the stride clamped by s_max_u32 ..., 1.
  • The other 6 multiply by a value from v_readfirstlane_b32 or an s_cselect_b32 chain, and are out of scope.

Plan:

  • For a buffer store, accept the byte-window form of the descriptor (words 1-3 as above) and bind it as the raw UAV of the unmodified descriptor, as gfx2hlsl.py does. This reuses raw_buffer_uav with the relaxed word check, so the manifest and runtime are unchanged.
  • Accept the OR on a plain loaded word 3, in addition to the cleared form. Keep the stride proof: the s_mul_i32 operand must be the clamped stride of the same descriptor's word 1.
  • Out-of-range behaviour is that of the bound raw view: D3D12 drops writes past it. Sizing the view to the converted byte count is runtime work and not in scope, as docs/experiments.md already notes for the Python path. With a guest stride of 0, the guest byte count is 0 while the host view still accepts writes, which is the same view-sizing limit.
  • Other descriptor edits stay refused.

Tests: a hardware readback through native_store_replay.

  • Stores of 1 to 4 dwords through the patched descriptor, fully inside the bound view.
  • Controls that stay refused:
    • the s_mul_i32 operand is not the clamped stride;
    • a word from a different descriptor;
    • an s_or_b32 with a constant other than 0x30000000.
  • Mutants: dropping the stride proof, and accepting a foreign descriptor's word, must each fail a control.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6637109218 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2965). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T23:57:01Z. --- Target branch `cpp-migration`. Part of #2935 (instruction coverage). I am taking this; please say if you already have it locally and I will drop it. **Gap:** a common idiom turns a loaded structured-buffer descriptor into a raw byte window before a buffer store: ``` s_load_dwordx4 s[8:11], ... s_bfe_u32 s18, s9, 0xe0010 ; stride from word 1 s_max_u32 s18, s18, 1 ; at least 1 s_and_b32 s9, s9, 0xc000ffff ; stride := 0 s_mul_i32 s10, s10, s18 ; NUM_RECORDS := records * stride (bytes) s_or_b32 s11, s11, 0x30000000 ; OOB_SELECT := 3 (raw) buffer_store_dwordx4 v[0:3], off, s[8:11], 0 ``` The direct compute analysis already recognises these word edits (`zero_stride_word`, `byte_count`, `byte_oob` in `gfx1013_compute_native.cpp`). Two things keep the store from using them: - A buffer store binds `raw_buffer_uav`, which expects four unmodified descriptor words. It is refused with "non-contiguous resource descriptor". Only loads relax that check, through `byte_window_srv`. - `byte_oob` requires word 3 to be cleared with `0xcfffffff` before the OR. `tools/startup/gfx2hlsl.py` also accepts the OR on a plain loaded word, since OR-ing `0x30000000` sets `OOB_SELECT` (DW3[29:28]) to 3 whatever it held and touches no other bit. **Measured** on a local capture of 2,689 compute requests (counts and instruction shape only), with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests` built from `cpp-migration` `f934df52`. - 119 requests stop first at "non-contiguous resource descriptor" on a `buffer_store_dword{,x2,x3,x4}`. - 113 of them have exactly the sequence above, with the stride clamped by `s_max_u32 ..., 1`. - The other 6 multiply by a value from `v_readfirstlane_b32` or an `s_cselect_b32` chain, and are out of scope. **Plan:** - For a buffer store, accept the byte-window form of the descriptor (words 1-3 as above) and bind it as the raw UAV of the unmodified descriptor, as `gfx2hlsl.py` does. This reuses `raw_buffer_uav` with the relaxed word check, so the manifest and runtime are unchanged. - Accept the OR on a plain loaded word 3, in addition to the cleared form. Keep the stride proof: the `s_mul_i32` operand must be the clamped stride of the same descriptor's word 1. - Out-of-range behaviour is that of the bound raw view: D3D12 drops writes past it. Sizing the view to the converted byte count is runtime work and not in scope, as `docs/experiments.md` already notes for the Python path. With a guest stride of 0, the guest byte count is 0 while the host view still accepts writes, which is the same view-sizing limit. - Other descriptor edits stay refused. **Tests:** a hardware readback through `native_store_replay`. - Stores of 1 to 4 dwords through the patched descriptor, fully inside the bound view. - Controls that stay refused: - the `s_mul_i32` operand is not the clamped stride; - a word from a different descriptor; - an `s_or_b32` with a constant other than `0x30000000`. - Mutants: dropping the stride proof, and accepting a foreign descriptor's word, must each fail a control. AI-assisted.
MasterDomino commented 2026-11-27 00:36:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T00:36:12Z.


Closed by #2967, merged into cpp-migration as 78a071ca. native_bytewin_store_hardware passes on an RTX 5080 (author) and on an RX 9070 XT, and disabling the store byte-window path brings back non-contiguous resource descriptor. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7206597416 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2965#issuecomment-7206597416). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T00:36:12Z. --- Closed by #2967, merged into `cpp-migration` as `78a071ca`. `native_bytewin_store_hardware` passes on an RTX 5080 (author) and on an RX 9070 XT, and disabling the store byte-window path brings back `non-contiguous resource descriptor`. AI-assisted.
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#2965
No description provided.