radeon/r200/r300: Fix swtcl flushing not to invalidate dma region.
authorPauli Nieminen <suokkos@gmail.com>
Wed, 26 Aug 2009 19:24:25 +0000 (22:24 +0300)
committerPauli Nieminen <suokkos@gmail.com>
Wed, 26 Aug 2009 21:01:56 +0000 (00:01 +0300)
We were check command buffer sizes too alte so allocated dma regions
were freed before relocations so space checking failed.

src/mesa/drivers/dri/r200/r200_swtcl.c
src/mesa/drivers/dri/r300/r300_swtcl.c
src/mesa/drivers/dri/radeon/radeon_common_context.h
src/mesa/drivers/dri/radeon/radeon_dma.c
src/mesa/drivers/dri/radeon/radeon_swtcl.c

index 13bd6ac4e2cca926ee6d25f49adb3b1687e6da8f..6b7279e8db5be8cf66760a76205f91a628272806 100644 (file)
@@ -204,7 +204,21 @@ static void r200SetVertexFormat( GLcontext *ctx )
 
 static void r200RenderStart( GLcontext *ctx )
 {
+   const int vertex_array_size = 7;
+   const int prim_size = 3;
+   r200ContextPtr rmesa = R200_CONTEXT( ctx );
    r200SetVertexFormat( ctx );
+   if (RADEON_DEBUG & DEBUG_VERTS)
+      fprintf(stderr, "%s\n", __func__);
+   if (!rmesa->radeon.swtcl.primitive_counter) {
+      if (rcommonEnsureCmdBufSpace(&rmesa->radeon,
+              radeonCountStateEmitSize(&rmesa->radeon) +
+              vertex_array_size + prim_size,
+              __FUNCTION__))
+        rmesa->radeon.swtcl.primitive_counter = 0;
+      else
+        rmesa->radeon.swtcl.primitive_counter = 1;
+   }
 }
 
 
@@ -268,9 +282,8 @@ void r200ChooseVertexState( GLcontext *ctx )
 void r200_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
 {
    r200ContextPtr rmesa = R200_CONTEXT(ctx);
-   rcommonEnsureCmdBufSpace(&rmesa->radeon,
-                           radeonCountStateEmitSize(&rmesa->radeon) + (12*sizeof(int)),
-                           __FUNCTION__);
+   if (RADEON_DEBUG & DEBUG_VERTS)
+      fprintf(stderr, "%s\n", __func__);
 
 
    radeonEmitState(&rmesa->radeon);
@@ -284,6 +297,8 @@ void r200_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
                     rmesa->radeon.swtcl.hw_primitive,
                     rmesa->radeon.swtcl.numverts);
 
+   rmesa->radeon.swtcl.primitive_counter = 0;
+
 }
 
 /**************************************************************************/
@@ -890,6 +905,7 @@ void r200InitSwtcl( GLcontext *ctx )
       init_rast_tab();
       firsttime = 0;
    }
+   rmesa->radeon.swtcl.primitive_counter = 0;
 
    tnl->Driver.Render.Start = r200RenderStart;
    tnl->Driver.Render.Finish = r200RenderFinish;
