When I try to compile my compute shader, it fails to compile and yields the following error message:
Shader error in ‘AppendTest’: infinite loop detected - loop never exits at kernel CSMain at AppendTest.compute(355) (on d3d11)
Nothing I’m doing here should cause it to detect an infinite loop, as the condition is met after 5 successful iterations. The actual delcaration is simply for (uint i = 0; i < 16; i += 3)
but if you want to see the whole loop, here it is:
(I’m still pretty new to compute shaders, so apologies if my code is bad. Just trying to get this working, and then I’ll improve/optimize it. Just putting this so I don’t get unsolicited comments on the quality of my approach!)
for (uint i = 0; i < 16; i += 3)
{
Triangle toAppend;
uint edge1ID[2] = EdgeMap[edgesToConnect[i]];
uint edge2ID[2] = EdgeMap[edgesToConnect[i + 1]];
uint edge3ID[2] = EdgeMap[edgesToConnect[i + 2]];
toAppend.v1 = vertexInterp(blfPos, edge1ID[0] + blf, edge1ID[1] + blf);
toAppend.v2 = vertexInterp(blfPos, edge2ID[0] + blf, edge2ID[1] + blf);
toAppend.v3 = vertexInterp(blfPos, edge3ID[0] + blf, edge3ID[1] + blf);
//tris.Append(toAppend); Commented out because it yields a different confusing error, but that's for another thread.
}
(apologies for flagging this as CSharp code; it won’t let me select HLSL)
Strangely, when I add an if statement which can break the loop, it doesn’t encounter the error anymore. Very confused and haven’t been able to find anything online. Would appreciate some help. Thanks!
for (uint i = 0; i < 16; i += 3)
{
Triangle toAppend;
// And this if statement makes it compile without any errors.
if (edgesToConnect[i] == -1)
break;
uint edge1ID[2] = EdgeMap[edgesToConnect[i]];
uint edge2ID[2] = EdgeMap[edgesToConnect[i + 1]];
uint edge3ID[2] = EdgeMap[edgesToConnect[i + 2]];
toAppend.v1 = vertexInterp(blfPos, edge1ID[0] + blf, edge1ID[1] + blf);
toAppend.v2 = vertexInterp(blfPos, edge2ID[0] + blf, edge2ID[1] + blf);
toAppend.v3 = vertexInterp(blfPos, edge3ID[0] + blf, edge3ID[1] + blf);
//tris.Append(toAppend);
}