microsoft / microsoft/DirectXShaderCompiler

[SPIR-V] GetAttributeAtVertex does not work with arrays

Open
#6,259 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug spirv
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Description
The SPIR-V code generated by DXC when an array is marked with nointerpolation seems broken. It looks like internally we are inconsistent in how we expand the array into a two dimensional array.

Steps to Reproduce

I tried a number of examples, and they all fail. Here is one example: https://godbolt.org/z/dahbcj3EE.

// RUN: %dxc -T ps_6_0 -E main -fcgl  %s -spirv | FileCheck %s
               
struct PSInput {
  nointerpolation      float4 fp_h[2]: FPH;
};             

struct PSInput2 {
  float4 fp_h[2]: FPH;
};

float4 main(nointerpolation PSInput2 input) : SV_Target {
  return input.fp_h[1] + GetAttributeAtVertex(input.fp_h[0], 2);
}

Actual Behavior

The spir-v of interest is:

   %PSInput2 = OpTypeStruct %_arr__arr_v4float_uint_2_uint_3
         %35 = OpAccessChain %_ptr_Function_v4float %input %int_0 %uint_0 %int_1
         %36 = OpLoad %v4float %35
         %37 = OpAccessChain %_ptr_Function_v4float %input %int_0 %int_0 %uint_2
         %38 = OpLoad %v4float %37
         %39 = OpFAdd %v4float %36 %38

Note that we have an array of size 3 containing the array of size 2. This means that the order of the access chains should be

%v = OpAccessChain %type %input [[index into the PSInput struct]] [[index for the vertex]] [[index into fg_h array]]

The first access chain looks correct. The provoking vertex is 0, and we want index 1 in the array. However, the second access chain has the indices backwards. I would expect vertex 2 at index 0. This is probably due to the array access being on the input to GetAttributeAtVertex instead of the output. However, if I move [0] to be applied to the return value of GetAttributeAtVertex, there is a compilation error.

There seems to be a design issue here.

Environment

  • DXC version: latest (any version since GetAttributeAtVertex was enabled for spir-v.)
  • Host Operating System all

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided dxc command and FileCheck reproduction, using the Godbolt example as a reference. Trace GetAttributeAtVertex handling for array inputs and compare the emitted OpAccessChain indices with the expected vertex and array dimensions. Done means array inputs compile successfully and emit the correct access order.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.