startup: run every gfx2hlsl vertex-fetch buffer format #1689

Merged
Asimmimx merged 1 commit from upstream-pr/1696 into main 2026-11-24 17:39:20 +00:00
Asimmimx commented 2026-11-24 17:18:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:18:55Z.


Refs #1149.

Change

tools/startup/gfx2hlsl.py lowers tbuffer_load_format_* for ten buffer formats through a table of HLSL expressions. Each entry defines the word load, the field and conversion for each component, and the values of missing components. Only BUF_FMT_8_UINT and BUF_FMT_8_UNORM were ever run, both by startup_r8_uint. The other eight entries had no check: 8_8_UNORM, 16_16_UNORM, 16_16_FLOAT, 8_8_8_8_UNORM, 32_FLOAT, 32_32_FLOAT, 32_32_32_FLOAT and 32_32_32_32_FLOAT. That left their shifts, UNORM scales, binary16 widening, unaligned ldu() reads and default W untested.

This PR adds a check only. The translator does not change.

tests/startup_vertex_fetch_formats_check.py follows startup_r8_uint_check.py. For each format it:

  • translates a source-built vertex stage with one tbuffer_load_format_xyzw from vertex-buffer slot 1;
  • compiles the vertex entry as the startup tools do, then calls the generated vertex body from a compute wrapper;
  • reads back the four position components of 16 vertices through offscreen_check --compute-store-case.

The expected words come from an independent decode of the same bytes. Fields are read little-endian from the lowest byte. UNORM is n / (2^bits - 1), binary16 is widened to binary32, missing X, Y and Z are 0, and a missing W is 1.0 (1 for 8_UINT).

Format Code Stride, offset Byte alignments of the elements
8_UNORM, 8_UINT 1, 5 3, 1 0–3
8_8_UNORM 14 3, 2 0–3 (fields cross a dword)
16_16_UNORM 23 6, 2 0, 2
16_16_FLOAT 29 10, 10 0, 2
8_8_8_8_UNORM 56 5, 3 0–3
32_FLOAT … 32_32_32_32_FLOAT 22, 64, 74, 77 8/4, 12/0, 16/4, 20/8 0 (aligned Load())
  • Comparison. UNORM components are compared as round(v * (2^bits - 1)) in the wrapper, so the check does not depend on how many ulps the division is off. All other components are compared bit for bit. The controls check that the chosen binary16 halves and binary32 words are normal, so f16tof32 and the pass-through are exact on any adapter.
  • Negative controls. 25 wrong references must fail at their first differing word: swapped channels, fields one field higher, a missing W as 0, and UNORM over 2^bits, for each format where they change a word. Seven mutated translations must fail the readback:
    • 8_8_8_8_UNORM: second byte taken from the third;
    • 8_8_8_8_UNORM: fourth byte read as 1.0;
    • 8_8_UNORM: aligned load instead of ldu();
    • 16_16_UNORM: high half divided by 65536;
    • 16_16_FLOAT: low half read from the high half;
    • 32_32_32_FLOAT: missing W read as 0;
    • 32_32_32_32_FLOAT: W read from the third word.

The tests are registered as startup_vertex_fetch_formats_controls (device-free) and startup_vertex_fetch_formats_{warp,hardware}, next to startup_r8_uint. docs/experiments.md gets a subsection under "Startup vertex fetch from an unsigned byte".

Results

Commit 1e2bbb5b on 18a2942a. Windows 11 26300.9974, DXC 1.8.2502.11, debug layer on.

python -B tests/startup_vertex_fetch_formats_check.py controls
vertex fetch format controls passed
python -B tests/startup_vertex_fetch_formats_check.py <dxc> out/build/dev/offscreen_check.exe warp
BUF_FMT_8_UNORM: 16 vertices, stride 3, offset 1: groups=1 compared_words=320 mismatches=0
...
BUF_FMT_32_32_32_32_FLOAT: 16 vertices, stride 20, offset 8: groups=1 compared_words=320 mismatches=0
warp: 10 buffer formats, 16 vertices each, every wrong reference and 7 mutations fail
Adapter Driver Formats matched Wrong references Mutations
WARP 10.0.26100.9818 10/10 25/25 fail 7/7 fail
AMD Radeon RX 6600 (RDNA 2) 32.0.21045.29003 10/10 25/25 fail 7/7 fail

There were no skips. startup_r8_uint_warp, docs_links_check.py and bidi_controls_check.py still pass. ctest --preset dev -N -R vertex_fetch_formats lists the three tests.

