diff options
author | Paul Berry <[email protected]> | 2012-06-20 13:40:45 -0700 |
---|---|---|
committer | Paul Berry <[email protected]> | 2012-06-22 07:59:34 -0700 |
commit | 82d25963a838cfebdeb9b080169979329ee850ea (patch) | |
tree | 8cc534b94e7666bfa3b3a299f168921548e2973a /src/mesa/drivers/dri/i965/brw_fs.cpp | |
parent | d988ea5e810868244eb1a1e7ede32295c9ed9ad4 (diff) |
i965: Compute dFdy() correctly for FBOs.
On i965, dFdx() and dFdy() are computed by taking advantage of the
fact that each consecutive set of 4 pixels dispatched to the fragment
shader always constitutes a contiguous 2x2 block of pixels in a fixed
arrangement known as a "sub-span". So we calculate dFdx() by taking
the difference between the values computed for the left and right
halves of the sub-span, and we calculate dFdy() by taking the
difference between the values computed for the top and bottom halves
of the sub-span.
However, there's a subtlety when FBOs are in use: since FBOs use a
coordinate system where the origin is at the upper left, and window
system framebuffers use a coordinate system where the origin is at the
lower left, the computation of dFdy() needs to be negated for FBOs.
This patch modifies the fragment shader back-ends to negate the value
of dFdy() when an FBO is in use. It also modifies the code that
populates the program key (brw_wm_populate_key() and
brw_fs_precompile()) so that they always record in the program key
whether we are rendering to an FBO or to a window system framebuffer;
this ensures that the fragment shader will get recompiled when
switching between FBO and non-FBO use.
This will result in unnecessary recompiles of fragment shaders that
don't use dFdy(). To fix that, we will need to adapt the GLSL and
NV_fragment_program front-ends to record whether or not a given shader
uses dFdy(). I plan to implement this in a future patch series; I've
left FIXME comments in the code as a reminder.
Fixes Piglit test "fbo-deriv".
NOTE: This is a candidate for stable release branches.
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri/i965/brw_fs.cpp')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_fs.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp index 313e720d382..43efd68e2c4 100644 --- a/src/mesa/drivers/dri/i965/brw_fs.cpp +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp @@ -1848,6 +1848,13 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog) struct brw_context *brw = brw_context(ctx); struct brw_wm_prog_key key; + /* As a temporary measure we assume that all programs use dFdy() (and hence + * need to be compiled differently depending on whether we're rendering to + * an FBO). FIXME: set this bool correctly based on the contents of the + * program. + */ + bool program_uses_dfdy = true; + if (!prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) return true; @@ -1892,6 +1899,9 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog) if (fp->Base.InputsRead & FRAG_BIT_WPOS) { key.drawable_height = ctx->DrawBuffer->Height; + } + + if ((fp->Base.InputsRead & FRAG_BIT_WPOS) || program_uses_dfdy) { key.render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer); } |