Repository navigation
Shaders: tbuffer_load_format_d16 loads pack two 16-bit channels per VGPR - #169
Conversation
|
Tested
No game data used. |
…o 16-bit channels per VGPR) into the integration Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
A result from a second adapter, in case it helps. This PR's test So for a 16-bit UNORM channel of It does not block the PR, but the test will fail for anyone on AMD as it stands. Either the expected value could allow the neighbouring half for norm formats, or the conversion could avoid the divide for the all-ones input (the exact rule for UNORM is value / (2^n - 1), with all-ones giving exactly 1.0). From synthetic tests on those two adapters only; not run against the title. |
|
Reproduced r4tedx’s result at a103937 on an AMD Radeon RX 6700 XT, driver 32.0.21045.29003. I verified the dispatch device by D3D12 adapter LUID. cargo +1.98.1 test --locked --offline -p victory-shader --lib emit::valu_tests::tbuffer_d16_loads_pack_two_channels_per_dword -- --exact --test-threads=1 --nocapture 16_16_FLOAT and 16_16_UINT passed on both adapters. On the RX 6700 XT, 16_16_UNORM returned 0x3bff0000 for input 0xffff0000, with 0x3c000000 expected. The assertion stopped the run before WARP reached UNORM or either adapter reached 16_FLOAT. A WARP-only rerun passed all four cases and returned 0x3c000000 for UNORM. |
|
At a103937 on the RX 6700 XT (driver 32.0.21045.29003), I added a UAV readback of the normalized high channel for 0xFFFF0000 while keeping the d16 conversion in place. With the readback, both Radeon and WARP gave f32 0x3F800000 and packed 0x3C000000. The original Radeon test returned 0x3BFF0000 before and after removing the probe. The extra readback changes the Radeon result, so the intermediate in the failing shader is still unknown. |
|
@Dufftwt I tested the explicit 0xFFFF → 1.0f32 case in format_load at a103937. On the RX 6700 XT (driver 32.0.21045.29003), the clean test reproduced 0x3BFF0000. With the fix, all four cases in the original test passed on the LUID-verified Radeon and WARP with the existing expectations. Packed outputs for 0x0000, 0x8000, and 0xFFFE matched before and after on both. I can send the small patch for your branch. |
The d16 forms of the typed buffer loads return each channel as 16 bits, two per VGPR, low half first; the decoder already sizes their data that way. The lowering only treated `buffer_` names as d16, so a tbuffer_load_format_d16_* went through the 32-bit path: the first VGPR got channel x as a 32-bit value (the f32 bits of 1.0 instead of the f16 pair (1.0, 2.0)) and the other channels were dropped. The format path now packs its channels for d16: integer formats keep their low 16 bits, the other formats become f16 (as the MUBUF d16 path converts them).
a103937 to
c430b1d
Compare
The tester tree (upstream main ffe310e plus its PRs, update 8; see its INTEGRATION.md) ran 11-25 minutes in the world on an RTX 5070 without a device removal. Where both sides carry the same PR (the wave64 stack #223/#233/#320 with #439 and #180, #454, #336, #259, #331 and others), the tester tree's newer head is taken; our own work and the PRs only we merged are kept. Conflicts, file by file: - descriptor/host.rs: the tester layout (`spare`, the guard slot after the dynamic slots, `free_table`, the capped sampler heap). A capped view heap keeps `capped_reserve()` dynamic slots, now 2^18 by default (the tester measurement, and our 91fed158), still `VICTORY_DYNAMIC_SLOTS` in diagnostics builds; uncapped hosts keep our 2^19. Our slot statistics (TAKEN/PEAK/SHORT), the bindless plan cache (`CommittedRegions`, `timed_valid_title_address`, `timed_find`, `title_bounds`) and the revision triple are kept beside the tester's `guard_slot`. - Buffer states: the tester tree's buffer-state tracker (#334: every list moves host copies of title memory between GENERIC_READ and UNORDERED_ACCESS and back to common before it closes) and depth twins (#469) are taken. #40's enhanced/legacy indirect barriers (the indirect prelude, `use_indirect_buffers`, the title buffer handoff mirrored in `host_barrier`) cannot share buffers with that tracker and are dropped; #40's argument checks (`byte_len`, exact spans, overflow-safe clamp shader, aligned counts) stay. `indirect::bound` and #282's `rectangles` go through `buffer_state`, and `indirect::execute` (#334) replaces `done`. #178's DXC fallback compiles both of our passes. Our segments (#387: `close` ends the segment, `close_native` closes a native list) carry the tracker: each native list returns its buffers to common and its twins to their depth targets, and each prelude also holds our texture uploads. - shadow.rs: our write flow (`queue_write`, one `snapshot` after the batch's refreshes, `finish_writes`, the unchanged-page cache) with #261's copy-back that also gives the snapshot the title's bytes; its tests run through our flow. - pipeline/make.rs: #275's per-frame budget and per-pipeline wake pair, with our compute waits (a dispatch waits for its pipeline, up to 20 s). - pipeline/library.rs: the tester version (#347, #275's saver thread); our concurrent-write test kept. shader_cache.rs: our byte-returning cache API with #358's "translated, only not kept". - draw.rs: #493's root SRV tables; where no table can stand in, our drop of a draw whose root view is unset or outside title buffers. Our refusal of a table offset past the capped heap stays. - resource.rs: `HostTexture` has both our `staged` generation and the depth twin. - Shaders: the tester's lower.rs for the wave64 stack, #160's image sampling (it covers our #73 and #136 sample forms) and #453/#587; kept from our side: #136's preference for an image or buffer use of a descriptor read as data and its `s_buffer_` arm, #422's nearest-even narrowing (also for #169's d16 loads and #453's interpolation), #452's spin-wait limit, #391's LDS limit, #302's spilled root arguments (now in `NativeProgram::translation_ir`), #136's PSV0 interpolation beside the tester's row harmonisation. split_tests.rs, lane_read_loop_tests.rs and docs/wave64-on-wave32.md are the tester versions (the same PRs at newer heads). - Tests: #483's heap guard dwords filled in our GPU tests of #200 (v_div_scale) and #437 (scalar loads from a raw view), which read through the guard slot otherwise; #334's debug-layer test passes an offset to our `indirect::bound`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
On an AMD RX 9070 (RDNA4) the new
Checked with CI's steps (both clippy runs with |
Buffer format loads divide a UNORM or SNORM field by its largest value. A host may divide through a reciprocal and land just below 1.0: on an RX 9070 (RDNA 4), 16_16_UNORM's 65535 loaded through the d16 path as the half 0x3BFF instead of 0x3C00. The largest value now selects 1.0, and an SNORM field's two lowest values select -1.0, as the formats define them.
|
@alexdeliu thanks for running it on hardware. That's a real bug, and it's in Fixed in Could you rerun |
|
@Dufftwt reran it at |
…fied together Merges Marvisak#156 Marvisak#162 Marvisak#168 Marvisak#169 Marvisak#368 Marvisak#379 Marvisak#456 Marvisak#587 Marvisak#990 Marvisak#1021 Marvisak#1048 Marvisak#1052 Marvisak#1053 Marvisak#1095 Marvisak#1142 Marvisak#1190 Marvisak#1211 Marvisak#1223 Marvisak#1259 Marvisak#1293 on top of the bundle of Marvisak#1402 (which is on Marvisak#1319, on main ffe310e), each head unchanged. Hunks that conflicted in emit/lower.rs, emit/valu_tests.rs and emit/diff_tests.rs were merged by keeping both sides (additions next to each other); a PR was kept only if cargo clippy -p victory-shader --all-targets -- -D warnings still passed with it. No instruction name is handled in two places. Marvisak#98 is not in this version: an offline measurement on a retail dump showed it loses 31 programs that validate on Marvisak#1402. cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features, is clean and cargo test --workspace --locked passes (381 passed, 6 ignored; main has 342 passed, 6 ignored). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…6-bit channels per VGPR
Two ignored tests run synthetic shaders on the hardware GPU and WARP and print every mismatch, grouped by backend, operation and channel, with an example input: - sweep_typed_buffer_formats: all 77 GFX10 buffer formats through tbuffer_load_format_xyzw (one shader per channel), 72 input sets each, against the ISA's exact conversions (UNORM x/(2^n-1) and SNORM max(x/(2^(n-1)-1), -1) correctly rounded, scaled, integer, the small floats, missing channels 0, 0, 0, 1). SWEEP_D16=1 adds tbuffer_load_format_d16_xyzw (needs Marvisak#169); SWEEP_NORM_ONLY=1 keeps the 20 norm formats. - sweep_f16_alu: v_add/sub/mul/fma_f16, v_pk_add/mul/fma_f16 (both lanes), v_cvt_f16_f32 and v_cvt_f32_f16 against f64 results rounded to the nearest-even half. run_wide is run_cases with a 4-dword UAV, so the wide formats' inputs fit. Run with: cargo test -p victory-shader --lib sweep -- --ignored --nocapture Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What's wrong
The console GPU has "d16" forms of its typed buffer loads,
tbuffer_load_format_d16_x / _xy / _xyz / _xyzw. Instead of one 32-bit value per channel, they return each channel as 16 bits, packed two per register, low half first. Half-precision vertex data is typically read this way. The decoder (fields.rs) already knows this and sizes the result as half as many registers.The lowering in
lower.rsonly recognises d16 for names that start withbuffer_:so
tbuffer_load_format_d16_*takes the normal 32-bit path:Every shader that loads 16-bit data this way gets garbage in that register, and the other channels are silently dropped, because only half as many registers exist for them.
What the fix does
d16now applies totbuffer_loads as well asbuffer_ones.The typed-format load path (
format_load, used by everytbuffer_load) packs its channels when the instruction is d16. A new helper,d16_channels, takes the channelsformat_loadalready decoded and packs them two per register, low half first. If the channel count is odd, the last high half is 0.UINT/SINT) keep each channel's low 16 bits.buffer_load_format_d16path uses.A normalized format's ends load as exactly 1.0 and -1.0 (second commit).
format_loaddivides a UNORM or SNORM field by its largest value, and a host may divide through a reciprocal and land just below 1.0. alexdeliu's RX 9070 (RDNA 4) loaded16_16_UNORM's 65535 through this d16 path as the half0x3BFF, not0x3C00. The largest value now selects 1.0. An SNORM field's two lowest values select -1.0, which replaces the clamp. This applies to non-d16 loads too.Otherwise, non-d16 loads and all
buffer_loads don't change.How it behaves after the fix
tbuffer_load_format_d16_*fills its registers the way the hardware does. For example, loading16_16_FLOATdata(1.0, 2.0)gives0x4000_3C00in one register, and16_16_UNORM(0, 0xFFFF)gives the f16 pair(0.0, 1.0).Tests
The new test
tbuffer_d16_loads_pack_two_channels_per_dwordinvalu_tests.rsuses the synthetic-shader harness from #37. The shader stores a dword to the buffer and reads it back with the d16 load, in four cases:d16_xyof16_16_FLOATd16_xyof16_16_UINTd16_xyof16_16_UNORMd16_xof16_FLOATA second test,
normalized_buffer_formats_load_their_ends_exactly, loads the largest value of8_UNORMand16_UNORM, and the largest and two lowest of8_SNORMand16_SNORM, throughtbuffer_load_format_x. They must be exactly 1.0 and -1.0.I ran
cargo test -p victory-shaderon GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml. There's no GPU there, so the harness runs the shaders on WARP. Results:This PR (
645391b): both new tests pass; the shader crate has 122 passed, 1 ignored.The d16 test alone on
main: it fails. The load gives0x3F800000, channel x as a 32-bit float, instead of the stored0x40003C00.WARP divides exactly, so the second test passes there with or without the second commit. The case it covers was found on RDNA 4 hardware: at
c430b1dthe d16 test gave0x3bff0000for0xffff0000on an RX 9070 (alexdeliu, below).On RDNA 4 hardware (alexdeliu, RX 9070,
645391bonmain):cargo test -p victory-shaderpasses 122, 1 ignored. Both new tests pass on the hardware backend.Not tested: a title's shaders that use these instructions.
Related: #422 replaces every
legacyF32ToF16with a round-to-nearest-evenf16_nearest, since AMD's driver rounds toward zero. The new call ind16_channelsshould go through it too, whichever lands second. #164 also editsbuffer(), a few lines above thed16line. It refuses the_d16_hi_forms; this PR packs the plaintbufferd16 loads. They don't overlap in behaviour, but whichever lands second may need a small rebase.