draw_pt_vcache.c File Reference

Include dependency graph for draw_pt_vcache.c:

Go to the source code of this file.

Data Structures

struct  vcache_frontend

Defines

#define CACHE_MAX   256
#define FETCH_MAX   256
#define DRAW_MAX   (16*1024)
#define TRIANGLE(vc, flags, i0, i1, i2)   vcache_triangle_flags(vc,flags,i0,i1,i2)
#define QUAD(vc, i0, i1, i2, i3)   vcache_ef_quad(vc,i0,i1,i2,i3)
#define LINE(vc, flags, i0, i1)   vcache_line_flags(vc,flags,i0,i1)
#define POINT(vc, i0)   vcache_point(vc,i0)
#define FUNC   vcache_run_extras
#define TRIANGLE(vc, flags, i0, i1, i2)   vcache_triangle(vc,i0,i1,i2)
#define QUAD(vc, i0, i1, i2, i3)   vcache_quad(vc,i0,i1,i2,i3)
#define LINE(vc, flags, i0, i1)   vcache_line(vc,i0,i1)
#define POINT(vc, i0)   vcache_point(vc,i0)
#define FUNC   vcache_run

Functions

static void vcache_flush (struct vcache_frontend *vcache)
static void vcache_check_flush (struct vcache_frontend *vcache)
static void vcache_elt (struct vcache_frontend *vcache, unsigned felt, ushort flags)
static void vcache_triangle (struct vcache_frontend *vcache, unsigned i0, unsigned i1, unsigned i2)
static void vcache_triangle_flags (struct vcache_frontend *vcache, ushort flags, unsigned i0, unsigned i1, unsigned i2)
static void vcache_line (struct vcache_frontend *vcache, unsigned i0, unsigned i1)
static void vcache_line_flags (struct vcache_frontend *vcache, ushort flags, unsigned i0, unsigned i1)
static void vcache_point (struct vcache_frontend *vcache, unsigned i0)
static void vcache_quad (struct vcache_frontend *vcache, unsigned i0, unsigned i1, unsigned i2, unsigned i3)
static void vcache_ef_quad (struct vcache_frontend *vcache, unsigned i0, unsigned i1, unsigned i2, unsigned i3)
static void rebase_uint_elts (const unsigned *src, unsigned count, int delta, ushort *dest)
static void rebase_ushort_elts (const ushort *src, unsigned count, int delta, ushort *dest)
static void rebase_ubyte_elts (const ubyte *src, unsigned count, int delta, ushort *dest)
static void translate_uint_elts (const unsigned *src, unsigned count, ushort *dest)
static void translate_ushort_elts (const ushort *src, unsigned count, ushort *dest)
static void translate_ubyte_elts (const ubyte *src, unsigned count, ushort *dest)
static void vcache_check_run (struct draw_pt_front_end *frontend, pt_elt_func get_elt, const void *elts, unsigned draw_count)
static void vcache_prepare (struct draw_pt_front_end *frontend, unsigned prim, struct draw_pt_middle_end *middle, unsigned opt)
static void vcache_finish (struct draw_pt_front_end *frontend)
static void vcache_destroy (struct draw_pt_front_end *frontend)
struct draw_pt_front_enddraw_pt_vcache (struct draw_context *draw)


Define Documentation

#define CACHE_MAX   256

Definition at line 39 of file draw_pt_vcache.c.

#define DRAW_MAX   (16*1024)

Definition at line 41 of file draw_pt_vcache.c.

#define FETCH_MAX   256

Definition at line 40 of file draw_pt_vcache.c.

#define FUNC   vcache_run

Definition at line 223 of file draw_pt_vcache.c.

#define FUNC   vcache_run_extras

Definition at line 223 of file draw_pt_vcache.c.

#define LINE ( vc,
flags,
i0,
i1   )     vcache_line(vc,i0,i1)

Definition at line 221 of file draw_pt_vcache.c.

#define LINE ( vc,
flags,
i0,
i1   )     vcache_line_flags(vc,flags,i0,i1)

Definition at line 221 of file draw_pt_vcache.c.

#define POINT ( vc,
i0   )     vcache_point(vc,i0)

Definition at line 222 of file draw_pt_vcache.c.

#define POINT ( vc,
i0   )     vcache_point(vc,i0)

Definition at line 222 of file draw_pt_vcache.c.

#define QUAD ( vc,
i0,
i1,
i2,
i3   )     vcache_quad(vc,i0,i1,i2,i3)

Definition at line 220 of file draw_pt_vcache.c.

#define QUAD ( vc,
i0,
i1,
i2,
i3   )     vcache_ef_quad(vc,i0,i1,i2,i3)

Definition at line 220 of file draw_pt_vcache.c.

#define TRIANGLE ( vc,
flags,
i0,
i1,
i2   )     vcache_triangle(vc,i0,i1,i2)

Definition at line 219 of file draw_pt_vcache.c.

#define TRIANGLE ( vc,
flags,
i0,
i1,
i2   )     vcache_triangle_flags(vc,flags,i0,i1,i2)

Definition at line 219 of file draw_pt_vcache.c.


Function Documentation

struct draw_pt_front_end* draw_pt_vcache ( struct draw_context draw  )  [read]

Definition at line 485 of file draw_pt_vcache.c.

References vcache_frontend::base, CALLOC_STRUCT, draw_pt_front_end::destroy, vcache_frontend::draw, draw_pt_front_end::finish, vcache_frontend::in, draw_pt_front_end::prepare, draw_pt_front_end::run, vcache_destroy(), vcache_finish(), and vcache_prepare().

00486 {
00487    struct vcache_frontend *vcache = CALLOC_STRUCT( vcache_frontend );
00488    if (vcache == NULL)
00489       return NULL;
00490  
00491    vcache->base.prepare = vcache_prepare;
00492    vcache->base.run     = NULL;
00493    vcache->base.finish  = vcache_finish;
00494    vcache->base.destroy = vcache_destroy;
00495    vcache->draw = draw;
00496    
00497    memset(vcache->in, ~0, sizeof(vcache->in));
00498   
00499    return &vcache->base;
00500 }

static void rebase_ubyte_elts ( const ubyte src,
unsigned  count,
int  delta,
ushort dest 
) [static]

Definition at line 251 of file draw_pt_vcache.c.

00255 {
00256    unsigned i;
00257 
00258    for (i = 0; i < count; i++) 
00259       dest[i] = (ushort)(src[i] + delta);
00260 }

static void rebase_uint_elts ( const unsigned *  src,
unsigned  count,
int  delta,
ushort dest 
) [static]

Definition at line 227 of file draw_pt_vcache.c.

00231 {
00232    unsigned i;
00233 
00234    for (i = 0; i < count; i++) 
00235       dest[i] = (ushort)(src[i] + delta);
00236 }

static void rebase_ushort_elts ( const ushort src,
unsigned  count,
int  delta,
ushort dest 
) [static]

Definition at line 239 of file draw_pt_vcache.c.

00243 {
00244    unsigned i;
00245 
00246    for (i = 0; i < count; i++) 
00247       dest[i] = (ushort)(src[i] + delta);
00248 }

static void translate_ubyte_elts ( const ubyte src,
unsigned  count,
ushort dest 
) [static]

Definition at line 287 of file draw_pt_vcache.c.

00290 {
00291    unsigned i;
00292 
00293    for (i = 0; i < count; i++) 
00294       dest[i] = (ushort)(src[i]);
00295 }

static void translate_uint_elts ( const unsigned *  src,
unsigned  count,
ushort dest 
) [static]

Definition at line 265 of file draw_pt_vcache.c.

00268 {
00269    unsigned i;
00270 
00271    for (i = 0; i < count; i++) 
00272       dest[i] = (ushort)(src[i]);
00273 }

static void translate_ushort_elts ( const ushort src,
unsigned  count,
ushort dest 
) [static]

Definition at line 276 of file draw_pt_vcache.c.

00279 {
00280    unsigned i;
00281 
00282    for (i = 0; i < count; i++) 
00283       dest[i] = (ushort)(src[i]);
00284 }

static void vcache_check_flush ( struct vcache_frontend vcache  )  [static]

Definition at line 91 of file draw_pt_vcache.c.

