1 /****************************************************************************
2 * Copyright (C) 2014-2015 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 /// @brief Function signature for clearing from the hot tiles clear value
71 /// @param hPrivateContext - handle to private data
72 /// @param renderTargetIndex - render target to store, can be color, depth or stencil
73 /// @param x - destination x coordinate
74 /// @param y - destination y coordinate
75 /// @param pClearColor - pointer to the hot tile's clear value
76 typedef void(SWR_API
*PFN_CLEAR_TILE
)(HANDLE hPrivateContext
,
77 SWR_RENDERTARGET_ATTACHMENT rtIndex
,
78 uint32_t x
, uint32_t y
, const float* pClearColor
);
82 //////////////////////////////////////////////////////////////////////////
83 /// SWR_CREATECONTEXT_INFO
84 /////////////////////////////////////////////////////////////////////////
85 struct SWR_CREATECONTEXT_INFO
89 // External functions (e.g. sampler) need per draw context state.
90 // Use SwrGetPrivateContextState() to access private state.
91 uint32_t privateStateSize
;
93 // Tile manipulation functions
94 PFN_LOAD_TILE pfnLoadTile
;
95 PFN_STORE_TILE pfnStoreTile
;
96 PFN_CLEAR_TILE pfnClearTile
;
98 // Pointer to rdtsc buckets mgr returned to the caller.
99 // Only populated when KNOB_ENABLE_RDTSC is set
100 BucketManager
* pBucketMgr
;
102 // Output: size required memory passed to for SwrSaveState / SwrRestoreState
103 size_t contextSaveSize
;
106 //////////////////////////////////////////////////////////////////////////
108 /////////////////////////////////////////////////////////////////////////
117 //////////////////////////////////////////////////////////////////////////
118 /// @brief Create SWR Context.
119 /// @param pCreateInfo - pointer to creation info.
120 HANDLE SWR_API
SwrCreateContext(
121 SWR_CREATECONTEXT_INFO
* pCreateInfo
);
123 //////////////////////////////////////////////////////////////////////////
124 /// @brief Destroys SWR Context.
125 /// @param hContext - Handle passed back from SwrCreateContext
126 void SWR_API
SwrDestroyContext(
129 //////////////////////////////////////////////////////////////////////////
130 /// @brief Saves API state associated with hContext
131 /// @param hContext - Handle passed back from SwrCreateContext
132 /// @param pOutputStateBlock - Memory block to receive API state data
133 /// @param memSize - Size of memory pointed to by pOutputStateBlock
134 void SWR_API
SwrSaveState(
136 void* pOutputStateBlock
,
139 //////////////////////////////////////////////////////////////////////////
140 /// @brief Restores API state to hContext previously saved with SwrSaveState
141 /// @param hContext - Handle passed back from SwrCreateContext
142 /// @param pStateBlock - Memory block to read API state data from
143 /// @param memSize - Size of memory pointed to by pStateBlock
144 void SWR_API
SwrRestoreState(
146 const void* pStateBlock
,
149 //////////////////////////////////////////////////////////////////////////
150 /// @brief Sync cmd. Executes the callback func when all rendering up to this sync
151 /// has been completed
152 /// @param hContext - Handle passed back from SwrCreateContext
153 /// @param pfnFunc - pointer to callback function,
154 /// @param userData - user data to pass back
155 void SWR_API
SwrSync(
157 PFN_CALLBACK_FUNC pfnFunc
,
160 uint64_t userData3
= 0);
162 //////////////////////////////////////////////////////////////////////////
163 /// @brief Blocks until all rendering has been completed.
164 /// @param hContext - Handle passed back from SwrCreateContext
165 void SWR_API
SwrWaitForIdle(
168 //////////////////////////////////////////////////////////////////////////
169 /// @brief Set vertex buffer state.
170 /// @param hContext - Handle passed back from SwrCreateContext
171 /// @param numBuffers - Number of vertex buffer state descriptors.
172 /// @param pVertexBuffers - Array of vertex buffer state descriptors.
173 void SWR_API
SwrSetVertexBuffers(
176 const SWR_VERTEX_BUFFER_STATE
* pVertexBuffers
);
178 //////////////////////////////////////////////////////////////////////////
179 /// @brief Set index buffer
180 /// @param hContext - Handle passed back from SwrCreateContext
181 /// @param pIndexBuffer - Index buffer.
182 void SWR_API
SwrSetIndexBuffer(
184 const SWR_INDEX_BUFFER_STATE
* pIndexBuffer
);
186 //////////////////////////////////////////////////////////////////////////
187 /// @brief Set fetch shader pointer.
188 /// @param hContext - Handle passed back from SwrCreateContext
189 /// @param pfnFetchFunc - Pointer to shader.
190 void SWR_API
SwrSetFetchFunc(
192 PFN_FETCH_FUNC pfnFetchFunc
);
194 //////////////////////////////////////////////////////////////////////////
195 /// @brief Set streamout shader pointer.
196 /// @param hContext - Handle passed back from SwrCreateContext
197 /// @param pfnSoFunc - Pointer to shader.
198 /// @param streamIndex - specifies stream
199 void SWR_API
SwrSetSoFunc(
201 PFN_SO_FUNC pfnSoFunc
,
202 uint32_t streamIndex
);
204 //////////////////////////////////////////////////////////////////////////
205 /// @brief Set streamout state
206 /// @param hContext - Handle passed back from SwrCreateContext
207 /// @param pSoState - Pointer to streamout state.
208 void SWR_API
SwrSetSoState(
210 SWR_STREAMOUT_STATE
* pSoState
);
212 //////////////////////////////////////////////////////////////////////////
213 /// @brief Set streamout buffer state
214 /// @param hContext - Handle passed back from SwrCreateContext
215 /// @param pSoBuffer - Pointer to streamout buffer.
216 /// @param slot - Slot to bind SO buffer to.
217 void SWR_API
SwrSetSoBuffers(
219 SWR_STREAMOUT_BUFFER
* pSoBuffer
,
222 //////////////////////////////////////////////////////////////////////////
223 /// @brief Set vertex shader pointer.
224 /// @param hContext - Handle passed back from SwrCreateContext
225 /// @param pfnVertexFunc - Pointer to shader.
226 void SWR_API
SwrSetVertexFunc(
228 PFN_VERTEX_FUNC pfnVertexFunc
);
230 //////////////////////////////////////////////////////////////////////////
231 /// @brief Set frontend state.
232 /// @param hContext - Handle passed back from SwrCreateContext
233 /// @param pState - Pointer to state
234 void SWR_API
SwrSetFrontendState(
236 SWR_FRONTEND_STATE
*pState
);
238 //////////////////////////////////////////////////////////////////////////
239 /// @brief Set geometry shader state.
240 /// @param hContext - Handle passed back from SwrCreateContext
241 /// @param pState - Pointer to state
242 void SWR_API
SwrSetGsState(
244 SWR_GS_STATE
*pState
);
246 //////////////////////////////////////////////////////////////////////////
247 /// @brief Set geometry shader
248 /// @param hContext - Handle passed back from SwrCreateContext
249 /// @param pState - Pointer to geometry shader function
250 void SWR_API
SwrSetGsFunc(
252 PFN_GS_FUNC pfnGsFunc
);
254 //////////////////////////////////////////////////////////////////////////
255 /// @brief Set compute shader
256 /// @param hContext - Handle passed back from SwrCreateContext
257 /// @param pfnCsFunc - Pointer to compute shader function
258 /// @param totalThreadsInGroup - product of thread group dimensions.
259 /// @param totalSpillFillSize - size in bytes needed for spill/fill.
260 void SWR_API
SwrSetCsFunc(
262 PFN_CS_FUNC pfnCsFunc
,
263 uint32_t totalThreadsInGroup
,
264 uint32_t totalSpillFillSize
);
266 //////////////////////////////////////////////////////////////////////////
267 /// @brief Set tessellation state.
268 /// @param hContext - Handle passed back from SwrCreateContext
269 /// @param pState - Pointer to state
270 void SWR_API
SwrSetTsState(
272 SWR_TS_STATE
*pState
);
274 //////////////////////////////////////////////////////////////////////////
275 /// @brief Set hull shader
276 /// @param hContext - Handle passed back from SwrCreateContext
277 /// @param pfnFunc - Pointer to shader function
278 void SWR_API
SwrSetHsFunc(
280 PFN_HS_FUNC pfnFunc
);
282 //////////////////////////////////////////////////////////////////////////
283 /// @brief Set domain shader
284 /// @param hContext - Handle passed back from SwrCreateContext
285 /// @param pfnFunc - Pointer to shader function
286 void SWR_API
SwrSetDsFunc(
288 PFN_DS_FUNC pfnFunc
);
290 //////////////////////////////////////////////////////////////////////////
291 /// @brief Set depth stencil state
292 /// @param hContext - Handle passed back from SwrCreateContext
293 /// @param pState - Pointer to state.
294 void SWR_API
SwrSetDepthStencilState(
296 SWR_DEPTH_STENCIL_STATE
*pState
);
298 //////////////////////////////////////////////////////////////////////////
299 /// @brief Set backend state
300 /// @param hContext - Handle passed back from SwrCreateContext
301 /// @param pState - Pointer to state.
302 void SWR_API
SwrSetBackendState(
304 SWR_BACKEND_STATE
*pState
);
306 //////////////////////////////////////////////////////////////////////////
307 /// @brief Set pixel shader state
308 /// @param hContext - Handle passed back from SwrCreateContext
309 /// @param pState - Pointer to state.
310 void SWR_API
SwrSetPixelShaderState(
312 SWR_PS_STATE
*pState
);
314 //////////////////////////////////////////////////////////////////////////
315 /// @brief Set blend state
316 /// @param hContext - Handle passed back from SwrCreateContext
317 /// @param pState - Pointer to state.
318 void SWR_API
SwrSetBlendState(
320 SWR_BLEND_STATE
*pState
);
322 //////////////////////////////////////////////////////////////////////////
323 /// @brief Set blend function
324 /// @param hContext - Handle passed back from SwrCreateContext
325 /// @param renderTarget - render target index
326 /// @param pfnBlendFunc - function pointer
327 void SWR_API
SwrSetBlendFunc(
329 uint32_t renderTarget
,
330 PFN_BLEND_JIT_FUNC pfnBlendFunc
);
332 //////////////////////////////////////////////////////////////////////////
334 /// @param hContext - Handle passed back from SwrCreateContext
335 /// @param topology - Specifies topology for draw.
336 /// @param startVertex - Specifies start vertex in vertex buffer for draw.
337 /// @param primCount - Number of vertices.
338 void SWR_API
SwrDraw(
340 PRIMITIVE_TOPOLOGY topology
,
341 uint32_t startVertex
,
344 //////////////////////////////////////////////////////////////////////////
345 /// @brief SwrDrawInstanced
346 /// @param hContext - Handle passed back from SwrCreateContext
347 /// @param topology - Specifies topology for draw.
348 /// @param numVertsPerInstance - How many vertices to read sequentially from vertex data.
349 /// @param numInstances - How many instances to render.
350 /// @param startVertex - Specifies start vertex for draw. (vertex data)
351 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
352 void SWR_API
SwrDrawInstanced(
354 PRIMITIVE_TOPOLOGY topology
,
355 uint32_t numVertsPerInstance
,
356 uint32_t numInstances
,
357 uint32_t startVertex
,
358 uint32_t startInstance
);
360 //////////////////////////////////////////////////////////////////////////
361 /// @brief DrawIndexed
362 /// @param hContext - Handle passed back from SwrCreateContext
363 /// @param topology - Specifies topology for draw.
364 /// @param numIndices - Number of indices to read sequentially from index buffer.
365 /// @param indexOffset - Starting index into index buffer.
366 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
367 void SWR_API
SwrDrawIndexed(
369 PRIMITIVE_TOPOLOGY topology
,
371 uint32_t indexOffset
,
374 //////////////////////////////////////////////////////////////////////////
375 /// @brief SwrDrawIndexedInstanced
376 /// @param hContext - Handle passed back from SwrCreateContext
377 /// @param topology - Specifies topology for draw.
378 /// @param numIndices - Number of indices to read sequentially from index buffer.
379 /// @param numInstances - Number of instances to render.
380 /// @param indexOffset - Starting index into index buffer.
381 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
382 /// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
383 void SWR_API
SwrDrawIndexedInstanced(
385 PRIMITIVE_TOPOLOGY topology
,
387 uint32_t numInstances
,
388 uint32_t indexOffset
,
390 uint32_t startInstance
);
392 //////////////////////////////////////////////////////////////////////////
393 /// @brief SwrInvalidateTiles
394 /// @param hContext - Handle passed back from SwrCreateContext
395 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to invalidate.
396 void SWR_API
SwrInvalidateTiles(
398 uint32_t attachmentMask
);
400 //////////////////////////////////////////////////////////////////////////
401 /// @brief SwrDiscardRect
402 /// @param hContext - Handle passed back from SwrCreateContext
403 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard.
404 /// @param rect - if rect is all zeros, the entire attachment surface will be discarded
405 void SWR_API
SwrDiscardRect(
407 uint32_t attachmentMask
,
410 //////////////////////////////////////////////////////////////////////////
411 /// @brief SwrDispatch
412 /// @param hContext - Handle passed back from SwrCreateContext
413 /// @param threadGroupCountX - Number of thread groups dispatched in X direction
414 /// @param threadGroupCountY - Number of thread groups dispatched in Y direction
415 /// @param threadGroupCountZ - Number of thread groups dispatched in Z direction
416 void SWR_API
SwrDispatch(
418 uint32_t threadGroupCountX
,
419 uint32_t threadGroupCountY
,
420 uint32_t threadGroupCountZ
);
425 SWR_TILE_INVALID
= 0, // tile is in unitialized state and should be loaded with surface contents before rendering
426 SWR_TILE_DIRTY
= 2, // tile contains newer data than surface it represents
427 SWR_TILE_RESOLVED
= 3, // is in sync with surface it represents
430 /// @todo Add a good description for what attachments are and when and why you would use the different SWR_TILE_STATEs.
431 void SWR_API
SwrStoreTiles(
433 SWR_RENDERTARGET_ATTACHMENT attachment
,
434 SWR_TILE_STATE postStoreTileState
);
436 void SWR_API
SwrClearRenderTarget(
439 const float clearColor
[4],
443 void SWR_API
SwrSetRastState(
445 const SWR_RASTSTATE
*pRastState
);
447 //////////////////////////////////////////////////////////////////////////
448 /// @brief SwrSetViewports
449 /// @param hContext - Handle passed back from SwrCreateContext
450 /// @param numViewports - number of viewports passed in
451 /// @param pViewports - Specifies extents of viewport.
452 /// @param pMatrices - If not specified then SWR computes a default one.
453 void SWR_API
SwrSetViewports(
455 uint32_t numViewports
,
456 const SWR_VIEWPORT
* pViewports
,
457 const SWR_VIEWPORT_MATRIX
* pMatrices
);
459 //////////////////////////////////////////////////////////////////////////
460 /// @brief SwrSetScissorRects
461 /// @param hContext - Handle passed back from SwrCreateContext
462 /// @param numScissors - number of scissors passed in
463 /// @param pScissors - array of scissors
464 void SWR_API
SwrSetScissorRects(
466 uint32_t numScissors
,
467 const BBOX
* pScissors
);
469 //////////////////////////////////////////////////////////////////////////
470 /// @brief Returns a pointer to the private context state for the current
471 /// draw operation. This is used for external componets such as the
474 /// @note Client needs to resend private state prior to each draw call.
475 /// Also, SWR is responsible for the private state memory.
476 /// @param hContext - Handle passed back from SwrCreateContext
477 VOID
* SWR_API
SwrGetPrivateContextState(
480 //////////////////////////////////////////////////////////////////////////
481 /// @brief Clients can use this to allocate memory for draw/dispatch
482 /// operations. The memory will automatically be freed once operation
483 /// has completed. Client can use this to allocate binding tables,
484 /// etc. needed for shader execution.
485 /// @param hContext - Handle passed back from SwrCreateContext
486 /// @param size - Size of allocation
487 /// @param align - Alignment needed for allocation.
488 VOID
* SWR_API
SwrAllocDrawContextMemory(
493 //////////////////////////////////////////////////////////////////////////
494 /// @brief Returns pointer to SWR stats.
495 /// @note The counters are incremented by multiple threads.
496 /// When calling this, you need to ensure all previous operations
498 /// @param hContext - Handle passed back from SwrCreateContext
499 /// @param pStats - SWR will fill this out for caller.
500 void SWR_API
SwrGetStats(
504 //////////////////////////////////////////////////////////////////////////
505 /// @brief Enables stats counting
506 /// @param hContext - Handle passed back from SwrCreateContext
507 /// @param enable - If true then counts are incremented.
508 void SWR_API
SwrEnableStats(
512 //////////////////////////////////////////////////////////////////////////
513 /// @brief Mark end of frame - used for performance profiling
514 /// @param hContext - Handle passed back from SwrCreateContext
515 void SWR_API
SwrEndFrame(
517 #endif//__SWR_API_H__