fix(shader): pack D16 image reads toward zero and saturate 32-bit integers as RDNA2 does #22750
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22750"
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 boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-11-18T06:56:18Z.
What
D16 image reads packed their components the host's way, which differs from RDNA2. Floats went through
packHalf2x16: round to nearest even, overflow to infinity, signaling NaNs quieted. Integers were truncated to their low 16 bits. RDNA2's texture unit does this instead:Change (
SpirvImageEmitter.cpp, the D16 branch shared by loads, samples and gathers):float components are packed toward zero with the existing
EmitPackFloat2x16Rtz(thev_cvt_pkrtz_f16_f32lowering) when the new per-image specialization constantD16TowardZeroBase + indexis 1, else to nearest withEmitPackHalf2x16as before.DescriptorBindingBuildersets the constant from the T# format for direct images that have a 16-bit data access (!depthBitsCompatible): 1 for 32_FLOAT, 32_32_FLOAT, 32_32_32_FLOAT and 32_32_32_32_FLOAT, 0 otherwise. Images read through a table and registration modules do not know the format, so they keep round-to-nearest. A NaN input then gets the hardware's NaN half;integer components go through
UMin(·, 0xffff)/SClamp(·, −32768, 32767)before the 16-bit mask. 8- and 16-bit formats never exceed that range, so they are unaffected.test: new
ImageD16Load.cpploads 16 texels each of 32_UINT, 32_SINT, 32_FLOAT, 16_FLOAT, 8_UNORM and 8_SNORM withimage_load … d16(DMASK 0x1). The 8_UNORM row includes code 9, which reads 0x2885 (toward zero would give 0x2884). It checks every lane against the gfx1036 result and the three untouched sentinels. The texel and expected tables were run throughtools/hw-oracleon gfx1036 as they stand in the file, and match.debt: a new
shader.mdentry (fragmentdocs/dev/debt/changes/fix-d16-image-reads-round-toward-zero.md).Source of the semantics:
tools/hw-oracleon gfx1036 (AMD Windows driver 32.0.21045.16010) withimage_load, pointimage_sample_lzandimage_gather4(D16) over the values above. The sample and gather use the same packing as the load: toward zero and saturating. A point sample of a NaN first sees the sampler's canonical 0xffc00000 and so returns 0xfe00. That NaN-texel difference is recorded in #22727 and is not changed here.Tested
Windows 11 Pro 10.0.26200, validation layer 1.4.363,
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer:agc_driver_image_d16_load, this branchVUID-VUID-main(fix reverted)image_load d16 of 32_UINT texel 0x00010000: v10 is 0x00000000, RDNA 2 returns 0x0000ffffctest -R 'agc_driver_(image|format_d16|d16|depth_storage|sampled_cache_budget|depth_plane_sampling|texture)|agc_shader_memory'(132 tests), this branch (incl.agc_driver_image_table, which exercises table images that must not get the constant)image_plane_address_on_line,image_sample_lod_clampandimage_sample_lod_clamp_shader_lanefail, as they do onmainon this GPUagc_driver_graphicsand the 63^agc_driver_graphics$|^agc_shadertests also pass on both GPUs. Every log showsInsert instance layer "VK_LAYER_KHRONOS_validation", and none showswas not found but was requested.A differential run of the hardware oracle against
agc_oracle_runnerwith this change found:pr_overlap.py --branchfailed closed on 12 open PRs that shareSpirvImageEmitter.cpp. None of their diffs touches the D16 packing.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T07:58:36Z.
Review: COMMENTED
Reviewed — no blocking findings
The changed D16 packing logic and its load test are consistent with the stated behavior; I did not run the tests or independently confirm the reported hardware results.
What I ran
Reviewed head
dbd8b11ad392e81af9fdda24d10b41212f4ab670using the prepared review bundle and the pinned repository reader. No executable commands or tests were run. I read the full newImageD16Load.cpp, the changedResultVectorfunction and its RTZ helper, and the full debt entry. The shader source was otherwise not read.Results
Negative control
Could not run a negative control because tests were not run.
Findings
Blocking
None.
Non-blocking
Sources
Not verified
I did not run the build or tests, and did not independently verify the described NVIDIA or AMD hardware behavior. The rest of
SpirvImageEmitter.cppwas not read. All three changed files were included in the review bundle; the test and debt entry were read in full, while only the changed shader function and the referenced conversion helper were read.To get this to a good state
Nothing is required. Optional: add sample and gather regression coverage for D16 conversion.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T16:40:32Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the focused code and test support the stated D16 packing behavior.
What I ran
Reviewed head
671392e910644307c003f2da81dc4095a34ab5fc. No commands or tests were run in this review; the hardware and test results in the description are author reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. Hardware behavior and the author reported CI/test results were not independently verified. All files listed as reviewed in
manifest.jsonwere read:ImageD16Load.cpp,DescriptorBindingBuilder.cpp,PipelineSpecialization.hpp,SpirvImageEmitter.cpp, and the D16 debt entry. No changed files were excluded.To get this to a good state
Nothing is required.