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