You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[SPIR-V] Fix texel selection in Gather with four constant offsets - #9158
A four-offset Gather with constant offsets returns the wrong texels in SPIR-V. With four int2(0, 0) offsets, GatherRed returns the i0j0 texel in every element of the result.
DXC copies the four HLSL offsets into ConstOffsets unchanged, but the two are relative to different texels. In HLSL, offset k moves the texel that element k reads. In SPIR-V, every ConstOffsets entry moves texel i0j0, the one element w reads (Texel Gathering). So with zero offsets, every element reads i0j0.
This change adds each element's position in the 2x2 footprint, (0,1), (1,1), (1,0) and (0,0) for elements x, y, z and w, to its offset before building ConstOffsets. Non-constant offsets already use four gathers, so they don't need to be handled.
Tests:
texture.gather-const-offsets.hlsl checks zero and negative offsets and GatherCmpRed.
The texture.gather-* and texture.array.gather-* tests expect the adjusted constants.
The reason will be displayed to describe this comment to others. Learn more.
While this fixes a genuine problem, that problem is not #9031 because I don't think that is a real problem.
Edit: nevermind. I see that though it started saying the problem was that all the values were the same and not A,B,C,D like DXIL, it went on to explain this won't work with SPIR-V.
I'm going to have to insist on not calling elements of vectors lanes in spite of what agents might say. Please reword the description and title as well.
Diego Novillo (dnovillo)
changed the title
[SPIR-V] Add lane positions to four constant Gather offsets
[SPIR-V] Fix texel selection in Gather with four constant offsets
Dec 1, 2026
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Offset rebasing can exceed Vulkan’s supported gather-offset range for previously valid inputs; a fallback to the original offsets and an upper-bound regression test are needed.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Rebased gather offsets exceed Vulkan's guaranteed range
tools/clang/lib/SPIRV/SpirvEmitter.cpp:4930
Four int2(7, 7) offsets now produce (7, 8), (8, 8), (8, 7), and (7, 7), exceeding the supported range on Vulkan devices with maxTexelGatherOffset == 7. The original offsets fit that limit, so this adjustment makes previously supported inputs exceed it. Fall back to four gathers with the original offsets when rebasing exceeds the guaranteed range, and add an upper-bound regression test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A four-offset
Gatherwith constant offsets returns the wrong texels in SPIR-V. With fourint2(0, 0)offsets,GatherRedreturns thei0j0texel in every element of the result.DXC copies the four HLSL offsets into
ConstOffsetsunchanged, but the two are relative to different texels. In HLSL, offsetkmoves the texel that elementkreads. In SPIR-V, everyConstOffsetsentry moves texeli0j0, the one elementwreads (Texel Gathering). So with zero offsets, every element readsi0j0.This change adds each element's position in the 2x2 footprint,
(0,1),(1,1),(1,0)and(0,0)for elementsx,y,zandw, to its offset before buildingConstOffsets. Non-constant offsets already use four gathers, so they don't need to be handled.Tests:
texture.gather-const-offsets.hlslchecks zero and negative offsets andGatherCmpRed.texture.gather-*andtexture.array.gather-*tests expect the adjusted constants.Fixes #9031