void
_brw_batchbuffer_flush(struct brw_batchbuffer *batch, 
		       const char *file,
		       int line)
{
   GLuint used = batch->ptr - batch->map;

   if (used == 0)
      return;

   /* Post-swap throttling done by the state tracker.
    */

   if (BRW_DEBUG & DEBUG_BATCH)
      debug_printf("%s:%d: Batchbuffer flush with %db used\n", 
		   file, line, used);

   if (ALWAYS_EMIT_MI_FLUSH) {
      *(GLuint *) (batch->ptr) = MI_FLUSH | BRW_FLUSH_STATE_CACHE;
      batch->ptr += 4;
      used = batch->ptr - batch->map;
   }

   /* Round batchbuffer usage to 2 DWORDs. 
    */
   if ((used & 4) == 0) {
      *(GLuint *) (batch->ptr) = 0; /* noop */
      batch->ptr += 4;
      used = batch->ptr - batch->map;
   }

   /* Mark the end of the buffer. 
    */
   *(GLuint *) (batch->ptr) = MI_BATCH_BUFFER_END;
   batch->ptr += 4;
   used = batch->ptr - batch->map;

   batch->sws->bo_flush_range(batch->buf, 0, used);
   batch->sws->bo_unmap(batch->buf);
   batch->map = NULL;
   batch->ptr = NULL;
      
   batch->sws->bo_exec(batch->buf, used );

   if (BRW_DEBUG & DEBUG_SYNC) {
      /* Abuse map/unmap to achieve wait-for-fence.
       *
       * XXX: hide this inside the winsys and export a fence
       * interface.
       */
      debug_printf("waiting for idle\n");
      batch->sws->bo_wait_idle(batch->buf);
   }

   /* Reset the buffer:
    */
   brw_batchbuffer_reset(batch);
}
Beispiel #2
0
struct brw_batchbuffer *
brw_batchbuffer_alloc(struct brw_winsys_screen *sws)
{
   struct brw_batchbuffer *batch = CALLOC_STRUCT(brw_batchbuffer);

   batch->sws = sws;
   brw_batchbuffer_reset(batch);

   return batch;
}