965: add asserts to catch batch overrun
authorKeith Whitwell <keith@tungstengraphics.com>
Thu, 10 Jan 2008 14:57:55 +0000 (14:57 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Fri, 25 Jan 2008 15:50:05 +0000 (15:50 +0000)
src/mesa/pipe/i965simple/brw_batch.h
src/mesa/pipe/i965simple/brw_winsys.h
src/mesa/pipe/xlib/xm_winsys_aub.c

index 8605d7c10834c447a078e8128579ea64c7d0f1fa..5f5932a4883fa4894eb3f79026f950ecdc275122 100644 (file)
@@ -44,7 +44,8 @@
 #define OUT_RELOC( buf, flags, delta ) \
    brw->winsys->batch_reloc(brw->winsys, buf, flags, delta)
 
-#define ADVANCE_BATCH()
+#define ADVANCE_BATCH() \
+   brw->winsys->batch_end( brw->winsys )
 
 /* XXX: this is bogus - need proper handling for out-of-memory in batchbuffer.
  */
index 253599896ca03ae571e122bee910face77a8fbc2..b60f63aa5bfa29072487754838ce3a10225cc48e 100644 (file)
@@ -193,9 +193,13 @@ static inline boolean brw_batchbuffer_data(struct brw_winsys *winsys,
    uint i;
    const unsigned *udata = (const unsigned*)(data);
    unsigned size = bytes/incr;
+
+   winsys->batch_start(winsys, size, 0);
    for (i = 0; i < size; ++i) {
       winsys->batch_dword(winsys, udata[i]);
    }
+   winsys->batch_end(winsys);
+
    return (i == size);
 }
 #endif
index 2be8f8793de9a8194f442f14eb8de08177b98ad7..980c0be540f839a083b2ca687c1dd5960ac23598 100644 (file)
@@ -466,9 +466,10 @@ struct aub_brw_winsys {
                          
    struct pipe_winsys *pipe_winsys;
 
-   unsigned data[IWS_BATCHBUFFER_SIZE];
-   unsigned nr;
-   unsigned size;
+   unsigned batch_data[IWS_BATCHBUFFER_SIZE];
+   unsigned batch_nr;
+   unsigned batch_size;
+   unsigned batch_alloc;
 };
 
 
@@ -490,9 +491,10 @@ static unsigned *aub_i965_batch_start( struct brw_winsys *sws,
 {
    struct aub_brw_winsys *iws = aub_brw_winsys(sws);
 
-   if (iws->size < iws->nr + dwords)
+   if (iws->batch_size < iws->batch_nr + dwords)
       return NULL;
 
+   iws->batch_alloc = iws->batch_nr + dwords;
    return (void *)1;                   /* not a valid pointer! */
 }
 
@@ -501,7 +503,8 @@ static void aub_i965_batch_dword( struct brw_winsys *sws,
 {
    struct aub_brw_winsys *iws = aub_brw_winsys(sws);
 
-   iws->data[iws->nr++] = dword;
+   assert(iws->batch_nr < iws->batch_alloc);
+   iws->batch_data[iws->batch_nr++] = dword;
 }
 
 static void aub_i965_batch_reloc( struct brw_winsys *sws,
@@ -511,7 +514,8 @@ static void aub_i965_batch_reloc( struct brw_winsys *sws,
 {
    struct aub_brw_winsys *iws = aub_brw_winsys(sws);
 
-   iws->data[iws->nr++] = aub_bo(buf)->offset + delta;
+   assert(iws->batch_nr < iws->batch_alloc);
+   iws->batch_data[iws->batch_nr++] = aub_bo(buf)->offset + delta;
 }
 
 static unsigned aub_i965_get_buffer_offset( struct brw_winsys *sws,
@@ -521,19 +525,27 @@ static unsigned aub_i965_get_buffer_offset( struct brw_winsys *sws,
    return aub_bo(buf)->offset;
 }
 
+static void aub_i965_batch_end( struct brw_winsys *sws )
+{
+   struct aub_brw_winsys *iws = aub_brw_winsys(sws);
 
+   assert(iws->batch_nr <= iws->batch_alloc);
+   iws->batch_alloc = 0;
+}
 
 static void aub_i965_batch_flush( struct brw_winsys *sws,
                                    struct pipe_fence_handle **fence )
 {
    struct aub_brw_winsys *iws = aub_brw_winsys(sws);
-   assert(iws->nr <= iws->size);
+   assert(iws->batch_nr <= iws->batch_size);
 
-   if (iws->nr)
+   if (iws->batch_nr) {
       xmesa_commands_aub( iws->pipe_winsys,
-                         iws->data,
-                         iws->nr );
-   iws->nr = 0;
+                         iws->batch_data,
+                         iws->batch_nr );
+   }
+
+   iws->batch_nr = 0;
 }
 
 
@@ -639,13 +651,14 @@ xmesa_create_i965simple( struct pipe_winsys *winsys )
    iws->winsys.batch_start = aub_i965_batch_start;
    iws->winsys.batch_dword = aub_i965_batch_dword;
    iws->winsys.batch_reloc = aub_i965_batch_reloc;
+   iws->winsys.batch_end = aub_i965_batch_end;
    iws->winsys.batch_flush = aub_i965_batch_flush;
    iws->winsys.buffer_subdata_typed = aub_i965_buffer_subdata_typed;
    iws->winsys.get_buffer_offset = aub_i965_get_buffer_offset;
 
    iws->pipe_winsys = winsys;
 
-   iws->size = IWS_BATCHBUFFER_SIZE;
+   iws->batch_size = IWS_BATCHBUFFER_SIZE;
 
    /* Create the i965simple context:
     */