1 /****************************************************************************
2 * Copyright (C) 2014-2016 Intel Corporation. All Rights Reserved.
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:
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
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
25 * @brief API definitions
27 ******************************************************************************/
32 #include "common/os.h"
37 #include "common/simdintrin.h"
38 #include "common/formats.h"
39 #include "core/utils.h"
40 #include "core/state.h"
42 ///@todo place all the API functions into the 'swr' namespace.
44 typedef void(SWR_API
*PFN_CALLBACK_FUNC
)(uint64_t data
, uint64_t data2
, uint64_t data3
);
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
);
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
);
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
);
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
);
91 //////////////////////////////////////////////////////////////////////////
92 /// @brief Callback to allow driver to update their copy of stats.
93 /// @param hPrivateContext - handle to private data
94 /// @param pStats - pointer to draw stats
95 typedef void(SWR_API
*PFN_UPDATE_STATS
)(HANDLE hPrivateContext
,
96 const SWR_STATS
* pStats
);
100 //////////////////////////////////////////////////////////////////////////
101 /// SWR_THREADING_INFO
102 /////////////////////////////////////////////////////////////////////////
103 struct SWR_THREADING_INFO
105 uint32_t MAX_WORKER_THREADS
;
106 uint32_t MAX_NUMA_NODES
;
107 uint32_t MAX_CORES_PER_NUMA_NODE
;
108 uint32_t MAX_THREADS_PER_CORE
;
109 bool SINGLE_THREADED
;
112 //////////////////////////////////////////////////////////////////////////
113 /// SWR_CREATECONTEXT_INFO
114 /////////////////////////////////////////////////////////////////////////
115 struct SWR_CREATECONTEXT_INFO
119 // External functions (e.g. sampler) need per draw context state.
120 // Use SwrGetPrivateContextState() to access private state.
121 uint32_t privateStateSize
;
123 // Callback functions
124 PFN_LOAD_TILE pfnLoadTile
;
125 PFN_STORE_TILE pfnStoreTile
;
126 PFN_CLEAR_TILE pfnClearTile
;
127 PFN_UPDATE_SO_WRITE_OFFSET pfnUpdateSoWriteOffset
;
128 PFN_UPDATE_STATS pfnUpdateStats
;
130 // Pointer to rdtsc buckets mgr returned to the caller.
131 // Only populated when KNOB_ENABLE_RDTSC is set
132 BucketManager
* pBucketMgr
;
134 // Output: size required memory passed to for SwrSaveState / SwrRestoreState
135 size_t contextSaveSize
;
137 // Input (optional): Threading info that overrides any set KNOB values.
138 SWR_THREADING_INFO
* pThreadInfo
;
141 //////////////////////////////////////////////////////////////////////////
143 /////////////////////////////////////////////////////////////////////////
152 //////////////////////////////////////////////////////////////////////////
153 /// @brief Create SWR Context.
154 /// @param pCreateInfo - pointer to creation info.
155 HANDLE SWR_API
SwrCreateContext(
156 SWR_CREATECONTEXT_INFO
* pCreateInfo
);
158 //////////////////////////////////////////////////////////////////////////
159 /// @brief Destroys SWR Context.
160 /// @param hContext - Handle passed back from SwrCreateContext
161 void SWR_API
SwrDestroyContext(
164 //////////////////////////////////////////////////////////////////////////
165 /// @brief Saves API state associated with hContext
166 /// @param hContext - Handle passed back from SwrCreateContext
167 /// @param pOutputStateBlock - Memory block to receive API state data
168 /// @param memSize - Size of memory pointed to by pOutputStateBlock
169 void SWR_API
SwrSaveState(
171 void* pOutputStateBlock
,
174 //////////////////////////////////////////////////////////////////////////
175 /// @brief Restores API state to hContext previously saved with SwrSaveState
176 /// @param hContext - Handle passed back from SwrCreateContext
177 /// @param pStateBlock - Memory block to read API state data from
178 /// @param memSize - Size of memory pointed to by pStateBlock
179 void SWR_API
SwrRestoreState(
181 const void* pStateBlock
,
184 //////////////////////////////////////////////////////////////////////////
185 /// @brief Sync cmd. Executes the callback func when all rendering up to this sync
186 /// has been completed
187 /// @param hContext - Handle passed back from SwrCreateContext
188 /// @param pfnFunc - pointer to callback function,
189 /// @param userData - user data to pass back
190 void SWR_API
SwrSync(
192 PFN_CALLBACK_FUNC pfnFunc
,
195 uint64_t userData3
= 0);
197 //////////////////////////////////////////////////////////////////////////
198 /// @brief Blocks until all rendering has been completed.
199 /// @param hContext - Handle passed back from SwrCreateContext
200 void SWR_API
SwrWaitForIdle(
203 //////////////////////////////////////////////////////////////////////////
204 /// @brief Blocks until all FE rendering has been completed.
205 /// @param hContext - Handle passed back from SwrCreateContext
206 void SWR_API
SwrWaitForIdleFE(
209 //////////////////////////////////////////////////////////////////////////
210 /// @brief Set vertex buffer state.
211 /// @param hContext - Handle passed back from SwrCreateContext
212 /// @param numBuffers - Number of vertex buffer state descriptors.
213 /// @param pVertexBuffers - Array of vertex buffer state descriptors.
214 void SWR_API
SwrSetVertexBuffers(
217 const SWR_VERTEX_BUFFER_STATE
* pVertexBuffers
);
219 //////////////////////////////////////////////////////////////////////////
220 /// @brief Set index buffer
221 /// @param hContext - Handle passed back from SwrCreateContext
222 /// @param pIndexBuffer - Index buffer.
223 void SWR_API
SwrSetIndexBuffer(
225 const SWR_INDEX_BUFFER_STATE
* pIndexBuffer
);
227 //////////////////////////////////////////////////////////////////////////
228 /// @brief Set fetch shader pointer.
229 /// @param hContext - Handle passed back from SwrCreateContext
230 /// @param pfnFetchFunc - Pointer to shader.
231 void SWR_API
SwrSetFetchFunc(
233 PFN_FETCH_FUNC pfnFetchFunc
);
235 //////////////////////////////////////////////////////////////////////////
236 /// @brief Set streamout shader pointer.
237 /// @param hContext - Handle passed back from SwrCreateContext
238 /// @param pfnSoFunc - Pointer to shader.
239 /// @param streamIndex - specifies stream
240 void SWR_API
SwrSetSoFunc(
242 PFN_SO_FUNC pfnSoFunc
,
243 uint32_t streamIndex
);
245 //////////////////////////////////////////////////////////////////////////
246 /// @brief Set streamout state
247 /// @param hContext - Handle passed back from SwrCreateContext
248 /// @param pSoState - Pointer to streamout state.
249 void SWR_API
SwrSetSoState(
251 SWR_STREAMOUT_STATE
* pSoState
);
253 //////////////////////////////////////////////////////////////////////////
254 /// @brief Set streamout buffer state
255 /// @param hContext - Handle passed back from SwrCreateContext
256 /// @param pSoBuffer - Pointer to streamout buffer.
257 /// @param slot - Slot to bind SO buffer to.
258 void SWR_API
SwrSetSoBuffers(
260 SWR_STREAMOUT_BUFFER
* pSoBuffer
,
263 //////////////////////////////////////////////////////////////////////////
264 /// @brief Set vertex shader pointer.
265 /// @param hContext - Handle passed back from SwrCreateContext
266 /// @param pfnVertexFunc - Pointer to shader.
267 void SWR_API
SwrSetVertexFunc(
269 PFN_VERTEX_FUNC pfnVertexFunc
);
271 //////////////////////////////////////////////////////////////////////////
272 /// @brief Set frontend state.
273 /// @param hContext - Handle passed back from SwrCreateContext
274 /// @param pState - Pointer to state
275 void SWR_API
SwrSetFrontendState(
277 SWR_FRONTEND_STATE
*pState
);
279 //////////////////////////////////////////////////////////////////////////
280 /// @brief Set geometry shader state.
281 /// @param hContext - Handle passed back from SwrCreateContext
282 /// @param pState - Pointer to state
283 void SWR_API
SwrSetGsState(
285 SWR_GS_STATE
*pState
);
287 //////////////////////////////////////////////////////////////////////////
288 /// @brief Set geometry shader
289 /// @param hContext - Handle passed back from SwrCreateContext
290 /// @param pState - Pointer to geometry shader function
291 void SWR_API
SwrSetGsFunc(
293 PFN_GS_FUNC pfnGsFunc
);
295 //////////////////////////////////////////////////////////////////////////
296 /// @brief Set compute shader
297 /// @param hContext - Handle passed back from SwrCreateContext
298 /// @param pfnCsFunc - Pointer to compute shader function
299 /// @param totalThreadsInGroup - product of thread group dimensions.
300 /// @param totalSpillFillSize - size in bytes needed for spill/fill.
301 void SWR_API
SwrSetCsFunc(
303 PFN_CS_FUNC pfnCsFunc
,
304 uint32_t totalThreadsInGroup
,
305 uint32_t totalSpillFillSize
);
307 //////////////////////////////////////////////////////////////////////////
308 /// @brief Set tessellation state.
309 /// @param hContext - Handle passed back from SwrCreateContext
310 /// @param pState - Pointer to state
311 void SWR_API
SwrSetTsState(
313 SWR_TS_STATE
*pState
);
315 //////////////////////////////////////////////////////////////////////////
316 /// @brief Set hull shader
317 /// @param hContext - Handle passed back from SwrCreateContext
318 /// @param pfnFunc - Pointer to shader function
319 void SWR_API
SwrSetHsFunc(
321 PFN_HS_FUNC pfnFunc
);
323 //////////////////////////////////////////////////////////////////////////
324 /// @brief Set domain shader
325 /// @param hContext - Handle passed back from SwrCreateContext
326 /// @param pfnFunc - Pointer to shader function
327 void SWR_API
SwrSetDsFunc(
329 PFN_DS_FUNC pfnFunc
);
331 //////////////////////////////////////////////////////////////////////////
332 /// @brief Set depth stencil state
333 /// @param hContext - Handle passed back from SwrCreateContext
334 /// @param pState - Pointer to state.
335 void SWR_API
SwrSetDepthStencilState(
337 SWR_DEPTH_STENCIL_STATE
*pState
);
339 //////////////////////////////////////////////////////////////////////////
340 /// @brief Set backend state
341 /// @param hContext - Handle passed back from SwrCreateContext
342 /// @param pState - Pointer to state.
343 void SWR_API
SwrSetBackendState(
345 SWR_BACKEND_STATE
*pState
);
347 //////////////////////////////////////////////////////////////////////////
348 /// @brief Set pixel shader state
349 /// @param hContext - Handle passed back from SwrCreateContext
350 /// @param pState - Pointer to state.
351 void SWR_API
SwrSetPixelShaderState(
353 SWR_PS_STATE
*pState
);
355 //////////////////////////////////////////////////////////////////////////
356 /// @brief Set blend state
357 /// @param hContext - Handle passed back from SwrCreateContext
358 /// @param pState - Pointer to state.
359 void SWR_API
SwrSetBlendState(
361 SWR_BLEND_STATE
*pState
);
363 //////////////////////////////////////////////////////////////////////////
364 /// @brief Set blend function
365 /// @param hContext - Handle passed back from SwrCreateContext
366 /// @param renderTarget - render target index
367 /// @param pfnBlendFunc - function pointer
368 void SWR_API
SwrSetBlendFunc(
370 uint32_t renderTarget
,
371 PFN_BLEND_JIT_FUNC pfnBlendFunc
);
373 //////////////////////////////////////////////////////////////////////////
375 /// @param hContext - Handle passed back from SwrCreateContext
376 /// @param topology - Specifies topology for draw.
377 /// @param startVertex - Specifies start vertex in vertex buffer for draw.
378 /// @param primCount - Number of vertices.
379 void SWR_API
SwrDraw(
381 PRIMITIVE_TOPOLOGY topology
,
382 uint32_t startVertex
,
385 //////////////////////////////////////////////////////////////////////////
386 /// @brief SwrDrawInstanced
387 /// @param hContext - Handle passed back from SwrCreateContext
388 /// @param topology - Specifies topology for draw.
389 /// @param numVertsPerInstance - How many vertices to read sequentially from vertex data.
390 /// @param numInstances - How many instances to render.
391 /// @param startVertex - Specifies start vertex for draw. (vertex data)
392 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
393 void SWR_API
SwrDrawInstanced(
395 PRIMITIVE_TOPOLOGY topology
,
396 uint32_t numVertsPerInstance
,
397 uint32_t numInstances
,
398 uint32_t startVertex
,
399 uint32_t startInstance
);
401 //////////////////////////////////////////////////////////////////////////
402 /// @brief DrawIndexed
403 /// @param hContext - Handle passed back from SwrCreateContext
404 /// @param topology - Specifies topology for draw.
405 /// @param numIndices - Number of indices to read sequentially from index buffer.
406 /// @param indexOffset - Starting index into index buffer.
407 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
408 void SWR_API
SwrDrawIndexed(
410 PRIMITIVE_TOPOLOGY topology
,
412 uint32_t indexOffset
,
415 //////////////////////////////////////////////////////////////////////////
416 /// @brief SwrDrawIndexedInstanced
417 /// @param hContext - Handle passed back from SwrCreateContext
418 /// @param topology - Specifies topology for draw.
419 /// @param numIndices - Number of indices to read sequentially from index buffer.
420 /// @param numInstances - Number of instances to render.
421 /// @param indexOffset - Starting index into index buffer.
422 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
423 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
424 void SWR_API
SwrDrawIndexedInstanced(
426 PRIMITIVE_TOPOLOGY topology
,
428 uint32_t numInstances
,
429 uint32_t indexOffset
,
431 uint32_t startInstance
);
433 //////////////////////////////////////////////////////////////////////////
434 /// @brief SwrInvalidateTiles
435 /// @param hContext - Handle passed back from SwrCreateContext
436 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
437 void SWR_API
SwrInvalidateTiles(
439 uint32_t attachmentMask
);
441 //////////////////////////////////////////////////////////////////////////
442 /// @brief SwrDiscardRect
443 /// @param hContext - Handle passed back from SwrCreateContext
444 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard.
445 /// @param rect - if rect is all zeros, the entire attachment surface will be discarded
446 void SWR_API
SwrDiscardRect(
448 uint32_t attachmentMask
,
451 //////////////////////////////////////////////////////////////////////////
452 /// @brief SwrDispatch
453 /// @param hContext - Handle passed back from SwrCreateContext
454 /// @param threadGroupCountX - Number of thread groups dispatched in X direction
455 /// @param threadGroupCountY - Number of thread groups dispatched in Y direction
456 /// @param threadGroupCountZ - Number of thread groups dispatched in Z direction
457 void SWR_API
SwrDispatch(
459 uint32_t threadGroupCountX
,
460 uint32_t threadGroupCountY
,
461 uint32_t threadGroupCountZ
);
466 SWR_TILE_INVALID
= 0, // tile is in unitialized state and should be loaded with surface contents before rendering
467 SWR_TILE_DIRTY
= 2, // tile contains newer data than surface it represents
468 SWR_TILE_RESOLVED
= 3, // is in sync with surface it represents
471 /// @todo Add a good description for what attachments are and when and why you would use the different SWR_TILE_STATEs.
472 void SWR_API
SwrStoreTiles(
474 SWR_RENDERTARGET_ATTACHMENT attachment
,
475 SWR_TILE_STATE postStoreTileState
);
477 void SWR_API
SwrClearRenderTarget(
480 const float clearColor
[4],
484 void SWR_API
SwrSetRastState(
486 const SWR_RASTSTATE
*pRastState
);
488 //////////////////////////////////////////////////////////////////////////
489 /// @brief SwrSetViewports
490 /// @param hContext - Handle passed back from SwrCreateContext
491 /// @param numViewports - number of viewports passed in
492 /// @param pViewports - Specifies extents of viewport.
493 /// @param pMatrices - If not specified then SWR computes a default one.
494 void SWR_API
SwrSetViewports(
496 uint32_t numViewports
,
497 const SWR_VIEWPORT
* pViewports
,
498 const SWR_VIEWPORT_MATRICES
* pMatrices
);
500 //////////////////////////////////////////////////////////////////////////
501 /// @brief SwrSetScissorRects
502 /// @param hContext - Handle passed back from SwrCreateContext
503 /// @param numScissors - number of scissors passed in
504 /// @param pScissors - array of scissors
505 void SWR_API
SwrSetScissorRects(
507 uint32_t numScissors
,
508 const BBOX
* pScissors
);
510 //////////////////////////////////////////////////////////////////////////
511 /// @brief Returns a pointer to the private context state for the current
512 /// draw operation. This is used for external componets such as the
515 /// @note Client needs to resend private state prior to each draw call.
516 /// Also, SWR is responsible for the private state memory.
517 /// @param hContext - Handle passed back from SwrCreateContext
518 VOID
* SWR_API
SwrGetPrivateContextState(
521 //////////////////////////////////////////////////////////////////////////
522 /// @brief Clients can use this to allocate memory for draw/dispatch
523 /// operations. The memory will automatically be freed once operation
524 /// has completed. Client can use this to allocate binding tables,
525 /// etc. needed for shader execution.
526 /// @param hContext - Handle passed back from SwrCreateContext
527 /// @param size - Size of allocation
528 /// @param align - Alignment needed for allocation.
529 VOID
* SWR_API
SwrAllocDrawContextMemory(
534 //////////////////////////////////////////////////////////////////////////
535 /// @brief Returns pointer to SWR stats.
536 /// @note The counters are incremented by multiple threads.
537 /// When calling this, you need to ensure all previous operations
539 /// @param hContext - Handle passed back from SwrCreateContext
540 /// @param pStats - SWR will fill this out for caller.
541 void SWR_API
SwrGetStats(
545 //////////////////////////////////////////////////////////////////////////
546 /// @brief Enables stats counting
547 /// @param hContext - Handle passed back from SwrCreateContext
548 /// @param enable - If true then counts are incremented.
549 void SWR_API
SwrEnableStats(
553 //////////////////////////////////////////////////////////////////////////
554 /// @brief Mark end of frame - used for performance profiling
555 /// @param hContext - Handle passed back from SwrCreateContext
556 void SWR_API
SwrEndFrame(
558 #endif//__SWR_API_H__