Contents
How does having a variable-length loop affect shader performance?
This means the GPU is executing some unknown number of loop iterations per pixel (although you can have an upper bound like maxIterations ). How does having a variable-length loop affect shader performance? Imagine the simple ray-marching psuedocode: How are the various mainstream GPU families (Nvidia, ATI, PowerVR, Mali, Intel, etc) affected?
How many threads does it take to run a shader?
As far as performance goes, the latest (DX11-class) graphics cards execute shaders on SIMD units that run 32 (NVIDIA) or 64 (AMD) “threads” in lockstep. These groups are variously known as warps or wavefronts.
What does it mean to run a loop on a GPU?
Its popular to render procedural content inside the GPU e.g. in the demoscene (drawing a single quad to fill the screen and letting the GPU compute the pixels). This means the GPU is executing some unknown number of loop iterations per pixel (although you can have an upper bound like maxIterations ).
How many pixels are in a pixel shader?
For pixel shaders, each thread equals one pixel, so I would expect that the SIMD unit is processing something like an 8×4 (NVIDIA) or 8×8 (AMD) block of pixels together. Branching and flow control is done per-wavefront, so all the threads in a wavefront have to loop as many times as the deepest individual pixel within that wavefront.
How are variables passed from the CPU to the shader?
If something is not a built in variable, you can send that information from the CPU (your main program) to the GPU (your shader). ShaderToy handles that for us. You can see all the variables being passed to the shader in the Shader Inputs tab. Variables passed in this way from CPU to GPU are called uniform in GLSL.
Is it worth learning to write graphics shaders?
Learning to write graphics shaders is learning to leverage the power of the GPU, with its thousands of cores all running in parallel. It’s a kind of programming that requires a different mindset, but unlocking its potential is worth the initial trouble.