fix(shader): sample a 1D T# through a 2D implicit-LOD image_sample #3222

Merged
fma-rc merged 2 commits from upstream-pr/3222 into main 2026-10-11 07:16:29 +00:00
fma-rc commented 2026-10-11 01:59:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T01:59:39Z.


What

A plain image_sample (implicit LOD, no bias, offset or compare) that says DIM 2D on a 1D T# had no runtime image mode and stopped the draw with image descriptor is incompatible with the static runtime image interface. The 1D mode already existed for image_sample_lz and mip-less image_load; this allows it for the plain sample as well, so the access becomes a 1D implicit-LOD sample on the first coordinate.

Source: measured with the hardware oracle on RDNA2 gfx1036 (Radeon 610M), wave32 and wave64, ieee 0, dx10_clamp 1, denormals preserved, round to nearest even. On a 16-texel, 5-mip 32_UINT 1D T# with point filters, DIM 2D picks the same mip and texel as DIM 1D for first-coordinate steps of 0, 1, 2, 4 and 8 texels per lane, whatever the second coordinate does; the same rows on a 16x16 2D T# move the mip with the second coordinate. The limits (point filters, gfx1036, and the LOD 0 every plain sample gets outside the pixel stage) are in docs/dev/TechnicalDebt.md.

Astro's Playroom (PPSA01325) draws with such a pair: pixel shader image_sample ... dim:SQ_RSRC_IMG_2D on a type 8 T#, format 71.

Tested

Arch Linux, GCC 16.2.1. New test agc_driver_image_plane_address_on_line_implicit_lod samples a 16-texel, 5-mip 1D T# from a pixel shader with DIM 2D while the second coordinate advances 3 per pixel, and requires mip 0, 1 or 2 by the first coordinate's step and the right texel on every pixel; image_sample_b on the same pair must still be refused. It fails on main d31b57a4c with the error above and passes with the change, on an RTX 5080 and on RADV gfx1036. Full ctest: 753/753 on RADV; on the RTX 5080 only agc_driver_dcc_keys_first_write fails, which this change does not touch. tools/check_conventions.py --base origin/main passes.

The title needs two changes that are not on main to get this far (#3186 and #3214), so the title runs used all three together: without this one it stops on the image error (2 of 2 runs), with it that error is gone and the title stops later on its own Out of Global Heap Memory assert (2 of 2 runs).

Not tested: Windows, linear filtering through such a pair, the PS5's gfx1013.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4815904203 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3222). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-11T01:59:39Z. --- ### What A plain `image_sample` (implicit LOD, no bias, offset or compare) that says DIM 2D on a 1D T# had no runtime image mode and stopped the draw with `image descriptor is incompatible with the static runtime image interface`. The 1D mode already existed for `image_sample_lz` and mip-less `image_load`; this allows it for the plain sample as well, so the access becomes a 1D implicit-LOD sample on the first coordinate. Source: measured with the hardware oracle on RDNA2 gfx1036 (Radeon 610M), wave32 and wave64, `ieee 0`, `dx10_clamp 1`, denormals preserved, round to nearest even. On a 16-texel, 5-mip 32_UINT 1D T# with point filters, DIM 2D picks the same mip and texel as DIM 1D for first-coordinate steps of 0, 1, 2, 4 and 8 texels per lane, whatever the second coordinate does; the same rows on a 16x16 2D T# move the mip with the second coordinate. The limits (point filters, gfx1036, and the LOD 0 every plain sample gets outside the pixel stage) are in `docs/dev/TechnicalDebt.md`. Astro's Playroom (PPSA01325) draws with such a pair: pixel shader `image_sample ... dim:SQ_RSRC_IMG_2D` on a type 8 T#, format 71. ### Tested Arch Linux, GCC 16.2.1. New test `agc_driver_image_plane_address_on_line_implicit_lod` samples a 16-texel, 5-mip 1D T# from a pixel shader with DIM 2D while the second coordinate advances 3 per pixel, and requires mip 0, 1 or 2 by the first coordinate's step and the right texel on every pixel; `image_sample_b` on the same pair must still be refused. It fails on `main` d31b57a4c with the error above and passes with the change, on an RTX 5080 and on RADV gfx1036. Full ctest: 753/753 on RADV; on the RTX 5080 only `agc_driver_dcc_keys_first_write` fails, which this change does not touch. `tools/check_conventions.py --base origin/main` passes. The title needs two changes that are not on `main` to get this far (#3186 and #3214), so the title runs used all three together: without this one it stops on the image error (2 of 2 runs), with it that error is gone and the title stops later on its own `Out of Global Heap Memory` assert (2 of 2 runs). Not tested: Windows, linear filtering through such a pair, the PS5's gfx1013. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-11 01:59:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T01:59:49Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6104417649 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3222#issuecomment-6104417649). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T01:59:49Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
reyani-dev commented 2026-10-11 06:14:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by reyani-dev on 2026-10-11T06:14:55Z.


Windows run, since the PR lists Windows as untested. Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, RTX 4070 Laptop GPU (driver 616.92), head 8132ac7a merged onto main 4be74d4f. I ran with VK_LOADER_DRIVERS_DISABLE=*dzn* because this machine's Dozen ICD crashes on its own (#3255).

  • The build has no warnings.
  • agc_driver_image_plane_address_on_line_implicit_lod passes, as does the existing agc_driver_image_plane_address_on_line.
  • ctest -R "^agc_|video_out|^shader|recompiler": 358/358 pass. The VideoOut flip tests skip as usual on this machine.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106151798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3222#issuecomment-6106151798). Originally posted by [reyani-dev](https://github.com/reyani-dev) on 2026-10-11T06:14:55Z. --- Windows run, since the PR lists Windows as untested. Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release, RTX 4070 Laptop GPU (driver 616.92), head `8132ac7a` merged onto `main` `4be74d4f`. I ran with `VK_LOADER_DRIVERS_DISABLE=*dzn*` because this machine's Dozen ICD crashes on its own (#3255). - The build has no warnings. - `agc_driver_image_plane_address_on_line_implicit_lod` passes, as does the existing `agc_driver_image_plane_address_on_line`. - `ctest -R "^agc_|video_out|^shader|recompiler"`: 358/358 pass. The VideoOut flip tests skip as usual on this machine.
adriadam10 commented 2026-10-11 07:16:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:16:26Z.


Checked on RDNA2 (gfx1035) with the hardware oracle, compute kernel with quad derivatives, IEEE 0 and 1: across 2880 lanes, plain image_sample with DIM 2D on a 16-texel, 5-mip 1D T# returns the same bits as DIM 1D for point and trilinear filtering, clamp and wrap, whatever the second coordinate does; the mip is round(log2(max |du|)) on every lane, and a 16x16 2D T# moves with the second coordinate as a control. So linear filtering matches too. The new test passes on RADV and fails without the change. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106588293 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3222#issuecomment-6106588293). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T07:16:26Z. --- Checked on RDNA2 (gfx1035) with the hardware oracle, compute kernel with quad derivatives, IEEE 0 and 1: across 2880 lanes, plain `image_sample` with DIM 2D on a 16-texel, 5-mip 1D T# returns the same bits as DIM 1D for point and trilinear filtering, clamp and wrap, whatever the second coordinate does; the mip is round(log2(max |du|)) on every lane, and a 16x16 2D T# moves with the second coordinate as a control. So linear filtering matches too. The new test passes on RADV and fails without the change. Merging.
orishamir commented 2026-10-11 07:57:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-11T07:57:16Z.


agc_driver_image_plane_address_on_line_implicit_lod fails on lavapipe, so CI's linux job is red on main since this merged: run 38121878271 (2bb78d2c) fails only this test of 790, and the pre-merge dispatch of this PR, run 38118105222 (06:27Z), failed the same way:

AGC graphics: image_sample 2d on a 1D texture with the first coordinate advancing 1 texels per pixel: pixel 20,0 component 0 is 170, expected 10

Replica of the job (ubuntu 24.04, GCC 13.3, Mesa 25.2.8 llvmpipe LLVM 20.1.2, the driver CI logs, ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx), on main b6f649d9:

  • A copy of the test with Require replaced by a record of every wrong pixel reads the wrong mip at 88 of 1024 pixels for step 1 and 94 for steps 2 and 4, the same pixels in 10 of 10 runs; the same binary gives the same pixels on Mesa 26.0.8 (LLVM 21.1.8).
  • The wrong pixels are whole 2x2 quads reading the 1x1 mip (mark 170) where mip 0 was expected, a few quads reading mips 2 and 3, and at steps 2 and 4 single pixels on the diagonal x + y = 20 reading mip 0.
  • Holding the second coordinate at 0 instead of advancing 3 per pixel changes nothing (same 88/94/94). agc_driver_image_plane_address_on_line (image_sample_lz on the same coordinate) passes, so the coordinate is right and what differs is the LOD llvmpipe computes for this sample.
  • The recompiled fragment shader has one OpImageSampleImplicitLod on a Dim1D sampled image with a scalar float coordinate, in the entry block; spirv-val --target-env vulkan1.3 passes. RADV, the RTX 5080 and the RTX 4070 pass per the PR and @AchrafReyani's run.
Step 1 map: rows y = 0..15, 64 pixels each, `.` right, digit = mip level read
  y 0 ....................44..........................................
  y 1 ....................44..........................................
  y 2 ................................................................
  y 3 ................................................................
  y 4 ..............44................................................
  y 5 ..............44................................................
  y 6 ............44..................................................
  y 7 ............44..................................................
  y 8 ................................................................
  y 9 ................................................................
  y10 ......33..............................................4444444444
  y11 ......33..............................................4444444444
  y12 ....22........................444444444444......................
  y13 ....22........................444444444444......................
  y14 ......333333444444..............................................
  y15 ......333333444444..............................................

AI-assisted: yes (Claude Code Fable 5.1 xhigh)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6106896713 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3222#issuecomment-6106896713). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-11T07:57:16Z. --- `agc_driver_image_plane_address_on_line_implicit_lod` fails on lavapipe, so CI's `linux` job is red on `main` since this merged: [run 38121878271](https://github.com/boykopovar/AnyPS5/actions/runs/38121878271) (2bb78d2c) fails only this test of 790, and the pre-merge dispatch of this PR, [run 38118105222](https://github.com/boykopovar/AnyPS5/actions/runs/38118105222) (06:27Z), failed the same way: ``` AGC graphics: image_sample 2d on a 1D texture with the first coordinate advancing 1 texels per pixel: pixel 20,0 component 0 is 170, expected 10 ``` Replica of the job (ubuntu 24.04, GCC 13.3, Mesa 25.2.8 llvmpipe LLVM 20.1.2, the driver CI logs, `ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx`), on `main` b6f649d9: - A copy of the test with `Require` replaced by a record of every wrong pixel reads the wrong mip at 88 of 1024 pixels for step 1 and 94 for steps 2 and 4, the same pixels in 10 of 10 runs; the same binary gives the same pixels on Mesa 26.0.8 (LLVM 21.1.8). - The wrong pixels are whole 2x2 quads reading the 1x1 mip (mark 170) where mip 0 was expected, a few quads reading mips 2 and 3, and at steps 2 and 4 single pixels on the diagonal x + y = 20 reading mip 0. - Holding the second coordinate at 0 instead of advancing 3 per pixel changes nothing (same 88/94/94). `agc_driver_image_plane_address_on_line` (`image_sample_lz` on the same coordinate) passes, so the coordinate is right and what differs is the LOD llvmpipe computes for this sample. - The recompiled fragment shader has one `OpImageSampleImplicitLod` on a `Dim1D` sampled image with a scalar float coordinate, in the entry block; `spirv-val --target-env vulkan1.3` passes. RADV, the RTX 5080 and the RTX 4070 pass per the PR and @AchrafReyani's run. <details><summary>Step 1 map: rows y = 0..15, 64 pixels each, `.` right, digit = mip level read</summary> ``` y 0 ....................44.......................................... y 1 ....................44.......................................... y 2 ................................................................ y 3 ................................................................ y 4 ..............44................................................ y 5 ..............44................................................ y 6 ............44.................................................. y 7 ............44.................................................. y 8 ................................................................ y 9 ................................................................ y10 ......33..............................................4444444444 y11 ......33..............................................4444444444 y12 ....22........................444444444444...................... y13 ....22........................444444444444...................... y14 ......333333444444.............................................. y15 ......333333444444.............................................. ``` </details> AI-assisted: yes (Claude Code Fable 5.1 xhigh)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!3222
No description provided.