shader: lower compute v_cvt_pk_u8_f32 #1592
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!1592
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1592/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 14:39 UTC · original
Asimmimx:shader/compute-cvt-pk-u8-f32→main· +255 −0 · 4 files · 1 commits · merged 2026-11-24 17:43 UTCChange
Refs #1546. This lowers
v_cvt_pk_u8_f32(VOP3A opcode 350) in the compute translator (tools/compute_store_aot.py), for a restricted set of source values.Semantics. The RDNA 1.0 and RDNA 2 ISA guides give:
The byte select and the merge are fully specified.
flt32_to_uint8is never defined: the guides state no rounding mode, no clamping, and no result for negative or NaN inputs. AMD's machine-readable ISA XML only says "convert … to an unsigned 8-bit integer".docs/experiments.mdalready notes, for the pixel profile, that no public source states this.Restriction. The lowering therefore covers only an S0 that is +0.0 or an integer in [1, 255]. For those values, truncation, every rounding mode and any clamp all give the same byte.
HLSL.
The template is a new
CVT_PK_U8dict, placed afterFLOAT_INLINE. The newelifsits before thev_lshl_add_u32 v, v, n, vbranch. S0 goes throughfloat_wordplus the integer-range check; S1 and S2 go throughalu_word.Fixture. The fixture and controls are in a new
tests/compute_alu_cvt_pk_u8_check.py. It imports the helpers oftests/compute_store_check.py, which is unchanged.v_or_b32andv_subrev_f32.cvt_pk(y, 3, cvt_pk(x, w >> 8, cap)) ^ cvt_pk(0, 1, cvt_pk(1.0, 0, cvt_pk(255.0, 2, w))), with cap =params[0].y= 0xa5c3e17b.w >> 8keeps bits above [1:0]. Across 150 lanes all four byte positions occur, and both 0 and 255 reach the conversion from memory.The expected words come from a separate Python model of the ISA pseudocode. Four lanes are worked by hand: lane 0
0x893ce17a, lane 40x994ae17a, lane 70x943cc87a, lane 100xa03ce1da.The draw must reject:
Controls. These are refused with "Unsupported compute instruction":
-v3,|v3|,-|v3|,clampandmul:2forms;_e64spelling andv[5:6];v_cvt_pknorm_u16_f32.These are refused with "Unverified ALU operand":
v256destination.The existing messages also cover a dropped vmcnt wait, address and guard misuse, and a chain that is too long.
The new CTest is
compute_store_aot_alu_cvt_pk_u8_${adapter}, registered aftercompute_store_aot_mimg_load. A "Guarded float-to-byte insert" subsection is added todocs/experiments.md.Verification
Commit
6c0e5380(main) plus this change,devpreset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.1002:73ff), driver 32.0.21045.29003, debug layer enabledThese also pass with the change:
compute_store_checktranslator controls and itscompile-mimg-atomic-*modes;draw-guard-readanddraw-f32on WARP;tests/docs_links_check.py,tests/bidi_controls_check.py,tests/form_coverage_check.pyandgit diff --check.Open points
tools/ffx_dispatch_aot.pyassumes round-to-nearest with a [0, 255] clamp, but I found no source that confirms it.f32_subreturns exactly +0.0 for one y lane. That is exact under the round-to-nearest-even the profile already assumes, but it stretches the subset's "finite and normal" wording to cover zero.Checklist
AI-assisted (Claude Code).
@tedin7 on GitHub · 2026-11-24 15:01 UTC · original · reviewed
Reviewed
da4d5d7d(tools/compute_store_aot.py,tests/compute_alu_cvt_pk_u8_check.py,CMakeLists.txt,docs/experiments.md).Findings
CVT_PK_U8matches the RDNA 1.0 / RDNA 2v_cvt_pk_u8_f32byte-insert pseudocodeD = (S2 & ~(0xff << 8 * S1[1:0])) | ((flt32_to_uint8(S0) & 0xff) << 8 * S1[1:0])on the agreed domain (+0.0and integers in[1, 255]), where rounding/clamp differences do not apply.S0outside{+0.0} ∪ [1, 255] ∩ ℤ(fractional, negative,-0.0,>= 256.0, Inf/NaN, nonzero inline integers, >32-bit literals), unwaited/unknown/descriptor/exec sources,v256+, input/output modifiers,_e64, and register ranges are all rejected, and results remain data-only.compute_store_aot_alu_cvt_pk_u8_${adapter}inCMakeLists.txtdoes not setFORM_COVERAGE_RECORD, unlike siblingcompute_store_aot_*tests.Verification
python3 tests/compute_alu_cvt_pk_u8_check.py controls: passed.llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encodingon the fixture'sv_cvt_pk_u8_f32forms: passed.python3 tests/docs_links_check.py: passed (16 Markdown files, 344 links).python3 tests/bidi_controls_check.py: passed (1253 tracked files)./O2):ctest --preset devon the 41offscreen_check/compute_*_warptests (includingcompute_store_aot_alu_cvt_pk_u8_warp): 41/41 passed (58.19s).ctest --preset releaseon the same 41 tests: 41/41 passed.AI-assisted; commands listed were executed locally.
@Jess-Doit on GitHub · 2026-11-24 16:46 UTC · original · reviewed
Hardware check on NVIDIA, which adds a data point to the RX 6600 and WARP runs. Nothing below is a code change.
Tested:
da4d5d7dmerged onto mainc864f138.docs/experiments.mdconflicts with main (see the end of this review). For the build I kept this PR's version of that file; no code conflicted.Environment:
10de:1c03), driver 32.0.15.6094 (Pascal).1414:008c.Ran:
python -B tests/compute_alu_cvt_pk_u8_check.py controls: passed.ctest --preset {dev,release} --no-tests=error -R '^compute_store_aot_(alu_cvt_pk_u8_(warp|hardware)|warp|hardware)$' -V: 4/4 in Debug and 4/4 in Release. Every dispatch readcompared_words=320 mismatches=0withdebug_errors=0 debug_warnings=0, on the 1060 and on WARP.So each one changed the readback there, and
uint(asfloat(S0))gives the exact byte for +0.0 and the integers 1–255 on this driver.Reading of the lowering:
0and the bit patterns0x3f800000–0x437f0000whose value is an integer, which is +0.0 and 1.0–255.0.alu_word, and the select is masked to[1:0]before the shift, as the ISA pseudocode does.compute_store_aot_alu_cvt_pk_u8_${adapter}has noFORM_COVERAGE_RECORD, unlike the sibling tests (#1591 sets it).Merge conflict:
docs/experiments.mdcurrently conflicts with main, next to the new "Guarded float-to-byte insert" section. It needs a rebase or merge before this can land.AI-assisted (Claude Code); the commands listed were run locally.
@tedin7 on GitHub · 2026-11-24 17:08 UTC · original · reviewed
Re-review at
head_sha:d03f2264dbad398a0697aacd76fec67f25e9e18d(previously reviewed atda4d5d7d).Findings
No P1/P2. No defect found.
main. I compared the patch of the old commit with the patch of this one (git range-diff, and a diff of the added and removed lines): the PR's own content is unchanged. Even the changed lines are the same; only the surrounding context differs.git merge-treeof the head against currentmain(80f413a7at the time) reports no conflicts (treebfcb62d4).Verified
Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware
ctestfor this head (no Windows runner in this pass), so thedrawmode is covered only by the unchanged patch content and the earlier Windows results on the previous head.python3 -B tests/compute_alu_cvt_pk_u8_check.py controls-> exit 0.llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encodingassemblesv_cvt_pk_u8_f32 v1, v2, v3, v4andv_cvt_pk_u8_f32 v1, 1.0, 2, v4.python3 -B tests/docs_links_check.py-> 16 files, 351 links OK.git diff --check HEAD^ HEADclean.<< 3uto<< 2uin theCVT_PK_U8template;controlsfails with anAssertionError(exit 1). Restored withgit checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-24 17:42 UTC · original · reviewed
Verified at
head_sha:d03f2264dbad398a0697aacd76fec67f25e9e18d(0 P1, 0 P2).Scope & Semantics
tools/compute_store_aot.py,tests/compute_alu_cvt_pk_u8_check.py,CMakeLists.txt(test-onlycompute_store_aot_alu_cvt_pk_u8_{hardware,warp}), anddocs/experiments.md.v_cvt_pk_u8_f32(((S2 & ~(0xffu << ((S1 & 3u) << 3u))) | ((uint(asfloat(S0)) & 0xffu) << ((S1 & 3u) << 3u)))) matches AMD RDNA 1.0/2 ISA VOP3A opcode 350 on the agreed exact domain (+0.0or integer in[1, 255]), with static constant S0 checked strictly (0or0x3f800000..0x437f0000withis_integer()), refusing-0.0, fractions, negatives,>= 256.0, infinities, NaNs, subnormals, modifiers, and_e64.Verified
git diff --check origin/main...HEAD-> cleanpython3 tests/docs_links_check.py-> passed (16 Markdown files, 351 links)python3 tests/bidi_controls_check.py-> passed (1280 tracked files)python3 tests/compute_alu_cvt_pk_u8_check.py controls-> passedllvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding:v_cvt_pk_u8_f32 v1, v2, v3, v4(01 00 5e d5 02 07 12 04)--preset dev):offscreen_checkbuilt (3.37s),ctest --preset dev -R 'compute_store_aot_alu_cvt_pk_u8'2/2 passed (4.53s:compute_store_aot_alu_cvt_pk_u8_warp,compute_store_aot_alu_cvt_pk_u8_hardware)/O2(--preset release):offscreen_checkbuilt (1.09s),ctest --preset release -R 'compute_store_aot_alu_cvt_pk_u8'2/2 passed (4.34s)& 3uto& 2uinCVT_PK_U8intools/compute_store_aot.py->compute_alu_cvt_pk_u8_check.py controlsfailed as expected.0x437f0000(255.0) to0x43800000(256.0) intools/compute_store_aot.py->compute_alu_cvt_pk_u8_check.py controlsfailed as expected (256.0no longer rejected).AI-assisted; commands listed were executed locally.