My favorites | Sign in
Project Home Wiki Issues Source
Search
for
InternalGrGLProgram  
Pieces of the Ganesh GPU Shader Model
Updated Oct 20, 2011 by bsalo...@google.com

This documentation describes the state of an internal component as of r2494.

Introduction

GPU vertex/fragment shaders are generated and managed as GrGLProgram objects. They are identified at runtime by a hash computed off of the ProgramDesc, a private struct of packed descriptors.

The basic model of a shader hearkens back to the fixed function pipeline: a series of stages, each of which receives an input color and texture coordinates, reads a single texture n times, and writes a single output that as the input to the next stage. Currently, each stage modulates the incoming color by its computed color. The input to the first stage will be one of:

  • interpolated per-vertex color
  • uniform color
  • a known constant color (solid white or transparent black)

Some transfer (blend) modes require computing fractional coverage separately from alpha. The program descriptor contains a stage index that divides the stages been color- and coverage-computing. The coverage stages are linked series in the same manner as the color stages. The initial input to the first coverage stage is either:

  • 1.0 (full coverage)
  • interpolated per-vertex coverage

The frag shader color output (gl_FragColor) is color x coverage. A secondary frag shader output may be computed from the color and coverage. It is used as a dst coefficient to the GL blend operation (see GL_ARB_blend_func_extended). The program descriptor enum DualSrcOutput indicates whether this additional output is necessary and how it is computed.

These stages are augmented with several special-purpose elements:

  • a color filter can be inserted after the last color stage. It is expressed as a xfer mode between the last stage's output color and a constant color (loaded as a uniform to the frag shader).
  • edge-distance antialiasing can be the input to the first coverage stage.

Shaders are generated as groups of strings of text by GrGLProgram::genProgram(), then compiled, with their setup information stored in a GrGLProgram::CachedData struct. The parameters to genProgram() are set up by GrGpuGLShaders::buildProgram(), which is called by GrGpuGLShaders::ProgramCache::getProgramData(), which is in turn called by GrGpuGLShaders::flushGraphicsState(). The CachedData object is stored in GrGpuGLShaders::fProgramData and used heavily throughout GrGpuGLShaders.

Future Work

  • Refactor and clean up code
  • Add a gamma correction element
    • This will require supporting stages with multiple inputs & outptus
  • Generalize the stage model to include edge AA (no texture), single-stage gamma correction (two textures), ...
    • Does this require increasing the max # of stages, or letting it vary? What does that do to hash performance, which has been an unexpected bottleneck in the past?
  • Create an intermediate representation so we can output DirectX instead of OpenGL.
Powered by Google Project Hosting