I am attempting to learn Unity’s compute shader language. When compiling the script below I get the following error:
Debug Error!
Program: …ogram
Files\Unity\Data\Tools64\UnityShaderCompuler.exe
R6010
-abort() has been called
this pops up one more time after hitting ignore.
After that the code works the way it should 90%. Meaning that if I uncomment the last else if statement (I know I really shouldn’t be using if and else if but I cannot think of any other way to possible do it) the whole thing breaks and nothing happens when I hit play. And that’s what happens on my AMD card. On my computer with an NVIDIA card in it, my entire system freezes forcing a hard restart, not exactly what I had in mind when coding compute shaders. What should happen is that yellow dots should appear on 6 textures that correspond with a skybox. It all works fine when I work with 5 textures but as soon as I do the 6th, it all breaks appart and ruins my day.
So I would like to understand why this is all happening, and the things I can do to fix it, and how I can avoid it happening in the future.
Here is the code for the compute shader. I don’t think the script controlling the shader has anything to do with it. All it does is assign buffers.
- #pragma kernel CSMain
- #pragma kernel draw0
-
- RWTexture2D tex0;
- RWTexture2D tex1;
- RWTexture2D tex2;
- RWTexture2D tex3;
- RWTexture2D tex4;
- RWTexture2D tex5;
-
- RWStructuredBuffer buffer;
- RWStructuredBuffer buffer1;
- RWStructuredBuffer buffer2;
-
- int3 pixelPos;
- float w;
-
- [numthreads(16,16,1)]
-
- void CSMain (int2 id : SV_DispatchThreadID)
- {
- tex0[id] = float4(0, 0, 0, 1);
- tex1[id] = float4(0, 0, 0, 1);
- tex2[id] = float4(0, 0, 0, 1);
- tex3[id] = float4(0, 0, 0, 1);
- tex4[id] = float4(0, 0, 0, 1);
- tex5[id] = float4(0, 0, 0, 1);
- }
-
- [numthreads(1,1,1)]
-
- void draw0(){
- for(int x=0; x<buffer.Length; x++){
- if(buffer2[×] == 0){
- tex0[int2(buffer[×], buffer1[×])] = float4(1, 1, 0, 1);
-
- }
-
- else if(buffer2[×] == 1){
- tex1[int2(buffer[×], buffer1[×])] = float4(1, 1, 0, 1);
-
- }
-
- else if(buffer2[×] == 2){
- tex2[int2(buffer[×], buffer1[×])] = float4(1, 1, 0, 1);
-
- }
-
- else if(buffer2[×] == 3){
- tex3[int2(buffer[×], buffer1[×])] = float4(1, 1, 0, 1);
-
- }
-
- else if(buffer2[×] == 4){
- tex4[int2(buffer[×], buffer1[×])] = float4(1, 1, 0, 1);
-
- }
-
- //else if(buffer2[×] == 5){
- // tex5[int2(buffer[×], buffer1[×])] = float4(1, 1, 0, 1);
-
- //}
- }
- }