1
$\begingroup$

Today we have tools such as Nvidia's CUDA and OpenCL to perform general purpose computing on the GPU (GPGPU). Seeing that traditional shaders are specifically used for generating graphics by filling a frame buffer with pixel values, are there any examples of graphics shaders being used for non-graphics computing prior to the modern GPGPU capability?

Shaders can take input parameter values sent from the CPU, and the GPU can be told to render to a texture buffer instead of the screen. With this in mind, I feel like someone could send in values for computation, compute them using the vertex and/or pixel shaders, and encode the results in the output pixel values which can be read by the CPU from the target buffer.

$\endgroup$
1

2 Answers 2

1
$\begingroup$

One early example of this (no doubt there are many others) was a 2004 Gamasutra article "Building a Million-Particle System". It represented particle data, such as positions and velocities, encoded as color values in textures, and used fragment shaders to update them.

In graphics hardware terms the input data stream can be represented by a texture, the output data stream by a render target. Output data is often re-used as input in a further processing step. In that case the data streams are textures as well as render targets. The processing kernel is represented by a pixel shader (also called fragment program). By drawing a full-screen rectangle, the graphics hardware is instructed to call the pixel shader once for each output data record, reading from the input stream in the pixel shader.

This article even performed depth sorting of particles using multi-pass merge sort, and has some historically interesting discussion of the difficulties of turning the pixel data back into vertex data at the time (as there was no support for sampling textures in vertex shaders).

$\endgroup$
2
  • $\begingroup$ Nice to have such an old reference, at the time the article was written I was learning how to tie my shoes! $\endgroup$ Oct 24, 2022 at 22:19
  • $\begingroup$ Awesome answer! That really is certainly an old reference, so it surely has been used for quite a long time. $\endgroup$ Oct 25, 2022 at 13:25
2
$\begingroup$

This still happens in constraint platforms like OpenGL ES or the like were there are no compute shaders available and you end up hacking pixel shaders to do general purpose calculations, see any WebGL GPU physics demo and you most probably see ping ponging between fragment shader FBOs to be able to do computations. Or simply go to shadertoy.com and look at any physics/simulation demo. At the end of the day a compute shader ends up being very similar with the difference of it being more general purpose and therefore more tweakable and sometimes more performant for certain tasks. Would be very nice if some OG could point at a very primitive example or the first time that someone thought that programable GPU programs/shaders were suitable for doing math on non graphics related stuff and did it though.

$\endgroup$
4
  • 1
    $\begingroup$ the floating point power was realized almost immediately I don't have any links but books like the first edition of the "orange" book has some good examples like early attempts at ambient occlusion. $\endgroup$
    – pmw1234
    Oct 23, 2022 at 12:34
  • $\begingroup$ would be nice to look at that, when I have some time I might try to find that edition. $\endgroup$ Oct 23, 2022 at 20:14
  • $\begingroup$ Thanks for this answer! In my head, it seemed like such an obvious way to do GPGPU without specific libraries like CUDA that I know someone had to be doing it somewhere. $\endgroup$ Oct 25, 2022 at 13:25
  • $\begingroup$ I think this happened the other way around. Computers used to have an optional floating point processor, which was later integrated into the CPU which made it cheaper and more ubiquitous. The idea that gamers would buy a dedicated floating point processor just made the economy of scale work. $\endgroup$ Oct 25, 2022 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.