sp_quad_fs.c File Reference

Include dependency graph for sp_quad_fs.c:

Go to the source code of this file.

Data Structures

struct  quad_shade_stage

Functions

static struct quad_shade_stagequad_shade_stage (struct quad_stage *qs)
 cast wrapper
static void shade_quad (struct quad_stage *qs, struct quad_header *quad)
 Execute fragment shader for the four fragments in the quad.
static void shade_begin (struct quad_stage *qs)
 Per-primitive (or per-begin?) setup.
static void shade_destroy (struct quad_stage *qs)
struct quad_stagesp_quad_shade_stage (struct softpipe_context *softpipe)


Function Documentation

static struct quad_shade_stage* quad_shade_stage ( struct quad_stage qs  )  [static, read]

cast wrapper

Definition at line 62 of file sp_quad_fs.c.

00063 {
00064    return (struct quad_shade_stage *) qs;
00065 }

static void shade_begin ( struct quad_stage qs  )  [static]

Per-primitive (or per-begin?) setup.

Definition at line 146 of file sp_quad_fs.c.

References quad_stage::begin, softpipe_context::fs, quad_shade_stage::machine, MAX2, quad_stage::next, softpipe_context::num_samplers, softpipe_context::num_textures, sp_fragment_shader::prepare, quad_shade_stage(), softpipe_context::sampler, quad_shade_stage::samplers, quad_stage::softpipe, tgsi_sampler::state, softpipe_context::texture, and tgsi_sampler::texture.

00147 {
00148    struct quad_shade_stage *qss = quad_shade_stage(qs);
00149    struct softpipe_context *softpipe = qs->softpipe;
00150    unsigned i;
00151    unsigned num = MAX2(softpipe->num_textures, softpipe->num_samplers);
00152 
00153    /* set TGSI sampler state that varies */
00154    for (i = 0; i < num; i++) {
00155       qss->samplers[i].state = softpipe->sampler[i];
00156       qss->samplers[i].texture = softpipe->texture[i];
00157    }
00158 
00159    softpipe->fs->prepare( softpipe->fs, 
00160                           &qss->machine,
00161                           qss->samplers );
00162 
00163    qs->next->begin(qs->next);
00164 }

static void shade_destroy ( struct quad_stage qs  )  [static]

Definition at line 167 of file sp_quad_fs.c.

References FREE, quad_shade_stage::inputs, quad_shade_stage::machine, quad_shade_stage::outputs, and tgsi_exec_machine_free_data().

00168 {
00169    struct quad_shade_stage *qss = (struct quad_shade_stage *) qs;
00170 
00171    tgsi_exec_machine_free_data(&qss->machine);
00172    FREE( qss->inputs );
00173    FREE( qss->outputs );
00174    FREE( qs );
00175 }

static void shade_quad ( struct quad_stage qs,
struct quad_header quad 
) [static]

Execute fragment shader for the four fragments in the quad.

Definition at line 73 of file sp_quad_fs.c.

References tgsi_interp_coef::a0, quad_header::coef, quad_header_output::color, tgsi_exec_machine::Consts, tgsi_interp_coef::dadx, tgsi_interp_coef::dady, quad_header_output::depth, tgsi_exec_channel::f, FALSE, softpipe_context::fs, sp_fragment_shader::info, quad_header::inout, quad_header::input, tgsi_exec_machine::InterpCoefs, quad_shade_stage::machine, softpipe_context::mapped_constants, quad_header_inout::mask, quad_stage::next, tgsi_shader_info::num_outputs, quad_header::output, tgsi_shader_info::output_semantic_index, tgsi_shader_info::output_semantic_name, tgsi_exec_machine::Outputs, PIPE_SHADER_FRAGMENT, quad_header::posCoef, quad_shade_stage(), quad_stage::run, sp_fragment_shader::run, quad_stage::softpipe, quad_shade_stage::stage, TGSI_SEMANTIC_COLOR, TGSI_SEMANTIC_POSITION, TRUE, quad_header_input::x0, tgsi_exec_vector::xyzw, and quad_header_input::y0.