Not covered: the formats the table refuses, and the _x, _xy and _xyz variants. Those variants share the same table and only write fewer registers.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587441542 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1696). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:18:55Z. --- Refs #1149. ## Change `tools/startup/gfx2hlsl.py` lowers `tbuffer_load_format_*` for ten buffer formats through a table of HLSL expressions. Each entry defines the word load, the field and conversion for each component, and the values of missing components. Only `BUF_FMT_8_UINT` and `BUF_FMT_8_UNORM` were ever run, both by `startup_r8_uint`. The other eight entries had no check: `8_8_UNORM`, `16_16_UNORM`, `16_16_FLOAT`, `8_8_8_8_UNORM`, `32_FLOAT`, `32_32_FLOAT`, `32_32_32_FLOAT` and `32_32_32_32_FLOAT`. That left their shifts, UNORM scales, binary16 widening, unaligned `ldu()` reads and default W untested. This PR adds a check only. The translator does not change. `tests/startup_vertex_fetch_formats_check.py` follows `startup_r8_uint_check.py`. For each format it: - translates a source-built vertex stage with one `tbuffer_load_format_xyzw` from vertex-buffer slot 1; - compiles the vertex entry as the startup tools do, then calls the generated vertex body from a compute wrapper; - reads back the four position components of 16 vertices through `offscreen_check --compute-store-case`. The expected words come from an independent decode of the same bytes. Fields are read little-endian from the lowest byte. UNORM is `n / (2^bits - 1)`, binary16 is widened to binary32, missing X, Y and Z are 0, and a missing W is 1.0 (1 for `8_UINT`). | Format | Code | Stride, offset | Byte alignments of the elements | |---|---|---|---| | `8_UNORM`, `8_UINT` | 1, 5 | 3, 1 | 0–3 | | `8_8_UNORM` | 14 | 3, 2 | 0–3 (fields cross a dword) | | `16_16_UNORM` | 23 | 6, 2 | 0, 2 | | `16_16_FLOAT` | 29 | 10, 10 | 0, 2 | | `8_8_8_8_UNORM` | 56 | 5, 3 | 0–3 | | `32_FLOAT` … `32_32_32_32_FLOAT` | 22, 64, 74, 77 | 8/4, 12/0, 16/4, 20/8 | 0 (aligned `Load()`) | - **Comparison.** UNORM components are compared as `round(v * (2^bits - 1))` in the wrapper, so the check does not depend on how many ulps the division is off. All other components are compared bit for bit. The controls check that the chosen binary16 halves and binary32 words are normal, so `f16tof32` and the pass-through are exact on any adapter. - **Negative controls.** 25 wrong references must fail at their first differing word: swapped channels, fields one field higher, a missing W as 0, and UNORM over `2^bits`, for each format where they change a word. Seven mutated translations must fail the readback: - `8_8_8_8_UNORM`: second byte taken from the third; - `8_8_8_8_UNORM`: fourth byte read as 1.0; - `8_8_UNORM`: aligned load instead of `ldu()`; - `16_16_UNORM`: high half divided by 65536; - `16_16_FLOAT`: low half read from the high half; - `32_32_32_FLOAT`: missing W read as 0; - `32_32_32_32_FLOAT`: W read from the third word. The tests are registered as `startup_vertex_fetch_formats_controls` (device-free) and `startup_vertex_fetch_formats_{warp,hardware}`, next to `startup_r8_uint`. `docs/experiments.md` gets a subsection under "Startup vertex fetch from an unsigned byte". ## Results Commit `1e2bbb5b` on `18a2942a`. Windows 11 26300.9974, DXC 1.8.2502.11, debug layer on. ``` python -B tests/startup_vertex_fetch_formats_check.py controls vertex fetch format controls passed python -B tests/startup_vertex_fetch_formats_check.py <dxc> out/build/dev/offscreen_check.exe warp BUF_FMT_8_UNORM: 16 vertices, stride 3, offset 1: groups=1 compared_words=320 mismatches=0 ... BUF_FMT_32_32_32_32_FLOAT: 16 vertices, stride 20, offset 8: groups=1 compared_words=320 mismatches=0 warp: 10 buffer formats, 16 vertices each, every wrong reference and 7 mutations fail ``` | Adapter | Driver | Formats matched | Wrong references | Mutations | |---|---|---|---|---| | WARP | 10.0.26100.9818 | 10/10 | 25/25 fail | 7/7 fail | | AMD Radeon RX 6600 (RDNA 2) | 32.0.21045.29003 | 10/10 | 25/25 fail | 7/7 fail | There were no skips. `startup_r8_uint_warp`, `docs_links_check.py` and `bidi_controls_check.py` still pass. `ctest --preset dev -N -R vertex_fetch_formats` lists the three tests. Not covered: the formats the table refuses, and the `_x`, `_xy` and `_xyz` variants. Those variants share the same table and only write fewer registers. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 18:02:36 +00:00
tedin7 commented 2026-11-24 18:02:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:23:44Z.

Review: COMMENTED


Review of head 1e2bbb5b76 (comment only, not an approval).

