We don't need the clamped variable, because we can just return early. We should also do the regular culling after the distance culling passes. All spotted by Brian.
Signed-off-by: Zack Rusin <za...@vmware.com> --- src/gallium/auxiliary/draw/draw_pipe_cull.c | 79 ++++++++++++--------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_pipe_cull.c b/src/gallium/auxiliary/draw/draw_pipe_cull.c index 50a25e3..dd9965f 100644 --- a/src/gallium/auxiliary/draw/draw_pipe_cull.c +++ b/src/gallium/auxiliary/draw/draw_pipe_cull.c @@ -51,10 +51,10 @@ static INLINE struct cull_stage *cull_stage( struct draw_stage *stage ) return (struct cull_stage *)stage; } -static INLINE -boolean cull_distance_is_out(float dist) +static INLINE boolean +cull_distance_is_out(float dist) { - return (dist < 0) || util_is_inf_or_nan(dist); + return (dist < 0.0f) || util_is_inf_or_nan(dist); } /* @@ -68,23 +68,21 @@ static void cull_point( struct draw_stage *stage, { const unsigned num_written_culldistances = draw_current_shader_num_written_culldistances(stage->draw); - - if (num_written_culldistances) { - unsigned i; - boolean culled = FALSE; - for (i = 0; i < num_written_culldistances; ++i) { - unsigned cull_idx = i / 4; - unsigned out_idx = - draw_current_shader_culldistance_output(stage->draw, cull_idx); - unsigned idx = i % 4; - float cull1 = header->v[0]->data[out_idx][idx]; - boolean vert1_out = cull_distance_is_out(cull1); - if (vert1_out) - culled = TRUE; - } - if (!culled) - stage->next->point( stage->next, header ); + unsigned i; + + debug_assert(num_written_culldistances); + + for (i = 0; i < num_written_culldistances; ++i) { + unsigned cull_idx = i / 4; + unsigned out_idx = + draw_current_shader_culldistance_output(stage->draw, cull_idx); + unsigned idx = i % 4; + float cull1 = header->v[0]->data[out_idx][idx]; + boolean vert1_out = cull_distance_is_out(cull1); + if (vert1_out) + return; } + stage->next->point( stage->next, header ); } /* @@ -94,29 +92,27 @@ static void cull_point( struct draw_stage *stage, * on primitives without faces (e.g. points and lines) */ static void cull_line( struct draw_stage *stage, - struct prim_header *header ) + struct prim_header *header ) { const unsigned num_written_culldistances = - draw_current_shader_num_written_culldistances(stage->draw); - - if (num_written_culldistances) { - unsigned i; - boolean culled = FALSE; - for (i = 0; i < num_written_culldistances; ++i) { - unsigned cull_idx = i / 4; - unsigned out_idx = - draw_current_shader_culldistance_output(stage->draw, cull_idx); - unsigned idx = i % 4; - float cull1 = header->v[0]->data[out_idx][idx]; - float cull2 = header->v[1]->data[out_idx][idx]; - boolean vert1_out = cull_distance_is_out(cull1); - boolean vert2_out = cull_distance_is_out(cull2); - if (vert1_out && vert2_out) - culled = TRUE; - } - if (!culled) - stage->next->line( stage->next, header ); + draw_current_shader_num_written_culldistances(stage->draw); + unsigned i; + + debug_assert(num_written_culldistances); + + for (i = 0; i < num_written_culldistances; ++i) { + unsigned cull_idx = i / 4; + unsigned out_idx = + draw_current_shader_culldistance_output(stage->draw, cull_idx); + unsigned idx = i % 4; + float cull1 = header->v[0]->data[out_idx][idx]; + float cull2 = header->v[1]->data[out_idx][idx]; + boolean vert1_out = cull_distance_is_out(cull1); + boolean vert2_out = cull_distance_is_out(cull2); + if (vert1_out && vert2_out) + return; } + stage->next->line( stage->next, header ); } /* @@ -133,7 +129,6 @@ static void cull_tri( struct draw_stage *stage, /* Do the distance culling */ if (num_written_culldistances) { unsigned i; - boolean culled = FALSE; for (i = 0; i < num_written_culldistances; ++i) { unsigned cull_idx = i / 4; unsigned out_idx = @@ -146,10 +141,8 @@ static void cull_tri( struct draw_stage *stage, boolean vert2_out = cull_distance_is_out(cull2); boolean vert3_out = cull_distance_is_out(cull3); if (vert1_out && vert2_out && vert3_out) - culled = TRUE; + return; } - if (!culled) - stage->next->tri( stage->next, header ); } /* Do the regular face culling */ -- 1.7.10.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev