1 /* 2 * Copyright (c) 2009-2019, Intel Corporation 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 shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file mos_interface.h 24 //! \brief MOS interface definition 25 //! 26 //! Device level: OsDeviceContext in device/Libva context. 27 //! The global level of entire media driver instance in user space. 28 //! There could be multiple devices in a single process. 29 //! Stream level: OsStreamState in Hal instances (Codec pipeline, VP pipeline, CM device, CP session, etc) 30 //! Each Hal instance can have an OsStreamState to indicate that stream's state specific to OS. 31 //! Each Device can have multiple streams. 32 //! All OsStreamStates must be binded with a valid OsDeviceContext to indicate the inclusion relationship 33 //! between device and stream in DDI 34 //! 35 //! MOS interface provide following OS services: (OS services are abstracted and diff OS behavior is tranparent to MOS customers) 36 //! 1) Workload scheduling (GPU context, cmdbuffer, sync, virtual engine, etc) 37 //! 2) Resource managment (Graphic resource, external resource) 38 //! 3) Utilities (Abstraction of generalized system call) 39 //! 4) Performance interface 40 //! 5) Debug interface 41 //! 42 //! Caller: DDI, Media interface, HAL, MHW 43 //! Any interface func returning MOS_STATUS_UNKNOWN mean Device level is go into unstable situation. 44 //! Caller needs to make sure exiting properly. 45 46 47 #ifndef __MOS_INTERFACE_H__ 48 #define __MOS_INTERFACE_H__ 49 50 #include "mos_defs.h" 51 #include "mos_os.h" 52 53 class GpuContextSpecificNext; 54 struct _MOS_VIRTUALENGINE_SET_PARAMS; 55 struct _MOS_VIRTUALENGINE_INIT_PARAMS; 56 typedef struct _MOS_VIRTUALENGINE_SET_PARAMS MOS_VIRTUALENGINE_SET_PARAMS, *PMOS_VIRTUALENGINE_SET_PARAMS; 57 typedef struct _MOS_VIRTUALENGINE_INIT_PARAMS MOS_VIRTUALENGINE_INIT_PARAMS, *PMOS_VIRTUALENGINE_INIT_PARAMS; 58 typedef struct _MOS_CMD_BUF_ATTRI_VE MOS_CMD_BUF_ATTRI_VE, *PMOS_CMD_BUF_ATTRI_VE; 59 class MosInterface 60 { 61 protected: 62 //! 63 //! \brief Destructor 64 //! \details There is no members in Mos Interface, it's pure interface. 65 //! Never call the Destructor of Mos interface 66 //! 67 ~MosInterface() = default; 68 69 //! 70 //! \brief Constructor 71 //! \details There is no members in Mos Interface, it's pure interface. 72 //! Never call the Constructor of Mos interface 73 //! 74 MosInterface() = default; 75 76 public: 77 //! 78 //! \brief Create Os Device Context 79 //! \details Create the Os Device Context in device level. 80 //! \details Caller: DDI only. 81 //! \details The Os Device Context is a singleton in the device, DDI must make sure call this only once. 82 //! If the creation failed, DDI must yield to continue the initialization of device. 83 //! 84 //! \param [in] ddiDeviceContext 85 //! Pointer of device context in DDI to init Os Device Context 86 //! \param [out] deviceContext 87 //! Handle of Os Device Context to create. If creation failed, it is INVALID_HANLE. 88 //! OsDeviceContext is a device level singleton which stores the states, info specific to OS. 89 //! It contain sub modules of MOS to transfer OS specific services to OS agnositic abstractions. 90 //! 91 //! \return MOS_STATUS 92 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 93 //! 94 static MOS_STATUS CreateOsDeviceContext(DDI_DEVICE_CONTEXT ddiDeviceContext, MOS_DEVICE_HANDLE *deviceContext); 95 96 //! 97 //! \brief Destroy Os Device Context 98 //! \details Destroy the Os Device Context in device level 99 //! \details Caller: DDI only. 100 //! 101 //! \param [in] deviceContext 102 //! Handle of Os Device Context to Destroy 103 //! 104 //! \return MOS_STATUS 105 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 106 //! 107 static MOS_STATUS DestroyOsDeviceContext(MOS_DEVICE_HANDLE deviceContext); 108 109 //! 110 //! \brief Create Os Stream State 111 //! \details Create the Os Stream State in stream level. 112 //! \details Caller: DDI 113 //! \details In DDI, one stream (Hal instance) can only create one Os Stream State corresponding to it. 114 //! Os Stream state directly created by DDI is not corresponding any streams (Hal instances) 115 //! 116 //! \param [out] streamState 117 //! Handle of Os Stream State to create. If creation failed, it is INVALID_HANLE. 118 //! OsStreamState is a stream level state which stores the flags, info specific to OS specfic to that stream. 119 //! It is be binded with a valid OsDeviceContext to indicate the inclusion relationship between device and stream. 120 //! 121 //! \return MOS_STATUS 122 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 123 //! 124 static MOS_STATUS CreateOsStreamState( 125 MOS_STREAM_HANDLE *streamState, 126 MOS_DEVICE_HANDLE deviceContext); 127 128 //! 129 //! \brief Destroy Os Stream State 130 //! \details Destroy the Os Stream State in stream level 131 //! \details Caller: DDI 132 //! 133 //! \param [in] streamState 134 //! Handle of Os Stream State to Destroy 135 //! 136 //! \return MOS_STATUS 137 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 138 //! 139 static MOS_STATUS DestroyOsStreamState( 140 MOS_STREAM_HANDLE streamState); 141 142 //! 143 //! \brief Get OS runtime interface version 144 //! \details [System info Interface] Get OS runtime interface version 145 //! \details Caller: DDI only 146 //! \details Only DDI can derive diff behavior due to OS runtime interface version 147 //! 148 //! \param [in] deviceContext 149 //! Handle of Os Device Context 150 //! 151 //! \return uint32_t 152 //! Read-only OS runtime interface version, it's meaning diff from OS and API 153 //! 154 static uint32_t GetInterfaceVersion(MOS_DEVICE_HANDLE deviceContext); 155 156 //! 157 //! \brief Get Platform 158 //! \details [System info Interface] Get Get Platform information 159 //! \details Caller: DDI & HAL & MHW 160 //! \details This func is called in DDI only to generate hal instance stand for specific platform. 161 //! This func can be used in HAL & MHW to get platfrom detailed info to judge the path of different behavior. 162 //! 163 //! \param [in] streamState 164 //! Handle of Os Stream State 165 //! 166 //! \return PLATFORM 167 //! Gfx driver shared enum of platform got. Read-only. 168 //! 169 static PLATFORM *GetPlatform(MOS_STREAM_HANDLE streamState); 170 171 //! 172 //! \brief Get SkuTable 173 //! \details [System info Interface] Get Sku Table 174 //! \details Caller: DDI & HAL & MHW 175 //! \details This func is called to differentiate the behavior according to SKU table. 176 //! 177 //! \param [in] streamState 178 //! Handle of Os Stream State 179 //! 180 //! \return MEDIA_FEATURE_TABLE* 181 //! Read-only SKU table got, nullptr if failed to get 182 //! 183 static MEDIA_FEATURE_TABLE *GetSkuTable(MOS_STREAM_HANDLE streamState); 184 185 //! 186 //! \brief Get WaTable 187 //! \details [System info Interface] Get WA Table 188 //! \details Caller: DDI & HAL & MHW 189 //! \details This func is called to differentiate the behavior according to WA table. 190 //! 191 //! \param [in] streamState 192 //! Handle of Os Stream State 193 //! 194 //! \return MEDIA_WA_TABLE* 195 //! Read-only WA table got, nullptr if failed to get 196 //! 197 static MEDIA_WA_TABLE *GetWaTable(MOS_STREAM_HANDLE streamState); 198 199 //! 200 //! \brief Get Gt System Info 201 //! \details [System info Interface] Get Gt System Info 202 //! \details Caller: HAL & MHW 203 //! \details This func is called to differentiate the behavior according to Gt System Info. 204 //! 205 //! \param [in] streamState 206 //! Handle of Os Stream State 207 //! 208 //! \return MEDIA_SYSTEM_INFO* 209 //! Read-only GT system info got, nullptr if failed to get 210 //! 211 static MEDIA_SYSTEM_INFO *GetGtSystemInfo(MOS_STREAM_HANDLE streamState); 212 213 //! 214 //! \brief Get Adapter Info 215 //! \details [System info Interface] Get Adapter Info 216 //! \details Caller: DDI & HAL 217 //! \details This func is called to differentiate the behavior according to Adapter Info. 218 //! 219 //! \param [in] streamState 220 //! Handle of Os Stream State 221 //! 222 //! \return ADAPTER_INFO* 223 //! Read-only Adapter Info got, nullptr if failed to get 224 //! 225 static ADAPTER_INFO *GetAdapterInfo(MOS_STREAM_HANDLE streamState); 226 227 //! 228 //! \brief Get current gmmclientcontext 229 //! \details Get current gmmclientcontext 230 //! \param PMOS_INTERFACE pOsInterface 231 //! [in] OS Interface 232 //! \return GMM_CLIENT_CONTEXT 233 //! Current gmmclientcontext 234 //! 235 static GMM_CLIENT_CONTEXT *GetGmmClientContext( 236 MOS_STREAM_HANDLE streamState); 237 238 //! 239 //! \brief Create Gpu Context 240 //! \details [GPU Context Interface] Create Gpu Context to submit cmdbuffers 241 //! \details Caller: HAL (Media Context) only 242 //! \details This func is called when a stream (Hal instance) needs a SW queue to submit cmd buffers programmed with GPU cmds. 243 //! \details This queue contain options to indicate the properties of virtual GPU engine to execute these cmds. 244 //! \details Caller can use Usage & option & GPU_CONTEXT_HANDLE to track and re-use the GPU contexts. 245 //! 246 //! \param [in] streamState 247 //! Handle of Os Stream State 248 //! \param [in] createOption 249 //! Properties of Gpu context to create. They stand for the request from HAL on the Gpu context. 250 //! The request include engine type, pipe count, restrictions, etc. 251 //! \param [out] gpuContext 252 //! Handle of gpu Context created. If creation failed, it is INVALID_HANLE 253 //! GPU context stands for a SW queue in user space to submit cmd buffers FIFO. 254 //! 255 //! \return MOS_STATUS 256 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 257 //! 258 static MOS_STATUS CreateGpuContext( 259 MOS_STREAM_HANDLE streamState, 260 GpuContextCreateOption &createOption, 261 GPU_CONTEXT_HANDLE &gpuContext); 262 263 //! 264 //! \brief Destroy Gpu Context 265 //! \details [GPU Context Interface] Destroy Gpu Context to submit cmdbuffers 266 //! \details Caller: HAL (Media Context) only 267 //! \details This func is called when a stream (Hal instance) never needs this SW queue to submit cmd buffers 268 //! \details This func is called only in the destruction stage of Hal instance. 269 //! Never should be SetGpuContext called to set destroied Gpu Context. 270 //! 271 //! \param [in] streamState 272 //! Handle of Os Stream State 273 //! \param [in] gpuContext 274 //! Handle of gpu Context to destroy. 275 //! 276 //! \return MOS_STATUS 277 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 278 //! 279 static MOS_STATUS DestroyGpuContext( 280 MOS_STREAM_HANDLE streamState, 281 GPU_CONTEXT_HANDLE gpuContext); 282 283 //! 284 //! \brief Set Gpu Context 285 //! \details [GPU Context Interface] Set current Gpu Context to submit cmd buffers for the stream(Hal instance) 286 //! \details Caller: HAL (Media Context) only 287 //! \details This func is called when a stream (Hal instance) needs an existing GPU context to submit cmd buffers. 288 //! \details Current GPU context is the major state of Os Stream State. 289 //! \details Before getting a cmd buffer to program GPU cmds, a valid GPU context must be setted into the stream. 290 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 291 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 292 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 293 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 294 //! 295 //! \param [in] streamState 296 //! Handle of Os Stream State 297 //! \param [in] gpuContext 298 //! Current handle of gpu Context to set. 299 //! 300 //! \return MOS_STATUS 301 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 302 //! 303 static MOS_STATUS SetGpuContext( 304 MOS_STREAM_HANDLE streamState, 305 GPU_CONTEXT_HANDLE gpuContext); 306 307 //! 308 //! \brief Add Command 309 //! \details [Cmd Buffer Interface] Add gpu commands into cmd buffer 310 //! \details Caller: MHW only 311 //! \details This func is called when a stream (Hal instance) adds gpu cmds into cmd buffer. 312 //! \details Before getting a cmd buffer to program GPU cmds, a valid GPU context must be setted into the stream. 313 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 314 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 315 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 316 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 317 //! 318 //! \param [in] cmdBuffer 319 //! Handle of cmd buffer to add cmd. cmd buffer handle can be get by calling GetCommandBuffer. 320 //! \param [in] cmd 321 //! Pointer to the memory to indicate cmd, caller must make sure it's valid. 322 //! \param [in] cmdSize 323 //! Size of cmd to program. 324 //! 325 //! \return MOS_STATUS 326 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 327 //! 328 static MOS_STATUS AddCommand( 329 COMMAND_BUFFER_HANDLE cmdBuffer, 330 const void *cmd, 331 uint32_t cmdSize); 332 333 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED 334 //! 335 //! \brief Dump Command Buffer 336 //! \details [Cmd Buffer Interface] Dump an existing cmd buffer 337 //! \details Caller: HAL only 338 //! \details This func is called when a stream (Hal instance) needs to dump cmd buffer. 339 //! \details Only after ReturnCommandBuffer can Command Buffer being dumped 340 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 341 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 342 //! 343 //! \param [in] streamState 344 //! Handle of Os Stream State 345 //! \param [in] cmdBuffer 346 //! Handle of cmd buffer to add cmd. cmd buffer handle can be get by calling GetCommandBuffer. 347 //! 348 //! \return MOS_STATUS 349 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 350 //! 351 static MOS_STATUS DumpCommandBuffer( 352 MOS_STREAM_HANDLE streamState, 353 COMMAND_BUFFER_HANDLE cmdBuffer); 354 #endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED 355 356 //! 357 //! \brief Get Command Buffer 358 //! \details [Cmd Buffer Interface] Get current cmd buffer to program based on streamState 359 //! \details Caller: HAL only 360 //! \details This func is called when a stream (Hal instance) needs to get a cmd buffer corresponding to current GPU context in os stream state. 361 //! \details Before getting a cmd buffer to program GPU cmds, a valid GPU context must be setted into the stream. 362 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 363 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 364 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 365 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 366 //! 367 //! \param [in] streamState 368 //! Handle of Os Stream State 369 //! \param [out] cmdBuffer 370 //! Handle of cmd buffer to get. If get failed, it is INVALID_HANLE. 371 //! \param [in] pipeIdx 372 //! Pipe index to indicate which pipe's cmdbuffer to get. 373 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 374 //! 375 //! \return MOS_STATUS 376 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 377 //! 378 static MOS_STATUS GetCommandBuffer( 379 MOS_STREAM_HANDLE streamState, 380 COMMAND_BUFFER_HANDLE &cmdBuffer, 381 uint32_t pipeIdx = 0); 382 383 //! 384 //! \brief Return Command Buffer 385 //! \details [Cmd Buffer Interface] Return current cmd buffer to the MOS 386 //! \details Caller: HAL only 387 //! \details This func is called when a stream (Hal instance) finished add cmds into a cmd buffer. 388 //! \details ReturnCommandBuffer must be called before submit cmd buffer. MOS will do necessary operations in this interface. 389 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 390 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 391 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 392 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 393 //! 394 //! \param [in] streamState 395 //! Handle of Os Stream State 396 //! \param [in] cmdBuffer 397 //! Handle of cmd buffer to return. 398 //! \param [in] pipeIdx 399 //! Pipe index to indicate which pipe's cmdbuffer to get. 400 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 401 //! 402 //! \return MOS_STATUS 403 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 404 //! 405 static MOS_STATUS ReturnCommandBuffer( 406 MOS_STREAM_HANDLE streamState, 407 COMMAND_BUFFER_HANDLE cmdBuffer, 408 uint32_t pipeIdx = 0); 409 410 //! 411 //! \brief Submit Command Buffer 412 //! \details [Cmd Buffer Interface] Submit current cmd buffer to current GPU context queue. 413 //! \details Caller: HAL only 414 //! \details When a stream (Hal instance) call this interface, cmd buffer is enqueued into current GPU context in streamState. 415 //! \details OS runtime and KMD will schedule the workload. HW cmds in the cmd buffer will be executed in HW engines. 416 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 417 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 418 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 419 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 420 //! \details Cmd buffer execution in GPU context is async with Hal programming. Return of this interface does not guarantee finish executing actual cmds. 421 //! 422 //! \param [in] streamState 423 //! Handle of Os Stream State 424 //! \param [in] cmdBuffer 425 //! Handle of cmd buffer to Submit. 426 //! If there is frame split case (more than 1 pipe) in current GPU context queue, this is primary cmd buffer handle. 427 //! \param [in] nullRendering 428 //! Flag to indicate if not actually submit workload into HW. 429 //! 430 //! \return MOS_STATUS 431 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 432 //! 433 static MOS_STATUS SubmitCommandBuffer( 434 MOS_STREAM_HANDLE streamState, 435 COMMAND_BUFFER_HANDLE cmdBuffer, 436 bool nullRendering = false); 437 438 //! 439 //! \brief Reset Command Buffer 440 //! \details [Cmd Buffer Interface] Reset cmd buffer to the initialized state. 441 //! \details Caller: HAL only 442 //! \details ResetCommandBuffer can be called after a stream (Hal instance) call GetCommandBuffer. 443 //! \details OS runtime and KMD will schedule the workload. HW cmds in the cmd buffer will be executed in HW engines. 444 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer (-> ResetCommandBuffer) -> AddCommand ... 445 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 446 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 447 //! \details Cmd buffer reset means stream starts to program a new set of cmds into a cmd buffer got. 448 //! This interface must not be called when the cmd buffer already programed cmds and not submitted unless the stream needs to drop these cmds. 449 //! 450 //! \param [in] streamState 451 //! Handle of Os Stream State 452 //! \param [in, out] cmdBuffer 453 //! Handle of cmd buffer to reset. 454 //! If there is frame split case (more than 1 pipe) in current GPU context queue, this is primary cmd buffer handle. 455 //! 456 //! \return MOS_STATUS 457 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 458 //! 459 static MOS_STATUS ResetCommandBuffer( 460 MOS_STREAM_HANDLE streamState, 461 COMMAND_BUFFER_HANDLE cmdBuffer); 462 463 //! 464 //! \brief Verify Command Buffer Size 465 //! \details [Cmd Buffer Interface] Check if cmd buffer size is larger than the requested size 466 //! \details Caller: HAL only 467 //! 468 //! \param [in] streamState 469 //! Handle of Os Stream State 470 //! \param [in, out] cmdBuffer 471 //! Handle of cmd buffer to verify size 472 //! \param [in] requestedSize 473 //! Requested size 474 //! \param [in] pipeIdx 475 //! Pipe index to indicate which pipe's cmdbuffer to verify. 476 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 477 //! 478 //! \return MOS_STATUS 479 //! Return MOS_STATUS_SUCCESS if successful, MOS_STATUS_UNKNOWN if size does not meet the requirment, otherwise failed 480 //! 481 static MOS_STATUS VerifyCommandBufferSize( 482 MOS_STREAM_HANDLE streamState, 483 COMMAND_BUFFER_HANDLE cmdBuffer, 484 uint32_t requestedSize, 485 uint32_t pipeIdx = 0); 486 487 //! 488 //! \brief Resize Command Buffer and Patch List 489 //! \details [Cmd Buffer Interface] Resize the cmd buffer to contain more cmds. Resize the patch list to have more resource.s 490 //! \details Caller: HAL only 491 //! \details ResizeCommandBuffer can be called at any time if providing valid a cmd buffer. 492 //! When cmds number to be added is increased, this interface needs to be called. 493 //! MOS will make sure the existing cmds copied to the resized cmd buffer. 494 //! Patch list contain the entries to patch cmds. When cmds number to be added is increased, this interface needs to be called. 495 //! \details Recommand to call this interface only once for a specific cmd buffer with a conservative requestedSize. 496 //! 497 //! \param [in] streamState 498 //! Handle of Os Stream State 499 //! \param [in, out] cmdBuffer 500 //! Handle of cmd buffer to resize. 501 //! \param [in] requestedSize 502 //! Requested size. If the size already larger than the requirement, no operations is done to cmd buffer. 503 //! \param [in] requestedPatchListSize 504 //! Requested patch list size. If the size already larger than the requirement, no operations is done to cmd buffer. 505 //! \param [in] pipeIdx 506 //! Pipe index to indicate which pipe's cmdbuffer to resize. 507 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 508 //! 509 //! \return MOS_STATUS 510 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 511 //! 512 static MOS_STATUS ResizeCommandBufferAndPatchList( 513 MOS_STREAM_HANDLE streamState, 514 COMMAND_BUFFER_HANDLE cmdBuffer, 515 uint32_t requestedSize, 516 uint32_t requestedPatchListSize, 517 uint32_t pipeIdx = 0); 518 519 //! 520 //! \brief Set Patch Entry 521 //! \details [Cmd Buffer Interface] Set a patch entry in cmd buffer. 522 //! \details Caller: MHW only 523 //! \details This interface is called only when adding a resource into a cmd. 524 //! The entries in cmd buffer indicate the gfx address to be patched. 525 //! 526 //! \param [in] streamState 527 //! Handle of Os Stream State 528 //! \param [in] params 529 //! Pointer to the patch entry parameters. 530 //! 531 //! \return MOS_STATUS 532 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 533 //! 534 static MOS_STATUS SetPatchEntry( 535 MOS_STREAM_HANDLE streamState, 536 PMOS_PATCH_ENTRY_PARAMS params); 537 538 //! 539 //! \brief Get Indirect State 540 //! \details [Cmd Buffer Interface] Get the indirect state in cmd buffer. 541 //! \details Caller: MHW only 542 //! \details This interface is called when preparing indirect state data in cmd buffer. 543 //! Indirect state is a reserved region in cmd buffer which contains the data needed by execute Media kernel. 544 //! 545 //! \param [in] streamState 546 //! Handle of Os Stream State 547 //! \param [out] indirectState 548 //! Pointer to pointer to indirectState data. MHW can use this ptr to set data. 549 //! \param [out] offset 550 //! Offset of indirect state in the cmd buffer. 551 //! \param [out] size 552 //! Size of indirect state in the cmd buffer. 553 //! 554 //! \return MOS_STATUS 555 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 556 //! 557 static MOS_STATUS GetIndirectState( 558 MOS_STREAM_HANDLE streamState, 559 uint8_t **indirectState, 560 uint32_t &offset, 561 uint32_t &size); 562 563 //! 564 //! \brief Setup indirect state 565 //! \details [Cmd Buffer Interface] Setup the indirect state region in cmd buffer. 566 //! \details Caller: MHW only 567 //! \details This interface is called to reserve the region of indirect state data in cmd buffer. 568 //! \details Indirect state is a reserved region in cmd buffer which contains the data needed by execute Media kernel. 569 //! The region is at the end of cmd buffer, size is only needed. Between each SubmitCommandBuffer, this interface should only be call once. 570 //! 571 //! \param [in] streamState 572 //! Handle of Os Stream State 573 //! \param [in] size 574 //! Size of indirect state in the cmd buffer. 575 //! 576 //! \return MOS_STATUS 577 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 578 //! 579 static MOS_STATUS SetupIndirectState( 580 MOS_STREAM_HANDLE streamState, 581 uint32_t size); 582 583 //! 584 //! \brief Setup VE Attribute Buffer 585 //! \details [Cmd Buffer Interface] Setup VE Attribute Buffer into cmd buffer. 586 //! \details Caller: MHW only 587 //! \details This interface is called to setup into cmd buffer. 588 //! 589 //! \param [in] streamState 590 //! Handle of Os Stream State 591 //! \param [out] cmdBuffer 592 //! Cmd buffer to setup VE attribute. 593 //! 594 //! \return MOS_STATUS 595 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 596 //! 597 static MOS_STATUS SetupAttributeVeBuffer( 598 MOS_STREAM_HANDLE streamState, 599 COMMAND_BUFFER_HANDLE cmdBuffer); 600 601 //! 602 //! \brief Get VE Attribute Buffer 603 //! \details [Cmd Buffer Interface] Get VE Attribute Buffer from cmd buffer. 604 //! \details Caller: HAL only 605 //! \details This interface is called to get VE attribute buffer from cmd buffer if it contains one. 606 //! If there is no VE attribute buffer returned, it means the cmd buffer has no such buffer 607 //! in current MOS module. It is not error state if it is nullptr. 608 //! 609 //! \param [out] cmdBuffer 610 //! Cmd buffer to setup VE attribute. 611 //! 612 //! \return MOS_CMD_BUF_ATTRI_VE* 613 //! Return pointer of VE attribute buffer, nullptr if current cmdBuffer didn't contain attribute. 614 //! 615 static MOS_CMD_BUF_ATTRI_VE *GetAttributeVeBuffer( 616 COMMAND_BUFFER_HANDLE cmdBuffer); 617 618 //! 619 //! \brief Get Cache Policy Memory Object 620 //! \details [Resource Interface] Get Cache Policy Memory Object in GMM corresponding to the resource usage 621 //! Caller: HAL & MHW 622 //! 623 //! \param [in] streamState 624 //! Handle of Os Stream State 625 //! \param [in] mosUsage 626 //! Resource usage as index to the memory object table 627 //! If prociding unknown usage, default state will be returned 628 //! 629 //! \return MEMORY_OBJECT_CONTROL_STATE 630 //! The cache policy memory object got from MOS interface 631 //! 632 static MEMORY_OBJECT_CONTROL_STATE GetCachePolicyMemoryObject( 633 MOS_STREAM_HANDLE streamState, 634 MOS_HW_RESOURCE_DEF mosUsage); 635 636 //! 637 //! \brief Get Cache Policy L1 Config 638 //! \details [Resource Interface] Get L1 Cache Config in GMM corresponding to the resource usage 639 //! Caller: HAL & MHW 640 //! 641 //! \param [in] streamState 642 //! Handle of Os Stream State 643 //! \param [in] mosUsage 644 //! Resource usage as index to the memory object table 645 //! If prociding unknown usage, default state will be returned 646 //! 647 //! \return uint8_t 648 //! The L1_Cache_Config got from MOS interface 649 //! 650 static uint8_t GetCachePolicyL1Config( 651 MOS_STREAM_HANDLE streamState, 652 MOS_HW_RESOURCE_DEF mosUsage); 653 654 //! 655 //! \brief Convert Resource From Ddi 656 //! \details [Resource Interface] Convert Resource structure From OS/API specific to MOS reource. 657 //! \details Caller: DDI only 658 //! \details MOS resoure is the structure inside MOS module. DDI specific resource depends on OS/API verison. 659 //! DDI call this to convert external resources (not created by hal) to Mos resources so that HAL & MHW can use them. 660 //! 661 //! \param [in] osResource 662 //! OS/API specific resource structure to convert. 663 //! \param [out] resource 664 //! Handle of Mos resource convert. 665 //! \param UINT firstArraySlice 666 //! [in] resource special info 667 //! \param UINT mipSlice 668 //! [in] resource special info 669 //! 670 //! \return MOS_STATUS 671 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 672 //! 673 static MOS_STATUS ConvertResourceFromDdi( 674 OsSpecificRes osResource, 675 MOS_RESOURCE_HANDLE &resource, 676 uint32_t firstArraySlice, 677 uint32_t mipSlice); 678 679 //! 680 //! \brief Create Os Specific Resource Info 681 //! \details [Resource Interface] Create OS/API specific resource info structures. 682 //! \details Caller: DDI only 683 //! \details Os Specific resource info must be created before uing in DDI or converting to MOS resource. 684 //! This interface doesn't allocate Os Specific Resource. It only create the decorated structure of that resource. 685 //! 686 //! \param [in, out] resource 687 //! OS/API specific resource structure to initialize. 688 //! \param [in] isInternal 689 //! Indicate if the resource is media internal. 690 //! 691 //! \return MOS_STATUS 692 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 693 //! 694 static MOS_STATUS CreateOsSpecificResourceInfo(OsSpecificRes resource, bool isInternal = false); 695 696 //! 697 //! \brief Destroy Os Specific Resource Info 698 //! \details [Resource Interface] Destroy OS/API specific resource structure. 699 //! \details Caller: DDI only 700 //! \details Os Specific resource info must be destroied if the resource is not used anymore. 701 //! 702 //! \param [in, out] resource 703 //! OS/API specific resource structure to initialize. 704 //! 705 //! \return MOS_STATUS 706 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 707 //! 708 static MOS_STATUS DestroySpecificResourceInfo(OsSpecificRes resource); 709 710 //! 711 //! \brief Allocate Resource 712 //! \details [Resource Interface] Allocate a graphic resource. 713 //! \details Caller: HAL only 714 //! \details Graphic resource is a buffer contain data used in the HW cmds. 715 //! This interface allocates the gfx resource and its internal data structure. 716 //! RegisterResource must be called when cmds in cmd buffer programmed are using this resource. 717 //! 718 //! \param [in] streamState 719 //! Handle of Os Stream State 720 //! \param [in] params 721 //! Pointer to the parameters for allocating resource 722 //! \param [out] resource 723 //! MOS Resource handle of the allocated resource. 724 //! 725 //! \return MOS_STATUS 726 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 727 //! 728 static MOS_STATUS AllocateResource( 729 MOS_STREAM_HANDLE streamState, 730 PMOS_ALLOC_GFXRES_PARAMS params, // user provided va 731 MOS_RESOURCE_HANDLE &resource); 732 733 //! 734 //! \brief Free Resource 735 //! \details [Resource Interface] Free a graphic resource. 736 //! \details Caller: HAL only 737 //! \details Graphic resource is a buffer contain data used in the HW cmds. 738 //! This interface frees the gfx resource and its internal data structure. 739 //! This interface must be called when the resource is not used anymore. 740 //! 741 //! \param [in] streamState 742 //! Handle of Os Stream State 743 //! \param [in] resource 744 //! MOS Resource handle of the allocated resource. 745 //! \param [in] flag 746 //! User defined free flag of the resource. 747 //! 748 //! \return MOS_STATUS 749 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 750 //! 751 static MOS_STATUS FreeResource( 752 MOS_STREAM_HANDLE streamState, 753 MOS_RESOURCE_HANDLE resource, 754 uint32_t flag); 755 756 //! 757 //! \brief Get Resource Info 758 //! \details [Resource Interface] Get the info of a graphic resource. 759 //! \details Caller: HAL only 760 //! \details This interface gets the read-only detailed info of a graphic resource. 761 //! Any modification of details provided by this interface will not impact the actual resource. 762 //! 763 //! \param [in] streamState 764 //! Handle of Os Stream State 765 //! \param [in] resource 766 //! MOS Resource handle of the allocated resource. 767 //! \param [out] details 768 //! Resource detailed info got. 769 //! 770 //! \return MOS_STATUS 771 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 772 //! 773 static MOS_STATUS GetResourceInfo( 774 MOS_STREAM_HANDLE streamState, 775 MOS_RESOURCE_HANDLE resource, 776 MosResourceInfo &details); 777 778 //! 779 //! \brief Lock Resource 780 //! \details [Resource Interface] Lock the gfx resource for CPU to access 781 //! \details Caller: HAL only 782 //! \details A sys memory ptr will be provided by this interface if executed successfully. 783 //! \details The sys memory is mapped to the gfx memory inside MOS module. 784 //! \details This interface is usually for driver to read/write data into a resource directly (without program HW cmd). 785 //! \details Caller must make sure no access out of bound of the locked out data. UnlockResource must be called when finished access the locked data. 786 //! A resource already been locked cannot be locked again. 787 //! This is a blocking call if the resource is used by the cmdbuffer which already submitted to an existing GPU context. 788 //! Unless SkipResourceSync is called. This interface will make sure the sync of Lock. 789 //! \details If the resource is compressed, gfx memory decompression will be triggered. 790 //! 791 //! \param [in] streamState 792 //! Handle of Os Stream State 793 //! \param [in] resource 794 //! MOS Resource handle of the resource to lock. 795 //! \param [in] flags 796 //! Control flags of locking resource. 797 //! 798 //! \return void * 799 //! Locked memory data pointer, nullptr if lock failed. 800 //! 801 static void *LockMosResource( 802 MOS_STREAM_HANDLE streamState, 803 MOS_RESOURCE_HANDLE resource, 804 PMOS_LOCK_PARAMS flags); 805 806 //! 807 //! \brief Unlock Resource 808 //! \details [Resource Interface] Unlock the gfx resource which is locked out. 809 //! \details Caller: HAL only 810 //! \details UnlockResource must be called when finished access the locked data of the resource. 811 //! A resource already been unlocked cannot be unlocked again. 812 //! \details Unlock resource will not trigger compressing or changing the layout of the resource. 813 //! 814 //! \param [in] streamState 815 //! Handle of Os Stream State 816 //! \param [in] resource 817 //! MOS Resource handle of the allocated resource. 818 //! 819 //! \return MOS_STATUS 820 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 821 //! 822 static MOS_STATUS UnlockMosResource( 823 MOS_STREAM_HANDLE streamState, 824 MOS_RESOURCE_HANDLE resource); 825 826 //! 827 //! \brief Register Resource 828 //! \details [Resource Interface] Register the resource to current streamState. 829 //! \details Caller: MHW only 830 //! \details Register resource to inform MOS that the resource is read/written by current cmd buffer being programmed 831 //! and this cmd buffer will be submitted into current GPU context in streamState. 832 //! \details RegisterResource must be called when cmds in cmd buffer programmed are using this resource. 833 //! \details This interface is to make the residency of the resource and handle resource sync harzad between GPU contexts. 834 //! \details Calling sequence is like: SetGpuContext -> RegisterResource... -> SubmitCommandBuffer -> 835 //! SetGpuContext(another) -> RegisterResource(another or same resource)... -> SubmitCommandBuffer 836 //! \details If Register same resource to different GPU context when calling SetGpuContext, sync harzad will be handled. 837 //! RegisterResource for the same resource can be called repeatedly. MOS will make sure no duplicated residency making and sync. 838 //! 839 //! \param [in] streamState 840 //! Handle of Os Stream State 841 //! \param [out] resource 842 //! MOS Resource handle of the allocated resource. 843 //! \param [in] write 844 //! Indicate if the resource is written by HW or just read. 845 //! 846 //! \return MOS_STATUS 847 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 848 //! 849 static MOS_STATUS RegisterResource( 850 MOS_STREAM_HANDLE streamState, 851 MOS_RESOURCE_HANDLE resource, 852 bool write); 853 854 //! 855 //! \brief Get Resource Gfx Address 856 //! \details [Resource Interface] Get the graphic virtual address of the resource. 857 //! \details Caller: MHW only 858 //! \details Only use this interface to add resource's address directly into cmd field. 859 //! If MHW needs patch the address in the cmd field, GetResourceAllocationIndex should be called. 860 //! 861 //! \param [in] streamState 862 //! Handle of Os Stream State 863 //! \param [in] resource 864 //! MOS Resource handle of the allocated resource. 865 //! 866 //! \return uint64_t 867 //! 64bit virtual graphic address got. 0x00000000 if execution failed. 868 //! 869 static uint64_t GetResourceGfxAddress( 870 MOS_STREAM_HANDLE streamState, 871 MOS_RESOURCE_HANDLE resource); 872 873 //! 874 //! \brief Get Resource Allocation index 875 //! \details [Resource Interface] Get the allocation index of the resource. 876 //! \details Caller: MHW only 877 //! \details Allocation index is used when calling SetPatchEntry to add resource into cmd. 878 //! If MHW needs patch the address in the cmd field, GetResourceAllocationIndex should be called. 879 //! 880 //! \param [in] streamState 881 //! Handle of Os Stream State 882 //! \param [in] resource 883 //! MOS Resource handle of the allocated resource. 884 //! 885 //! \return uint32_t 886 //! Allocation index got. 0 if execution failed. 887 //! 888 static uint32_t GetResourceAllocationIndex( 889 MOS_STREAM_HANDLE streamState, 890 MOS_RESOURCE_HANDLE resource); 891 892 //! 893 //! \brief Skip Resource Sync 894 //! \details [Resource Interface] Skip the sync handling of the resource 895 //! \details Caller: HAL only 896 //! \details Indicate the resource provided needn't to be synced. 897 //! The resource skipping sync can be accessed by different cmd buffers on different GPU contexts at the same time. 898 //! \details RegisterResource and LockResource will not handling the sync of the resources between different GPU cotnexts. 899 //! \details Usually the resource skipping sync is for the case like: 900 //! Different cmd buffers at the same time access the non-overlapped region of the resource 901 //! 902 //! \param [in] streamState 903 //! Handle of Os Stream State 904 //! \param [in] params 905 //! Pointer to the parameters for allocating resource 906 //! \param [out] resource 907 //! MOS Resource handle of the allocated resource. 908 //! 909 //! \return MOS_STATUS 910 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 911 //! 912 static MOS_STATUS SkipResourceSync( 913 MOS_RESOURCE_HANDLE resource); 914 915 //! 916 //! \brief Sync on resource 917 //! \details [Resource Interface] Explicit sync on resource 918 //! \details Caller: HAL only 919 //! \details Resource is shared by different cmd buffers on different GPU contexts. 920 //! Adding sync object into requestor GPU context queue to resolve the hazard if necessary. 921 //! This func is called by hal to declare the resource to consider the sync explicitly. 922 //! It is a strong sync request for the resource. 923 //! 924 //! \param [in] streamState 925 //! Handle of Os Stream State 926 //! \param [in] resource 927 //! MOS Resource handle for the resource contain hazard of sync 928 //! \param [in] writeOperation 929 //! Indicate the current programming is to write resource or not 930 //! \param [in] requsetorGpuContext 931 //! GpuContext which programming the resource. Recommand not setting it and use current GPU context. 932 //! 933 //! \return MOS_STATUS 934 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 935 //! 936 static MOS_STATUS SyncOnResource( 937 MOS_STREAM_HANDLE streamState, 938 MOS_RESOURCE_HANDLE resource, 939 bool writeOperation, 940 GPU_CONTEXT_HANDLE requsetorGpuContext = MOS_GPU_CONTEXT_INVALID_HANDLE); 941 942 //! 943 //! \brief Resource Sync call back between Media and 3D for resource Sync 944 //! \details [Resource Interface] Sync Call Back based on resource 945 //! \details Caller: DDI only 946 //! \details Resource is shared by different cmd buffers on different GPU contexts. 947 //! Adding sync object into requestor GPU context queue to resolve the hazard if necessary. 948 //! If there is a hazard, one cmd buffer in requestor GPU context queue will wait for the other cmd buffer in busy GPU context. 949 //! 950 //! \param [in] resource 951 //! OS specific resource handle for the resource contain hazard of sync 952 //! \param [in] deviceContext 953 //! Handle of Os Device Context 954 //! \param [in] index 955 //! Sub-resource index 956 //! \param [in] hazardType 957 //! Type of hazard: RAW, WAR, WAR 958 //! \param [in] busyCtx 959 //! GPU Context handle of the queue being waiting for. 960 //! \param [in] requestorCtx 961 //! GPU Context handle of current GPU which requesting to use the resoure and find the hazard to wait the busy context. 962 //! \param [in] osRequestorHandle 963 //! OS runtime handle of requestor context 964 //! 965 //! \return MOS_STATUS 966 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 967 //! 968 static MOS_STATUS ResourceSyncCallback( 969 OsSpecificRes resource, 970 MOS_DEVICE_HANDLE deviceContext, 971 uint32_t index, 972 SYNC_HAZARD hazardType, 973 GPU_CONTEXT_HANDLE busyCtx, 974 GPU_CONTEXT_HANDLE requestorCtx, 975 OS_HANDLE osRequestorHandle); 976 977 //! 978 //! \brief Lock Sync Callback between Media and 3D 979 //! \details [Resource Interface] Lock Sync Call Back 980 //! \details Caller: DDI only 981 //! \details Resource is used in a cmd buffer on an existing GPU context. 982 //! Before Locking the resource, make sure the resource finished used by all GPU contexts which are using this resource. 983 //! If there is a hazard, CPU side will wait for the cmd buffer in busy GPU context. 984 //! 985 //! \param [in] resource 986 //! OS specific resource handle for the resource contain hazard of sync 987 //! \param [in] deviceContext 988 //! Handle of Os Device Context 989 //! \param [in] index 990 //! Sub-resource index 991 //! \param [in] hazardType 992 //! Type of hazard: RAW, WAR, WAR 993 //! \param [in] busyCtx 994 //! GPU Context handle of the queue being waiting for. 995 //! \param [in] doNotWait 996 //! Indicate this is blocking call or not. When set to true, possibly return MOS_STATUS_STILL_DRAWING 997 //! 998 //! \return MOS_STATUS 999 //! Return MOS_STATUS_SUCCESS if successful, MOS_STATUS_STILL_DRAWING if doNotWait 1000 //! is set to true and resoure is still being used in HW, otherwise failed 1001 //! 1002 static MOS_STATUS LockSyncCallback( 1003 OsSpecificRes resource, 1004 MOS_DEVICE_HANDLE deviceContext, 1005 uint32_t index, 1006 SYNC_HAZARD hazardType, 1007 GPU_CONTEXT_HANDLE busyCtx, 1008 bool doNotWait); 1009 1010 //! 1011 //! \brief Wait For cmd Completion 1012 //! \details [GPU Context Interface] Waiting for the completion of cmd in provided GPU context 1013 //! \details Caller: HAL only 1014 //! 1015 //! \param [in] streamState 1016 //! Handle of Os Stream State 1017 //! \param [in] gpuCtx 1018 //! GpuContext handle of the gpu context to wait cmd completion 1019 //! 1020 //! \return MOS_STATUS 1021 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1022 //! 1023 static MOS_STATUS WaitForCmdCompletion( 1024 MOS_STREAM_HANDLE streamState, 1025 GPU_CONTEXT_HANDLE gpuCtx); 1026 1027 //! 1028 //! \brief Trim Residency 1029 //! 1030 //! \param [in] periodicTrim 1031 //! Indicate if the trim is periodic 1032 //! \param [in] restartPeriodicTrim 1033 //! Indicate if restarting periodic trim 1034 //! \param [in] numBytesToTrim 1035 //! Number bytes to trim 1036 //! \param [in] trimToMinimum 1037 //! Indicate if trim to minimum 1038 //! \param [in] trimOnlyMediaResources 1039 //! Indicate if only trim media resources. 1040 //! 1041 //! \return MOS_STATUS 1042 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1043 //! 1044 static MOS_STATUS TrimResidency( 1045 bool periodicTrim, 1046 bool restartPeriodicTrim, 1047 uint64_t &numBytesToTrim, 1048 bool trimToMinimum, 1049 bool trimOnlyMediaResources); 1050 1051 // Memory compression interfaces 1052 1053 //! 1054 //! \brief Decompress resource 1055 //! 1056 //! \param [in] streamState 1057 //! Handle of Os Stream State 1058 //! \param [in] resource 1059 //! MOS Resource handle of the resource to decompress. 1060 //! \return MOS_STATUS 1061 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1062 //! 1063 static MOS_STATUS DecompResource( 1064 MOS_STREAM_HANDLE streamState, 1065 MOS_RESOURCE_HANDLE resource); 1066 1067 //! 1068 //! \brief Set Memory Compression Mode 1069 //! 1070 //! \param [in] streamState 1071 //! Handle of Os Stream State 1072 //! \param [in, out] resource 1073 //! MOS Resource handle 1074 //! \param [in] resMmcMode 1075 //! MMC mode 1076 //! 1077 //! \return MOS_STATUS 1078 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1079 //! 1080 static MOS_STATUS SetMemoryCompressionMode( 1081 MOS_STREAM_HANDLE streamState, 1082 MOS_RESOURCE_HANDLE resource, 1083 MOS_MEMCOMP_STATE resMmcMode); 1084 1085 //! 1086 //! \brief Get Memory Compression Mode 1087 //! 1088 //! \param [in] streamState 1089 //! Handle of Os Stream State 1090 //! \param [in] resource 1091 //! MOS Resource handle 1092 //! \param [out] resMmcMode 1093 //! MMC mode 1094 //! 1095 //! \return MOS_STATUS 1096 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1097 //! 1098 static MOS_STATUS GetMemoryCompressionMode( 1099 MOS_STREAM_HANDLE streamState, 1100 MOS_RESOURCE_HANDLE resource, 1101 MOS_MEMCOMP_STATE &resMmcMode); 1102 1103 //! 1104 //! \brief Set Memory Compression Hint 1105 //! 1106 //! \param [in] streamState 1107 //! Handle of Os Stream State 1108 //! \param [in, out] resource 1109 //! MOS Resource handle 1110 //! \param [in] hintOn 1111 //! Flag to set hint on or off 1112 //! 1113 //! \return MOS_STATUS 1114 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1115 //! 1116 static MOS_STATUS SetMemoryCompressionHint( 1117 MOS_STREAM_HANDLE streamState, 1118 MOS_RESOURCE_HANDLE resource, 1119 bool hintOn); 1120 1121 //! 1122 //! \brief Get Memory Compression Format 1123 //! 1124 //! \param [in] streamState 1125 //! Handle of Os Stream State 1126 //! \param [in, out] resource 1127 //! MOS Resource handle 1128 //! \param [out] resMmcFormat 1129 //! MMC format got 1130 //! 1131 //! \return MOS_STATUS 1132 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1133 //! 1134 static MOS_STATUS GetMemoryCompressionFormat( 1135 MOS_STREAM_HANDLE streamState, 1136 MOS_RESOURCE_HANDLE resource, 1137 uint32_t *resMmcFormat); 1138 1139 //! 1140 //! \brief Double buffer copy resource 1141 //! 1142 //! \param [in] streamState 1143 //! Handle of Os Stream State 1144 //! \param [in] inputResource 1145 //! Input resource to copy. 1146 //! \param [out] outputResource 1147 //! Output resource. 1148 //! \param [in] outputCompressed 1149 //! Insdicate if output resource is compressed. 1150 //! \return MOS_STATUS 1151 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1152 //! 1153 static MOS_STATUS DoubleBufferCopyResource( 1154 MOS_STREAM_HANDLE streamState, 1155 MOS_RESOURCE_HANDLE inputResource, 1156 MOS_RESOURCE_HANDLE outputResource, 1157 bool outputCompressed); 1158 1159 //! 1160 //! \brief Copy Resource to Another Buffer 1161 //! \details Decompress and Copy Resource to Another 2D Buffer 1162 //! 1163 //! \param [in] streamState 1164 //! Handle of Os Stream State 1165 //! \param inputResource 1166 //! [in] Input Resource object 1167 //! \param outputResource 1168 //! [out] output Resource object 1169 //! \param [in] copyWidth 1170 //! The 2D surface Width 1171 //! \param [in] copyHeight 1172 //! The 2D surface height 1173 //! \param [in] copyInputOffset 1174 //! The offset of copied surface from 1175 //! \param [in] copyOutputOffset 1176 //! The offset of copied to 1177 //! \param [in] outputCompressed 1178 //! True means apply compression on output surface, else output uncompressed surface 1179 //! \return MOS_STATUS 1180 //! MOS_STATUS_SUCCESS if successful 1181 //! 1182 static MOS_STATUS MediaCopyResource2D( 1183 MOS_STREAM_HANDLE streamState, 1184 MOS_RESOURCE_HANDLE inputResource, 1185 MOS_RESOURCE_HANDLE outputResource, 1186 uint32_t copyWidth, 1187 uint32_t copyHeight, 1188 uint32_t copyInputOffset, 1189 uint32_t copyOutputOffset, 1190 bool outputCompressed); 1191 1192 // GPU Status interfaces 1193 1194 //! 1195 //! \brief Get Gpu Status Tag 1196 //! 1197 //! \param [in] streamState 1198 //! Handle of Os Stream State 1199 //! \param [in] gpuContext 1200 //! MOS GPU Context handle 1201 //! 1202 //! \return uint32_t 1203 //! Tag got from GPU Context indicated, 0 if failed to get the tag 1204 //! 1205 static uint32_t GetGpuStatusTag( 1206 MOS_STREAM_HANDLE streamState, 1207 GPU_CONTEXT_HANDLE gpuContext); 1208 1209 //! 1210 //! \brief Increment Gpu Status Tag 1211 //! 1212 //! \param [in] streamState 1213 //! Handle of Os Stream State 1214 //! \param [in] gpuContext 1215 //! MOS GPU Context handle 1216 //! 1217 //! \return MOS_STATUS 1218 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1219 //! 1220 static MOS_STATUS IncrementGpuStatusTag( 1221 MOS_STREAM_HANDLE streamState, 1222 GPU_CONTEXT_HANDLE gpuContext); 1223 1224 //! 1225 //! \brief Get Gpu Status Sync Tag 1226 //! 1227 //! \param [in] streamState 1228 //! Handle of Os Stream State 1229 //! \param [in] gpuContext 1230 //! MOS GPU Context handle 1231 //! 1232 //! \return uint64_t 1233 //! HW tag got from GPU context, 0 if get failed 1234 //! 1235 static uint64_t GetGpuStatusSyncTag( 1236 MOS_STREAM_HANDLE streamState, 1237 GPU_CONTEXT_HANDLE gpuContext); 1238 1239 //! 1240 //! \brief Get Gpu Status Buffer Resource 1241 //! 1242 //! \param [in] streamState 1243 //! Handle of Os Stream State 1244 //! \param [out] resource 1245 //! MOS resource handle of GPU status buffer got from current GPU context 1246 //! \param [in] gpuContext 1247 //! MOS GPU Context handle 1248 //! 1249 //! \return MOS_STATUS 1250 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1251 //! 1252 1253 static MOS_STATUS GetGpuStatusBufferResource( 1254 MOS_STREAM_HANDLE streamState, 1255 MOS_RESOURCE_HANDLE resource, 1256 GPU_CONTEXT_HANDLE gpuContext); 1257 1258 //! 1259 //! \brief Get CP Interface 1260 //! 1261 //! \param [in] streamState 1262 //! Handle of Os Stream State 1263 //! 1264 //! \return MosCpInterface 1265 //! CP Interface got from stream State, nullptr if get failed 1266 //! 1267 static MosCpInterface *GetCpInterface(MOS_STREAM_HANDLE streamState); 1268 1269 //! 1270 //! \brief Get OCA Interface 1271 //! 1272 //! \param [in] streamState 1273 //! Handle of Os Stream State 1274 //! 1275 //! \return MosOcaInterface 1276 //! OCA Interface got from stream State, nullptr if get failed 1277 //! 1278 static MosOcaInterface *GetOcaInterface(MOS_STREAM_HANDLE streamState); 1279 1280 //! 1281 //! \brief Maps the specified executable module into the address space of 1282 //! the calling process. 1283 //! \param PMOS_INTERFACE pOsInterface 1284 //! [in] A handle to OS interface. This can be nullptr which allows a caller to 1285 //! always get library from specified library path (function will never check 1286 //! driver store) which is useful if there's a constant static path of a library 1287 //! \param const PCCHAR lpLibFileName 1288 //! [in] String containing resource name to load. Absolute path is given here 1289 //! if pOsInterface is nullptr, else only lib path is given, and driver will check store for path 1290 //! \param PHMODULE phModule 1291 //! [out] Handle to library given back to the caller 1292 //! \return MOS_STATUS 1293 //! Returns one of the MOS_STATUS error codes if failed, 1294 //! else MOS_STATUS_SUCCESS 1295 //! 1296 static MOS_STATUS MosLoadLibrary( 1297 MOS_STREAM_HANDLE streamState, 1298 PCCHAR pFileName, 1299 PHMODULE phModule); 1300 1301 //! 1302 //! \brief Free the loaded dynamic-link library 1303 //! \details Free the loaded dynamic-link library 1304 //! \param [in] hLibModule 1305 //! A handle to the loaded DLL module 1306 //! \return int32_t 1307 //! true if success else false 1308 //! 1309 static MOS_STATUS MosFreeLibrary(HMODULE hLibModule); 1310 1311 //! \brief Get Virtual Engine State 1312 //! \details [Virtual Engine Interface] Get Virtual Engine State from streamState 1313 //! \details Caller: Hal (Scalability) only 1314 //! \details This func is called when a stream (Hal instance) need to get a VE state 1315 //! \details corresponding to current GPU context. 1316 //! 1317 //! \param [in] streamState 1318 //! Handle of Os Stream State 1319 //! 1320 //! \return MOS_VE_HANDLE 1321 //! Handle of MOS virtual engine state, Invalid handle if get failed 1322 //! 1323 static MOS_VE_HANDLE GetVirtualEngineState( 1324 MOS_STREAM_HANDLE streamState); 1325 1326 //! 1327 //! \brief Set Virtual Engine State 1328 //! \details [Virtual Engine Interface] Set Virtual Engine State of provided streamState 1329 //! \details Caller: Hal (Scalability) only 1330 //! \details This func is called when a stream (Hal instance) need to set an existing VE state 1331 //! \details into provided stream. 1332 //! 1333 //! \param [in] streamState 1334 //! Handle of Os Stream State 1335 //! \param [in] veState 1336 //! Handle of Virtual Engine State to set 1337 //! 1338 //! \return MOS_STATUS 1339 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1340 //! 1341 static MOS_STATUS SetVirtualEngineState( 1342 MOS_STREAM_HANDLE streamState, 1343 MOS_VE_HANDLE veState); 1344 1345 //! 1346 //! \brief Create Virtual Engine State 1347 //! \details [Virtual Engine Interface] Create Virtual Engine State of provided streamState 1348 //! \details Caller: Hal (Scalability) only 1349 //! \details This func is called when a stream (Hal instance) need to create a VE state 1350 //! \details into provided stream. 1351 //! 1352 //! \param [in] streamState 1353 //! Handle of Os Stream State 1354 //! \param [in] veInitParms 1355 //! Pointer of parameters to init ve staet 1356 //! \param [out] veState 1357 //! Reference of the handle of Virtual Engine State to created 1358 //! 1359 //! \return MOS_STATUS 1360 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1361 //! 1362 static MOS_STATUS CreateVirtualEngineState( 1363 MOS_STREAM_HANDLE streamState, 1364 PMOS_VIRTUALENGINE_INIT_PARAMS veInitParms, 1365 MOS_VE_HANDLE &veState); 1366 1367 //! 1368 //! \brief Destroy Virtual Engine State 1369 //! \details [Virtual Engine Interface] Destroy Virtual Engine State of provided streamState 1370 //! \details Caller: Hal (Scalability) only 1371 //! \details This func is called when a stream (Hal instance) need to destroy a VE state 1372 //! \details into provided stream. 1373 //! 1374 //! \param [in] streamState 1375 //! Handle of Os Stream State 1376 //! \param [out] veState 1377 //! Reference of the handle of Virtual Engine State to created 1378 //! 1379 //! \return MOS_STATUS 1380 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1381 //! 1382 static MOS_STATUS DestroyVirtualEngineState( 1383 MOS_STREAM_HANDLE streamState); 1384 1385 //! 1386 //! \brief Set hint parameters 1387 //! 1388 //! \details [Virtual Engine Interface] Set hint parameters into Virtual Engine State in provided stream 1389 //! \details Caller: Hal (Scalability) only 1390 //! \details Set hint parameters for virtual engine state 1391 //! 1392 //! \param [in] streamState 1393 //! Handle of Os Stream State 1394 //! \param [in] veParams 1395 //! pointer to VE parameter data structure to set 1396 //! \return MOS_STATUS 1397 //! MOS_STATUS_SUCCESS if success, else fail reason 1398 //! 1399 static MOS_STATUS SetVeHintParams( 1400 MOS_STREAM_HANDLE streamState, 1401 PMOS_VIRTUALENGINE_SET_PARAMS veParams); 1402 1403 //! 1404 //! \brief Get hint parameters 1405 //! 1406 //! \details [Virtual Engine Interface] Get hint parameters from Virtual Engine State in provided stream 1407 //! \details Caller: Hal (Scalability) only 1408 //! \details Get hint parameters from virtual engine state 1409 //! 1410 //! \param [in] streamState 1411 //! Handle of Os Stream State 1412 //! \param [in] scalableMode 1413 //! flag to indicate if scalability mode 1414 //! \param [out] hintParams 1415 //! pointer to VE hint parameter address 1416 //! \return MOS_STATUS 1417 //! MOS_STATUS_SUCCESS if success, else fail reason 1418 //! 1419 static MOS_STATUS GetVeHintParams( 1420 MOS_STREAM_HANDLE streamState, 1421 bool scalableMode, 1422 PMOS_VIRTUALENGINE_HINT_PARAMS *hintParams); 1423 1424 //! 1425 //! \brief Set Virtual Engine Submission Type 1426 //! 1427 //! \details [Virtual Engine Interface] Set submission type for the provided cmd buffer 1428 //! \details Caller: Hal (Scalability) only 1429 //! \details Set submission type as per cmd buffer hint parameter. Must be set before submission. 1430 //! Submission type is to set cmd buffer (primary or secondary) property to indicate 1431 //! which pipe it belongs. See MOS_SUBMISSION_TYPE. 1432 //! 1433 //! \param [in] streamState 1434 //! Handle of Os Stream State 1435 //! \param [out] cmdBuf 1436 //! Handle of cmd buffer to set submission type 1437 //! \param [in] type 1438 //! Submission type to set 1439 //! \return MOS_STATUS 1440 //! MOS_STATUS_SUCCESS if success, else fail reason 1441 //! 1442 static MOS_STATUS SetVeSubmissionType( 1443 MOS_STREAM_HANDLE streamState, 1444 COMMAND_BUFFER_HANDLE cmdBuf, 1445 MOS_SUBMISSION_TYPE type); 1446 1447 #if _DEBUG || _RELEASE_INTERNAL 1448 //! 1449 //! \brief Get engine count 1450 //! 1451 //! \details [Virtual Engine Interface] Get engine count from Virtual Engine State in provided stream 1452 //! \details Caller: Hal (Scalability) only 1453 //! \details Get engine count from virtual engine state 1454 //! 1455 //! \param [in] streamState 1456 //! Handle of Os Stream State 1457 //! \return uint8_t 1458 //! Engine count 1459 //! 1460 static uint8_t GetVeEngineCount( 1461 MOS_STREAM_HANDLE streamState); 1462 1463 //! 1464 //! \brief Get Engine Logic Id 1465 //! \details [Virtual Engine Interface] Get engine Logic Id from Virtual Engine State in provided stream 1466 //! \details Caller: Hal (Scalability) only 1467 //! \details Get engine Logic Id from virtual engine state 1468 //! 1469 //! \param [in] streamState 1470 //! Handle of Os Stream State 1471 //! \param [in] instanceIdx 1472 //! Engine instance index 1473 //! \return uint8_t 1474 //! 1475 static uint8_t GetEngineLogicId( 1476 MOS_STREAM_HANDLE streamState, 1477 uint32_t instanceIdx); 1478 1479 #endif // _DEBUG || _RELEASE_INTERNAL 1480 1481 private: 1482 1483 //! 1484 //! \brief Compose Cmd buffer header 1485 //! \details Compose Cmd buffer header if it contains header 1486 //! 1487 //! \param [in] streamState 1488 //! Handle of Os Stream State 1489 //! \param [out] cmdBuffer 1490 //! Cmd buffer to compose header. 1491 //! 1492 //! \return MOS_STATUS 1493 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1494 //! 1495 static MOS_STATUS ComposeCommandBufferHeader( 1496 MOS_STREAM_HANDLE streamState, 1497 COMMAND_BUFFER_HANDLE cmdBuffer); 1498 1499 //! 1500 //! \brief Get GpuContext 1501 //! \details MOS internal toolset func to get GPU context instance 1502 //! 1503 //! \param [in] streamState 1504 //! Handle of Os Stream State 1505 //! \param [in] gpuContext 1506 //! MOS GPU Context handle 1507 //! 1508 //! \return GpuContextSpecificNext 1509 //! GPU Context instance got by GPU context handle, nullptr if get failed 1510 //! 1511 static GpuContextSpecificNext *GetGpuContext(MOS_STREAM_HANDLE streamState, GPU_CONTEXT_HANDLE handle); 1512 }; 1513 1514 #endif // __MOS_INTERFACE_H__