fix(recompiler): sample the first row when the address omits coordinates #1416

Merged
gjonn merged 2 commits from upstream-pr/1416 into main 2026-10-11 09:14:21 +00:00
gjonn commented 2026-10-08 03:12:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gjonn on 2026-10-08T03:12:54Z.


What

A sample, gather or image_get_lod whose DIM field encodes fewer coordinates than the bound resource was refused at SPIR-V emission ("has an image address with too few coordinate components"). A title runs image_sample_lz with a 1D address on a 2D texture. This is the sampling counterpart of #1379, which reads missing components of image loads as 0.

CoordF32 now completes the address:

  • A missing position component samples the centre of the first row (or slice): 0.5 / extent of the base level, from OpImageQuerySizeLod. This is exact for an extent of 1 under any filter and addressing mode, and selects that row with point sampling. Bilinear sampling of a taller image reads only that row.
  • A missing array layer is layer 0.
  • A missing derivative component is 0.
  • Cube coordinates still need all components and throw, as does an address with fewer VGPRs than its own DIM.

The ISA does not document what the hardware reads for address components the instruction does not provide. Addressing the first row, slice or layer matches what #1379 does for loads.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, RTX 5090: agc_driver_image_address_dimension passes. The case that expected image_sample_l 1d on a 2D texture to be refused now checks its result: for 32 threads it returns row 0 of the selected level at the requested x (level, x >> level, 0, from a texture whose texels encode their level, x and y). The other image sampling tests still pass.
  • A title whose compute shader does this no longer aborts there.

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: #1379 (this branch is stacked on it; review only the last commit)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4781255916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1416). Originally posted by [gjonn](https://github.com/gjonn) on 2026-10-08T03:12:54Z. --- ### What A sample, gather or `image_get_lod` whose `DIM` field encodes fewer coordinates than the bound resource was refused at SPIR-V emission ("has an image address with too few coordinate components"). A title runs `image_sample_lz` with a 1D address on a 2D texture. This is the sampling counterpart of #1379, which reads missing components of image loads as 0. `CoordF32` now completes the address: - A missing position component samples the centre of the first row (or slice): `0.5 / extent` of the base level, from `OpImageQuerySizeLod`. This is exact for an extent of 1 under any filter and addressing mode, and selects that row with point sampling. Bilinear sampling of a taller image reads only that row. - A missing array layer is layer 0. - A missing derivative component is 0. - Cube coordinates still need all components and throw, as does an address with fewer VGPRs than its own `DIM`. The ISA does not document what the hardware reads for address components the instruction does not provide. Addressing the first row, slice or layer matches what #1379 does for loads. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, RTX 5090: `agc_driver_image_address_dimension` passes. The case that expected `image_sample_l` 1d on a 2D texture to be refused now checks its result: for 32 threads it returns row 0 of the selected level at the requested x (level, x >> level, 0, from a texture whose texels encode their level, x and y). The other image sampling tests still pass. - A title whose compute shader does this no longer aborts there. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #1379 (this branch is stacked on it; review only the last commit) - [x] AI-assisted: yes
Celegans12 commented 2026-10-08 09:11:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-08T09:11:36Z.


I've had this PR (50c65319b) in our Ghost of Yōtei (PPSA26344 v1.008) tree for two runs today, and it fixes the only SPIR-V emission failures the game had.

Without it, three pixel shaders failed with ImageSampleRaw ... has an image address with too few coordinate components (8 skipped draws in a 3,000 s run). With it, all three recompile: 0x802ce1bd00 into 42,225 SPIR-V words, 0x8053ebce00 into 19,047 and 0x8069151500 into 14,735, and an hour-long run from the disk cache has no emission failure at all. I can't tell you whether any of their images is a cube, since I have no dump of their T#s, and I haven't compared what they draw against a console.

The hour-long run had no FATAL and no Vulkan error.

Details

Windows 11, RTX 3080 Laptop. With the PR: our integration tree on main c8a2f0632 + this PR at 50c65319b. Without: the previous integration build.

Without the PR (the log prints the hashes in decimal: 550508805376 = 0x802ce1bd00, 551163776512 = 0x8053ebce00, 551518803200 = 0x8069151500):

[gpu] skipped draw: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x550508805376 stage=2 opcode=ImageSampleRaw reason=has an image address with too few coordinate components
[gpu] skipped draw: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x551163776512 stage=2 opcode=ImageSampleRaw reason=has an image address with too few coordinate components
[gpu] skipped draw: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x551518803200 stage=2 opcode=ImageSampleRaw reason=has an image address with too few coordinate components

With it (cold cache):

