summaryrefslogtreecommitdiffstats
path: root/src/mesa/state_tracker
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2010-12-02 20:39:59 +0100
committerMarek Olšák <[email protected]>2010-12-03 05:56:40 +0100
commitd531f9c2f5c78468d913fc509b223760ac1c1124 (patch)
treecbd023be1ac512982e2fcf8bcb89fcc9f9e5e070 /src/mesa/state_tracker
parent6a46fce14f38adf72925842edf9829c00d1ee800 (diff)
mesa, st/mesa: fix gl_FragCoord with FBOs in Gallium
gl_FragCoord.y needs to be flipped upside down if a FBO is bound. This fixes: - piglit/fbo-fragcoord - https://bugs.freedesktop.org/show_bug.cgi?id=29420 Here I add a new program state STATE_FB_WPOS_Y_TRANSFORM, which is set based on whether a FBO is bound. The state contains a pair of transformations. It can be either (XY=identity, ZW=transformY) if a FBO is bound, or (XY=transformY, ZW=identity) otherwise, where identity = (1, 0), transformY = (-1, height-1). A classic driver (or st/mesa) may, based on some other state, choose whether to use XY or ZW, thus negate the conditional "if (is a FBO bound) ...". The reason for this is that a Gallium driver is allowed to only support WPOS relative to either the lower left or the upper left corner, so we must flip the Y axis accordingly again. (the "invert" parameter in emit_wpos_inversion) NOTE: This is a candidate for the 7.9 branch. Signed-off-by: Marek Olšák <[email protected]> Signed-off-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r--src/mesa/state_tracker/st_mesa_to_tgsi.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c
index c5c239b2c95..f848462310e 100644
--- a/src/mesa/state_tracker/st_mesa_to_tgsi.c
+++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c
@@ -760,10 +760,13 @@ emit_adjusted_wpos( struct st_translate *t,
/**
* Emit the TGSI instructions for inverting the WPOS y coordinate.
+ * This code is unavoidable because it also depends on whether
+ * a FBO is bound (STATE_FB_WPOS_Y_TRANSFORM).
*/
static void
-emit_inverted_wpos( struct st_translate *t,
- const struct gl_program *program )
+emit_wpos_inversion( struct st_translate *t,
+ const struct gl_program *program,
+ boolean invert)
{
struct ureg_program *ureg = t->ureg;
@@ -771,17 +774,17 @@ emit_inverted_wpos( struct st_translate *t,
* Need to replace instances of INPUT[WPOS] with temp T
* where T = INPUT[WPOS] by y is inverted.
*/
- static const gl_state_index winSizeState[STATE_LENGTH]
- = { STATE_INTERNAL, STATE_FB_SIZE, 0, 0, 0 };
+ static const gl_state_index wposTransformState[STATE_LENGTH]
+ = { STATE_INTERNAL, STATE_FB_WPOS_Y_TRANSFORM, 0, 0, 0 };
/* XXX: note we are modifying the incoming shader here! Need to
* do this before emitting the constant decls below, or this
* will be missed:
*/
- unsigned winHeightConst = _mesa_add_state_reference(program->Parameters,
- winSizeState);
+ unsigned wposTransConst = _mesa_add_state_reference(program->Parameters,
+ wposTransformState);
- struct ureg_src winsize = ureg_DECL_constant( ureg, winHeightConst );
+ struct ureg_src wpostrans = ureg_DECL_constant( ureg, wposTransConst );
struct ureg_dst wpos_temp;
struct ureg_src wpos_input = t->inputs[t->inputMapping[FRAG_ATTRIB_WPOS]];
@@ -794,12 +797,23 @@ emit_inverted_wpos( struct st_translate *t,
ureg_MOV( ureg, wpos_temp, wpos_input );
}
- /* SUB wpos_temp.y, winsize_const, wpos_input
- */
- ureg_SUB( ureg,
- ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
- winsize,
- wpos_input);
+ if (invert) {
+ /* MAD wpos_temp.y, wpos_input, wpostrans.xxxx, wpostrans.yyyy
+ */
+ ureg_MAD( ureg,
+ ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
+ wpos_input,
+ ureg_scalar(wpostrans, 0),
+ ureg_scalar(wpostrans, 1));
+ } else {
+ /* MAD wpos_temp.y, wpos_input, wpostrans.zzzz, wpostrans.wwww
+ */
+ ureg_MAD( ureg,
+ ureg_writemask(wpos_temp, TGSI_WRITEMASK_Y ),
+ wpos_input,
+ ureg_scalar(wpostrans, 2),
+ ureg_scalar(wpostrans, 3));
+ }
/* Use wpos_temp as position input from here on:
*/
@@ -861,8 +875,7 @@ emit_wpos(struct st_context *st,
/* we invert after adjustment so that we avoid the MOV to temporary,
* and reuse the adjustment ADD instead */
- if (invert)
- emit_inverted_wpos(t, program);
+ emit_wpos_inversion(t, program, invert);
}