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