brw_sf.c File Reference

Include dependency graph for brw_sf.c:

Go to the source code of this file.

Functions

static void compile_sf_prog (struct brw_context *brw, struct brw_sf_prog_key *key)
static boolean search_cache (struct brw_context *brw, struct brw_sf_prog_key *key)
static void upload_sf_prog (struct brw_context *brw)

Variables

struct brw_tracked_state brw_sf_prog


Function Documentation

static void compile_sf_prog ( struct brw_context brw,
struct brw_sf_prog_key key 
) [static]

Definition at line 42 of file brw_sf.c.

References assert, brw_emit_line_setup(), brw_emit_point_setup(), brw_emit_tri_setup(), brw_get_program(), brw_init_compile(), BRW_SF_PROG, brw_upload_cache(), brw_context::cache, brw_sf_prog_key::fp_input_count, brw_sf_compile::func, brw_sf_compile::key, brw_sf_compile::nr_attr_regs, brw_sf_compile::nr_attrs, brw_sf_compile::nr_setup_attrs, brw_sf_compile::nr_setup_regs, brw_sf_compile::nr_verts, brw_sf_prog_key::primitive, brw_context::prog_data, brw_sf_compile::prog_data, brw_context::prog_gs_offset, brw_context::sf, SF_LINES, SF_POINTS, SF_TRIANGLES, SF_UNFILLED_TRIS, brw_sf_prog_data::urb_entry_size, brw_sf_prog_data::urb_read_length, and brw_sf_prog_key::vp_output_count.

00044 {
00045    struct brw_sf_compile c;
00046    const unsigned *program;
00047    unsigned program_size;
00048 
00049    memset(&c, 0, sizeof(c));
00050 
00051    /* Begin the compilation:
00052     */
00053    brw_init_compile(&c.func);
00054 
00055    c.key = *key;
00056 
00057 
00058    c.nr_attrs = c.key.vp_output_count;
00059    c.nr_attr_regs = (c.nr_attrs+1)/2;
00060 
00061    c.nr_setup_attrs = c.key.fp_input_count + 1; /* +1 for position */
00062    c.nr_setup_regs = (c.nr_setup_attrs+1)/2;
00063 
00064    c.prog_data.urb_read_length = c.nr_attr_regs;
00065    c.prog_data.urb_entry_size = c.nr_setup_regs * 2;
00066 
00067 
00068    /* Which primitive?  Or all three?
00069     */
00070    switch (key->primitive) {
00071    case SF_TRIANGLES:
00072       c.nr_verts = 3;
00073       brw_emit_tri_setup( &c );
00074       break;
00075    case SF_LINES:
00076       c.nr_verts = 2;
00077       brw_emit_line_setup( &c );
00078       break;
00079    case SF_POINTS:
00080       c.nr_verts = 1;
00081       brw_emit_point_setup( &c );
00082       break;
00083 
00084    case SF_UNFILLED_TRIS:
00085    default:
00086       assert(0);
00087       return;
00088    }
00089 
00090 
00091 
00092    /* get the program
00093     */
00094    program = brw_get_program(&c.func, &program_size);
00095 
00096    /* Upload
00097     */
00098    brw->sf.prog_gs_offset = brw_upload_cache( &brw->cache[BRW_SF_PROG],
00099                                               &c.key,
00100                                               sizeof(c.key),
00101                                               program,
00102                                               program_size,
00103                                               &c.prog_data,
00104                                               &brw->sf.prog_data );
00105 }

static boolean search_cache ( struct brw_context brw,
struct brw_sf_prog_key key 
) [static]

Definition at line 108 of file brw_sf.c.

References brw_search_cache(), BRW_SF_PROG, brw_context::cache, brw_context::prog_data, brw_context::prog_gs_offset, and brw_context::sf.

00110 {
00111    return brw_search_cache(&brw->cache[BRW_SF_PROG],
00112                            key, sizeof(*key),
00113                            &brw->sf.prog_data,
00114                            &brw->sf.prog_gs_offset);
00115 }

static void upload_sf_prog ( struct brw_context brw  )  [static]

Definition at line 120 of file brw_sf.c.

References brw_context::attribs, compile_sf_prog(), brw_sf_prog_key::const_mask, debug_printf(), tgsi_full_declaration::Declaration, tgsi_full_declaration::DeclarationRange, tgsi_declaration::File, tgsi_shader_info::file_max, tgsi_declaration_range::First, brw_sf_prog_key::fp_input_count, brw_context::FragmentProgram, tgsi_full_token::FullDeclaration, tgsi_parse_context::FullToken, brw_fragment_program::info, tgsi_declaration::Interpolate, tgsi_declaration_range::Last, brw_sf_prog_key::linear_mask, brw_vs_prog_data::outputs_written, brw_sf_prog_key::persp_mask, PIPE_PRIM_LINES, PIPE_PRIM_POINTS, PIPE_PRIM_TRIANGLES, brw_sf_prog_key::primitive, brw_context::prog_data, brw_fragment_program::program, brw_context::reduced_primitive, search_cache(), SF_LINES, SF_POINTS, SF_TRIANGLES, TGSI_FILE_INPUT, TGSI_INTERPOLATE_CONSTANT, TGSI_INTERPOLATE_LINEAR, TGSI_INTERPOLATE_PERSPECTIVE, tgsi_parse_end_of_tokens(), tgsi_parse_init(), tgsi_parse_token(), TGSI_TOKEN_TYPE_DECLARATION, tgsi_full_token::Token, pipe_shader_state::tokens, tgsi_token::Type, brw_sf_prog_key::vp_output_count, and brw_context::vs.

