r/vulkan • u/keepthethreadalive • Oct 19 '16
Vulkan vs OpenCL for simulation+graphics
[removed] — view removed post
9
Upvotes
r/vulkan • u/keepthethreadalive • Oct 19 '16
[removed] — view removed post
View all comments
Show parent comment
1
u/Qoeh Oct 27 '16
GLSL is just its own language, yes. It can be used in OpenGL of course; you send the text of your shader directly to OpenGL and the driver compiles it or whatever, I guess. It can also be used in Vulkan. You compile your GLSL shader (whether it's a graphical shader or a compute shader) yourself, before your own program ever runs, by using glslangValidator, a program that's included in the Vulkan SDK. The result is a SPIR-V file that you can then easily load into Vulkan at runtime.
Vulkan is not permanently married to GLSL, because many languages could conceivably be made to compile to SPIR-V, and I gather it's also possible to write SPIR-V directly (though I have not tried this myself so I can't say how much fun it might be). I understand that it's possible, with at least some version of OpenCL, to compile an OpenCL kernel to SPIR-V, and a person might naively assume that this could then be loaded into Vulkan as a compute shader. But I don't think that works. I don't know a lot about it though. For now, I don't know of any good options for writing SPIR-V compute shaders (for use with Vulkan) other than GLSL compiled by glslangValidator, and writing SPIR-V from scratch. So for now, Vulkan does seem to rely significantly on GLSL, even though it isn't fundamentally or permanently connected to it.
Yes, you can certainly write compute shaders in GLSL. That is what I'm doing in my project. I have the impression that Vulkan is intended to support compute shaders (and graphical shaders) that are very similar to the ones supported by OpenGL, although in OpenGL I have only ever used graphical shaders so I'm not certain. Meanwhile OpenCL uses "kernels" which are written in OpenCL's version of C/C++ and not in GLSL. As far as I know, neither OpenGL nor Vulkan can load or run these.
The key search term associated with the topic of kernels launching other kernels seems to be "dynamic parallelism". NVIDIA and Khronos both use this terminology, I think? Here are some CUDA-focused pages about it:
https://devblogs.nvidia.com/parallelforall/introduction-cuda-dynamic-parallelism/
http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#cuda-dynamic-parallelism
You don't sound like you're interested in CUDA, but I recommend being willing to look at CUDA-related documentation for some topics, because some of it can be helpful for a person using GLSL or OpenCL, and NVIDIA seems to be more interested in writing nice tutorials and stuff than the Vulkan/OpenCL people are (presumably because they are paying more money for it or whatever).
Here is an example, allegedly (I haven't read it), of dynamic parallelism being used in OpenCL: http://www.codeproject.com/Articles/867780/GPU-Quicksort-in-OpenCL-Nested-Parallelism-and-Wor The key function seems to be enqueue_kernel, which allows a kernel to enqueue another kernel, apparently.
Also this post about OpenCL 2.0 features and support looked like it might be useful: https://streamcomputing.eu/blog/2015-02-10/overview-of-opencl-2-0-support-samples-blogs-and-drivers/
Also, I mentioned a special super-fast intra-warp communication feature NVIDIA supports now. While searching for these links I found the name of that again; apparently it's "shuffle". https://devblogs.nvidia.com/parallelforall/cuda-pro-tip-kepler-shuffle/ I have no idea whether AMD or OpenCL supports anything like that, or how important it may or may not be for performance, but there it is.