Add BUF_FMT_16_16_SNORM to the vertex fetch table #2092

Merged
Ybucaille merged 2 commits from upstream-pr/2099 into main 2026-11-25 00:38:57 +00:00
Ybucaille commented 2026-11-25 00:14:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-25T00:14:12Z.


Item G of #2023, limited to the 16_16_SNORM buffer format (the other two formats stay open).

tools/startup/gfx2hlsl.py: BUF_FMT_16_16_SNORM (format 24, DXGI R16G16_SNORM 37) next to BUF_FMT_16_16_UNORM. Each half is sign-extended, divided by 32767 and clamped to -1.0, so -32768 and -32767 both give -1.0. Semantics: the Direct3D / Vulkan SNORM rule max(c / 32767, -1.0), as in LLVM 15 and Mesa ac_formats.

Evidence:

  • Fixture: the source-built vertex stage of tests/startup_vertex_fetch_formats_check.py gains the format (device table, readback compares round(v * 32767) against an independent byte decode).
  • Boundaries: the harness pattern in t0 holds no 0x8000, so startup_vertex_fetch_formats_controls also evaluates the emitted expressions on 0x8000, 0x8001, 0x7fff, 0x0000, 0xffff and 0x4000 in each half, with a nonzero neighbour half.
  • Negative controls: unsigned read, no clamp, divisor 32768 and one half used for both must each fail that check (all fail); the device run adds an unsigned-read wrong reference and an unsigned-read mutated translation.
  • Existing startup_gfx2hlsl_*_check.py, startup_translator_check.py, docs_links_check.py and git diff --check pass.

Not run: the D3D12 / WARP draw (startup_vertex_fetch_formats_warp|hardware) needs Windows; only the controls ran, on Linux.