00076 {
00077    struct quad_shade_stage *qss = quad_shade_stage( qs );
00078    struct softpipe_context *softpipe = qs->softpipe;
00079    struct tgsi_exec_machine *machine = &qss->machine;
00080    boolean z_written;
00081    
00082    /* Consts do not require 16 byte alignment. */
00083    machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT];
00084 
00085    machine->InterpCoefs = quad->coef;
00086 
00087    /* run shader */
00088    quad->inout.mask &= softpipe->fs->run( softpipe->fs, 
00089                                     &qss->machine,
00090                                     quad );
00091 
00092    /* store outputs */
00093    z_written = FALSE;
00094    {
00095       const ubyte *sem_name = softpipe->fs->info.output_semantic_name;
00096       const ubyte *sem_index = softpipe->fs->info.output_semantic_index;
00097       const uint n = qss->stage.softpipe->fs->info.num_outputs;
00098       uint i;
00099       for (i = 0; i < n; i++) {
00100          switch (sem_name[i]) {
00101          case TGSI_SEMANTIC_COLOR:
00102             {
00103                uint cbuf = sem_index[i];
00104                memcpy(quad->output.color[cbuf],
00105                       &machine->Outputs[i].xyzw[0].f[0],
00106                       sizeof(quad->output.color[0]) );
00107             }
00108             break;
00109          case TGSI_SEMANTIC_POSITION:
00110             {
00111                uint j;
00112                for (j = 0; j < 4; j++) {
00113                   quad->output.depth[j] = machine->Outputs[0].xyzw[2].f[j];
00114                }
00115                z_written = TRUE;
00116             }
00117             break;
00118          }
00119       }
00120    }
00121 
00122    if (!z_written) {
00123       /* compute Z values now, as in the quad earlyz stage */
00124       /* XXX we should really only do this if the earlyz stage is not used */
00125       const float fx = (float) quad->input.x0;
00126       const float fy = (float) quad->input.y0;
00127       const float dzdx = quad->posCoef->dadx[2];
00128       const float dzdy = quad->posCoef->dady[2];
00129       const float z0 = quad->posCoef->a0[2] + dzdx * fx + dzdy * fy;
00130 
00131       quad->output.depth[0] = z0;
00132       quad->output.depth[1] = z0 + dzdx;
00133       quad->output.depth[2] = z0 + dzdy;
00134       quad->output.depth[3] = z0 + dzdx + dzdy;
00135    }
00136 
00137    /* shader may cull fragments */
00138    if( quad->inout.mask ) {
00139       qs->next->run( qs->next, quad );
00140    }
00141 }

struct quad_stage* sp_quad_shade_stage ( struct softpipe_context softpipe  )  [read]

Definition at line 178 of file sp_quad_fs.c.

References align16(), assert, quad_stage::begin, tgsi_sampler::cache, CALLOC_STRUCT, quad_stage::destroy, tgsi_sampler::get_samples, tgsi_exec_machine::Inputs, quad_shade_stage::inputs, quad_shade_stage::machine, MALLOC, tgsi_exec_machine::Outputs, quad_shade_stage::outputs, softpipe_context::pipe, tgsi_sampler::pipe, PIPE_MAX_ATTRIBS, PIPE_MAX_SAMPLERS, quad_stage::run, quad_shade_stage::samplers, shade_begin(), shade_destroy(), shade_quad(), quad_stage::softpipe, sp_get_samples(), quad_shade_stage::stage, softpipe_context::tex_cache, and tgsi_exec_machine_init().

00179 {
00180    struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage);
00181    uint i;
00182 
00183    /* allocate storage for program inputs/outputs, aligned to 16 bytes */
00184    qss->inputs = MALLOC(PIPE_MAX_ATTRIBS * sizeof(*qss->inputs) + 16);
00185    qss->outputs = MALLOC(PIPE_MAX_ATTRIBS * sizeof(*qss->outputs) + 16);
00186    qss->machine.Inputs = align16(qss->inputs);
00187    qss->machine.Outputs = align16(qss->outputs);
00188 
00189    qss->stage.softpipe = softpipe;
00190    qss->stage.begin = shade_begin;
00191    qss->stage.run = shade_quad;
00192    qss->stage.destroy = shade_destroy;
00193 
00194    /* set TGSI sampler state that's constant */
00195    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
00196       assert(softpipe->tex_cache[i]);
00197       qss->samplers[i].get_samples = sp_get_samples;
00198       qss->samplers[i].pipe = &softpipe->pipe;
00199       qss->samplers[i].cache = softpipe->tex_cache[i];
00200    }
00201 
00202    tgsi_exec_machine_init( &qss->machine );
00203 
00204    return &qss->stage;
00205 }


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