Search Unity

OpenCL from Unity

Discussion in 'Editor & General Support' started by fct509, Aug 2, 2019.

  1. fct509


    Aug 15, 2018

    I'm working on a Unity Editor extension for Unity 2018.4 (I'm expecting it to work on newer versions too), and I need to do some computationally intensive work from the GPU. I already got a simple prototype working with a Compute Shader, but it turns out that the only way to run a Compute Shader is by freezing the main thread. I even tried to dispatch the Compute Shader from an IJob, but the only thing that did was enable the Editor to catch the exception without me wrapping the code in my own try-catch.

    I asked the folks over on the GPU Progressive Lightmapper thread how they managed to run code on the GPU without freezing the main thread and they said that this was done by using OpenCL from a background thread.

    Does anyone have any recent advise on how to run OpenCL from Unity; please keep in mind that I've never used OpenCL before. Most of what I found was either people talking about error codes from the GPU Progressive Lightmapper or a few threads from 2012. Unity has changed a lot these last four years, so I'm not very hopeful when it comes to those older threads.

    Can anyone point me to some resources on running OpenCL from a background thread?