Repository navigation
fix(agc): sample the base level of mipmapped views with unnormalized coordinates - #1377
Conversation
adriadam10
left a comment
There was a problem hiding this comment.
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.- It is not exact for the rest. With unnormalized coordinates the hardware still selects a LOD:
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.- The
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.- A possible direction: accept
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. - Minor: the llvmpipe skip leaves the mip-1 case untested on Linux CI. On RADV it passes here.
|
Linux results, since this was tested on Windows only. Everything passes here. Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
The CPU failure is |
…coordinates Vulkan only accepts unnormalized samplers on single-level views, while the guest binds full mip chains and samples their base level. Bind a lazily created one-level view of the descriptor's base mip instead of refusing mipmapped views and views that start above mip 0.
…d coordinates only where the hardware does Multi-level views, and views starting above mip 0, are bound as their base level only when every use of the image is image_sample_lz through an unnormalized S# without minimum LOD or LOD bias, the case measured exact on RDNA2. Selected-LOD, implicit-LOD and offset uses keep throwing. The recompiler records selected-LOD uses (SamplerUseNonZeroLod) and proves the case per image (imageUnnormalizedBaseLevel); the shader disk cache format goes to 27. Co-Authored-By: Claude <noreply@anthropic.com>
22b49f5 to
ac1c3b7
Compare
adriadam10
left a comment
There was a problem hiding this comment.
Thanks @fisherjoey for the Linux runs. Checked this on RDNA2 hardware (gfx1035): with unnormalized coordinates the base level is only read by image_sample_lz through an S# without MIN_LOD or LOD bias; image_sample_l, image_sample and biased samples pick other mips on a mipmapped view.
Added on your branch, since it had no push after the review:
- Rebased onto current
main. - Multi-level views, and views starting above mip 0, are bound as their base level only when every use of the image is
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. - Shader disk cache
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_memory and agc_shader_disk_cache pass on RADV; a mutant that accepts _l is caught. The mip 1 case is still skipped on llvmpipe, so CI does not cover it.
|
@adriadam10 a follow-up for your RDNA2 oracle, if you have time. Gran Turismo 7 (PPSA01317) has ten hull programs that sample a 10-level 512x256 2D texture with Your review here found that AI-assisted: yes (Claude Code) |
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)