fix(shader): keep cube image gradients out of the face coordinate bias #4209
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4209"
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 karanvora2599 on 2026-10-12T01:25:08Z.
What
image_sample_dandimage_sample_cdon a cube image now pass their gradients to the host sample unchanged. Before, the gradients were run through the coordinate conversion and lost 1.0 on each axis, so the sample read the smallest mip whatever the gradient.Background. Cubes are bound as 2D arrays.
CoordF32maps AMD's cube face coordinates from their [1, 2] range to [0, 1] by subtracting 1.0 from x and y (CubeAxis). The derivative path builds the gradient operands with the same function (SpirvImageEmitter.cpp, theRdnaImageSampleFlagDerivativebranch of the sample emitter), so a cube's gradients were biased too. A gradient is a difference of coordinates, so the bias doesn't belong there. A gradient of one texel, 1/16 on a 16×16 face, became about -0.94, and the LOD came out near the last level.Source. Mesa's AMD texture lowering,
src/amd/common/nir/ac_nir_lower_tex_coords.c,prepare_cube_coords:deriv_sc * invma - deriv_ma * sc, and the same fortc.sc + 1.5,tc + 1.5), never to the derivatives.So the hardware takes unbiased face-space gradients next to [1, 2] coordinates.
How.
CoordF32takes agradientflag, and the two gradient operands pass it, which skipsCubeAxis. Coordinates,image_get_lodand every non-cube image are unchanged.Tested
Windows 11, MinGW-w64 GCC 15.2.0, Release. Devices:
GALLIUM_OVERRIDE_CPU_CAPS=avx.This round's four changes were built and tested together on
mainatbca7a29d2(cube image gradients, early depth tests, bindless table search, LDS fence; one pull request each, in unrelated code). The branch is rebased onto34ba918bc. Its two new commits touch onlyGuestMemory.cppand thePreparedShaders.cppfixture.agc_driver_image_sample_cube_derivatives:image_sample_d. One gradient is set to 2^(level - 0.25) texels to select levels 0 to 4, the others are 0.image_sample_d cube: thread 0 (face 0, level 0) component 0 is 4.000000, expected 0. Every level-0 to level-3 sample read the last level.agc_driver_image_sample_derivatives,agc_driver_emulated_color_compareandagc_driver_image_sample_lod_clamppass. The last is skipped on the Intel UHD, which has noshaderResourceMinLod.agc_driver_*,agc_shader_*,agc_spirv_*,vector_*,agc_masked_select,agc_validate_program,agc_denormal*,agc_float16_*; 338 tests):agc_driver_prepared_shaders_registered_workgroup_sync, which fails the same way onmainatbca7a29d2(fixed since by #4177). I left out the BDA tests that lose the device on driver 591.86 (#3291):agc_driver_flat_loads*,agc_driver_global_loads*,agc_driver_flat_apertures*,agc_driver_pixel_interlock.main:agc_driver_ds_swizzle,agc_driver_f32_dot2_roundingandagc_driver_prepared_shaders_registered_workgroup_sync. Also,agc_driver_compute_user_data_calls_registeredexited with 0xc0000374 once under the suite's load, then passed three runs on its own.agc_driver_prepared_shaders_registered_workgroup_sync, as onmain.Limits.
TechnicalDebt.mdrecords that.image_sample_d.image_sample_cdtakes the same gradient path.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 karanvora2599 on 2026-10-12T03:22:46Z.
For the record, from @fma-rc's census of the shaders nine titles submit (https://github.com/fma-rc/AnyPS5/tree/evidence/shader-census: 749 shaders, 301,896 instructions; see #4061): there is no
image_sample_dorimage_sample_cdat all, so none of those titles takes this path.It stays a correctness fix for titles that sample cubes with explicit gradients. The new test shows what they get on
main: the last mip instead of the one the gradient selects.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:34:14Z.
Measured on RDNA2 (gfx1035) with the hardware oracle: on a 16x16, five-level cube, the level
image_sample_dreads matches unbiased face-space gradients (round(log2(16 * max(|ddx|, |ddy|)))) on all 1032 rows (every component, both signs, mixed, six faces, two coordinates); main's biased gradients miss 816 of them. The new test fails without the fix, and the scoped build and ctest pass.What we added on your branch:
TechnicalDebt.mdhas been split intodocs/dev/debt/, so the entry moved todebt/shader.md.image_sample_cdtakes one LOD per quad, from the quad's first lane, while the host computes it per lane. Main already has that gap and this PR doesn't change it.Merging once the full build is green.