fix(shader): let image samples clamp their LOD on devices with shaderResourceMinLod #388

Merged
DotDebian merged 1 commit from upstream-pr/388 into main 2026-10-04 01:04:31 +00:00
DotDebian commented 2026-10-02 17:05:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DotDebian on 2026-10-02T17:05:08Z.


What

Every image sample with an LOD clamp (image_sample_cl, _d_cl, _b_cl, _c_cl, _cl_o, _cl_a) fails to compile with clamps its LOD, which needs the device's shaderResourceMinLod, also on devices that have the feature.

  • EmitSampleOp looked for CapabilityMinLod in state.requirements.capabilities. AnalyzeProgramRequirements never fills that list, so the check could not pass. It now reads state.supportedCapabilities, the target's list, where VulkanDevice puts CapabilityMinLod when shaderResourceMinLod is enabled.
  • A sample that takes the MinLod image operand now declares OpCapability MinLod. Nothing declared it.

The gate is otherwise unchanged: the explicit-level path (level clamped with FMax) still asks for the device feature, it only reads the right list.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5080. ctest: 109/109 pass.

New execution test agc_driver_image_sample_lod_clamp (tests/execution/ImageSampleLodClamp.cpp). A compute shader samples a 16x16 texture with five mip levels, point filtered, where each texel stores its level and position:

v_lshlrev_b32 v1, 6, v0
buffer_load_dword v5..v11, v1, s[0:3], 0 offen offset:0..24
s_waitcnt
image_sample_d_cl v[12:15], v[5:11], s[4:11], s[12:15]
buffer_store_dword v12..v15, v1, s[0:3], 0 offen offset:32..44
image_sample_cl v[12:15], v[9:11], s[4:11], s[12:15]
buffer_store_dword v12..v15, v1, s[0:3], 0 offen offset:48..60
s_endpgm
  • image_sample_d_cl takes the Grad and MinLod operands: the level read is max(level of the gradients, clamp). The 32 threads put the gradient in each of the four derivative slots, on levels 0 to 4, against clamps 0 to 3.
  • image_sample_cl in a compute shader samples an explicit level 0 clamped with FMax: the level read is the clamp.
  • The test fails on main with the error above. It also fails when the emitter drops the MinLod operand or the FMax (checked by hand, not part of the change).
  • It is skipped (77) without a Vulkan device or without shaderResourceMinLod.

Not tested: a title, a pixel shader (implicit LOD with MinLod, the same operand path), the Vulkan validation layers (not installed here).

Checklist

  • Based on current main; no other open PR implements the same functions (#226 adds more _cl opcodes to the decoder, #303 edits the offset block of EmitSampleOp; neither touches the capability check, both merge cleanly with this branch)
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4719206135 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/388). Originally posted by [DotDebian](https://github.com/DotDebian) on 2026-10-02T17:05:08Z. --- ### What Every image sample with an LOD clamp (`image_sample_cl`, `_d_cl`, `_b_cl`, `_c_cl`, `_cl_o`, `_cl_a`) fails to compile with `clamps its LOD, which needs the device's shaderResourceMinLod`, also on devices that have the feature. - `EmitSampleOp` looked for `CapabilityMinLod` in `state.requirements.capabilities`. `AnalyzeProgramRequirements` never fills that list, so the check could not pass. It now reads `state.supportedCapabilities`, the target's list, where `VulkanDevice` puts `CapabilityMinLod` when `shaderResourceMinLod` is enabled. - A sample that takes the `MinLod` image operand now declares `OpCapability MinLod`. Nothing declared it. The gate is otherwise unchanged: the explicit-level path (level clamped with `FMax`) still asks for the device feature, it only reads the right list. ### Tested Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5080. `ctest`: 109/109 pass. New execution test `agc_driver_image_sample_lod_clamp` (`tests/execution/ImageSampleLodClamp.cpp`). A compute shader samples a 16x16 texture with five mip levels, point filtered, where each texel stores its level and position: ``` v_lshlrev_b32 v1, 6, v0 buffer_load_dword v5..v11, v1, s[0:3], 0 offen offset:0..24 s_waitcnt image_sample_d_cl v[12:15], v[5:11], s[4:11], s[12:15] buffer_store_dword v12..v15, v1, s[0:3], 0 offen offset:32..44 image_sample_cl v[12:15], v[9:11], s[4:11], s[12:15] buffer_store_dword v12..v15, v1, s[0:3], 0 offen offset:48..60 s_endpgm ``` - `image_sample_d_cl` takes the `Grad` and `MinLod` operands: the level read is `max(level of the gradients, clamp)`. The 32 threads put the gradient in each of the four derivative slots, on levels 0 to 4, against clamps 0 to 3. - `image_sample_cl` in a compute shader samples an explicit level 0 clamped with `FMax`: the level read is the clamp. - The test fails on `main` with the error above. It also fails when the emitter drops the `MinLod` operand or the `FMax` (checked by hand, not part of the change). - It is skipped (77) without a Vulkan device or without `shaderResourceMinLod`. Not tested: a title, a pixel shader (implicit LOD with `MinLod`, the same operand path), the Vulkan validation layers (not installed here). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#226 adds more `_cl` opcodes to the decoder, #303 edits the offset block of `EmitSampleOp`; neither touches the capability check, both merge cleanly with this branch) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!388
No description provided.