index 9d6f7568799b474cf2b95fe1e6db474aca3e4a52..18af51e666addeedb23eab27af1cef9043fc5ada 100644 (file)
@@ -83,6 +83,9 @@ void r300ChooseSwtclVertexFormat(GLcontext *ctx, GLuint *_InputsRead,  GLuint *_
        rmesa->swtcl.coloroffset = rmesa->swtcl.specoffset = 0;
        rmesa->radeon.swtcl.vertex_attr_count = 0;
 
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
+
        /* We always want non Ndc coords format */
        VB->AttribPtr[VERT_ATTRIB_POS] = VB->ClipPtr;
 
@@ -462,6 +465,8 @@ static void r300ChooseRenderState( GLcontext *ctx )
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        GLuint index = 0;
        GLuint flags = ctx->_TriangleCaps;
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
 
        if (flags & DD_TRI_UNFILLED)      index |= R300_UNFILLED_BIT;
 
@@ -489,6 +494,8 @@ static void r300ChooseRenderState( GLcontext *ctx )
 
 void r300RenderStart(GLcontext *ctx)
 {
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
        r300ContextPtr rmesa = R300_CONTEXT( ctx );
 
        r300ChooseRenderState(ctx);
@@ -501,6 +508,19 @@ void r300RenderStart(GLcontext *ctx)
 
        r300UpdateShaderStates(rmesa);
 
+       const int vertex_size = 7;
+       const int prim_size = 3;
+
+       if (!rmesa->radeon.swtcl.primitive_counter) {
+               if (rcommonEnsureCmdBufSpace(&rmesa->radeon,
+                                       radeonCountStateEmitSize(&rmesa->radeon) +
+                                       + vertex_size + prim_size,
+                                       __FUNCTION__))
+                       rmesa->radeon.swtcl.primitive_counter = 0;
+               else
+                       rmesa->radeon.swtcl.primitive_counter = 1;
+       }
+
        r300EmitCacheFlush(rmesa);
 
        /* investigate if we can put back flush optimisation if needed */
@@ -516,6 +536,8 @@ void r300RenderFinish(GLcontext *ctx)
 static void r300RasterPrimitive( GLcontext *ctx, GLuint hwprim )
 {
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
 
        if (rmesa->radeon.swtcl.hw_primitive != hwprim) {
                R300_NEWPRIM( rmesa );
@@ -528,6 +550,8 @@ void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
 
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        rmesa->radeon.swtcl.render_primitive = prim;
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
 
        if ((prim == GL_TRIANGLES) && (ctx->_TriangleCaps & DD_TRI_UNFILLED))
                return;
@@ -537,6 +561,8 @@ void r300RenderPrimitive(GLcontext *ctx, GLenum prim)
 
 void r300ResetLineStipple(GLcontext *ctx)
 {
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
 }
 
 void r300InitSwtcl(GLcontext *ctx)
@@ -544,11 +570,14 @@ void r300InitSwtcl(GLcontext *ctx)
        TNLcontext *tnl = TNL_CONTEXT(ctx);
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
        static int firsttime = 1;
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
 
        if (firsttime) {
                init_rast_tab();
                firsttime = 0;
        }
+       rmesa->radeon.swtcl.primitive_counter = 0;
 
        tnl->Driver.Render.Start = r300RenderStart;
        tnl->Driver.Render.Finish = r300RenderFinish;
@@ -597,6 +626,8 @@ static void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vert
 {
        BATCH_LOCALS(&rmesa->radeon);
        int type, num_verts;
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
 
        type = r300PrimitiveType(rmesa, primitive);
        num_verts = r300NumVerts(rmesa, vertex_nr, primitive);
@@ -609,11 +640,10 @@ static void r300EmitVbufPrim(r300ContextPtr rmesa, GLuint primitive, GLuint vert
 
 void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
 {
+       if (RADEON_DEBUG & DEBUG_VERTS)
+               fprintf(stderr, "%s\n", __func__);
        r300ContextPtr rmesa = R300_CONTEXT(ctx);
 
-       rcommonEnsureCmdBufSpace(&rmesa->radeon,
-                          rmesa->radeon.hw.max_state_size + (12*sizeof(int)),
-                          __FUNCTION__);
        radeonEmitState(&rmesa->radeon);
     r300_emit_scissor(ctx);
        r300EmitVertexAOS(rmesa,
@@ -625,5 +655,6 @@ void r300_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
                   rmesa->radeon.swtcl.hw_primitive,
                   rmesa->radeon.swtcl.numverts);
        r300EmitCacheFlush(rmesa);
+       rmesa->radeon.swtcl.primitive_counter = 0;
        COMMIT_BATCH();
 }
index cb47484de1ae21cedb7671cd24a792b00263b1cc..5c4b4abaca42601553ed4fe212c93e35093ace3d 100644 (file)
@@ -342,6 +342,7 @@ struct radeon_swtcl_info {
        struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
        GLuint vertex_attr_count;
 
+       GLuint primitive_counter;
 };
 
 #define RADEON_MAX_AOS_ARRAYS          16
index 51f764cf47336540230d90b052edf1c142526a7d..7aa59675b7a67d9a711c1377b182dcfb8bfe5268 100644 (file)
@@ -428,7 +428,6 @@ rcommonAllocDmaLowVerts( radeonContextPtr rmesa, int nverts, int vsize )
 {
        GLuint bytes = vsize * nverts;
        void *head;
-restart:
        if (RADEON_DEBUG & DEBUG_IOCTL)
                fprintf(stderr, "%s\n", __FUNCTION__);
        if (is_empty_list(&rmesa->dma.reserved)
@@ -437,13 +436,7 @@ restart:
        }
 
         if (!rmesa->dma.flush) {
-               /* make sure we have enough space to use this in cmdbuf */
-               rcommonEnsureCmdBufSpace(rmesa,
-                             radeonCountStateEmitSize( rmesa ) + (20*sizeof(int)),
-                             __FUNCTION__);
                /* if cmdbuf flushed DMA restart */
-               if (is_empty_list(&rmesa->dma.reserved))
-                       goto restart;
                 rmesa->glCtx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
                 rmesa->dma.flush = rcommon_flush_last_swtcl_prim;
         }
index 14d5b5a2af12949a17d64447d8534c9408c78ff6..c9e399f9b61dd4bd23f57a85772d3e5c34256bc5 100644 (file)
@@ -223,13 +223,23 @@ static void radeonSetVertexFormat( GLcontext *ctx )
 
 static void radeonRenderStart( GLcontext *ctx )
 {
-   r100ContextPtr rmesa = R100_CONTEXT( ctx );
-
-   radeonSetVertexFormat( ctx );
-   
-   if (rmesa->radeon.dma.flush != 0 && 
-       rmesa->radeon.dma.flush != rcommon_flush_last_swtcl_prim)
-      rmesa->radeon.dma.flush( ctx );
+    r100ContextPtr rmesa = R100_CONTEXT( ctx );
+
+    radeonSetVertexFormat( ctx );
+
+    if (rmesa->radeon.dma.flush != 0 &&
+            rmesa->radeon.dma.flush != rcommon_flush_last_swtcl_prim)
+        rmesa->radeon.dma.flush( ctx );
+
+    if (!rmesa->radeon.swtcl.primitive_counter) {
+        if (rcommonEnsureCmdBufSpace(&rmesa->radeon,
+                    radeonCountStateEmitSize( &rmesa->radeon ) +
+                    (8 + 8 + 7), /* scissor + primis + VertexAOS */
+                    __FUNCTION__))
+            rmesa->radeon.swtcl.primitive_counter = 0;
+        else
+            rmesa->radeon.swtcl.primitive_counter = 1;
+    }
 }
 
 
@@ -284,9 +294,6 @@ void r100_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
 {
    r100ContextPtr rmesa = R100_CONTEXT(ctx);
 
-   rcommonEnsureCmdBufSpace(&rmesa->radeon,
-                           radeonCountStateEmitSize( &rmesa->radeon ) + (12*sizeof(int)),
-                           __FUNCTION__);
 
 
    radeonEmitState(&rmesa->radeon);
@@ -301,6 +308,9 @@ void r100_swtcl_flush(GLcontext *ctx, uint32_t current_offset)
                       rmesa->radeon.swtcl.hw_primitive,
                       rmesa->radeon.swtcl.numverts);
 
+
+   rmesa->radeon.swtcl.primitive_counter = 0;
+
 }
 
 /*
@@ -804,6 +814,7 @@ void radeonInitSwtcl( GLcontext *ctx )
    if (firsttime) {
       init_rast_tab();
       firsttime = 0;
+      rmesa->radeon.swtcl.primitive_counter = 0;
    }
 
    tnl->Driver.Render.Start = radeonRenderStart;