[capture] fragment variant 1a09da5f98f40ccd: program 0x802ce1bd00, 42225 SPIR-V words, recompile 9 ms
[capture] fragment variant c3b81fac03f9130f: program 0x8053ebce00, 19047 SPIR-V words, recompile 1 ms
[capture] fragment variant a180804cbd1ee4c5: program 0x8069151500, 14735 SPIR-V words, recompile 1 ms
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056609005 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1416#issuecomment-6056609005). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-08T09:11:36Z. --- I've had this PR (50c65319b) in our Ghost of Yōtei (PPSA26344 v1.008) tree for two runs today, and it fixes the only SPIR-V emission failures the game had. Without it, three pixel shaders failed with `ImageSampleRaw ... has an image address with too few coordinate components` (8 skipped draws in a 3,000 s run). With it, all three recompile: 0x802ce1bd00 into 42,225 SPIR-V words, 0x8053ebce00 into 19,047 and 0x8069151500 into 14,735, and an hour-long run from the disk cache has no emission failure at all. I can't tell you whether any of their images is a cube, since I have no dump of their T#s, and I haven't compared what they draw against a console. The hour-long run had no FATAL and no Vulkan error. <details><summary>Details</summary> Windows 11, RTX 3080 Laptop. With the PR: our integration tree on main c8a2f0632 + this PR at 50c65319b. Without: the previous integration build. Without the PR (the log prints the hashes in decimal: 550508805376 = 0x802ce1bd00, 551163776512 = 0x8053ebce00, 551518803200 = 0x8069151500): ``` [gpu] skipped draw: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x550508805376 stage=2 opcode=ImageSampleRaw reason=has an image address with too few coordinate components [gpu] skipped draw: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x551163776512 stage=2 opcode=ImageSampleRaw reason=has an image address with too few coordinate components [gpu] skipped draw: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x551518803200 stage=2 opcode=ImageSampleRaw reason=has an image address with too few coordinate components ``` With it (cold cache): ``` [capture] fragment variant 1a09da5f98f40ccd: program 0x802ce1bd00, 42225 SPIR-V words, recompile 9 ms [capture] fragment variant c3b81fac03f9130f: program 0x8053ebce00, 19047 SPIR-V words, recompile 1 ms [capture] fragment variant a180804cbd1ee4c5: program 0x8069151500, 14735 SPIR-V words, recompile 1 ms ``` </details>
adriadam10 commented 2026-10-08 13:10:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T13:10:22Z.

Review: CHANGES_REQUESTED


Measured on the HW oracle (gfx1035, image_sample_lz / image_sample_d, point and bilinear samplers with clamp, wrap, mirror and border addressing). The hardware reads an address component the instruction omits as 0 (normalized), exactly like an explicit 0, and ignores the next VGPR. 0.5 / extent gives the same result only under point sampling or clamp/mirror addressing:

case u HW (= explicit 0) this PR (= 0.5/extent)
1D on 2D, bilinear, wrap 0.3 15.70 0.70
1D on 2D, bilinear, border (black) 0.3 0.35 0.70
2D on 3D (4 slices), bilinear + linear Z, wrap (0.3, 0.3) 157.69 7.69

