Are HLSL loops broken?

Viewed 56

I've been messing around with HLSL and Direct3D12 and encountered something strange. Here's a minimal reproducible example:

float4 main() : SV_TARGET
{
    uint indices[3];
    indices[0] = 0;
    uint l = 0;

    [loop] while (true) {
        if (indices[l] == 1)
            return float4(1.0f, 0.0f, 0.0f, 1.0f);
        indices[l + 1] = 1;
        if (++l == 2)
            break;
    }
    return float4(0.0f, 1.0f, 0.0f, 1.0f);
}

The code is completely pointless, but at least in my eyes, there shouldn't be a problem with it, and it should return a red color. However, compiling and running this (with HLSL version 5_0, with and without optimizations) does strangely enough neither return red nor green; it doesn't seem to return anything at all, as even though I have all blending disabled, nothing is being drawn.

Changing seemingly meaningless things, like removing the [loop] tag or changing the size of indices to 2, gets rid of the strange behavior.

Does anyone know what's going on here? Are HLSL loops simply broken?

0 Answers
Related