Skip to content

shader: decode buffer FORMAT 47 (10_10_10_2 SSCALED) from hardware descriptors - #3382

Open
tedin7 wants to merge 6 commits into
R0Y00:mainfrom
tedin7:upprs-sscaled
Open

tedin7 wants to merge 6 commits into
R0Y00:mainfrom
tedin7:upprs-sscaled

Conversation

@tedin7

@tedin7 tedin7 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #870

What this unblocks: buffer_load_format_* from a hardware descriptor whose FORMAT field is 47 (BUF_FMT_10_10_10_2_SSCALED), which was refused as an unsupported FORMAT.

What changed:

  • tools/startup/gfx2hlsl.py: new BUF_FMT_10_10_10_2_SSCALED entry (FORMAT 47). Each field is sign-extended and converted to a float without dividing; x is the 2-bit field in bits 1:0, y, z and w are the 10-bit fields above it. No DXGI typed view has this layout, so it is listed in DESCRIPTOR_ONLY_FORMATS.
  • src/startup_stubs/formatted_buffer.h: the runtime accepts code 47.
  • Tests: new startup_vertex_fetch_sscaled_{controls,warp,hardware} (sixteen elements at an unaligned stride read back bit for bit against a CPU reference, plus mutants for the removed case, dropped sign extension and wrong field order); the sibling format-count check and the word3 table check account for the descriptor-only format.

Verification:

  • Linux: python3 -B tests/startup_vertex_fetch_sscaled_check.py controls, python3 -B tests/startup_vertex_fetch_formats_check.py controls, python3 -B tests/startup_buffer_format_word3_table_check.py: pass.
  • Win2025 (aws-1) at 66a993b: x2w_pipe.py win2025 3382 --host aws-1 --targets offscreen_check,startup_buffer_format_word3_check --regex '^startup_(vertex_fetch|buffer_format_word3)' --force: dev 9/9 and release 9/9 passed (includes startup_vertex_fetch_sscaled_warp and _hardware).
  • Mutant (source change: float(int(w << 30) >> 30) -> float(uint(w << 30) >> 30) in the SSCALED entry), x2w_pipe.py win2025 3382 --host aws-1 --patch <mutant> --skip-release --regex '^startup_vertex_fetch': startup_vertex_fetch_sscaled_warp and startup_vertex_fetch_sscaled_hardware fail (4/6 pass).

Draft until an independent peer review and the Win2025 WARP gate pass.

Thanks to @Makto94 for the testing that found this.

AI-assisted; commands listed were executed locally.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean addition for an otherwise unreachable format.

Adds BUF_FMT_10_10_10_2_SSCALED (FORMAT 47) decode to gfx2hlsl.py: four signed fields packed in one dword (x=2-bit, y/z/w=10-bit each), sign-extended and converted to float without division. No DXGI typed view has this layout, so only hardware descriptors reach it. Runtime formatted_buffer.h now accepts FORMAT 47. Test fixture checks 16 elements bit-exact against CPU reference, with mutations (case removed, sign extension dropped, wrong field order) all failing correctly.

Ready to land.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean extension of MTBUF formatted loads to the SRV byte window.

Extends the SRV byte window path to formatted loads (tbuffer_load_format_x). requires_identity_dst_sel threads from manifest through cache encoding, binder, and dispatch refusal. indirect_table_buffer checks identity DST_SEL and component mapping before binding. gfx1013_compute_mtbuf.inl detects the zero-stride rewrite and routes through byte_window_srv. Writable MTBUF byte windows refuse without a verified view contract. New test startup_compute_mtbuf_window_check.py covers identity readback, swapped X/Y refusal, CBV-token refusal, and cold/warm cache manifest equality. Existing tests updated for raw and formatted window loads.

Ready to land.

@tedin7

tedin7 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Merged current main into this branch (merge commit, no force push); head is now 0abb4b208, no conflicts and no change to the PR's own files.

Verification (Windows Server 2025, D3D12 WARP, head 0abb4b208): x2w_pipe.py win2025 3382 --regex '^startup_(vertex_fetch|buffer_format_word3)' -> 9/9 passed, including startup_vertex_fetch_sscaled_warp and _hardware. The sign-extension mutant from the PR body fails these two tests, as before.