References vcache_frontend::draw_count, DRAW_MAX, vcache_frontend::fetch_count, FETCH_MAX, and vcache_flush().

00092 {
00093    if ( vcache->draw_count + 6 >= DRAW_MAX ||
00094         vcache->fetch_count + 4 >= FETCH_MAX )
00095    {
00096       vcache_flush( vcache );
00097    }
00098 }

static void vcache_check_run ( struct draw_pt_front_end frontend,
pt_elt_func  get_elt,
const void *  elts,
unsigned  draw_count 
) [static]

Definition at line 314 of file draw_pt_vcache.c.

References assert, debug_printf(), vcache_frontend::draw, draw, vcache_frontend::fetch_max, FREE, vcache_frontend::input_prim, MALLOC, draw_context::max_index, vcache_frontend::middle, vcache_frontend::middle_prim, draw_context::min_index, vcache_frontend::opt, draw_pt_middle_end::prepare, draw_context::pt, rebase_ubyte_elts(), rebase_uint_elts(), rebase_ushort_elts(), draw_pt_middle_end::run_linear_elts, translate_ubyte_elts(), translate_uint_elts(), translate_ushort_elts(), and draw_context::user.

00318 {
00319    struct vcache_frontend *vcache = (struct vcache_frontend *)frontend; 
00320    struct draw_context *draw = vcache->draw;
00321    unsigned min_index = draw->pt.user.min_index;
00322    unsigned max_index = draw->pt.user.max_index;
00323    unsigned index_size = draw->pt.user.eltSize;
00324    unsigned fetch_count = max_index + 1 - min_index;
00325    const ushort *transformed_elts;
00326    ushort *storage = NULL;
00327    boolean ok;
00328 
00329 
00330    if (0) debug_printf("fetch_count %d fetch_max %d draw_count %d\n", fetch_count, 
00331                        vcache->fetch_max,
00332                        draw_count);
00333       
00334    if (max_index == 0xffffffff ||
00335        fetch_count > draw_count) {
00336       if (0) debug_printf("fail\n");
00337       goto fail;
00338    }
00339       
00340    if (vcache->middle_prim != vcache->input_prim) {
00341       vcache->middle_prim = vcache->input_prim;
00342       vcache->middle->prepare( vcache->middle, 
00343                                vcache->middle_prim, 
00344                                vcache->opt, 
00345                                &vcache->fetch_max );
00346    }
00347 
00348 
00349    if (min_index == 0 &&
00350        index_size == 2) 
00351    {
00352       transformed_elts = (const ushort *)elts;
00353    }
00354    else 
00355    {
00356       storage = MALLOC( draw_count * sizeof(ushort) );
00357       if (!storage)
00358          goto fail;
00359       
00360       if (min_index == 0) {
00361          switch(index_size) {
00362          case 1:
00363             translate_ubyte_elts( (const ubyte *)elts,
00364                                   draw_count,
00365                                   storage );
00366             break;
00367 
00368          case 2:
00369             translate_ushort_elts( (const ushort *)elts,
00370                                    draw_count,
00371                                    storage );
00372             break;
00373 
00374          case 4:
00375             translate_uint_elts( (const uint *)elts,
00376                                  draw_count,
00377                                  storage );
00378             break;
00379 
00380          default:
00381             assert(0);
00382             return;
00383          }
00384       }
00385       else {
00386          switch(index_size) {
00387          case 1:
00388             rebase_ubyte_elts( (const ubyte *)elts,
00389                                   draw_count,
00390                                   0 - (int)min_index,
00391                                   storage );
00392             break;
00393 
00394          case 2:
00395             rebase_ushort_elts( (const ushort *)elts,
00396                                    draw_count,
00397                                    0 - (int)min_index,
00398                                    storage );
00399             break;
00400 
00401          case 4:
00402             rebase_uint_elts( (const uint *)elts,
00403                                  draw_count,
00404                                  0 - (int)min_index,
00405                                  storage );
00406             break;
00407 
00408          default:
00409             assert(0);
00410             return;
00411          }
00412       }
00413       transformed_elts = storage;
00414    }
00415 
00416    ok = vcache->middle->run_linear_elts( vcache->middle,
00417                                          min_index, /* start */
00418                                          fetch_count,
00419                                          transformed_elts,
00420                                          draw_count );
00421    
00422    FREE(storage);
00423 
00424    if (ok)
00425       return;
00426 
00427    debug_printf("failed to execute atomic draw elts for %d/%d, splitting up\n",
00428                 fetch_count, draw_count);
00429 
00430  fail:
00431    vcache_run( frontend, get_elt, elts, draw_count );
00432 }