(4×4 R32F texture, texel = x + 10·y + 100·z.)

  • SpirvImageEmitter.cpp:173-181: a missing position component should be ZeroF32, the same as #1379 does for loads. That also removes the OpImageQuerySizeLod.
  • ImageAddressDimension.cpp:216-226: CheckNarrow samples with point filtering, so it passes with either 0 or 0.5 / extent. Please add a bilinear sampler with wrap (or border) addressing at a row where the two differ, so the test pins the value.
  • Missing derivative components read as 0 (measured with image_sample_d 1D on a 2D T#: the same result as explicit dtdx = dtdy = 0), so that part is correct.
  • With the measurement, the description can say that the hardware uses 0 instead of saying the ISA leaves it undocumented.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5457085895 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1416#pullrequestreview-5457085895). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T13:10:22Z. **Review:** CHANGES_REQUESTED --- Measured on the HW oracle (gfx1035, `image_sample_lz` / `image_sample_d`, point and bilinear samplers with clamp, wrap, mirror and border addressing). The hardware reads an address component the instruction omits as **0** (normalized), exactly like an explicit 0, and ignores the next VGPR. `0.5 / extent` gives the same result only under point sampling or clamp/mirror addressing: | case | u | HW (= explicit 0) | this PR (= 0.5/extent) | |---|---|---|---| | 1D on 2D, bilinear, wrap | 0.3 | 15.70 | 0.70 | | 1D on 2D, bilinear, border (black) | 0.3 | 0.35 | 0.70 | | 2D on 3D (4 slices), bilinear + linear Z, wrap | (0.3, 0.3) | 157.69 | 7.69 | (4×4 R32F texture, texel = x + 10·y + 100·z.) - `SpirvImageEmitter.cpp:173-181`: a missing position component should be `ZeroF32`, the same as #1379 does for loads. That also removes the `OpImageQuerySizeLod`. - `ImageAddressDimension.cpp:216-226`: `CheckNarrow` samples with point filtering, so it passes with either 0 or `0.5 / extent`. Please add a bilinear sampler with wrap (or border) addressing at a row where the two differ, so the test pins the value. - Missing derivative components read as 0 (measured with `image_sample_d` 1D on a 2D T#: the same result as explicit `dtdx = dtdy = 0`), so that part is correct. - With the measurement, the description can say that the hardware uses 0 instead of saying the ISA leaves it undocumented.
adriadam10 commented 2026-10-11 09:10:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T09:10:45Z.

Review: APPROVED


Thanks for the fix, and to @Celegans12 for running it on a title. Rebased onto current main and pushed two changes on top:

  • SpirvImageEmitter.cpp CoordF32: an omitted position component is now 0, not 0.5 / extent. Measured on gfx1035 (image_sample_lz/image_sample_d, point and bilinear, clamp/wrap/mirror/border): the hardware reads the omitted component as an explicit 0 and ignores the next VGPR. 0.5 / extent differs under wrap/border with bilinear filtering (1D on 2D, u = 0.3, wrap: HW 15.70 vs 0.70). This also drops the OpImageQuerySizeLod.
  • ImageAddressDimension.cpp: added a bilinear + wrap case that pins row 0/last-row averaging (7.5), which 0.5 / extent would fail; the existing point-sampled case passes with either value.
  • ResourceMaterializer.cpp RuntimeImageModes: after the runtime image mode table landed, a 1D access on a 2D T# no longer matched any mode and was refused with the same "too few coordinate components" before reaching the emitter. Sampled 1D accesses (not storage/depth/converted/packed) now also accept a 2D view.

agc_driver_image_address_dimension fails without the code changes and passes with them; the rest of the libSceAgc/libSceAgcDriver ctest scope is green. The PR description still mentions 0.5 / extent, please update it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5482701889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1416#pullrequestreview-5482701889). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T09:10:45Z. **Review:** APPROVED --- Thanks for the fix, and to @Celegans12 for running it on a title. Rebased onto current `main` and pushed two changes on top: - `SpirvImageEmitter.cpp` `CoordF32`: an omitted position component is now `0`, not `0.5 / extent`. Measured on gfx1035 (`image_sample_lz`/`image_sample_d`, point and bilinear, clamp/wrap/mirror/border): the hardware reads the omitted component as an explicit 0 and ignores the next VGPR. `0.5 / extent` differs under wrap/border with bilinear filtering (1D on 2D, u = 0.3, wrap: HW 15.70 vs 0.70). This also drops the `OpImageQuerySizeLod`. - `ImageAddressDimension.cpp`: added a bilinear + wrap case that pins row 0/last-row averaging (7.5), which `0.5 / extent` would fail; the existing point-sampled case passes with either value. - `ResourceMaterializer.cpp` `RuntimeImageModes`: after the runtime image mode table landed, a 1D access on a 2D T# no longer matched any mode and was refused with the same "too few coordinate components" before reaching the emitter. Sampled 1D accesses (not storage/depth/converted/packed) now also accept a 2D view. `agc_driver_image_address_dimension` fails without the code changes and passes with them; the rest of the libSceAgc/libSceAgcDriver ctest scope is green. The PR description still mentions `0.5 / extent`, please update it.
orishamir commented 2026-10-11 09:52:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orishamir on 2026-10-11T09:52:56Z.


The new agc_driver_image_address_dimension fails on lavapipe, so it is one of the three failures of CI's linux job on main since this merged: run 38128072167 on 4c9686fe (the other two, agc_driver_image_plane_address_on_line_implicit_lod and guest_kernel_stack_protect, are older and unrelated).

AGC graphics: image_sample_l 1d on a 2D texture, bilinear wrap: thread 0 component 2 is 8.000000, expected 7.500000

Replica of the job (ubuntu 24.04, GCC 13.3, Mesa 25.2.8 llvmpipe LLVM 20.1.2, ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx) on main a73a1af9: the same line 3/3. The same binary on Mesa 26.0.8 llvmpipe (LLVM 21.1.8) reads 7.000000 instead, also outside the 0.25 tolerance. So the bilinear sample at the omitted coordinate's 0 with wrap lands on one neighbour row or the other on llvmpipe instead of the half-way blend the RTX 5090 returned; the other cases of the test pass on both llvmpipes.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107770103 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1416#issuecomment-6107770103). Originally posted by [orishamir](https://github.com/orishamir) on 2026-10-11T09:52:56Z. --- The new `agc_driver_image_address_dimension` fails on lavapipe, so it is one of the three failures of CI's `linux` job on `main` since this merged: [run 38128072167](https://github.com/boykopovar/AnyPS5/actions/runs/38128072167) on 4c9686fe (the other two, `agc_driver_image_plane_address_on_line_implicit_lod` and `guest_kernel_stack_protect`, are older and unrelated). ``` AGC graphics: image_sample_l 1d on a 2D texture, bilinear wrap: thread 0 component 2 is 8.000000, expected 7.500000 ``` Replica of the job (ubuntu 24.04, GCC 13.3, Mesa 25.2.8 llvmpipe LLVM 20.1.2, `ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx`) on `main` a73a1af9: the same line 3/3. The same binary on Mesa 26.0.8 llvmpipe (LLVM 21.1.8) reads 7.000000 instead, also outside the 0.25 tolerance. So the bilinear sample at the omitted coordinate's 0 with wrap lands on one neighbour row or the other on llvmpipe instead of the half-way blend the RTX 5090 returned; the other cases of the test pass on both llvmpipes. 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!1416
No description provided.