shader: support BUF_FMT_8_8_8_8_UINT fetch format in gfx2hlsl (Part of #1723) #1997

Closed
tedin7 wants to merge 3 commits from upstream-pr/2004 into main
tedin7 commented 2026-11-24 22:57:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T22:57:48Z.


Part of #1723

What this unblocks: typed buffer loads with BUF_FMT_8_8_8_8_UINT now translate (four unscaled bytes) instead of being refused, so shaders using it can get past startup translation.

Changes:

  • tools/startup/gfx2hlsl.py: add BUF_FMT_8_8_8_8_UINT to FETCH_FORMATS (bytes of one word, no 1/255 scale).
  • tests/startup_gfx2hlsl_buf_8888_uint_check.py + CTest startup_gfx2hlsl_buf_8888_uint: pure Python, evaluates the emitted lines for several words.

Verification:

  • python3 -B tests/startup_gfx2hlsl_buf_8888_uint_check.py with fix: ok
  • Same command with gfx2hlsl.py from origin/main: Unsupported: buffer format BUF_FMT_8_8_8_8_UINT
  • Not run on Win2025 (no GPU/compiler needed by this test); no hardware measurement of the format.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593094999 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T22:57:48Z. --- Part of #1723 What this unblocks: typed buffer loads with `BUF_FMT_8_8_8_8_UINT` now translate (four unscaled bytes) instead of being refused, so shaders using it can get past startup translation. Changes: - `tools/startup/gfx2hlsl.py`: add `BUF_FMT_8_8_8_8_UINT` to `FETCH_FORMATS` (bytes of one word, no 1/255 scale). - `tests/startup_gfx2hlsl_buf_8888_uint_check.py` + CTest `startup_gfx2hlsl_buf_8888_uint`: pure Python, evaluates the emitted lines for several words. Verification: - `python3 -B tests/startup_gfx2hlsl_buf_8888_uint_check.py` with fix: `ok` - Same command with `gfx2hlsl.py` from origin/main: `Unsupported: buffer format BUF_FMT_8_8_8_8_UINT` - Not run on Win2025 (no GPU/compiler needed by this test); no hardware measurement of the format. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 23:03:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:00:31Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3cf4cb9091

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048761027 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#pullrequestreview-6048761027). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:00:31Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `3cf4cb9091` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-24 23:03:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T22:57:56Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:00:35.930684Z 3cf4cb9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7146852650 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#issuecomment-7146852650). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T22:57:56Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"3cf4cb9091831c165514e0bbf9e5cf62f8bc3c4f","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T23:00:35.930684Z">2026-11-24T23:00:35.930684Z</relative-time> | `3cf4cb9` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
chatgpt-codex-connector[bot commented 2026-11-24 23:03:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:00:32Z.

Code review location: tools/startup/gfx2hlsl.py; line 85

@@ -82,6 +82,7 @@ def strip_header(code):
     'BUF_FMT_8_8_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', 'U(((w >> 16) & 255) / 255.0)', 'U((w >> 24) / 255.0)']),
     'BUF_FMT_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', '0u', 'U(1.0)']),
     'BUF_FMT_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', '0u', '0u', 'U(1.0)']),
+    'BUF_FMT_8_8_8_8_UINT': ('ldu({0}, a)', ['w & 255u', '(w >> 8) & 255u', '(w >> 16) & 255u', 'w >> 24']),

P1 Badge Document the new typed-buffer capability and validation scope

This adds support for BUF_FMT_8_8_8_8_UINT but leaves both the README and docs/experiments.md unchanged, so contributors following the published experiment documentation cannot discover or reproduce the new capability. AGENTS.md requires a documentation update when a public capability changes. Add an experiment entry with the new test command and distinguish its Python-only expression checks from compiled-shader or GPU validation.

AGENTS.md reference: AGENTS.md:L207-L208

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4687708963 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#discussion_r4687708963). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T23:00:32Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 85 ~~~~diff @@ -82,6 +82,7 @@ def strip_header(code): 'BUF_FMT_8_8_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', 'U(((w >> 16) & 255) / 255.0)', 'U((w >> 24) / 255.0)']), 'BUF_FMT_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', '0u', 'U(1.0)']), 'BUF_FMT_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', '0u', '0u', 'U(1.0)']), + 'BUF_FMT_8_8_8_8_UINT': ('ldu({0}, a)', ['w & 255u', '(w >> 8) & 255u', '(w >> 16) & 255u', 'w >> 24']), ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new typed-buffer capability and validation scope** This adds support for `BUF_FMT_8_8_8_8_UINT` but leaves both the README and `docs/experiments.md` unchanged, so contributors following the published experiment documentation cannot discover or reproduce the new capability. `AGENTS.md` requires a documentation update when a public capability changes. Add an experiment entry with the new test command and distinguish its Python-only expression checks from compiled-shader or GPU validation. AGENTS.md reference: [AGENTS.md:L207-L208](https://github.com/R0Y00/Xbox2Windows/blob/3cf4cb9091831c165514e0bbf9e5cf62f8bc3c4f/AGENTS.md#L207-L208) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-25 01:01:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:53:34Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049880278 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#pullrequestreview-6049880278). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:53:34Z. **Review:** COMMENTED --- _No description provided._
ChazY11 commented 2026-11-25 01:01:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T23:22:17Z.


Ran both, broke each one four ways — all caught — and checked the SNORM mapping over all 65,536 halves

Two small format additions, reviewed together because they share FETCH_FORMATS and both are Part of #1723.

# BUF_FMT_16_16_SNORM
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_tbuffer_16_16_snorm_check.py   # exit 0
# BUF_FMT_8_8_8_8_UINT
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_buf_8888_uint_check.py          # exit 0
mutation result
SNORM: x and y halves swapped caught
SNORM: the -1.0 clamp removed caught
SNORM: / 32767.0 → / 32768.0 caught
SNORM: x read with asint(w & 0xffffu) instead of the sign-extending shift caught
UINT: x and y channels swapped caught
UINT: z loses its & 255u caught
UINT: w becomes w >> 8 caught

Both fixtures carry the boundary values, not just mid-range ones — the sign-extending shift and the removed clamp are exactly the two that would
survive a fixture built from small positives.

The SNORM mapping, checked exhaustively

I reimplemented the emitted expression (max(float(asint(w << 16) >> 16) / 32767.0, -1.0)) and compared it with the DXGI SNORM rule over every
16-bit half:

values checked: 65536  mismatches: 0  worst delta: 0

0x0000 -> 0.0000000      0x7fff -> 1.0000000       0x8000 -> -1.0000000
0x8001 -> -1.0000000     0xffff -> -0.0000305      0x4000 -> 0.5000153
-32768 with the clamp removed -> -1.0000305 (outside SNORM)

-32768 is the only input that needs the clamp: /32767 gives -1.0000305, and every other half already lands inside [-1, 1]. That is worth a
sentence in the description, because it explains why the clamp is a max on one specific value rather than a general guard, and why a reader who
replaces it with saturate()-style clamping would change nothing for 65,535 of the 65,536 inputs.

The +32767 → 1.0 endpoint is exact and -32767 → -1.0 too, so both extremes of the representable range are hit exactly, which is the property a
signed-normalised vertex attribute depends on.

UINT

w & 255u, (w >> 8) & 255u, (w >> 16) & 255u, w >> 24 — the last channel needs no mask because the shift already bounds it to 0..255, and a
mask there would be dead code rather than a bug. The three masks that exist are each pinned by the mutations above.

Worth noting the asymmetry with SNORM in the same table: one format sign-extends and divides, the other masks and shifts, and both are now covered by
fixtures that fail when the wrong one is used.

Merge state, and the overlap I flagged earlier

Both branches are clean against main individually, but they are the pair that overlaps at lines 87–89 in FETCH_FORMATS: whichever lands second
needs a one-line rebase. Nothing else in either PR touches the other.

What is not covered

No vertex shader was compiled or run; the values above are the emitted expressions evaluated in Python, not a draw. And the z = 0u, w = 1.0
filler for the two-channel SNORM format matches the other two-channel entries — that is a convention I checked against the table, not a format
property.

