Skip to content

Instantly share code, notes, and snippets.

@joekarl
Last active August 29, 2015 14:26
Show Gist options
  • Save joekarl/a967c0de27d2a1e04842 to your computer and use it in GitHub Desktop.
Save joekarl/a967c0de27d2a1e04842 to your computer and use it in GitHub Desktop.
Programmable pipeline implementation

So after some more thought, I'm thinking a programmable pipeline would start to look like this.

  • say we want to render a thing (a thing being a chunk of memory representing the thing, ie a buffer)
  • vertex shader gets one slice from the buffer (all of the data for a single vertex)
    • this necessitates interleaved buffers but that shouldn't be a problem
    • nice thing about this is we're loading up all the data for a vertex into cache nicely for the cpu to play with
  • the vertex shader outputs an array of data to be passed to the rasterizer (we'll call each of these a varying)
  • the rasterizer takes these outputs (which are an array per vertex) and does scan conversion on them (ie convert the triangle into a set of scan lines that are in pixel space)
    • also done in this step are screen space clipping
    • each scanline will contain the x,y screen coords
    • each scanline will also contain the left and right values of each varying that was output from the vertex shader
    • NOTE this process will have to be heavily optimized
  • each scanline is processed through the fragment shader and it will output a color value for each pixel in the scanline
    • the shader will get an input of the interpolated x,y screen coords
    • the shader will also get an input of the interpolated value of the varyings
    • the shader should be able to set the z-value of the pixel
  • each output from the fragment shader will be written to the underlying raster using the colorspace of the renderer context
    • before doing this the z-value of the pixel should be checked against a z-buffer to ensure that we should actually write the color to the raster (or to do color blending)

This ought to give us a simple pipeline that we can pass all sorts of data between things. The downside to doing things this way is there's no actual types as inputs to the vertex shader and varying going between the shaders are just arrays (and probably float or double arrays at that). That being said, inside the shaders one can extract the needed components and cast back to vec4 or mat4 or whatever. Also with this setup, because the shader inputs are just arrays we can standardize each shader to just be a function pointer (and this can be a C defined function pointer).

This setup computes all the scanlines at once but we may want to run the fragment shader and blending steps on each scanline as they're created, not sure what the right answer here is...

Hopefully this makes a little sense :p

@joekarl
Copy link
Author

joekarl commented Aug 3, 2015

Most of the linear algebra in the fixed bits of the pipeline will be done in the scan conversion step so this will need some heavy optimization.
Also anything doing linear interpolation (ie calculating varyings or scanline endings) will need some heavy optimization as well but that should be fairly easy to accomplish and should be able to simd the heck out of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment