Repository navigation
Translator: decode every GFX10 buffer format a V# can carry (65 of 77 codes), shared store encode — 2.4M elements on AMD hardware, 0 mismatches - #2022
Conversation
Raw buffer_load_format_xyzw, tbuffer_load_format_xyzw and buffer_store_format_xyzw / tbuffer_store_format_xyzw kernels per format on the AMD GPU (tools/hw_oracle), compared word for word with a CPU model. Formats are mapped by name because GFX11 numbers them differently; the twelve 10_11_11 / 11_11_10 non-FLOAT codes and the two SCALED 10_10_10_2 codes have no GFX11 spelling. On a Radeon 880M (gfx1150, RDNA3.5, not RDNA2): 1,264,744 elements over 63 formats, V# and tbuffer, loads and stores, 0 mismatches; --negative-control shows a wrong V# format is caught. docs/buffer_formats.md records the measured rules (SCALED stores convert as NORM, float stores round toward zero and saturate, a 2-bit SNORM half rounds away, NaN payloads, channel fill) and where the translator's older stores differ. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Gen.FORMATS now holds 65 of the 77 codes a V# or MTBUF can carry. Added: 8/16-bit UINT and SINT, every USCALED and SSCALED, SINT of the wider families, 10_11_11_FLOAT and 11_11_10_FLOAT (unsigned 5-bit-exponent floats), and the SNORM / SCALED / UINT / SINT members of the 10_10_10_2 and 2_10_10_10 families. The twelve non-FLOAT 10_11_11 / 11_11_10 codes stay unsupported: GFX11 has none, so nothing measures them. Stores follow what the Radeon 880M did (RDNA3.5, not RDNA2): SINT and UINT saturate, NORM stores round the exact product (Gen.norm_encode_exact), a SCALED store converts as its NORM format, the small floats round toward zero and saturate to the largest finite value (Gen.ufloat_encode_bits), and a half rounds away from zero in a 2-bit SNORM field. Existing formats keep their emission: with the table cut back to its old 32 codes the output for all 182 runtime/test/shaders is byte-identical to before. tests/semantic/test_buffer_formats_all.py holds the translation to the hardware model for every added format (loads through the V# and tbuffer, stores, hand-worked values) and pins two older stores that differ from the hardware as expected failures. cs_fmt_all.asm is the GPU fixture (28 loads, 15 stores; AMD Radeon 880M and NVIDIA RTX 5070). docs/design.md gets the contract row. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Every buffer_store_format_* site inlined the encode arm of every format, so the larger format table tripled the dynamic-store sites (cs_store 169 KB -> 503 KB), the kind of growth that hit the SPIR-V id bound for loads (ItsNotRexed#884, dcd8ecf). The encode is now one function and the element size another, each store site a call plus the dword stores, like the shared decode. Semantics are unchanged (GPU fixtures cs_store, cs_fmt_*, cs_oob_tail, cs_oob_select and cs_fmt_all pass on a Radeon 880M and an RTX 5070; the semantic suite and the hardware model checks pass). Sizes: cs_store 169 KB -> 90 KB, cs_fmt_sint32 256 -> 269 KB, cs_fmt_1010102 113 -> 163 KB, cs_fmt_xy_xyz 468 -> 406 KB, cs_oob_tail 71 -> 96 KB (load decode arms). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…at still is not Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Flyander
left a comment
There was a problem hiding this comment.
The hardware oracle cannot distinguish the second component of two-component stores on this path. store_inputs() sets
[3] = r[1] for every two-component format ( ools/buffer_format_fuzz.py:246-248), and
un_stores() feeds those rows to the GPU. That makes (x,y) and (x,w) identical, even though the project's format notes say the 880M stores (x,w) while the translator emits (x,y), and explicitly state RDNA2 is still unmeasured (docs/buffer_formats.md:70,166-167). So the reported zero-mismatch total does not validate the second component for these formats. Please make y and w distinct in the probe and report this case as unresolved for the target RDNA2 until measured, or exclude it from the validated pass count.
Flyander
left a comment
There was a problem hiding this comment.
Clarifying the finding in plain text: tools/buffer_format_fuzz.py sets r[3] equal to r[1] for every two-component format before run_stores sends those values to the GPU. This cannot distinguish a translator store using x,y from hardware behavior using x,w. docs/buffer_formats.md says this differs on the 880M and that RDNA2 is still unmeasured. Please use distinct y and w and mark the target behavior unresolved until measured, or exclude these cases from the validated count.
|
Tested 357945f on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass. The PR's diff applied cleanly to
|
…, w) routing apart store_inputs() gave y and w the same value for two-component formats, so run_stores could not tell the translator's (x, y) from the Radeon 880M's (x, w) for buffer_store_format_*; the zero mismatches did not validate the second component. The probe now uses a different value in every register and also runs _xy stores. The hardware model routes a two-component buffer_store_format_* to (x, w) (_xy: (x, 0)); tbuffer_store_format_* takes (x, y) like the translator. Those stores are counted as known-difference elements, outside the validated count: 1,330,469 validated elements, 0 mismatches, plus 26,523 known-difference elements. The translator is unchanged (RDNA2 unmeasured); the difference is pinned as an expectedFailure in test_buffer_formats_all.py. docs/buffer_formats.md and the design.md row say so. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks @Flyander, you were right: store_inputs() gave y and w the same value for two-component formats, so the zero-mismatch total could not tell the translator's (x, y) from the 880M's (x, w) for those stores. Fixed in a93da2c. The probe now uses a different value in every register and also runs _xy stores. New numbers (Radeon 880M, gfx1150, RDNA3.5, not RDNA2; The translator is unchanged because RDNA2 is unmeasured. The difference is pinned as an expectedFailure in test_buffer_formats_all.py, and docs/buffer_formats.md and the design.md row say the validated count excludes it and that the RDNA2 behaviour is unresolved until measured. AI-assisted (Claude Code). |
|
Tested |
Flyander
left a comment
There was a problem hiding this comment.
The updated head resolves my validation concern: two-component stores now use distinct y/w values and exercise both xyzw and xy forms. The 26,523 Radeon 880M differences are kept out of the validated count and documented as unresolved for target RDNA2, while tbuffer stores remain separately validated. I reviewed the updated code and docs; I did not run tests.
|
Tested
No game files. AI-assisted (Claude Code). |
|
RDNA2 run of Setup. Ryzen 7 9800X3D iGPU (Raphael, gfx1036, RDNA2, PCI 0x13c0), the Linux DRM backend from #1265 (engine 10.0, native GFX10 format numbers, no name mapping), CachyOS, kernel 7.3.5, clang 23.1.5. Full run, same settings as yours (
The three open points on RDNA2. Single
What this settles:
The 14 GFX10-only codes. Without Not checked: RDNA2's d16 forms, and the console's own gfx1013 (gfx1036 is the same RDNA2 generation, a different chip). AI-assisted (Claude Code). No game files. |
|
@AwkGrep256, thank you, that's exactly the measurement that was missing. RDNA2 (gfx1036) gives the same totals as the 880M: 1,330,469 validated, 0 mismatches, and 26,523 known-difference elements. On all three open points it does what the 880M does, and the 14 GFX10-only codes validate against the model. To keep this PR as reviewed, the translator stays unchanged here. A follow-up stacked on #2022 will make the translator match RDNA2 on the three points:
It will also add the GFX10-only codes your run validated, and fix AI-assisted (Claude Code). |
# Conflicts: # docs/design.md # tests/test_shader_checks.py
…ture Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A correction to what I wrote above. "Two-component stores take (x, w) on RDNA2" holds only when the V#'s channel selectors are identity (XYZW), and that's what this PR's oracle used. With the runtime's X,Y,0,1 selectors, gfx1036 writes (x, y); the existing narrow-integer fixtures measured that. Across 16 selector sets on the 880M, the second component is y exactly when The follow-up, which makes the translator match RDNA2 on all three points with that rule, is stacked on this PR. @AwkGrep256, your measurement stands as it was; only my reading of it was too broad. AI-assisted (Claude Code). |
|
Tested
AI-assisted run. |
|
I ran head 90b31ac over the full corpus: 26,503 shaders, LLVM 23.1.5, default options. The head already contains
Counts only, no game files. AI-assisted (Claude Code). |
Conflicts in tools/rdna2spirv.py and docs/design.md. Main had meanwhile fixed three of the older stores this branch found (SHADER-358: f16 toward zero; SHADER-364: exact NORM rounding and the DST_SEL-dependent routing of a two-component format), so the merge keeps main's mem_f16, encode_norm_bits and 2-component swizzle, applies them to the new SCALED kinds as well, and passes the swizzled channels into the shared typed-store encode function (Gen.format_encode_call, now 29 parameters). Gen.norm_encode_exact and EXACT_NORM_CODES go: encode_norm_bits does the same job. The three expectedFailure tests pass now and pin the older stores to the oracle's words; cs_fmt_all's 16_16_SINT store is (x, 0) through its identity-selector V#. design.md keeps one Typed buffer formats row; test_buffer_store_format's unsupported-format example is BUF_FMT_INVALID (8_USCALED is supported now). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Merged main (conflict in tools/rdna2spirv.py); rebasing would need a force-push, which I can't do. Happy for this to be squash-merged. AI-assisted (Claude Code). |
ItsNotRexed#2022 now carries main's SHADER-358 / SHADER-364, which did what the stores commit did for the three older stores: f16 format stores toward zero (Gen.mem_f16), exact NORM rounding (Gen.encode_norm_bits) and the DST_SEL-dependent routing of a two-component V# store (identity selectors: x, w; the runtime's X,Y,0,1: x, y; tbuffer: x, y). This merge keeps their translator code, drops the duplicate encoders (norm_encode_exact, the y-route flag) and what is left of this branch is: the 12 non-FLOAT 10_11_11 / 11_11_10 codes (Gen.FORMATS now holds all 77, gfx1036 validated them: @AwkGrep256, ItsNotRexed#2022), the oracle (one store model per path, XY01 store runs, all 77 codes by default on a GFX10 device), the larger cs_fmt_all fixture, and the docs. Co-Authored-By: AwkGrep256 <AwkGrep256@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Conflicts in docs/design.md (main's Buffer format stores row kept, the "and the formats of the Typed buffer formats row" suffix and the Typed buffer formats row added once) and tests/test_shader_checks.py: TOTAL counts main's 12 fixtures (three mesh, ps_tex, ps_imgatomic, five compute, ps_ssharp, vs_base_ids) plus cs_fmt_all, so + 13. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Conflicts: tools/rdna2spirv.py (main's x_round state next to this branch's fmt_enc_fn, and the function types of both: both kept), docs/design.md (main's rows, our Typed buffer loads sentence re-applied), tests/test_shader_checks.py (TOTAL: main's 13 plus cs_fmt_all = 14, and both mock branches kept; 75 tests pass). Main's typed-buffer work that overlaps (aa2988c: byte size of the format from one table, SHADER-429: DST_SEL=1 on out-of-bounds typed loads) merged without conflict and takes this branch's formats from Gen.FORMATS. Ten tests in test_mutations, test_cmp_class_f64, test_loop_ballot_barrier and test_vcmp16_opsel fail on origin/main itself, with and without this branch. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested 1674b1b (merge base 03b09a0) on NVIDIA GeForce RTX 5080, Linux 580.65.06: pass Tested the PR head merged with current main
Line-by-line against my main run (results that differ from main):
PR-specific: this PR adds Not run: the full AI-assisted (Claude Code). |
|
Tested
Not run: AI-assisted (Claude Code). |
|
Tested
Note: AI-assisted (Claude Code). |
…RM rounding, two-component routing), all 77 codes @AwkGrep256 ran tools/buffer_format_fuzz.py on a real RDNA2 (gfx1036, ItsNotRexed#2022): the same totals as the Radeon 880M, 0 mismatches, and 199,144 elements of the 14 GFX10-only codes, also 0. This follows both. - 16_FLOAT, 16_16_FLOAT and 16_16_16_16_FLOAT format stores round toward zero, saturate at +-65504 and keep a NaN a NaN (Gen.ufloat_encode_bits, now with an optional sign). d16 data rounding (ItsNotRexed#1759) is not touched. - Every UNORM, SNORM and SCALED store rounds the exact product once (Gen.norm_encode_exact): 0.3 * 65535 stores 19661, not 19660. - A two-component format stored through a V# takes channel y as its second component when DST_SEL_Y is Y and DST_SEL_Z a constant (the runtime's X,Y,0,1: gfx1036 narrow-integer fixtures, gfx1150), and channel w otherwise (identity XYZW, @AwkGrep256 and gfx1150); _xy then writes (x, 0). tbuffer keeps (x, y). A probe with XYZW alone would have shown (x, w) for every V# and broken the runtime's selectors, which the oracle now also covers (XY01 runs for the two-component formats). - Gen.FORMATS has all 77 codes: 30-35 and 37-42 (10_11_11 and 11_11_10 with UNORM..SINT) join. - buffer_format_fuzz: the model has one store route per path, select_formats runs all 77 codes by default on a GFX10 device, the known-difference count is gone (0 on the 880M). The three expectedFailure tests pass; the fixtures that baked the old behaviour (cs_fmt_sint32, test_translate f16 and int32 store tests, test_value_semantics) take the measured words. Sizes: cs_store 206 KB on main, 125 KB here. Co-Authored-By: AwkGrep256 <AwkGrep256@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
What and why
Claimed in #1548. @Vonsek's #1811 showed that 88,924 of the 90,316 formatted MUBUF accesses in the game take their format from descriptors the executable writes. Any GFX10 buffer code can therefore show up at run time, and the translator has to decode it. This PR teaches the translator to decode every GFX10 buffer data format a V# or MTBUF can carry, and to encode it wherever the format can be stored.
Formats:
Gen.FORMATSnow covers 65 of the 77 GFX10 buffer codes. A V#'s FORMAT field is 7 bits, so codes from 128 up are image-only. New here:10_11_11_FLOATand11_11_10_FLOAT, unsigned floats with a 5-bit exponent;10_10_10_2and2_10_10_10families.mainadded the narrow UINT/SINT codes andtbuffer_storein parallel; their table entries are kept. The twelve non-FLOAT10_11_11/11_11_10codes (30–35, 37–42) stay unsupported, because GFX11 has none of them and nothing could measure them.Hardware behaviour followed for the new formats (measured on a Radeon 880M):
Module size: dynamic-format stores now call one shared encode function per module, as the dynamic decode already did since dcd8ecf.
cs_storedrops from 206 KB onmainto 90 KB. Shaders that only load grow by about 26% from the extra decode arms, which are emitted once per module.Hardware oracle:
tools/buffer_format_fuzz.pyruns raw buffer/tbuffer load and store kernels for each format on an AMD GPU throughtools/hw_oracle, and compares them word for word with a CPU model.docs/buffer_formats.mdhas the measured rules and the per-format counts.Found in the existing translator, not changed here (measured on RDNA3.5, so it needs an RDNA2 run before anything changes):
16_FLOAT/16_16_FLOAT/16_16_16_16_FLOATstores round to nearest and overflow to infinity, while the 880M rounds toward zero and saturates at 65504.buffer_store_format_xyzwinto a 2-component format writes (x, y). The 880M writes (x, w).The first two are pinned as
expectedFailuretests, so they flag themselves once fixed.Out of scope, untouched: #1529 (xy/xyz formats and
32_32_32_UINT) and #1759's d16 rounding.Tested
Radeon 880M (gfx1150, RDNA3.5, not RDNA2; GFX11 numbers formats differently, so they're matched by name),
buffer_format_fuzz --oracle hw:--negative-controlcatches a wrong V# format.Codes 46 and 47 (
10_10_10_2SCALED) have no GFX11 spelling. They follow their measured2_10_10_10sibling and aren't hardware-checked.GPU fixtures on the Radeon 880M and the RTX 5070: the new
cs_fmt_all(28 loads, 15 stores, all 316 words checked) pluscs_store,cs_fmt_1010102,cs_fmt_sint32,cs_fmt_xy_xyz,cs_oob_tail,cs_oob_selectandcs_tbuffer_storepass on both.All 200 test shaders translate and pass
spirv-val.Semantic suite: all pass, including the new
test_buffer_formats_all.py.test_translategives 500 passed, 2 skipped;test_shader_checks60 OK;test_tool_stdout_encodingOK.RDNA2 itself: not measured. Owners of a gfx103x GPU could run
py -I tools/buffer_format_fuzz.py --oracle hwthrough Tools: a Linux backend for the hardware oracle (libdrm_amdgpu), and its first runs on RDNA2 #1265's Linux backend.Checklist
docs/design.md, with how it was confirmed;docs/buffer_formats.mdcs_fmt_all.asm) and semantic tests for the new kindsAI-assisted (Claude Code).
🤖 Generated with Claude Code