00121 {
00122    const struct brw_fragment_program *fs = brw->attribs.FragmentProgram;
00123    struct brw_sf_prog_key key;
00124    struct tgsi_parse_context parse;
00125    int i, done = 0;
00126 
00127 
00128    memset(&key, 0, sizeof(key));
00129 
00130    /* Populate the key, noting state dependencies:
00131     */
00132    /* CACHE_NEW_VS_PROG */
00133    key.vp_output_count = brw->vs.prog_data->outputs_written;
00134 
00135    /* BRW_NEW_FS */
00136    key.fp_input_count = brw->attribs.FragmentProgram->info.file_max[TGSI_FILE_INPUT] + 1;
00137 
00138 
00139    /* BRW_NEW_REDUCED_PRIMITIVE */
00140    switch (brw->reduced_primitive) {
00141    case PIPE_PRIM_TRIANGLES:
00142 //      if (key.attrs & (1<<VERT_RESULT_EDGE))
00143 //       key.primitive = SF_UNFILLED_TRIS;
00144 //      else
00145       key.primitive = SF_TRIANGLES;
00146       break;
00147    case PIPE_PRIM_LINES:
00148       key.primitive = SF_LINES;
00149       break;
00150    case PIPE_PRIM_POINTS:
00151       key.primitive = SF_POINTS;
00152       break;
00153    }
00154 
00155 
00156 
00157    /* Scan fp inputs to figure out what interpolation modes are
00158     * required for each incoming vp output.  There is an assumption
00159     * that the state tracker makes sure there is a 1:1 linkage between
00160     * these sets of attributes (XXX: position??)
00161     */
00162    tgsi_parse_init( &parse, fs->program.tokens );
00163    while( !done &&
00164           !tgsi_parse_end_of_tokens( &parse ) ) 
00165    {
00166       tgsi_parse_token( &parse );
00167 
00168       switch( parse.FullToken.Token.Type ) {
00169       case TGSI_TOKEN_TYPE_DECLARATION:
00170          if (parse.FullToken.FullDeclaration.Declaration.File == TGSI_FILE_INPUT) 
00171          {
00172             int first = parse.FullToken.FullDeclaration.DeclarationRange.First;
00173             int last = parse.FullToken.FullDeclaration.DeclarationRange.Last;
00174             int interp_mode = parse.FullToken.FullDeclaration.Declaration.Interpolate;
00175             //int semantic = parse.FullToken.FullDeclaration.Semantic.SemanticName;
00176             //int semantic_index = parse.FullToken.FullDeclaration.Semantic.SemanticIndex;
00177 
00178             debug_printf("fs input %d..%d interp mode %d\n", first, last, interp_mode);
00179             
00180             switch (interp_mode) {
00181             case TGSI_INTERPOLATE_CONSTANT:
00182                for (i = first; i <= last; i++) 
00183                   key.const_mask |= (1 << i);
00184                break;
00185             case TGSI_INTERPOLATE_LINEAR:
00186                for (i = first; i <= last; i++) 
00187                   key.linear_mask |= (1 << i);
00188                break;
00189             case TGSI_INTERPOLATE_PERSPECTIVE:
00190                for (i = first; i <= last; i++) 
00191                   key.persp_mask |= (1 << i);
00192                break;
00193             default:
00194                break;
00195             }
00196 
00197             /* Also need stuff for flat shading, twosided color.
00198              */
00199 
00200          }
00201          break;
00202       default:
00203          done = 1;
00204          break;
00205       }
00206    }
00207 
00208    /* Hack: Adjust for position.  Optimize away when not required (ie
00209     * for perspective interpolation).
00210     */
00211    key.persp_mask <<= 1;
00212    key.linear_mask <<= 1; 
00213    key.linear_mask |= 1;
00214    key.const_mask <<= 1;
00215 
00216    debug_printf("key.persp_mask: %x\n", key.persp_mask);
00217    debug_printf("key.linear_mask: %x\n", key.linear_mask);
00218    debug_printf("key.const_mask: %x\n", key.const_mask);
00219 
00220 
00221 //   key.do_point_sprite = brw->attribs.Point->PointSprite;
00222 //   key.SpriteOrigin = brw->attribs.Point->SpriteOrigin;
00223 
00224 //   key.do_flat_shading = (brw->attribs.Raster->flatshade);
00225 //   key.do_twoside_color = (brw->attribs.Light->Enabled && brw->attribs.Light->Model.TwoSide);
00226 
00227 //   if (key.do_twoside_color)
00228 //      key.frontface_ccw = (brw->attribs.Polygon->FrontFace == GL_CCW);
00229 
00230 
00231    if (!search_cache(brw, &key))
00232       compile_sf_prog( brw, &key );
00233 }


Variable Documentation

struct brw_tracked_state brw_sf_prog

Initial value:

 {
   .dirty = {
      .brw   = ( 0x2  |
                 0x80000  |
                 0x4000  |
                 0x4 ),
      .cache = 0,
   },
   .update = upload_sf_prog
}

Definition at line 236 of file brw_sf.c.


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