draw_vs_varient.c File Reference

Include dependency graph for draw_vs_varient.c:

Go to the source code of this file.

Data Structures

struct  draw_vs_varient_generic

Functions

static void vsvg_set_buffer (struct draw_vs_varient *varient, unsigned buffer, const void *ptr, unsigned stride)
static void do_rhw_viewport (struct draw_vs_varient_generic *vsvg, unsigned count, void *output_buffer)
static void do_viewport (struct draw_vs_varient_generic *vsvg, unsigned count, void *output_buffer)
static void PIPE_CDECL vsvg_run_elts (struct draw_vs_varient *varient, const unsigned *elts, unsigned count, void *output_buffer)
static void PIPE_CDECL vsvg_run_linear (struct draw_vs_varient *varient, unsigned start, unsigned count, void *output_buffer)
static void vsvg_destroy (struct draw_vs_varient *varient)
struct draw_vs_varientdraw_vs_varient_generic (struct draw_vertex_shader *vs, const struct draw_vs_varient_key *key)


Function Documentation

static void do_rhw_viewport ( struct draw_vs_varient_generic vsvg,
unsigned  count,
void *  output_buffer 
) [static]

Definition at line 83 of file draw_vs_varient.c.

References draw_vs_varient_generic::base, draw_vertex_shader::draw, draw_vertex_shader::position_output, pipe_viewport_state::scale, stride(), draw_vs_varient_generic::temp_vertex_stride, pipe_viewport_state::translate, draw_context::viewport, and draw_vs_varient::vs.

00086 {
00087    char *ptr = (char *)output_buffer;
00088    const float *scale = vsvg->base.vs->draw->viewport.scale;
00089    const float *trans = vsvg->base.vs->draw->viewport.translate;
00090    unsigned stride = vsvg->temp_vertex_stride;
00091    unsigned j;
00092 
00093    ptr += vsvg->base.vs->position_output * 4 * sizeof(float);
00094 
00095    for (j = 0; j < count; j++, ptr += stride) {
00096       float *data = (float *)ptr;
00097       float w = 1.0f / data[3];
00098 
00099       data[0] = data[0] * w * scale[0] + trans[0];
00100       data[1] = data[1] * w * scale[1] + trans[1];
00101       data[2] = data[2] * w * scale[2] + trans[2];
00102       data[3] = w;
00103    }
00104 }

static void do_viewport ( struct draw_vs_varient_generic vsvg,
unsigned  count,
void *  output_buffer 
) [static]

Definition at line 106 of file draw_vs_varient.c.

References draw_vs_varient_generic::base, draw_vertex_shader::draw, draw_vertex_shader::position_output, pipe_viewport_state::scale, stride(), draw_vs_varient_generic::temp_vertex_stride, pipe_viewport_state::translate, draw_context::viewport, and draw_vs_varient::vs.

00109 {
00110    char *ptr = (char *)output_buffer;
00111    const float *scale = vsvg->base.vs->draw->viewport.scale;
00112    const float *trans = vsvg->base.vs->draw->viewport.translate;
00113    unsigned stride = vsvg->temp_vertex_stride;
00114    unsigned j;
00115 
00116    ptr += vsvg->base.vs->position_output * 4 * sizeof(float);
00117 
00118    for (j = 0; j < count; j++, ptr += stride) {
00119       float *data = (float *)ptr;
00120 
00121       data[0] = data[0] * scale[0] + trans[0];
00122       data[1] = data[1] * scale[1] + trans[1];
00123       data[2] = data[2] * scale[2] + trans[2];
00124    }
00125 }

struct draw_vs_varient* draw_vs_varient_generic ( struct draw_vertex_shader vs,
const struct draw_vs_varient_key key 
) [read]

Definition at line 256 of file draw_vs_varient.c.

References assert, draw_vs_varient_generic::base, draw_varient_input::buffer, CALLOC_STRUCT, draw_vs_varient::destroy, draw_vertex_shader::draw, draw_vs_varient_generic::draw, draw_translate_vinfo_format(), draw_vs_get_emit(), draw_vs_get_fetch(), draw_vs_varient_key::element, translate_key::element, draw_vs_varient_generic::emit, EMIT_1F_PSIZE, draw_vs_varient_generic::fetch, draw_varient_output::format, draw_varient_input::format, draw_varient_element::in, draw_vertex_shader::info, translate_element::input_buffer, translate_element::input_format, translate_element::input_offset, draw_vs_varient::key, MAX2, translate_key::nr_elements, draw_vs_varient_key::nr_inputs, draw_vs_varient_key::nr_outputs, tgsi_shader_info::num_outputs, draw_varient_output::offset, draw_varient_input::offset, draw_varient_element::out, translate_element::output_format, translate_element::output_offset, draw_vs_varient_key::output_stride, translate_key::output_stride, PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, draw_vs_varient::set_buffer, draw_vs_varient_generic::temp_vertex_stride, draw_vs_varient::vs, draw_varient_output::vs_output, vsvg_destroy(), vsvg_run_elts(), vsvg_run_linear(), and vsvg_set_buffer().

