fix(recompiler): sample with texel offsets the guest computes, through maintenance8's Offset #303

Merged
oneandonlydean merged 1 commit from upstream-pr/303 into main 2026-10-03 06:46:59 +00:00
oneandonlydean commented 2026-10-02 00:24:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-02T00:24:24Z.


What

image_sample_*_o reads its texel offset from an address VGPR. EmitSampleOp accepts only an immediate there and fails with requires a constant texel offset for image sampling for anything else. PPSA21564's title and menu post-processing programs move their offset into the VGPR under EXEC (v_mov_b32 v3, 1, which the IR reads back as a select of the old value), so those programs never compile on main.

Changes:

  • An offset that resolves (through identities) to a constant at its packed address position stays a ConstOffset, as before.
  • Any other offset becomes the Offset image operand, built with the existing PackedOffset (the same 6-bit signed fields). Vulkan allows Offset on sampling instructions only with VK_KHR_maintenance8's maintenance8 feature, and SPIR-V requires ImageGatherExtended for it. Without both, the sample still fails, now with has a texel offset that is not a constant, which image sampling takes only with VK_KHR_maintenance8 and shaderImageGatherExtended.
  • VulkanDevice enables maintenance8 when the extension and feature are present and reports it through the new SpirvTarget::nonConstantImageOffsets.
  • The flag is part of the recompile cache key and of the request serialization (version 6, read only from version 6 on). It also sets the SPIRV-Tools validator's allow_offset_texture_operand for the validation before and after optimization and for the optimizer's own validation.
  • agc_shader_replay --maintenance8 recompiles a dumped request for such a device.

Tested

  • Linux (CachyOS, RTX 4090, NVIDIA 610.57.04, which exposes VK_KHR_maintenance8).

  • agc_shader_memory_tests gains verifyComputedTexelOffsets, a wave32 compute program that samples with image_sample_lz_o:

    • with the offset taken from v0, it fails without nonConstantImageOffsets;
    • with the flag, it compiles to an OpImageSampleExplicitLod carrying Offset (not ConstOffset) and declares ImageGatherExtended;
    • with a literal offset, it gives ConstOffset and no ImageGatherExtended, with the flag and without it.

    The test also checks that the flag survives serialization, and agc_shader_disk_cache_tests checks that it changes the cache key. With main's sources and only the flag assignments taken out of the test, the computed-offset program fails with opcode=ImageSampleRaw reason=requires a constant texel offset for image sampling; the literal-offset case passes on main too.

  • ctest: 96/96 pass.

  • PPSA21564: this change has been on my integration branch through repeated passes of my visual regression check (from the intro video through the title and save menu into gameplay; checkpoint frames, flicker, video tearing and FPS). Before it, the title and menu post-processing programs failed to compile there and the scene went black.

Related open PRs: #226 decodes more _o sample variants, which reach this same path; there is no shared function. #295 enables other device features a few hunks away in VulkanDevice.cpp.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4711180316 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/303). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-02T00:24:24Z. --- ### What `image_sample_*_o` reads its texel offset from an address VGPR. `EmitSampleOp` accepts only an immediate there and fails with `requires a constant texel offset for image sampling` for anything else. PPSA21564's title and menu post-processing programs move their offset into the VGPR under EXEC (`v_mov_b32 v3, 1`, which the IR reads back as a select of the old value), so those programs never compile on main. Changes: - An offset that resolves (through identities) to a constant at its packed address position stays a `ConstOffset`, as before. - Any other offset becomes the `Offset` image operand, built with the existing `PackedOffset` (the same 6-bit signed fields). Vulkan allows `Offset` on sampling instructions only with `VK_KHR_maintenance8`'s `maintenance8` feature, and SPIR-V requires `ImageGatherExtended` for it. Without both, the sample still fails, now with `has a texel offset that is not a constant, which image sampling takes only with VK_KHR_maintenance8 and shaderImageGatherExtended`. - `VulkanDevice` enables `maintenance8` when the extension and feature are present and reports it through the new `SpirvTarget::nonConstantImageOffsets`. - The flag is part of the recompile cache key and of the request serialization (version 6, read only from version 6 on). It also sets the SPIRV-Tools validator's `allow_offset_texture_operand` for the validation before and after optimization and for the optimizer's own validation. - `agc_shader_replay --maintenance8` recompiles a dumped request for such a device. ### Tested - Linux (CachyOS, RTX 4090, NVIDIA 610.57.04, which exposes `VK_KHR_maintenance8`). - `agc_shader_memory_tests` gains `verifyComputedTexelOffsets`, a wave32 compute program that samples with `image_sample_lz_o`: - with the offset taken from `v0`, it fails without `nonConstantImageOffsets`; - with the flag, it compiles to an `OpImageSampleExplicitLod` carrying `Offset` (not `ConstOffset`) and declares `ImageGatherExtended`; - with a literal offset, it gives `ConstOffset` and no `ImageGatherExtended`, with the flag and without it. The test also checks that the flag survives serialization, and `agc_shader_disk_cache_tests` checks that it changes the cache key. With main's sources and only the flag assignments taken out of the test, the computed-offset program fails with `opcode=ImageSampleRaw reason=requires a constant texel offset for image sampling`; the literal-offset case passes on main too. - `ctest`: 96/96 pass. - PPSA21564: this change has been on my integration branch through repeated passes of my visual regression check (from the intro video through the title and save menu into gameplay; checkpoint frames, flicker, video tearing and FPS). Before it, the title and menu post-processing programs failed to compile there and the scene went black. Related open PRs: #226 decodes more `_o` sample variants, which reach this same path; there is no shared function. #295 enables other device features a few hunks away in `VulkanDevice.cpp`. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
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!303
No description provided.