shader: move coordinates for runtime texel offsets of image samples (NHL 27, #1101) #1446
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1446
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1446/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@overlordxrz-source on GitHub · 2026-10-12 08:52 UTC · original
overlordxrz-source:fix/runtime-texel-offsets→main· +187 −9 · 2 files · 1 commits · closed without mergingStop: NHL 27 (PPSA34063) on the official
e51de54build crashes right after you pick teams for a quick game. fozter's log on #1101 ends with:Cause:
984cfcebdemits aConstOffsetwhen the offset DWORD of anIMAGE_SAMPLE*_Ois constant in the active lanes. When it isn't constant, it callsctx.Fail(spirvEmitterImage.cpp,ctx.Failon the non-constant sample offset path), because Vulkan allows a non-constantOffsetimage operand only on gathers. The NHL 27 compute shader0x8ff7afec7c5ab786(3 blocks) has an offset like that, so the compute pipeline is never built. The log has no disassembly for it, so I can't tell which_Ovariant it uses, or whether the offset comes from a VGPR or an SGPR.Change (spirvEmitterImage.cpp, sample path only):
ConstOffsetthroughPackedOffset.OffsetSampleCoordinates. It no longer fails: for each spatial component it decodes the signed 6-bit offset at bits [5:0], [13:8] and [21:16] withOpBitFieldSExtract, then addsoffset / sizeto the coordinate. The array layer isn't changed.sizecomes fromOpImageQuerySizeLodat the level the sample reads, rounded to the nearest level and clamped to[0, OpImageQueryLevels - 1]. That level is:_L_O: the explicit LOD._LZ_O, and implicit samples outside pixel shaders, which this emitter already samples at LOD 0: level 0._D_O:0.5 * log2(max(|ddx|², |ddy|²)), with the gradients scaled to texels of the base level.OpImageQueryLod(unclamped.y) plus the instruction's bias.OffsetwithImageGatherExtended.The coordinate-shift approach is TheCruZ's from #1220, credited with Co-authored-by. #1220 was written before
984cfcebdand now conflicts with main. This patch keeps main'sConstOffset/exec handling and adds only the runtime path.Test:
ImageSampleRuntimeOffsetsMoveCoordinatesinshader_recompiler_compute_tests. It also runs with--image-sample-offset-only. It builds the offset fromv0(v_add_nc_u32with a literal), so it isn't an IR constant, on a 16×16 image:_LZ_Owith (+3, +1)_LZ_Owith (-9, +8), outside the guaranteedConstOffsetrange_L_Owith LOD 3 on a single-level image, which has to clamp to level 0_D_Owith one-texel gradientsIt expects the four shifted texels, requires
OpImageQuerySizeLod/OpImageQueryLevels/OpFDiv, and forbidsConstOffset.Not verified:
-fsyntax-only, x86_64).Checks:
spirvEmitterImage.cppcompiles with zig/clang x86_64-linux-gnu,-std=c++20 -Wall -Wextra: rc=0, 0 warnings.tests/ShaderRecompilerComputeTests.cpppasses-fsyntax-onlywith 0 errors.dad900c(cherry-pick, no conflicts); spirvEmitterImage.cpp recompiled there rc=0 and the tests file passes-fsyntax-only.Refs #1101 (NHL 27 stop after team selection). Follow-up to #1220 at TheCruZ's request (he asked for it on #1220 and will close #1220 once this is up).
AI-assisted: yes (investigation, code and description; I reviewed it. The coordinate-shift approach is from TheCruZ's #1220).
@coderabbitai[bot] on GitHub · 2026-10-12 08:57 UTC · original
📝 Walkthrough
Walkthrough
SPIR-V emission now adjusts non-cube image coordinates for runtime sample offsets, using the selected mip extent. It derives the mip from explicit LOD, gradients, or an implicit pixel-shader LOD query with sampler bias. Immediate offsets remain image operands, and cube candidates skip runtime adjustment. A compute test covers four sampling forms and checks the generated SPIR-V.
Suggested reviewers:
nmzik,claxten10,popcoder565Priority: ⬇️ Low
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: 🔵 Low · up to
5b302The change is mergeable with a follow-up test using distinct mip levels. The current test cannot catch incorrect offset scaling across levels.
Pre-merge checks |
4 |
1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
#1220]. It preserves the existingConstOffsetpath for constant offsets. It adds runtime coordinate shifts for non-constantIMAGE_SAMPLE*_Ooffse…spirvEmitterImage.cppandShaderRecompilerComputeTests.cpp. The emitter changes implement runtime texel offsets from [#1220] and address the NHL 27 failure described in [#110…Full details: Docstring Coverage
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. (1 skipped: 1 too large.)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-12 08:57 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
5d8cdb8d-e290-456b-8226-d548cbc6d0bb📥 Commits
Reviewing files that changed from the base of the PR and between
dad900c61dand5b30248f5e.📒 Files selected for processing (2)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@theantipopau on GitHub · 2026-10-12 10:22 UTC · original · approved these changes
Verified the change is confined to the sample path (
EmitSample/OverflowSampleCoordinatesin spirvEmitterImage.cpp):layout.offsetthrough the standardPackedOffsetinto theOpImageGatherOffsetimage operand at spirvEmitterImage.cpp:838, which is the one Vulkan place a non-constant offset is legal — no behavior change.ConstOffsetoperand with a zero-extended three-bit offset per component, unchanged.OverflowSampleCoordinatesdecodes the signed six-bit offset from RDNA2 low bits of each byte ([5:0]/[13:8]/[21:16]) withOpBitFieldSExtract— same bit layout as the constant path'sPackedOffsetdecode at line 340 — then biases the coordinate by offset/extent of the mip-level dims. The queried level is: explicit LOD for_L_O, LOD 0 for_LZ_O/compute stages, the OTW computation from gradients for_D_O(0.5*log2(|ddx|^2+|ddy|^2)), and a pixel-shaderOpImageQueryLod(plus bias) for implicit. It clamps intoOpImageQueryLevelswithOpUMin32(level, levels-1)andNMax(…, 0), and rdna2 foldsImageQueryLodon a multi-view-restricted range, which matches how the sampler wraps huge LODs.2DArray/cube unaffected dims behave exactly as the preexisting coordinate streams.test.image_width/height16×16 with every written pixel pattern matches the expected+3/+1,-9/+8,+1/+2cases map to (7,10)/(3,11)/(9,4); the positive and negative assertions aroundOpImageQuerySizeLod/OpBitFieldSExtractkeep this honest since this exact path also validates with a shader only the real Vulkan driver supports (SPIR-V validates, checked in CI on all three OSes including the Linux NVIDIA test).One small note, not blocking: when a cube maps arrive at this path
candidate.cubegets clamped instead of dropping the offset silently, so a fallback offset of 0/0/0 for cube is fine as the operand never existed.This is the first convergence of
IMAGE_SAMPLE*_OtospirvEmitterProgram.cpp:587inBuildComputeRuntime. CI (5 checks green) means NHL 27's0x8ff7afec7c5ab786compute dispatch should now emit rather than fail.@theantipopau on GitHub · 2026-10-12 10:22 UTC · original
Correction to my review above (two mistakes to avoid misleading you when merging):
OffsetSampleCoordinates(I wrote "Overflow…").!candidate.cube, so cube samples with a runtime offset simply keep their coordinates untouched — identical to the old code path before the crash, not "clamped". That matches the "Cube maps take no texel offsets" comment you wrote.Everything else stands: gathers/atomics untouched, constant offsets unchanged, level selection (
_L_Oexplicit LOD /_LZ_O+compute LOD 0 /_D_Ofrom gradients / implicit pixel-shader query+bias), NMax-to-zero for non-finite LODs, OpUMin32 againstOpImageQueryLevels - 1, and the 16×16 execution test covering Signed/Unsigned + LOD past the last level.@overlordxrz-source on GitHub · 2026-10-12 19:16 UTC · original
Game confirmation from fozter on #1101: with this PR's CI build, NHL 27 (#1101) no longer stops at
SPIR-V emission failed: hash=0x8ff7afec7c5ab786 ... has a nonconstant sample texel offset(still present on maindf5b9b9). It now reaches Start Game and stops later at an unrelated shader CFG issue (unsupported dynamic S_SETPC_B64, CS 0xad738baf31b6e28b), which I'll handle separately.@overlordxrz-source on GitHub · 2026-10-16 18:52 UTC · original
Closing:
460a196fcnow emits dynamic sample texel offsets natively with maintenance8, which covers the NHL 27 shader this targeted.Pull request closed