The dream of having something resembling CUDA Computing on the GPU in simple OpenGL on open source drivers.
To perform general computing tasks, of the type of CUDA on the GPU using Compute Shaders and SSBO - Shader Storage Buffer Objects.
The following code has a bug and in my open source Linux drivers on a Integrated
AMD GPU inside my CPU AMD Ryzen 4700 G, it crashes the computer. Not fun at all.
But because there is so little information on the internet about how to use the
Compute shaders and SSBO - Shader Storage Buffer Objects, I am posting this code
anyway.
I implemented this code in Odin after doing a lot of research on the internet.
I post here the code and the references that I used to implement it.
There is also a other program inside the directory "opengl_simple_program_working", that works, I made it from following the learning OpenGL tutorial from the site: https://learnopengl.com and from one example of Odin of the GLFW library. That program doesn't use Compute Shaders and SSBO - Shader Storage Buffer Objects, but it works and it is a good starting point to learn how to use OpenGL in Odin.
-
Medium Article on Compute Shaders with texture buffers, no SSBO.
https://medium.com/@daniel.coady/compute-shaders-in-opengl-4-3-d1c741998c03 -
GitHub of the previous article
https://github.com/pondodev/opengl_compute/tree/29802608ead55c92184fadfac63042382d5592c3 -
What is the difference between OpenCL and OpenGL's compute shader?
https://stackoverflow.com/questions/15868498/what-is-the-difference-between-opencl-and-opengls-compute-shader/15874988 -
StackOverFlow response - To resolve the fact than OpenGL calculation can be less accurate then IEEE float 32
Those interested in OpenGL arithmetic precision guarantees should regard the ARB_shader_precision extension, introduced in OpenGL 4.1.a
See: https://registry.khronos.org/OpenGL/extensions/ARB/ARB_shader_precision.txt
Droid Coder
Aug 11, 2019 at 11:22 -
OpenGL (4.3) compute shader example
http://wili.cc/blog/opengl-cs.html -
Compute Shader - Official documentation
https://www.khronos.org/opengl/wiki/Compute_Shader -
It's More Fun to Compute
An Introduction to Compute Shaders
https://antongerdelan.net/opengl/compute.html -
Mike Bailey
OpenGL Compute Shaders
https://web.engr.oregonstate.edu/~mjb/cs557/Handouts/compute.shader.1pp.pdf -
In Python - Compute Shader Tutorial
https://api.arcade.academy/en/latest/tutorials/compute_shader/index.html -
ktyldev - oglc -- Cat flynn
https://github.com/ktyldev/oglc -
glCreateShader — Creates a shader object
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glCreateShader.xhtml -
Shader Storage Buffer Object
https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object -
GPU Buffers: Introduction to OpenGL 4.3 Shader Storage Buffers Objects
https://www.geeks3d.com/20140704/tutorial-introduction-to-opengl-4-3-shader-storage-buffers-objects-ssbo-demo/ -
Buffer Object
https://www.khronos.org/opengl/wiki/Buffer_Object -
glTexImage2D — specify a two-dimensional texture image
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glTexImage2D.xhtml -
glBindImageTexture — bind a level of a texture to an image unit
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml -
Compute Shaders - Inputs
https://www.khronos.org/opengl/wiki/Compute_Shader#Inputs -
Compute Shaders - local_size
https://www.khronos.org/opengl/wiki/Compute_Shader#Local_size -
glGetTexImage — return a texture image
https://registry.khronos.org/OpenGL-Refpages/gl4/html/glGetTexImage.xhtml
MIT Open Source License
Best regards,
João Nuno Carvalho