Skip to content

[SPIR-V] Incorrect GatherRed/GatherGreen/GatherBlue/GatherAlpha texel selection with four compile-time constant offsets #9031

Done

Description

@Icohedron

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.

  1. 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));
}
  1. Make the SPIR-V module:
dxc -T ps_6_0 -E main -spirv -Od repro.hlsl -Fo repro.spv
  1. Make its assembly file:
spirv-dis repro.spv -o repro.spvasm
  1. 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
  1. Compare the gather instructions for NoOffsets and ZeroOffsets in repro.spvasm and repro.dxil.txt.
  2. Replace GatherRed with GatherGreen, GatherBlue, or GatherAlpha to test a different channel.
  3. 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.

Activity

  1. added
    bug
    spirv
    needs-triage
    on Oct 15, 2026
  2. changed the title [-][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[/+] on Oct 15, 2026
  3. pow2clk commented on Nov 30, 2026

    @pow2clk
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triagespirv

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions