startup: run every gfx2hlsl vertex-fetch buffer format #1696
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1696
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1696/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Asimmimx on GitHub · 2026-11-24 17:18 UTC · original
Asimmimx:startup/vertex-fetch-formats-check→main· +241 −0 · 3 files · 1 commits · merged 2026-11-24 17:39 UTCRefs #1149.
Change
tools/startup/gfx2hlsl.pylowerstbuffer_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. OnlyBUF_FMT_8_UINTandBUF_FMT_8_UNORMwere ever run, both bystartup_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_FLOATand32_32_32_32_FLOAT. That left their shifts, UNORM scales, binary16 widening, unalignedldu()reads and default W untested.This PR adds a check only. The translator does not change.
tests/startup_vertex_fetch_formats_check.pyfollowsstartup_r8_uint_check.py. For each format it:tbuffer_load_format_xyzwfrom vertex-buffer slot 1;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 for8_UINT).8_UNORM,8_UINT8_8_UNORM16_16_UNORM16_16_FLOAT8_8_8_8_UNORM32_FLOAT…32_32_32_32_FLOATLoad())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, sof16tof32and the pass-through are exact on any adapter.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 ofldu();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) andstartup_vertex_fetch_formats_{warp,hardware}, next tostartup_r8_uint.docs/experiments.mdgets a subsection under "Startup vertex fetch from an unsigned byte".Results
Commit
1e2bbb5bon18a2942a. Windows 11 26300.9974, DXC 1.8.2502.11, debug layer on.There were no skips.
startup_r8_uint_warp,docs_links_check.pyandbidi_controls_check.pystill pass.ctest --preset dev -N -R vertex_fetch_formatslists the three tests.Not covered: the formats the table refuses, and the
_x,_xyand_xyzvariants. Those variants share the same table and only write fewer registers.AI-assisted (Claude Code).
gfx2hlsl lowers tbuffer_load_format_* for ten buffer formats from a table of HLSL expressions, but only BUF_FMT_8_UINT and BUF_FMT_8_UNORM were ever run (startup_r8_uint). The other eight entries, their field shifts, UNORM scales, binary16 widening, unaligned ldu() reads and default components had no check. tests/startup_vertex_fetch_formats_check.py follows startup_r8_uint: it translates a source-built vertex stage with one tbuffer_load_format_xyzw from vertex buffer 1 per format, calls the generated vertex body from a compute wrapper and reads back 16 vertices through offscreen_check --compute-store-case. The expected words come from an independent decode of the same bytes (little-endian fields, n / (2^bits - 1), binary16 to binary32, missing X/Y/Z 0 and W 1.0 or 1). Sub-dword formats use strides and offsets at mixed byte alignments; UNORM is compared as round(v * (2^bits - 1)), everything else bit for bit. 25 wrong references and 7 mutated translations must fail the readback. All ten formats match on WARP and on an RX 6600. Registered as startup_vertex_fetch_formats_{controls,warp,hardware}.@tedin7 on GitHub · 2026-11-24 17:23 UTC · original · reviewed
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
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.missing = [0,0,0,0]: controls fail ("no wrong reference changes BUF_FMT_32_FLOAT"). Restored, green.f16tof32(w >> 16)->f16tof32(w); 32_32_FLOAT missing WU(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
stride, offset, bits, kind, countandlabelare unpacked and unused.old in sourcechecks). Acceptable here because the same strings drive the runtime mutations and the readback is the real check.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.