slang icon indicating copy to clipboard operation
slang copied to clipboard

Metal: Slang does not legalize `[[color(n)]]`/`[[attribute(n)]]` attributes correctly

Open ArielG-NV opened this issue 8 months ago • 4 comments

breaks compile of:

  • tests/compute/compile-time-loop.slang
  • tests/compute/constexpr.slang
  • tests/compute/discard-stmt.slang
  • tests/compute/texture-sampling.slang

problem: the following metal code is allowed:

struct FragmentStageOutput_0
{
    float4 fragment_0 [[color(0)]];
};

[[fragment]] FragmentStageOutput_0 fragmentMain(float device* outputBuffer_0 [[buffer(0)]])
{
    thread FragmentStageOutput_0 output_0;
    (&output_0)->fragment_0 = float4(1.0, 1.0, 1.0, 1.0);
    *(outputBuffer_0+int(0)) = 1.0;
    return output_0;
}

the following metal code is not allowed (Slang generates the following code if struct wrapping a SV_Target):

struct float4Wrapper
{
    float4 v;
}
struct FragmentStageOutput_0
{
    float4Wrapper fragment_0 [[color(0)]];
};

[[fragment]] FragmentStageOutput_0 fragmentMain(float device* outputBuffer_0 [[buffer(0)]])
{
    thread FragmentStageOutput_0 output_0;
    (&output_0)->fragment_0.v = float4(1.0, 1.0, 1.0, 1.0);
    *(outputBuffer_0+int(0)) = 1.0;
    return output_0;
}

Specifically, metal allows [[color()]] and [[attribute()]] to only be annotated on PRIMITIVE and vector<PRIMITIVE,N>.

ArielG-NV avatar Jun 26 '24 15:06 ArielG-NV