r200: make use of DMA buffers for Elts a lot better.
authorDave Airlie <airlied@redhat.com>
Fri, 26 Jun 2009 05:05:02 +0000 (15:05 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 26 Jun 2009 05:09:12 +0000 (15:09 +1000)
This allows us to return the unused portion of the dma buffer
to the allocator instead of wasting nearly 16k a pop.

src/mesa/drivers/dri/r200/r200_cmdbuf.c
src/mesa/drivers/dri/radeon/radeon_dma.c
src/mesa/drivers/dri/radeon/radeon_dma.h

index df9dd83344caa5bd701f0a2418f9ac3e351b421a..fe173b601adaa541599d6f484c8bb96848cba33f 100644 (file)
@@ -213,6 +213,9 @@ void r200FlushElts(GLcontext *ctx)
    radeon_bo_unref(rmesa->radeon.tcl.elt_dma_bo);
    rmesa->radeon.tcl.elt_dma_bo = NULL;
 
+   if (R200_ELT_BUF_SZ > elt_used)
+     radeonReturnDmaRegion(rmesa, R200_ELT_BUF_SZ - elt_used);
+
    if (R200_DEBUG & DEBUG_SYNC) {
       fprintf(stderr, "%s: Syncing\n", __FUNCTION__);
       radeonFinish( rmesa->radeon.glCtx );
@@ -233,21 +236,13 @@ GLushort *r200AllocEltsOpenEnded( r200ContextPtr rmesa,
    
    radeonEmitState(&rmesa->radeon);
 
-   rmesa->radeon.tcl.elt_dma_bo = radeon_bo_open(rmesa->radeon.radeonScreen->bom,
-                                         0, R200_ELT_BUF_SZ, 4,
-                                         RADEON_GEM_DOMAIN_GTT, 0);
-   rmesa->radeon.tcl.elt_dma_offset = 0;
+   radeonAllocDmaRegion(&rmesa->radeon, &rmesa->radeon.tcl.elt_dma_bo,
+                       &rmesa->radeon.tcl.elt_dma_offset, R200_ELT_BUF_SZ, 4);
    rmesa->tcl.elt_used = min_nr * 2;
 
-   radeon_validate_bo(&rmesa->radeon, rmesa->radeon.tcl.elt_dma_bo,
-                      RADEON_GEM_DOMAIN_GTT, 0);
-   if (radeon_revalidate_bos(rmesa->radeon.glCtx) == GL_FALSE)
-      fprintf(stderr,"failure to revalidate BOs - badness\n");
-
    radeon_bo_map(rmesa->radeon.tcl.elt_dma_bo, 1);
    retval = rmesa->radeon.tcl.elt_dma_bo->ptr + rmesa->radeon.tcl.elt_dma_offset;
    
-
    if (R200_DEBUG & DEBUG_PRIMS)
       fprintf(stderr, "%s: header prim %x \n",
              __FUNCTION__, primitive);
index 48b0d638183734b6634daeb5a3e32229b65b712e..0b91434b2bad88db4b40e0c46546bbcab117c03d 100644 (file)
@@ -167,7 +167,7 @@ void radeonRefillCurrentDmaRegion(radeonContextPtr rmesa, int size)
        size = MAX2(size, MAX_DMA_BUF_SZ);
 
        if (RADEON_DEBUG & (DEBUG_IOCTL | DEBUG_DMA))
-               fprintf(stderr, "%s\n", __FUNCTION__);
+               fprintf(stderr, "%s %d\n", __FUNCTION__, rmesa->dma.nr_released_bufs);
 
        if (rmesa->dma.flush) {
                rmesa->dma.flush(rmesa->glCtx);
@@ -178,11 +178,7 @@ void radeonRefillCurrentDmaRegion(radeonContextPtr rmesa, int size)
                rmesa->dma.nr_released_bufs = 0;
        }
 
-       if (rmesa->dma.current) {
-               radeon_bo_unmap(rmesa->dma.current);
-               radeon_bo_unref(rmesa->dma.current);
-               rmesa->dma.current = 0;
-       }
+       radeonReleaseDmaRegion(rmesa);
 
 again_alloc:   
        rmesa->dma.current = radeon_bo_open(rmesa->radeonScreen->bom,
@@ -244,6 +240,17 @@ void radeonAllocDmaRegion(radeonContextPtr rmesa,
        assert(rmesa->dma.current_used <= rmesa->dma.current->size);
 }
 
+void radeonReturnDmaRegion(radeonContextPtr rmesa, int return_bytes)
+{
+       if (!rmesa->dma.current)
+               return;
+
+       if (RADEON_DEBUG & DEBUG_IOCTL)
+               fprintf(stderr, "%s %d\n", __FUNCTION__, return_bytes);
+       rmesa->dma.current_used -= return_bytes;
+       rmesa->dma.current_vertexptr = rmesa->dma.current_used;
+}
+
 void radeonReleaseDmaRegion(radeonContextPtr rmesa)
 {
        if (RADEON_DEBUG & DEBUG_IOCTL)
index 06e388fc1de443835ccf2a02e93aeeca05cbcfd9..c6eabd3bc868132c4377cc6960f9d7e891cb6dcd 100644 (file)
@@ -39,6 +39,7 @@ void radeonEmitVec12(uint32_t *out, GLvoid * data, int stride, int count);
 void rcommon_emit_vector(GLcontext * ctx, struct radeon_aos *aos,
                         GLvoid * data, int size, int stride, int count);
 
+void radeonReturnDmaRegion(radeonContextPtr rmesa, int return_bytes);
 void radeonRefillCurrentDmaRegion(radeonContextPtr rmesa, int size);
 void radeonAllocDmaRegion(radeonContextPtr rmesa,
                          struct radeon_bo **pbo, int *poffset,