• Advertisement
Sign in to follow this  

Compiler error when writing to a buffer in a conditional expression

This topic is 932 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
buffer declaration, please. I bet it's some Buffer buffer[10]. This translates to several SRV/UAV slots and indeed cannot be indexed the way you wish. You need another approach.

Share this post


Link to post
Share on other sites

I probably did something incredibly stupid, like usual! tongue.png  

RWBuffer<float3> g_bffSampleLow : register(u1);
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

"Do they need to be in separate buffers?" Definitely not, it would be extremely easy to pack it together, but I'm trying out a new technique so I'd like to take things one step at a time. smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement