Skip to content

Conversation

gtong-nv
Copy link
Contributor

@gtong-nv gtong-nv commented Apr 15, 2025

This change aims to report error when the nested func requires constexpr, and the caller calls wrapper func with non-cost params.
For example, the following should failed to compile because RWTexture2D::Load requires offset to be constexpr.

Texture2D<float3> input;
RWTexture2D<float3> output;

float3 LoadSourceColor(int2 offset) {
    int3 pixelPos = int3(0,0,0);
    return input.Load(pixelPos, offset);
}

[shader("compute")]
void Test() {
    float3 result = 0;

    [ForceUnroll]
    for (int i = 0; i < 3; i++) {
        //result += input.Load( int3(0,0,0), int2( i, i ));
        result += LoadSourceColor(int2( i, i ));
    }

    output[0] = result;
}

Fixes: #6370

@gtong-nv gtong-nv requested a review from a team as a code owner April 15, 2025 21:32
@gtong-nv gtong-nv marked this pull request as draft April 15, 2025 21:43
@gtong-nv
Copy link
Contributor Author

/format

@slangbot
Copy link
Contributor

🌈 Formatted, please merge the changes from this PR

@gtong-nv gtong-nv added the pr: non-breaking PRs without breaking changes label Apr 16, 2025
@gtong-nv gtong-nv changed the title Draft: check constexpr of the nested calls check constexpr of the nested calls Apr 16, 2025
@gtong-nv gtong-nv marked this pull request as ready for review April 16, 2025 04:09
break;

callee = returnVal;
changedInThisInst = checkInstConstExprRecursively(context, ii);
Copy link
Contributor

@juliusikkala juliusikkala Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be changedInThisInst |= checkInstConstExprRecursively(context, ii);, otherwise changedInThisInst may reset back to false if a later instruction didn't change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recursion going through this line causes a stack overflow if a recursive function is given in input, like in tests/diagnostics/recursion.slang.


if (maybeMarkConstExprBackwardPass(context, arg))
{
changedInThisInst = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering for all of those changedInThisInst = true; can we just early return? It doesn't look like we need to go through everything.

@gtong-nv gtong-nv marked this pull request as draft June 3, 2025 15:28
@gtong-nv gtong-nv closed this by deleting the head repository Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constexpr propagation checks do not work as expected.

4 participants