KelboLive approved 66a993b6; the only change since is the main merge. Marking this Ready.

@MasterDomino ready for review and merge when you have time.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 28, 2026 21:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
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-28T22:03:37.550593Z 0abb4b2 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0abb4b2083

ℹ️ 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".

switch (code) {
case 1: case 5: case 14: case 22: case 23: case 24: case 27:
case 29: case 50: case 56: case 60: case 64: case 71: case 74: case 77:
case 29: case 47: case 50: case 56: case 60: case 64: case 71: case 74: case 77:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Invalidate cached translations before accepting FORMAT 47

When reusing a shader cache containing an already-translated buffer_load_format_* pipeline, this gate now accepts FORMAT 47 even though the cached bytecode has no corresponding switch case and returns DESC_FORMAT_UNKNOWN NaNs for identity selectors. The Python and runtime cache revisions remain unchanged: the source-built MUBUF fixture retains key 170fc67bcc26ed98 across this commit, load_translation() loads the existing bytecode, and pending_keys() skips complete results. Consequently, upgrading the runtime and translator can replace the previous explicit refusal with incorrect shader results without ever running the new decoder. Bump the synchronized cache revisions or otherwise invalidate existing translations alongside this acceptance change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revision 30 (already on this branch) changes the graphics and compute cache keys, so results translated before FORMAT 47 support are not reused. 0a7b7b1 adds a check to tests/startup_shader_cache_rekey_check.py: completed revision 29 results stay pending under the current revision. Linux: startup_shader_cache_rekey_check passes; the revision 29 negative control fails as expected.

Comment thread tools/startup/gfx2hlsl.py
'BUF_FMT_32_32_FLOAT': 64, 'BUF_FMT_16_16_16_16_FLOAT': 71, 'BUF_FMT_32_32_32_FLOAT': 74,
'BUF_FMT_32_32_32_32_FLOAT': 77}
# Formats only a hardware descriptor reaches: no DXGI typed view has their layout.
DESCRIPTOR_ONLY_FORMATS = frozenset({'BUF_FMT_10_10_10_2_SSCALED'})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document FORMAT 47 support and its reproduction tests

This introduces the first descriptor-only decoded format, changing a public capability without the documentation update required by AGENTS.md. A repository-wide search for SSCALED and startup_vertex_fetch_sscaled finds no README or experiment entry; docs/experiments.md still states that the DXGI table equals DESC_FORMAT_CODES, and its documented vertex-fetch filter excludes the new fixture. Update the capability documentation to explain descriptor-only FORMAT 47 support and provide the new reproduction command.

AGENTS.md reference: AGENTS.md:L329-L330

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FORMAT 47 is documented in docs/experiments.md with its reproduction commands. 0a7b7b1 also corrects the table description: the DXGI table agrees with FETCH_DXGI and maps to DESC_FORMAT_CODES, and descriptor-only FORMAT 47 has no DXGI entry.

…ched before FORMAT 47 are redone, and document FORMAT 47
@tedin7

tedin7 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Both findings are addressed in 025f16dd0 (pushed on top of the main merge, no force push).

  1. Cached translations: accepting FORMAT 47 changes what an existing buffer_load_format_* translation does, so the startup shader cache revisions are bumped from x2w-startup-shader-29 / 29cs to 30 / 30cs in the runtime (d3d12_draw.inl), the native request reader (shader_compute_request.cpp), gfx2hlsl.py, patch_manifest.py, the revision-pinned tests (new known-answer keys, recomputed with an independent FNV, including the framed compute key) and the docs. The archived revision-28 fallback is unchanged. A cache written before this change now has other keys, so it is retranslated. Mutant: reverting only the runtime literal to 29 fails startup_gfx2hlsl_fract_check ("the two literals are identical").
  2. Documentation: docs/experiments.md now describes FORMAT 47 as the first descriptor-only decoded format (not in the DXGI table), the field layout, the cache revision bump, and the reproduction command ctest --preset dev --no-tests=error -R '^startup_vertex_fetch_sscaled_(controls|warp|hardware)$' -V.

