brw_wm_decl.c File Reference

Include dependency graph for brw_wm_decl.c:

Go to the source code of this file.

Functions

static struct brw_reg alloc_tmp (struct brw_wm_compile *c)
static void release_tmps (struct brw_wm_compile *c)
static int is_null (struct brw_reg reg)
static void emit_pixel_xy (struct brw_wm_compile *c)
static void emit_delta_xy (struct brw_wm_compile *c)
static void emit_cinterp (struct brw_wm_compile *c, int idx, int mask)
static void emit_linterp (struct brw_wm_compile *c, int idx, int mask)
static void prealloc_reg (struct brw_wm_compile *c)
void brw_wm_emit_decls (struct brw_wm_compile *c)


Function Documentation

static struct brw_reg alloc_tmp ( struct brw_wm_compile c  )  [static, read]

Definition at line 10 of file brw_wm_decl.c.

References brw_vec8_grf(), and MAX2.

00011 {
00012    c->tmp_index++;
00013    c->reg_index = MAX2(c->reg_index, c->tmp_start + c->tmp_index);
00014    return brw_vec8_grf(c->tmp_start + c->tmp_index, 0);
00015 }

void brw_wm_emit_decls ( struct brw_wm_compile c  ) 

Definition at line 337 of file brw_wm_decl.c.

References tgsi_full_declaration::Declaration, tgsi_full_declaration::DeclarationRange, emit_cinterp(), emit_linterp(), tgsi_declaration::File, tgsi_declaration_range::First, brw_wm_compile::fp, tgsi_full_token::FullDeclaration, tgsi_parse_context::FullToken, tgsi_declaration::Interpolate, tgsi_declaration_range::Last, prealloc_reg(), brw_fragment_program::program, release_tmps(), TGSI_FILE_INPUT, TGSI_INTERPOLATE_CONSTANT, TGSI_INTERPOLATE_LINEAR, TGSI_INTERPOLATE_PERSPECTIVE, tgsi_parse_end_of_tokens(), tgsi_parse_free(), tgsi_parse_init(), tgsi_parse_token(), TGSI_TOKEN_TYPE_DECLARATION, TGSI_TOKEN_TYPE_IMMEDIATE, TGSI_TOKEN_TYPE_INSTRUCTION, tgsi_full_token::Token, pipe_shader_state::tokens, tgsi_token::Type, and tgsi_declaration::UsageMask.

00338 {
00339    struct tgsi_parse_context parse;
00340    int done = 0;
00341 
00342    prealloc_reg(c);
00343 
00344    tgsi_parse_init( &parse, c->fp->program.tokens );
00345 
00346    while( !done &&
00347           !tgsi_parse_end_of_tokens( &parse ) ) 
00348    {
00349       tgsi_parse_token( &parse );
00350 
00351       switch( parse.FullToken.Token.Type ) {
00352       case TGSI_TOKEN_TYPE_DECLARATION:
00353       {
00354          const struct tgsi_full_declaration *decl = &parse.FullToken.FullDeclaration;
00355          unsigned first = decl->DeclarationRange.First;
00356          unsigned last = decl->DeclarationRange.Last;
00357          unsigned mask = decl->Declaration.UsageMask; /* ? */
00358          unsigned i;
00359 
00360          if (decl->Declaration.File != TGSI_FILE_INPUT)
00361             break;
00362 
00363          for( i = first; i <= last; i++ ) {
00364             switch (decl->Declaration.Interpolate) {
00365             case TGSI_INTERPOLATE_CONSTANT:
00366                emit_cinterp(c, i, mask);
00367                break;
00368 
00369             case TGSI_INTERPOLATE_LINEAR:
00370                emit_linterp(c, i, mask);
00371                break;
00372 
00373             case TGSI_INTERPOLATE_PERSPECTIVE:
00374                //emit_pinterp(c, i, mask);
00375                emit_linterp(c, i, mask);
00376                break;
00377             }
00378          }
00379          break;
00380       }
00381       case TGSI_TOKEN_TYPE_IMMEDIATE:
00382       case TGSI_TOKEN_TYPE_INSTRUCTION:
00383       default:
00384          done = 1;
00385          break;
00386       }
00387    }
00388 
00389    tgsi_parse_free (&parse);
00390    
00391    release_tmps(c);
00392 }

