Repository navigation
Description
Description
DXC's SPIR-V output gives different texel selection from FXC and DXIL for four-offset GatherRed, GatherGreen, GatherBlue, and GatherAlpha calls when all four offset arguments are compile-time constants. If at least one argument is dynamic, DXC uses a different lowering that remains equivalent to DXIL.
Where DXIL would output [A,B,C,D], SPIR-V would output [D,D,D,D].
Steps to Reproduce
Compiler Explorer example with SPIR-V, DXIL, and Microsoft FXC outputs: https://godbolt.org/z/ePr9nW7eG
The example and the procedure below compare compiler output. They do not run the shader.
- Save this source code as
repro.hlsl:
Texture2D<float4> tex;
SamplerState samp;
void main(float2 uv : TEXCOORD0,
out float4 NoOffsets : SV_Target0,
out float4 ZeroOffsets : SV_Target1) {
NoOffsets = tex.GatherRed(samp, uv);
ZeroOffsets = tex.GatherRed(samp, uv, int2(0,0), int2(0,0), int2(0,0), int2(0,0));
}- Make the SPIR-V module:
dxc -T ps_6_0 -E main -spirv -Od repro.hlsl -Fo repro.spv- Make its assembly file:
spirv-dis repro.spv -o repro.spvasm- Make the DXIL module and its assembly file:
dxc -T ps_6_0 -E main -Od repro.hlsl -Fo repro.dxil -Fc repro.dxil.txt- Compare the gather instructions for
NoOffsetsandZeroOffsetsinrepro.spvasmandrepro.dxil.txt. - Replace
GatherRedwithGatherGreen,GatherBlue, orGatherAlphato test a different channel. - Do steps 2 through 5 again for that channel.
Actual Behavior
NoOffsets has the same value in DXIL, FXC, and SPIR-V. In this example, that value is [A,B,C,D] in lanes x, y, z, and w. Each letter is the red channel value of one texel in the selected 2×2 rectangle.
In DXIL and FXC, ZeroOffsets has the same value as NoOffsets.
In SPIR-V, DXC uses OpImageGather with the ConstOffsets image operand for ZeroOffsets. This operand is a reference to an array of four constant texel offsets. According to the Vulkan spec, each ConstOffsets entry is added to the same texel position (0,0) specified by uv. Position (0,0) corresponds to lane w (D) of NoOffsets. Thus, four (0,0) entries select D for all four result lanes.
| Target | NoOffsets |
ZeroOffsets |
|---|---|---|
| DXIL and FXC | [A,B,C,D] |
[A,B,C,D] |
| SPIR-V | [A,B,C,D] |
[D,D,D,D] |
The issue is that DXC copies the HLSL offsets into ConstOffsets without adding the normal lane offsets (0,1), (1,1), (1,0), and (0,0).
Environment
- DXC version on Compiler Explorer:
libdxcompiler.so: 1.9(1-01b62ad4)(1.9.0.1). - Microsoft FXC version on Compiler Explorer:
10.0.26100.8249; target and flags:-T ps_5_0 -E main -Od. - Host Operating System for the Vulkan test: Linux x64, WSL2 kernel
6.6.87.2-microsoft-standard-WSL2.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTriaged
Activity
[-][SPIR-V] Different texel selection for constant-offset gathers in SPIR-V and DirectX[/-][+][SPIR-V] Incorrect GatherRed/GatherGreen/GatherBlue/GatherAlpha texel selection with four compile-time constant offsets[/+]pow2clk commentedon Nov 30, 2026
Sorry disregard my previous comment. While the godbolt comparison was confusing, I realize that this is pointing out the issue specific to SPIR-V's operation.
[SPIR-V] Fix texel selection in Gather with four constant offsets (#9158