Shaders: round scaled and normalized D16 buffer loads to nearest even #2841
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2843"
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?
Imported from Marvisak/VIctory. Originally posted by dooprazol on 2026-11-25T22:02:47Z.
Use the existing bitwise narrowing implementation for scaled and normalized D16 buffer loads. For example, 2051 rounds to 2052. The synthetic shader regression failed before the fix and passed afterward. On
b2a97b1, cargo test --locked -p victory-shader passed on Linux with 166 passed and 3 ignored. On the initial base, cargo test --workspace failed during Linux compilation on both clean and patched trees.The Windows shader tests were type-checked. No RX 9060 XT dispatch or gameplay was tested. The device-loss reports remain open.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T22:11:38Z.
Review: COMMENTED
Correct: D16 conversions of scaled/normalized formats are always round-to-nearest-even in the ISA — VALU MODE's rtz applies only to explicit v_cvt_f16_f32. narrow16_bits parameterizing the direction keeps the MODE-sensitive path and the fixed-RNE path sharing one implementation. The legacy_half_conversion test flag checks the right observable. LGTM.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T22:29:36Z.
Independent Windows verification of
a0a2e525against currentmain(f3578e38).main, the assertion failed because the lowering still emittedlegacyF32ToF16. This check inspects the emitted code.0x1414:0x008c, software flag0x2) with the SDKdxil.dllconfigured. The full suite was not rerun with this harness change.Claude Code (claude-opus-5-5) ran the shader suites and rebuilt the PR after detecting stale Cargo artifacts. Codex (gpt-6.2-sol) checked the corrected logs, ran the targeted main comparison and verified the adapter with the focused WARP run. Synthetic data only.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T22:47:25Z.
Reviewed and verified
a0a2e525on Windows 11 (RTX 5090 + WARP +dxil.dll) againstmain(f3578e3):narrow16intonarrow16_bits(f, rtz)and routingd16_channels(Uscaled | Sscaled | Unorm | Snorm) throughnarrow16_bits(f, false)cleanly enforces portable IEEE round-to-nearest-even (including±0.0,±Inf, quiet NaN payload, subnormal sticky bit, andUSCALED65520..=65535 -> +Inf) regardless ofVALU MODE, while keepingUint/Sint(& 0xFFFF) andFloat(legacyF32ToF16) intact.cargo test --locked -p victory-shader --lib d165/5 passed (includingd16_scaled_buffer_load_uses_portable_roundingand the updatedtbuffer_d16_loads_pack_two_channels_per_dword),emit::lower::tests34/34 passed,cargo clippy --locked -p victory-shader --all-targets -- -D warnings0 warnings,cargo xtask policy(190 files ok).crates/victory-shader/src/emit/lower.rsis at521,634bytes (2,654bytes under the 512 KiBxtask policycap).a0a2e52) that also adds#[cfg(windows)]on 3Validator::loadsites inlower.rs— rebasing ontomainwould keep the history linear.d16_channels); image D16 paths are untouched.Imported from Marvisak/VIctory. Originally posted by dooprazol on 2026-11-25T22:51:31Z.
Confirmed on Windows 11 with a Radeon RX 9060 XT 16 GB at
a0a2e525. The focused tbuffer_d16_loads_pack_two_channels_per_dword test passed (1 passed, 0 failed). Local DXGI logging identified the physical adapter as warp=false name=AMD Radeon RX 9060 XT. WARP also ran separately.The numerical checks included 2051 → 2052, −2051 → −2052, and 2049 → 2048. This run used synthetic buffer data only.
Imported from Marvisak/VIctory. Originally posted by AwsAli05 on 2026-11-25T23:15:45Z.
Review: COMMENTED
The focused portable-rounding test passed on Windows at
a0a2e525. The distinction between fixed D16 rounding and VALU's configurable rounding is the part I would pin with a second case. Run the same halfway USCALED load after selecting round-toward-zero with the existing MODE fixture. 2051 should still produce 2052. That would catch accidentally routing this path through mode-sensitivenarrow16, which would still satisfy the current check for absence of the legacy DXIL conversion.AI-assisted review and test.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T03:24:26Z.
Automated triage for the maintainers.
Verdict: needs work. The code does what the title says. In
crates/victory-shader/src/emit/lower.rs,narrow16is split intonarrow16_bits(f, rtz), and the D16 packing loop sendsUscaled/Sscaled/Unorm/Snormchannels throughnarrow16_bits(f, false)instead oflegacyF32ToF16.FloatkeepslegacyF32ToF16and the integer formats keep the mask. It merges cleanly.What is missing is evidence for the console behaviour it encodes. This changes emulation results, and the tests (
tbuffer_d16_loads_pack_two_channels_per_dword's new rows,d16_uscaled_keeps_nearest_even_in_valu_rtz_mode) check the emitted conversion against the values the PR expects (2051 to 2052, and RNE under MODE RTZ), not against the console. Please point to something that shows the console's D16 format conversion rounds to nearest even and ignores the VALU MODE round bits: a hardware capture, the public ISA documentation, or the title's own data depending on it. Two further points: why shouldFloat(f32 data narrowed to f16) still use the host'slegacyF32ToF16rounding when the scaled and normalized formats do not? And the#[cfg(windows)]additions on the threeValidator::loadtest sites are unrelated, so they would fit better in a separate PR.CI: not run on this head yet (awaiting workflow approval).
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T16:06:34Z.
AMD check on a Radeon RX 7900 XTX (gfx1100, 32.0.32029.2010),
victory-shaderbuilt with--features host:63bcca4: 2 of 6d16_cases fail on the hardware backend (format 9 of0x00000803→0x00006801, want0x00006802).Synthetic only. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-26T20:53:38Z.
NEW-284 verification on current head, Windows 11, toolchain 1.98.1,
--test-threads=1, AMD Radeon 780M (RDNA3 iGPU) and WARP (VICTORY_WARP=1).cargo test -p victory-shader -p victory-gpu --locked --no-fail-fast: no failures on the 780M; on WARP only the four synthetic_tests failures main63bcca4also has (fixed by #2225).d16_scaled_buffer_load_uses_portable_rounding,d16_uscaled_keeps_nearest_even_in_valu_rtz_mode.AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by dooprazol on 2026-11-26T22:04:31Z.
To follow up on the
Floatquestion, I ran a synthetic D16 buffer-load test on Windows 11 at commit628ab890with a local diagnostic patch. The physical Radeon RX 9060 XT (warp=false, vendor0x1002) and Microsoft WARP returned identical bits in all four cases.The input was 2051 in each format. An explicit
v_cvt_f16_f32in the same shader served as the control.16_USCALEDD16 load32_FLOATD16 load0x6802(2052)0x6801(2050)0x6802(2052)0x6802(2052)0x6801(2050)0x6801(2050)The VALU control changed from 2052 to 2050, confirming that the mode switch took effect. For this halfway input, the existing
Floatpath truncated to 2050 in both modes. TheUSCALEDpath rounded to the nearest even value, 2052, in both modes. This format distinction matches the buffer D16 conversion rule in AMD’s RDNA 3 ISA, “D16 Instructions”.This test measured VIctory’s translated shader on the two PC backends using synthetic data. Native console behavior remains unverified.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:20:24Z.
Review: CHANGES_REQUESTED
Verified on
628ab890:cargo xtask policy:191 files ok;crates/victory-shader/src/emit/lower.rssize is521,634bytes.rustfmt --edition 2024 --check: clean on all PR-modified hunks inlower.rsandvalu_tests.rs.cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default and--all-features): clean.cargo test --locked -p victory-shader --lib -- --test-threads=1 emit::valu_tests:: emit::lower::: 70 passed, 0 failed under bothVICTORY_WARP=0andVICTORY_WARP=1, includingd16_scaled_buffer_load_uses_portable_roundingandd16_uscaled_keeps_nearest_even_in_valu_rtz_mode.narrow16_bits(f, false)fixes RNE rounding for explicit-formattbuffer_load_format_d16_*(Uscaled,Sscaled,Unorm,Snorm), independently of VALUMODE. One blocking gap and a couple of minor items remain:buffer_load_format_d16_{x,xy,xyz,xyzw}(MUBUF descriptor-format loads) bypasses the fix (crates/victory-shader/src/emit/lower.rs:9389, 9799, 9874):d16_channelsis only reached in the explicit-format (tbuffer_load_format_*) path; descriptor-format MUBUF D16 loads still pack channels withdx.op.legacyF32ToF16(opcode 130, RTZ), misrounding normalized/scaled midpoints.UNORM/SNORMstill double-round throughf32on four 16-bit codes (16_UNORM0xFFAF/0xFFEF,16_SNORM0x7FF7/0x8009off by 1 ULP vs native RDNA2), andlower.rs:11603, 11657, 11708include three unrelated#[cfg(windows)]additions.Imported from Marvisak/VIctory. Originally posted by dooprazol on 2026-11-26T22:39:54Z.
Thanks for spotting the descriptor-format path. I reproduced the rounding issue in
buffer_load_format_d16_xon Windows 11 with a physical Radeon RX 9060 XT and Microsoft WARP. Both backends returned the same results.I ran the same synthetic test twice at
628ab890: first with only the regression test added, then with a local candidate fix. Each row used 32 lanes with the same input.0x28010x28020x28020xac010xac020xac020x68010x68010x68010x08030x08030x0803Before the fix, all 32 lanes failed for each normalized format on each backend. With the local fix, all 32 lanes matched the expected value in every row. The FLOAT and UINT controls passed in both runs.
Coverage is limited to the single-channel descriptor load and these four inputs. The candidate fix is still local. Synthetic data only.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:39:50Z.
Review: CHANGES_REQUESTED
The
VIEW_NORMALIZEDflag plumbing,VIEW_STRIDE_BITSupdate ((1 << 29) - 1), MTBUF/MUBUF D16 lowering (narrow16_bits(f, false)), and tests look solid overall:lower.rsstays under the 512 KiB limit (521,698bytes).cargo xtask policyandcargo clippy -p victory-shader -p victory-gpu(default and--features diagnostics,--tests -- -D warnings) pass cleanly.emit::valu_tests(includingtbuffer_d16_loads_pack_two_channels_per_dwordandd16_uscaled_keeps_nearest_even_in_valu_rtz_mode) andemit::stride_tests::mubuf_d16_descriptor_roundingpass on both hardware GPU and WARP withdxil.dllvalidation.buffer_load_format_d16_xtesting under VALUMODE=RTZconfirmed nearest-even rounding on both hardware GPU and WARP forR16_UNORM,R16_SNORM,R8_UNORM(254/255 -> 0x3bf8),R8_SNORM,R8G8B8A8_UNORM, andR10G10B10A2_UNORM.One concrete gap reproduced on both hardware GPU and WARP:
normalized_buffer_formatomits D3D12 BGRA UNORM typed buffer formats (87,88, and optional85,86,115)crates/victory-shader/src/emit/shader.rs:29-32Querying
ID3D12Device::CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT)on both hardware GPU and WARP shows:DXGI_FORMAT_B8G8R8A8_UNORM(87):D3D12_FORMAT_SUPPORT1_BUFFER = trueandTYPED_UNORDERED_ACCESS_VIEW = trueon both hardware GPU and WARP.DXGI_FORMAT_B8G8R8X8_UNORM(88):D3D12_FORMAT_SUPPORT1_BUFFER = trueon both hardware GPU and WARP.DXGI_FORMAT_B5G6R5_UNORM(85),DXGI_FORMAT_B5G5R5A1_UNORM(86), andDXGI_FORMAT_B4G4R4A4_UNORM(115):D3D12_FORMAT_SUPPORT1_BUFFER = trueandTYPED_UNORDERED_ACCESS_VIEW = trueon WARP.victory-gpualready accepts87and88as 4-byte view/element formats (crates/victory-gpu/src/resource.rs:125,crates/victory-gpu/src/descriptor/host.rs:2404-2407). Becausenormalized_buffer_format(87)returnsfalse,view_kind/view_stridesomitsVIEW_NORMALIZED, causingB8G8R8A8_UNORMMUBUF D16 loads to fall back tolegacyF32ToF16(RTZ) instead of nearest-even.Reproduced live on both hardware GPU and WARP with
buffer_load_format_d16_x(R = 254,254 / 255.0 = 0x3f7e_feff):R8G8B8A8_UNORM(28):stride_entry = 0x20000004, result =0x3bf8(nearest even).B8G8R8A8_UNORM(87):stride_entry = 0x4, result =0x3bf7(truncated, 1 ULP off on both hardware and WARP).Fix: Include
85 | 86 | 87 | 88 | 115innormalized_buffer_format(zero impact onlower.rssize) and add aB8G8R8A8_UNORMcase tomubuf_d16_descriptor_rounding/descriptor::host::tests.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-27T03:20:29Z.
WARP verification of head
8bd21f58(NEW-284 claim: #1633)Environment: Windows 10 22H2, WARP software adapter (
VICTORY_WARP=1 VICTORY_D3D12_WARP=1), rust 1.98.1 msvc. Important local caveat: both adapters on this machine cap at SM 6.2, so SM-6.6 pipeline execution is impossible here for upstream code equally (proven: upstream's own SM-6.6 pipeline tests fail at creation on unmodified main63bcca43). victory-gpu runs use--features diagnostics— WARP selection is feature-gated there — and--test-threads=1serial.victory-shader
--lib: 215 passed / 90 failed / 3 ignored vs baseline 214/88/3 — zero regressions. Every test present in both trees has identical status; the arithmetic is fully explained by the 3 new tests (the failure counts are dominated by environmental no-SM-6.6-device skips-as-failures, identical on main).emit::lower::tests::d16_scaled_buffer_load_uses_portable_rounding: PASS — the core correctness claim at lowering level: D16 scaled/normalized buffer loads lower to the portable bitwise round-to-nearest-even instead of host-dependentlegacyF32ToF16mubuf_d16_descriptor_rounding/d16_uscaled_keeps_nearest_even_in_valu_rtz_modefail only environmentally (no SM 6.6 hardware device; skipped) — cannot execute on any adapter of this machine, upstream equallyinteger_typed_buffer_views_are_marked_in_the_stride_table(R16_SNORM → VIEW_NORMALIZED): PASSresource_trackingintegration: 3 passed / 1 ignoredVerdict: verification supports at lowering level; GPU execution of the rounding tests needs an SM 6.6 machine.
Imported from Marvisak/VIctory. Originally posted by dooprazol on 2026-11-27T11:38:41Z.
Thanks for catching this. Fixed in
a0957b5. I reproduced the BGRA rounding issue on a physical Radeon RX 9060 XT and on WARP. With R = 254/255, all 32 BGRA lanes returned 0x3bf7 before the fix and 0x3bf8 afterward on both backends. The RGBA control returned 0x3bf8 in both runs.The descriptor test covers all five newly classified formats. The GPU readback covered B8G8R8A8_UNORM (87).
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T11:58:42Z.
SM 6.6 run of the latest head
a0957b5(including the BGRA fix), which kotekompotek's SM 6.2 machine couldn't execute: Windows 11, AMD Radeon 780M (RDNA3), toolchain 1.98.1,--no-fail-fast -- --test-threads=1. WARP:VICTORY_WARP=1(+VICTORY_D3D12_WARP=1 --features diagnosticsfor victory-gpu).mubuf_d16_descriptor_roundingd16_uscaled_keeps_nearest_even_in_valu_rtz_moded16_scaled_buffer_load_uses_portable_roundingnormalized_buffer_formats_load_correctly_rounded_quotients,..._load_their_ends_exactly,normalized_codes_truncate_back_to_themselvestbuffer_d16_loads_pack_two_channels_per_dword,d16_typed_buffer_accesses_pass_bits_through_integer_views,d16_x_loads_read_r16_uint_and_r16_float_viewsinteger_typed_buffer_views_are_marked_in_the_stride_table,normalized_attributes_are_interpolated_in_their_own_range(victory-gpu)The four WARP failures are the synthetic_tests ones main has with
VICTORY_WARP=1(fixed by #2225). So the GPU-backed rounding tests execute and pass on RDNA3 hardware, alongside your RX 9060 XT (RDNA4) results.AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T11:59:23Z.
I merged
a0957b5into current main63bcca4and ran the D16 tests on WARP 1.0.22 with DXIL validation. All seven regular D16 tests passed, including the BGRA format case. With the same fixtures on main, the descriptor rounding test and both explicit-format rounding tests failed. The full runs were 297 passed / 7 failed / 5 ignored on main and 301 / 4 / 5 on the merged branch. The four remaining failures are identical on both revisions. Strict shader and GPU Clippy and the asset policy passed.I also checked the four exact-normalization cases @fuzeofficlal noted. On both MTBUF and MUBUF, WARP gave the expected single-rounding value on main and moved one FP16 step away with this PR:
ffaf3bfd3bfeffef3bff3c007ff73bff3c008009bbffbc00Reproducer
081045ccontains the current-main merge and two opt-in probes. Filter forrounding_four_edge_codesand pass-- --ignored --nocapture --test-threads=1. The probes compare against rounding the exact normalized fractions once. Both pass on main and both report the mismatch with this PR. The MUBUF comparison checked all 32 lanes per input. #1940 covers the explicit-format side of single rounding. The descriptor-format cases would still need a check of their own.Synthetic Windows/WARP testing only. AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T12:04:23Z.
@andrewpozdnakov7-jpg ran your probes (081045c,
a0957b5+ the tworounding_four_edge_codestests) on AMD hardware: Windows 11, Radeon 780M (RDNA3),--ignored --nocapture --test-threads=1, paired hardware + WARP backends.The hardware gives the same bits as WARP in all eight cases, 32/32 lanes each:
0xffaf0x3bfe0x3bfd0xffef0x3c000x3bff0x7ff70x3c000x3bff0x80090xbc000xbbffSo the double rounding at these edge codes comes from the translated shader, not from WARP; it reproduces on RDNA3 silicon too. (Note on my earlier comment: the PR's own tests pass, but they don't cover these four codes.)
AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T13:32:12Z.
I resolved the conflict between #2843 and #1940 on current main
63bcca4. Combined branch 8bcc0bf retains both PR histories. MTBUF uses #1940's exact 32-bit normalization and keeps #2843's USCALED/SSCALED rounding. MUBUF selects the exact UNORM16 or SNORM16 path from the buffer view's format flags. The byte-stride bits and the integer-view flags retain their existing interpretation.The four codes in the Radeon 780M report now return
3bfd,3bff,3bffandbbffon both MTBUF and MUBUF with app-local WARP 1.0.22. The same MUBUF fixture at081045cwas wrong in all 32 lanes per code and now matches all 32. An independent CPU model of the new runtime conversion matched the exact rational reference for all 131,072 UNORM16/SNORM16 code values.All 11 D16 tests passed, including the BGRA, RTZ, float and integer controls and the Int64ShaderOps check across the explicit normalized formats. The GPU descriptor classification test passed. Full shader run: 305 passed, 4 failed, 3 ignored. All four failures also occur on the same WARP with main. Strict all-feature/all-target shader and GPU Clippy and the asset check passed.
@kilolimaVI could you repeat
cargo test --locked -p victory-shader --lib d16 -- --nocapture --test-threads=1at8bcc0bfon the Radeon 780M? The MUBUF four-code probe is now a regular test, and the MTBUF fixture includes the same four codes.If folding the integration into a new commit, please retain Git authorship or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>for this contribution.AI-assisted with Codex. Synthetic buffers only.
Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T15:40:38Z.
@andrewpozdnakov7-jpg repeated on the Radeon 780M at 8bcc0bf (review/exact-d16-buffer-normalization), Windows 11, toolchain 1.98.1:
cargo test --locked -p victory-shader --lib d16 -- --nocapture --test-threads=1.The four codes are right now, on the hardware and on WARP, 0/32 lanes wrong each:
0xffaf0x3bfd0x3bfd0x3bfd0xffef0x3bff0x3bff0x3bff0x7ff70x3bff0x3bff0x3bff0x80090xbbff0xbbff0xbbffAll 11 D16 tests pass (including
mubuf_d16_rounding_four_edge_codes,tbuffer_d16_loads_of_16_bit_norms_round_once,d16_normalized_format_loads_do_not_require_int64,tbuffer_d16_loads_saturate_32_bit_integers). Wholevictory-shaderlib on the 780M: 309 passed, 0 failed, 3 ignored. So on RDNA3 the combined branch fixes the four codes that were wrong at 081045c, with nothing else regressing.AI-assisted (Claude).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.