shader: unpack compressed f16 pixel exports #395
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!395
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-395"
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?
@Loggerten on GitHub · 2026-11-24 02:54 UTC · original
Loggerten:fix/compressed-exports→main· +1688 −1338 · 2 files · 7 commits · openWhat
EXP with
comprpacks two f16 channels per source dword (low half first), so four channels come from two VGPRs.export()refused every compressed export outright; the pixel color and depth targets now unpack each dword's low and high half instead, reusing the existing half-flag store path (legacyF16ToF32). Primitive, primitive-param, param and position targets stay refused, so thetranslatetally still counts the real remainder.Why
victory translatetallies compressed exports as a per-program failure reason (translate.rscompressed), so every pixel program that finishes with a compressed MRT export is dropped. Unpacking them removes that entire reason for the common render-target case.Verified
emit::lower::tests::a_compressed_export_unpacks_two_f16_channels_per_dword(a PS program: twov_mov_b32into v0/v1, thenexp mrt0, v0, v0, v1, v1 done compr): panics on main witha compressed export, passes with this change.cargo test -p victory-shader: 57 passed, 0 failed (56 baseline + 1).cargo fmt --check -p victory-shaderandcargo clippy -p victory-shader --all-targets: clean (one pre-existing dead-code warning on main, untouched).cargo xtask policy: 151 files ok.AI-assisted (Hermes Agent); I reviewed the diff and ran the tests and gates myself.
@CesarLopesO on GitHub · 2026-11-24 03:00 UTC · original
Independent validation — Debian 13 (Trixie)
I tested the current PR head
9c760ablocally on Debian 13.Results
cargo test --locked -p victory-shader— 57 passed, 0 failed.cargo clippy --locked -p victory-shader --all-targets— completed successfully.rustfmt --edition 2024 --check crates/victory-shader/src/emit/lower.rs— passed.cargo xtask policy— passed (151 files).git diff --check— passed; working tree clean.The compiler reports an unrelated
dead_codewarning forconstant_colorincrates/victory-shader/src/emit/mod.rs:450. No warnings were reported in the changed file.The compressed f16 pixel export regression test passes on Linux, and the full shader test suite passes.
No game files or game data were used.
Thanks for the fix!
@CaravelaLabs on GitHub · 2026-11-24 14:11 UTC · original
@Loggerten the float color unpack matches. On
c0d3769, a compressed export of f16 2, 1, 1, 3 stores f32 2, 1, 1, 3. Low half first, high half shifted by 16, thenlegacyF16ToF32.Integer outputs are not. The convert runs before the component-type check, so a non-float target stores those f32 bits as
storeOutput.i32. A uintSV_Target(component type 5, which the signature parser uses for uint16 and uint32) of a compressed export whose dword is0x00020001lowers successfully and stores0x33800000and0x34000000— f16(1) and f16(2) widened — not the integers 1 and 2. Seegithub.com/Marvisak/VIctory@c0d3769751/crates/victory-shader/src/emit/lower.rs (L6649-L6673)The depth path this change newly allows does the same. Channel 1 of a compressed
mrtz, alreadySV_StencilRefhere, is stored as0x34a00000when the high half is 5, not the integer 5.The new test only checks that a float target returns Ok, so it does not catch this. A uint or stencil output should stay refused, or be stored as an integer, not passed through
legacyF16ToF32.AI-assisted; Linux shader-lib probe, run on this machine.
@Loggerten on GitHub · 2026-11-24 14:38 UTC · original
@CaravelaLabs You're right, and the probe's hex matches the code: the unpack ran
legacyF16ToF32before the component-type check, sostoreOutput.i32stored the f32 bit patterns (0x33800000/0x34000000, and the stencil's0x34a00000) instead of the channel values.Fixed in 8c3e0d4. On the console
compris f16 by definition, so there is no integer to store honestly: the raw halves as integers are the f16 bits, and converting through f32 truncates to zero. Only an output element the host declares a 32-bit float unpacks now; a uintSV_Targetand the stencil half of a compressedmrtzkeep thea compressed exportrefusal, so thetranslatetally still counts those programs.New tests
a_compressed_export_to_a_uint_target_stays_refusedanda_compressed_depth_export_with_stencil_stays_refused(through a newlowers_ps_withhelper that takes the output elements) assert the refusals; both lower successfully on the previous head, so they catch exactly this.Verified on the new head, test-merged with current
main(ffe310e):cargo test -p victory-shader --locked99 passed / 0 failed (97 + the two new),cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warningsclean,cargo xtask policy154 files ok.AI-assisted (Hermes Agent).
@CaravelaLabs on GitHub · 2026-11-24 15:06 UTC · original
Thanks @Loggerten — refusing the non-float case is the right call, and it holds on
8c3e0d4.A compressed export now stays refused unless that output element is a 32-bit float. The convert runs only after that check, so a uint
SV_Targetand the stencil half of a compressedmrtznever reachlegacyF16ToF32.a_compressed_export_to_a_uint_target_stays_refusedanda_compressed_depth_export_with_stencil_stays_refusedpassed. The float unpack still lowers. I did not re-measure the stored bits; that path is unchanged. Linux, rustc 1.98.1.AI-assisted; tests run on this machine.
@Marvisak on GitHub · 2026-11-25 00:31 UTC · original · edited 2026-11-25 09:19 UTC
Automated triage for the maintainers.
Needs work.
Re-reviewed at
1c4c480. Since the last pass:lowers_ps_withnow setsview_marks: false, andcheckpasses.exp mrtz ... compr: refused, as before. The comment now cites Mesa'ssi_export_mrt_z, which is public.v_cvt_pkrtz_f16_f32gate is ready. In this head, though,Lower::exportrefuses a compressed export only when the target is notTarget::Color. Every compressed color export to a 32-bit floatSV_Targetis still unpacked throughlegacyF16ToF32, with no check on how its source was produced. That is the unconditional FP16 assumption from the last pass, and it would read UNORM16/SNORM16 halves as f16.Please do one of two things. Push the
v_cvt_pkrtz_f16_f32producer gate, with a test showing that a compressed export from another source stays refused. Or say plainly that this PR waits until then. The tests still check only whether lowering succeeds or is refused, not the stored values.CI: passing (
check).Generated by Claude Code
@Loggerten on GitHub · 2026-11-25 08:20 UTC · original
Dropped
mrtz comprfrom the unpack. Mesa reads that form as UINT16_ABGR (stencil and sample mask), not depth, so the code now citessi_export_mrt_zand stays refused there.On the FP16 proof: the
expencoding carries no format field, so a shader cannot show that a render target is FP16 by itself. The only in-shader proof is av_cvt_pkrtz_f16_f32producer.The unpack must therefore gate on that producer. I built the gate, but its positive test needs a pixel harness fix before it ships. Until then the branch keeps the conservative refusal. Rebased onto main and CI is green.
@catminou4 on GitHub · 2026-11-24 13:20 UTC · original · approved these changes
Restricts compressed (
compr) pixel exports to color/depth targets and unpacks two f16 channels per source dword (odd channel = high half), keeping everything else refused. TheTarget::Color(_) | Target::Depthguard is the right shape, andch % 2 == 1matches the "low half first" packing the ISA documents.The new lowering test
a_compressed_export_unpacks_two_f16_channels_per_dwordruns on macOS (it's inlower.rs's unit tests, not the Windows-gatedvalu_tests) and builds a real PS with anexp ... compr— good.Verified locally: test-merge with current main (
ffe310e) clean;cargo test -p victory-shader --locked(macOS arm64, rustc 1.98.1) green — the newvalu_testsexecution cases are#[cfg(windows)]-gated like the rest of that suite, so they will run on the Windows CI lane, not here.: 97 passed / 0 failed / 1 ignored (one more than main's 96 — the new test).@Loggerten on GitHub · 2026-11-26 20:08 UTC · original
Gate pushed in
37ff52e: a compressed export lowers only when every source dword comes fromv_cvt_pkrtz_f16_f32(followed through plainv_mov_b32copies); any other producer stays refused, so UNORM16/SNORM16 halves are never widened as f16.mrtzand non-float targets stay refused as before.The pixel-harness fix turned out to be in the
expword itself: undercompr, the second word names two packed source dwords at bits 0 and 8, so the old0x0000_0100encoding fed v0/v1 no matter which registers the test named. A helper (exp_compr) now builds the word, correct by construction. (view_markshas no effect on these pixel tests.)Tests: a pkrtz-fed compr export lowers; a mov-fed one stays refused; the uint-target test feeds pkrtz so only the target type refuses it. Windows run: 251 shader tests pass; workspace clippy clean.
63bcca4) into fix/compressed-exports 3bda6654c2@Loggerten on GitHub · 2026-11-26 20:15 UTC · original
Merged current main (
63bcca4) into the branch, now head3bda665(merge keeps main's newdef_site/def_instand thef16_packedgate). Merged-tree run on Windows:cargo test -p victory-shader306 passed / 3 ignored;cargo clippy --workspace --all-targets --locked -- -D warningsclean.@Loggerten on GitHub · 2026-11-26 20:21 UTC · original
CI caught the asset-policy size cap: the merged
lower.rswas 529654 bytes, over the 512 KiB limit.356f328moves the test module toemit/lower_tests.rsunchanged;lower.rsis now 472754 bytes andcargo xtask policyreports 192 files ok. Merged-tree Windows run after the move: 306 passed / 3 ignored.@andrewpozdnakov7-jpg on GitHub · 2026-11-26 20:56 UTC · original
I combined
356f328with #470 ated2d2c8inec7c106. Both branches moved the lowering tests into the same new file. The merge keeps the compressed-export tests and the wave-prefix scan test, with both production changes intact.The new Windows readback test packs four distinct values with two
v_cvt_pkrtz_f16_f32instructions and copies the dwords through plainv_mov_b32before the compressed export. On app-local Agility 1.620.2 / WARP 1.0.22, all 16 pixels read back[0.5, 1.0, 2.0, 4.0]in three runs. The refusal cases for non-FP16 input, a UINT target and compressed depth/stencil passed, and the min-prefix DXIL validated. The full WARP sweep had 305 passed, 4 failed and 3 ignored, with the same gather, two lane-permute and edge-flagged mesh failures observed on main. Strict Clippy in both feature configurations and the asset policy check passed.@Loggerten, this is a tested resolution if either PR lands first. Please keep the Git author or use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if you fold the resolution or readback test into another commit.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.