swr/rast: add SwrGetInterface() function to return api
[mesa.git] / src / gallium / drivers / swr / rasterizer / core / api.cpp
1 /****************************************************************************
2 * Copyright (C) 2014-2016 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * @file api.cpp
24 *
25 * @brief API implementation
26 *
27 ******************************************************************************/
28
29 #include <cfloat>
30 #include <cmath>
31 #include <cstdio>
32 #include <new>
33
34 #include "core/api.h"
35 #include "core/backend.h"
36 #include "core/context.h"
37 #include "core/depthstencil.h"
38 #include "core/frontend.h"
39 #include "core/rasterizer.h"
40 #include "core/rdtsc_core.h"
41 #include "core/threads.h"
42 #include "core/tilemgr.h"
43 #include "core/clip.h"
44 #include "core/utils.h"
45
46 #include "common/os.h"
47
48 static const SWR_RECT g_MaxScissorRect = { 0, 0, KNOB_MAX_SCISSOR_X, KNOB_MAX_SCISSOR_Y };
49
50 void SetupDefaultState(SWR_CONTEXT *pContext);
51
52 static INLINE SWR_CONTEXT* GetContext(HANDLE hContext)
53 {
54 return (SWR_CONTEXT*)hContext;
55 }
56
57 void WakeAllThreads(SWR_CONTEXT *pContext)
58 {
59 pContext->FifosNotEmpty.notify_all();
60 }
61
62 //////////////////////////////////////////////////////////////////////////
63 /// @brief Create SWR Context.
64 /// @param pCreateInfo - pointer to creation info.
65 HANDLE SwrCreateContext(
66 SWR_CREATECONTEXT_INFO* pCreateInfo)
67 {
68 RDTSC_RESET();
69 RDTSC_INIT(0);
70
71 void* pContextMem = AlignedMalloc(sizeof(SWR_CONTEXT), KNOB_SIMD_WIDTH * 4);
72 memset(pContextMem, 0, sizeof(SWR_CONTEXT));
73 SWR_CONTEXT *pContext = new (pContextMem) SWR_CONTEXT();
74
75 pContext->privateStateSize = pCreateInfo->privateStateSize;
76
77 pContext->dcRing.Init(KNOB_MAX_DRAWS_IN_FLIGHT);
78 pContext->dsRing.Init(KNOB_MAX_DRAWS_IN_FLIGHT);
79
80 pContext->pMacroTileManagerArray = (MacroTileMgr*)AlignedMalloc(sizeof(MacroTileMgr) * KNOB_MAX_DRAWS_IN_FLIGHT, 64);
81 pContext->pDispatchQueueArray = (DispatchQueue*)AlignedMalloc(sizeof(DispatchQueue) * KNOB_MAX_DRAWS_IN_FLIGHT, 64);
82
83 for (uint32_t dc = 0; dc < KNOB_MAX_DRAWS_IN_FLIGHT; ++dc)
84 {
85 pContext->dcRing[dc].pArena = new CachingArena(pContext->cachingArenaAllocator);
86 new (&pContext->pMacroTileManagerArray[dc]) MacroTileMgr(*pContext->dcRing[dc].pArena);
87 new (&pContext->pDispatchQueueArray[dc]) DispatchQueue();
88
89 pContext->dsRing[dc].pArena = new CachingArena(pContext->cachingArenaAllocator);
90 }
91
92 pContext->threadInfo.MAX_WORKER_THREADS = KNOB_MAX_WORKER_THREADS;
93 pContext->threadInfo.MAX_NUMA_NODES = KNOB_MAX_NUMA_NODES;
94 pContext->threadInfo.MAX_CORES_PER_NUMA_NODE = KNOB_MAX_CORES_PER_NUMA_NODE;
95 pContext->threadInfo.MAX_THREADS_PER_CORE = KNOB_MAX_THREADS_PER_CORE;
96 pContext->threadInfo.SINGLE_THREADED = KNOB_SINGLE_THREADED;
97
98 if (pCreateInfo->pThreadInfo)
99 {
100 pContext->threadInfo = *pCreateInfo->pThreadInfo;
101 }
102
103 memset(&pContext->WaitLock, 0, sizeof(pContext->WaitLock));
104 memset(&pContext->FifosNotEmpty, 0, sizeof(pContext->FifosNotEmpty));
105 new (&pContext->WaitLock) std::mutex();
106 new (&pContext->FifosNotEmpty) std::condition_variable();
107
108 CreateThreadPool(pContext, &pContext->threadPool);
109
110 pContext->ppScratch = new uint8_t*[pContext->NumWorkerThreads];
111 pContext->pStats = new SWR_STATS[pContext->NumWorkerThreads];
112
113 #if defined(KNOB_ENABLE_AR)
114 // Setup ArchRast thread contexts which includes +1 for API thread.
115 pContext->pArContext = new HANDLE[pContext->NumWorkerThreads+1];
116 pContext->pArContext[pContext->NumWorkerThreads] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::API);
117 #endif
118
119 // Allocate scratch space for workers.
120 ///@note We could lazily allocate this but its rather small amount of memory.
121 for (uint32_t i = 0; i < pContext->NumWorkerThreads; ++i)
122 {
123 #if defined(_WIN32)
124 uint32_t numaNode = pContext->threadPool.pThreadData ?
125 pContext->threadPool.pThreadData[i].numaId : 0;
126 pContext->ppScratch[i] = (uint8_t*)VirtualAllocExNuma(
127 GetCurrentProcess(), nullptr, 32 * sizeof(KILOBYTE),
128 MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE,
129 numaNode);
130 #else
131 pContext->ppScratch[i] = (uint8_t*)AlignedMalloc(32 * sizeof(KILOBYTE), KNOB_SIMD_WIDTH * 4);
132 #endif
133
134 #if defined(KNOB_ENABLE_AR)
135 // Initialize worker thread context for ArchRast.
136 pContext->pArContext[i] = ArchRast::CreateThreadContext(ArchRast::AR_THREAD::WORKER);
137 #endif
138 }
139
140 // State setup AFTER context is fully initialized
141 SetupDefaultState(pContext);
142
143 // initialize hot tile manager
144 pContext->pHotTileMgr = new HotTileMgr();
145
146 // initialize function pointer tables
147 InitClearTilesTable();
148
149 // initialize callback functions
150 pContext->pfnLoadTile = pCreateInfo->pfnLoadTile;
151 pContext->pfnStoreTile = pCreateInfo->pfnStoreTile;
152 pContext->pfnClearTile = pCreateInfo->pfnClearTile;
153 pContext->pfnUpdateSoWriteOffset = pCreateInfo->pfnUpdateSoWriteOffset;
154 pContext->pfnUpdateStats = pCreateInfo->pfnUpdateStats;
155 pContext->pfnUpdateStatsFE = pCreateInfo->pfnUpdateStatsFE;
156
157
158 // pass pointer to bucket manager back to caller
159 #ifdef KNOB_ENABLE_RDTSC
160 pCreateInfo->pBucketMgr = &gBucketMgr;
161 #endif
162
163 pCreateInfo->contextSaveSize = sizeof(API_STATE);
164
165 StartThreadPool(pContext, &pContext->threadPool);
166
167 return (HANDLE)pContext;
168 }
169
170 void CopyState(DRAW_STATE& dst, const DRAW_STATE& src)
171 {
172 memcpy(&dst.state, &src.state, sizeof(API_STATE));
173 }
174
175 template<bool IsDraw>
176 void QueueWork(SWR_CONTEXT *pContext)
177 {
178 DRAW_CONTEXT* pDC = pContext->pCurDrawContext;
179 uint32_t dcIndex = pDC->drawId % KNOB_MAX_DRAWS_IN_FLIGHT;
180
181 if (IsDraw)
182 {
183 pDC->pTileMgr = &pContext->pMacroTileManagerArray[dcIndex];
184 pDC->pTileMgr->initialize();
185 }
186
187 // Each worker thread looks at a DC for both FE and BE work at different times and so we
188 // multiply threadDone by 2. When the threadDone counter has reached 0 then all workers
189 // have moved past this DC. (i.e. Each worker has checked this DC for both FE and BE work and
190 // then moved on if all work is done.)
191 pContext->pCurDrawContext->threadsDone = pContext->NumFEThreads + pContext->NumBEThreads;
192
193 if (IsDraw)
194 {
195 InterlockedIncrement((volatile LONG*)&pContext->drawsOutstandingFE);
196 }
197
198 _ReadWriteBarrier();
199 {
200 std::unique_lock<std::mutex> lock(pContext->WaitLock);
201 pContext->dcRing.Enqueue();
202 }
203
204 if (pContext->threadInfo.SINGLE_THREADED)
205 {
206 // flush denormals to 0
207 uint32_t mxcsr = _mm_getcsr();
208 _mm_setcsr(mxcsr | _MM_FLUSH_ZERO_ON | _MM_DENORMALS_ZERO_ON);
209
210 if (IsDraw)
211 {
212 uint32_t curDraw[2] = { pContext->pCurDrawContext->drawId, pContext->pCurDrawContext->drawId };
213 WorkOnFifoFE(pContext, 0, curDraw[0]);
214 WorkOnFifoBE(pContext, 0, curDraw[1], pContext->singleThreadLockedTiles, 0, 0);
215 }
216 else
217 {
218 uint32_t curDispatch = pContext->pCurDrawContext->drawId;
219 WorkOnCompute(pContext, 0, curDispatch);
220 }
221
222 // Dequeue the work here, if not already done, since we're single threaded (i.e. no workers).
223 while (CompleteDrawContext(pContext, pContext->pCurDrawContext) > 0) {}
224
225 // restore csr
226 _mm_setcsr(mxcsr);
227 }
228 else
229 {
230 AR_API_BEGIN(APIDrawWakeAllThreads, pDC->drawId);
231 WakeAllThreads(pContext);
232 AR_API_END(APIDrawWakeAllThreads, 1);
233 }
234
235 // Set current draw context to NULL so that next state call forces a new draw context to be created and populated.
236 pContext->pPrevDrawContext = pContext->pCurDrawContext;
237 pContext->pCurDrawContext = nullptr;
238 }
239
240 INLINE void QueueDraw(SWR_CONTEXT* pContext)
241 {
242 QueueWork<true>(pContext);
243 }
244
245 INLINE void QueueDispatch(SWR_CONTEXT* pContext)
246 {
247 QueueWork<false>(pContext);
248 }
249
250 DRAW_CONTEXT* GetDrawContext(SWR_CONTEXT *pContext, bool isSplitDraw = false)
251 {
252 AR_API_BEGIN(APIGetDrawContext, 0);
253 // If current draw context is null then need to obtain a new draw context to use from ring.
254 if (pContext->pCurDrawContext == nullptr)
255 {
256 // Need to wait for a free entry.
257 while (pContext->dcRing.IsFull())
258 {
259 _mm_pause();
260 }
261
262 uint64_t curDraw = pContext->dcRing.GetHead();
263 uint32_t dcIndex = curDraw % KNOB_MAX_DRAWS_IN_FLIGHT;
264
265 if ((pContext->frameCount - pContext->lastFrameChecked) > 2 ||
266 (curDraw - pContext->lastDrawChecked) > 0x10000)
267 {
268 // Take this opportunity to clean-up old arena allocations
269 pContext->cachingArenaAllocator.FreeOldBlocks();
270
271 pContext->lastFrameChecked = pContext->frameCount;
272 pContext->lastDrawChecked = curDraw;
273 }
274
275 DRAW_CONTEXT* pCurDrawContext = &pContext->dcRing[dcIndex];
276 pContext->pCurDrawContext = pCurDrawContext;
277
278 // Assign next available entry in DS ring to this DC.
279 uint32_t dsIndex = pContext->curStateId % KNOB_MAX_DRAWS_IN_FLIGHT;
280 pCurDrawContext->pState = &pContext->dsRing[dsIndex];
281
282 // Copy previous state to current state.
283 if (pContext->pPrevDrawContext)
284 {
285 DRAW_CONTEXT* pPrevDrawContext = pContext->pPrevDrawContext;
286
287 // If we're splitting our draw then we can just use the same state from the previous
288 // draw. In this case, we won't increment the DS ring index so the next non-split
289 // draw can receive the state.
290 if (isSplitDraw == false)
291 {
292 CopyState(*pCurDrawContext->pState, *pPrevDrawContext->pState);
293
294 // Should have been cleaned up previously
295 SWR_ASSERT(pCurDrawContext->pState->pArena->IsEmpty() == true);
296
297 pCurDrawContext->pState->pPrivateState = nullptr;
298
299 pContext->curStateId++; // Progress state ring index forward.
300 }
301 else
302 {
303 // If its a split draw then just copy the state pointer over
304 // since its the same draw.
305 pCurDrawContext->pState = pPrevDrawContext->pState;
306 SWR_ASSERT(pPrevDrawContext->cleanupState == false);
307 }
308 }
309 else
310 {
311 SWR_ASSERT(pCurDrawContext->pState->pArena->IsEmpty() == true);
312 pContext->curStateId++; // Progress state ring index forward.
313 }
314
315 SWR_ASSERT(pCurDrawContext->pArena->IsEmpty() == true);
316
317 // Reset dependency
318 pCurDrawContext->dependent = false;
319 pCurDrawContext->dependentFE = false;
320
321 pCurDrawContext->pContext = pContext;
322 pCurDrawContext->isCompute = false; // Dispatch has to set this to true.
323
324 pCurDrawContext->doneFE = false;
325 pCurDrawContext->FeLock = 0;
326 pCurDrawContext->threadsDone = 0;
327 pCurDrawContext->retireCallback.pfnCallbackFunc = nullptr;
328
329 pCurDrawContext->dynState.Reset(pContext->NumWorkerThreads);
330
331 // Assign unique drawId for this DC
332 pCurDrawContext->drawId = pContext->dcRing.GetHead();
333
334 pCurDrawContext->cleanupState = true;
335
336 }
337 else
338 {
339 SWR_ASSERT(isSplitDraw == false, "Split draw should only be used when obtaining a new DC");
340 }
341
342 AR_API_END(APIGetDrawContext, 0);
343 return pContext->pCurDrawContext;
344 }
345
346 API_STATE* GetDrawState(SWR_CONTEXT *pContext)
347 {
348 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
349 SWR_ASSERT(pDC->pState != nullptr);
350
351 return &pDC->pState->state;
352 }
353
354 void SwrDestroyContext(HANDLE hContext)
355 {
356 SWR_CONTEXT *pContext = GetContext(hContext);
357 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
358
359 pDC->FeWork.type = SHUTDOWN;
360 pDC->FeWork.pfnWork = ProcessShutdown;
361
362 //enqueue
363 QueueDraw(pContext);
364
365 DestroyThreadPool(pContext, &pContext->threadPool);
366
367 // free the fifos
368 for (uint32_t i = 0; i < KNOB_MAX_DRAWS_IN_FLIGHT; ++i)
369 {
370 delete[] pContext->dcRing[i].dynState.pStats;
371 delete pContext->dcRing[i].pArena;
372 delete pContext->dsRing[i].pArena;
373 pContext->pMacroTileManagerArray[i].~MacroTileMgr();
374 pContext->pDispatchQueueArray[i].~DispatchQueue();
375 }
376
377 AlignedFree(pContext->pDispatchQueueArray);
378 AlignedFree(pContext->pMacroTileManagerArray);
379
380 // Free scratch space.
381 for (uint32_t i = 0; i < pContext->NumWorkerThreads; ++i)
382 {
383 #if defined(_WIN32)
384 VirtualFree(pContext->ppScratch[i], 0, MEM_RELEASE);
385 #else
386 AlignedFree(pContext->ppScratch[i]);
387 #endif
388
389 #if defined(KNOB_ENABLE_AR)
390 ArchRast::DestroyThreadContext(pContext->pArContext[i]);
391 #endif
392 }
393
394 delete[] pContext->ppScratch;
395 delete[] pContext->pStats;
396
397 delete(pContext->pHotTileMgr);
398
399 pContext->~SWR_CONTEXT();
400 AlignedFree(GetContext(hContext));
401 }
402
403 void SWR_API SwrSaveState(
404 HANDLE hContext,
405 void* pOutputStateBlock,
406 size_t memSize)
407 {
408 SWR_CONTEXT *pContext = GetContext(hContext);
409 auto pSrc = GetDrawState(pContext);
410 SWR_ASSERT(pOutputStateBlock && memSize >= sizeof(*pSrc));
411
412 memcpy(pOutputStateBlock, pSrc, sizeof(*pSrc));
413 }
414
415 void SWR_API SwrRestoreState(
416 HANDLE hContext,
417 const void* pStateBlock,
418 size_t memSize)
419 {
420 SWR_CONTEXT *pContext = GetContext(hContext);
421 auto pDst = GetDrawState(pContext);
422 SWR_ASSERT(pStateBlock && memSize >= sizeof(*pDst));
423
424 memcpy(pDst, pStateBlock, sizeof(*pDst));
425 }
426
427 void SetupDefaultState(SWR_CONTEXT *pContext)
428 {
429 API_STATE* pState = GetDrawState(pContext);
430
431 pState->rastState.cullMode = SWR_CULLMODE_NONE;
432 pState->rastState.frontWinding = SWR_FRONTWINDING_CCW;
433
434 pState->depthBoundsState.depthBoundsTestEnable = false;
435 pState->depthBoundsState.depthBoundsTestMinValue = 0.0f;
436 pState->depthBoundsState.depthBoundsTestMaxValue = 1.0f;
437 }
438
439 void SwrSync(HANDLE hContext, PFN_CALLBACK_FUNC pfnFunc, uint64_t userData, uint64_t userData2, uint64_t userData3)
440 {
441 SWR_ASSERT(pfnFunc != nullptr);
442
443 SWR_CONTEXT *pContext = GetContext(hContext);
444 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
445
446 AR_API_BEGIN(APISync, 0);
447
448 pDC->FeWork.type = SYNC;
449 pDC->FeWork.pfnWork = ProcessSync;
450
451 // Setup callback function
452 pDC->retireCallback.pfnCallbackFunc = pfnFunc;
453 pDC->retireCallback.userData = userData;
454 pDC->retireCallback.userData2 = userData2;
455 pDC->retireCallback.userData3 = userData3;
456
457 AR_API_EVENT(SwrSyncEvent(pDC->drawId));
458
459 //enqueue
460 QueueDraw(pContext);
461
462 AR_API_END(APISync, 1);
463 }
464
465 void SwrWaitForIdle(HANDLE hContext)
466 {
467 SWR_CONTEXT *pContext = GetContext(hContext);
468
469 AR_API_BEGIN(APIWaitForIdle, 0);
470
471 while (!pContext->dcRing.IsEmpty())
472 {
473 _mm_pause();
474 }
475
476 AR_API_END(APIWaitForIdle, 1);
477 }
478
479 void SwrWaitForIdleFE(HANDLE hContext)
480 {
481 SWR_CONTEXT *pContext = GetContext(hContext);
482
483 AR_API_BEGIN(APIWaitForIdle, 0);
484
485 while (pContext->drawsOutstandingFE > 0)
486 {
487 _mm_pause();
488 }
489
490 AR_API_END(APIWaitForIdle, 1);
491 }
492
493 void SwrSetVertexBuffers(
494 HANDLE hContext,
495 uint32_t numBuffers,
496 const SWR_VERTEX_BUFFER_STATE* pVertexBuffers)
497 {
498 API_STATE* pState = GetDrawState(GetContext(hContext));
499
500 for (uint32_t i = 0; i < numBuffers; ++i)
501 {
502 const SWR_VERTEX_BUFFER_STATE *pVB = &pVertexBuffers[i];
503 pState->vertexBuffers[pVB->index] = *pVB;
504 }
505 }
506
507 void SwrSetIndexBuffer(
508 HANDLE hContext,
509 const SWR_INDEX_BUFFER_STATE* pIndexBuffer)
510 {
511 API_STATE* pState = GetDrawState(GetContext(hContext));
512
513 pState->indexBuffer = *pIndexBuffer;
514 }
515
516 void SwrSetFetchFunc(
517 HANDLE hContext,
518 PFN_FETCH_FUNC pfnFetchFunc)
519 {
520 API_STATE* pState = GetDrawState(GetContext(hContext));
521
522 pState->pfnFetchFunc = pfnFetchFunc;
523 }
524
525 void SwrSetSoFunc(
526 HANDLE hContext,
527 PFN_SO_FUNC pfnSoFunc,
528 uint32_t streamIndex)
529 {
530 API_STATE* pState = GetDrawState(GetContext(hContext));
531
532 SWR_ASSERT(streamIndex < MAX_SO_STREAMS);
533
534 pState->pfnSoFunc[streamIndex] = pfnSoFunc;
535 }
536
537 void SwrSetSoState(
538 HANDLE hContext,
539 SWR_STREAMOUT_STATE* pSoState)
540 {
541 API_STATE* pState = GetDrawState(GetContext(hContext));
542
543 pState->soState = *pSoState;
544 }
545
546 void SwrSetSoBuffers(
547 HANDLE hContext,
548 SWR_STREAMOUT_BUFFER* pSoBuffer,
549 uint32_t slot)
550 {
551 API_STATE* pState = GetDrawState(GetContext(hContext));
552
553 SWR_ASSERT((slot < 4), "There are only 4 SO buffer slots [0, 3]\nSlot requested: %d", slot);
554
555 pState->soBuffer[slot] = *pSoBuffer;
556 }
557
558 void SwrSetVertexFunc(
559 HANDLE hContext,
560 PFN_VERTEX_FUNC pfnVertexFunc)
561 {
562 API_STATE* pState = GetDrawState(GetContext(hContext));
563
564 pState->pfnVertexFunc = pfnVertexFunc;
565 }
566
567 void SwrSetFrontendState(
568 HANDLE hContext,
569 SWR_FRONTEND_STATE *pFEState)
570 {
571 API_STATE* pState = GetDrawState(GetContext(hContext));
572 pState->frontendState = *pFEState;
573 }
574
575 void SwrSetGsState(
576 HANDLE hContext,
577 SWR_GS_STATE *pGSState)
578 {
579 API_STATE* pState = GetDrawState(GetContext(hContext));
580 pState->gsState = *pGSState;
581 }
582
583 void SwrSetGsFunc(
584 HANDLE hContext,
585 PFN_GS_FUNC pfnGsFunc)
586 {
587 API_STATE* pState = GetDrawState(GetContext(hContext));
588 pState->pfnGsFunc = pfnGsFunc;
589 }
590
591 void SwrSetCsFunc(
592 HANDLE hContext,
593 PFN_CS_FUNC pfnCsFunc,
594 uint32_t totalThreadsInGroup,
595 uint32_t totalSpillFillSize,
596 uint32_t scratchSpaceSizePerInstance,
597 uint32_t numInstances)
598 {
599 API_STATE* pState = GetDrawState(GetContext(hContext));
600 pState->pfnCsFunc = pfnCsFunc;
601 pState->totalThreadsInGroup = totalThreadsInGroup;
602 pState->totalSpillFillSize = totalSpillFillSize;
603 pState->scratchSpaceSize = scratchSpaceSizePerInstance;
604 pState->scratchSpaceNumInstances = numInstances;
605 }
606
607 void SwrSetTsState(
608 HANDLE hContext,
609 SWR_TS_STATE *pState)
610 {
611 API_STATE* pApiState = GetDrawState(GetContext(hContext));
612 pApiState->tsState = *pState;
613 }
614
615 void SwrSetHsFunc(
616 HANDLE hContext,
617 PFN_HS_FUNC pfnFunc)
618 {
619 API_STATE* pApiState = GetDrawState(GetContext(hContext));
620 pApiState->pfnHsFunc = pfnFunc;
621 }
622
623 void SwrSetDsFunc(
624 HANDLE hContext,
625 PFN_DS_FUNC pfnFunc)
626 {
627 API_STATE* pApiState = GetDrawState(GetContext(hContext));
628 pApiState->pfnDsFunc = pfnFunc;
629 }
630
631 void SwrSetDepthStencilState(
632 HANDLE hContext,
633 SWR_DEPTH_STENCIL_STATE *pDSState)
634 {
635 API_STATE* pState = GetDrawState(GetContext(hContext));
636
637 pState->depthStencilState = *pDSState;
638 }
639
640 void SwrSetBackendState(
641 HANDLE hContext,
642 SWR_BACKEND_STATE *pBEState)
643 {
644 API_STATE* pState = GetDrawState(GetContext(hContext));
645
646 pState->backendState = *pBEState;
647 }
648
649 void SwrSetDepthBoundsState(
650 HANDLE hContext,
651 SWR_DEPTH_BOUNDS_STATE *pDBState)
652 {
653 API_STATE* pState = GetDrawState(GetContext(hContext));
654
655 pState->depthBoundsState = *pDBState;
656 }
657
658 void SwrSetPixelShaderState(
659 HANDLE hContext,
660 SWR_PS_STATE *pPSState)
661 {
662 API_STATE *pState = GetDrawState(GetContext(hContext));
663 pState->psState = *pPSState;
664 }
665
666 void SwrSetBlendState(
667 HANDLE hContext,
668 SWR_BLEND_STATE *pBlendState)
669 {
670 API_STATE *pState = GetDrawState(GetContext(hContext));
671 memcpy(&pState->blendState, pBlendState, sizeof(SWR_BLEND_STATE));
672 }
673
674 void SwrSetBlendFunc(
675 HANDLE hContext,
676 uint32_t renderTarget,
677 PFN_BLEND_JIT_FUNC pfnBlendFunc)
678 {
679 SWR_ASSERT(renderTarget < SWR_NUM_RENDERTARGETS);
680 API_STATE *pState = GetDrawState(GetContext(hContext));
681 pState->pfnBlendFunc[renderTarget] = pfnBlendFunc;
682 }
683
684 // update guardband multipliers for the viewport
685 void updateGuardbands(API_STATE *pState)
686 {
687 uint32_t numGbs = pState->gsState.emitsRenderTargetArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
688
689 for(uint32_t i = 0; i < numGbs; ++i)
690 {
691 // guardband center is viewport center
692 pState->gbState.left[i] = KNOB_GUARDBAND_WIDTH / pState->vp[i].width;
693 pState->gbState.right[i] = KNOB_GUARDBAND_WIDTH / pState->vp[i].width;
694 pState->gbState.top[i] = KNOB_GUARDBAND_HEIGHT / pState->vp[i].height;
695 pState->gbState.bottom[i] = KNOB_GUARDBAND_HEIGHT / pState->vp[i].height;
696 }
697 }
698
699 void SwrSetRastState(
700 HANDLE hContext,
701 const SWR_RASTSTATE *pRastState)
702 {
703 SWR_CONTEXT *pContext = GetContext(hContext);
704 API_STATE* pState = GetDrawState(pContext);
705
706 memcpy(&pState->rastState, pRastState, sizeof(SWR_RASTSTATE));
707 }
708
709 void SwrSetViewports(
710 HANDLE hContext,
711 uint32_t numViewports,
712 const SWR_VIEWPORT* pViewports,
713 const SWR_VIEWPORT_MATRICES* pMatrices)
714 {
715 SWR_ASSERT(numViewports <= KNOB_NUM_VIEWPORTS_SCISSORS,
716 "Invalid number of viewports.");
717
718 SWR_CONTEXT *pContext = GetContext(hContext);
719 API_STATE* pState = GetDrawState(pContext);
720
721 memcpy(&pState->vp[0], pViewports, sizeof(SWR_VIEWPORT) * numViewports);
722 // @todo Faster to copy portions of the SOA or just copy all of it?
723 memcpy(&pState->vpMatrices, pMatrices, sizeof(SWR_VIEWPORT_MATRICES));
724
725 updateGuardbands(pState);
726 }
727
728 void SwrSetScissorRects(
729 HANDLE hContext,
730 uint32_t numScissors,
731 const SWR_RECT* pScissors)
732 {
733 SWR_ASSERT(numScissors <= KNOB_NUM_VIEWPORTS_SCISSORS,
734 "Invalid number of scissor rects.");
735
736 API_STATE* pState = GetDrawState(GetContext(hContext));
737 memcpy(&pState->scissorRects[0], pScissors, numScissors * sizeof(pScissors[0]));
738 };
739
740 void SetupMacroTileScissors(DRAW_CONTEXT *pDC)
741 {
742 API_STATE *pState = &pDC->pState->state;
743 uint32_t numScissors = pState->gsState.emitsViewportArrayIndex ? KNOB_NUM_VIEWPORTS_SCISSORS : 1;
744 pState->scissorsTileAligned = true;
745
746 for (uint32_t index = 0; index < numScissors; ++index)
747 {
748 SWR_RECT &scissorInFixedPoint = pState->scissorsInFixedPoint[index];
749
750 // Set up scissor dimensions based on scissor or viewport
751 if (pState->rastState.scissorEnable)
752 {
753 scissorInFixedPoint = pState->scissorRects[index];
754 }
755 else
756 {
757 // the vp width and height must be added to origin un-rounded then the result round to -inf.
758 // The cast to int works for rounding assuming all [left, right, top, bottom] are positive.
759 scissorInFixedPoint.xmin = (int32_t)pState->vp[index].x;
760 scissorInFixedPoint.xmax = (int32_t)(pState->vp[index].x + pState->vp[index].width);
761 scissorInFixedPoint.ymin = (int32_t)pState->vp[index].y;
762 scissorInFixedPoint.ymax = (int32_t)(pState->vp[index].y + pState->vp[index].height);
763 }
764
765 // Clamp to max rect
766 scissorInFixedPoint &= g_MaxScissorRect;
767
768 // Test for tile alignment
769 bool tileAligned;
770 tileAligned = (scissorInFixedPoint.xmin % KNOB_TILE_X_DIM) == 0;
771 tileAligned &= (scissorInFixedPoint.ymin % KNOB_TILE_Y_DIM) == 0;
772 tileAligned &= (scissorInFixedPoint.xmax % KNOB_TILE_X_DIM) == 0;
773 tileAligned &= (scissorInFixedPoint.ymax % KNOB_TILE_Y_DIM) == 0;
774
775 pState->scissorsTileAligned &= tileAligned;
776
777 // Scale to fixed point
778 scissorInFixedPoint.xmin *= FIXED_POINT_SCALE;
779 scissorInFixedPoint.xmax *= FIXED_POINT_SCALE;
780 scissorInFixedPoint.ymin *= FIXED_POINT_SCALE;
781 scissorInFixedPoint.ymax *= FIXED_POINT_SCALE;
782
783 // Make scissor inclusive
784 scissorInFixedPoint.xmax -= 1;
785 scissorInFixedPoint.ymax -= 1;
786 }
787 }
788
789 // templated backend function tables
790 extern PFN_BACKEND_FUNC gBackendNullPs[SWR_MULTISAMPLE_TYPE_COUNT];
791 extern PFN_BACKEND_FUNC gBackendSingleSample[SWR_INPUT_COVERAGE_COUNT][2][2];
792 extern PFN_BACKEND_FUNC gBackendSampleRateTable[SWR_MULTISAMPLE_TYPE_COUNT][SWR_INPUT_COVERAGE_COUNT][2][2];
793 void SetupPipeline(DRAW_CONTEXT *pDC)
794 {
795 DRAW_STATE* pState = pDC->pState;
796 const SWR_RASTSTATE &rastState = pState->state.rastState;
797 const SWR_PS_STATE &psState = pState->state.psState;
798 BACKEND_FUNCS& backendFuncs = pState->backendFuncs;
799
800 // setup backend
801 if (psState.pfnPixelShader == nullptr)
802 {
803 backendFuncs.pfnBackend = gBackendNullPs[pState->state.rastState.sampleCount];
804 }
805 else
806 {
807 const uint32_t forcedSampleCount = (rastState.forcedSampleCount) ? 1 : 0;
808 const bool bMultisampleEnable = ((rastState.sampleCount > SWR_MULTISAMPLE_1X) || forcedSampleCount) ? 1 : 0;
809 const uint32_t centroid = ((psState.barycentricsMask & SWR_BARYCENTRIC_CENTROID_MASK) > 0) ? 1 : 0;
810 const uint32_t canEarlyZ = (psState.forceEarlyZ || (!psState.writesODepth && !psState.usesSourceDepth && !psState.usesUAV)) ? 1 : 0;
811 SWR_BARYCENTRICS_MASK barycentricsMask = (SWR_BARYCENTRICS_MASK)psState.barycentricsMask;
812
813 // select backend function
814 switch(psState.shadingRate)
815 {
816 case SWR_SHADING_RATE_PIXEL:
817 if(bMultisampleEnable)
818 {
819 // always need to generate I & J per sample for Z interpolation
820 barycentricsMask = (SWR_BARYCENTRICS_MASK)(barycentricsMask | SWR_BARYCENTRIC_PER_SAMPLE_MASK);
821 backendFuncs.pfnBackend = gBackendPixelRateTable[rastState.sampleCount][rastState.bIsCenterPattern][psState.inputCoverage]
822 [centroid][forcedSampleCount][canEarlyZ]
823 ;
824 }
825 else
826 {
827 // always need to generate I & J per pixel for Z interpolation
828 barycentricsMask = (SWR_BARYCENTRICS_MASK)(barycentricsMask | SWR_BARYCENTRIC_PER_PIXEL_MASK);
829 backendFuncs.pfnBackend = gBackendSingleSample[psState.inputCoverage][centroid][canEarlyZ];
830 }
831 break;
832 case SWR_SHADING_RATE_SAMPLE:
833 SWR_ASSERT(rastState.bIsCenterPattern != true);
834 // always need to generate I & J per sample for Z interpolation
835 barycentricsMask = (SWR_BARYCENTRICS_MASK)(barycentricsMask | SWR_BARYCENTRIC_PER_SAMPLE_MASK);
836 backendFuncs.pfnBackend = gBackendSampleRateTable[rastState.sampleCount][psState.inputCoverage][centroid][canEarlyZ];
837 break;
838 default:
839 SWR_ASSERT(0 && "Invalid shading rate");
840 break;
841 }
842 }
843
844 PFN_PROCESS_PRIMS pfnBinner;
845 #if USE_SIMD16_FRONTEND
846 PFN_PROCESS_PRIMS_SIMD16 pfnBinner_simd16;
847 #endif
848 switch (pState->state.topology)
849 {
850 case TOP_POINT_LIST:
851 pState->pfnProcessPrims = ClipPoints;
852 pfnBinner = BinPoints;
853 #if USE_SIMD16_FRONTEND
854 pState->pfnProcessPrims_simd16 = ClipPoints_simd16;
855 pfnBinner_simd16 = BinPoints_simd16;
856 #endif
857 break;
858 case TOP_LINE_LIST:
859 case TOP_LINE_STRIP:
860 case TOP_LINE_LOOP:
861 case TOP_LINE_LIST_ADJ:
862 case TOP_LISTSTRIP_ADJ:
863 pState->pfnProcessPrims = ClipLines;
864 pfnBinner = BinLines;
865 #if USE_SIMD16_FRONTEND
866 pState->pfnProcessPrims_simd16 = ClipLines_simd16;
867 pfnBinner_simd16 = BinLines_simd16;
868 #endif
869 break;
870 default:
871 pState->pfnProcessPrims = ClipTriangles;
872 pfnBinner = GetBinTrianglesFunc((rastState.conservativeRast > 0));
873 #if USE_SIMD16_FRONTEND
874 pState->pfnProcessPrims_simd16 = ClipTriangles_simd16;
875 pfnBinner_simd16 = GetBinTrianglesFunc_simd16((rastState.conservativeRast > 0));
876 #endif
877 break;
878 };
879
880
881 // disable clipper if viewport transform is disabled
882 if (pState->state.frontendState.vpTransformDisable)
883 {
884 pState->pfnProcessPrims = pfnBinner;
885 #if USE_SIMD16_FRONTEND
886 pState->pfnProcessPrims_simd16 = pfnBinner_simd16;
887 #endif
888 }
889
890 if ((pState->state.psState.pfnPixelShader == nullptr) &&
891 (pState->state.depthStencilState.depthTestEnable == FALSE) &&
892 (pState->state.depthStencilState.depthWriteEnable == FALSE) &&
893 (pState->state.depthStencilState.stencilTestEnable == FALSE) &&
894 (pState->state.depthStencilState.stencilWriteEnable == FALSE) &&
895 (pState->state.backendState.numAttributes == 0))
896 {
897 pState->pfnProcessPrims = nullptr;
898 #if USE_SIMD16_FRONTEND
899 pState->pfnProcessPrims_simd16 = nullptr;
900 #endif
901 }
902
903 if (pState->state.soState.rasterizerDisable == true)
904 {
905 pState->pfnProcessPrims = nullptr;
906 #if USE_SIMD16_FRONTEND
907 pState->pfnProcessPrims_simd16 = nullptr;
908 #endif
909 }
910
911
912 // set up the frontend attribute count
913 pState->state.feNumAttributes = 0;
914 const SWR_BACKEND_STATE& backendState = pState->state.backendState;
915 if (backendState.swizzleEnable)
916 {
917 // attribute swizzling is enabled, iterate over the map and record the max attribute used
918 for (uint32_t i = 0; i < backendState.numAttributes; ++i)
919 {
920 pState->state.feNumAttributes = std::max(pState->state.feNumAttributes, (uint32_t)backendState.swizzleMap[i].sourceAttrib + 1);
921 }
922 }
923 else
924 {
925 pState->state.feNumAttributes = pState->state.backendState.numAttributes;
926 }
927
928 if (pState->state.soState.soEnable)
929 {
930 uint32_t streamMasks = 0;
931 for (uint32_t i = 0; i < 4; ++i)
932 {
933 streamMasks |= pState->state.soState.streamMasks[i];
934 }
935
936 DWORD maxAttrib;
937 if (_BitScanReverse(&maxAttrib, streamMasks))
938 {
939 pState->state.feNumAttributes = std::max(pState->state.feNumAttributes, (uint32_t)(maxAttrib + 1));
940 }
941 }
942
943 // complicated logic to test for cases where we don't need backing hottile memory for a draw
944 // have to check for the special case where depth/stencil test is enabled but depthwrite is disabled.
945 pState->state.depthHottileEnable = ((!(pState->state.depthStencilState.depthTestEnable &&
946 !pState->state.depthStencilState.depthWriteEnable &&
947 !pState->state.depthBoundsState.depthBoundsTestEnable &&
948 pState->state.depthStencilState.depthTestFunc == ZFUNC_ALWAYS)) &&
949 (pState->state.depthStencilState.depthTestEnable ||
950 pState->state.depthStencilState.depthWriteEnable ||
951 pState->state.depthBoundsState.depthBoundsTestEnable)) ? true : false;
952
953 pState->state.stencilHottileEnable = (((!(pState->state.depthStencilState.stencilTestEnable &&
954 !pState->state.depthStencilState.stencilWriteEnable &&
955 pState->state.depthStencilState.stencilTestFunc == ZFUNC_ALWAYS)) ||
956 // for stencil we have to check the double sided state as well
957 (!(pState->state.depthStencilState.doubleSidedStencilTestEnable &&
958 !pState->state.depthStencilState.stencilWriteEnable &&
959 pState->state.depthStencilState.backfaceStencilTestFunc == ZFUNC_ALWAYS))) &&
960 (pState->state.depthStencilState.stencilTestEnable ||
961 pState->state.depthStencilState.stencilWriteEnable)) ? true : false;
962
963 uint32_t numRTs = pState->state.psState.numRenderTargets;
964 pState->state.colorHottileEnable = 0;
965 if (psState.pfnPixelShader != nullptr)
966 {
967 for (uint32_t rt = 0; rt < numRTs; ++rt)
968 {
969 pState->state.colorHottileEnable |=
970 (!pState->state.blendState.renderTarget[rt].writeDisableAlpha ||
971 !pState->state.blendState.renderTarget[rt].writeDisableRed ||
972 !pState->state.blendState.renderTarget[rt].writeDisableGreen ||
973 !pState->state.blendState.renderTarget[rt].writeDisableBlue) ? (1 << rt) : 0;
974 }
975 }
976
977 // Setup depth quantization function
978 if (pState->state.depthHottileEnable)
979 {
980 switch (pState->state.rastState.depthFormat)
981 {
982 case R32_FLOAT_X8X24_TYPELESS: pState->state.pfnQuantizeDepth = QuantizeDepth < R32_FLOAT_X8X24_TYPELESS > ; break;
983 case R32_FLOAT: pState->state.pfnQuantizeDepth = QuantizeDepth < R32_FLOAT > ; break;
984 case R24_UNORM_X8_TYPELESS: pState->state.pfnQuantizeDepth = QuantizeDepth < R24_UNORM_X8_TYPELESS > ; break;
985 case R16_UNORM: pState->state.pfnQuantizeDepth = QuantizeDepth < R16_UNORM > ; break;
986 default: SWR_INVALID("Unsupported depth format for depth quantiztion.");
987 pState->state.pfnQuantizeDepth = QuantizeDepth < R32_FLOAT > ;
988 }
989 }
990 else
991 {
992 // set up pass-through quantize if depth isn't enabled
993 pState->state.pfnQuantizeDepth = QuantizeDepth < R32_FLOAT > ;
994 }
995 }
996
997 //////////////////////////////////////////////////////////////////////////
998 /// @brief InitDraw
999 /// @param pDC - Draw context to initialize for this draw.
1000 void InitDraw(
1001 DRAW_CONTEXT *pDC,
1002 bool isSplitDraw)
1003 {
1004 // We don't need to re-setup the scissors/pipeline state again for split draw.
1005 if (isSplitDraw == false)
1006 {
1007 SetupMacroTileScissors(pDC);
1008 SetupPipeline(pDC);
1009 }
1010
1011
1012 }
1013
1014 //////////////////////////////////////////////////////////////////////////
1015 /// @brief We can split the draw for certain topologies for better performance.
1016 /// @param totalVerts - Total vertices for draw
1017 /// @param topology - Topology used for draw
1018 uint32_t MaxVertsPerDraw(
1019 DRAW_CONTEXT* pDC,
1020 uint32_t totalVerts,
1021 PRIMITIVE_TOPOLOGY topology)
1022 {
1023 API_STATE& state = pDC->pState->state;
1024
1025 uint32_t vertsPerDraw = totalVerts;
1026
1027 if (state.soState.soEnable)
1028 {
1029 return totalVerts;
1030 }
1031
1032 switch (topology)
1033 {
1034 case TOP_POINT_LIST:
1035 case TOP_TRIANGLE_LIST:
1036 vertsPerDraw = KNOB_MAX_PRIMS_PER_DRAW;
1037 break;
1038
1039 case TOP_PATCHLIST_1:
1040 case TOP_PATCHLIST_2:
1041 case TOP_PATCHLIST_3:
1042 case TOP_PATCHLIST_4:
1043 case TOP_PATCHLIST_5:
1044 case TOP_PATCHLIST_6:
1045 case TOP_PATCHLIST_7:
1046 case TOP_PATCHLIST_8:
1047 case TOP_PATCHLIST_9:
1048 case TOP_PATCHLIST_10:
1049 case TOP_PATCHLIST_11:
1050 case TOP_PATCHLIST_12:
1051 case TOP_PATCHLIST_13:
1052 case TOP_PATCHLIST_14:
1053 case TOP_PATCHLIST_15:
1054 case TOP_PATCHLIST_16:
1055 case TOP_PATCHLIST_17:
1056 case TOP_PATCHLIST_18:
1057 case TOP_PATCHLIST_19:
1058 case TOP_PATCHLIST_20:
1059 case TOP_PATCHLIST_21:
1060 case TOP_PATCHLIST_22:
1061 case TOP_PATCHLIST_23:
1062 case TOP_PATCHLIST_24:
1063 case TOP_PATCHLIST_25:
1064 case TOP_PATCHLIST_26:
1065 case TOP_PATCHLIST_27:
1066 case TOP_PATCHLIST_28:
1067 case TOP_PATCHLIST_29:
1068 case TOP_PATCHLIST_30:
1069 case TOP_PATCHLIST_31:
1070 case TOP_PATCHLIST_32:
1071 if (pDC->pState->state.tsState.tsEnable)
1072 {
1073 uint32_t vertsPerPrim = topology - TOP_PATCHLIST_BASE;
1074 vertsPerDraw = vertsPerPrim * KNOB_MAX_TESS_PRIMS_PER_DRAW;
1075 }
1076 break;
1077
1078 // The Primitive Assembly code can only handle 1 RECT at a time.
1079 case TOP_RECT_LIST:
1080 vertsPerDraw = 3;
1081 break;
1082
1083 default:
1084 // We are not splitting up draws for other topologies.
1085 break;
1086 }
1087
1088 return vertsPerDraw;
1089 }
1090
1091
1092 //////////////////////////////////////////////////////////////////////////
1093 /// @brief DrawInstanced
1094 /// @param hContext - Handle passed back from SwrCreateContext
1095 /// @param topology - Specifies topology for draw.
1096 /// @param numVerts - How many vertices to read sequentially from vertex data (per instance).
1097 /// @param startVertex - Specifies start vertex for draw. (vertex data)
1098 /// @param numInstances - How many instances to render.
1099 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
1100 void DrawInstanced(
1101 HANDLE hContext,
1102 PRIMITIVE_TOPOLOGY topology,
1103 uint32_t numVertices,
1104 uint32_t startVertex,
1105 uint32_t numInstances = 1,
1106 uint32_t startInstance = 0)
1107 {
1108 if (KNOB_TOSS_DRAW)
1109 {
1110 return;
1111 }
1112
1113 SWR_CONTEXT *pContext = GetContext(hContext);
1114 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1115
1116 AR_API_BEGIN(APIDraw, pDC->drawId);
1117 AR_API_EVENT(DrawInstancedEvent(pDC->drawId, topology, numVertices, startVertex, numInstances, startInstance));
1118
1119 uint32_t maxVertsPerDraw = MaxVertsPerDraw(pDC, numVertices, topology);
1120 uint32_t primsPerDraw = GetNumPrims(topology, maxVertsPerDraw);
1121 uint32_t remainingVerts = numVertices;
1122
1123 API_STATE *pState = &pDC->pState->state;
1124 pState->topology = topology;
1125 pState->forceFront = false;
1126
1127 // disable culling for points/lines
1128 uint32_t oldCullMode = pState->rastState.cullMode;
1129 if (topology == TOP_POINT_LIST)
1130 {
1131 pState->rastState.cullMode = SWR_CULLMODE_NONE;
1132 pState->forceFront = true;
1133 }
1134 else if (topology == TOP_RECT_LIST)
1135 {
1136 pState->rastState.cullMode = SWR_CULLMODE_NONE;
1137 }
1138
1139
1140 int draw = 0;
1141 while (remainingVerts)
1142 {
1143 uint32_t numVertsForDraw = (remainingVerts < maxVertsPerDraw) ?
1144 remainingVerts : maxVertsPerDraw;
1145
1146 bool isSplitDraw = (draw > 0) ? true : false;
1147 DRAW_CONTEXT* pDC = GetDrawContext(pContext, isSplitDraw);
1148 InitDraw(pDC, isSplitDraw);
1149
1150 pDC->FeWork.type = DRAW;
1151 pDC->FeWork.pfnWork = GetProcessDrawFunc(
1152 false, // IsIndexed
1153 false, // bEnableCutIndex
1154 pState->tsState.tsEnable,
1155 pState->gsState.gsEnable,
1156 pState->soState.soEnable,
1157 pDC->pState->pfnProcessPrims != nullptr);
1158 pDC->FeWork.desc.draw.numVerts = numVertsForDraw;
1159 pDC->FeWork.desc.draw.startVertex = startVertex;
1160 pDC->FeWork.desc.draw.numInstances = numInstances;
1161 pDC->FeWork.desc.draw.startInstance = startInstance;
1162 pDC->FeWork.desc.draw.startPrimID = draw * primsPerDraw;
1163 pDC->FeWork.desc.draw.startVertexID = draw * maxVertsPerDraw;
1164
1165 pDC->cleanupState = (remainingVerts == numVertsForDraw);
1166
1167 //enqueue DC
1168 QueueDraw(pContext);
1169
1170 AR_API_EVENT(DrawInstancedSplitEvent(pDC->drawId));
1171
1172 remainingVerts -= numVertsForDraw;
1173 draw++;
1174 }
1175
1176 // restore culling state
1177 pDC = GetDrawContext(pContext);
1178 pDC->pState->state.rastState.cullMode = oldCullMode;
1179
1180
1181 AR_API_END(APIDraw, numVertices * numInstances);
1182 }
1183
1184 //////////////////////////////////////////////////////////////////////////
1185 /// @brief SwrDraw
1186 /// @param hContext - Handle passed back from SwrCreateContext
1187 /// @param topology - Specifies topology for draw.
1188 /// @param startVertex - Specifies start vertex in vertex buffer for draw.
1189 /// @param primCount - Number of vertices.
1190 void SwrDraw(
1191 HANDLE hContext,
1192 PRIMITIVE_TOPOLOGY topology,
1193 uint32_t startVertex,
1194 uint32_t numVertices)
1195 {
1196 DrawInstanced(hContext, topology, numVertices, startVertex);
1197 }
1198
1199 //////////////////////////////////////////////////////////////////////////
1200 /// @brief SwrDrawInstanced
1201 /// @param hContext - Handle passed back from SwrCreateContext
1202 /// @param topology - Specifies topology for draw.
1203 /// @param numVertsPerInstance - How many vertices to read sequentially from vertex data.
1204 /// @param numInstances - How many instances to render.
1205 /// @param startVertex - Specifies start vertex for draw. (vertex data)
1206 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
1207 void SwrDrawInstanced(
1208 HANDLE hContext,
1209 PRIMITIVE_TOPOLOGY topology,
1210 uint32_t numVertsPerInstance,
1211 uint32_t numInstances,
1212 uint32_t startVertex,
1213 uint32_t startInstance
1214 )
1215 {
1216 DrawInstanced(hContext, topology, numVertsPerInstance, startVertex, numInstances, startInstance);
1217 }
1218
1219 //////////////////////////////////////////////////////////////////////////
1220 /// @brief DrawIndexedInstanced
1221 /// @param hContext - Handle passed back from SwrCreateContext
1222 /// @param topology - Specifies topology for draw.
1223 /// @param numIndices - Number of indices to read sequentially from index buffer.
1224 /// @param indexOffset - Starting index into index buffer.
1225 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
1226 /// @param numInstances - Number of instances to render.
1227 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
1228 void DrawIndexedInstance(
1229 HANDLE hContext,
1230 PRIMITIVE_TOPOLOGY topology,
1231 uint32_t numIndices,
1232 uint32_t indexOffset,
1233 int32_t baseVertex,
1234 uint32_t numInstances = 1,
1235 uint32_t startInstance = 0)
1236 {
1237 if (KNOB_TOSS_DRAW)
1238 {
1239 return;
1240 }
1241
1242 SWR_CONTEXT *pContext = GetContext(hContext);
1243 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1244 API_STATE* pState = &pDC->pState->state;
1245
1246 AR_API_BEGIN(APIDrawIndexed, pDC->drawId);
1247 AR_API_EVENT(DrawIndexedInstancedEvent(pDC->drawId, topology, numIndices, indexOffset, baseVertex, numInstances, startInstance));
1248
1249 uint32_t maxIndicesPerDraw = MaxVertsPerDraw(pDC, numIndices, topology);
1250 uint32_t primsPerDraw = GetNumPrims(topology, maxIndicesPerDraw);
1251 uint32_t remainingIndices = numIndices;
1252
1253 uint32_t indexSize = 0;
1254 switch (pState->indexBuffer.format)
1255 {
1256 case R32_UINT: indexSize = sizeof(uint32_t); break;
1257 case R16_UINT: indexSize = sizeof(uint16_t); break;
1258 case R8_UINT: indexSize = sizeof(uint8_t); break;
1259 default:
1260 SWR_INVALID("Invalid index buffer format: %d", pState->indexBuffer.format);
1261 }
1262
1263 int draw = 0;
1264 uint8_t *pIB = (uint8_t*)pState->indexBuffer.pIndices;
1265 pIB += (uint64_t)indexOffset * (uint64_t)indexSize;
1266
1267 pState->topology = topology;
1268 pState->forceFront = false;
1269
1270 // disable culling for points/lines
1271 uint32_t oldCullMode = pState->rastState.cullMode;
1272 if (topology == TOP_POINT_LIST)
1273 {
1274 pState->rastState.cullMode = SWR_CULLMODE_NONE;
1275 pState->forceFront = true;
1276 }
1277 else if (topology == TOP_RECT_LIST)
1278 {
1279 pState->rastState.cullMode = SWR_CULLMODE_NONE;
1280 }
1281
1282
1283 while (remainingIndices)
1284 {
1285 uint32_t numIndicesForDraw = (remainingIndices < maxIndicesPerDraw) ?
1286 remainingIndices : maxIndicesPerDraw;
1287
1288 // When breaking up draw, we need to obtain new draw context for each iteration.
1289 bool isSplitDraw = (draw > 0) ? true : false;
1290
1291 pDC = GetDrawContext(pContext, isSplitDraw);
1292 InitDraw(pDC, isSplitDraw);
1293
1294 pDC->FeWork.type = DRAW;
1295 pDC->FeWork.pfnWork = GetProcessDrawFunc(
1296 true, // IsIndexed
1297 pState->frontendState.bEnableCutIndex,
1298 pState->tsState.tsEnable,
1299 pState->gsState.gsEnable,
1300 pState->soState.soEnable,
1301 pDC->pState->pfnProcessPrims != nullptr);
1302 pDC->FeWork.desc.draw.pDC = pDC;
1303 pDC->FeWork.desc.draw.numIndices = numIndicesForDraw;
1304 pDC->FeWork.desc.draw.pIB = (int*)pIB;
1305 pDC->FeWork.desc.draw.type = pDC->pState->state.indexBuffer.format;
1306
1307 pDC->FeWork.desc.draw.numInstances = numInstances;
1308 pDC->FeWork.desc.draw.startInstance = startInstance;
1309 pDC->FeWork.desc.draw.baseVertex = baseVertex;
1310 pDC->FeWork.desc.draw.startPrimID = draw * primsPerDraw;
1311
1312 pDC->cleanupState = (remainingIndices == numIndicesForDraw);
1313
1314 //enqueue DC
1315 QueueDraw(pContext);
1316
1317 AR_API_EVENT(DrawIndexedInstancedSplitEvent(pDC->drawId));
1318
1319 pIB += maxIndicesPerDraw * indexSize;
1320 remainingIndices -= numIndicesForDraw;
1321 draw++;
1322 }
1323
1324 // Restore culling state
1325 pDC = GetDrawContext(pContext);
1326 pDC->pState->state.rastState.cullMode = oldCullMode;
1327
1328
1329 AR_API_END(APIDrawIndexed, numIndices * numInstances);
1330 }
1331
1332
1333 //////////////////////////////////////////////////////////////////////////
1334 /// @brief DrawIndexed
1335 /// @param hContext - Handle passed back from SwrCreateContext
1336 /// @param topology - Specifies topology for draw.
1337 /// @param numIndices - Number of indices to read sequentially from index buffer.
1338 /// @param indexOffset - Starting index into index buffer.
1339 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
1340 void SwrDrawIndexed(
1341 HANDLE hContext,
1342 PRIMITIVE_TOPOLOGY topology,
1343 uint32_t numIndices,
1344 uint32_t indexOffset,
1345 int32_t baseVertex
1346 )
1347 {
1348 DrawIndexedInstance(hContext, topology, numIndices, indexOffset, baseVertex);
1349 }
1350
1351 //////////////////////////////////////////////////////////////////////////
1352 /// @brief SwrDrawIndexedInstanced
1353 /// @param hContext - Handle passed back from SwrCreateContext
1354 /// @param topology - Specifies topology for draw.
1355 /// @param numIndices - Number of indices to read sequentially from index buffer.
1356 /// @param numInstances - Number of instances to render.
1357 /// @param indexOffset - Starting index into index buffer.
1358 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
1359 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
1360 void SwrDrawIndexedInstanced(
1361 HANDLE hContext,
1362 PRIMITIVE_TOPOLOGY topology,
1363 uint32_t numIndices,
1364 uint32_t numInstances,
1365 uint32_t indexOffset,
1366 int32_t baseVertex,
1367 uint32_t startInstance)
1368 {
1369 DrawIndexedInstance(hContext, topology, numIndices, indexOffset, baseVertex, numInstances, startInstance);
1370 }
1371
1372 //////////////////////////////////////////////////////////////////////////
1373 /// @brief SwrInvalidateTiles
1374 /// @param hContext - Handle passed back from SwrCreateContext
1375 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
1376 /// @param invalidateRect - The pixel-coordinate rectangle to invalidate. This will be expanded to
1377 /// be hottile size-aligned.
1378 void SWR_API SwrInvalidateTiles(
1379 HANDLE hContext,
1380 uint32_t attachmentMask,
1381 const SWR_RECT& invalidateRect)
1382 {
1383 if (KNOB_TOSS_DRAW)
1384 {
1385 return;
1386 }
1387
1388 SWR_CONTEXT *pContext = GetContext(hContext);
1389 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1390
1391 pDC->FeWork.type = DISCARDINVALIDATETILES;
1392 pDC->FeWork.pfnWork = ProcessDiscardInvalidateTiles;
1393 pDC->FeWork.desc.discardInvalidateTiles.attachmentMask = attachmentMask;
1394 pDC->FeWork.desc.discardInvalidateTiles.rect = invalidateRect;
1395 pDC->FeWork.desc.discardInvalidateTiles.rect &= g_MaxScissorRect;
1396 pDC->FeWork.desc.discardInvalidateTiles.newTileState = SWR_TILE_INVALID;
1397 pDC->FeWork.desc.discardInvalidateTiles.createNewTiles = false;
1398 pDC->FeWork.desc.discardInvalidateTiles.fullTilesOnly = false;
1399
1400 //enqueue
1401 QueueDraw(pContext);
1402
1403 AR_API_EVENT(SwrInvalidateTilesEvent(pDC->drawId));
1404 }
1405
1406 //////////////////////////////////////////////////////////////////////////
1407 /// @brief SwrDiscardRect
1408 /// @param hContext - Handle passed back from SwrCreateContext
1409 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard.
1410 /// @param rect - The pixel-coordinate rectangle to discard. Only fully-covered hottiles will be
1411 /// discarded.
1412 void SWR_API SwrDiscardRect(
1413 HANDLE hContext,
1414 uint32_t attachmentMask,
1415 const SWR_RECT& rect)
1416 {
1417 if (KNOB_TOSS_DRAW)
1418 {
1419 return;
1420 }
1421
1422 SWR_CONTEXT *pContext = GetContext(hContext);
1423 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1424
1425 // Queue a load to the hottile
1426 pDC->FeWork.type = DISCARDINVALIDATETILES;
1427 pDC->FeWork.pfnWork = ProcessDiscardInvalidateTiles;
1428 pDC->FeWork.desc.discardInvalidateTiles.attachmentMask = attachmentMask;
1429 pDC->FeWork.desc.discardInvalidateTiles.rect = rect;
1430 pDC->FeWork.desc.discardInvalidateTiles.rect &= g_MaxScissorRect;
1431 pDC->FeWork.desc.discardInvalidateTiles.newTileState = SWR_TILE_RESOLVED;
1432 pDC->FeWork.desc.discardInvalidateTiles.createNewTiles = true;
1433 pDC->FeWork.desc.discardInvalidateTiles.fullTilesOnly = true;
1434
1435 //enqueue
1436 QueueDraw(pContext);
1437
1438 AR_API_EVENT(SwrDiscardRectEvent(pDC->drawId));
1439 }
1440
1441 //////////////////////////////////////////////////////////////////////////
1442 /// @brief SwrDispatch
1443 /// @param hContext - Handle passed back from SwrCreateContext
1444 /// @param threadGroupCountX - Number of thread groups dispatched in X direction
1445 /// @param threadGroupCountY - Number of thread groups dispatched in Y direction
1446 /// @param threadGroupCountZ - Number of thread groups dispatched in Z direction
1447 void SwrDispatch(
1448 HANDLE hContext,
1449 uint32_t threadGroupCountX,
1450 uint32_t threadGroupCountY,
1451 uint32_t threadGroupCountZ)
1452 {
1453 if (KNOB_TOSS_DRAW)
1454 {
1455 return;
1456 }
1457
1458 SWR_CONTEXT *pContext = GetContext(hContext);
1459 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1460
1461 AR_API_BEGIN(APIDispatch, pDC->drawId);
1462 AR_API_EVENT(DispatchEvent(pDC->drawId, threadGroupCountX, threadGroupCountY, threadGroupCountZ));
1463 pDC->isCompute = true; // This is a compute context.
1464
1465 COMPUTE_DESC* pTaskData = (COMPUTE_DESC*)pDC->pArena->AllocAligned(sizeof(COMPUTE_DESC), 64);
1466
1467 pTaskData->threadGroupCountX = threadGroupCountX;
1468 pTaskData->threadGroupCountY = threadGroupCountY;
1469 pTaskData->threadGroupCountZ = threadGroupCountZ;
1470
1471 uint32_t totalThreadGroups = threadGroupCountX * threadGroupCountY * threadGroupCountZ;
1472 uint32_t dcIndex = pDC->drawId % KNOB_MAX_DRAWS_IN_FLIGHT;
1473 pDC->pDispatch = &pContext->pDispatchQueueArray[dcIndex];
1474 pDC->pDispatch->initialize(totalThreadGroups, pTaskData, &ProcessComputeBE);
1475
1476 QueueDispatch(pContext);
1477 AR_API_END(APIDispatch, threadGroupCountX * threadGroupCountY * threadGroupCountZ);
1478 }
1479
1480 // Deswizzles, converts and stores current contents of the hot tiles to surface
1481 // described by pState
1482 void SWR_API SwrStoreTiles(
1483 HANDLE hContext,
1484 uint32_t attachmentMask,
1485 SWR_TILE_STATE postStoreTileState,
1486 const SWR_RECT& storeRect)
1487 {
1488 if (KNOB_TOSS_DRAW)
1489 {
1490 return;
1491 }
1492
1493 SWR_CONTEXT *pContext = GetContext(hContext);
1494 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1495
1496 AR_API_BEGIN(APIStoreTiles, pDC->drawId);
1497
1498 pDC->FeWork.type = STORETILES;
1499 pDC->FeWork.pfnWork = ProcessStoreTiles;
1500 pDC->FeWork.desc.storeTiles.attachmentMask = attachmentMask;
1501 pDC->FeWork.desc.storeTiles.postStoreTileState = postStoreTileState;
1502 pDC->FeWork.desc.storeTiles.rect = storeRect;
1503 pDC->FeWork.desc.storeTiles.rect &= g_MaxScissorRect;
1504
1505 //enqueue
1506 QueueDraw(pContext);
1507
1508 AR_API_EVENT(SwrStoreTilesEvent(pDC->drawId));
1509
1510 AR_API_END(APIStoreTiles, 1);
1511 }
1512
1513 //////////////////////////////////////////////////////////////////////////
1514 /// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil
1515 /// @param hContext - Handle passed back from SwrCreateContext
1516 /// @param attachmentMask - combination of SWR_ATTACHMENT_*_BIT attachments to clear
1517 /// @param renderTargetArrayIndex - the RT array index to clear
1518 /// @param clearColor - color use for clearing render targets
1519 /// @param z - depth value use for clearing depth buffer
1520 /// @param stencil - stencil value used for clearing stencil buffer
1521 /// @param clearRect - The pixel-coordinate rectangle to clear in all cleared buffers
1522 void SWR_API SwrClearRenderTarget(
1523 HANDLE hContext,
1524 uint32_t attachmentMask,
1525 uint32_t renderTargetArrayIndex,
1526 const float clearColor[4],
1527 float z,
1528 uint8_t stencil,
1529 const SWR_RECT& clearRect)
1530 {
1531 if (KNOB_TOSS_DRAW)
1532 {
1533 return;
1534 }
1535
1536 SWR_CONTEXT *pContext = GetContext(hContext);
1537 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1538
1539 AR_API_BEGIN(APIClearRenderTarget, pDC->drawId);
1540
1541 pDC->FeWork.type = CLEAR;
1542 pDC->FeWork.pfnWork = ProcessClear;
1543 pDC->FeWork.desc.clear.rect = clearRect;
1544 pDC->FeWork.desc.clear.rect &= g_MaxScissorRect;
1545 pDC->FeWork.desc.clear.attachmentMask = attachmentMask;
1546 pDC->FeWork.desc.clear.renderTargetArrayIndex = renderTargetArrayIndex;
1547 pDC->FeWork.desc.clear.clearDepth = z;
1548 pDC->FeWork.desc.clear.clearRTColor[0] = clearColor[0];
1549 pDC->FeWork.desc.clear.clearRTColor[1] = clearColor[1];
1550 pDC->FeWork.desc.clear.clearRTColor[2] = clearColor[2];
1551 pDC->FeWork.desc.clear.clearRTColor[3] = clearColor[3];
1552 pDC->FeWork.desc.clear.clearStencil = stencil;
1553
1554 // enqueue draw
1555 QueueDraw(pContext);
1556
1557 AR_API_END(APIClearRenderTarget, 1);
1558 }
1559
1560 //////////////////////////////////////////////////////////////////////////
1561 /// @brief Returns a pointer to the private context state for the current
1562 /// draw operation. This is used for external componets such as the
1563 /// sampler.
1564 /// SWR is responsible for the allocation of the private context state.
1565 /// @param hContext - Handle passed back from SwrCreateContext
1566 VOID* SwrGetPrivateContextState(
1567 HANDLE hContext)
1568 {
1569 SWR_CONTEXT* pContext = GetContext(hContext);
1570 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1571 DRAW_STATE* pState = pDC->pState;
1572
1573 if (pState->pPrivateState == nullptr)
1574 {
1575 pState->pPrivateState = pState->pArena->AllocAligned(pContext->privateStateSize, KNOB_SIMD_WIDTH*sizeof(float));
1576 }
1577
1578 return pState->pPrivateState;
1579 }
1580
1581 //////////////////////////////////////////////////////////////////////////
1582 /// @brief Clients can use this to allocate memory for draw/dispatch
1583 /// operations. The memory will automatically be freed once operation
1584 /// has completed. Client can use this to allocate binding tables,
1585 /// etc. needed for shader execution.
1586 /// @param hContext - Handle passed back from SwrCreateContext
1587 /// @param size - Size of allocation
1588 /// @param align - Alignment needed for allocation.
1589 VOID* SwrAllocDrawContextMemory(
1590 HANDLE hContext,
1591 uint32_t size,
1592 uint32_t align)
1593 {
1594 SWR_CONTEXT* pContext = GetContext(hContext);
1595 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1596
1597 return pDC->pState->pArena->AllocAligned(size, align);
1598 }
1599
1600 //////////////////////////////////////////////////////////////////////////
1601 /// @brief Enables stats counting
1602 /// @param hContext - Handle passed back from SwrCreateContext
1603 /// @param enable - If true then counts are incremented.
1604 void SwrEnableStatsFE(
1605 HANDLE hContext,
1606 bool enable)
1607 {
1608 SWR_CONTEXT *pContext = GetContext(hContext);
1609 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1610
1611 pDC->pState->state.enableStatsFE = enable;
1612 }
1613
1614 //////////////////////////////////////////////////////////////////////////
1615 /// @brief Enables stats counting
1616 /// @param hContext - Handle passed back from SwrCreateContext
1617 /// @param enable - If true then counts are incremented.
1618 void SwrEnableStatsBE(
1619 HANDLE hContext,
1620 bool enable)
1621 {
1622 SWR_CONTEXT *pContext = GetContext(hContext);
1623 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1624
1625 pDC->pState->state.enableStatsBE = enable;
1626 }
1627
1628 //////////////////////////////////////////////////////////////////////////
1629 /// @brief Mark end of frame - used for performance profiling
1630 /// @param hContext - Handle passed back from SwrCreateContext
1631 void SWR_API SwrEndFrame(
1632 HANDLE hContext)
1633 {
1634 SWR_CONTEXT *pContext = GetContext(hContext);
1635 DRAW_CONTEXT* pDC = GetDrawContext(pContext);
1636 (void)pDC; // var used
1637
1638 RDTSC_ENDFRAME();
1639 AR_API_EVENT(FrameEndEvent(pContext->frameCount, pDC->drawId));
1640
1641 pContext->frameCount++;
1642 }
1643
1644
1645 void SwrGetInterface(SWR_INTERFACE &out_funcs)
1646 {
1647 out_funcs.pfnSwrCreateContext = SwrCreateContext;
1648 out_funcs.pfnSwrDestroyContext = SwrDestroyContext;
1649 out_funcs.pfnSwrSaveState = SwrSaveState;
1650 out_funcs.pfnSwrRestoreState = SwrRestoreState;
1651 out_funcs.pfnSwrSync = SwrSync;
1652 out_funcs.pfnSwrWaitForIdle = SwrWaitForIdle;
1653 out_funcs.pfnSwrWaitForIdleFE = SwrWaitForIdleFE;
1654 out_funcs.pfnSwrSetVertexBuffers = SwrSetVertexBuffers;
1655 out_funcs.pfnSwrSetIndexBuffer = SwrSetIndexBuffer;
1656 out_funcs.pfnSwrSetFetchFunc = SwrSetFetchFunc;
1657 out_funcs.pfnSwrSetSoFunc = SwrSetSoFunc;
1658 out_funcs.pfnSwrSetSoState = SwrSetSoState;
1659 out_funcs.pfnSwrSetSoBuffers = SwrSetSoBuffers;
1660 out_funcs.pfnSwrSetVertexFunc = SwrSetVertexFunc;
1661 out_funcs.pfnSwrSetFrontendState = SwrSetFrontendState;
1662 out_funcs.pfnSwrSetGsState = SwrSetGsState;
1663 out_funcs.pfnSwrSetGsFunc = SwrSetGsFunc;
1664 out_funcs.pfnSwrSetCsFunc = SwrSetCsFunc;
1665 out_funcs.pfnSwrSetTsState = SwrSetTsState;
1666 out_funcs.pfnSwrSetHsFunc = SwrSetHsFunc;
1667 out_funcs.pfnSwrSetDsFunc = SwrSetDsFunc;
1668 out_funcs.pfnSwrSetDepthStencilState = SwrSetDepthStencilState;
1669 out_funcs.pfnSwrSetBackendState = SwrSetBackendState;
1670 out_funcs.pfnSwrSetDepthBoundsState = SwrSetDepthBoundsState;
1671 out_funcs.pfnSwrSetPixelShaderState = SwrSetPixelShaderState;
1672 out_funcs.pfnSwrSetBlendState = SwrSetBlendState;
1673 out_funcs.pfnSwrSetBlendFunc = SwrSetBlendFunc;
1674 out_funcs.pfnSwrDraw = SwrDraw;
1675 out_funcs.pfnSwrDrawInstanced = SwrDrawInstanced;
1676 out_funcs.pfnSwrDrawIndexed = SwrDrawIndexed;
1677 out_funcs.pfnSwrDrawIndexedInstanced = SwrDrawIndexedInstanced;
1678 out_funcs.pfnSwrInvalidateTiles = SwrInvalidateTiles;
1679 out_funcs.pfnSwrDiscardRect = SwrDiscardRect;
1680 out_funcs.pfnSwrDispatch = SwrDispatch;
1681 out_funcs.pfnSwrStoreTiles = SwrStoreTiles;
1682 out_funcs.pfnSwrClearRenderTarget = SwrClearRenderTarget;
1683 out_funcs.pfnSwrSetRastState = SwrSetRastState;
1684 out_funcs.pfnSwrSetViewports = SwrSetViewports;
1685 out_funcs.pfnSwrSetScissorRects = SwrSetScissorRects;
1686 out_funcs.pfnSwrGetPrivateContextState = SwrGetPrivateContextState;
1687 out_funcs.pfnSwrAllocDrawContextMemory = SwrAllocDrawContextMemory;
1688 out_funcs.pfnSwrEnableStatsFE = SwrEnableStatsFE;
1689 out_funcs.pfnSwrEnableStatsBE = SwrEnableStatsBE;
1690 out_funcs.pfnSwrEndFrame = SwrEndFrame;
1691 }