static void vcache_destroy ( struct draw_pt_front_end frontend  )  [static]

Definition at line 479 of file draw_pt_vcache.c.

References FREE.

00480 {
00481    FREE(frontend);
00482 }

static void vcache_ef_quad ( struct vcache_frontend vcache,
unsigned  i0,
unsigned  i1,
unsigned  i2,
unsigned  i3 
) [static]

Definition at line 190 of file draw_pt_vcache.c.

References DRAW_PIPE_EDGE_FLAG_0, DRAW_PIPE_EDGE_FLAG_1, DRAW_PIPE_EDGE_FLAG_2, DRAW_PIPE_RESET_STIPPLE, and vcache_triangle_flags().

00195 {
00196    vcache_triangle_flags( vcache,
00197                           ( DRAW_PIPE_RESET_STIPPLE |
00198                             DRAW_PIPE_EDGE_FLAG_0 |
00199                             DRAW_PIPE_EDGE_FLAG_2 ),
00200                           i0, i1, i3 );
00201 
00202    vcache_triangle_flags( vcache,
00203                           ( DRAW_PIPE_EDGE_FLAG_0 |
00204                             DRAW_PIPE_EDGE_FLAG_1 ),
00205                           i1, i2, i3 );
00206 }

static void vcache_elt ( struct vcache_frontend vcache,
unsigned  felt,
ushort  flags 
) [static]

Definition at line 102 of file draw_pt_vcache.c.

References assert, CACHE_MAX, vcache_frontend::draw_count, vcache_frontend::draw_elts, vcache_frontend::fetch_count, vcache_frontend::fetch_elts, FETCH_MAX, vcache_frontend::in, and vcache_frontend::out.

00105 {
00106    unsigned idx = felt % CACHE_MAX;
00107 
00108    if (vcache->in[idx] != felt) {
00109       assert(vcache->fetch_count < FETCH_MAX);
00110 
00111       vcache->in[idx] = felt;
00112       vcache->out[idx] = (ushort)vcache->fetch_count;
00113       vcache->fetch_elts[vcache->fetch_count++] = felt;
00114    }
00115 
00116    vcache->draw_elts[vcache->draw_count++] = vcache->out[idx] | flags;
00117 }

static void vcache_finish ( struct draw_pt_front_end frontend  )  [static]

Definition at line 471 of file draw_pt_vcache.c.

References draw_pt_middle_end::finish, and vcache_frontend::middle.

00472 {
00473    struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
00474    vcache->middle->finish( vcache->middle );
00475    vcache->middle = NULL;
00476 }

static void vcache_flush ( struct vcache_frontend vcache  )  [static]

Definition at line 67 of file draw_pt_vcache.c.

References vcache_frontend::draw_count, vcache_frontend::draw_elts, vcache_frontend::fetch_count, vcache_frontend::fetch_elts, vcache_frontend::fetch_max, vcache_frontend::in, vcache_frontend::middle, vcache_frontend::middle_prim, vcache_frontend::opt, vcache_frontend::output_prim, draw_pt_middle_end::prepare, and draw_pt_middle_end::run.

00068 {
00069    if (vcache->middle_prim != vcache->output_prim) {
00070       vcache->middle_prim = vcache->output_prim;
00071       vcache->middle->prepare( vcache->middle, 
00072                                vcache->middle_prim, 
00073                                vcache->opt, 
00074                                &vcache->fetch_max );
00075    }
00076 
00077    if (vcache->draw_count) {
00078       vcache->middle->run( vcache->middle,
00079                            vcache->fetch_elts,
00080                            vcache->fetch_count,
00081                            vcache->draw_elts,
00082                            vcache->draw_count );
00083    }
00084 
00085    memset(vcache->in, ~0, sizeof(vcache->in));
00086    vcache->fetch_count = 0;
00087    vcache->draw_count = 0;
00088 }

