1 /**************************************************************************** 2 * Copyright (C) 2014-2018 Intel Corporation. All Rights Reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 * 23 * @file api.h 24 * 25 * @brief API definitions 26 * 27 ******************************************************************************/ 28 29 #ifndef __SWR_API_H__ 30 #define __SWR_API_H__ 31 32 #include "common/os.h" 33 34 #include <assert.h> 35 #include <algorithm> 36 37 #include "common/intrin.h" 38 #include "common/formats.h" 39 #include "core/state.h" 40 41 typedef void(SWR_API* PFN_CALLBACK_FUNC)(uint64_t data, uint64_t data2, uint64_t data3); 42 43 ////////////////////////////////////////////////////////////////////////// 44 /// @brief Rectangle structure 45 struct SWR_RECT 46 { 47 int32_t xmin; ///< inclusive 48 int32_t ymin; ///< inclusive 49 int32_t xmax; ///< exclusive 50 int32_t ymax; ///< exclusive 51 52 bool operator==(const SWR_RECT& rhs) 53 { 54 return (this->ymin == rhs.ymin && this->ymax == rhs.ymax && this->xmin == rhs.xmin && 55 this->xmax == rhs.xmax); 56 } 57 58 bool operator!=(const SWR_RECT& rhs) { return !(*this == rhs); } 59 IntersectSWR_RECT60 SWR_RECT& Intersect(const SWR_RECT& other) 61 { 62 this->xmin = std::max(this->xmin, other.xmin); 63 this->ymin = std::max(this->ymin, other.ymin); 64 this->xmax = std::min(this->xmax, other.xmax); 65 this->ymax = std::min(this->ymax, other.ymax); 66 67 if (xmax - xmin < 0 || ymax - ymin < 0) 68 { 69 // Zero area 70 ymin = ymax = xmin = xmax = 0; 71 } 72 73 return *this; 74 } 75 SWR_RECT& operator&=(const SWR_RECT& other) { return Intersect(other); } 76 UnionSWR_RECT77 SWR_RECT& Union(const SWR_RECT& other) 78 { 79 this->xmin = std::min(this->xmin, other.xmin); 80 this->ymin = std::min(this->ymin, other.ymin); 81 this->xmax = std::max(this->xmax, other.xmax); 82 this->ymax = std::max(this->ymax, other.ymax); 83 84 return *this; 85 } 86 87 SWR_RECT& operator|=(const SWR_RECT& other) { return Union(other); } 88 TranslateSWR_RECT89 void Translate(int32_t x, int32_t y) 90 { 91 xmin += x; 92 ymin += y; 93 xmax += x; 94 ymax += y; 95 } 96 }; 97 98 ////////////////////////////////////////////////////////////////////////// 99 /// @brief Function signature for load hot tiles 100 /// @param hDC - handle to DRAW_CONTEXT 101 /// @param dstFormat - format of the hot tile 102 /// @param renderTargetIndex - render target to store, can be color, depth or stencil 103 /// @param x - destination x coordinate 104 /// @param y - destination y coordinate 105 /// @param pDstHotTile - pointer to the hot tile surface 106 typedef void(SWR_API* PFN_LOAD_TILE)(HANDLE hDC, 107 HANDLE hWorkerPrivateData, 108 SWR_FORMAT dstFormat, 109 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex, 110 uint32_t x, 111 uint32_t y, 112 uint32_t renderTargetArrayIndex, 113 uint8_t* pDstHotTile); 114 115 ////////////////////////////////////////////////////////////////////////// 116 /// @brief Function signature for store hot tiles 117 /// @param hDC - handle to DRAW_CONTEXT 118 /// @param srcFormat - format of the hot tile 119 /// @param renderTargetIndex - render target to store, can be color, depth or stencil 120 /// @param x - destination x coordinate 121 /// @param y - destination y coordinate 122 /// @param pSrcHotTile - pointer to the hot tile surface 123 typedef void(SWR_API* PFN_STORE_TILE)(HANDLE hDC, 124 HANDLE hWorkerPrivateData, 125 SWR_FORMAT srcFormat, 126 SWR_RENDERTARGET_ATTACHMENT renderTargetIndex, 127 uint32_t x, 128 uint32_t y, 129 uint32_t renderTargetArrayIndex, 130 uint8_t* pSrcHotTile); 131 132 ////////////////////////////////////////////////////////////////////////// 133 /// @brief Function signature for clearing from the hot tiles clear value 134 /// @param hPrivateContext - handle to private data 135 /// @param renderTargetIndex - render target to store, can be color, depth or stencil 136 /// @param x - destination x coordinate 137 /// @param y - destination y coordinate 138 /// @param renderTargetArrayIndex - render target array offset from arrayIndex 139 /// @param pClearColor - pointer to the hot tile's clear value 140 typedef void(SWR_API* PFN_CLEAR_TILE)(HANDLE hPrivateContext, 141 HANDLE hWorkerPrivateData, 142 SWR_RENDERTARGET_ATTACHMENT rtIndex, 143 uint32_t x, 144 uint32_t y, 145 uint32_t renderTargetArrayIndex, 146 const float* pClearColor); 147 148 typedef void*(SWR_API* PFN_TRANSLATE_GFXPTR_FOR_READ)(HANDLE hPrivateContext, 149 gfxptr_t xpAddr, 150 bool* pbNullTileAccessed, 151 HANDLE hPrivateWorkerData); 152 153 typedef void*(SWR_API* PFN_TRANSLATE_GFXPTR_FOR_WRITE)(HANDLE hPrivateContext, 154 gfxptr_t xpAddr, 155 bool* pbNullTileAccessed, 156 HANDLE hPrivateWorkerData); 157 158 typedef gfxptr_t(SWR_API* PFN_MAKE_GFXPTR)(HANDLE hPrivateContext, void* sysAddr); 159 160 typedef HANDLE(SWR_API* PFN_CREATE_MEMORY_CONTEXT)(HANDLE hExternalMemory); 161 162 typedef void(SWR_API* PFN_DESTROY_MEMORY_CONTEXT)(HANDLE hExternalMemory, HANDLE hMemoryContext); 163 164 ////////////////////////////////////////////////////////////////////////// 165 /// @brief Callback to allow driver to update their copy of streamout write offset. 166 /// This is call is made for any draw operation that has streamout enabled 167 /// and has updated the write offset. 168 /// @param hPrivateContext - handle to private data 169 /// @param soBufferSlot - buffer slot for write offset 170 /// @param soWriteOffset - update value for so write offset. 171 typedef void(SWR_API* PFN_UPDATE_SO_WRITE_OFFSET)(HANDLE hPrivateContext, 172 uint32_t soBufferSlot, 173 uint32_t soWriteOffset); 174 175 ////////////////////////////////////////////////////////////////////////// 176 /// @brief Callback to allow driver to update their copy of stats. 177 /// @param hPrivateContext - handle to private data 178 /// @param pStats - pointer to draw stats 179 typedef void(SWR_API* PFN_UPDATE_STATS)(HANDLE hPrivateContext, const SWR_STATS* pStats); 180 181 ////////////////////////////////////////////////////////////////////////// 182 /// @brief Callback to allow driver to update their copy of FE stats. 183 /// @note Its optimal to have a separate callback for FE stats since 184 /// there is only one DC per FE thread. This means we do not have 185 /// to sum up the stats across all of the workers. 186 /// @param hPrivateContext - handle to private data 187 /// @param pStats - pointer to draw stats 188 typedef void(SWR_API* PFN_UPDATE_STATS_FE)(HANDLE hPrivateContext, const SWR_STATS_FE* pStats); 189 190 ////////////////////////////////////////////////////////////////////////// 191 /// @brief Callback to allow driver to update StreamOut status 192 /// @param hPrivateContext - handle to private data 193 /// @param numPrims - number of primitives written to StreamOut buffer 194 typedef void(SWR_API* PFN_UPDATE_STREAMOUT)(HANDLE hPrivateContext, uint64_t numPrims); 195 196 ////////////////////////////////////////////////////////////////////////// 197 /// BucketManager 198 /// Forward Declaration (see rdtsc_buckets.h for full definition) 199 ///////////////////////////////////////////////////////////////////////// 200 class BucketManager; 201 202 ////////////////////////////////////////////////////////////////////////// 203 /// SWR_THREADING_INFO 204 ///////////////////////////////////////////////////////////////////////// 205 struct SWR_THREADING_INFO 206 { 207 uint32_t BASE_NUMA_NODE; 208 uint32_t BASE_CORE; 209 uint32_t BASE_THREAD; 210 uint32_t MAX_WORKER_THREADS; 211 uint32_t MAX_NUMA_NODES; 212 uint32_t MAX_CORES_PER_NUMA_NODE; 213 uint32_t MAX_THREADS_PER_CORE; 214 bool SINGLE_THREADED; 215 }; 216 217 ////////////////////////////////////////////////////////////////////////// 218 /// SWR_API_THREADING_INFO 219 /// Data used to reserve HW threads for API use 220 /// API Threads are reserved from numa nodes / cores used for 221 /// SWR Worker threads. Specifying reserved threads here can reduce 222 /// the total number of SWR worker threads. 223 ///////////////////////////////////////////////////////////////////////// 224 struct SWR_API_THREADING_INFO 225 { 226 uint32_t numAPIReservedThreads; // Default is 1 if SWR_API_THREADING_INFO is not sent 227 uint32_t bindAPIThread0; // Default is true if numAPIReservedThreads is > 0, 228 // binds thread used in SwrCreateContext to API Reserved 229 // thread 0 230 uint32_t numAPIThreadsPerCore; // 0 - means use all threads per core, else clamp to this number. 231 // Independent of KNOB_MAX_THREADS_PER_CORE. 232 }; 233 234 ////////////////////////////////////////////////////////////////////////// 235 /// SWR_CONTEXT 236 /// Forward Declaration (see context.h for full definition) 237 ///////////////////////////////////////////////////////////////////////// 238 struct SWR_CONTEXT; 239 240 ////////////////////////////////////////////////////////////////////////// 241 /// SWR_WORKER_PRIVATE_STATE 242 /// Data used to allocate per-worker thread private data. A pointer 243 /// to this data will be passed in to each shader function. 244 /// The first field of this private data must be SWR_WORKER_DATA 245 /// perWorkerPrivateStateSize must be >= sizeof SWR_WORKER_DATA 246 ///////////////////////////////////////////////////////////////////////// 247 struct SWR_WORKER_PRIVATE_STATE 248 { 249 typedef void(SWR_API* PFN_WORKER_DATA)(SWR_CONTEXT* pContext, HANDLE hWorkerPrivateData, uint32_t iWorkerNum); 250 251 size_t perWorkerPrivateStateSize; ///< Amount of data to allocate per-worker 252 PFN_WORKER_DATA pfnInitWorkerData; ///< Init function for worker data. If null 253 ///< worker data will be initialized to 0. 254 PFN_WORKER_DATA pfnFinishWorkerData; ///< Finish / destroy function for worker data. 255 ///< Can be null. 256 }; 257 258 ////////////////////////////////////////////////////////////////////////// 259 /// SWR_CREATECONTEXT_INFO 260 ///////////////////////////////////////////////////////////////////////// 261 struct SWR_CREATECONTEXT_INFO 262 { 263 // External functions (e.g. sampler) need per draw context state. 264 // Use SwrGetPrivateContextState() to access private state. 265 size_t privateStateSize; 266 267 // Optional per-worker state, can be NULL for no worker-private data 268 SWR_WORKER_PRIVATE_STATE* pWorkerPrivateState; 269 270 // Callback functions 271 PFN_LOAD_TILE pfnLoadTile; 272 PFN_STORE_TILE pfnStoreTile; 273 PFN_TRANSLATE_GFXPTR_FOR_READ pfnTranslateGfxptrForRead; 274 PFN_TRANSLATE_GFXPTR_FOR_WRITE pfnTranslateGfxptrForWrite; 275 PFN_MAKE_GFXPTR pfnMakeGfxPtr; 276 PFN_CREATE_MEMORY_CONTEXT pfnCreateMemoryContext; 277 PFN_DESTROY_MEMORY_CONTEXT pfnDestroyMemoryContext; 278 PFN_UPDATE_SO_WRITE_OFFSET pfnUpdateSoWriteOffset; 279 PFN_UPDATE_STATS pfnUpdateStats; 280 PFN_UPDATE_STATS_FE pfnUpdateStatsFE; 281 PFN_UPDATE_STREAMOUT pfnUpdateStreamOut; 282 283 284 // Pointer to rdtsc buckets mgr returned to the caller. 285 // Only populated when KNOB_ENABLE_RDTSC is set 286 BucketManager* pBucketMgr; 287 288 // Output: size required memory passed to for SwrSaveState / SwrRestoreState 289 size_t contextSaveSize; 290 291 // ArchRast event manager. 292 HANDLE hArEventManager; 293 294 // handle to external memory for worker data to create memory contexts 295 HANDLE hExternalMemory; 296 297 // Input (optional): Threading info that overrides any set KNOB values. 298 SWR_THREADING_INFO* pThreadInfo; 299 300 // Input (optional): Info for reserving API threads 301 SWR_API_THREADING_INFO* pApiThreadInfo; 302 303 // Input: if set to non-zero value, overrides KNOB value for maximum 304 // number of draws in flight 305 uint32_t MAX_DRAWS_IN_FLIGHT; 306 307 std::string contextName; 308 }; 309 310 ////////////////////////////////////////////////////////////////////////// 311 /// @brief Create SWR Context. 312 /// @param pCreateInfo - pointer to creation info. 313 SWR_FUNC(HANDLE, SwrCreateContext, SWR_CREATECONTEXT_INFO* pCreateInfo); 314 315 ////////////////////////////////////////////////////////////////////////// 316 /// @brief Destroys SWR Context. 317 /// @param hContext - Handle passed back from SwrCreateContext 318 SWR_FUNC(void, SwrDestroyContext, HANDLE hContext); 319 320 ////////////////////////////////////////////////////////////////////////// 321 /// @brief Bind current thread to an API reserved HW thread 322 /// @param hContext - Handle passed back from SwrCreateContext 323 /// @param apiThreadId - index of reserved HW thread to bind to. 324 SWR_FUNC(void, SwrBindApiThread, HANDLE hContext, uint32_t apiThreadId); 325 326 ////////////////////////////////////////////////////////////////////////// 327 /// @brief Saves API state associated with hContext 328 /// @param hContext - Handle passed back from SwrCreateContext 329 /// @param pOutputStateBlock - Memory block to receive API state data 330 /// @param memSize - Size of memory pointed to by pOutputStateBlock 331 SWR_FUNC(void, SwrSaveState, HANDLE hContext, void* pOutputStateBlock, size_t memSize); 332 333 ////////////////////////////////////////////////////////////////////////// 334 /// @brief Restores API state to hContext previously saved with SwrSaveState 335 /// @param hContext - Handle passed back from SwrCreateContext 336 /// @param pStateBlock - Memory block to read API state data from 337 /// @param memSize - Size of memory pointed to by pStateBlock 338 SWR_FUNC(void, SwrRestoreState, HANDLE hContext, const void* pStateBlock, size_t memSize); 339 340 ////////////////////////////////////////////////////////////////////////// 341 /// @brief Sync cmd. Executes the callback func when all rendering up to this sync 342 /// has been completed 343 /// @param hContext - Handle passed back from SwrCreateContext 344 /// @param pfnFunc - pointer to callback function, 345 /// @param userData - user data to pass back 346 SWR_FUNC(void, 347 SwrSync, 348 HANDLE hContext, 349 PFN_CALLBACK_FUNC pfnFunc, 350 uint64_t userData, 351 uint64_t userData2, 352 uint64_t userData3); 353 354 ////////////////////////////////////////////////////////////////////////// 355 /// @brief Stall cmd. Stalls the backend until all previous work has been completed. 356 /// Frontend work can continue to make progress 357 /// @param hContext - Handle passed back from SwrCreateContext 358 SWR_FUNC(void, SwrStallBE, HANDLE hContext); 359 360 ////////////////////////////////////////////////////////////////////////// 361 /// @brief Blocks until all rendering has been completed. 362 /// @param hContext - Handle passed back from SwrCreateContext 363 SWR_FUNC(void, SwrWaitForIdle, HANDLE hContext); 364 365 ////////////////////////////////////////////////////////////////////////// 366 /// @brief Blocks until all FE rendering has been completed. 367 /// @param hContext - Handle passed back from SwrCreateContext 368 SWR_FUNC(void, SwrWaitForIdleFE, HANDLE hContext); 369 370 ////////////////////////////////////////////////////////////////////////// 371 /// @brief Set vertex buffer state. 372 /// @param hContext - Handle passed back from SwrCreateContext 373 /// @param numBuffers - Number of vertex buffer state descriptors. 374 /// @param pVertexBuffers - Array of vertex buffer state descriptors. 375 SWR_FUNC(void, 376 SwrSetVertexBuffers, 377 HANDLE hContext, 378 uint32_t numBuffers, 379 const SWR_VERTEX_BUFFER_STATE* pVertexBuffers); 380 381 ////////////////////////////////////////////////////////////////////////// 382 /// @brief Set index buffer 383 /// @param hContext - Handle passed back from SwrCreateContext 384 /// @param pIndexBuffer - Index buffer. 385 SWR_FUNC(void, SwrSetIndexBuffer, HANDLE hContext, const SWR_INDEX_BUFFER_STATE* pIndexBuffer); 386 387 ////////////////////////////////////////////////////////////////////////// 388 /// @brief Set fetch shader pointer. 389 /// @param hContext - Handle passed back from SwrCreateContext 390 /// @param pfnFetchFunc - Pointer to shader. 391 SWR_FUNC(void, SwrSetFetchFunc, HANDLE hContext, PFN_FETCH_FUNC pfnFetchFunc); 392 393 ////////////////////////////////////////////////////////////////////////// 394 /// @brief Set streamout shader pointer. 395 /// @param hContext - Handle passed back from SwrCreateContext 396 /// @param pfnSoFunc - Pointer to shader. 397 /// @param streamIndex - specifies stream 398 SWR_FUNC(void, SwrSetSoFunc, HANDLE hContext, PFN_SO_FUNC pfnSoFunc, uint32_t streamIndex); 399 400 ////////////////////////////////////////////////////////////////////////// 401 /// @brief Set streamout state 402 /// @param hContext - Handle passed back from SwrCreateContext 403 /// @param pSoState - Pointer to streamout state. 404 SWR_FUNC(void, SwrSetSoState, HANDLE hContext, SWR_STREAMOUT_STATE* pSoState); 405 406 ////////////////////////////////////////////////////////////////////////// 407 /// @brief Set streamout buffer state 408 /// @param hContext - Handle passed back from SwrCreateContext 409 /// @param pSoBuffer - Pointer to streamout buffer. 410 /// @param slot - Slot to bind SO buffer to. 411 SWR_FUNC(void, SwrSetSoBuffers, HANDLE hContext, SWR_STREAMOUT_BUFFER* pSoBuffer, uint32_t slot); 412 413 ////////////////////////////////////////////////////////////////////////// 414 /// @brief Set vertex shader pointer. 415 /// @param hContext - Handle passed back from SwrCreateContext 416 /// @param pfnVertexFunc - Pointer to shader. 417 SWR_FUNC(void, SwrSetVertexFunc, HANDLE hContext, PFN_VERTEX_FUNC pfnVertexFunc); 418 419 ////////////////////////////////////////////////////////////////////////// 420 /// @brief Set frontend state. 421 /// @param hContext - Handle passed back from SwrCreateContext 422 /// @param pState - Pointer to state 423 SWR_FUNC(void, SwrSetFrontendState, HANDLE hContext, SWR_FRONTEND_STATE* pState); 424 425 ////////////////////////////////////////////////////////////////////////// 426 /// @brief Set geometry shader state. 427 /// @param hContext - Handle passed back from SwrCreateContext 428 /// @param pState - Pointer to state 429 SWR_FUNC(void, SwrSetGsState, HANDLE hContext, SWR_GS_STATE* pState); 430 431 ////////////////////////////////////////////////////////////////////////// 432 /// @brief Set geometry shader 433 /// @param hContext - Handle passed back from SwrCreateContext 434 /// @param pState - Pointer to geometry shader function 435 SWR_FUNC(void, SwrSetGsFunc, HANDLE hContext, PFN_GS_FUNC pfnGsFunc); 436 437 ////////////////////////////////////////////////////////////////////////// 438 /// @brief Set compute shader 439 /// @param hContext - Handle passed back from SwrCreateContext 440 /// @param pfnCsFunc - Pointer to compute shader function 441 /// @param totalThreadsInGroup - product of thread group dimensions. 442 /// @param totalSpillFillSize - size in bytes needed for spill/fill. 443 /// @param scratchSpaceSizePerInstance - size of the scratch space needed per simd instance 444 /// @param numInstances - number of simd instances that are run per execution of the shader 445 SWR_FUNC(void, 446 SwrSetCsFunc, 447 HANDLE hContext, 448 PFN_CS_FUNC pfnCsFunc, 449 uint32_t totalThreadsInGroup, 450 uint32_t totalSpillFillSize, 451 uint32_t scratchSpaceSizePerInstance, 452 uint32_t numInstances); 453 454 ////////////////////////////////////////////////////////////////////////// 455 /// @brief Set tessellation state. 456 /// @param hContext - Handle passed back from SwrCreateContext 457 /// @param pState - Pointer to state 458 SWR_FUNC(void, SwrSetTsState, HANDLE hContext, SWR_TS_STATE* pState); 459 460 ////////////////////////////////////////////////////////////////////////// 461 /// @brief Set hull shader 462 /// @param hContext - Handle passed back from SwrCreateContext 463 /// @param pfnFunc - Pointer to shader function 464 SWR_FUNC(void, SwrSetHsFunc, HANDLE hContext, PFN_HS_FUNC pfnFunc); 465 466 ////////////////////////////////////////////////////////////////////////// 467 /// @brief Set domain shader 468 /// @param hContext - Handle passed back from SwrCreateContext 469 /// @param pfnFunc - Pointer to shader function 470 SWR_FUNC(void, SwrSetDsFunc, HANDLE hContext, PFN_DS_FUNC pfnFunc); 471 472 ////////////////////////////////////////////////////////////////////////// 473 /// @brief Set depth stencil state 474 /// @param hContext - Handle passed back from SwrCreateContext 475 /// @param pState - Pointer to state. 476 SWR_FUNC(void, SwrSetDepthStencilState, HANDLE hContext, SWR_DEPTH_STENCIL_STATE* pState); 477 478 ////////////////////////////////////////////////////////////////////////// 479 /// @brief Set backend state 480 /// @param hContext - Handle passed back from SwrCreateContext 481 /// @param pState - Pointer to state. 482 SWR_FUNC(void, SwrSetBackendState, HANDLE hContext, SWR_BACKEND_STATE* pState); 483 484 ////////////////////////////////////////////////////////////////////////// 485 /// @brief Set depth bounds state 486 /// @param hContext - Handle passed back from SwrCreateContext 487 /// @param pState - Pointer to state. 488 SWR_FUNC(void, SwrSetDepthBoundsState, HANDLE hContext, SWR_DEPTH_BOUNDS_STATE* pState); 489 490 ////////////////////////////////////////////////////////////////////////// 491 /// @brief Set pixel shader state 492 /// @param hContext - Handle passed back from SwrCreateContext 493 /// @param pState - Pointer to state. 494 SWR_FUNC(void, SwrSetPixelShaderState, HANDLE hContext, SWR_PS_STATE* pState); 495 496 ////////////////////////////////////////////////////////////////////////// 497 /// @brief Set blend state 498 /// @param hContext - Handle passed back from SwrCreateContext 499 /// @param pState - Pointer to state. 500 SWR_FUNC(void, SwrSetBlendState, HANDLE hContext, SWR_BLEND_STATE* pState); 501 502 ////////////////////////////////////////////////////////////////////////// 503 /// @brief Set blend function 504 /// @param hContext - Handle passed back from SwrCreateContext 505 /// @param renderTarget - render target index 506 /// @param pfnBlendFunc - function pointer 507 SWR_FUNC( 508 void, SwrSetBlendFunc, HANDLE hContext, uint32_t renderTarget, PFN_BLEND_JIT_FUNC pfnBlendFunc); 509 510 ////////////////////////////////////////////////////////////////////////// 511 /// @brief SwrDraw 512 /// @param hContext - Handle passed back from SwrCreateContext 513 /// @param topology - Specifies topology for draw. 514 /// @param startVertex - Specifies start vertex in vertex buffer for draw. 515 /// @param primCount - Number of vertices. 516 SWR_FUNC(void, 517 SwrDraw, 518 HANDLE hContext, 519 PRIMITIVE_TOPOLOGY topology, 520 uint32_t startVertex, 521 uint32_t primCount); 522 523 ////////////////////////////////////////////////////////////////////////// 524 /// @brief SwrDrawInstanced 525 /// @param hContext - Handle passed back from SwrCreateContext 526 /// @param topology - Specifies topology for draw. 527 /// @param numVertsPerInstance - How many vertices to read sequentially from vertex data. 528 /// @param numInstances - How many instances to render. 529 /// @param startVertex - Specifies start vertex for draw. (vertex data) 530 /// @param startInstance - Which instance to start sequentially fetching from in each buffer 531 /// (instanced data) 532 SWR_FUNC(void, 533 SwrDrawInstanced, 534 HANDLE hContext, 535 PRIMITIVE_TOPOLOGY topology, 536 uint32_t numVertsPerInstance, 537 uint32_t numInstances, 538 uint32_t startVertex, 539 uint32_t startInstance); 540 541 ////////////////////////////////////////////////////////////////////////// 542 /// @brief DrawIndexed 543 /// @param hContext - Handle passed back from SwrCreateContext 544 /// @param topology - Specifies topology for draw. 545 /// @param numIndices - Number of indices to read sequentially from index buffer. 546 /// @param indexOffset - Starting index into index buffer. 547 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed. 548 SWR_FUNC(void, 549 SwrDrawIndexed, 550 HANDLE hContext, 551 PRIMITIVE_TOPOLOGY topology, 552 uint32_t numIndices, 553 uint32_t indexOffset, 554 int32_t baseVertex); 555 556 ////////////////////////////////////////////////////////////////////////// 557 /// @brief SwrDrawIndexedInstanced 558 /// @param hContext - Handle passed back from SwrCreateContext 559 /// @param topology - Specifies topology for draw. 560 /// @param numIndices - Number of indices to read sequentially from index buffer. 561 /// @param numInstances - Number of instances to render. 562 /// @param indexOffset - Starting index into index buffer. 563 /// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed. 564 /// @param startInstance - Which instance to start sequentially fetching from in each buffer 565 /// (instanced data) 566 SWR_FUNC(void, 567 SwrDrawIndexedInstanced, 568 HANDLE hContext, 569 PRIMITIVE_TOPOLOGY topology, 570 uint32_t numIndices, 571 uint32_t numInstances, 572 uint32_t indexOffset, 573 int32_t baseVertex, 574 uint32_t startInstance); 575 576 ////////////////////////////////////////////////////////////////////////// 577 /// @brief SwrInvalidateTiles 578 /// @param hContext - Handle passed back from SwrCreateContext 579 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to 580 /// invalidate. 581 /// @param invalidateRect - The pixel-coordinate rectangle to invalidate. This will be expanded to 582 /// be hottile size-aligned. 583 SWR_FUNC(void, 584 SwrInvalidateTiles, 585 HANDLE hContext, 586 uint32_t attachmentMask, 587 const SWR_RECT& invalidateRect); 588 589 ////////////////////////////////////////////////////////////////////////// 590 /// @brief SwrDiscardRect 591 /// @param hContext - Handle passed back from SwrCreateContext 592 /// @param attachmentMask - The mask specifies which surfaces attached to the hottiles to discard. 593 /// @param rect - The pixel-coordinate rectangle to discard. Only fully-covered hottiles will be 594 /// discarded. 595 SWR_FUNC(void, SwrDiscardRect, HANDLE hContext, uint32_t attachmentMask, const SWR_RECT& rect); 596 597 ////////////////////////////////////////////////////////////////////////// 598 /// @brief SwrDispatch 599 /// @param hContext - Handle passed back from SwrCreateContext 600 /// @param threadGroupCountX - Number of thread groups dispatched in X direction 601 /// @param threadGroupCountY - Number of thread groups dispatched in Y direction 602 /// @param threadGroupCountZ - Number of thread groups dispatched in Z direction 603 SWR_FUNC(void, 604 SwrDispatch, 605 HANDLE hContext, 606 uint32_t threadGroupCountX, 607 uint32_t threadGroupCountY, 608 uint32_t threadGroupCountZ); 609 610 /// @note this enum needs to be kept in sync with HOTTILE_STATE! 611 enum SWR_TILE_STATE 612 { 613 SWR_TILE_INVALID = 0, // tile is in uninitialized state and should be loaded with surface contents 614 // before rendering 615 SWR_TILE_DIRTY = 2, // tile contains newer data than surface it represents 616 SWR_TILE_RESOLVED = 3, // is in sync with surface it represents 617 }; 618 619 /// @todo Add a good description for what attachments are and when and why you would use the 620 /// different SWR_TILE_STATEs. 621 SWR_FUNC(void, 622 SwrStoreTiles, 623 HANDLE hContext, 624 uint32_t attachmentMask, 625 SWR_TILE_STATE postStoreTileState, 626 const SWR_RECT& storeRect); 627 628 ////////////////////////////////////////////////////////////////////////// 629 /// @brief SwrClearRenderTarget - Clear attached render targets / depth / stencil 630 /// @param hContext - Handle passed back from SwrCreateContext 631 /// @param attachmentMask - combination of SWR_ATTACHMENT_*_BIT attachments to clear 632 /// @param renderTargetArrayIndex - the RT array index to clear 633 /// @param clearColor - color use for clearing render targets 634 /// @param z - depth value use for clearing depth buffer 635 /// @param stencil - stencil value used for clearing stencil buffer 636 /// @param clearRect - The pixel-coordinate rectangle to clear in all cleared buffers 637 SWR_FUNC(void, 638 SwrClearRenderTarget, 639 HANDLE hContext, 640 uint32_t attachmentMask, 641 uint32_t renderTargetArrayIndex, 642 const float clearColor[4], 643 float z, 644 uint8_t stencil, 645 const SWR_RECT& clearRect); 646 647 ////////////////////////////////////////////////////////////////////////// 648 /// @brief SwrSetRastState 649 /// @param hContext - Handle passed back from SwrCreateContext 650 /// @param pRastState - New SWR_RASTSTATE used for SwrDraw* commands 651 SWR_FUNC(void, SwrSetRastState, HANDLE hContext, const SWR_RASTSTATE* pRastState); 652 653 ////////////////////////////////////////////////////////////////////////// 654 /// @brief SwrSetViewports 655 /// @param hContext - Handle passed back from SwrCreateContext 656 /// @param numViewports - number of viewports passed in 657 /// @param pViewports - Specifies extents of viewport. 658 /// @param pMatrices - If not specified then SWR computes a default one. 659 SWR_FUNC(void, 660 SwrSetViewports, 661 HANDLE hContext, 662 uint32_t numViewports, 663 const SWR_VIEWPORT* pViewports, 664 const SWR_VIEWPORT_MATRICES* pMatrices); 665 666 ////////////////////////////////////////////////////////////////////////// 667 /// @brief SwrSetScissorRects 668 /// @param hContext - Handle passed back from SwrCreateContext 669 /// @param numScissors - number of scissors passed in 670 /// @param pScissors - array of scissors 671 SWR_FUNC( 672 void, SwrSetScissorRects, HANDLE hContext, uint32_t numScissors, const SWR_RECT* pScissors); 673 674 ////////////////////////////////////////////////////////////////////////// 675 /// @brief Returns a pointer to the private context state for the current 676 /// draw operation. This is used for external componets such as the 677 /// sampler. 678 /// 679 /// @note Client needs to resend private state prior to each draw call. 680 /// Also, SWR is responsible for the private state memory. 681 /// @param hContext - Handle passed back from SwrCreateContext 682 SWR_FUNC(void*, SwrGetPrivateContextState, HANDLE hContext); 683 684 ////////////////////////////////////////////////////////////////////////// 685 /// @brief Clients can use this to allocate memory for draw/dispatch 686 /// operations. The memory will automatically be freed once operation 687 /// has completed. Client can use this to allocate binding tables, 688 /// etc. needed for shader execution. 689 /// @param hContext - Handle passed back from SwrCreateContext 690 /// @param size - Size of allocation 691 /// @param align - Alignment needed for allocation. 692 SWR_FUNC(void*, SwrAllocDrawContextMemory, HANDLE hContext, uint32_t size, uint32_t align); 693 694 ////////////////////////////////////////////////////////////////////////// 695 /// @brief Enables stats counting 696 /// @param hContext - Handle passed back from SwrCreateContext 697 /// @param enable - If true then counts are incremented. 698 SWR_FUNC(void, SwrEnableStatsFE, HANDLE hContext, bool enable); 699 700 ////////////////////////////////////////////////////////////////////////// 701 /// @brief Enables stats counting 702 /// @param hContext - Handle passed back from SwrCreateContext 703 /// @param enable - If true then counts are incremented. 704 SWR_FUNC(void, SwrEnableStatsBE, HANDLE hContext, bool enable); 705 706 ////////////////////////////////////////////////////////////////////////// 707 /// @brief Mark end of frame - used for performance profiling 708 /// @param hContext - Handle passed back from SwrCreateContext 709 SWR_FUNC(void, SwrEndFrame, HANDLE hContext); 710 711 ////////////////////////////////////////////////////////////////////////// 712 /// @brief Initialize swr backend and memory internal tables 713 SWR_FUNC(void, SwrInit); 714 715 716 struct SWR_INTERFACE 717 { 718 PFNSwrCreateContext pfnSwrCreateContext; 719 PFNSwrDestroyContext pfnSwrDestroyContext; 720 PFNSwrBindApiThread pfnSwrBindApiThread; 721 PFNSwrSaveState pfnSwrSaveState; 722 PFNSwrRestoreState pfnSwrRestoreState; 723 PFNSwrSync pfnSwrSync; 724 PFNSwrStallBE pfnSwrStallBE; 725 PFNSwrWaitForIdle pfnSwrWaitForIdle; 726 PFNSwrWaitForIdleFE pfnSwrWaitForIdleFE; 727 PFNSwrSetVertexBuffers pfnSwrSetVertexBuffers; 728 PFNSwrSetIndexBuffer pfnSwrSetIndexBuffer; 729 PFNSwrSetFetchFunc pfnSwrSetFetchFunc; 730 PFNSwrSetSoFunc pfnSwrSetSoFunc; 731 PFNSwrSetSoState pfnSwrSetSoState; 732 PFNSwrSetSoBuffers pfnSwrSetSoBuffers; 733 PFNSwrSetVertexFunc pfnSwrSetVertexFunc; 734 PFNSwrSetFrontendState pfnSwrSetFrontendState; 735 PFNSwrSetGsState pfnSwrSetGsState; 736 PFNSwrSetGsFunc pfnSwrSetGsFunc; 737 PFNSwrSetCsFunc pfnSwrSetCsFunc; 738 PFNSwrSetTsState pfnSwrSetTsState; 739 PFNSwrSetHsFunc pfnSwrSetHsFunc; 740 PFNSwrSetDsFunc pfnSwrSetDsFunc; 741 PFNSwrSetDepthStencilState pfnSwrSetDepthStencilState; 742 PFNSwrSetBackendState pfnSwrSetBackendState; 743 PFNSwrSetDepthBoundsState pfnSwrSetDepthBoundsState; 744 PFNSwrSetPixelShaderState pfnSwrSetPixelShaderState; 745 PFNSwrSetBlendState pfnSwrSetBlendState; 746 PFNSwrSetBlendFunc pfnSwrSetBlendFunc; 747 PFNSwrDraw pfnSwrDraw; 748 PFNSwrDrawInstanced pfnSwrDrawInstanced; 749 PFNSwrDrawIndexed pfnSwrDrawIndexed; 750 PFNSwrDrawIndexedInstanced pfnSwrDrawIndexedInstanced; 751 PFNSwrInvalidateTiles pfnSwrInvalidateTiles; 752 PFNSwrDiscardRect pfnSwrDiscardRect; 753 PFNSwrDispatch pfnSwrDispatch; 754 PFNSwrStoreTiles pfnSwrStoreTiles; 755 PFNSwrClearRenderTarget pfnSwrClearRenderTarget; 756 PFNSwrSetRastState pfnSwrSetRastState; 757 PFNSwrSetViewports pfnSwrSetViewports; 758 PFNSwrSetScissorRects pfnSwrSetScissorRects; 759 PFNSwrGetPrivateContextState pfnSwrGetPrivateContextState; 760 PFNSwrAllocDrawContextMemory pfnSwrAllocDrawContextMemory; 761 PFNSwrEnableStatsFE pfnSwrEnableStatsFE; 762 PFNSwrEnableStatsBE pfnSwrEnableStatsBE; 763 PFNSwrEndFrame pfnSwrEndFrame; 764 PFNSwrInit pfnSwrInit; 765 }; 766 767 extern "C" { 768 typedef void(SWR_API* PFNSwrGetInterface)(SWR_INTERFACE& out_funcs); 769 SWR_VISIBLE void SWR_API SwrGetInterface(SWR_INTERFACE& out_funcs); 770 } 771 772 #endif 773