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