microsoft / microsoft/DirectXShaderCompiler

Array bound with static const variable

Open
#2,530 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello,

In some cases(namely type conversions) DXC compiler do not allow to use static const variables as an array bounds.

First case:

static const float ARRAY_SIZE = 1;

float4 main() : SV_Target
{
    float array[uint(ARRAY_SIZE)] = { 1.0f };
    return (float4)0;
}

Second case:

static const float ARRAY_SIZE = 1;
static const uint ARRAY_SIZE_UINT = (uint)ARRAY_SIZE;

float4 main() : SV_Target
{
    float array[ARRAY_SIZE_UINT] = { 1.0f };
    return (float4)0;
}

This same code compiles successfully with FXC.
While DXC returns "error: variable length arrays are not supported in HLSL".

Thanks,
Oleksandr

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 reproducing both HLSL examples with DXC and comparing their results with FXC, focusing on the diagnostic that reports variable length arrays. Done means DXC accepts static const float and converted uint values as array bounds, with regression coverage for both examples.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.