Verification (Windows Server 2025, D3D12 WARP, dev and release, head 025f16dd0): x2w_pipe.py win2025 3382 --regex '^(startup_vertex_fetch|startup_buffer_format_word3|startup_compute_request|startup_gfx2hlsl_(export_null|mul24)|startup_packed_(position|target)|startup_shader_cache|startup_indirect_draw_indexed|startup_resource_retire_title|startup_ui_texture_bands|native_startup_request_cache|native_compile_dxil_rekey|patch_manifest)' -> 44/46 passed. The two failures are native_startup_request_cache_warp and _hardware ("compute dispatch output mismatch"). The same two fail with the revision bump reverted (--patch of the reverse of this commit), so they are not caused by this change; I did not look into them further here.

AI-assisted; commands listed were executed locally.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment at 025f16d, no blocking finding. Reading only: the diff and the code around it, against main 212d4b5. Nothing was built or run.

Semantics. Code 47 is BUF_FMT_10_10_10_2_SSCALED (tools/disasm_rdna2.py:1281). docs/experiments.md:6599 says AMD names list fields from the most significant bit, so x is bits 1:0, y 11:2, z 21:12, w 31:22. gfx2hlsl.py:146-147 extracts those fields with an arithmetic >> on int and no division. DST_SEL 1 gives 1.0, since the format is not in DESC_ONE_INTEGER (:181).

Scope not in the body. tbuffer() / load_format() (gfx2hlsl.py:7714-7731) accept any FETCH_FORMATS name, so tbuffer_load_format_* format:[BUF_FMT_10_10_10_2_SSCALED] is now translated as well. No test covers that path.

Cache revision. 29/29cs become 30/30cs in d3d12_draw.inl:393-394, shader_compute_request.cpp:180/191, gfx2hlsl.py:12973/12983, tools/patch_manifest.py:24 and the pinned tests. Side effect: the request readers called by compile_dxil compare against the current revision and 28 only, so a revision-29 capture is now rejected while a revision-28 one is still accepted (shader_compute_request.cpp:295-298, :317-318):

if (x2w::compute_request_key(code, data, root, desc, sa, sb) != expected &&
    x2w::compute_request_key(code, data, root, desc, sa, sb, "x2w-startup-shader-28cs") != expected)
    throw std::runtime_error("compute request key mismatch");

Docs still stale.

  • docs/experiments.md:618 says the word3 table check "checks that the DXGI table equals DESC_FORMAT_CODES"; the check now adds DESCRIPTOR_ONLY_FORMATS (startup_buffer_format_word3_table_check.py:37).
  • docs/startup-runtime.md:209 names revision 30, but :210-213 describe 29 and the following lines 28 and 25. No line says what 30 invalidates.
  • docs/experiments/patch-manifests.md:103 still uses x2w-startup-shader-29b in its example.

Tests (tests/startup_vertex_fetch_sscaled_check.py).

  • "case removed" and "sign extension dropped" (:99-100) edit the translated source, and the data has a negative and a non-negative value in every channel (:79-81). Both can fail only through the translation.
  • "wrong field order" (:108) runs the unmodified translation against expected(order=(1, 0, 2, 3)). Only the reference is swapped, so it shows that x and y differ in the data, which :82 already asserts. The reference decodes with FIELDS (:25), written from the same reading of the name as the translation, so a misread layout would pass on both sides. The layout rests on experiments.md:6599, not on this test.
  • The device case writes descword3 straight into the constants (:68) and never reaches formatted_buffer_supported (d3d12_draw.inl:2677). Dropping case 47: from formatted_buffer.h is caught only by text matches on the header (:84, startup_vertex_fetch_formats_check.py:299, startup_buffer_format_word3_table_check.py:33). startup_buffer_format_word3_check.cpp:91-92 executes the function for 0, 2 and 77; adding 47 there would cover it.

