Search code examples
hlslmarching-cubes

one int variable works as an array index but another one doesn't


I'm working on a marching cube compute shader in unity at some point i need to find an index so that i can make vertices by connecting those edges here is the code

uint cubeIndex = 0;

for (int i = 0; i < 8; i++)
{
    if (cube[i].isInside == 1)
    {
        cubeIndex |= 1 << i;
    }
}

    return cubeIndex;

the problem is when i use "cubeIndex" as an array index it gives me this error: Program 'CSMain', error X4505: Sum of temp registers and indexable temp registers exceeds limit of 4096 at kernel CSMain.

if change the array index to any other int the code works!

here is my main kernel

 uint myCubeIndex = CubeInit(cube);
Edges midPoints = CalMidPoints(cube);

int edge = triTable[myCubeIndex][0];

float3 position = midPoints.midPoints[edge];

vertexArray.Append(position);

Solution

  • I believe that the bitshift with the unit is either going into the negatives giving you an overflow. or !!

    How to use a huge array in HLSL (error X4505)

    this issue as someone over here also tried to put too many vertices in a hlsl shader trying to make marching cubes work and needed to limit it to 4096