static void emit_cinterp ( struct brw_wm_compile c,
int  idx,
int  mask 
) [static]

Definition at line 120 of file brw_wm_decl.c.

References brw_MOV(), brw_vec1_grf(), brw_wm_compile::func, brw_reg::nr, brw_wm_compile::payload_coef, suboffset(), TGSI_FILE_INPUT, and brw_wm_compile::wm_regs.

00123 {
00124    struct brw_compile *p = &c->func;
00125    struct brw_reg interp[4];
00126    struct brw_reg coef = c->payload_coef[idx];
00127    int i;
00128 
00129    interp[0] = brw_vec1_grf(coef.nr, 0);
00130    interp[1] = brw_vec1_grf(coef.nr, 4);
00131    interp[2] = brw_vec1_grf(coef.nr+1, 0);
00132    interp[3] = brw_vec1_grf(coef.nr+1, 4);
00133 
00134    for(i = 0; i < 4; i++ ) {
00135       if (mask & (1<<i)) {
00136          struct brw_reg dst = c->wm_regs[TGSI_FILE_INPUT][idx][i];
00137          brw_MOV(p, dst, suboffset(interp[i],3));
00138       }
00139    }
00140 }

static void emit_delta_xy ( struct brw_wm_compile c  )  [static]

Definition at line 60 of file brw_wm_decl.c.

References alloc_tmp(), brw_ADD(), BRW_REGISTER_TYPE_UW, brw_vec1_grf(), brw_wm_compile::delta_xy, emit_pixel_xy(), brw_wm_compile::func, is_null(), negate(), brw_wm_compile::pixel_xy, retype(), and suboffset().

00061 {
00062    if (is_null(c->delta_xy[0])) {
00063       struct brw_compile *p = &c->func;
00064       struct brw_reg r1 = brw_vec1_grf(1, 0);
00065 
00066       emit_pixel_xy(c);
00067 
00068       c->delta_xy[0] = alloc_tmp(c);
00069       c->delta_xy[1] = alloc_tmp(c);
00070 
00071       /* Calc delta X,Y by subtracting origin in r1 from the pixel
00072        * centers.
00073        */
00074       brw_ADD(p,
00075               c->delta_xy[0],
00076               retype(c->pixel_xy[0], BRW_REGISTER_TYPE_UW),
00077               negate(r1));
00078 
00079       brw_ADD(p,
00080               c->delta_xy[1],
00081               retype(c->pixel_xy[1], BRW_REGISTER_TYPE_UW),
00082               negate(suboffset(r1,1)));
00083    }
00084 }

static void emit_linterp ( struct brw_wm_compile c,
int  idx,
int  mask 
) [static]

Definition at line 142 of file brw_wm_decl.c.

References brw_LINE(), brw_MAC(), brw_null_reg(), brw_vec1_grf(), brw_wm_compile::delta_xy, emit_delta_xy(), brw_wm_compile::func, brw_reg::nr, brw_wm_compile::payload_coef, suboffset(), TGSI_FILE_INPUT, and brw_wm_compile::wm_regs.