CI. Neither the pr filter (CMakePresets.json:51) nor the Linux Python list (windows.yml python-linux, tests/checks/python-linux) selects startup_vertex_fetch_sscaled_*, startup_vertex_fetch_formats_controls, startup_gfx2hlsl_fract or native_compile_dxil_rekey, so the checks on this PR do not run the new tests. The recomputed keys do run there: startup_shader_cache_key (pr filter), startup_compute_request_offline and startup_buffer_format_word3_table (windows.yml:304, :389).

Merge. git merge-tree against main 212d4b5 is clean; main is still at revision 29. #3410 (24755d1) adds key_parts = G.fnv(b'x2w-startup-shader-29') in tests/startup_gfx2hlsl_ps57in_check.py and compares it with pipeline_key(), and its gfx2hlsl.py hunk edits the lines directly around the revision literal (:12973 here). Whichever merges second has to resolve that hunk and move the test literal to 30.

@Leyukaka

Copy link
Copy Markdown
Collaborator

git merge-tree --write-tree origin/main 025f16dd (main 77d1ba4d) conflicts in two files, both from #3448 (ea68a605):

  • tools/startup/gfx2hlsl.py, pipeline_key: main added the slot 57 .ps57in paragraph to the docstring, next to the revision line. Resolution: main's docstring with your fnv(b'x2w-startup-shader-30').
  • docs/experiments/native-startup-request-cache.md: main added the req_<key>.ps57in sentence above the compute line. Resolution: main's sentence with your x2w-startup-shader-30cs.

Also open: #3435 needs a bump of the same revision (main is at 29/29cs), so whichever of the two merges second takes 31/31cs.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Review of 025f16dd against main 77d1ba4d. Verdict: hold (conflicts), with one rebase item nobody has raised yet. The FORMAT 47 decode itself looks right to me. On the default launcher path (X2W_NATIVE_SHADERS_ONLY=1 since #3449) gfx2hlsl manifests aren't loaded (load_compute_translation: if (native_shaders_only()) { tr.manifest_retry.found(); return nullptr; }). So the decode reaches -Translate runs only.

MUST

  1. Please rebase. Leyukaka gave the resolution of the two conflict hunks above. After that resolution, one test from startup: hash slot 57 pixel entry records in gfx2hlsl request keys #3448 still fails, because its known answers are pinned to revision 29.
    • What I did: exported git merge-tree --write-tree origin/main 025f16dd, resolved pipeline_key as main's docstring plus fnv(b'x2w-startup-shader-30'), then ran python -B tests/startup_shader_cache_key_check.py.
    • It fails at check_slot57_entry: assert gfx2hlsl.pipeline_key(*vector, slot57_entry=entry) == 0x9ffda271506f7dc6 → AssertionError.
    • Under revision 30 the two slot 57 known answers become 0x7bc40f6441693a1c (no layout) and 0xff83a450bf031030 (with b"ia\x00\xfe"). I computed them with an independent FNV-1a: it reproduces main's 0xa837b162afd547ce / 0x9ffda271506f7dc6 / 0x06315afc32bae986 for revision 29, and your 0x1fe778b573d7abcc for revision 30.
    • With those two values replaced, the check passes (startup shader cache key checks: passed).
    • On the same resolved tree, startup_vertex_fetch_sscaled_check.py controls, startup_vertex_fetch_formats_check.py controls, startup_buffer_format_word3_table_check.py, startup_gfx2hlsl_fract_check.py, startup_compute_request_offline_check.py and startup_shader_cache_rekey_check.py all exit 0.

NIT

  1. After the rebase, git grep -n 'startup-shader-29' on the merged tree also finds docs/experiments/patch-manifests.md:103 (x2w-startup-shader-29b), which Leyukaka mentioned. It's only an example, but moving it to 30 keeps the revision grep clean.

Checks I ran: Linux, Python 3.13, the pure-Python checks above. No Windows, WARP or GPU run.

AI-assisted.

# Conflicts:
#	docs/experiments/native-startup-request-cache.md
#	tools/startup/gfx2hlsl.py
@tedin7

tedin7 commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator Author

Merged current main (077bff3ac) and updated the slot-57 revision-30 cache keys for the merge; targeted Linux shader checks pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants