static void upload_clip_unit( struct brw_context *brw )
{
   struct brw_clip_unit_key key;

   clip_unit_populate_key(brw, &key);

   dri_bo_unreference(brw->clip.state_bo);
   brw->clip.state_bo = brw_search_cache(&brw->cache, BRW_CLIP_UNIT,
					 &key, sizeof(key),
					 &brw->clip.prog_bo, 1,
					 NULL);
   if (brw->clip.state_bo == NULL) {
      brw->clip.state_bo = clip_unit_create_from_key(brw, &key);
   }
}
static int upload_clip_unit( struct brw_context *brw )
{
   struct brw_clip_unit_key key;
   int ret = 0;

   clip_unit_populate_key(brw, &key);

   dri_bo_unreference(brw->clip.state_bo);
   brw->clip.state_bo = brw_search_cache(&brw->cache, BRW_CLIP_UNIT,
					 &key, sizeof(key),
					 &brw->clip.prog_bo, 1,
					 NULL);
   if (brw->clip.state_bo == NULL) {
      brw->clip.state_bo = clip_unit_create_from_key(brw, &key);
   }

   ret = dri_bufmgr_check_aperture_space(brw->clip.state_bo);
   return ret;
}
static int upload_clip_unit( struct brw_context *brw )
{
   struct brw_clip_unit_key key;
   struct brw_winsys_reloc reloc[1];
   unsigned grf_reg_count;
   enum pipe_error ret;

   clip_unit_populate_key(brw, &key);

   grf_reg_count = align(key.total_grf, 16) / 16 - 1;

   /* clip program relocation
    *
    * XXX: these reloc structs are long lived and only need to be
    * updated when the bound BO changes.  Hopefully the stuff mixed in
    * in the delta's is non-orthogonal.
    */
   assert(brw->clip.prog_bo);
   make_reloc(&reloc[0],
              BRW_USAGE_STATE,
              grf_reg_count << 1,
              offsetof(struct brw_clip_unit_state, thread0),
              brw->clip.prog_bo);


   if (brw_search_cache(&brw->cache, BRW_CLIP_UNIT,
                        &key, sizeof(key),
                        reloc, 1,
                        NULL,
                        &brw->clip.state_bo))
      return PIPE_OK;
      
   /* Create new:
    */
   ret = clip_unit_create_from_key(brw, &key, 
                                   reloc,
                                   &brw->clip.state_bo);
   if (ret)
      return ret;
   
   return PIPE_OK;
}