[Mesa-dev] [PATCH v2 14/14] swr: [rasterizer core] fix dependency bug

Tim Rowley timothy.o.rowley at intel.com
Mon Jun 20 21:37:08 UTC 2016


Never be dependent on "draw 0", instead have a bool that makes the draw
dependent on the previous draw or not dependent at all.
---
 src/gallium/drivers/swr/rasterizer/core/api.cpp      | 6 +++---
 src/gallium/drivers/swr/rasterizer/core/context.h    | 4 ++--
 src/gallium/drivers/swr/rasterizer/core/ringbuffer.h | 8 ++++----
 src/gallium/drivers/swr/rasterizer/core/threads.cpp  | 2 +-
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/gallium/drivers/swr/rasterizer/core/api.cpp b/src/gallium/drivers/swr/rasterizer/core/api.cpp
index b63d547..edde918 100644
--- a/src/gallium/drivers/swr/rasterizer/core/api.cpp
+++ b/src/gallium/drivers/swr/rasterizer/core/api.cpp
@@ -322,7 +322,7 @@ DRAW_CONTEXT* GetDrawContext(SWR_CONTEXT *pContext, bool isSplitDraw = false)
 
         SWR_ASSERT(pCurDrawContext->pArena->IsEmpty() == true);
 
-        pCurDrawContext->dependency = 0;
+        pCurDrawContext->dependent = false;
         pCurDrawContext->pContext = pContext;
         pCurDrawContext->isCompute = false; // Dispatch has to set this to true.
 
@@ -406,7 +406,7 @@ void SwrSync(HANDLE hContext, PFN_CALLBACK_FUNC pfnFunc, uint64_t userData, uint
     pDC->FeWork.desc.sync.userData3 = userData3;
 
     // cannot execute until all previous draws have completed
-    pDC->dependency = pDC->drawId - 1;
+    pDC->dependent = true;
 
     //enqueue
     QueueDraw(pContext);
@@ -1500,7 +1500,7 @@ void SwrGetStats(
     pDC->FeWork.desc.queryStats.pStats = pStats;
 
     // cannot execute until all previous draws have completed
-    pDC->dependency = pDC->drawId - 1;
+    pDC->dependent = true;
 
     //enqueue
     QueueDraw(pContext);
diff --git a/src/gallium/drivers/swr/rasterizer/core/context.h b/src/gallium/drivers/swr/rasterizer/core/context.h
index 08eadf4..be4c2e9 100644
--- a/src/gallium/drivers/swr/rasterizer/core/context.h
+++ b/src/gallium/drivers/swr/rasterizer/core/context.h
@@ -381,8 +381,6 @@ struct DRAW_STATE
 struct DRAW_CONTEXT
 {
     SWR_CONTEXT*    pContext;
-    uint32_t        drawId;
-    uint32_t        dependency;
     union
     {
         MacroTileMgr*   pTileMgr;
@@ -391,6 +389,8 @@ struct DRAW_CONTEXT
     DRAW_STATE*     pState;
     CachingArena*   pArena;
 
+    uint32_t        drawId;
+    bool            dependent;
     bool            isCompute;      // Is this DC a compute context?
     bool            cleanupState;   // True if this is the last draw using an entry in the state ring.
     volatile bool   doneFE;         // Is FE work done for this draw?
diff --git a/src/gallium/drivers/swr/rasterizer/core/ringbuffer.h b/src/gallium/drivers/swr/rasterizer/core/ringbuffer.h
index 97f75c6..f1bef21 100644
--- a/src/gallium/drivers/swr/rasterizer/core/ringbuffer.h
+++ b/src/gallium/drivers/swr/rasterizer/core/ringbuffer.h
@@ -46,6 +46,7 @@ public:
     void Init(uint32_t numEntries)
     {
         SWR_ASSERT(numEntries > 0);
+        SWR_ASSERT(((1ULL << 32) % numEntries) == 0, "%d is not evenly divisible into 2 ^ 32.  Wrap errors will occur!", numEntries);
         mNumEntries = numEntries;
         mpRingBuffer = (T*)AlignedMalloc(sizeof(T)*numEntries, 64);
         SWR_ASSERT(mpRingBuffer != nullptr);
@@ -67,6 +68,8 @@ public:
     INLINE void Enqueue()
     {
         mRingHead++; // There's only one producer.
+        // Assert to find wrap-around cases, NEVER ENABLE DURING CHECKIN!!
+        // SWR_REL_ASSERT(mRingHead);
     }
 
     INLINE void Dequeue()
@@ -81,10 +84,7 @@ public:
 
     INLINE bool IsFull()
     {
-        ///@note We don't handle wrap case due to using 64-bit indices.
-        ///      It would take 11 million years to wrap at 50,000 DCs per sec.
-        ///      If we used 32-bit indices then its about 23 hours to wrap.
-        uint64_t numEnqueued = GetHead() - GetTail();
+        uint32_t numEnqueued = GetHead() - GetTail();
         SWR_ASSERT(numEnqueued <= mNumEntries);
 
         return (numEnqueued == mNumEntries);
diff --git a/src/gallium/drivers/swr/rasterizer/core/threads.cpp b/src/gallium/drivers/swr/rasterizer/core/threads.cpp
index fe164a0..9671f77 100644
--- a/src/gallium/drivers/swr/rasterizer/core/threads.cpp
+++ b/src/gallium/drivers/swr/rasterizer/core/threads.cpp
@@ -317,7 +317,7 @@ bool IDComparesLess(uint32_t a, uint32_t b)
 INLINE
 bool CheckDependency(SWR_CONTEXT *pContext, DRAW_CONTEXT *pDC, uint32_t lastRetiredDraw)
 {
-    return IDComparesLess(lastRetiredDraw, pDC->dependency);
+    return pDC->dependent && IDComparesLess(lastRetiredDraw, pDC->drawId - 1);
 }
 
 // inlined-only version
-- 
1.9.1



More information about the mesa-dev mailing list