• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h
24 *
25 * @brief API definitions
26 *
27 ******************************************************************************/
28 
29 #ifndef __SWR_API_H__
30 #define __SWR_API_H__
31 
32 #include "common/os.h"
33 
34 #include <assert.h>
35 #include <algorithm>
36 
37 #include "common/intrin.h"
38 #include "common/formats.h"
39 #include "core/state.h"
40 
41 typedef void(SWR_API *PFN_CALLBACK_FUNC)(uint64_t data, uint64_t data2, uint64_t data3);
42 
43 //////////////////////////////////////////////////////////////////////////
44 /// @brief Rectangle structure
45 struct SWR_RECT
46 {
47     int32_t xmin; ///< inclusive
48     int32_t ymin; ///< inclusive
49     int32_t xmax; ///< exclusive
50     int32_t ymax; ///< exclusive
51 
52     bool operator == (const SWR_RECT& rhs)
53     {
54         return (this->ymin == rhs.ymin &&
55             this->ymax == rhs.ymax &&
56             this->xmin == rhs.xmin &&
57             this->xmax == rhs.xmax);
58     }
59 
60     bool operator != (const SWR_RECT& rhs)
61     {
62         return !(*this == rhs);
63     }
64 
IntersectSWR_RECT65     SWR_RECT& Intersect(const SWR_RECT& other)
66     {
67         this->xmin = std::max(this->xmin, other.xmin);
68         this->ymin = std::max(this->ymin, other.ymin);
69         this->xmax = std::min(this->xmax, other.xmax);
70         this->ymax = std::min(this->ymax, other.ymax);
71 
72         if (xmax - xmin < 0 ||
73             ymax - ymin < 0)
74         {
75             // Zero area
76             ymin = ymax = xmin = xmax = 0;
77         }
78 
79         return *this;
80     }
81     SWR_RECT& operator &= (const SWR_RECT& other)
82     {
83         return Intersect(other);
84     }
85 
UnionSWR_RECT86     SWR_RECT& Union(const SWR_RECT& other)
87     {
88         this->xmin = std::min(this->xmin, other.xmin);
89         this->ymin = std::min(this->ymin, other.ymin);
90         this->xmax = std::max(this->xmax, other.xmax);
91         this->ymax = std::max(this->ymax, other.ymax);
92 
93         return *this;
94     }
95 
96     SWR_RECT& operator |= (const SWR_RECT& other)
97     {
98         return Union(other);
99     }
100 
TranslateSWR_RECT101     void Translate(int32_t x, int32_t y)
102     {
103         xmin += x;
104         ymin += y;
105         xmax += x;
106         ymax += y;
107     }
108 };
109 
110 //////////////////////////////////////////////////////////////////////////
111 /// @brief Function signature for load hot tiles
112 /// @param hPrivateContext - handle to private data
113 /// @param dstFormat - format of the hot tile
114 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
115 /// @param x - destination x coordinate
116 /// @param y - destination y coordinate
117 /// @param pDstHotTile - pointer to the hot tile surface
118 typedef void(SWR_API *PFN_LOAD_TILE)(HANDLE hPrivateContext, SWR_FORMAT dstFormat,
119     SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
120     uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, uint8_t *pDstHotTile);
121 
122 //////////////////////////////////////////////////////////////////////////
123 /// @brief Function signature for store hot tiles
124 /// @param hPrivateContext - handle to private data
125 /// @param srcFormat - format of the hot tile
126 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
127 /// @param x - destination x coordinate
128 /// @param y - destination y coordinate
129 /// @param pSrcHotTile - pointer to the hot tile surface
130 typedef void(SWR_API *PFN_STORE_TILE)(HANDLE hPrivateContext, SWR_FORMAT srcFormat,
131     SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
132     uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, uint8_t *pSrcHotTile);
133 
134 //////////////////////////////////////////////////////////////////////////
135 /// @brief Function signature for clearing from the hot tiles clear value
136 /// @param hPrivateContext - handle to private data
137 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
138 /// @param x - destination x coordinate
139 /// @param y - destination y coordinate
140 /// @param renderTargetArrayIndex - render target array offset from arrayIndex
141 /// @param pClearColor - pointer to the hot tile's clear value
142 typedef void(SWR_API *PFN_CLEAR_TILE)(HANDLE hPrivateContext,
143     SWR_RENDERTARGET_ATTACHMENT rtIndex,
144     uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, const float* pClearColor);
145 
146 //////////////////////////////////////////////////////////////////////////
147 /// @brief Callback to allow driver to update their copy of streamout write offset.
148 ///        This is call is made for any draw operation that has streamout enabled
149 ///        and has updated the write offset.
150 /// @param hPrivateContext - handle to private data
151 /// @param soBufferSlot - buffer slot for write offset
152 /// @param soWriteOffset - update value for so write offset.
153 typedef void(SWR_API *PFN_UPDATE_SO_WRITE_OFFSET)(HANDLE hPrivateContext,
154     uint32_t soBufferSlot, uint32_t soWriteOffset);
155 
156 //////////////////////////////////////////////////////////////////////////
157 /// @brief Callback to allow driver to update their copy of stats.
158 /// @param hPrivateContext - handle to private data
159 /// @param pStats - pointer to draw stats
160 typedef void(SWR_API *PFN_UPDATE_STATS)(HANDLE hPrivateContext,
161     const SWR_STATS* pStats);
162 
163 //////////////////////////////////////////////////////////////////////////
164 /// @brief Callback to allow driver to update their copy of FE stats.
165 /// @note Its optimal to have a separate callback for FE stats since
166 ///       there is only one DC per FE thread. This means we do not have
167 ///       to sum up the stats across all of the workers.
168 /// @param hPrivateContext - handle to private data
169 /// @param pStats - pointer to draw stats
170 typedef void(SWR_API *PFN_UPDATE_STATS_FE)(HANDLE hPrivateContext,
171     const SWR_STATS_FE* pStats);
172 
173 //////////////////////////////////////////////////////////////////////////
174 /// BucketManager
175 /// Forward Declaration (see rdtsc_buckets.h for full definition)
176 /////////////////////////////////////////////////////////////////////////
177 class BucketManager;
178 
179 //////////////////////////////////////////////////////////////////////////
180 /// SWR_THREADING_INFO
181 /////////////////////////////////////////////////////////////////////////
182 struct SWR_THREADING_INFO
183 {
184     uint32_t    BASE_NUMA_NODE;
185     uint32_t    BASE_CORE;
186     uint32_t    BASE_THREAD;
187     uint32_t    MAX_WORKER_THREADS;
188     uint32_t    MAX_NUMA_NODES;
189     uint32_t    MAX_CORES_PER_NUMA_NODE;
190     uint32_t    MAX_THREADS_PER_CORE;
191     bool        SINGLE_THREADED;
192 };
193 
194 //////////////////////////////////////////////////////////////////////////
195 /// SWR_API_THREADING_INFO
196 /// Data used to reserve HW threads for API use
197 /// API Threads are reserved from numa nodes / cores used for
198 /// SWR Worker threads.  Specifying reserved threads here can reduce
199 /// the total number of SWR worker threads.
200 /////////////////////////////////////////////////////////////////////////
201 struct SWR_API_THREADING_INFO
202 {
203     uint32_t numAPIReservedThreads; // Default is 1 if SWR_API_THREADING_INFO is not sent
204     uint32_t bindAPIThread0;        // Default is true if numAPIReservedThreads is > 0,
205                                     // binds thread used in SwrCreateContext to API Reserved
206                                     // thread 0
207     uint32_t numAPIThreadsPerCore;  // 0 - means use all threads per core, else clamp to this number.
208                                     // Independent of KNOB_MAX_THREADS_PER_CORE.
209 };
210 
211 
212 //////////////////////////////////////////////////////////////////////////
213 /// SWR_CREATECONTEXT_INFO
214 /////////////////////////////////////////////////////////////////////////
215 struct SWR_CREATECONTEXT_INFO
216 {
217     // External functions (e.g. sampler) need per draw context state.
218     // Use SwrGetPrivateContextState() to access private state.
219     uint32_t privateStateSize;
220 
221     // Callback functions
222     PFN_LOAD_TILE               pfnLoadTile;
223     PFN_STORE_TILE              pfnStoreTile;
224     PFN_CLEAR_TILE              pfnClearTile;
225     PFN_UPDATE_SO_WRITE_OFFSET  pfnUpdateSoWriteOffset;
226     PFN_UPDATE_STATS            pfnUpdateStats;
227     PFN_UPDATE_STATS_FE         pfnUpdateStatsFE;
228 
229 
230     // Pointer to rdtsc buckets mgr returned to the caller.
231     // Only populated when KNOB_ENABLE_RDTSC is set
232     BucketManager* pBucketMgr;
233 
234     // Output: size required memory passed to for SwrSaveState / SwrRestoreState
235     size_t  contextSaveSize;
236 
237     // ArchRast event manager.
238     HANDLE  hArEventManager;
239 
240     // Input (optional): Threading info that overrides any set KNOB values.
241     SWR_THREADING_INFO* pThreadInfo;
242 
243     // Input (optional}: Info for reserving API threads
244     SWR_API_THREADING_INFO* pApiThreadInfo;
245 
246     // Input: if set to non-zero value, overrides KNOB value for maximum
247     // number of draws in flight
248     uint32_t MAX_DRAWS_IN_FLIGHT;
249 };
250 
251 //////////////////////////////////////////////////////////////////////////
252 /// @brief Create SWR Context.
253 /// @param pCreateInfo - pointer to creation info.
254 SWR_FUNC(HANDLE, SwrCreateContext,
255     SWR_CREATECONTEXT_INFO* pCreateInfo);
256 
257 //////////////////////////////////////////////////////////////////////////
258 /// @brief Destroys SWR Context.
259 /// @param hContext - Handle passed back from SwrCreateContext
260 SWR_FUNC(void, SwrDestroyContext,
261     HANDLE hContext);
262 
263 //////////////////////////////////////////////////////////////////////////
264 /// @brief Bind current thread to an API reserved HW thread
265 /// @param hContext - Handle passed back from SwrCreateContext
266 /// @param apiThreadId - index of reserved HW thread to bind to.
267 SWR_FUNC(void, SwrBindApiThread,
268     HANDLE hContext,
269     uint32_t apiThreadId);
270 
271 //////////////////////////////////////////////////////////////////////////
272 /// @brief Saves API state associated with hContext
273 /// @param hContext - Handle passed back from SwrCreateContext
274 /// @param pOutputStateBlock - Memory block to receive API state data
275 /// @param memSize - Size of memory pointed to by pOutputStateBlock
276 SWR_FUNC(void, SwrSaveState,
277     HANDLE hContext,
278     void* pOutputStateBlock,
279     size_t memSize);
280 
281 //////////////////////////////////////////////////////////////////////////
282 /// @brief Restores API state to hContext previously saved with SwrSaveState
283 /// @param hContext - Handle passed back from SwrCreateContext
284 /// @param pStateBlock - Memory block to read API state data from
285 /// @param memSize - Size of memory pointed to by pStateBlock
286 SWR_FUNC(void, SwrRestoreState,
287     HANDLE hContext,
288     const void* pStateBlock,
289     size_t memSize);
290 
291 //////////////////////////////////////////////////////////////////////////
292 /// @brief Sync cmd. Executes the callback func when all rendering up to this sync
293 ///        has been completed
294 /// @param hContext - Handle passed back from SwrCreateContext
295 /// @param pfnFunc - pointer to callback function,
296 /// @param userData - user data to pass back
297 SWR_FUNC(void, SwrSync,
298     HANDLE hContext,
299     PFN_CALLBACK_FUNC pfnFunc,
300     uint64_t userData,
301     uint64_t userData2,
302     uint64_t userData3);
303 
304 //////////////////////////////////////////////////////////////////////////
305 /// @brief Stall cmd. Stalls the backend until all previous work has been completed.
306 ///        Frontend work can continue to make progress
307 /// @param hContext - Handle passed back from SwrCreateContext
308 SWR_FUNC(void, SwrStallBE,
309     HANDLE hContext);
310 
311 //////////////////////////////////////////////////////////////////////////
312 /// @brief Blocks until all rendering has been completed.
313 /// @param hContext - Handle passed back from SwrCreateContext
314 SWR_FUNC(void, SwrWaitForIdle,
315     HANDLE hContext);
316 
317 //////////////////////////////////////////////////////////////////////////
318 /// @brief Blocks until all FE rendering has been completed.
319 /// @param hContext - Handle passed back from SwrCreateContext
320 SWR_FUNC(void, SwrWaitForIdleFE,
321     HANDLE hContext);
322 
323 //////////////////////////////////////////////////////////////////////////
324 /// @brief Set vertex buffer state.
325 /// @param hContext - Handle passed back from SwrCreateContext
326 /// @param numBuffers - Number of vertex buffer state descriptors.
327 /// @param pVertexBuffers - Array of vertex buffer state descriptors.
328 SWR_FUNC(void, SwrSetVertexBuffers,
329     HANDLE hContext,
330     uint32_t numBuffers,
331     const SWR_VERTEX_BUFFER_STATE* pVertexBuffers);
332 
333 //////////////////////////////////////////////////////////////////////////
334 /// @brief Set index buffer
335 /// @param hContext - Handle passed back from SwrCreateContext
336 /// @param pIndexBuffer - Index buffer.
337 SWR_FUNC(void, SwrSetIndexBuffer,
338     HANDLE hContext,
339     const SWR_INDEX_BUFFER_STATE* pIndexBuffer);
340 
341 //////////////////////////////////////////////////////////////////////////
342 /// @brief Set fetch shader pointer.
343 /// @param hContext - Handle passed back from SwrCreateContext
344 /// @param pfnFetchFunc - Pointer to shader.
345 SWR_FUNC(void, SwrSetFetchFunc,
346     HANDLE hContext,
347     PFN_FETCH_FUNC    pfnFetchFunc);
348 
349 //////////////////////////////////////////////////////////////////////////
350 /// @brief Set streamout shader pointer.
351 /// @param hContext - Handle passed back from SwrCreateContext
352 /// @param pfnSoFunc - Pointer to shader.
353 /// @param streamIndex - specifies stream
354 SWR_FUNC(void, SwrSetSoFunc,
355     HANDLE hContext,
356     PFN_SO_FUNC    pfnSoFunc,
357     uint32_t streamIndex);
358 
359 //////////////////////////////////////////////////////////////////////////
360 /// @brief Set streamout state
361 /// @param hContext - Handle passed back from SwrCreateContext
362 /// @param pSoState - Pointer to streamout state.
363 SWR_FUNC(void, SwrSetSoState,
364     HANDLE hContext,
365     SWR_STREAMOUT_STATE* pSoState);
366 
367 //////////////////////////////////////////////////////////////////////////
368 /// @brief Set streamout buffer state
369 /// @param hContext - Handle passed back from SwrCreateContext
370 /// @param pSoBuffer - Pointer to streamout buffer.
371 /// @param slot - Slot to bind SO buffer to.
372 SWR_FUNC(void, SwrSetSoBuffers,
373     HANDLE hContext,
374     SWR_STREAMOUT_BUFFER* pSoBuffer,
375     uint32_t slot);
376 
377 //////////////////////////////////////////////////////////////////////////
378 /// @brief Set vertex shader pointer.
379 /// @param hContext - Handle passed back from SwrCreateContext
380 /// @param pfnVertexFunc - Pointer to shader.
381 SWR_FUNC(void, SwrSetVertexFunc,
382     HANDLE hContext,
383     PFN_VERTEX_FUNC pfnVertexFunc);
384 
385 //////////////////////////////////////////////////////////////////////////
386 /// @brief Set frontend state.
387 /// @param hContext - Handle passed back from SwrCreateContext
388 /// @param pState - Pointer to state
389 SWR_FUNC(void, SwrSetFrontendState,
390     HANDLE hContext,
391     SWR_FRONTEND_STATE *pState);
392 
393 //////////////////////////////////////////////////////////////////////////
394 /// @brief Set geometry shader state.
395 /// @param hContext - Handle passed back from SwrCreateContext
396 /// @param pState - Pointer to state
397 SWR_FUNC(void, SwrSetGsState,
398     HANDLE hContext,
399     SWR_GS_STATE *pState);
400 
401 //////////////////////////////////////////////////////////////////////////
402 /// @brief Set geometry shader
403 /// @param hContext - Handle passed back from SwrCreateContext
404 /// @param pState - Pointer to geometry shader function
405 SWR_FUNC(void, SwrSetGsFunc,
406     HANDLE hContext,
407     PFN_GS_FUNC pfnGsFunc);
408 
409 //////////////////////////////////////////////////////////////////////////
410 /// @brief Set compute shader
411 /// @param hContext - Handle passed back from SwrCreateContext
412 /// @param pfnCsFunc - Pointer to compute shader function
413 /// @param totalThreadsInGroup - product of thread group dimensions.
414 /// @param totalSpillFillSize - size in bytes needed for spill/fill.
415 /// @param scratchSpaceSizePerInstance - size of the scratch space needed per simd instance
416 /// @param numInstances - number of simd instances that are run per execution of the shader
417 SWR_FUNC(void, SwrSetCsFunc,
418     HANDLE hContext,
419     PFN_CS_FUNC pfnCsFunc,
420     uint32_t totalThreadsInGroup,
421     uint32_t totalSpillFillSize,
422     uint32_t scratchSpaceSizePerInstance,
423     uint32_t numInstances
424     );
425 
426 //////////////////////////////////////////////////////////////////////////
427 /// @brief Set tessellation state.
428 /// @param hContext - Handle passed back from SwrCreateContext
429 /// @param pState - Pointer to state
430 SWR_FUNC(void, SwrSetTsState,
431     HANDLE hContext,
432     SWR_TS_STATE *pState);
433 
434 //////////////////////////////////////////////////////////////////////////
435 /// @brief Set hull shader
436 /// @param hContext - Handle passed back from SwrCreateContext
437 /// @param pfnFunc - Pointer to shader function
438 SWR_FUNC(void, SwrSetHsFunc,
439     HANDLE hContext,
440     PFN_HS_FUNC pfnFunc);
441 
442 //////////////////////////////////////////////////////////////////////////
443 /// @brief Set domain shader
444 /// @param hContext - Handle passed back from SwrCreateContext
445 /// @param pfnFunc - Pointer to shader function
446 SWR_FUNC(void, SwrSetDsFunc,
447     HANDLE hContext,
448     PFN_DS_FUNC pfnFunc);
449 
450 //////////////////////////////////////////////////////////////////////////
451 /// @brief Set depth stencil state
452 /// @param hContext - Handle passed back from SwrCreateContext
453 /// @param pState - Pointer to state.
454 SWR_FUNC(void, SwrSetDepthStencilState,
455     HANDLE hContext,
456     SWR_DEPTH_STENCIL_STATE *pState);
457 
458 //////////////////////////////////////////////////////////////////////////
459 /// @brief Set backend state
460 /// @param hContext - Handle passed back from SwrCreateContext
461 /// @param pState - Pointer to state.
462 SWR_FUNC(void, SwrSetBackendState,
463     HANDLE hContext,
464     SWR_BACKEND_STATE *pState);
465 
466 //////////////////////////////////////////////////////////////////////////
467 /// @brief Set depth bounds state
468 /// @param hContext - Handle passed back from SwrCreateContext
469 /// @param pState - Pointer to state.
470 SWR_FUNC(void, SwrSetDepthBoundsState,
471     HANDLE hContext,
472     SWR_DEPTH_BOUNDS_STATE *pState);
473 
474 //////////////////////////////////////////////////////////////////////////
475 /// @brief Set pixel shader state
476 /// @param hContext - Handle passed back from SwrCreateContext
477 /// @param pState - Pointer to state.
478 SWR_FUNC(void, SwrSetPixelShaderState,
479     HANDLE hContext,
480     SWR_PS_STATE *pState);
481 
482 //////////////////////////////////////////////////////////////////////////
483 /// @brief Set blend state
484 /// @param hContext - Handle passed back from SwrCreateContext
485 /// @param pState - Pointer to state.
486 SWR_FUNC(void, SwrSetBlendState,
487     HANDLE hContext,
488     SWR_BLEND_STATE *pState);
489 
490 //////////////////////////////////////////////////////////////////////////
491 /// @brief Set blend function
492 /// @param hContext - Handle passed back from SwrCreateContext
493 /// @param renderTarget - render target index
494 /// @param pfnBlendFunc - function pointer
495 SWR_FUNC(void, SwrSetBlendFunc,
496     HANDLE hContext,
497     uint32_t renderTarget,
498     PFN_BLEND_JIT_FUNC pfnBlendFunc);
499 
500 //////////////////////////////////////////////////////////////////////////
501 /// @brief SwrDraw
502 /// @param hContext - Handle passed back from SwrCreateContext
503 /// @param topology - Specifies topology for draw.
504 /// @param startVertex - Specifies start vertex in vertex buffer for draw.
505 /// @param primCount - Number of vertices.
506 SWR_FUNC(void, SwrDraw,
507     HANDLE hContext,
508     PRIMITIVE_TOPOLOGY topology,
509     uint32_t startVertex,
510     uint32_t primCount);
511 
512 //////////////////////////////////////////////////////////////////////////
513 /// @brief SwrDrawInstanced
514 /// @param hContext - Handle passed back from SwrCreateContext
515 /// @param topology - Specifies topology for draw.
516 /// @param numVertsPerInstance - How many vertices to read sequentially from vertex data.
517 /// @param numInstances - How many instances to render.
518 /// @param startVertex - Specifies start vertex for draw. (vertex data)
519 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
520 SWR_FUNC(void, SwrDrawInstanced,
521     HANDLE hContext,
522     PRIMITIVE_TOPOLOGY topology,
523     uint32_t numVertsPerInstance,
524     uint32_t numInstances,
525     uint32_t startVertex,
526     uint32_t startInstance);
527 
528 //////////////////////////////////////////////////////////////////////////
529 /// @brief DrawIndexed
530 /// @param hContext - Handle passed back from SwrCreateContext
531 /// @param topology - Specifies topology for draw.
532 /// @param numIndices - Number of indices to read sequentially from index buffer.
533 /// @param indexOffset - Starting index into index buffer.
534 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
535 SWR_FUNC(void, SwrDrawIndexed,
536     HANDLE hContext,
537     PRIMITIVE_TOPOLOGY topology,
538     uint32_t numIndices,
539     uint32_t indexOffset,
540     int32_t baseVertex);
541 
542 //////////////////////////////////////////////////////////////////////////
543 /// @brief SwrDrawIndexedInstanced
544 /// @param hContext - Handle passed back from SwrCreateContext
545 /// @param topology - Specifies topology for draw.
546 /// @param numIndices - Number of indices to read sequentially from index buffer.
547 /// @param numInstances - Number of instances to render.
548 /// @param indexOffset - Starting index into index buffer.
549 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
550 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
551 SWR_FUNC(void, SwrDrawIndexedInstanced,
552     HANDLE hContext,
553     PRIMITIVE_TOPOLOGY topology,
554     uint32_t numIndices,
555     uint32_t numInstances,
556     uint32_t indexOffset,
557     int32_t baseVertex,
558     uint32_t startInstance);
559 
560 //////////////////////////////////////////////////////////////////////////
561 /// @brief SwrInvalidateTiles
562 /// @param hContext - Handle passed back from SwrCreateContext
563 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
564 /// @param invalidateRect - The pixel-coordinate rectangle to invalidate.  This will be expanded to
565 ///                         be hottile size-aligned.
566 SWR_FUNC(void, SwrInvalidateTiles,
567     HANDLE hContext,
568     uint32_t attachmentMask,
569     const SWR_RECT& invalidateRect);
570 
571 //////////////////////////////////////////////////////////////////////////
572 /// @brief SwrDiscardRect
573 /// @param hContext - Handle passed back from SwrCreateContext
574 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard.
575 /// @param rect - The pixel-coordinate rectangle to discard.  Only fully-covered hottiles will be
576 ///               discarded.
577 SWR_FUNC(void, SwrDiscardRect,
578     HANDLE hContext,
579     uint32_t attachmentMask,
580     const SWR_RECT& rect);
581 
582 //////////////////////////////////////////////////////////////////////////
583 /// @brief SwrDispatch
584 /// @param hContext - Handle passed back from SwrCreateContext
585 /// @param threadGroupCountX - Number of thread groups dispatched in X direction
586 /// @param threadGroupCountY - Number of thread groups dispatched in Y direction
587 /// @param threadGroupCountZ - Number of thread groups dispatched in Z direction
588 SWR_FUNC(void, SwrDispatch,
589     HANDLE hContext,
590     uint32_t threadGroupCountX,
591     uint32_t threadGroupCountY,
592     uint32_t threadGroupCountZ);
593 
594 
595 enum SWR_TILE_STATE
596 {
597     SWR_TILE_INVALID    = 0,    // tile is in unitialized state and should be loaded with surface contents before rendering
598     SWR_TILE_DIRTY      = 2,    // tile contains newer data than surface it represents
599     SWR_TILE_RESOLVED   = 3,    // is in sync with surface it represents
600 };
601 
602 /// @todo Add a good description for what attachments are and when and why you would use the different SWR_TILE_STATEs.
603 SWR_FUNC(void, SwrStoreTiles,
604     HANDLE hContext,
605     uint32_t attachmentMask,
606     SWR_TILE_STATE postStoreTileState,
607     const SWR_RECT& storeRect);
608 
609 
610 //////////////////////////////////////////////////////////////////////////
611 /// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil
612 /// @param hContext - Handle passed back from SwrCreateContext
613 /// @param attachmentMask - combination of SWR_ATTACHMENT_*_BIT attachments to clear
614 /// @param renderTargetArrayIndex - the RT array index to clear
615 /// @param clearColor - color use for clearing render targets
616 /// @param z - depth value use for clearing depth buffer
617 /// @param stencil - stencil value used for clearing stencil buffer
618 /// @param clearRect - The pixel-coordinate rectangle to clear in all cleared buffers
619 SWR_FUNC(void, SwrClearRenderTarget,
620     HANDLE hContext,
621     uint32_t attachmentMask,
622     uint32_t renderTargetArrayIndex,
623     const float clearColor[4],
624     float z,
625     uint8_t stencil,
626     const SWR_RECT& clearRect);
627 
628 //////////////////////////////////////////////////////////////////////////
629 /// @brief SwrSetRastState
630 /// @param hContext - Handle passed back from SwrCreateContext
631 /// @param pRastState - New SWR_RASTSTATE used for SwrDraw* commands
632 SWR_FUNC(void, SwrSetRastState,
633     HANDLE hContext,
634     const SWR_RASTSTATE *pRastState);
635 
636 //////////////////////////////////////////////////////////////////////////
637 /// @brief SwrSetViewports
638 /// @param hContext - Handle passed back from SwrCreateContext
639 /// @param numViewports - number of viewports passed in
640 /// @param pViewports - Specifies extents of viewport.
641 /// @param pMatrices - If not specified then SWR computes a default one.
642 SWR_FUNC(void, SwrSetViewports,
643     HANDLE hContext,
644     uint32_t numViewports,
645     const SWR_VIEWPORT* pViewports,
646     const SWR_VIEWPORT_MATRICES* pMatrices);
647 
648 //////////////////////////////////////////////////////////////////////////
649 /// @brief SwrSetScissorRects
650 /// @param hContext - Handle passed back from SwrCreateContext
651 /// @param numScissors - number of scissors passed in
652 /// @param pScissors - array of scissors
653 SWR_FUNC(void, SwrSetScissorRects,
654     HANDLE hContext,
655     uint32_t numScissors,
656     const SWR_RECT* pScissors);
657 
658 //////////////////////////////////////////////////////////////////////////
659 /// @brief Returns a pointer to the private context state for the current
660 ///        draw operation. This is used for external componets such as the
661 ///        sampler.
662 ///
663 /// @note  Client needs to resend private state prior to each draw call.
664 ///        Also, SWR is responsible for the private state memory.
665 /// @param hContext - Handle passed back from SwrCreateContext
666 SWR_FUNC(void*, SwrGetPrivateContextState,
667     HANDLE hContext);
668 
669 //////////////////////////////////////////////////////////////////////////
670 /// @brief Clients can use this to allocate memory for draw/dispatch
671 ///        operations. The memory will automatically be freed once operation
672 ///        has completed. Client can use this to allocate binding tables,
673 ///        etc. needed for shader execution.
674 /// @param hContext - Handle passed back from SwrCreateContext
675 /// @param size - Size of allocation
676 /// @param align - Alignment needed for allocation.
677 SWR_FUNC(void*, SwrAllocDrawContextMemory,
678     HANDLE hContext,
679     uint32_t size,
680     uint32_t align);
681 
682 //////////////////////////////////////////////////////////////////////////
683 /// @brief Enables stats counting
684 /// @param hContext - Handle passed back from SwrCreateContext
685 /// @param enable - If true then counts are incremented.
686 SWR_FUNC(void, SwrEnableStatsFE,
687     HANDLE hContext,
688     bool enable);
689 
690 //////////////////////////////////////////////////////////////////////////
691 /// @brief Enables stats counting
692 /// @param hContext - Handle passed back from SwrCreateContext
693 /// @param enable - If true then counts are incremented.
694 SWR_FUNC(void, SwrEnableStatsBE,
695     HANDLE hContext,
696     bool enable);
697 
698 //////////////////////////////////////////////////////////////////////////
699 /// @brief Mark end of frame - used for performance profiling
700 /// @param hContext - Handle passed back from SwrCreateContext
701 SWR_FUNC(void, SwrEndFrame,
702     HANDLE hContext);
703 
704 //////////////////////////////////////////////////////////////////////////
705 /// @brief Initialize swr backend and memory internal tables
706 SWR_FUNC(void, SwrInit);
707 
708 
709 //////////////////////////////////////////////////////////////////////////
710 /// @brief Loads a full hottile from a render surface
711 /// @param hPrivateContext - Handle to private DC
712 /// @param dstFormat - Format for hot tile.
713 /// @param renderTargetIndex - Index to src render target
714 /// @param x, y - Coordinates to raster tile.
715 /// @param pDstHotTile - Pointer to Hot Tile
716 SWR_FUNC(void, SwrLoadHotTile,
717     const SWR_SURFACE_STATE *pSrcSurface,
718     SWR_FORMAT dstFormat,
719     SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
720     uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,
721     uint8_t *pDstHotTile);
722 
723 //////////////////////////////////////////////////////////////////////////
724 /// @brief Deswizzles and stores a full hottile to a render surface
725 /// @param hPrivateContext - Handle to private DC
726 /// @param srcFormat - Format for hot tile.
727 /// @param renderTargetIndex - Index to destination render target
728 /// @param x, y - Coordinates to raster tile.
729 /// @param pSrcHotTile - Pointer to Hot Tile
730 SWR_FUNC(void, SwrStoreHotTileToSurface,
731     SWR_SURFACE_STATE *pDstSurface,
732     SWR_FORMAT srcFormat,
733     SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
734     uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex,
735     uint8_t *pSrcHotTile);
736 
737 //////////////////////////////////////////////////////////////////////////
738 /// @brief Writes clear color to every pixel of a render surface
739 /// @param hPrivateContext - Handle to private DC
740 /// @param renderTargetIndex - Index to destination render target
741 /// @param x, y - Coordinates to raster tile.
742 /// @param pClearColor - Pointer to clear color
743 SWR_FUNC(void, SwrStoreHotTileClear,
744          SWR_SURFACE_STATE *pDstSurface,
745          SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
746          uint32_t x,
747          uint32_t y,
748          uint32_t renderTargetArrayIndex,
749          const float* pClearColor);
750 
751 struct SWR_INTERFACE
752 {
753     PFNSwrCreateContext pfnSwrCreateContext;
754     PFNSwrDestroyContext pfnSwrDestroyContext;
755     PFNSwrBindApiThread pfnSwrBindApiThread;
756     PFNSwrSaveState pfnSwrSaveState;
757     PFNSwrRestoreState pfnSwrRestoreState;
758     PFNSwrSync pfnSwrSync;
759     PFNSwrStallBE pfnSwrStallBE;
760     PFNSwrWaitForIdle pfnSwrWaitForIdle;
761     PFNSwrWaitForIdleFE pfnSwrWaitForIdleFE;
762     PFNSwrSetVertexBuffers pfnSwrSetVertexBuffers;
763     PFNSwrSetIndexBuffer pfnSwrSetIndexBuffer;
764     PFNSwrSetFetchFunc pfnSwrSetFetchFunc;
765     PFNSwrSetSoFunc pfnSwrSetSoFunc;
766     PFNSwrSetSoState pfnSwrSetSoState;
767     PFNSwrSetSoBuffers pfnSwrSetSoBuffers;
768     PFNSwrSetVertexFunc pfnSwrSetVertexFunc;
769     PFNSwrSetFrontendState pfnSwrSetFrontendState;
770     PFNSwrSetGsState pfnSwrSetGsState;
771     PFNSwrSetGsFunc pfnSwrSetGsFunc;
772     PFNSwrSetCsFunc pfnSwrSetCsFunc;
773     PFNSwrSetTsState pfnSwrSetTsState;
774     PFNSwrSetHsFunc pfnSwrSetHsFunc;
775     PFNSwrSetDsFunc pfnSwrSetDsFunc;
776     PFNSwrSetDepthStencilState pfnSwrSetDepthStencilState;
777     PFNSwrSetBackendState pfnSwrSetBackendState;
778     PFNSwrSetDepthBoundsState pfnSwrSetDepthBoundsState;
779     PFNSwrSetPixelShaderState pfnSwrSetPixelShaderState;
780     PFNSwrSetBlendState pfnSwrSetBlendState;
781     PFNSwrSetBlendFunc pfnSwrSetBlendFunc;
782     PFNSwrDraw pfnSwrDraw;
783     PFNSwrDrawInstanced pfnSwrDrawInstanced;
784     PFNSwrDrawIndexed pfnSwrDrawIndexed;
785     PFNSwrDrawIndexedInstanced pfnSwrDrawIndexedInstanced;
786     PFNSwrInvalidateTiles pfnSwrInvalidateTiles;
787     PFNSwrDiscardRect pfnSwrDiscardRect;
788     PFNSwrDispatch pfnSwrDispatch;
789     PFNSwrStoreTiles pfnSwrStoreTiles;
790     PFNSwrClearRenderTarget pfnSwrClearRenderTarget;
791     PFNSwrSetRastState pfnSwrSetRastState;
792     PFNSwrSetViewports pfnSwrSetViewports;
793     PFNSwrSetScissorRects pfnSwrSetScissorRects;
794     PFNSwrGetPrivateContextState pfnSwrGetPrivateContextState;
795     PFNSwrAllocDrawContextMemory pfnSwrAllocDrawContextMemory;
796     PFNSwrEnableStatsFE pfnSwrEnableStatsFE;
797     PFNSwrEnableStatsBE pfnSwrEnableStatsBE;
798     PFNSwrEndFrame pfnSwrEndFrame;
799     PFNSwrInit pfnSwrInit;
800     PFNSwrLoadHotTile pfnSwrLoadHotTile;
801     PFNSwrStoreHotTileToSurface pfnSwrStoreHotTileToSurface;
802     PFNSwrStoreHotTileClear pfnSwrStoreHotTileClear;
803 };
804 
805 extern "C" {
806 typedef void (SWR_API * PFNSwrGetInterface)(SWR_INTERFACE &out_funcs);
807 SWR_VISIBLE void SWR_API SwrGetInterface(SWR_INTERFACE &out_funcs);
808 }
809 
810 #endif
811