Search Unity

ComputeShader support on OS X ?

Discussion in 'Shaders' started by radicalEd, Dec 17, 2016.

  1. radicalEd

    radicalEd

    Joined:
    Mar 19, 2016
    Posts:
    81
    Is there any way to get ComputeShaders working on an OSX device?

    Here's the hardware of my machine (if it matters);
    - MacBook Pro (Retina, 13-inch, Late 2013)
    - 2.8 GHz Intel Core i7
    - 8 GB 1600 MHz DDR3
    - Intel Iris 1536 MB

    If there's not a way to directly get this functioning properly, is there a way to virtualize GPU threads for the sake of developing while mobile?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    While the hardware used in Macs have had support for OpenGL computer shaders for a few years, OSX itself does not. Compute shaders are a core feature of OpenGL 4.3 and later, but OSX only has support for OpenGL 4.1.

    The only way to use OpenGL compute shaders on a Mac is to install Windows. Alternately the Unity 5.6 beta has support for Apple's Metal graphics API with compute for both OSX and iOS.
     
  3. radicalEd

    radicalEd

    Joined:
    Mar 19, 2016
    Posts:
    81
    I'm trying to run the ComputeBuffer on the beta, still getting the same "not supported" error. Is the metal API accessed differently than a typical ComputeBuffer call?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    By default the editor runs in OpenGL mode, you likely have to force enable Metal via a command line, though I do not know what that command line argument is. I don't have a Mac. It should be listed here, but the document hasn't been updated yet.
     
  5. radicalEd

    radicalEd

    Joined:
    Mar 19, 2016
    Posts:
    81
    I found that I could enable metal by modifying the build settings.

    After doing, this, however, trying to declare a ComputeShader object freezes unity forever.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    Post in the beta forums then?
     
  7. VinW

    VinW

    Joined:
    Jan 31, 2017
    Posts:
    2
    Could you solve the problem?
    I set the Mac Graphics API in the player settings to metal and still get this error, when dispatching a compute shader kernel:
    "Platform does not support compute shaders"
    The kernel can't be found as well in a script:
    computeShader.FindKernel ("CSXX"); => "Kernel 'CSXX' not found"

    When I click on the ComputeShader file in the Editor, the Inspector shows the kernels correctly:
    Kernels:
    CSXX Metal OpenGLCore

    (Unity 5.6 b5)
     
  8. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    It is not enough to just select Metal as the API - you also need to tick the box in Player settings that enabled Metal support in the Unity editor.
     
    jason-fisher likes this.
  9. jason-fisher

    jason-fisher

    Joined:
    Mar 19, 2014
    Posts:
    133
    Are GetData calls non-blocking in iOS due to the GPU and CPU memory being shared? Will Unity still make a copy of the object to support its internal pipeline?
     
  10. VinW

    VinW

    Joined:
    Jan 31, 2017
    Posts:
    2
    I did this and now the Unity Editor freezes forever like radicalEd described it before. When I build the app and run it, it won't freeze, but the compute shaders aren't executed as well.

    So this might be a bug in the beta?
     
  11. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    If you still have those sorts of issues with latest beta of Unity 5.6, I would recommend posting about your experience in the following thread in the beta forum:

    https://forum.unity3d.com/threads/metal-editor.450548/

    Some bugs/isues probably are hardware/vendor/driver specific so always best to mention that sort of thing. macOS version matters too - only Sierra is supported properly as far as I was told, though I cant remember if that applies to both editor and runtime or just editor metal mode.
     
  12. cstenson

    cstenson

    Joined:
    Dec 10, 2015
    Posts:
    3
    Hi!
    Looking into porting a current project using ComandBuffers on Windows to iOS and Metal Graphics API. I have had some issues and come to the conclusion that the editor hangs when adding a command buffer to a camera. Right now I have no clue what can be the problem more than it is when setting the commmandbuffer to the camera.

    Okay I managed to track the issue down a bit further to this line:
    commandBuffer.DispatchCompute(computeShader, kernelIndex: 0, threadGroupsX: 1, threadGroupsY: 1, threadGroupsZ: 1);

    Edit:
    Realized it was one of the bug fixes to the Unity 2017.2. However it didnt solved my issue.

    I have narrowed it down to that the issue appears when I'm modifying a float inside in a manner similar to this:

    void kernel(....){
    float counter
    for(){
    if(condition){
    counter++;
    }
    }
    bufferOut = counter;
    }

    Any ideas on why this happens? Moving it outside of the if (in the for ) works...
     
    Last edited: Oct 16, 2017
  13. jcowles

    jcowles

    Joined:
    May 25, 2016
    Posts:
    11
    No clue, but FYI, I'm running OSX with Metal enabled both for the graphics API and the editor and I'm still getting the "Platform does not support compute shaders" error running Unity 2018.1.0f2.
     
  14. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    Which model of Mac? Which version of OS X?
     
  15. John1515

    John1515

    Joined:
    Nov 29, 2012
    Posts:
    248
    Any updates on this? Really want to learn+use compute shaders for my project..
     
  16. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    Compute Shaders have worked on the mac with Unity using Metal graphics API for a long time now. If it isnt working for you then its either a bug or you dont have suitable mac hardware or macos version or are using a really old version of Unity or some setting is wrong or your compute shader code has issues.
     
  17. John1515

    John1515

    Joined:
    Nov 29, 2012
    Posts:
    248
    I have everything up to date, but I think that the shader I was using wasn't made for metal or something.
    My intereste was mostly for particle systems though (inspired by the development of Tonandi on magic Leap), but in the meantime someone told me that shader graph supports GPU based particle systems as well. So I guess I don't need to learn compute shaders after all
     
  18. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,502
    The Unity VFX Graph for the HDRP is a modern GPU particle system.

    https://unity.com/visual-effect-graph

    Its been a little while since I used it on a mac but it certainly worked when I tried it.