Refs #2023 (item G)

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6594123952 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2099). Originally posted by [Ybucaille](https://github.com/Ybucaille) on 2026-11-25T00:14:12Z. --- Item G of #2023, limited to the `16_16_SNORM` buffer format (the other two formats stay open). `tools/startup/gfx2hlsl.py`: `BUF_FMT_16_16_SNORM` (format 24, DXGI `R16G16_SNORM` 37) next to `BUF_FMT_16_16_UNORM`. Each half is sign-extended, divided by 32767 and clamped to -1.0, so -32768 and -32767 both give -1.0. Semantics: the Direct3D / Vulkan SNORM rule `max(c / 32767, -1.0)`, as in LLVM 15 and Mesa `ac_formats`. Evidence: - Fixture: the source-built vertex stage of `tests/startup_vertex_fetch_formats_check.py` gains the format (device table, readback compares `round(v * 32767)` against an independent byte decode). - Boundaries: the harness pattern in t0 holds no 0x8000, so `startup_vertex_fetch_formats_controls` also evaluates the emitted expressions on 0x8000, 0x8001, 0x7fff, 0x0000, 0xffff and 0x4000 in each half, with a nonzero neighbour half. - Negative controls: unsigned read, no clamp, divisor 32768 and one half used for both must each fail that check (all fail); the device run adds an unsigned-read wrong reference and an unsigned-read mutated translation. - Existing `startup_gfx2hlsl_*_check.py`, `startup_translator_check.py`, `docs_links_check.py` and `git diff --check` pass. Not run: the D3D12 / WARP draw (`startup_vertex_fetch_formats_warp|hardware`) needs Windows; only the controls ran, on Linux. Refs #2023 (item G) AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:01:40 +00:00
R0Y00 commented 2026-11-25 01:02:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:35:06Z.


The exact previous head failed on WARP: the wrapper multiplied signed normalized values by 65535 while the CPU reference expected 32767 (first word expected ffff8b02, observed ffff1603). I corrected the wrapper scale only. RTX 4060 Laptop and WARP now each pass all 12 formats, 16 vertices per format, the wrong-reference controls and nine compiled mutations. Thanks to #2005 for the independent typed-buffer decode and full signed-half check.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148664340 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2099#issuecomment-7148664340). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T00:35:06Z. --- The exact previous head failed on WARP: the wrapper multiplied signed normalized values by 65535 while the CPU reference expected 32767 (first word expected `ffff8b02`, observed `ffff1603`). I corrected the wrapper scale only. RTX 4060 Laptop and WARP now each pass all 12 formats, 16 vertices per format, the wrong-reference controls and nine compiled mutations. Thanks to #2005 for the independent typed-buffer decode and full signed-half check.
ChazY11 commented 2026-11-25 01:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:36:47Z.


This branch fails its own GPU check — reproducible here, with main as the control

# branch pr-2099, offscreen_check rebuilt from this branch, WARP
out/pe-env/Scripts/python.exe -B tests/startup_vertex_fetch_formats_check.py \
    "<Windows Kits>/10/bin/10.0.26100.0/x64/dxc.exe" out/build/dev/offscreen_check.exe warp
RuntimeError: BUF_FMT_16_16_SNORM: backend=warp debug_layer=enabled
debug_errors=0 debug_warnings=0
word=0 expected=ffff8b02 actual=ffff1603
Compute readback differs from CPU reference          exit 1

The same command on main at 30888b67, same binary, same machine:

warp: 11 buffer formats, 16 vertices each, every wrong reference and 8 mutations fail    exit 0

So this is not my environment: the only difference between the two runs is the branch, and the failing word is the new entry's first vertex. expected is
your CPU reference, actual is the readback, so either the lowering or the reference is wrong for BUF_FMT_16_16_SNORM — and the check is doing its job by
saying so.

The two words are worth looking at together:

expected ffff8b02
actual   ffff1603

0x8b02 and 0x1603 differ in the middle bits, not in the top halves, which are ffff on both sides — so the sign extension and the final -1.0 clamp are
probably fine and the disagreement is inside the value. One candidate I would check first: the low-half expression uses int(w) >> 16 while the high-half
one uses int(w << 16) >> 16. On a 32-bit w those select different halves of the same dword only if the two fields are in one word; if the format's
two halves arrive in different dwords (the ldu() path, because the check deliberately uses a misaligned stride), then int(w) >> 16 is reading the second
dword's high half rather than the first dword's second half. Your 16_16_FLOAT entry next to it uses the same shape, so if that one passes and this one does
not, the difference is inside U(max(float(...) / 32767.0, -1.0)) rather than in the field extraction — worth checking which of the two it is before
changing anything.

What did run clean here

controls mode passes on this branch, and four of my five mutations of the new row are caught:

mutation controls
the -1.0 clamp removed caught
divisor 32767.0 → 32768.0 caught
high half without sign extension caught
the two halves swapped caught
format number 37 → 38 survived

The last one is only "survived" in the sense that controls does not pin the descriptor number — the GPU mode would have to, since the draw feeds the number
through the descriptor. Given the failure above, that mode is red on this branch for a different reason, so I could not tell you which.

Suggested order

  1. settle the BUF_FMT_16_16_SNORM mismatch above (the check is registered in CMakeLists.txt at 2246/2258, so CI's startup_vertex_fetch_formats_warp is
    red on this head too, unless your last push is newer than the branch I fetched);
  2. then add the number to the controls, so a wrong format id cannot pass as "translation still refused".

AI-assisted; both runs above were made on Windows 11 build 26300.9974, DXC 10.0.26100.0, offscreen_check rebuilt from the branch under test.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148694610 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2099#issuecomment-7148694610). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:36:47Z. --- ## This branch fails its own GPU check — reproducible here, with `main` as the control ```powershell # branch pr-2099, offscreen_check rebuilt from this branch, WARP out/pe-env/Scripts/python.exe -B tests/startup_vertex_fetch_formats_check.py \ "<Windows Kits>/10/bin/10.0.26100.0/x64/dxc.exe" out/build/dev/offscreen_check.exe warp ``` ```text RuntimeError: BUF_FMT_16_16_SNORM: backend=warp debug_layer=enabled debug_errors=0 debug_warnings=0 word=0 expected=ffff8b02 actual=ffff1603 Compute readback differs from CPU reference exit 1 ``` The same command on `main` at `30888b67`, same binary, same machine: ```text warp: 11 buffer formats, 16 vertices each, every wrong reference and 8 mutations fail exit 0 ``` So this is not my environment: the only difference between the two runs is the branch, and the failing word is the new entry's first vertex. `expected` is your CPU reference, `actual` is the readback, so either the lowering or the reference is wrong for `BUF_FMT_16_16_SNORM` — and the check is doing its job by saying so. The two words are worth looking at together: ```text expected ffff8b02 actual ffff1603 ``` `0x8b02` and `0x1603` differ in the middle bits, not in the top halves, which are `ffff` on both sides — so the sign extension and the final `-1.0` clamp are probably fine and the disagreement is inside the value. One candidate I would check first: the low-half expression uses `int(w) >> 16` while the high-half one uses `int(w << 16) >> 16`. On a 32-bit `w` those select different halves of the **same dword** only if the two fields are in one word; if the format's two halves arrive in *different* dwords (the `ldu()` path, because the check deliberately uses a misaligned stride), then `int(w) >> 16` is reading the second dword's high half rather than the first dword's second half. Your `16_16_FLOAT` entry next to it uses the same shape, so if that one passes and this one does not, the difference is inside `U(max(float(...) / 32767.0, -1.0))` rather than in the field extraction — worth checking which of the two it is before changing anything. ## What did run clean here `controls` mode passes on this branch, and four of my five mutations of the new row are caught: | mutation | controls | |---|---| | the `-1.0` clamp removed | **caught** | | divisor `32767.0` → `32768.0` | **caught** | | high half without sign extension | **caught** | | the two halves swapped | **caught** | | format number `37` → `38` | survived | The last one is only "survived" in the sense that `controls` does not pin the descriptor number — the GPU mode would have to, since the draw feeds the number through the descriptor. Given the failure above, that mode is red on this branch for a different reason, so I could not tell you which. ## Suggested order 1. settle the `BUF_FMT_16_16_SNORM` mismatch above (the check is registered in `CMakeLists.txt` at 2246/2258, so CI's `startup_vertex_fetch_formats_warp` is red on this head too, unless your last push is newer than the branch I fetched); 2. then add the number to the controls, so a wrong format id cannot pass as "translation still refused". AI-assisted; both runs above were made on Windows 11 build 26300.9974, DXC 10.0.26100.0, offscreen_check rebuilt from the branch under test.
Its3rr0rsWRLD commented 2026-11-25 01:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-25T00:40:26Z.


Windows run of the requested draws for #2099 at the earlier head 6b508be0909261b78c9b21cb7058033198571521. The branch has since moved to 0832296e. I'm rerunning there now and will post those results too.

Environment

  • Windows 11 26H2, build 26300.9974
  • Hardware adapter: NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088
  • WARP: Microsoft Basic Render Driver, d3d10warp.dll 10.0.26100.9818
  • dev preset, D3D12 debug layer enabled

Command

ctest --preset dev --no-tests=error -R "^startup_(gfx2hlsl_interp_f16|gfx2hlsl_bit_alu|vertex_fetch_formats|gfx2hlsl_cvt_pk_u8)_(controls|warp|hardware)$" --output-on-failure

Results at 6b508be0: 4 passed, 2 failed

Test Result
startup_vertex_fetch_formats_controls pass
startup_vertex_fetch_formats_warp fail
startup_vertex_fetch_formats_hardware fail
startup_gfx2hlsl_bit_alu_controls pass
startup_gfx2hlsl_bit_alu_warp pass
startup_gfx2hlsl_bit_alu_hardware pass

Both failures are the new format, with identical output on both adapters:

BUF_FMT_16_16_SNORM: backend=warp debug_layer=enabled
debug_errors=0 debug_warnings=0
word=0 expected=ffff8b02 actual=ffff1603
Compute readback differs from CPU reference
BUF_FMT_16_16_SNORM: backend=hardware debug_layer=enabled
debug_errors=0 debug_warnings=0
word=0 expected=ffff8b02 actual=ffff1603
Compute readback differs from CPU reference

Run by Claude (AI-assisted).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148757017 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2099#issuecomment-7148757017). Originally posted by [Its3rr0rsWRLD](https://github.com/Its3rr0rsWRLD) on 2026-11-25T00:40:26Z. --- Windows run of the requested draws for #2099 at the earlier head `6b508be0909261b78c9b21cb7058033198571521`. The branch has since moved to `0832296e`. I'm rerunning there now and will post those results too. **Environment** - Windows 11 26H2, build 26300.9974 - Hardware adapter: NVIDIA GeForce RTX 4070 Ti, driver 32.0.16.1088 - WARP: Microsoft Basic Render Driver, d3d10warp.dll 10.0.26100.9818 - `dev` preset, D3D12 debug layer enabled **Command** ``` ctest --preset dev --no-tests=error -R "^startup_(gfx2hlsl_interp_f16|gfx2hlsl_bit_alu|vertex_fetch_formats|gfx2hlsl_cvt_pk_u8)_(controls|warp|hardware)$" --output-on-failure ``` **Results at `6b508be0`: 4 passed, 2 failed** | Test | Result | |---|---| | `startup_vertex_fetch_formats_controls` | pass | | `startup_vertex_fetch_formats_warp` | **fail** | | `startup_vertex_fetch_formats_hardware` | **fail** | | `startup_gfx2hlsl_bit_alu_controls` | pass | | `startup_gfx2hlsl_bit_alu_warp` | pass | | `startup_gfx2hlsl_bit_alu_hardware` | pass | Both failures are the new format, with identical output on both adapters: ``` BUF_FMT_16_16_SNORM: backend=warp debug_layer=enabled debug_errors=0 debug_warnings=0 word=0 expected=ffff8b02 actual=ffff1603 Compute readback differs from CPU reference ``` ``` BUF_FMT_16_16_SNORM: backend=hardware debug_layer=enabled debug_errors=0 debug_warnings=0 word=0 expected=ffff8b02 actual=ffff1603 Compute readback differs from CPU reference ``` Run by Claude (AI-assisted).
ChazY11 commented 2026-11-25 01:02:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:41:52Z.


Re-ran the fix on both adapters here, on the merged head

Independent of your 4060, on 0832296e (now merged as 246a875d), Windows 11 build 26300.9974, DXC 10.0.26100.0,
offscreen_check rebuilt from the branch:

controls                                                vertex fetch format controls passed            exit 0
dxc out/build/dev/offscreen_check.exe warp        12 buffer formats, 16 vertices each, every wrong reference and 9 mutations fail   exit 0
dxc out/build/dev/offscreen_check.exe hardware    12 buffer formats, 16 vertices each, every wrong reference and 9 mutations fail   exit 0

So the readback now agrees with the CPU reference on the card (RTX 5080 Laptop, driver 32.0.15.8142) as well as on WARP, and the nine compiled
mutations still fail — the scale change did not weaken the negative controls.

For the record, the pair of words that made this diagnosable:

expected ffff8b02   actual ffff1603      wrapper ×65535 vs reference ×32767

0x8b02 / 65535 ≈ 0.543 and 0x1603 / 32767 ≈ 0.172 — the ratio is about 3.16, not 2, which is the signature of two different divisors rather than a
shifted field. That is the sort of thing I only noticed because the check printed both words; worth keeping that output shape in whatever check comes
next.

Nothing outstanding from my side on this PR.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148782166 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2099#issuecomment-7148782166). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:41:52Z. --- ## Re-ran the fix on both adapters here, on the merged head Independent of your 4060, on `0832296e` (now merged as `246a875d`), Windows 11 build 26300.9974, DXC 10.0.26100.0, `offscreen_check` rebuilt from the branch: ```text controls vertex fetch format controls passed exit 0 dxc out/build/dev/offscreen_check.exe warp 12 buffer formats, 16 vertices each, every wrong reference and 9 mutations fail exit 0 dxc out/build/dev/offscreen_check.exe hardware 12 buffer formats, 16 vertices each, every wrong reference and 9 mutations fail exit 0 ``` So the readback now agrees with the CPU reference on the card (RTX 5080 Laptop, driver 32.0.15.8142) as well as on WARP, and the nine compiled mutations still fail — the scale change did not weaken the negative controls. For the record, the pair of words that made this diagnosable: ```text expected ffff8b02 actual ffff1603 wrapper ×65535 vs reference ×32767 ``` `0x8b02 / 65535 ≈ 0.543` and `0x1603 / 32767 ≈ 0.172` — the ratio is about 3.16, not 2, which is the signature of two different divisors rather than a shifted field. That is the sort of thing I only noticed because the check printed both words; worth keeping that output shape in whatever check comes next. Nothing outstanding from my side on this PR. AI-assisted.
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!2092
No description provided.