Notes

  • AI-assisted review.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7147322899 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#issuecomment-7147322899). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T23:22:17Z. --- ## Ran both, broke each one four ways — all caught — and checked the SNORM mapping over all 65,536 halves Two small format additions, reviewed together because they share `FETCH_FORMATS` and both are `Part of #1723`. ```powershell # BUF_FMT_16_16_SNORM out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_tbuffer_16_16_snorm_check.py # exit 0 # BUF_FMT_8_8_8_8_UINT out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_buf_8888_uint_check.py # exit 0 ``` | mutation | result | |---|---| | SNORM: x and y halves swapped | **caught** | | SNORM: the `-1.0` clamp removed | **caught** | | SNORM: `/ 32767.0` → `/ 32768.0` | **caught** | | SNORM: x read with `asint(w & 0xffffu)` instead of the sign-extending shift | **caught** | | UINT: x and y channels swapped | **caught** | | UINT: `z` loses its `& 255u` | **caught** | | UINT: `w` becomes `w >> 8` | **caught** | Both fixtures carry the boundary values, not just mid-range ones — the sign-extending shift and the removed clamp are exactly the two that would survive a fixture built from small positives. ## The SNORM mapping, checked exhaustively I reimplemented the emitted expression (`max(float(asint(w << 16) >> 16) / 32767.0, -1.0)`) and compared it with the DXGI SNORM rule over every 16-bit half: ```text values checked: 65536 mismatches: 0 worst delta: 0 0x0000 -> 0.0000000 0x7fff -> 1.0000000 0x8000 -> -1.0000000 0x8001 -> -1.0000000 0xffff -> -0.0000305 0x4000 -> 0.5000153 -32768 with the clamp removed -> -1.0000305 (outside SNORM) ``` `-32768` is the **only** input that needs the clamp: `/32767` gives `-1.0000305`, and every other half already lands inside `[-1, 1]`. That is worth a sentence in the description, because it explains why the clamp is a `max` on one specific value rather than a general guard, and why a reader who replaces it with `saturate()`-style clamping would change nothing for 65,535 of the 65,536 inputs. The `+32767 → 1.0` endpoint is exact and `-32767 → -1.0` too, so both extremes of the representable range are hit exactly, which is the property a signed-normalised vertex attribute depends on. ## UINT `w & 255u`, `(w >> 8) & 255u`, `(w >> 16) & 255u`, `w >> 24` — the last channel needs no mask because the shift already bounds it to 0..255, and a mask there would be dead code rather than a bug. The three masks that exist are each pinned by the mutations above. Worth noting the asymmetry with SNORM in the same table: one format sign-extends and divides, the other masks and shifts, and both are now covered by fixtures that fail when the wrong one is used. ## Merge state, and the overlap I flagged earlier Both branches are clean against `main` individually, but they are the pair that overlaps at lines 87–89 in `FETCH_FORMATS`: whichever lands second needs a one-line rebase. Nothing else in either PR touches the other. ## What is not covered No vertex shader was compiled or run; the values above are the emitted expressions evaluated in Python, not a draw. And the `z = 0u`, `w = 1.0` filler for the two-channel SNORM format matches the other two-channel entries — that is a convention I checked against the table, not a format property. ## Notes - AI-assisted review.
tedin7 commented 2026-11-25 01:02:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:53:34Z.

Code review location: tools/startup/gfx2hlsl.py; line 85

@@ -82,6 +82,7 @@ def strip_header(code):
     'BUF_FMT_8_8_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', 'U(((w >> 16) & 255) / 255.0)', 'U((w >> 24) / 255.0)']),
     'BUF_FMT_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', '0u', 'U(1.0)']),
     'BUF_FMT_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', '0u', '0u', 'U(1.0)']),
+    'BUF_FMT_8_8_8_8_UINT': ('ldu({0}, a)', ['w & 255u', '(w >> 8) & 255u', '(w >> 16) & 255u', 'w >> 24']),

Added the experiment entry in docs/experiments.md (test command, Python-only scope, no DXC/WARP run) in a929d075 on the rebased branch. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_buf_8888_uint_check.py; python3 -B tests/startup_vertex_fetch_formats_check.py controls.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4688702630 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#discussion_r4688702630). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T00:53:34Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 85 ~~~~diff @@ -82,6 +82,7 @@ def strip_header(code): 'BUF_FMT_8_8_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', 'U(((w >> 16) & 255) / 255.0)', 'U((w >> 24) / 255.0)']), 'BUF_FMT_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', '0u', 'U(1.0)']), 'BUF_FMT_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', '0u', '0u', 'U(1.0)']), + 'BUF_FMT_8_8_8_8_UINT': ('ldu({0}, a)', ['w & 255u', '(w >> 8) & 255u', '(w >> 16) & 255u', 'w >> 24']), ~~~~ --- Added the experiment entry in docs/experiments.md (test command, Python-only scope, no DXC/WARP run) in a929d075 on the rebased branch. AI-assisted; commands listed were executed locally: python3 -B tests/startup_gfx2hlsl_buf_8888_uint_check.py; python3 -B tests/startup_vertex_fetch_formats_check.py controls.
upstream-sync closed this pull request 2026-11-25 11:02:01 +00:00
tedin7 commented 2026-11-25 11:02:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:58:21Z.


Closing as superseded by #2193 (merged on main at 19509ee4), which landed the same BUF_FMT_8_8_8_8_UINT fetch format, DXGI 30 entry, and vertex fetch coverage.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7160416502 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2004#issuecomment-7160416502). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:58:21Z. --- Closing as superseded by #2193 (merged on main at `19509ee4`), which landed the same `BUF_FMT_8_8_8_8_UINT` fetch format, DXGI 30 entry, and vertex fetch coverage.

Pull request closed

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!1997
No description provided.