Rather than waiting for the API thread to re-use it.tags/12.0-branchpoint
@@ -297,6 +297,8 @@ DRAW_CONTEXT* GetDrawContext(SWR_CONTEXT *pContext, bool isSplitDraw = false) | |||
// Assign unique drawId for this DC | |||
pCurDrawContext->drawId = pContext->dcRing.GetHead(); | |||
pCurDrawContext->cleanupState = true; | |||
} | |||
else | |||
{ | |||
@@ -1076,6 +1078,8 @@ void DrawInstanced( | |||
pDC->FeWork.desc.draw.startPrimID = draw * primsPerDraw; | |||
pDC->FeWork.desc.draw.startVertexID = draw * maxVertsPerDraw; | |||
pDC->cleanupState = (remainingVerts == numVertsForDraw); | |||
//enqueue DC | |||
QueueDraw(pContext); | |||
@@ -1210,6 +1214,8 @@ void DrawIndexedInstance( | |||
pDC->FeWork.desc.draw.baseVertex = baseVertex; | |||
pDC->FeWork.desc.draw.startPrimID = draw * primsPerDraw; | |||
pDC->cleanupState = (remainingIndices == numIndicesForDraw); | |||
//enqueue DC | |||
QueueDraw(pContext); | |||
@@ -402,6 +402,8 @@ struct DRAW_CONTEXT | |||
CachingArena* pArena; | |||
uint8_t* pSpillFill[KNOB_MAX_NUM_THREADS]; // Scratch space used for spill fills. | |||
bool cleanupState; // True if this is the last draw using an entry in the state ring. | |||
}; | |||
INLINE const API_STATE& GetApiState(const DRAW_CONTEXT* pDC) |
@@ -287,11 +287,15 @@ INLINE void CompleteDrawContext(SWR_CONTEXT* pContext, DRAW_CONTEXT* pDC) | |||
if (result == 0) | |||
{ | |||
_ReadWriteBarrier(); | |||
// Cleanup memory allocations | |||
pDC->pArena->Reset(true); | |||
pDC->pTileMgr->initialize(); | |||
if (pDC->cleanupState) | |||
{ | |||
pDC->pState->pArena->Reset(true); | |||
} | |||
_ReadWriteBarrier(); | |||
pContext->dcRing.Dequeue(); // Remove from tail | |||
} |