Verdict: 0 P1 / 0 P2. The diff only adds lines (CMakeLists.txt +7, docs/experiments.md +14, the new check +220), so no assertion is loosened, skipped or removed. tools/gfx2hlsl.py is untouched.

Read

  • The reference decodes bytes independently (little-endian fields, UNORM as n/(2^bits-1), binary16 widened, missing X/Y/Z as 0, missing W as 1.0, or 1 for 8_UINT) and matches the translator table at gfx2hlsl.py:658-669.
  • The largest element (324 bytes) fits the 1280-byte DATA buffer; the doc counts (25 wrong references, 7 mutations) match the code; the add_test lines follow the startup_r8_uint pattern with SKIP_RETURN_CODE 77.

Run

  • cd tests && python3 -B startup_vertex_fetch_formats_check.py controls: "vertex fetch format controls passed".
  • python3 -m py_compile tests/startup_vertex_fetch_formats_check.py: clean. A small script counted 25 wrong references that change a word, as the PR says.
  • Mutation 1, reference missing = [0,0,0,0]: controls fail ("no wrong reference changes BUF_FMT_32_FLOAT"). Restored, green.
  • Mutations 2 and 3 in gfx2hlsl.py (16_16_FLOAT f16tof32(w >> 16) -> f16tof32(w); 32_32_FLOAT missing W U(1.0) -> 0u): the controls still pass, because they only check that the 7 MUTATIONS strings appear in the generated HLSL. Only the _warp/_hardware readback can catch those, and I could not run it. The 10/10 and 7/7 results in the PR are therefore unconfirmed here.

Non-blocking

  • check.py:140 comment says changing any byte of vertex 5 changes a word; the code checks that some wrong reference does. Stale comment.
  • check.py:141-142: stride, offset, bits, kind, count and label are unpacked and unused.
  • The device-free controls assert on generated HLSL text (the old in source checks). Acceptable here because the same strings drive the runtime mutations and the readback is the real check.
  • The doc says 8_UINT and 8_UNORM ran before via startup_r8_uint; I did not re-verify that.

No other open PR touches vertex fetch or tbuffer formats.

Linux limits: no Windows, MSVC, DXC or D3D12 device here; LLVM 19 only. Anything that needs them was not run.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044114393 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1696#pullrequestreview-6044114393). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:23:44Z. **Review:** COMMENTED --- Review of head 1e2bbb5b76f807465464870971d07e1d7eb25e48 (comment only, not an approval). Verdict: 0 P1 / 0 P2. The diff only adds lines (CMakeLists.txt +7, docs/experiments.md +14, the new check +220), so no assertion is loosened, skipped or removed. tools/gfx2hlsl.py is untouched. Read - The reference decodes bytes independently (little-endian fields, UNORM as n/(2^bits-1), binary16 widened, missing X/Y/Z as 0, missing W as 1.0, or 1 for 8_UINT) and matches the translator table at gfx2hlsl.py:658-669. - The largest element (324 bytes) fits the 1280-byte DATA buffer; the doc counts (25 wrong references, 7 mutations) match the code; the add_test lines follow the startup_r8_uint pattern with SKIP_RETURN_CODE 77. Run - `cd tests && python3 -B startup_vertex_fetch_formats_check.py controls`: "vertex fetch format controls passed". - `python3 -m py_compile tests/startup_vertex_fetch_formats_check.py`: clean. A small script counted 25 wrong references that change a word, as the PR says. - Mutation 1, reference `missing = [0,0,0,0]`: controls fail ("no wrong reference changes BUF_FMT_32_FLOAT"). Restored, green. - Mutations 2 and 3 in gfx2hlsl.py (16_16_FLOAT `f16tof32(w >> 16)` -> `f16tof32(w)`; 32_32_FLOAT missing W `U(1.0)` -> `0u`): the controls still pass, because they only check that the 7 MUTATIONS strings appear in the generated HLSL. Only the _warp/_hardware readback can catch those, and I could not run it. The 10/10 and 7/7 results in the PR are therefore unconfirmed here. Non-blocking - check.py:140 comment says changing any byte of vertex 5 changes a word; the code checks that some wrong reference does. Stale comment. - check.py:141-142: `stride, offset, bits, kind, count` and `label` are unpacked and unused. - The device-free controls assert on generated HLSL text (the `old in source` checks). Acceptable here because the same strings drive the runtime mutations and the readback is the real check. - The doc says 8_UINT and 8_UNORM ran before via startup_r8_uint; I did not re-verify that. No other open PR touches vertex fetch or tbuffer formats. Linux limits: no Windows, MSVC, DXC or D3D12 device here; LLVM 19 only. Anything that needs them was not run. AI-assisted; commands listed were executed locally.
Sign in to join this conversation.
No reviewers
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!1689
No description provided.