static void vcache_line ( struct vcache_frontend vcache,
unsigned  i0,
unsigned  i1 
) [static]

Definition at line 148 of file draw_pt_vcache.c.

References vcache_check_flush(), and vcache_elt().

00151 {
00152    vcache_elt(vcache, i0, 0);
00153    vcache_elt(vcache, i1, 0);
00154    vcache_check_flush(vcache);
00155 }

static void vcache_line_flags ( struct vcache_frontend vcache,
ushort  flags,
unsigned  i0,
unsigned  i1 
) [static]

Definition at line 159 of file draw_pt_vcache.c.

References vcache_check_flush(), and vcache_elt().

00163 {
00164    vcache_elt(vcache, i0, flags);
00165    vcache_elt(vcache, i1, 0);
00166    vcache_check_flush(vcache);
00167 }

static void vcache_point ( struct vcache_frontend vcache,
unsigned  i0 
) [static]

Definition at line 171 of file draw_pt_vcache.c.

References vcache_check_flush(), and vcache_elt().

00173 {
00174    vcache_elt(vcache, i0, 0);
00175    vcache_check_flush(vcache);
00176 }

static void vcache_prepare ( struct draw_pt_front_end frontend,
unsigned  prim,
struct draw_pt_middle_end middle,
unsigned  opt 
) [static]

Definition at line 438 of file draw_pt_vcache.c.

References vcache_frontend::base, draw_pt_reduced_prim(), vcache_frontend::fetch_max, vcache_frontend::input_prim, vcache_frontend::middle, vcache_frontend::middle_prim, vcache_frontend::opt, vcache_frontend::output_prim, draw_pt_middle_end::prepare, PT_PIPELINE, draw_pt_front_end::run, and vcache_check_run().

00442 {
00443    struct vcache_frontend *vcache = (struct vcache_frontend *)frontend;
00444 
00445    if (opt & PT_PIPELINE)
00446    {
00447       vcache->base.run = vcache_run_extras;
00448    }
00449    else 
00450    {
00451       vcache->base.run = vcache_check_run;
00452    }
00453 
00454    vcache->input_prim = prim;
00455    vcache->output_prim = draw_pt_reduced_prim(prim);
00456 
00457    vcache->middle = middle;
00458    vcache->opt = opt;
00459 
00460    /* Have to run prepare here, but try and guess a good prim for
00461     * doing so:
00462     */
00463    vcache->middle_prim = (opt & PT_PIPELINE) ? vcache->output_prim : vcache->input_prim;
00464    middle->prepare( middle, vcache->middle_prim, opt, &vcache->fetch_max );
00465 }

static void vcache_quad ( struct vcache_frontend vcache,
unsigned  i0,
unsigned  i1,
unsigned  i2,
unsigned  i3 
) [static]

Definition at line 179 of file draw_pt_vcache.c.

References vcache_triangle().

00184 {
00185    vcache_triangle( vcache, i0, i1, i3 );
00186    vcache_triangle( vcache, i1, i2, i3 );
00187 }

static void vcache_triangle ( struct vcache_frontend vcache,
unsigned  i0,
unsigned  i1,
unsigned  i2 
) [static]

Definition at line 122 of file draw_pt_vcache.c.

References vcache_check_flush(), and vcache_elt().

00126 {
00127    vcache_elt(vcache, i0, 0);
00128    vcache_elt(vcache, i1, 0);
00129    vcache_elt(vcache, i2, 0);
00130    vcache_check_flush(vcache);
00131 }

static void vcache_triangle_flags ( struct vcache_frontend vcache,
ushort  flags,
unsigned  i0,
unsigned  i1,
unsigned  i2 
) [static]

Definition at line 135 of file draw_pt_vcache.c.

References vcache_check_flush(), and vcache_elt().

00140 {
00141    vcache_elt(vcache, i0, flags);
00142    vcache_elt(vcache, i1, 0);
00143    vcache_elt(vcache, i2, 0);
00144    vcache_check_flush(vcache);
00145 }


Generated on Tue Sep 29 06:25:21 2009 for Gallium3D by  doxygen 1.5.4