llvmpipe: Obey rasterization rules.

Replicates softpipe.
This commit is contained in:
José Fonseca 2010-03-13 11:22:39 +00:00
parent 3160cbabcc
commit a80e33f407
5 changed files with 40 additions and 30 deletions

View File

@ -337,7 +337,8 @@ void
lp_setup_set_triangle_state( struct lp_setup_context *setup, lp_setup_set_triangle_state( struct lp_setup_context *setup,
unsigned cull_mode, unsigned cull_mode,
boolean ccw_is_frontface, boolean ccw_is_frontface,
boolean scissor ) boolean scissor,
boolean gl_rasterization_rules)
{ {
LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__); LP_DBG(DEBUG_SETUP, "%s\n", __FUNCTION__);
@ -345,6 +346,7 @@ lp_setup_set_triangle_state( struct lp_setup_context *setup,
setup->cullmode = cull_mode; setup->cullmode = cull_mode;
setup->triangle = first_triangle; setup->triangle = first_triangle;
setup->scissor_test = scissor; setup->scissor_test = scissor;
setup->pixel_offset = gl_rasterization_rules ? 0.5f : 0.0f;
} }

View File

@ -89,7 +89,8 @@ void
lp_setup_set_triangle_state( struct lp_setup_context *setup, lp_setup_set_triangle_state( struct lp_setup_context *setup,
unsigned cullmode, unsigned cullmode,
boolean front_is_ccw, boolean front_is_ccw,
boolean scissor ); boolean scissor,
boolean gl_rasterization_rules );
void void
lp_setup_set_fs_inputs( struct lp_setup_context *setup, lp_setup_set_fs_inputs( struct lp_setup_context *setup,

View File

@ -89,6 +89,7 @@ struct lp_setup_context
boolean ccw_is_frontface; boolean ccw_is_frontface;
boolean scissor_test; boolean scissor_test;
unsigned cullmode; unsigned cullmode;
float pixel_offset;
struct pipe_framebuffer_state fb; struct pipe_framebuffer_state fb;

View File

@ -41,7 +41,8 @@
/** /**
* Compute a0 for a constant-valued coefficient (GL_FLAT shading). * Compute a0 for a constant-valued coefficient (GL_FLAT shading).
*/ */
static void constant_coef( struct lp_rast_triangle *tri, static void constant_coef( struct lp_setup_context *setup,
struct lp_rast_triangle *tri,
unsigned slot, unsigned slot,
const float value, const float value,
unsigned i ) unsigned i )
@ -56,7 +57,8 @@ static void constant_coef( struct lp_rast_triangle *tri,
* Compute a0, dadx and dady for a linearly interpolated coefficient, * Compute a0, dadx and dady for a linearly interpolated coefficient,
* for a triangle. * for a triangle.
*/ */
static void linear_coef( struct lp_rast_triangle *tri, static void linear_coef( struct lp_setup_context *setup,
struct lp_rast_triangle *tri,
float oneoverarea, float oneoverarea,
unsigned slot, unsigned slot,
const float (*v1)[4], const float (*v1)[4],
@ -90,8 +92,8 @@ static void linear_coef( struct lp_rast_triangle *tri,
* instead - i'll switch to this later. * instead - i'll switch to this later.
*/ */
tri->inputs.a0[slot][i] = (a1 - tri->inputs.a0[slot][i] = (a1 -
(dadx * (v1[0][0] - 0.5f) + (dadx * (v1[0][0] - setup->pixel_offset) +
dady * (v1[0][1] - 0.5f))); dady * (v1[0][1] - setup->pixel_offset)));
} }
@ -103,7 +105,8 @@ static void linear_coef( struct lp_rast_triangle *tri,
* Later, when we compute the value at a particular fragment position we'll * Later, when we compute the value at a particular fragment position we'll
* divide the interpolated value by the interpolated W at that fragment. * divide the interpolated value by the interpolated W at that fragment.
*/ */
static void perspective_coef( struct lp_rast_triangle *tri, static void perspective_coef( struct lp_setup_context *setup,
struct lp_rast_triangle *tri,
float oneoverarea, float oneoverarea,
unsigned slot, unsigned slot,
const float (*v1)[4], const float (*v1)[4],
@ -125,8 +128,8 @@ static void perspective_coef( struct lp_rast_triangle *tri,
tri->inputs.dadx[slot][i] = dadx; tri->inputs.dadx[slot][i] = dadx;
tri->inputs.dady[slot][i] = dady; tri->inputs.dady[slot][i] = dady;
tri->inputs.a0[slot][i] = (a1 - tri->inputs.a0[slot][i] = (a1 -
(dadx * (v1[0][0] - 0.5f) + (dadx * (v1[0][0] - setup->pixel_offset) +
dady * (v1[0][1] - 0.5f))); dady * (v1[0][1] - setup->pixel_offset)));
} }
@ -137,7 +140,8 @@ static void perspective_coef( struct lp_rast_triangle *tri,
* We could do a bit less work if we'd examine gl_FragCoord's swizzle mask. * We could do a bit less work if we'd examine gl_FragCoord's swizzle mask.
*/ */
static void static void
setup_fragcoord_coef(struct lp_rast_triangle *tri, setup_fragcoord_coef(struct lp_setup_context *setup,
struct lp_rast_triangle *tri,
float oneoverarea, float oneoverarea,
unsigned slot, unsigned slot,
const float (*v1)[4], const float (*v1)[4],
@ -153,20 +157,21 @@ setup_fragcoord_coef(struct lp_rast_triangle *tri,
tri->inputs.dadx[slot][1] = 0.0; tri->inputs.dadx[slot][1] = 0.0;
tri->inputs.dady[slot][1] = 1.0; tri->inputs.dady[slot][1] = 1.0;
/*Z*/ /*Z*/
linear_coef(tri, oneoverarea, slot, v1, v2, v3, 0, 2); linear_coef(setup, tri, oneoverarea, slot, v1, v2, v3, 0, 2);
/*W*/ /*W*/
linear_coef(tri, oneoverarea, slot, v1, v2, v3, 0, 3); linear_coef(setup, tri, oneoverarea, slot, v1, v2, v3, 0, 3);
} }
static void setup_facing_coef( struct lp_rast_triangle *tri, static void setup_facing_coef( struct lp_setup_context *setup,
struct lp_rast_triangle *tri,
unsigned slot, unsigned slot,
boolean frontface ) boolean frontface )
{ {
constant_coef( tri, slot, 1.0f - frontface, 0 ); constant_coef( setup, tri, slot, 1.0f - frontface, 0 );
constant_coef( tri, slot, 0.0f, 1 ); /* wasted */ constant_coef( setup, tri, slot, 0.0f, 1 ); /* wasted */
constant_coef( tri, slot, 0.0f, 2 ); /* wasted */ constant_coef( setup, tri, slot, 0.0f, 2 ); /* wasted */
constant_coef( tri, slot, 0.0f, 3 ); /* wasted */ constant_coef( setup, tri, slot, 0.0f, 3 ); /* wasted */
} }
@ -185,7 +190,7 @@ static void setup_tri_coefficients( struct lp_setup_context *setup,
/* The internal position input is in slot zero: /* The internal position input is in slot zero:
*/ */
setup_fragcoord_coef(tri, oneoverarea, 0, v1, v2, v3); setup_fragcoord_coef(setup, tri, oneoverarea, 0, v1, v2, v3);
/* setup interpolation for all the remaining attributes: /* setup interpolation for all the remaining attributes:
*/ */
@ -196,27 +201,27 @@ static void setup_tri_coefficients( struct lp_setup_context *setup,
switch (setup->fs.input[slot].interp) { switch (setup->fs.input[slot].interp) {
case LP_INTERP_CONSTANT: case LP_INTERP_CONSTANT:
for (i = 0; i < NUM_CHANNELS; i++) for (i = 0; i < NUM_CHANNELS; i++)
constant_coef(tri, slot+1, v3[vert_attr][i], i); constant_coef(setup, tri, slot+1, v3[vert_attr][i], i);
break; break;
case LP_INTERP_LINEAR: case LP_INTERP_LINEAR:
for (i = 0; i < NUM_CHANNELS; i++) for (i = 0; i < NUM_CHANNELS; i++)
linear_coef(tri, oneoverarea, slot+1, v1, v2, v3, vert_attr, i); linear_coef(setup, tri, oneoverarea, slot+1, v1, v2, v3, vert_attr, i);
break; break;
case LP_INTERP_PERSPECTIVE: case LP_INTERP_PERSPECTIVE:
for (i = 0; i < NUM_CHANNELS; i++) for (i = 0; i < NUM_CHANNELS; i++)
perspective_coef(tri, oneoverarea, slot+1, v1, v2, v3, vert_attr, i); perspective_coef(setup, tri, oneoverarea, slot+1, v1, v2, v3, vert_attr, i);
break; break;
case LP_INTERP_POSITION: case LP_INTERP_POSITION:
/* XXX: fix me - duplicates the values in slot zero. /* XXX: fix me - duplicates the values in slot zero.
*/ */
setup_fragcoord_coef(tri, oneoverarea, slot+1, v1, v2, v3); setup_fragcoord_coef(setup, tri, oneoverarea, slot+1, v1, v2, v3);
break; break;
case LP_INTERP_FACING: case LP_INTERP_FACING:
setup_facing_coef(tri, slot+1, frontface); setup_facing_coef(setup, tri, slot+1, frontface);
break; break;
default: default:
@ -281,12 +286,12 @@ do_triangle_ccw(struct lp_setup_context *setup,
boolean frontfacing ) boolean frontfacing )
{ {
/* x/y positions in fixed point */ /* x/y positions in fixed point */
const int x1 = subpixel_snap(v1[0][0]); const int x1 = subpixel_snap(v1[0][0] + 0.5 - setup->pixel_offset);
const int x2 = subpixel_snap(v2[0][0]); const int x2 = subpixel_snap(v2[0][0] + 0.5 - setup->pixel_offset);
const int x3 = subpixel_snap(v3[0][0]); const int x3 = subpixel_snap(v3[0][0] + 0.5 - setup->pixel_offset);
const int y1 = subpixel_snap(v1[0][1]); const int y1 = subpixel_snap(v1[0][1] + 0.5 - setup->pixel_offset);
const int y2 = subpixel_snap(v2[0][1]); const int y2 = subpixel_snap(v2[0][1] + 0.5 - setup->pixel_offset);
const int y3 = subpixel_snap(v3[0][1]); const int y3 = subpixel_snap(v3[0][1] + 0.5 - setup->pixel_offset);
struct lp_scene *scene = lp_setup_get_current_scene(setup); struct lp_scene *scene = lp_setup_get_current_scene(setup);
struct lp_rast_triangle *tri; struct lp_rast_triangle *tri;

View File

@ -62,7 +62,8 @@ void llvmpipe_bind_rasterizer_state(struct pipe_context *pipe,
lp_setup_set_triangle_state( llvmpipe->setup, lp_setup_set_triangle_state( llvmpipe->setup,
llvmpipe->rasterizer->cull_mode, llvmpipe->rasterizer->cull_mode,
llvmpipe->rasterizer->front_winding == PIPE_WINDING_CCW, llvmpipe->rasterizer->front_winding == PIPE_WINDING_CCW,
llvmpipe->rasterizer->scissor); llvmpipe->rasterizer->scissor,
llvmpipe->rasterizer->gl_rasterization_rules);
} }
llvmpipe->dirty |= LP_NEW_RASTERIZER; llvmpipe->dirty |= LP_NEW_RASTERIZER;