Shaders: round D16 image reads according to the bound texture format #2028
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2030"
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 AlanQiang0418 on 2026-11-25T03:43:37Z.
Addresses #2006.
A sampler read from the runtime heap still leaves its filter unknown to the shader. Point sampling a 16-bit normalized texture through that path can double-round at boundary values. Runtime sampler measurements.
Validation
On
c80e81f, all seven D16 tests passed. RTX 5080 and WARP matched every RGBA8 and RGBA16 UNORM/SNORM code and all 16 A4B4G4R4_UNORM codes. The point-sample boundary cases, linear control and descriptor-slot reuse passed on both adapters. All 15 descriptor tests passed on WARP. Strict all-targets, all-features Clippy passed for the GPU and shader crates.The initial RTX 5080 (621.14) and WARP run also passed all six draw tests on each backend. The RTX gather failure and two stride-test failures from that run reproduced on upstream
940d32f. The tests use synthetic textures.Thanks to andrewpozdnakov7-jpg for the review fixes, current-main integration and WARP checks. Integration report.
AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T03:57:17Z.
Review: APPROVED
Verified locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):cargo test -p victory-shader --lib d16— 4 passed, 0 failed on RTX 5090 hardware + WARP (includingd16_image_load_rounds_normalized_texels_to_nearestandd16_image_sample_keeps_fractional_normalized_texels)cargo test -p victory-gpu --lib texture_rounding_follows_the_view_in_a_reused_heap_slot— 1 passed, 0 failed on RTX 5090cargo clippy -p victory-shader -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)Awesome sideband
view_tableimplementation solving #2006 cleanly across bothvictory-gpuandvictory-shader, verified end-to-end on RTX 5090 + WARP. Looks good.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:46:47Z.
Triage verdict — Keep for #2006, tighten the test signal (
f6058b0)Evidence
Host::newfails. If hardware and WARP both fail to initialize, both tests can report success after zero dispatches. An existing test in the same file already asserts that at least one backend ran. Load test · Sample test · Existing guardChecks and limits
Next step
This verification was AI-assisted.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T03:59:05Z.
A remaining D16 case on
f6058b0e83: a static MIN_MAG_MIP_POINT sampler selects one texel. The exact normalized-code conversion currently applies to loads and gathers, so a point SampleLevel still takes the interpolated-sample conversion and can double-round.79867f9 is one commit on that exact head. It uses the existing exact conversion for a statically known point sampler. The same WARP dispatch failed before with UNORM16 code 0xffaf returning 0x3bfe instead of 0x3bfd. After, both UNORM edge codes, the two signed SNORM edge codes and the linear interpolation control passed. The regression also requires a backend to dispatch.
Full forced-WARP shader suite: 245 passed / 4 failed / 3 ignored before, 246 / 3 / 3 after. The gather, lane-permute and edge-flagged triangle failures were present in both runs. Strict shader Clippy and asset policy passed.
Imported from Marvisak/VIctory. Originally posted by astrosteveo on 2026-11-25T04:06:06Z.
On Linux the FLOAT path needs one more step. RTX 5080, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1,
f6058b0:d16_image_load_rounds_normalized_texels_to_nearestfails at the FLOAT control: got[bc023c02, fc007c00], want[bc013c01, fbff7bff], 256 of 256 texels.legacyF32ToF16rounds to nearest here.github.com/astrosteveo/VIctory@980acd1is one commit on your head: it uses the existingf16_toward_zero, which corrects either rounding. With it bothd16_imagetests pass here. Other uses oflegacyF32ToF16for D16 data (d16_channelsand the D16 buffer loads) may round the same way here; I did not test them.The
warpruns are not real WARP under Wine. Not tested: Windows, the title. Take it or leave it. AI-assisted (Claude).Imported from Marvisak/VIctory. Originally posted by Neins12 on 2026-11-25T04:07:04Z.
Review of
f6058b0(read-only: source and diff, plus a bit-exact model of the new integer path; I did not build or run it).image_norm16is exact for every 16-bit code. I modelled it op for op in Python (Round_neof |x|·max, the 65537 / 131076 +mag >> 13fixed-point expansion,FirstbitHifrom the MSB with −1 for zero, the 13-place subnormal clamp,(doubled + 1) >> 1, sign from bit 31) and compared it with exact round-to-nearest-even ofcode / (2^w − 1)using rationals:The last row matters for the WARP results in #2006, where some returned f32 values were one ULP off: re-rounding
|x|·maxto an integer absorbs that. Endpoints 0 →0x0000and 1 →0x3C00come out right, including the carry from0x7FF + 1into the exponent. As a check on the reference itself, it reproduces the issue's figures: 31,740 / 65,536 for the old toward-zero conversion and 2 / 65,536 for nearest-even of the returned f32 (which is why the 16-bit path needs the exact conversion).Things I checked that hold:
image_d16cannot hit "an image without a heap index": every texture handle comes fromShader::heap_handle, which now records kinds 1–9.heap_handleclamps the index belowHEAP_VIEWSbefore it is stored inview_index, and the table hasmax(count, HEAP_VIEWS)entries.VIEW_STRIDE_MASKkeeps buffer strides out of the three tag bits, sostride_atstill reads 0 for a tagged texture slot (covered by the updated stride test).latergets entry 0 first and its real tag when it is made for the draw, becausemade[index]stays 0.Open points:
VIEW_NORMALIZED. An sRGB read returns the linearized value, notcode / 255. #2006 only measured UNORM and SNORM, so it is unverified whether RDNA2 rounds sRGB D16 reads to nearest or toward zero. Either measure it or leave sRGB on the legacy path until it is measured.a_sampler_chosen_by_a_uniform_branch_samples_as_chosendoes.DXGI_FORMAT_A4B4G4R4_UNORM(191) is missing fromtexture_rounding.R24_UNORM_X8_TYPELESSgoes through nearest-of-f32, which is exact for 8- and 10-bit formats but has not been checked for 24 bits.Model script (
norm16_check.py, standard library only)AI-assisted (Claude Code). No game files used.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:03Z.
Review: APPROVED
Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main
940d32f69b,cargo test -p victory-shader --locked.144 passed / 0 failed. D16 image reads round according to the bound texture format — format-aware rounding for D16 paths; mixed gpu+shader, gpu half Windows-only. Relates to #1927/#1940 d16 load cluster.
Imported from Marvisak/VIctory. Originally posted by StExpeditus on 2026-11-25T04:14:30Z.
Test report: RTX 5060 Ti (Blackwell), Windows 11 Pro 26200
Environment: Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5060 Ti (driver 621.24,
32.0.16.2124) beside an Intel UHD 770 iGPU, Intel Core i5-14600K, 32 GB, Rust 1.98.1 MSVC. Branchcodex/d16-normalized-image-readatf6058b0on main940d32f. No game files; the title was not run.cargo test --workspace --locked --no-fail-fast-> 698 passed, 5 failed, 10 ignored.The PR's D16 tests pass on this hardware (and on WARP):
d16_image_load_rounds_normalized_texels_to_nearest: all 256 codes of RGBA8 UNORM and RGBA8 SNORM and all 65,536 codes of RGBA16 UNORM and RGBA16 SNORM matched on hardware and WARP.d16_image_sample_keeps_fractional_normalized_texels: the linear RGBA16_UNORM sample matched on hardware and WARP.The 5 failures are pre-existing on main (identical panics at
940d32f), all from the NVIDIA 1,000,000-view heap cap (HEAP_VIEWSis 2^21), the same limit behind #1835, #1808, #1760 and test report #1744:victory-gpudescriptor::host::tests::dynamic_slots_are_held_until_releasedheap.NumDescriptors >= HEAP_VIEWSvictory-gpumemory::tests::lists_share_a_table_and_copies_keep_their_viewsvictory-shaderemit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stridehardwarelane mismatchvictory-shaderemit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zerosE_INVALIDARGvictory-shaderemit::synthetic_tests::gathers_at_a_level_match_the_hardwarehardwarelane mismatchNothing introduced by this PR fails on this machine.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T06:33:33Z.
Test report for
e87c4f1(the current head, after the static-point and float-truncation commits) on Ampere: NVIDIA RTX 3070, driver 616.56, Windows 11 26100, plus WARP.Tested
d16_image_load_rounds_normalized_texels_to_nearest,d16_point_and_linear_samples_round_correctlyandtexture_rounding_follows_the_view_in_a_reused_heap_slotpass on hardware and WARP. Every RGBA8/RGBA16 UNORM/SNORM code matched.cargo test -p victory-shader --locked: 246 passed, 3 failed.cargo test -p victory-gpu --locked: 141 passed, 3 failed. Five of the failures also fail onmainon this machine: twostride_testsheap-buffer reads,gathers_at_a_level_match_the_hardware, and the two NVIDIA heap-cap tests. The sixth is awatch::test that fails only in the parallel run and passes alone 3 of 3 times.1e-5,-2.9e-6,±0.75·2^-24). It passes on both backends, sof16_toward_zerotruncates subnormals here, with no flush and no round-up to 2^-24.Review points
Source::Constant) take the exact 16-bit path. A point sampler read from the heap, or aSource::Phichoice between two samplers, falls back to nearest-of-f32. That leaves 2 of 65,536 16-bit codes wrong, which may be worth a comment.A4B4G4R4_UNORMis missing fromtexture_rounding.cargo check -p victory-shader --testspasses). Those change onlyd16_channels. #1940'snorm_f16andimage_norm16here do the same exact conversion, so whichever lands second could reuse the other.AI-assisted (Claude Code); runs on the machine above.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T06:55:30Z.
@upipibi I reproduced the immediate-sampler control-flow case on
e87c4f1f03. A guest shader selects point or linear sampling by workgroup. On WARP the point arm returned 0x3bfe for UNORM16 code 0xffaf, where it should return 0x3bfd.734f7d6 uses the existing sampler choice to select the D16 rounding path in one commit on that exact head. The regression passes with both arm orders. Point reads back 0x3bfd and linear reads back 0x37fe. Forcing the exact texel conversion on both arms changes the linear result to 0x37ff, which the test also catches. Heap-loaded samplers still take the f32 path because their filter is runtime data.
Full forced-WARP shader suite: 246 passed, 4 failed and 3 ignored before, 247 passed, 3 failed and 3 ignored after. The gather, lane-permute and edge-flagged triangle failures were present in both builds. Strict shader Clippy and staged asset policy passed.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T07:17:49Z.
I also verified the A4B4G4R4_UNORM point from the review. WARP reports texture-load support for this format. On
e87c4f1f03, D16 image_load returned 0x38cc per channel for code 9. The nearest half for 9/15 is 0x38cd.2a474f0 adds the format to the existing normalized tag and extends the native readback. All 16 codes now match across all four channels. The same test still covers the existing FLOAT, RGBA8 and RGBA16 cases. The two follow-ups apply together without a textual conflict. DXGI format reference
Full forced-WARP shader suite: 245 passed, 4 failed, 3 ignored before and 246 passed, 3 failed, 3 ignored after. The three unrelated failures were shared. Strict shader Clippy and staged asset policy passed.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T07:34:43Z.
@andrewpozdnakov7-jpg Thanks for chasing both points.
734f7d6on hardware: RTX 3070 (Ampere, driver 616.56, Windows 11), plus WARP, since the test runs on both.d16_samples_follow_immediate_sampler_choicepasses 3 of 3 runs on734f7d6.Control: your new test on
e87c4f1'slower.rsfails on hardware the way you saw on WARP. The point arm reads0x3bfewhere0x3bfdis right, and the linear arm0x37ffmatches (left: [15358, 14335],right: [15357, 14335], filters[04000000, 18500000]).victory-shadersuite on734f7d6: 247 passed, 3 failed, 3 ignored. The three (a_heap_buffer_read_by_element_takes_the_views_stride,a_heap_buffer_read_where_no_buffer_view_is_reads_zeros,gathers_at_a_level_match_the_hardware) fail onmainon this machine too.734f7d6merged with2a474f0: the five D16 tests pass on hardware and WARP. Ampere does load A4B4G4R4_UNORM (hardware: all A4B4G4R4_UNORM codes matched, and WARP the same), and every RGBA8 / RGBA16 UNORM / SNORM texel still matches.AI-assisted (Claude Code). Synthetic tests only.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:13Z.
Automated triage for the maintainers.
This pull request no longer merges cleanly into
main(conflicts incrates/victory-gpu/src/descriptor/host.rs,crates/victory-shader/src/emit/lower.rs,crates/victory-shader/src/emit/shader.rs,crates/victory-shader/src/emit/stride_tests.rs). It will be reviewed once it is rebased onto the currentmain. The earlier verdict (needs-work) was for an older state ofmain.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T09:30:50Z.
The three review changes are together in 1d1f883, directly on
e87c4f1f03. It includes the A4B4G4R4_UNORM and point/linear Phi changes from 2a474f0 and 734f7d6. sRGB formats keep the pre-PR toward-zero pack path pending console measurements.The new WARP check reads a real RGBA8 sRGB view across all 256 codes. With the original sRGB tag, code 1's green channel rounded to 0x3bee instead of 0x3bed from the same view on the truncating path. With this commit, all 256 sRGB texels match that control. All five D16 tests passed, including RGBA8 and RGBA16 UNORM/SNORM, all 16 packed codes, and point/linear sampler selection. Full forced-WARP shader suite with the same added fixture: 246 passed, 4 failed, 3 ignored before and 247 passed, 3 failed, 3 ignored after. The three remaining failures are the same existing gather, lane-permute and edge-flag tests. Strict Clippy and the staged policy check passed.
For the evidence link in the PR description, the primary gfx1036 measurements cover 8- and 16-bit UNORM/SNORM loads and point samples, with 8-bit code 9 returning 0x2885. The xcl report shows the corresponding truncation difference. These measurements cover linear normalized texels.
Please preserve the Git author if you cherry-pick the commit. If you fold the changes or tests into another commit, please add:
Co-authored-by: andrewpozdnakov7-jpg [email protected]
AI-assisted. Synthetic tests only.
Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:45:36Z.
Offline measurement on a retail dump
Result: no count change against
main.I merged head
e87c4f1fontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T13:56:40Z.
I resolved the current-main conflicts on 190dd03. It keeps
e87c4f1and the existing review fixes in1d1f883, and merges upstream63bcca4. The view table now gives texture rounding tags separate bits from main's integer buffer flags. Both buffer and image paths read the shared table, and view creation computes the tag from the effective view format. The image rounding helpers are in a separate module to keeplower.rswithin policy.On WARP 1.0.22 with Agility 1.620.2, all seven D16 tests and all eight stride tests passed, including integer buffer round trips, UNORM/SNORM image loads, and immediate point/linear sampling. The 64-bit image atomic test also passed.
victory-gpupassed 247 tests with one ignored, including the reused-descriptor-slot case. Strict GPU and shader Clippy and policy passed.The full shader run was 300 passed, 5 failed, 3 ignored. Four of those tests also failed in the full main control. The fifth,
permutes_mask_high_address_bits_and_divergent_branches, failed in the synthetic test group on both main and the integration, and passed three isolated runs on each.The separate runtime sampler-heap case still needs the point/linear choice to reach the shader. The existing fixture and measured
0x3f7fb000collision are linked in the issue. Runtime sampler reportIf you take the integration, please retain the original Git authors, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>for the review/integration changes if folding those into another commit.AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-29T16:22:15Z.
Retested the original runtime-sampler fixture on
c80e81f57198c31a7414e1512b584e75eedceccbon an RTX 4090 Laptop (10de:2757) and WARP (1414:008c). The original DXIL preflight stops before dispatch because it expects two sampler-heap handles and this head emits one. In a test-only variant, allowing a shared handle let the original readback checks run. Both SampleLevel calls consume the same annotated sampler (%26), with separate D16 and f32 stores.Three fresh processes each ran point → linear → point on the same slot for three texture pairs on both devices. All 54 paired f32/D16 rows matched the per-device table from
e87c4f1f03ec92794c3008a75c8ef0371b70cf87bit for bit. Point at0xffaf/0xffefstill gave0x3bfe/0x3c00; the exact normalized texels round to0x3bfd/0x3bff. Every linear D16 matched the half conversion of its device's paired f32, and the second point reproduced the first. These measurements cover the synthetic dynamic sampler slot.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.