shader: take compute derivatives from four consecutive lanes #1686
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!1686
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1686/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?
@Nawid3333 on GitHub · 2026-10-19 03:00 UTC · original
Nawid3333:shader/compute-derivatives-linear→main· +72 −15 · 3 files · 6 commits · closed without mergingA compute shader that uses
image_get_lod(the only instruction that setscompute_derivatives) declaredDerivativeGroupQuadsKHR. That mode builds each derivative quad fromLocalInvocationId(x, y), (x+1, y), (x, y+1), (x+1, y+1). The hardware builds it from four consecutive lanes (4n top-left, 4n+1 top-right, 4n+2 bottom-left, 4n+3 bottom-right), which isDerivativeGroupLinearKHR. Mesa shows the same: RADV and radeonsi implementDerivativeGroupQuadsby remappingLocalInvocationIdinto consecutive invocations and then compiling the shader as linear (nir_lower_system_values.c,shuffle_local_ids_for_quad_derivatives).On a 64-wide host the guest thread IDs come from
LocalInvocationId, so a workgroup whose X size is not 2 got different derivative quads than on the console. In an 8x8 group, lanes 0..3 are x = 0..3 of row 0 on the console; with quads they were (0,0), (1,0), (0,1), (1,1). Quads also needs both X and Y to be multiples of two, so a 64x1 group was invalid; linear needs the product to be a multiple of four, so every size that was valid before still is (a group such as 1x1 stays invalid, as before). The 32-wide host path already forced a 2 x N local size so that quads matched the lane order.The device was also created without
VK_KHR_compute_shader_derivativesand without its feature, which the Vulkan registry requires for this extension and capability.Change:
ComputeDerivativeGroupLinearKHRandDerivativeGroupLinearKHR; drop the 2 x N reshape on 32-wide hosts (no longer needed).VK_KHR_compute_shader_derivativeswhen the device has it and chain its feature struct whencomputeDerivativeGroupLinearis supported. This AMD 26.8.1 driver and the vulkan.gpuinfo.org reports I checked (NVIDIA 582 and 610, Intel Arc B580 on Windows) support both modes. The log printsVulkan compute derivatives support: true/false.computeDerivativeGroupLinearinstead of quads.Not covered: hosts without the KHR extension and linear support (MoltenVK, older NVIDIA drivers that only have
VK_NV_compute_shader_derivatives) still get a shader that declares it, as on main. Implicit-LOD samples in compute shaders still use an explicit LOD, as on main.Tests
Windows, AMD Radeon RX 9070 XT (fork CI builds Windows, Linux and macOS and runs the CPU tests, all green on
7ffd3db2; CI runs no GPU tests):ImageGetLodComputeLaneQuadscases for 8x8, 64x1 and 16x16 groups inshader_recompiler_compute_tests, in--wave64-onlyand the full run: u = 0.25 * bit 1 of x on a 16x16 texture with mips. In each run of four lanes u is 0, 0, 0.25, 0.25, so only du/dy is non-zero (4 texels) and every LOD formula the spec allows gives exactly 2. On main the 8x8 and 16x16 cases return 0.0 for the clamped and -3.4e38 for the unclamped LOD in every lane (u is constant in each (x, y) quad, so the derivative is zero), and--wave64-onlystops at the first. The 64x1 case does not get that far on main: its SPIR-V failsspirv-val(VUID-StandaloneSpirv-DerivativeGroupQuadsKHR-10151), so with shader validation enabled the emulator stops on such a shader (SPIR-V validation failedinpipelineCache.cpp). With this change all three pass, also under the validation layer (no messages).image_get_lod,ImageSampleAndGather, passes with quads and with linear on 64-wide and 32-wide hosts. No other case changes: both emitter changes depend oncompute_derivatives.shader_cfgpasses on main and with this change.c67352d5; main had meanwhile added the MinLod requirement next to the derivatives one in the harness and VK_EXT_extended_dynamic_state next to this extension): on the RX 9070 XT, natively and with the harness forced to 32-wide subgroups (a local switch), and on the Ryzen 7600X iGPU, only the three new cases change.vulkanWindow.cpp) builds but was not run here (no game); the harness creates its device separately.No game report names this yet. If you would rather handle this differently, feel free to close it and say what you would prefer.
AI use
I used Claude Code (AI agent) to find the cause, write the change and the test, and run the checks; I reviewed the diff and the results.
906d2556into shader/compute-derivatives-linear 2aefa69935@coderabbitai[bot] on GitHub · 2026-10-19 03:07 UTC · original · edited 2026-11-03 19:52 UTC
No actionable comments were generated in the recent review.
Walkthrough
Vulkan setup queries and conditionally enables linear compute derivatives. The SPIR-V emitter declares the linear derivative capability and execution mode for compute shaders that use derivatives. Lane-count-2 shaders use a flattened workgroup size with
local_yandlocal_zset to 1. New image LOD compute tests cover three workgroup shapes and check results.Suggested reviewers:
claxten10Change: Bug fix
Merge Risk:
Minimal · previous review
7ffd3The linear-derivative changes are ready to merge after normal checks. The test tolerance has been corrected; devices without linear-derivative support remain outside this change’s scope.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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
CodeRabbit Verify
97b43925-5776-48b0-9026-9878838b7e00Reviewing files that changed from the base of the PR and between
cfdeb44d97and7ffd3db29a.tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-19 03:35 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
21130d21-5339-4a27-9fa6-62c3305d9d39📥 Commits
Reviewing files that changed from the base of the PR and between
c1fab1544aand5efd999691.📒 Files selected for processing: 1
tests/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.
@Nawid3333 on GitHub · 2026-10-19 03:48 UTC · original
This was already the case on main, which declared the quads capability without enabling any compute-derivatives extension. The description lists it under "Not covered": hosts without the KHR extension and linear support (MoltenVK, NVIDIA drivers that only have the NV extension) still get a shader that declares it. A fallback for them (for example an LOD computed from quad swaps) would be a separate change; MoltenVK does not get past device selection yet (#1068).
@coderabbitai[bot] on GitHub · 2026-10-28 20:19 UTC · original · edited 2026-10-28 21:23 UTC
On
tests/ShaderRecompilerComputeTests.cppline 39756 (outdated):Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2744
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 39360
Web query:
Vulkan 1.3 specification mipmapPrecisionBits textureQueryLod OpImageQueryLod precision exact integer LODResult:
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 23878
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8434
Web query:
Vulkan specification texture sampling mipmapPrecisionBits exact wording LOD calculation mipmap level contribution OpImageQueryLodResult:
Web query:
Vulkan texture specification "LOD must be computed with mipmapPrecisionBits of accuracy" LOD Operation rounding exact integer lambdaResult:
Use a tolerance compatible with
mipmapPrecisionBits.IMAGE_GET_LODemitsOpImageQueryLod, which performs the implicit LOD calculation. Vulkan permits only fourmipmapPrecisionBits, while this test accepts an error of at most1.0f / 64.0f. A conforming implementation may therefore return a valid LOD near2.0fthat this test rejects.This is a minor portability issue, not a major regression. The fixed-tolerance pattern already exists, but the harness does not query
mipmapPrecisionBits.Use a tolerance compatible with the minimum Vulkan precision, or derive it from the device limit.
✅ Addressed in commit
7ffd3db@coderabbitai[bot] on GitHub · 2026-10-28 20:19 UTC · original · reviewed
Actionable comments posted: 1
ded346b9-a035-43f3-89aa-ceb6205451c4Reviewing files that changed from the base of the PR and between
2aefa69935andcfdeb44d97.src/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
@Nawid3333 on GitHub · 2026-10-28 21:23 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 39756 (outdated):Agreed.
7ffd3db2allows 1/16 (Vulkan's minimum of 4mipmapPrecisionBits) instead of 1/64. The three cases still pass on the RX 9070 XT (natively and with 32-wide subgroups) and the Ryzen 7600X iGPU, and main's wrong LOD (0.0 or -3.4e38) stays far outside that.@coderabbitai[bot] on GitHub · 2026-10-28 21:23 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 39756 (outdated):@Nawid3333 Thanks. The
1/16tolerance addresses the precision concern. Your reported GPU results also confirm that the three cases still pass, while the incorrect LOD values frommainremain outside the tolerance.✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
Pull request closed