00145 {
00146    struct brw_compile *p = &c->func;
00147    struct brw_reg interp[4];
00148    struct brw_reg coef = c->payload_coef[idx];
00149    int i;
00150 
00151    emit_delta_xy(c);
00152 
00153    interp[0] = brw_vec1_grf(coef.nr, 0);
00154    interp[1] = brw_vec1_grf(coef.nr, 4);
00155    interp[2] = brw_vec1_grf(coef.nr+1, 0);
00156    interp[3] = brw_vec1_grf(coef.nr+1, 4);
00157 
00158    for(i = 0; i < 4; i++ ) {
00159       if (mask & (1<<i)) {
00160          struct brw_reg dst = c->wm_regs[TGSI_FILE_INPUT][idx][i];
00161          brw_LINE(p, brw_null_reg(), interp[i], c->delta_xy[0]);
00162          brw_MAC(p, dst, suboffset(interp[i],1), c->delta_xy[1]);
00163       }
00164    }
00165 }

static void emit_pixel_xy ( struct brw_wm_compile c  )  [static]

Definition at line 30 of file brw_wm_decl.c.

References alloc_tmp(), brw_ADD(), brw_imm_v(), BRW_REGISTER_TYPE_UW, brw_vec1_grf(), brw_wm_compile::func, is_null(), brw_wm_compile::pixel_xy, retype(), stride(), suboffset(), and vec8().

00031 {
00032    if (is_null(c->pixel_xy[0])) {
00033 
00034       struct brw_compile *p = &c->func;
00035       struct brw_reg r1_uw = retype(brw_vec1_grf(1, 0), BRW_REGISTER_TYPE_UW);
00036 
00037       c->pixel_xy[0] = vec8(retype(alloc_tmp(c), BRW_REGISTER_TYPE_UW));
00038       c->pixel_xy[1] = vec8(retype(alloc_tmp(c), BRW_REGISTER_TYPE_UW));
00039 
00040       /* Calculate pixel centers by adding 1 or 0 to each of the
00041        * micro-tile coordinates passed in r1.
00042        */
00043       brw_ADD(p,
00044               c->pixel_xy[0],
00045               stride(suboffset(r1_uw, 4), 2, 4, 0),
00046               brw_imm_v(0x10101010));
00047 
00048       brw_ADD(p,
00049               c->pixel_xy[1],
00050               stride(suboffset(r1_uw, 5), 2, 4, 0),
00051               brw_imm_v(0x11001100));
00052    }
00053 }

static int is_null ( struct brw_reg  reg  )  [static]

Definition at line 24 of file brw_wm_decl.c.

References BRW_ARCHITECTURE_REGISTER_FILE, BRW_ARF_NULL, brw_reg::file, and brw_reg::nr.

00025 {
00026    return (reg.file == BRW_ARCHITECTURE_REGISTER_FILE &&
00027            reg.nr == BRW_ARF_NULL);
00028 }

static void prealloc_reg ( struct brw_wm_compile c  )  [static]

Definition at line 247 of file brw_wm_decl.c.

References assert, BRW_GENERAL_REGISTER_FILE, brw_uw16_reg(), brw_uw1_reg(), brw_vec1_grf(), brw_vec8_grf(), brw_wm_prog_data::curb_read_length, brw_wm_compile::emit_mask_reg, tgsi_shader_info::file_count, tgsi_shader_info::file_max, brw_wm_prog_data::first_curbe_grf, brw_wm_compile::fp, brw_fragment_program::info, brw_wm_compile::key, brw_wm_prog_data::max_const, brw_wm_prog_key::nr_depth_regs, tgsi_shader_info::num_inputs, tgsi_shader_info::num_outputs, brw_wm_compile::payload_coef, brw_wm_compile::payload_depth, brw_wm_compile::prog_data, brw_wm_compile::reg_index, brw_wm_compile::stack, TGSI_FILE_CONSTANT, TGSI_FILE_INPUT, TGSI_FILE_OUTPUT, brw_wm_compile::tmp_start, brw_wm_prog_data::urb_read_length, and brw_wm_compile::wm_regs.

00248 {
00249    int i, j;
00250    int nr_curbe_regs = 0;
00251 
00252    /* R0, then some depth related regs:
00253     */
00254    for (i = 0; i < c->key.nr_depth_regs; i++) {
00255       c->payload_depth[i] =  brw_vec8_grf(i*2, 0);
00256       c->reg_index += 2;
00257    }
00258 
00259 
00260    /* Then a copy of our part of the CURBE entry:
00261     */
00262    {
00263       int nr_constants = c->fp->info.file_max[TGSI_FILE_CONSTANT] + 1;
00264       int index = 0;
00265 
00266       /* XXX number of constants, or highest numbered constant? */
00267       assert(nr_constants == c->fp->info.file_count[TGSI_FILE_CONSTANT]);
00268 
00269       c->prog_data.max_const = 4*nr_constants;
00270       for (i = 0; i < nr_constants; i++) {
00271          for (j = 0; j < 4; j++, index++) 
00272             c->wm_regs[TGSI_FILE_CONSTANT][i][j] = brw_vec1_grf(c->reg_index + index/8,
00273                                                                 index%8);
00274       }
00275 
00276       nr_curbe_regs = 2*((4*nr_constants+15)/16);
00277       c->reg_index += nr_curbe_regs;
00278    }
00279 
00280    /* Adjust for parameter coefficients for position, which are
00281     * currently always provided.
00282     */
00283 //   c->position_coef[i] = brw_vec8_grf(c->reg_index, 0);
00284    c->reg_index += 2;
00285 
00286    /* Next we receive the plane coefficients for parameter
00287     * interpolation:
00288     */
00289    assert(c->fp->info.file_max[TGSI_FILE_INPUT] == c->fp->info.num_inputs);
00290    for (i = 0; i < c->fp->info.file_max[TGSI_FILE_INPUT] + 1; i++) {
00291       c->payload_coef[i] = brw_vec8_grf(c->reg_index, 0);
00292       c->reg_index += 2;
00293    }
00294 
00295    c->prog_data.first_curbe_grf = c->key.nr_depth_regs * 2;
00296    c->prog_data.urb_read_length = (c->fp->info.num_inputs + 1) * 2;
00297    c->prog_data.curb_read_length = nr_curbe_regs;
00298 
00299    /* That's the end of the payload, now we can start allocating registers.
00300     */
00301    c->emit_mask_reg = brw_uw1_reg(BRW_GENERAL_REGISTER_FILE, c->reg_index, 0);
00302    c->reg_index++;
00303 
00304    c->stack = brw_uw16_reg(BRW_GENERAL_REGISTER_FILE, c->reg_index, 0);
00305    c->reg_index += 2;
00306 
00307    /* Now allocate room for the interpolated inputs and staging
00308     * registers for the outputs:
00309     */
00310    /* XXX do we want to loop over the _number_ of inputs/outputs or loop
00311     * to the highest input/output index that's used?
00312     *  Probably the same, actually.
00313     */
00314    assert(c->fp->info.file_max[TGSI_FILE_INPUT] + 1 == c->fp->info.num_inputs);
00315    assert(c->fp->info.file_max[TGSI_FILE_OUTPUT] + 1 == c->fp->info.num_outputs);
00316    for (i = 0; i < c->fp->info.file_max[TGSI_FILE_INPUT] + 1; i++) 
00317       for (j = 0; j < 4; j++)
00318          c->wm_regs[TGSI_FILE_INPUT][i][j] = brw_vec8_grf( c->reg_index++, 0 );
00319 
00320    for (i = 0; i < c->fp->info.file_max[TGSI_FILE_OUTPUT] + 1; i++) 
00321       for (j = 0; j < 4; j++)
00322          c->wm_regs[TGSI_FILE_OUTPUT][i][j] = brw_vec8_grf( c->reg_index++, 0 );
00323 
00324    /* Beyond this we should only need registers for internal temporaries:
00325     */
00326    c->tmp_start = c->reg_index;
00327 }

static void release_tmps ( struct brw_wm_compile c  )  [static]

Definition at line 17 of file brw_wm_decl.c.

References brw_wm_compile::tmp_index.

00018 {
00019    c->tmp_index = 0;
00020 }


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