00258 {
00259    unsigned i;
00260    struct translate_key fetch, emit;
00261 
00262    struct draw_vs_varient_generic *vsvg = CALLOC_STRUCT( draw_vs_varient_generic );
00263    if (vsvg == NULL)
00264       return NULL;
00265 
00266    vsvg->base.key = *key;
00267    vsvg->base.vs = vs;
00268    vsvg->base.set_buffer    = vsvg_set_buffer;
00269    vsvg->base.run_elts      = vsvg_run_elts;
00270    vsvg->base.run_linear    = vsvg_run_linear;
00271    vsvg->base.destroy       = vsvg_destroy;
00272 
00273    vsvg->draw = vs->draw;
00274 
00275    vsvg->temp_vertex_stride = MAX2(key->nr_inputs,
00276                                    vsvg->base.vs->info.num_outputs) * 4 * sizeof(float);
00277 
00278    /* Build free-standing fetch and emit functions:
00279     */
00280    fetch.nr_elements = key->nr_inputs;
00281    fetch.output_stride = vsvg->temp_vertex_stride;
00282    for (i = 0; i < key->nr_inputs; i++) {
00283       fetch.element[i].input_format = key->element[i].in.format;
00284       fetch.element[i].input_buffer = key->element[i].in.buffer;
00285       fetch.element[i].input_offset = key->element[i].in.offset;
00286       fetch.element[i].output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
00287       fetch.element[i].output_offset = i * 4 * sizeof(float);
00288       assert(fetch.element[i].output_offset < fetch.output_stride);
00289    }
00290 
00291 
00292    emit.nr_elements = key->nr_outputs;
00293    emit.output_stride = key->output_stride;
00294    for (i = 0; i < key->nr_outputs; i++) {
00295       if (key->element[i].out.format != EMIT_1F_PSIZE)
00296       {      
00297          emit.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
00298          emit.element[i].input_buffer = 0;
00299          emit.element[i].input_offset = key->element[i].out.vs_output * 4 * sizeof(float);
00300          emit.element[i].output_format = draw_translate_vinfo_format(key->element[i].out.format);
00301          emit.element[i].output_offset = key->element[i].out.offset;
00302          assert(emit.element[i].input_offset <= fetch.output_stride);
00303       }
00304       else {
00305          emit.element[i].input_format = PIPE_FORMAT_R32_FLOAT;
00306          emit.element[i].input_buffer = 1;
00307          emit.element[i].input_offset = 0;
00308          emit.element[i].output_format = PIPE_FORMAT_R32_FLOAT;
00309          emit.element[i].output_offset = key->element[i].out.offset;
00310       }
00311    }
00312 
00313    vsvg->fetch = draw_vs_get_fetch( vs->draw, &fetch );
00314    vsvg->emit = draw_vs_get_emit( vs->draw, &emit );
00315 
00316    return &vsvg->base;
00317 }

static void vsvg_destroy ( struct draw_vs_varient varient  )  [static]

Definition at line 250 of file draw_vs_varient.c.

References FREE.

00251 {
00252    FREE(varient);
00253 }

static void PIPE_CDECL vsvg_run_elts ( struct draw_vs_varient varient,
const unsigned *  elts,
unsigned  count,
void *  output_buffer 
) [static]

Definition at line 128 of file draw_vs_varient.c.

References align(), draw_vs_varient_generic::base, draw_vs_varient_key::clip, debug_printf(), do_rhw_viewport(), do_viewport(), draw_vs_varient_generic::draw, draw_vertex_shader::draw, draw_vs_varient_generic::emit, draw_vs_varient_generic::fetch, FREE, draw_vs_varient::key, MALLOC, pipe_rasterizer_state::point_size, draw_context::pt, draw_context::rasterizer, draw_vertex_shader::run_linear, translate::set_buffer, draw_vs_varient_generic::temp_vertex_stride, draw_context::user, draw_vs_varient_key::viewport, and draw_vs_varient::vs.

