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 <kenneth@whitecape.org>
- src/mesa/drivers/dri/i965/brw_fs.cpp 10 additions, 0 deletionssrc/mesa/drivers/dri/i965/brw_fs.cpp
- src/mesa/drivers/dri/i965/brw_fs.h 2 additions, 1 deletionsrc/mesa/drivers/dri/i965/brw_fs.h
- src/mesa/drivers/dri/i965/brw_fs_emit.cpp 11 additions, 3 deletionssrc/mesa/drivers/dri/i965/brw_fs_emit.cpp
- src/mesa/drivers/dri/i965/brw_wm.c 10 additions, 0 deletionssrc/mesa/drivers/dri/i965/brw_wm.c
- src/mesa/drivers/dri/i965/brw_wm.h 2 additions, 1 deletionsrc/mesa/drivers/dri/i965/brw_wm.h
- src/mesa/drivers/dri/i965/brw_wm_emit.c 11 additions, 4 deletionssrc/mesa/drivers/dri/i965/brw_wm_emit.c