swr: [rasterizer core] allow override of KNOB thread settings
[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 <vector>
36
37 #include "common/simdintrin.h"
38 #include "common/formats.h"
39 #include "core/utils.h"
40 #include "core/state.h"
41
42 ///@todo place all the API functions into the 'swr' namespace.
43
44 typedef void(SWR_API *PFN_CALLBACK_FUNC)(uint64_t data, uint64_t data2, uint64_t data3);
45
46 //////////////////////////////////////////////////////////////////////////
47 /// @brief Function signature for load hot tiles
48 /// @param hPrivateContext - handle to private data
49 /// @param dstFormat - format of the hot tile
50 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
51 /// @param x - destination x coordinate
52 /// @param y - destination y coordinate
53 /// @param pDstHotTile - pointer to the hot tile surface
54 typedef void(SWR_API *PFN_LOAD_TILE)(HANDLE hPrivateContext, SWR_FORMAT dstFormat,
55 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
56 uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, uint8_t *pDstHotTile);
57
58 //////////////////////////////////////////////////////////////////////////
59 /// @brief Function signature for store hot tiles
60 /// @param hPrivateContext - handle to private data
61 /// @param srcFormat - format of the hot tile
62 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
63 /// @param x - destination x coordinate
64 /// @param y - destination y coordinate
65 /// @param pSrcHotTile - pointer to the hot tile surface
66 typedef void(SWR_API *PFN_STORE_TILE)(HANDLE hPrivateContext, SWR_FORMAT srcFormat,
67 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex,
68 uint32_t x, uint32_t y, uint32_t renderTargetArrayIndex, uint8_t *pSrcHotTile);
69
70 //////////////////////////////////////////////////////////////////////////
71 /// @brief Function signature for clearing from the hot tiles clear value
72 /// @param hPrivateContext - handle to private data
73 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
74 /// @param x - destination x coordinate
75 /// @param y - destination y coordinate
76 /// @param pClearColor - pointer to the hot tile's clear value
77 typedef void(SWR_API *PFN_CLEAR_TILE)(HANDLE hPrivateContext,
78 SWR_RENDERTARGET_ATTACHMENT rtIndex,
79 uint32_t x, uint32_t y, const float* pClearColor);
80
81 //////////////////////////////////////////////////////////////////////////
82 /// @brief Callback to allow driver to update their copy of streamout write offset.
83 /// This is call is made for any draw operation that has streamout enabled
84 /// and has updated the write offset.
85 /// @param hPrivateContext - handle to private data
86 /// @param soBufferSlot - buffer slot for write offset
87 /// @param soWriteOffset - update value for so write offset.
88 typedef void(SWR_API *PFN_UPDATE_SO_WRITE_OFFSET)(HANDLE hPrivateContext,
89 uint32_t soBufferSlot, uint32_t soWriteOffset);
90
91 class BucketManager;
92
93 //////////////////////////////////////////////////////////////////////////
94 /// SWR_THREADING_INFO
95 /////////////////////////////////////////////////////////////////////////
96 struct SWR_THREADING_INFO
97 {
98 uint32_t MAX_WORKER_THREADS;
99 uint32_t MAX_NUMA_NODES;
100 uint32_t MAX_CORES_PER_NUMA_NODE;
101 uint32_t MAX_THREADS_PER_CORE;
102 bool SINGLE_THREADED;
103 };
104
105 //////////////////////////////////////////////////////////////////////////
106 /// SWR_CREATECONTEXT_INFO
107 /////////////////////////////////////////////////////////////////////////
108 struct SWR_CREATECONTEXT_INFO
109 {
110 DRIVER_TYPE driver;
111
112 // External functions (e.g. sampler) need per draw context state.
113 // Use SwrGetPrivateContextState() to access private state.
114 uint32_t privateStateSize;
115
116 // Callback functions
117 PFN_LOAD_TILE pfnLoadTile;
118 PFN_STORE_TILE pfnStoreTile;
119 PFN_CLEAR_TILE pfnClearTile;
120 PFN_UPDATE_SO_WRITE_OFFSET pfnUpdateSoWriteOffset;
121
122 // Pointer to rdtsc buckets mgr returned to the caller.
123 // Only populated when KNOB_ENABLE_RDTSC is set
124 BucketManager* pBucketMgr;
125
126 // Output: size required memory passed to for SwrSaveState / SwrRestoreState
127 size_t contextSaveSize;
128
129 // Input (optional): Threading info that overrides any set KNOB values.
130 SWR_THREADING_INFO* pThreadInfo;
131 };
132
133 //////////////////////////////////////////////////////////////////////////
134 /// SWR_RECT
135 /////////////////////////////////////////////////////////////////////////
136 struct SWR_RECT
137 {
138 uint32_t left;
139 uint32_t right;
140 uint32_t top;
141 uint32_t bottom;
142 };
143
144 //////////////////////////////////////////////////////////////////////////
145 /// @brief Create SWR Context.
146 /// @param pCreateInfo - pointer to creation info.
147 HANDLE SWR_API SwrCreateContext(
148 SWR_CREATECONTEXT_INFO* pCreateInfo);
149
150 //////////////////////////////////////////////////////////////////////////
151 /// @brief Destroys SWR Context.
152 /// @param hContext - Handle passed back from SwrCreateContext
153 void SWR_API SwrDestroyContext(
154 HANDLE hContext);
155
156 //////////////////////////////////////////////////////////////////////////
157 /// @brief Saves API state associated with hContext
158 /// @param hContext - Handle passed back from SwrCreateContext
159 /// @param pOutputStateBlock - Memory block to receive API state data
160 /// @param memSize - Size of memory pointed to by pOutputStateBlock
161 void SWR_API SwrSaveState(
162 HANDLE hContext,
163 void* pOutputStateBlock,
164 size_t memSize);
165
166 //////////////////////////////////////////////////////////////////////////
167 /// @brief Restores API state to hContext previously saved with SwrSaveState
168 /// @param hContext - Handle passed back from SwrCreateContext
169 /// @param pStateBlock - Memory block to read API state data from
170 /// @param memSize - Size of memory pointed to by pStateBlock
171 void SWR_API SwrRestoreState(
172 HANDLE hContext,
173 const void* pStateBlock,
174 size_t memSize);
175
176 //////////////////////////////////////////////////////////////////////////
177 /// @brief Sync cmd. Executes the callback func when all rendering up to this sync
178 /// has been completed
179 /// @param hContext - Handle passed back from SwrCreateContext
180 /// @param pfnFunc - pointer to callback function,
181 /// @param userData - user data to pass back
182 void SWR_API SwrSync(
183 HANDLE hContext,
184 PFN_CALLBACK_FUNC pfnFunc,
185 uint64_t userData,
186 uint64_t userData2,
187 uint64_t userData3 = 0);
188
189 //////////////////////////////////////////////////////////////////////////
190 /// @brief Blocks until all rendering has been completed.
191 /// @param hContext - Handle passed back from SwrCreateContext
192 void SWR_API SwrWaitForIdle(
193 HANDLE hContext);
194
195 //////////////////////////////////////////////////////////////////////////
196 /// @brief Blocks until all FE rendering has been completed.
197 /// @param hContext - Handle passed back from SwrCreateContext
198 void SWR_API SwrWaitForIdleFE(
199 HANDLE hContext);
200
201 //////////////////////////////////////////////////////////////////////////
202 /// @brief Set vertex buffer state.
203 /// @param hContext - Handle passed back from SwrCreateContext
204 /// @param numBuffers - Number of vertex buffer state descriptors.
205 /// @param pVertexBuffers - Array of vertex buffer state descriptors.
206 void SWR_API SwrSetVertexBuffers(
207 HANDLE hContext,
208 uint32_t numBuffers,
209 const SWR_VERTEX_BUFFER_STATE* pVertexBuffers);
210
211 //////////////////////////////////////////////////////////////////////////
212 /// @brief Set index buffer
213 /// @param hContext - Handle passed back from SwrCreateContext
214 /// @param pIndexBuffer - Index buffer.
215 void SWR_API SwrSetIndexBuffer(
216 HANDLE hContext,
217 const SWR_INDEX_BUFFER_STATE* pIndexBuffer);
218
219 //////////////////////////////////////////////////////////////////////////
220 /// @brief Set fetch shader pointer.
221 /// @param hContext - Handle passed back from SwrCreateContext
222 /// @param pfnFetchFunc - Pointer to shader.
223 void SWR_API SwrSetFetchFunc(
224 HANDLE hContext,
225 PFN_FETCH_FUNC pfnFetchFunc);
226
227 //////////////////////////////////////////////////////////////////////////
228 /// @brief Set streamout shader pointer.
229 /// @param hContext - Handle passed back from SwrCreateContext
230 /// @param pfnSoFunc - Pointer to shader.
231 /// @param streamIndex - specifies stream
232 void SWR_API SwrSetSoFunc(
233 HANDLE hContext,
234 PFN_SO_FUNC pfnSoFunc,
235 uint32_t streamIndex);
236
237 //////////////////////////////////////////////////////////////////////////
238 /// @brief Set streamout state
239 /// @param hContext - Handle passed back from SwrCreateContext
240 /// @param pSoState - Pointer to streamout state.
241 void SWR_API SwrSetSoState(
242 HANDLE hContext,
243 SWR_STREAMOUT_STATE* pSoState);
244
245 //////////////////////////////////////////////////////////////////////////
246 /// @brief Set streamout buffer state
247 /// @param hContext - Handle passed back from SwrCreateContext
248 /// @param pSoBuffer - Pointer to streamout buffer.
249 /// @param slot - Slot to bind SO buffer to.
250 void SWR_API SwrSetSoBuffers(
251 HANDLE hContext,
252 SWR_STREAMOUT_BUFFER* pSoBuffer,
253 uint32_t slot);
254
255 //////////////////////////////////////////////////////////////////////////
256 /// @brief Set vertex shader pointer.
257 /// @param hContext - Handle passed back from SwrCreateContext
258 /// @param pfnVertexFunc - Pointer to shader.
259 void SWR_API SwrSetVertexFunc(
260 HANDLE hContext,
261 PFN_VERTEX_FUNC pfnVertexFunc);
262
263 //////////////////////////////////////////////////////////////////////////
264 /// @brief Set frontend state.
265 /// @param hContext - Handle passed back from SwrCreateContext
266 /// @param pState - Pointer to state
267 void SWR_API SwrSetFrontendState(
268 HANDLE hContext,
269 SWR_FRONTEND_STATE *pState);
270
271 //////////////////////////////////////////////////////////////////////////
272 /// @brief Set geometry shader state.
273 /// @param hContext - Handle passed back from SwrCreateContext
274 /// @param pState - Pointer to state
275 void SWR_API SwrSetGsState(
276 HANDLE hContext,
277 SWR_GS_STATE *pState);
278
279 //////////////////////////////////////////////////////////////////////////
280 /// @brief Set geometry shader
281 /// @param hContext - Handle passed back from SwrCreateContext
282 /// @param pState - Pointer to geometry shader function
283 void SWR_API SwrSetGsFunc(
284 HANDLE hContext,
285 PFN_GS_FUNC pfnGsFunc);
286
287 //////////////////////////////////////////////////////////////////////////
288 /// @brief Set compute shader
289 /// @param hContext - Handle passed back from SwrCreateContext
290 /// @param pfnCsFunc - Pointer to compute shader function
291 /// @param totalThreadsInGroup - product of thread group dimensions.
292 /// @param totalSpillFillSize - size in bytes needed for spill/fill.
293 void SWR_API SwrSetCsFunc(
294 HANDLE hContext,
295 PFN_CS_FUNC pfnCsFunc,
296 uint32_t totalThreadsInGroup,
297 uint32_t totalSpillFillSize);
298
299 //////////////////////////////////////////////////////////////////////////
300 /// @brief Set tessellation state.
301 /// @param hContext - Handle passed back from SwrCreateContext
302 /// @param pState - Pointer to state
303 void SWR_API SwrSetTsState(
304 HANDLE hContext,
305 SWR_TS_STATE *pState);
306
307 //////////////////////////////////////////////////////////////////////////
308 /// @brief Set hull shader
309 /// @param hContext - Handle passed back from SwrCreateContext
310 /// @param pfnFunc - Pointer to shader function
311 void SWR_API SwrSetHsFunc(
312 HANDLE hContext,
313 PFN_HS_FUNC pfnFunc);
314
315 //////////////////////////////////////////////////////////////////////////
316 /// @brief Set domain shader
317 /// @param hContext - Handle passed back from SwrCreateContext
318 /// @param pfnFunc - Pointer to shader function
319 void SWR_API SwrSetDsFunc(
320 HANDLE hContext,
321 PFN_DS_FUNC pfnFunc);
322
323 //////////////////////////////////////////////////////////////////////////
324 /// @brief Set depth stencil state
325 /// @param hContext - Handle passed back from SwrCreateContext
326 /// @param pState - Pointer to state.
327 void SWR_API SwrSetDepthStencilState(
328 HANDLE hContext,
329 SWR_DEPTH_STENCIL_STATE *pState);
330
331 //////////////////////////////////////////////////////////////////////////
332 /// @brief Set backend state
333 /// @param hContext - Handle passed back from SwrCreateContext
334 /// @param pState - Pointer to state.
335 void SWR_API SwrSetBackendState(
336 HANDLE hContext,
337 SWR_BACKEND_STATE *pState);
338
339 //////////////////////////////////////////////////////////////////////////
340 /// @brief Set pixel shader state
341 /// @param hContext - Handle passed back from SwrCreateContext
342 /// @param pState - Pointer to state.
343 void SWR_API SwrSetPixelShaderState(
344 HANDLE hContext,
345 SWR_PS_STATE *pState);
346
347 //////////////////////////////////////////////////////////////////////////
348 /// @brief Set blend state
349 /// @param hContext - Handle passed back from SwrCreateContext
350 /// @param pState - Pointer to state.
351 void SWR_API SwrSetBlendState(
352 HANDLE hContext,
353 SWR_BLEND_STATE *pState);
354
355 //////////////////////////////////////////////////////////////////////////
356 /// @brief Set blend function
357 /// @param hContext - Handle passed back from SwrCreateContext
358 /// @param renderTarget - render target index
359 /// @param pfnBlendFunc - function pointer
360 void SWR_API SwrSetBlendFunc(
361 HANDLE hContext,
362 uint32_t renderTarget,
363 PFN_BLEND_JIT_FUNC pfnBlendFunc);
364
365 //////////////////////////////////////////////////////////////////////////
366 /// @brief SwrDraw
367 /// @param hContext - Handle passed back from SwrCreateContext
368 /// @param topology - Specifies topology for draw.
369 /// @param startVertex - Specifies start vertex in vertex buffer for draw.
370 /// @param primCount - Number of vertices.
371 void SWR_API SwrDraw(
372 HANDLE hContext,
373 PRIMITIVE_TOPOLOGY topology,
374 uint32_t startVertex,
375 uint32_t primCount);
376
377 //////////////////////////////////////////////////////////////////////////
378 /// @brief SwrDrawInstanced
379 /// @param hContext - Handle passed back from SwrCreateContext
380 /// @param topology - Specifies topology for draw.
381 /// @param numVertsPerInstance - How many vertices to read sequentially from vertex data.
382 /// @param numInstances - How many instances to render.
383 /// @param startVertex - Specifies start vertex for draw. (vertex data)
384 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
385 void SWR_API SwrDrawInstanced(
386 HANDLE hContext,
387 PRIMITIVE_TOPOLOGY topology,
388 uint32_t numVertsPerInstance,
389 uint32_t numInstances,
390 uint32_t startVertex,
391 uint32_t startInstance);
392
393 //////////////////////////////////////////////////////////////////////////
394 /// @brief DrawIndexed
395 /// @param hContext - Handle passed back from SwrCreateContext
396 /// @param topology - Specifies topology for draw.
397 /// @param numIndices - Number of indices to read sequentially from index buffer.
398 /// @param indexOffset - Starting index into index buffer.
399 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
400 void SWR_API SwrDrawIndexed(
401 HANDLE hContext,
402 PRIMITIVE_TOPOLOGY topology,
403 uint32_t numIndices,
404 uint32_t indexOffset,
405 int32_t baseVertex);
406
407 //////////////////////////////////////////////////////////////////////////
408 /// @brief SwrDrawIndexedInstanced
409 /// @param hContext - Handle passed back from SwrCreateContext
410 /// @param topology - Specifies topology for draw.
411 /// @param numIndices - Number of indices to read sequentially from index buffer.
412 /// @param numInstances - Number of instances to render.
413 /// @param indexOffset - Starting index into index buffer.
414 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
415 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
416 void SWR_API SwrDrawIndexedInstanced(
417 HANDLE hContext,
418 PRIMITIVE_TOPOLOGY topology,
419 uint32_t numIndices,
420 uint32_t numInstances,
421 uint32_t indexOffset,
422 int32_t baseVertex,
423 uint32_t startInstance);
424
425 //////////////////////////////////////////////////////////////////////////
426 /// @brief SwrInvalidateTiles
427 /// @param hContext - Handle passed back from SwrCreateContext
428 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
429 void SWR_API SwrInvalidateTiles(
430 HANDLE hContext,
431 uint32_t attachmentMask);
432
433 //////////////////////////////////////////////////////////////////////////
434 /// @brief SwrDiscardRect
435 /// @param hContext - Handle passed back from SwrCreateContext
436 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard.
437 /// @param rect - if rect is all zeros, the entire attachment surface will be discarded
438 void SWR_API SwrDiscardRect(
439 HANDLE hContext,
440 uint32_t attachmentMask,
441 SWR_RECT rect);
442
443 //////////////////////////////////////////////////////////////////////////
444 /// @brief SwrDispatch
445 /// @param hContext - Handle passed back from SwrCreateContext
446 /// @param threadGroupCountX - Number of thread groups dispatched in X direction
447 /// @param threadGroupCountY - Number of thread groups dispatched in Y direction
448 /// @param threadGroupCountZ - Number of thread groups dispatched in Z direction
449 void SWR_API SwrDispatch(
450 HANDLE hContext,
451 uint32_t threadGroupCountX,
452 uint32_t threadGroupCountY,
453 uint32_t threadGroupCountZ);
454
455
456 enum SWR_TILE_STATE
457 {
458 SWR_TILE_INVALID = 0, // tile is in unitialized state and should be loaded with surface contents before rendering
459 SWR_TILE_DIRTY = 2, // tile contains newer data than surface it represents
460 SWR_TILE_RESOLVED = 3, // is in sync with surface it represents
461 };
462
463 /// @todo Add a good description for what attachments are and when and why you would use the different SWR_TILE_STATEs.
464 void SWR_API SwrStoreTiles(
465 HANDLE hContext,
466 SWR_RENDERTARGET_ATTACHMENT attachment,
467 SWR_TILE_STATE postStoreTileState);
468
469 void SWR_API SwrClearRenderTarget(
470 HANDLE hContext,
471 uint32_t clearMask,
472 const float clearColor[4],
473 float z,
474 uint8_t stencil);
475
476 void SWR_API SwrSetRastState(
477 HANDLE hContext,
478 const SWR_RASTSTATE *pRastState);
479
480 //////////////////////////////////////////////////////////////////////////
481 /// @brief SwrSetViewports
482 /// @param hContext - Handle passed back from SwrCreateContext
483 /// @param numViewports - number of viewports passed in
484 /// @param pViewports - Specifies extents of viewport.
485 /// @param pMatrices - If not specified then SWR computes a default one.
486 void SWR_API SwrSetViewports(
487 HANDLE hContext,
488 uint32_t numViewports,
489 const SWR_VIEWPORT* pViewports,
490 const SWR_VIEWPORT_MATRIX* pMatrices);
491
492 //////////////////////////////////////////////////////////////////////////
493 /// @brief SwrSetScissorRects
494 /// @param hContext - Handle passed back from SwrCreateContext
495 /// @param numScissors - number of scissors passed in
496 /// @param pScissors - array of scissors
497 void SWR_API SwrSetScissorRects(
498 HANDLE hContext,
499 uint32_t numScissors,
500 const BBOX* pScissors);
501
502 //////////////////////////////////////////////////////////////////////////
503 /// @brief Returns a pointer to the private context state for the current
504 /// draw operation. This is used for external componets such as the
505 /// sampler.
506 ///
507 /// @note Client needs to resend private state prior to each draw call.
508 /// Also, SWR is responsible for the private state memory.
509 /// @param hContext - Handle passed back from SwrCreateContext
510 VOID* SWR_API SwrGetPrivateContextState(
511 HANDLE hContext);
512
513 //////////////////////////////////////////////////////////////////////////
514 /// @brief Clients can use this to allocate memory for draw/dispatch
515 /// operations. The memory will automatically be freed once operation
516 /// has completed. Client can use this to allocate binding tables,
517 /// etc. needed for shader execution.
518 /// @param hContext - Handle passed back from SwrCreateContext
519 /// @param size - Size of allocation
520 /// @param align - Alignment needed for allocation.
521 VOID* SWR_API SwrAllocDrawContextMemory(
522 HANDLE hContext,
523 uint32_t size,
524 uint32_t align);
525
526 //////////////////////////////////////////////////////////////////////////
527 /// @brief Returns pointer to SWR stats.
528 /// @note The counters are incremented by multiple threads.
529 /// When calling this, you need to ensure all previous operations
530 /// have completed.
531 /// @param hContext - Handle passed back from SwrCreateContext
532 /// @param pStats - SWR will fill this out for caller.
533 void SWR_API SwrGetStats(
534 HANDLE hContext,
535 SWR_STATS* pStats);
536
537 //////////////////////////////////////////////////////////////////////////
538 /// @brief Enables stats counting
539 /// @param hContext - Handle passed back from SwrCreateContext
540 /// @param enable - If true then counts are incremented.
541 void SWR_API SwrEnableStats(
542 HANDLE hContext,
543 bool enable);
544
545 //////////////////////////////////////////////////////////////////////////
546 /// @brief Mark end of frame - used for performance profiling
547 /// @param hContext - Handle passed back from SwrCreateContext
548 void SWR_API SwrEndFrame(
549 HANDLE hContext);
550 #endif//__SWR_API_H__