Skip to content

OpenCL / Vulkan Interop #7

@leios

Description

@leios

Ok, let me summarize:

I am quite happy with OpenCL. It gets the performance I want and is straightforward to write; however, it cannot directly render to a screen. So what do I do? I could switch entirely to Vulkan compute shaders, but the performance is lacking in many cases and it is unclear why I would switch to a graphics API when I only need to do computation.

The simplest solution is that Vulkan allows for a zero-copy sharing of data between the APIs [1,2]. This should be the best case scenario for supporting platforms. The problem is that I don't know what platforms will actually support this. I think most desktop PCs will. I am pretty sure Android (maybe not pixel tho?) and Arm laptops will as well. Mac / iOS is unlikely and will probably require it's own solution. You can use OpenCL for now on modern macs, but it's deprecated.

Other ideas:

  1. OpenCL without vulkan [3]. This involves a GPU -> CPU transfer for rendering with X (or whatever windowing API is necessary for specific platforms). It's a pain and the transfer times will probably be too slow for high FPS
  2. CLSPV to compile OpenCL to vulkan. MoltenVK for Apple. I think the performance here is lacking.
  3. Switch to Slang [5] or GLSL. MoltenVK for Apple. Again worried about performance / compilation performance. Slang can compile into Metal, but it treats it as a "textual target," meaning that it will generate a new text file to be read in to metal (for example). In that case, it makes more sense to just output metal directly since I am already string manipulating.
  4. Metal for Apple, OCL / Vulkan for everything else. I think runtime compilation for metal shaders is straightforward? [4]

In practice, this means that I will try OCL / Vulkan interop and ride that as long as I can. It should work on all desktops. If I want to support mobile, then I will support Metal / Vulkan directly (via GLSL / Slang).


  1. https://docs.vulkan.org/samples/latest/samples/extensions/open_cl_interop/README.html
  2. https://docs.vulkan.org/samples/latest/samples/extensions/open_cl_interop_arm/README.html
  3. https://github.com/ProjectPhysX/FluidX3D
  4. https://stackoverflow.com/questions/32298719/manually-compile-metal-shaders
  5. https://shader-slang.org/docs/first-slang-shader

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions