Skip to content

Using Conditional<T, bool> with [SpecializationConstant] causes compile error #7834

@HyPNOTIQ

Description

@HyPNOTIQ

Hi, I'm experimenting with using Conditional<T, bool> together with [SpecializationConstant], but I'm not sure if I'm using it correctly. I followed the docs as best as I could, but I'm running into a compilation error and not sure if this is supported or if I'm doing something wrong.

Here’s a code example:

struct VSInput
{
    [[vk::location(0)]] float3 position;
    [[vk::location(1)]] float3 normal;
}

interface IVertex
{
    property float3 position { get; }
    property Optional<float3> normal { get; }
}

struct Vertex<bool hasNormal> : IVertex
{
    private float3 m_position;
    private Conditional<float3, hasNormal> m_normal;

    __init(float3 position, float3 normal)
    {
        m_position = position;
        m_normal = normal;
    }

    property float3 position
    {
        get { return m_position; }
    }
    property Optional<float3> normal
    {
        get { return m_normal; }
    }
}

[SpecializationConstant]
const bool hasNormal = true;

[shader("vertex")]
Vertex<hasNormal> vertMain<bool hasNormal>(const VSInput input)
{
    return Vertex<hasNormal>(input.position, input.normal);
}

When I compile this, I get the following error:

error 99999: Slang compilation aborted due to an exception of class Slang::InternalError: unexpected: needed a known integer value

I'm not sure if Conditional<T, bool> is meant to be used this way, especially with [SpecializationConstant] involved. Just wanted to check if this is a known limitation or if there’s something I should change in how I’m using it.

Thanks!

Environment:

  • Slang Version v2025.12.1
  • OS Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions