extsrc/mesa/src/mesa/drivers/dri/i965/brw_fs.cpp
/**
 * Choose accesses from the UNIFORM file to demote to using the pull
 * constant buffer.
 *
 * We allow a fragment shader to have more than the specified minimum
 * maximum number of fragment shader uniform components (64).  If
 * there are too many of these, they'd fill up all of register space.
 * So, this will push some of them out to the pull constant buffer and
 * update the program to load them.
 */
Choose accesses from the UNIFORM file to demote to using the pull
constant buffer.

We allow a fragment shader to have more than the specified minimum
maximum number of fragment shader uniform components (64).  If
there are too many of these, they'd fill up all of register space.
So, this will push some of them out to the pull constant buffer and
update the program to load them.
Choose accesses from the UNIFORM file to demote to using the pull constant buffer . We allow a fragment shader to have more than the specified minimum maximum number of fragment shader uniform components ( 64 ) . If there are too many of these they ' d fill up all of register space . So this will push some of them out to the pull constant buffer and update the program to load them .
void
fs_visitor::setup_pull_constants()
{
   unsigned int max_uniform_components = 16 * 8;
   if (c->prog_data.nr_params <= max_uniform_components)
      return;
   if (c->dispatch_width == 16) {
      fail("Pull constants not supported in 16-wide\n");
      return;
   }
   int pull_uniform_base = max_uniform_components;
   int pull_uniform_count = c->prog_data.nr_params - pull_uniform_base;
   foreach_list(node, &this->instructions) {
      fs_inst *inst = (fs_inst *)node;
      for (int i = 0; i < 3; i++) {
	 if (inst->src[i].file != UNIFORM)
	    continue;
	 int uniform_nr = inst->src[i].reg + inst->src[i].reg_offset;
	 if (uniform_nr < pull_uniform_base)
	    continue;
	 fs_reg dst = fs_reg(this, glsl_type::float_type);
	 fs_inst *pull = new(mem_ctx) fs_inst(FS_OPCODE_PULL_CONSTANT_LOAD,
					      dst);
	 pull->offset = ((uniform_nr - pull_uniform_base) * 4) & ~15;
	 pull->ir = inst->ir;
	 pull->annotation = inst->annotation;
	 pull->base_mrf = 14;
	 pull->mlen = 1;
	 inst->insert_before(pull);
	 inst->src[i].file = GRF;
	 inst->src[i].reg = dst.reg;
	 inst->src[i].reg_offset = 0;
	 inst->src[i].smear = (uniform_nr - pull_uniform_base) & 3;
      }
   }
   for (int i = 0; i < pull_uniform_count; i++) {
      c->prog_data.pull_param[i] = c->prog_data.param[pull_uniform_base + i];
      c->prog_data.pull_param_convert[i] =
	 c->prog_data.param_convert[pull_uniform_base + i];
   }
   c->prog_data.nr_params -= pull_uniform_count;
   c->prog_data.nr_pull_params = pull_uniform_count;
}
void fs_visitor :: setup_pull_constants ( ) { unsigned int max_uniform_components = 16 * 8 ; if ( c -> prog_data . nr_params <= max_uniform_components ) return ; if ( c -> dispatch_width == 16 ) { fail ( " \n " ) ; return ; } int pull_uniform_base = max_uniform_components ; int pull_uniform_count = c -> prog_data . nr_params - pull_uniform_base ; foreach_list ( node , & this -> instructions ) { fs_inst * inst = ( fs_inst * ) node ; for ( int i = 0 ; i < 3 ; i ++ ) { if ( inst -> src [ i ] . file != UNIFORM ) continue ; int uniform_nr = inst -> src [ i ] . reg + inst -> src [ i ] . reg_offset ; if ( uniform_nr < pull_uniform_base ) continue ; fs_reg dst = fs_reg ( this , glsl_type :: float_type ) ; fs_inst * pull = new ( mem_ctx ) fs_inst ( FS_OPCODE_PULL_CONSTANT_LOAD , dst ) ; pull -> offset = ( ( uniform_nr - pull_uniform_base ) * 4 ) & ~ 15 ; pull -> ir = inst -> ir ; pull -> annotation = inst -> annotation ; pull -> base_mrf = 14 ; pull -> mlen = 1 ; inst -> insert_before ( pull ) ; inst -> src [ i ] . file = GRF ; inst -> src [ i ] . reg = dst . reg ; inst -> src [ i ] . reg_offset = 0 ; inst -> src [ i ] . smear = ( uniform_nr - pull_uniform_base ) & 3 ; } } for ( int i = 0 ; i < pull_uniform_count ; i ++ ) { c -> prog_data . pull_param [ i ] = c -> prog_data . param [ pull_uniform_base + i ] ; c -> prog_data . pull_param_convert [ i ] = c -> prog_data . param_convert [ pull_uniform_base + i ] ; } c -> prog_data . nr_params -= pull_uniform_count ; c -> prog_data . nr_pull_params = pull_uniform_count ; }
Choose accesses from the UNIFORM file to demote to using the pull
 constant buffer.
Choose accesses from the UNIFORM file to demote to using the pull constant buffer .
/* Only allow 16 registers (128 uniform components) as push constants. */ /* Just demote the end of the list.  We could probably do better
    * here, demoting things that are rarely used in the program first.
    */