Skip to content

Unexpected compilation error using EvaluateAttributeAtSample #6225

@damyanp

Description

@damyanp

Description
User sees a compilation error when using EvaluateAttributeAtSample in certain cases where they would not expect it to fail.

error: attribute evaluation can only be done on values taken directly from inputs.
O.x[i] = EvaluateAttributeAtSample(O.x[i],S);

They're able to reproduce this in all versions of DXC here:
https://godbolt.org/z/7PGn6Ts6z

Set ARRAY_INTERPOLATORS to 1 to demonstrate the problem.
Set INLINE_EVAL_AT_SAMPLE to 1 to work around the problem.

The bug happens when an array interpolant is passed to a function which then calls EvaluateAttributeAtSample on it.
Using a non-array interpolant works.
Inlining the code into the “Main” entry point also works.

Steps to Reproduce

This is code that's in the above godbolt link:

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

// Enabling this causes a compiler error
#define ARRAY_INTERPOLANTS (1) 
// Enabling this works around the compiler error when ARRAY_INTERPOLANTS is on
#define INLINE_EVAL_AT_SAMPLE (0)

struct PSInput
{
#if ARRAY_INTERPOLANTS
    float3 x[4] : TEST;
#else
    float3 x0 : TEST0;
    float3 x1 : TEST1;
    float3 x2 : TEST2;
    float3 x3 : TEST3;
#endif
};

PSInput EvalInterpAtSample(PSInput I, int S)
{
    PSInput O = I;
#if ARRAY_INTERPOLANTS
    [unroll]
    for( int i =0; i<4; ++i)
    {
        O.x[i] = EvaluateAttributeAtSample(O.x[i],S);
    }
#else
    O.x0 = EvaluateAttributeAtSample(O.x0,S);
    O.x1 = EvaluateAttributeAtSample(O.x1,S);
    O.x2 = EvaluateAttributeAtSample(O.x2,S);
    O.x3 = EvaluateAttributeAtSample(O.x3,S);
#endif
    return O;
}

void PSMain(
    float4 Position : SV_Position,
    PSInput input,
    out float3 OutColor : SV_Target0
)
{
    OutColor = 0;
    [unroll]
    for ( uint i=0; i <4; ++i)
    {
#if INLINE_EVAL_AT_SAMPLE
        PSInput I = input;
        #if ARRAY_INTERPOLANTS
            I.x[0] = EvaluateAttributeAtSample(input.x[0],i);
            I.x[1] = EvaluateAttributeAtSample(input.x[1],i);
            I.x[2] = EvaluateAttributeAtSample(input.x[2],i);
            I.x[3] = EvaluateAttributeAtSample(input.x[3],i);
        #else
            I.x0 = EvaluateAttributeAtSample(I.x0,i);
            I.x1 = EvaluateAttributeAtSample(I.x1,i);
            I.x2 = EvaluateAttributeAtSample(I.x2,i);
            I.x3 = EvaluateAttributeAtSample(I.x3,i);
        #endif
#else
        PSInput I = EvalInterpAtSample(input,i);
#endif    
        #if ARRAY_INTERPOLANTS
            OutColor += I.x[0] + I.x[1] + I.x[2] + I.x[3];
        #else
            OutColor += I.x0 + I.x1 + I.x2 + I.x3;
        #endif
    }
}

Actual Behavior

Compilation fails with the following error, although the user believes the code is valid:

error: attribute evaluation can only be done on values taken directly from inputs.
        O.x[i] = EvaluateAttributeAtSample(O.x[i],S);

Environment

  • DXC version: all versions currently supported by godbolt
  • Host Operating System windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Triaged

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions