Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm not really a 3D person, and I've only used shaders a little in some Three.js examples, and so far I've got an impression that they are only being used for the graphical part of the equation.

Although, the (quite cryptic) Wikipedia article and some other sources lead me to believe that they can be used for more than just graphical effects, ie, to program the GPU (Wikipedia).

So, the GPU is still a processor, right? With a larger and a different instruction set for easier and faster vector manipulation, but still a processor. Can I use shaders to make regular programs (provided I've got access to the video memory, which is probable)?

Edit: regular programs == "Applications", ie create windows/console programs, or at least have some way of drawing things on the screen, maybe even taking user input.

share|improve this question
2  
What do you mean by "regular programs" –  Miro Jul 2 '12 at 17:35
2  
+1 For the cutest game development question I've ever seen that also managed to rethink my view of the world. –  knight666 Jul 2 '12 at 18:21
1  
Er, thanks? Lol. –  jco Jul 2 '12 at 18:58
1  
"==" is comparator, not assignment operator :) –  Miro Jul 2 '12 at 20:17
2  
Yeah, I know, it's still valid to use. I didn't want to "assign" the explanation to the definition, I wanted to equate them. –  jco Jul 2 '12 at 20:31

3 Answers 3

up vote 13 down vote accepted

Originally, dedicated graphics processing hardware had a fixed, hardwired set of functions. It would take input geometry, do very specific things to it to transform and rasterize it, and then blast the results to the screen. Over time, this functionality became parameterized and eventually programmable. "Shaders" became the term used for the programs that ran on the GPU, since they controlled the transformation and shading of geometry.

As GPU hardware evolved, more and more of it has become programmable, so now the bulk of the kinds of shaders one can write only contribute indirectly to the actual shading of anything on screen (I'm referring to things like geometry and hull shaders here). With that came the generalization of the GPU as a device for doing large-scale highly-concurrent stream-based processing, such that while the intent of a GPU and of shaders is generally to implement some kind of fancy graphical effect, they can also be used to perform certain kinds of general-purpose computations (particularly those that are suited to being computed in parallel). This is often referred to as general purpose GPU programming, or "GPGPU."

However, the GPU is still highly specialized and can't do a lot of the things a CPU could do. It has limited connectivity to the rest of the hardware in a system, as well, so you can't really write "regular" programs (with console output or mouse input, et cetera) entirely on the GPU. You can perform calculations on the GPU that aren't intended to be interpreted as renders, but it isn't a standalone CPU in its own right.

share|improve this answer

Simple. The graphics processing unit eventually got shaders, which a fancy pant effects for shading. This became programmable so the effects got more and more fancy. Eventually the entire GPU became a SIMD unit.

SIMD means Single Instrution Muliple Data. Currently the GPUs are like a tree. It has X many cores, each having Y many cores, having Z many cores. The further you go down the tree, the faster and smaller the memory, the more parallel and simpeler the calculations.

So the GPU has become sort of a General Purpuse GPU. It's not called a CPU because it's not the central processing unit, even though it can handle I/O, memmory management and scheduling.

Needless to say that the power from the GPGPU comes from having to do some dividable, parallel operations on a lot of data at once. While it's therefore useless to most general software stuff, nVidia is working on making the GPGPU a CPU. They believe that they can expose the GPU as an ARM CPU. This translation technique is also inside x86 CPUs, which are RISC at their core.

OpenCL, CUDA and DirectX are like a split personality programming language. OpenCL for example runs on the CPU, but offloads 'bombs' ("kernels") that are benefiting from SIMD, to the GPU.

It won't be long before it's all Fusion/Sandy Bridge CPU-GPU style.

share|improve this answer
3  
-1. Your choice of words drastically lower the quality of that answer. –  bummzack Jul 3 '12 at 11:59
    
Choice of words are in itself meaningsless: en.wikipedia.org/wiki/On_Denoting Therefore it doesn't lower the quality of the answer, because quality has nothing to do with the question, but logic. It's actually the most correct answer. –  Vincent Jul 3 '12 at 15:53
2  
Choice of words is very important. If you use offensive language, then your answer will not be considered good. Someone with a worthwhile answer will spend time making sure it is eloquent and elegant. –  Nathan Sabruka Jul 3 '12 at 15:58
    
If you have a problem with the language, then edit the answer. It's up to everybody to make the site better. –  Tetrad Jul 3 '12 at 16:12
    
If the request for logical understanding comes from a bicameralistic philosophical zombie, it would satisfy me regardless, because knowledge equals power. I don't like to hand over knowledge to bicamerals who value emotion more than logic. It only improves the answer. –  Vincent Jul 3 '12 at 16:16

GPU can't tell CPU what to do. It can just provide results in its memory which will CPU read.

Shaders/GPGPU can't be used for:

  • taking user input directly without CPU, because they are implemented as CPU interrupts
  • creation of any application, because applications are managed by kernel and that is executed by CPU
  • creation of any window, because window manager/server is executed in CPU

Shaders/GPGPU can be used for:

  • drawing stuff on screen/window, but it has to be controlled by CPU
  • video decoding/encoding
  • image processing in professional graphic editors - various effects parallel executable effects like blur, sharpen edges, ...
  • physics calculations

See OpenCL. It can utilize shaders for non-graphic calculations.

Edit based on comments:

Shaders are used just for rendering graphics. Performing non-graphics computations in GPU is called GPGPU.

share|improve this answer
    
The last point isn't quite true, you're not using shaders to calculate physics, you're using the GPGPU API like OpenCL and CUDA. –  dreta Jul 2 '12 at 18:03
    
@dreta Yes. It's true. Based on his question i think he meant shaders as hardware - processing units. He said "but still a processor". –  Miro Jul 2 '12 at 18:13
2  
well then correct him for being wrong, why are you aknowledging his misconception, he said he's not a rendering guru, shaders aren't ambiguous, they have a specific role –  dreta Jul 2 '12 at 18:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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