"Compilation failed for kernel 'CSMain' [0x80004005 - unknown error] 'internal error: failed to emit instruction ' at kernel CSMain" Compile error

-1

So I've been hit with this compilation error, and I can't find any other instances of someone else getting this error message before. I don't know what the problem could be, so I'll just put down the code.

#pragma kernel CSMain
float minNorm;
float maxNorm;
float threshold;
float numNodes;
Buffer<float4> nodes;
RWBuffer<float> outputBuffer;
RWBuffer<half> boolOutputBuffer;
RWBuffer<float2> dist;
void getDistances(float3 pos) {
    for(int i = 0; i < 100; i++) {
        float3 pos2 = float3(nodes.Load(i)[0], nodes.Load(i)[1], nodes.Load(i)[2]);
        float a = distance(pos, pos2);
        dist[i] = float2(a, nodes.Load(i)[1]);
        if(dist[i][1] == 0)
            break;
    }
    for (;;){
        bool isSorted = true;
        for(int i = 0; i < 100; i++){
            if(dist[i + 1][1] == 0)
                break;
            if(dist[i][0] > dist[i + 1][0]){
                float2 temp = dist[i];
                dist[i] = dist[i + 1];
                dist[i + 1] = temp;
                isSorted = false;
            }
        }
        if(isSorted)
            break;
    }
}

[numthreads(8, 8, 8)]
void CSMain (uint3 id : SV_DispatchThreadID) {
    float3 pos = id;
    float weight = 0;
    int outputIndex = id.x*8*8+id.y*8+id.z;
    getDistances(pos);
    float output;
    for (int i = 0; i < numNodes - 1; i += 1){
        float type = dist[i][1];
        if (type == 1 || type == 3 || type == 4 || type == 5) 
            weight += dist[i][0] / dist[i + 1][0] / dist[numNodes][0];
        else 
            weight += dist[i + 1][0] / dist[i][0] / dist[numNodes][0];
    }
    float type = dist[0][1];
    if (type == 1)
        output = dist[0][0] / weight;
    else if (type == 2)
        output = weight / pow(abs(dist[0][0]), 0.01f);
    else if (type == 3 && numNodes > 1)
        output = dist[1][0] / weight;
    else if (type == 4)
        output = (-1 * pow(abs(dist[0][0]), (numNodes / dist[numNodes][0])) / weight);
    else if (type == 5)
        output = (pow(abs(dist[0][0]), (numNodes / dist[numNodes][0])) / weight);
    else
        output = (-1 * (pow(abs(dist[0][0]), (numNodes / dist[numNodes][0])) / weight));
    output -= minNorm;
    output /= maxNorm;
    output *= 100;
    outputBuffer[outputIndex] = output;
    if(output > threshold)
        boolOutputBuffer[outputIndex] = 1;
    else
        boolOutputBuffer[outputIndex] = 0;
}

This creates individual pixels of a 3D noise map. It took me a couple of days to resolve all of the compilation errors I was getting, and then I got the unknown error. Upon further inspection, I can confirm that it is not the content of the functions, as removing them altogether still gave me the error.

unity3d
shader
hlsl
compute-shader
asked on Stack Overflow Apr 7, 2021 by Joshua Favorite • edited Apr 7, 2021 by Joshua Favorite

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0