microsoft / microsoft/DirectXShaderCompiler

C++-style initialization of vectors (`int2 x{0,1}`) does not work, but compiles.

Open
#7,111 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description
C++-style initialization of vectors, e.g. int2 x{0,1}; appears to generate OpUndef in the SPIR-V output.
One effect that i have observed from this is that any comparisons with data from that vector are eval'ed to false.

Steps to Reproduce
DXC 1.8, with the following shader (godbolt link):

// The entry point and target profile are needed to compile this example:
// -T ps_6_6 -E PSMain

struct PSInput
{
    float4 position : SV_Position;
    float4 color    : COLOR0;
    float x : COLOR1;
    float y : COLOR2;
};


float4 PSMain(PSInput input) : SV_Target0
{
  int2 a{2, 1};
  return a.x == 2 ? float4(1.0,1.0,1.0,1.0) : float4(0.0,0.0,0.0,0.0);
}

Actual Behavior
OpUndef in generated spir-v and erratic behavior described above

I'd expect one of two outcomes:

  • this syntax to mean initialization and work same way as in c++
  • compile error.

Environment

  • DXC version 1.8
  • Host Operating System any

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 with the DXC 1.8 reproducer at the linked Godbolt entry point, using PSMain and inspecting the generated SPIR-V for OpUndef. Trace how brace initialization of int2 is parsed and lowered, then add coverage showing whether the syntax is supported or rejected, with the result matching one of the issue's stated expectations.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.