fix(agc): sample the base level of mipmapped views with unnormalized coordinates #1377
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1377"
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 gjonn on 2026-10-08T01:06:50Z.
What
A sampled image used with an unnormalized-coordinate sampler had to be a single-level view starting at mip 0, otherwise binding it threw. A title samples full mip chains this way from compute shaders during start-up: a 10-level 2D view at base level 0, and a 7-level view at base level 3 (a downsample chain).
Vulkan accepts unnormalized samplers only on single-level views, and the hardware samples the view's base level in that mode (the existing test already checks that
image_sample_land sampler LOD bias/clamps do not move it off level 0).Texturekeeps the create info for a one-level, one-layer view of the descriptor's base mip (1D, 2D, or the first layer of a 2D array) when the sampled view has more than one level, and creates that view on first use.ShaderResourcesbinds that view for unnormalized samplers instead of throwing. Views with more than one layer, other view types and a minimum LOD clamp still throw.Tested
agc_driver_image_sample_unnormalizedpasses with two new cases for every sampler and instruction: a full 4-level view samples like a 1-level image, and a 3-level view starting at mip 1 samples mip 1 in mip-1 texel coordinates (mip 1 now holds its own pattern).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T12:39:16Z.
Review: CHANGES_REQUESTED
Measured on RDNA2 hardware (gfx1035 via our HW oracle; 2D T# with 4 levels, BASE_LEVEL 0..3, the same instructions and S# words as this test). Probe:
sample_unnormalized_mips.py, happy to share it.image_sample_lzwith an S# that has no MIN_LOD/bias does read BASE_LEVEL, with coordinates in that level's texels (0 mismatches over every row, clamp and border modes included). So your one-level base view is exact for that case.image_sample_lwith LOD 2.7 reads mip 3 (base 0, 1 and 2 alike).image_samplepicks the level from the derivatives. Lanes in the same dispatch read mips 0 to 3.MIN_LOD 1, LOD bias 1.5sampler moves evenimage_sample_lzoff the base level (base 0 → a blend of mips 1 and 2, base 2 → mip 3).ImageSampleUnnormalized.cpp:248-251requires the base level for all 3 instructions and all 5 samplers onchainandfromLevelOne. It pins results the hardware doesn't produce.mainthrew in these cases, and now they return a plausible but wrong value.levels > 1only when the result is exact. That means every sample through the binding is an_lzform (the recompiler would need to flag that next toimageUnnormalized), and the S# has MIN_LOD 0 and no positive bias. Keep throwing otherwise. In the test, check the exact case and useExpectFailurefor the others.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-08T19:12:54Z.
Linux results, since this was tested on Windows only. Everything passes here.
Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
BUILD_TESTING=ON. This PR merged ontomain29e533ac.main29e533acmain+ this PRctest -R agc_driver -j1-E agc_driver)The CPU failure is
guest_dynamic_loader, which fails the same way onmain.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:12:51Z.
Review: APPROVED
Thanks @fisherjoey for the Linux runs. Checked this on RDNA2 hardware (gfx1035): with unnormalized coordinates the base level is only read by
image_sample_lzthrough an S# without MIN_LOD or LOD bias;image_sample_l,image_sampleand biased samples pick other mips on a mipmapped view.Added on your branch, since it had no push after the review:
main.image_sample_lzthrough an unnormalized S# with MIN_LOD 0 and bias 0 (imageUnnormalizedBaseLevel, proved inDescriptorBindingBuilder; newSamplerUseNonZeroLoduse bit). Selected-LOD, implicit-LOD and texel-offset uses keep throwing.FormatVersion26 → 27 and the layout checks for the new field and the wideruses.ImageSampleUnnormalized: animage_sample_lz-only program on the 4-level view and on the view from mip 1, andExpectFailurecases for_l/image_sample, a view from mip 1 with them, texel offsets, and an S# with MIN_LOD and bias.ShaderMemory/ShaderDiskCachecover the new flag.agc_driver_image_sample_unnormalized,agc_shader_memoryandagc_shader_disk_cachepass on RADV; a mutant that accepts_lis caught. The mip 1 case is still skipped on llvmpipe, so CI does not cover it.