00132 {
00133    struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
00134    unsigned temp_vertex_stride = vsvg->temp_vertex_stride;
00135    void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride );
00136    
00137    if (0) debug_printf("%s %d \n", __FUNCTION__,  count);
00138                         
00139    /* Want to do this in small batches for cache locality?
00140     */
00141    
00142    vsvg->fetch->run_elts( vsvg->fetch, 
00143                           elts,
00144                           count,
00145                           temp_buffer );
00146 
00147    vsvg->base.vs->run_linear( vsvg->base.vs, 
00148                               temp_buffer,
00149                               temp_buffer,
00150                               (const float (*)[4])vsvg->base.vs->draw->pt.user.constants,
00151                               count,
00152                               temp_vertex_stride, 
00153                               temp_vertex_stride);
00154 
00155 
00156    if (vsvg->base.key.clip) {
00157       /* not really handling clipping, just do the rhw so we can
00158        * see the results...
00159        */
00160       do_rhw_viewport( vsvg,
00161                        count,
00162                        temp_buffer );
00163    }
00164    else if (vsvg->base.key.viewport) {
00165       do_viewport( vsvg,
00166                    count,
00167                    temp_buffer );
00168    }
00169 
00170 
00171    vsvg->emit->set_buffer( vsvg->emit,
00172                            0, 
00173                            temp_buffer,
00174                            temp_vertex_stride );
00175 
00176    vsvg->emit->set_buffer( vsvg->emit, 
00177                            1,
00178                            &vsvg->draw->rasterizer->point_size,
00179                            0);
00180 
00181    vsvg->emit->run( vsvg->emit,
00182                     0, count,
00183                     output_buffer );
00184 
00185    FREE(temp_buffer);
00186 }

static void PIPE_CDECL vsvg_run_linear ( struct draw_vs_varient varient,
unsigned  start,
unsigned  count,
void *  output_buffer 
) [static]

Definition at line 189 of file draw_vs_varient.c.

References align(), draw_vs_varient_generic::base, draw_vs_varient_key::clip, debug_printf(), do_rhw_viewport(), do_viewport(), draw_vs_varient_generic::draw, draw_vertex_shader::draw, draw_vs_varient_generic::emit, draw_vs_varient_generic::fetch, FREE, draw_vs_varient::key, MALLOC, draw_vs_varient_key::output_stride, pipe_rasterizer_state::point_size, draw_context::pt, draw_context::rasterizer, draw_vertex_shader::run_linear, translate::set_buffer, draw_vs_varient_generic::temp_vertex_stride, draw_context::user, draw_vs_varient_key::viewport, and draw_vs_varient::vs.

00193 {
00194    struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
00195    unsigned temp_vertex_stride = vsvg->temp_vertex_stride;
00196    void *temp_buffer = MALLOC( align(count,4) * temp_vertex_stride );
00197         
00198    if (0) debug_printf("%s %d %d (sz %d, %d)\n", __FUNCTION__, start, count,
00199                        vsvg->base.key.output_stride,
00200                        temp_vertex_stride);
00201 
00202    vsvg->fetch->run( vsvg->fetch, 
00203                      start,
00204                      count,
00205                      temp_buffer );
00206 
00207    vsvg->base.vs->run_linear( vsvg->base.vs, 
00208                               temp_buffer,
00209                               temp_buffer,
00210                               (const float (*)[4])vsvg->base.vs->draw->pt.user.constants,
00211                               count,
00212                               temp_vertex_stride, 
00213                               temp_vertex_stride);
00214 
00215    if (vsvg->base.key.clip) {
00216       /* not really handling clipping, just do the rhw so we can
00217        * see the results...
00218        */
00219       do_rhw_viewport( vsvg,
00220                        count,
00221                        temp_buffer );
00222    }
00223    else if (vsvg->base.key.viewport) {
00224       do_viewport( vsvg,
00225                    count,
00226                    temp_buffer );
00227    }
00228 
00229    vsvg->emit->set_buffer( vsvg->emit,
00230                            0, 
00231                            temp_buffer,
00232                            temp_vertex_stride );
00233    
00234    vsvg->emit->set_buffer( vsvg->emit, 
00235                            1,
00236                            &vsvg->draw->rasterizer->point_size,
00237                            0);
00238    
00239    vsvg->emit->run( vsvg->emit,
00240                     0, count,
00241                     output_buffer );
00242 
00243    FREE(temp_buffer);
00244 }

static void vsvg_set_buffer ( struct draw_vs_varient varient,
unsigned  buffer,
const void *  ptr,
unsigned  stride 
) [static]

Definition at line 67 of file draw_vs_varient.c.

References draw_vs_varient_generic::fetch, and translate::set_buffer.

00071 {
00072    struct draw_vs_varient_generic *vsvg = (struct draw_vs_varient_generic *)varient;
00073 
00074    vsvg->fetch->set_buffer(vsvg->fetch, 
00075                            buffer, 
00076                            ptr, 
00077                            stride);
00078 }


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