Shaders: v_cvt_f16_u16 (0x050) and v_cvt_f16_i16 (0x051) have no hardware test #866
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#866
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@kss306 on GitHub · 2026-11-24 12:58 UTC · original
v_cvt_f16_u16(VOP1 0x050) andv_cvt_f16_i16(VOP1 0x051) are implemented incrates/victory-shader/src/emit/lower.rsbut have no hardware test incrates/victory-shader/src/emit/valu_tests.rs. Their reverse-direction siblingsv_cvt_u16_f16(0x052) andv_cvt_i16_f16(0x053) are exhaustively tested inv_cvt_u16_and_i16_f16_saturatewith 16 cases.Implementation evidence
lower.rs,valu16_op(), around line 4388:The
Shl 16+AShr 16sign-extension forv_cvt_f16_i16is unique to this instruction path.Missing test
valu_tests.rscontainsfn v_cvt_u16_and_i16_f16_saturate()(line 674) using opcodes0x052/0x053. Opcodes0x050and0x051do not appear anywhere in the test file.The sibling test structure with
vop1(0x001, 0, 128)to clear the high half applies directly.Interesting edge cases
0x00000x00000x00000x00010x0400(subnormal)0x04000x7FFF0x78000x78000x80000x78000xF8000xFFFF0x7C00(inf)0xBC00The case
v_cvt_f16_u16(0xFFFF)is the one u16 value where the rounding mode changes the output: before PR #422 it rounds toward zero to 65504.0 (0x7BFF); after PR #422 it rounds to nearest even to infinity (0x7C00). The sign-extension casev_cvt_f16_i16(0x8000)= convert -32768 is exactly representable and not rounding-sensitive.Suggested test
Add
fn v_cvt_f16_u16_and_i16_match_rdna2()tovalu_tests.rsmirroring the existing sibling test:Note: the expected value for
0xFFFF → v_cvt_f16_u16is0x7C00(infinity, nearest-even rounding per PR #422). If the test is written before #422 merges, change that case to0x7BFFand update after the PR lands.The test skips gracefully when no SM 6.6 device is available and runs on WARP. No game data needed.
AI-assisted: found with Kiro (Claude) and independently confirmed by five separate analysis passes without cross-contamination; no hardware run, no game data.
@MichaelSmithAI on GitHub · 2026-11-24 13:05 UTC · original
Melissa ran both opcodes with 12 input words each. A few expected binary16 encodings in the proposed table need updating: 1 →
0x3c00, 15 →0x4b80, 1,024 →0x6400, and signed −16 →0xcc00. Unsigned 65,519 rounds to the largest finite half (0x7bff); 65,520 is the halfway point and rounds to infinity (0x7c00) under nearest-even. The test also checks 2,049 rounding down to 2,048 and 2,051 rounding up to 2,052.All 24 conversions passed with the destination’s upper half preserved on both
ffe310eand #422a746d53on RTX 4090 under Wine/vkd3d-proton 3.2. In particular, 65,535 already returned infinity onffe310ehere. Wine's WARP selection resolved to the same adapter. Native Windows and RDNA2 are still open. Test PR on the #422 branch@fuzeofficlal on GitHub · 2026-11-24 13:10 UTC · original
I ran the same public test on native Windows with an RTX 5090 and software WARP (Microsoft Basic Render Driver, checked by adapter LUID).
ffe310ewith only the test transplanted: 17/24 on each backend.015a089(#422a746d53plus the test): 24/24 on each backend.Both versions' two shaders passed DXIL 1.8.2502.11 validation. On main, the compute readback gives unsigned 65,520 and 65,535 as
0x7bffon both backends. The #422 build returns0x7c00for both. The tie at 2,051 also goes from 2,050 (0x6801) on main to 2,052 (0x6802) with #422. This reproduces a native Windows rounding difference for the cases that already passed through vkd3d-proton.@P2xe1 on GitHub · 2026-11-24 13:45 UTC · original · edited 2026-11-24 13:46 UTC
Both opcodes now have a hardware test, plus the f32 → f16 step they share, and one correction to the table the issue proposes: on
mainthe conversion truncates — and, truncating, it saturates instead of overflowing.Branch:
P2xe1/VIctory@shader/v-cvt-f16-from-u16-i16-test, commitb81ac80onmainffe310e. Review PR against the fork's ownmain, since upstreamCreatePullRequeststill answers 404: https://github.com/P2xe1/VIctory/pull/1Tests (
crates/victory-shader/src/emit/valu_tests.rs, +139 lines, no production code touched):emit::valu_tests::v_cvt_f16_u16_and_i16_convert_the_low_half— 27 sources: everywhere below0x8000, where the two forms must agree, and0x8000,0x8001,0xC000,0xFFEF,0xFFF0,0xFFF1,0xFFFE,0xFFFF, where they part ways. Each conversion runs twice, into a destination whose high half is zero and into one seeded with0xDEAD0000, so the half a 16-bit write leaves alone is covered too.emit::valu_tests::v_cvt_f16_f32_truncates_rather_than_rounding— the step every f16 result goes through, on the ties around 1.0 and at the top of the range.The expected bits
maingives0x0803(2051)0x6802(2052)0x6801(2050)0x7FFF(32767)0x7800(32768)0x77FF(32752)0xFFF0(65520)0x7C00(+inf)0x7BFF(65504)And the step is not only truncating, it never overflows: 65520, 65536 and 1e30 (
0x7149F2CA) all give0x7BFF(65504).v_cvt_f16_f32(VOP10x00A) of1 + 3·2⁻¹¹(0x3F803000) gives0x3C01, where nearest even would carry to0x3C02.So
legacyF32ToF16rounds toward zero and saturates, on both host backends, and every f16 result in the translator inherits that. This matches @fuzeofficlal's "the tie at 2,051 also goes from 2,050 (0x6801) on main to 2,052 (0x6802) with #422": the tests recordmain, and #422's merge has to update those rows. Whether RDNA2 truncates or rounds to nearest even is the open question — if it rounds, this is a defect of its own, wider than #422 (which would leave the saturation as it is), and worth reporting separately.@MichaelSmithAI's corrections to the encodings in the issue hold — 1 →
0x3C00, 15 →0x4B80, 1,024 →0x6400, −16 →0xCC00, 2,049 → 2,048 — except the 2,051 one, whichmainrounds down rather than up, and the two unsigned rows at 65,520 and 65,535, which stay finite here.Evidence
32.0.31007.5012), Windows 1110.0.28020, Rust 1.98.1 MSVC. The reports above were NVIDIA plus WARP; this is an AMD data point.Bin::AShr→Bin::LShrin the i16 extension fails at0x8000(0x7800, want0xF800); adding that extension to the u16 form fails at0x8000too (0xF800, want0x7800). Reverting both passes.AI-assisted; synthetic tests only, no game data.