RenderTexture written in a compute shader doesn't work on Metal

I’m writing to RWTexture2D texture in a compute shader. It corresponds to a RenderTexture on cpu side. It works on Windows with DX11, but doesn’t work on MacOS with Metal.

I’m using Unity 2017.2.0f3

Shader code:

RWTexture2D<float4> textureOut;

#pragma kernel pixelCalc

[numthreads(8,8,1)]
void pixelCalc (uint3 id : SV_DispatchThreadID){
    textureOut[id.xy] = float4(1, 1, 1, 1);
}

Releveant parts of cpu side code:

outputTexture = new RenderTexture(1024, 1024, 32);
outputTexture.enableRandomWrite = true;                   
outputTexture.Create();
outputImage.material.mainTexture = outputTexture;  // this is just an image I use to visualize the renderTexture on
_shader.SetTexture(kiCalc, "textureOut", outputTexture); // _shader is a prepared ComputeShader object
_shader.Dispatch(kiCalc, 32, 32, 1);

Does anyone have any idea, why doesn’t it work on Metal, or how to make it work?

did you manage to get compute shaders to work on metal?

Well, yea. Not entirely for my purpose, but it works. I managed to put data to video memory via compute buffer, compute it with compute shader and get it back to cpu memory, all worked fine. There are just some limits Metal API has, that are not as wide as directx ones. For example, 256 threads per group limit or something like that, don’t remember precisely. For my case I figured that drawing pixels to render texture doesn’t work on Metal and I couldn’t find a way to fix it. So, probably I need to visualize data some other way.

1 Like