Search Unity

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

Discussion in 'Shaders' started by Zolden, Dec 23, 2017.

  1. Zolden

    Zolden

    Joined:
    May 9, 2014
    Posts:
    141
    I'm writing to RWTexture2D<float4> 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:

    Code (CSharp):
    1. RWTexture2D<float4> textureOut;
    2.  
    3. #pragma kernel pixelCalc
    4.  
    5. [numthreads(8,8,1)]
    6. void pixelCalc (uint3 id : SV_DispatchThreadID){
    7.     textureOut[id.xy] = float4(1, 1, 1, 1);
    8. }
    Releveant parts of cpu side code:

    Code (CSharp):
    1. outputTexture = new RenderTexture(1024, 1024, 32);
    2. outputTexture.enableRandomWrite = true;                  
    3. outputTexture.Create();
    4. outputImage.material.mainTexture = outputTexture;  // this is just an image I use to visualize the renderTexture on
    5. _shader.SetTexture(kiCalc, "textureOut", outputTexture); // _shader is a prepared ComputeShader object
    6. _shader.Dispatch(kiCalc, 32, 32, 1);
    Does anyone have any idea, why doesn't it work on Metal, or how to make it work?
     
  2. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,982
    did you manage to get compute shaders to work on metal?
     
  3. Zolden

    Zolden

    Joined:
    May 9, 2014
    Posts:
    141
    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.
     
    MadeFromPolygons likes this.