Skip to content

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

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
gjonn:fix/recompiler-sample-missing-coordinates
Oct 11, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
gjonn:fix/recompiler-sample-missing-coordinates

Conversation

@gjonn

@gjonn gjonn commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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: fix(recompiler): read image address components the instruction omits as 0 #1379 (this branch is stacked on it; review only the last commit)
  • AI-assisted: yes

@Celegans12

Copy link
Copy Markdown
Contributor

I've had this PR (50c6531) 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 c8a2f06 + this PR at 50c6531. 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

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 8, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 8, 2026
gjonn and others added 2 commits October 11, 2026 11:07
…n omits as 0

Measured on hardware: a position component the instruction omits reads as 0, like an explicit 0, and the next VGPR is ignored. Missing array layers and derivative components are 0 too. Cube coordinates still need all components.
A 1D sample or load of a 2D T# had no runtime image mode after the mode table landed, so it was still refused at materialization. Sampled 1D accesses now also accept a 2D view; the address completion in the emitter reads the missing row as 0.
@adriadam10
adriadam10 force-pushed the fix/recompiler-sample-missing-coordinates branch from 50c6531 to 60a14b5 Compare October 11, 2026 09:10

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@adriadam10
adriadam10 merged commit 3e1fa82 into boykopovar:main Oct 11, 2026
14 checks passed
@orishamir

Copy link
Copy Markdown
Contributor

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 4c9686f (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 a73a1af: 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants