Sign in to follow this  
Migi0027

Compiler error when writing to a buffer in a conditional expression

Recommended Posts

Code demonstrating the issue, not the actual monster: ( I believe this is the culprit, if not I apologize, although the example by it self produced the error )

// Example demonstrating the issue
[unroll] for (uint i = 0; i < 5; i++)
{
    if (i < 2)
    {
        buffer[5 * 3 + i] = 0;
    }
}

 

Error:

Resources being indexed cannot come from conditional expressions, they must come from literal expressions

.

What's the reasoning behind this error? I assume it's some underlying way the API is set up, but I would have assumed it would be an acceptable thing to do.

Edited by Migi0027 (????)

Share this post


Link to post
Share on other sites
Hmmm, I was wrong then. Give me a moment...

This...


RWBuffer<float3> buffer : register(u1);

void PS()
{
    [unroll] for (uint i = 0; i < 5; i++)
    {
       if (i < 2)
       {
           buffer[5 * 3 + i] = 0;
       }
    }	
}
... compiles fine for me.

So... provide a snippet which actually triggers that error. Edited by unbird

Share this post


Link to post
Share on other sites

Ahh, the issue was my fault. I did the following:

RWBuffer<float3> bffRay = (screen.Roughness < 0.2f ? g_bffRaysHigh : g_bffRaysLow); 

.

And then used bffRay as the "buffer". I naively assumed it was valid.

 

Thank you for the help thought.

Edited by Migi0027 (????)

Share this post


Link to post
Share on other sites
Do they need to be in separate buffers ? I mean, how about this:
 
 
RWBuffer<float3> g_bffRays;
void PS(float rough: ROUGH)
{
    [unroll] for (uint i = 0; i < 5; i++)
    {
        uint index = 5*3+i;
        index *= 2;
        if (rough < 0.2) // just some condition
        {
            index++;
        }
        g_bffRays[index] = 0;
    }	
}
So, low and high rays alternate. Not sure if this is useful, but it compiles wink.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this