Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected compilation error using EvaluateAttributeAtSample #6225

Open
damyanp opened this issue Jan 30, 2024 · 0 comments
Open

Unexpected compilation error using EvaluateAttributeAtSample #6225

damyanp opened this issue Jan 30, 2024 · 0 comments
Labels
bug Bug, regression, crash tech-debt
Milestone

Comments

@damyanp
Copy link
Member

damyanp commented Jan 30, 2024

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
@damyanp damyanp added bug Bug, regression, crash needs-triage Awaiting triage labels Jan 30, 2024
@pow2clk pow2clk moved this to For MSFT in HLSL Triage Feb 14, 2024
@pow2clk pow2clk added tech-debt and removed needs-triage Awaiting triage labels Mar 6, 2024
@pow2clk pow2clk moved this from For MSFT to Done in HLSL Triage Mar 6, 2024
@damyanp damyanp added this to the Dormant milestone Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug, regression, crash tech-debt
Projects
Status: Triaged
Development

No branches or pull requests

3 participants
@damyanp @pow2clk and others