pContext->privateStateSize = pCreateInfo->privateStateSize;
- pContext->dcRing.Init(KNOB_MAX_DRAWS_IN_FLIGHT);
- pContext->dsRing.Init(KNOB_MAX_DRAWS_IN_FLIGHT);
+ pContext->MAX_DRAWS_IN_FLIGHT = KNOB_MAX_DRAWS_IN_FLIGHT;
+ if (pCreateInfo->MAX_DRAWS_IN_FLIGHT != 0)
+ {
+ pContext->MAX_DRAWS_IN_FLIGHT = pCreateInfo->MAX_DRAWS_IN_FLIGHT;
+ }
+
+ pContext->dcRing.Init(pContext->MAX_DRAWS_IN_FLIGHT);
+ pContext->dsRing.Init(pContext->MAX_DRAWS_IN_FLIGHT);
- pContext->pMacroTileManagerArray = (MacroTileMgr*)AlignedMalloc(sizeof(MacroTileMgr) * KNOB_MAX_DRAWS_IN_FLIGHT, 64);
- pContext->pDispatchQueueArray = (DispatchQueue*)AlignedMalloc(sizeof(DispatchQueue) * KNOB_MAX_DRAWS_IN_FLIGHT, 64);
+ pContext->pMacroTileManagerArray = (MacroTileMgr*)AlignedMalloc(sizeof(MacroTileMgr) * pContext->MAX_DRAWS_IN_FLIGHT, 64);
+ pContext->pDispatchQueueArray = (DispatchQueue*)AlignedMalloc(sizeof(DispatchQueue) * pContext->MAX_DRAWS_IN_FLIGHT, 64);
- for (uint32_t dc = 0; dc < KNOB_MAX_DRAWS_IN_FLIGHT; ++dc)
+ for (uint32_t dc = 0; dc < pContext->MAX_DRAWS_IN_FLIGHT; ++dc)
{
pContext->dcRing[dc].pArena = new CachingArena(pContext->cachingArenaAllocator);
new (&pContext->pMacroTileManagerArray[dc]) MacroTileMgr(*pContext->dcRing[dc].pArena);
pContext->dsRing[dc].pArena = new CachingArena(pContext->cachingArenaAllocator);
}
- pContext->threadInfo.MAX_WORKER_THREADS = KNOB_MAX_WORKER_THREADS;
- pContext->threadInfo.MAX_NUMA_NODES = KNOB_MAX_NUMA_NODES;
- pContext->threadInfo.MAX_CORES_PER_NUMA_NODE = KNOB_MAX_CORES_PER_NUMA_NODE;
- pContext->threadInfo.MAX_THREADS_PER_CORE = KNOB_MAX_THREADS_PER_CORE;
- pContext->threadInfo.SINGLE_THREADED = KNOB_SINGLE_THREADED;
-
if (pCreateInfo->pThreadInfo)
{
pContext->threadInfo = *pCreateInfo->pThreadInfo;
}
+ else
+ {
+ pContext->threadInfo.MAX_WORKER_THREADS = KNOB_MAX_WORKER_THREADS;
+ pContext->threadInfo.BASE_NUMA_NODE = KNOB_BASE_NUMA_NODE;
+ pContext->threadInfo.BASE_CORE = KNOB_BASE_CORE;
+ pContext->threadInfo.BASE_THREAD = KNOB_BASE_THREAD;
+ pContext->threadInfo.MAX_NUMA_NODES = KNOB_MAX_NUMA_NODES;
+ pContext->threadInfo.MAX_CORES_PER_NUMA_NODE = KNOB_MAX_CORES_PER_NUMA_NODE;
+ pContext->threadInfo.MAX_THREADS_PER_CORE = KNOB_MAX_THREADS_PER_CORE;
+ pContext->threadInfo.SINGLE_THREADED = KNOB_SINGLE_THREADED;
+ }
+
+ if (pCreateInfo->pApiThreadInfo)
+ {
+ pContext->apiThreadInfo = *pCreateInfo->pApiThreadInfo;
+ }
+ else
+ {
+ pContext->apiThreadInfo.bindAPIThread0 = true;
+ pContext->apiThreadInfo.numAPIReservedThreads = 1;
+ pContext->apiThreadInfo.numAPIThreadsPerCore = 1;
+ }
memset(&pContext->WaitLock, 0, sizeof(pContext->WaitLock));
memset(&pContext->FifosNotEmpty, 0, sizeof(pContext->FifosNotEmpty));
CreateThreadPool(pContext, &pContext->threadPool);
+ if (pContext->apiThreadInfo.bindAPIThread0)
+ {
+ BindApiThread(pContext, 0);
+ }
+
pContext->ppScratch = new uint8_t*[pContext->NumWorkerThreads];
- pContext->pStats = new SWR_STATS[pContext->NumWorkerThreads];
+ pContext->pStats = (SWR_STATS*)AlignedMalloc(sizeof(SWR_STATS) * pContext->NumWorkerThreads, 64);
#if defined(KNOB_ENABLE_AR)
// Setup ArchRast thread contexts which includes +1 for API thread.
#endif
}
+#if defined(KNOB_ENABLE_AR)
+ // cache the API thread event manager, for use with sim layer
+ pCreateInfo->hArEventManager = pContext->pArContext[pContext->NumWorkerThreads];
+#endif
+
// State setup AFTER context is fully initialized
SetupDefaultState(pContext);
void QueueWork(SWR_CONTEXT *pContext)
{
DRAW_CONTEXT* pDC = pContext->pCurDrawContext;
- uint32_t dcIndex = pDC->drawId % KNOB_MAX_DRAWS_IN_FLIGHT;
+ uint32_t dcIndex = pDC->drawId % pContext->MAX_DRAWS_IN_FLIGHT;
if (IsDraw)
{
if (IsDraw)
{
- InterlockedIncrement((volatile LONG*)&pContext->drawsOutstandingFE);
+ InterlockedIncrement(&pContext->drawsOutstandingFE);
}
_ReadWriteBarrier();
}
else
{
- AR_API_BEGIN(APIDrawWakeAllThreads, pDC->drawId);
+ RDTSC_BEGIN(APIDrawWakeAllThreads, pDC->drawId);
WakeAllThreads(pContext);
- AR_API_END(APIDrawWakeAllThreads, 1);
+ RDTSC_END(APIDrawWakeAllThreads, 1);
}
// Set current draw context to NULL so that next state call forces a new draw context to be created and populated.
DRAW_CONTEXT* GetDrawContext(SWR_CONTEXT *pContext, bool isSplitDraw = false)
{
- AR_API_BEGIN(APIGetDrawContext, 0);
+ RDTSC_BEGIN(APIGetDrawContext, 0);
// If current draw context is null then need to obtain a new draw context to use from ring.
if (pContext->pCurDrawContext == nullptr)
{
}
uint64_t curDraw = pContext->dcRing.GetHead();
- uint32_t dcIndex = curDraw % KNOB_MAX_DRAWS_IN_FLIGHT;
+ uint32_t dcIndex = curDraw % pContext->MAX_DRAWS_IN_FLIGHT;
if ((pContext->frameCount - pContext->lastFrameChecked) > 2 ||
(curDraw - pContext->lastDrawChecked) > 0x10000)
pContext->pCurDrawContext = pCurDrawContext;
// Assign next available entry in DS ring to this DC.
- uint32_t dsIndex = pContext->curStateId % KNOB_MAX_DRAWS_IN_FLIGHT;
+ uint32_t dsIndex = pContext->curStateId % pContext->MAX_DRAWS_IN_FLIGHT;
pCurDrawContext->pState = &pContext->dsRing[dsIndex];
// Copy previous state to current state.
pCurDrawContext->drawId = pContext->dcRing.GetHead();
pCurDrawContext->cleanupState = true;
-
}
else
{
SWR_ASSERT(isSplitDraw == false, "Split draw should only be used when obtaining a new DC");
}
- AR_API_END(APIGetDrawContext, 0);
+ RDTSC_END(APIGetDrawContext, 0);
return pContext->pCurDrawContext;
}
DestroyThreadPool(pContext, &pContext->threadPool);
// free the fifos
- for (uint32_t i = 0; i < KNOB_MAX_DRAWS_IN_FLIGHT; ++i)
+ for (uint32_t i = 0; i < pContext->MAX_DRAWS_IN_FLIGHT; ++i)
{
- delete[] pContext->dcRing[i].dynState.pStats;
+ AlignedFree(pContext->dcRing[i].dynState.pStats);
delete pContext->dcRing[i].pArena;
delete pContext->dsRing[i].pArena;
pContext->pMacroTileManagerArray[i].~MacroTileMgr();
}
delete[] pContext->ppScratch;
- delete[] pContext->pStats;
+ AlignedFree(pContext->pStats);
delete(pContext->pHotTileMgr);
AlignedFree(GetContext(hContext));
}
+void SwrBindApiThread(HANDLE hContext, uint32_t apiThreadId)
+{
+ SWR_CONTEXT *pContext = GetContext(hContext);
+ BindApiThread(pContext, apiThreadId);
+}
+
void SWR_API SwrSaveState(
HANDLE hContext,
void* pOutputStateBlock,
SWR_CONTEXT *pContext = GetContext(hContext);
DRAW_CONTEXT* pDC = GetDrawContext(pContext);
- AR_API_BEGIN(APISync, 0);
+ RDTSC_BEGIN(APISync, 0);
pDC->FeWork.type = SYNC;
pDC->FeWork.pfnWork = ProcessSync;
//enqueue
QueueDraw(pContext);
- AR_API_END(APISync, 1);
+ RDTSC_END(APISync, 1);
+}
+
+void SwrStallBE(HANDLE hContext)
+{
+ SWR_CONTEXT* pContext = GetContext(hContext);
+ DRAW_CONTEXT* pDC = GetDrawContext(pContext);
+
+ pDC->dependent = true;
}
void SwrWaitForIdle(HANDLE hContext)
{
SWR_CONTEXT *pContext = GetContext(hContext);
- AR_API_BEGIN(APIWaitForIdle, 0);
+ RDTSC_BEGIN(APIWaitForIdle, 0);
while (!pContext->dcRing.IsEmpty())
{
_mm_pause();
}
- AR_API_END(APIWaitForIdle, 1);
+ RDTSC_END(APIWaitForIdle, 1);
}
void SwrWaitForIdleFE(HANDLE hContext)
{
SWR_CONTEXT *pContext = GetContext(hContext);
- AR_API_BEGIN(APIWaitForIdle, 0);
+ RDTSC_BEGIN(APIWaitForIdle, 0);
while (pContext->drawsOutstandingFE > 0)
{
_mm_pause();
}
- AR_API_END(APIWaitForIdle, 1);
+ RDTSC_END(APIWaitForIdle, 1);
}
void SwrSetVertexBuffers(
// update guardband multipliers for the viewport
void updateGuardbands(API_STATE *pState)
{
- uint32_t numGbs = pState->gsState.emitsRenderTargetArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
+ uint32_t numGbs = pState->backendState.readViewportArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
for(uint32_t i = 0; i < numGbs; ++i)
{
void SetupMacroTileScissors(DRAW_CONTEXT *pDC)
{
API_STATE *pState = &pDC->pState->state;
- uint32_t numScissors = pState->gsState.emitsViewportArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
+ uint32_t numScissors = pState->backendState.readViewportArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
pState->scissorsTileAligned = true;
for (uint32_t index = 0; index < numScissors; ++index)
}
}
+
// templated backend function tables
-extern PFN_BACKEND_FUNC gBackendNullPs[SWR_MULTISAMPLE_TYPE_COUNT];
-extern PFN_BACKEND_FUNC gBackendSingleSample[SWR_INPUT_COVERAGE_COUNT][2][2];
-extern PFN_BACKEND_FUNC gBackendSampleRateTable[SWR_MULTISAMPLE_TYPE_COUNT][SWR_INPUT_COVERAGE_COUNT][2][2];
+
void SetupPipeline(DRAW_CONTEXT *pDC)
{
DRAW_STATE* pState = pDC->pState;
const uint32_t forcedSampleCount = (rastState.forcedSampleCount) ? 1 : 0;
const bool bMultisampleEnable = ((rastState.sampleCount > SWR_MULTISAMPLE_1X) || forcedSampleCount) ? 1 : 0;
const uint32_t centroid = ((psState.barycentricsMask & SWR_BARYCENTRIC_CENTROID_MASK) > 0) ? 1 : 0;
- const uint32_t canEarlyZ = (psState.forceEarlyZ || (!psState.writesODepth && !psState.usesSourceDepth && !psState.usesUAV)) ? 1 : 0;
+ const uint32_t canEarlyZ = (psState.forceEarlyZ || (!psState.writesODepth && !psState.usesUAV)) ? 1 : 0;
SWR_BARYCENTRICS_MASK barycentricsMask = (SWR_BARYCENTRICS_MASK)psState.barycentricsMask;
// select backend function
break;
}
}
-
+
+ SWR_ASSERT(backendFuncs.pfnBackend);
+
PFN_PROCESS_PRIMS pfnBinner;
#if USE_SIMD16_FRONTEND
PFN_PROCESS_PRIMS_SIMD16 pfnBinner_simd16;
};
- // disable clipper if viewport transform is disabled
+ // Disable clipper if viewport transform is disabled
if (pState->state.frontendState.vpTransformDisable)
{
pState->pfnProcessPrims = pfnBinner;
#endif
}
+ // Disable rasterizer and backend if no pixel, no depth/stencil, and no attributes
if ((pState->state.psState.pfnPixelShader == nullptr) &&
(pState->state.depthStencilState.depthTestEnable == FALSE) &&
(pState->state.depthStencilState.depthWriteEnable == FALSE) &&
(pState->state.depthStencilState.stencilTestEnable ||
pState->state.depthStencilState.stencilWriteEnable)) ? true : false;
- uint32_t numRTs = pState->state.psState.numRenderTargets;
- pState->state.colorHottileEnable = 0;
+
+ uint32_t hotTileEnable = pState->state.psState.renderTargetMask;
+
+ // Disable hottile for surfaces with no writes
if (psState.pfnPixelShader != nullptr)
{
- for (uint32_t rt = 0; rt < numRTs; ++rt)
+ DWORD rt;
+ uint32_t rtMask = pState->state.psState.renderTargetMask;
+ while (_BitScanForward(&rt, rtMask))
{
- pState->state.colorHottileEnable |=
- (!pState->state.blendState.renderTarget[rt].writeDisableAlpha ||
- !pState->state.blendState.renderTarget[rt].writeDisableRed ||
- !pState->state.blendState.renderTarget[rt].writeDisableGreen ||
- !pState->state.blendState.renderTarget[rt].writeDisableBlue) ? (1 << rt) : 0;
+ rtMask &= ~(1 << rt);
+
+ if (pState->state.blendState.renderTarget[rt].writeDisableAlpha &&
+ pState->state.blendState.renderTarget[rt].writeDisableRed &&
+ pState->state.blendState.renderTarget[rt].writeDisableGreen &&
+ pState->state.blendState.renderTarget[rt].writeDisableBlue)
+ {
+ hotTileEnable &= ~(1 << rt);
+ }
}
}
+ pState->state.colorHottileEnable = hotTileEnable;
+
+
// Setup depth quantization function
if (pState->state.depthHottileEnable)
{
SWR_CONTEXT *pContext = GetContext(hContext);
DRAW_CONTEXT* pDC = GetDrawContext(pContext);
- AR_API_BEGIN(APIDraw, pDC->drawId);
- AR_API_EVENT(DrawInstancedEvent(pDC->drawId, topology, numVertices, startVertex, numInstances, startInstance));
+ RDTSC_BEGIN(APIDraw, pDC->drawId);
+ AR_API_EVENT(DrawInstancedEvent(pDC->drawId, ArchRast::Instanced, topology, numVertices, startVertex, numInstances, startInstance));
uint32_t maxVertsPerDraw = MaxVertsPerDraw(pDC, numVertices, topology);
uint32_t primsPerDraw = GetNumPrims(topology, maxVertsPerDraw);
pState->rastState.cullMode = SWR_CULLMODE_NONE;
}
-
int draw = 0;
while (remainingVerts)
{
//enqueue DC
QueueDraw(pContext);
- AR_API_EVENT(DrawInstancedSplitEvent(pDC->drawId));
+ AR_API_EVENT(DrawInstancedSplitEvent(pDC->drawId, ArchRast::InstancedSplit));
remainingVerts -= numVertsForDraw;
draw++;
pDC = GetDrawContext(pContext);
pDC->pState->state.rastState.cullMode = oldCullMode;
-
- AR_API_END(APIDraw, numVertices * numInstances);
+ RDTSC_END(APIDraw, numVertices * numInstances);
}
//////////////////////////////////////////////////////////////////////////
DRAW_CONTEXT* pDC = GetDrawContext(pContext);
API_STATE* pState = &pDC->pState->state;
- AR_API_BEGIN(APIDrawIndexed, pDC->drawId);
- AR_API_EVENT(DrawIndexedInstancedEvent(pDC->drawId, topology, numIndices, indexOffset, baseVertex, numInstances, startInstance));
+ RDTSC_BEGIN(APIDrawIndexed, pDC->drawId);
+ AR_API_EVENT(DrawIndexedInstancedEvent(pDC->drawId, ArchRast::IndexedInstancedSplit, topology, numIndices, indexOffset, baseVertex, numInstances, startInstance));
uint32_t maxIndicesPerDraw = MaxVertsPerDraw(pDC, numIndices, topology);
uint32_t primsPerDraw = GetNumPrims(topology, maxIndicesPerDraw);
pState->rastState.cullMode = SWR_CULLMODE_NONE;
}
-
while (remainingIndices)
{
uint32_t numIndicesForDraw = (remainingIndices < maxIndicesPerDraw) ?
//enqueue DC
QueueDraw(pContext);
- AR_API_EVENT(DrawIndexedInstancedSplitEvent(pDC->drawId));
+ AR_API_EVENT(DrawIndexedInstancedSplitEvent(pDC->drawId, ArchRast::IndexedInstancedSplit));
pIB += maxIndicesPerDraw * indexSize;
remainingIndices -= numIndicesForDraw;
pDC = GetDrawContext(pContext);
pDC->pState->state.rastState.cullMode = oldCullMode;
-
- AR_API_END(APIDrawIndexed, numIndices * numInstances);
+ RDTSC_END(APIDrawIndexed, numIndices * numInstances);
}
SWR_CONTEXT *pContext = GetContext(hContext);
DRAW_CONTEXT* pDC = GetDrawContext(pContext);
- AR_API_BEGIN(APIDispatch, pDC->drawId);
+ RDTSC_BEGIN(APIDispatch, pDC->drawId);
AR_API_EVENT(DispatchEvent(pDC->drawId, threadGroupCountX, threadGroupCountY, threadGroupCountZ));
pDC->isCompute = true; // This is a compute context.
pTaskData->threadGroupCountZ = threadGroupCountZ;
uint32_t totalThreadGroups = threadGroupCountX * threadGroupCountY * threadGroupCountZ;
- uint32_t dcIndex = pDC->drawId % KNOB_MAX_DRAWS_IN_FLIGHT;
+ uint32_t dcIndex = pDC->drawId % pContext->MAX_DRAWS_IN_FLIGHT;
pDC->pDispatch = &pContext->pDispatchQueueArray[dcIndex];
pDC->pDispatch->initialize(totalThreadGroups, pTaskData, &ProcessComputeBE);
QueueDispatch(pContext);
- AR_API_END(APIDispatch, threadGroupCountX * threadGroupCountY * threadGroupCountZ);
+ RDTSC_END(APIDispatch, threadGroupCountX * threadGroupCountY * threadGroupCountZ);
}
// Deswizzles, converts and stores current contents of the hot tiles to surface
SWR_CONTEXT *pContext = GetContext(hContext);
DRAW_CONTEXT* pDC = GetDrawContext(pContext);
- AR_API_BEGIN(APIStoreTiles, pDC->drawId);
+ RDTSC_BEGIN(APIStoreTiles, pDC->drawId);
pDC->FeWork.type = STORETILES;
pDC->FeWork.pfnWork = ProcessStoreTiles;
AR_API_EVENT(SwrStoreTilesEvent(pDC->drawId));
- AR_API_END(APIStoreTiles, 1);
+ RDTSC_END(APIStoreTiles, 1);
}
//////////////////////////////////////////////////////////////////////////
SWR_CONTEXT *pContext = GetContext(hContext);
DRAW_CONTEXT* pDC = GetDrawContext(pContext);
- AR_API_BEGIN(APIClearRenderTarget, pDC->drawId);
+ RDTSC_BEGIN(APIClearRenderTarget, pDC->drawId);
pDC->FeWork.type = CLEAR;
pDC->FeWork.pfnWork = ProcessClear;
// enqueue draw
QueueDraw(pContext);
- AR_API_END(APIClearRenderTarget, 1);
+ RDTSC_END(APIClearRenderTarget, 1);
}
//////////////////////////////////////////////////////////////////////////
InitClearTilesTable();
InitBackendFuncTables();
+ InitRasterizerFunctions();
}
-
void SwrGetInterface(SWR_INTERFACE &out_funcs)
{
out_funcs.pfnSwrCreateContext = SwrCreateContext;
out_funcs.pfnSwrDestroyContext = SwrDestroyContext;
+ out_funcs.pfnSwrBindApiThread = SwrBindApiThread;
out_funcs.pfnSwrSaveState = SwrSaveState;
out_funcs.pfnSwrRestoreState = SwrRestoreState;
out_funcs.pfnSwrSync = SwrSync;
+ out_funcs.pfnSwrStallBE = SwrStallBE;
out_funcs.pfnSwrWaitForIdle = SwrWaitForIdle;
out_funcs.pfnSwrWaitForIdleFE = SwrWaitForIdleFE;
out_funcs.pfnSwrSetVertexBuffers = SwrSetVertexBuffers;