1 /* 2 * Copyright (c) 2009-2023, 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_oca_rtlog_mgr_defs.h" 52 #include "mos_os.h" 53 #include "media_class_trace.h" 54 55 class GpuContextSpecificNext; 56 struct _MOS_VIRTUALENGINE_SET_PARAMS; 57 struct _MOS_VIRTUALENGINE_INIT_PARAMS; 58 struct SYNC_FENCE_INFO_TRINITY; 59 60 typedef struct _MOS_VIRTUALENGINE_SET_PARAMS MOS_VIRTUALENGINE_SET_PARAMS, *PMOS_VIRTUALENGINE_SET_PARAMS; 61 typedef struct _MOS_VIRTUALENGINE_INIT_PARAMS MOS_VIRTUALENGINE_INIT_PARAMS, *PMOS_VIRTUALENGINE_INIT_PARAMS; 62 typedef struct _MOS_CMD_BUF_ATTRI_VE MOS_CMD_BUF_ATTRI_VE, *PMOS_CMD_BUF_ATTRI_VE; 63 typedef struct _MHW_VDBOX_GPUNODE_LIMIT *PMHW_VDBOX_GPUNODE_LIMIT; 64 class MosInterface 65 { 66 protected: 67 //! 68 //! \brief Destructor 69 //! \details There is no members in Mos Interface, it's pure interface. 70 //! Never call the Destructor of Mos interface 71 //! 72 ~MosInterface() = default; 73 74 //! 75 //! \brief Constructor 76 //! \details There is no members in Mos Interface, it's pure interface. 77 //! Never call the Constructor of Mos interface 78 //! 79 MosInterface() = default; 80 81 public: 82 //! 83 //! \brief Init Os Utilities 84 //! \details Include Utilities, user settings key, mem ninja etc 85 //! \details Must be first called MOS interface before CreateOsDeviceContext 86 //! \details Caller: DDI only. 87 //! 88 //! \param [in] ddiDeviceContext 89 //! Pointer of device context in DDI to init Os Device Context 90 //! 91 //! \return MOS_STATUS 92 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 93 //! 94 static MOS_STATUS InitOsUtilities(DDI_DEVICE_CONTEXT ddiDeviceContext); 95 96 //! 97 //! \brief Close Os Utilities 98 //! \details Include Utilities, user settings key, mem ninja etc 99 //! \details Must be last called MOS interface after DestroyOsDeviceContext 100 //! \details Caller: DDI only. 101 //! 102 //! \param [in] mosCtx 103 //! Pointer of device context in DDI for reg ops 104 //! 105 //! \return MOS_STATUS 106 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 107 //! 108 static MOS_STATUS CloseOsUtilities(PMOS_CONTEXT mosCtx); 109 110 //! 111 //! \brief Init Os context interface 112 //! \details Init Os context interface 113 //! 114 //! \param [in/out] ctxInterface 115 //! Pointer of MOS_CONTEXT_INTERFACE 116 //! 117 //! \return MOS_STATUS 118 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 119 //! 120 static MOS_STATUS InitCtxInterface(MOS_CONTEXT_INTERFACE *ctxInterface); 121 122 //! 123 //! \brief Create Os Device Context 124 //! \details Create the Os Device Context in device level. 125 //! \details Caller: DDI only. 126 //! \details The Os Device Context is a singleton in the device, DDI must make sure call this only once. 127 //! If the creation failed, DDI must yield to continue the initialization of device. 128 //! 129 //! \param [in] ddiDeviceContext 130 //! Pointer of device context in DDI to init Os Device Context 131 //! \param [out] deviceContext 132 //! Handle of Os Device Context to create. If creation failed, it is INVALID_HANLE. 133 //! OsDeviceContext is a device level singleton which stores the states, info specific to OS. 134 //! It contain sub modules of MOS to transfer OS specific services to OS agnositic abstractions. 135 //! 136 //! \return MOS_STATUS 137 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 138 //! 139 static MOS_STATUS CreateOsDeviceContext(DDI_DEVICE_CONTEXT ddiDeviceContext, MOS_DEVICE_HANDLE *deviceContext); 140 141 //! 142 //! \brief Destroy Os Device Context 143 //! \details Destroy the Os Device Context in device level 144 //! \details Caller: DDI only. 145 //! 146 //! \param [in] deviceContext 147 //! Handle of Os Device Context to Destroy 148 //! 149 //! \return MOS_STATUS 150 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 151 //! 152 static MOS_STATUS DestroyOsDeviceContext(MOS_DEVICE_HANDLE deviceContext); 153 154 //! 155 //! \brief Create Os Stream State 156 //! \details Create the Os Stream State in stream level. 157 //! \details Caller: DDI 158 //! \details In DDI, one stream (Hal instance) can only create one Os Stream State corresponding to it. 159 //! Os Stream state directly created by DDI is not corresponding any streams (Hal instances) 160 //! 161 //! \param [out] streamState 162 //! Handle of Os Stream State to create. If creation failed, it is INVALID_HANLE. 163 //! OsStreamState is a stream level state which stores the flags, info specific to OS specfic to that stream. 164 //! It is be binded with a valid OsDeviceContext to indicate the inclusion relationship between device and stream. 165 //! \param [in] deviceContext 166 //! Device context to init streamState 167 //! \param [in] osInterface 168 //! Os interface to store streamState 169 //! \param [in] component 170 //! Indicate which component the stream state to create belongs to 171 //! \param [in] extraParams 172 //! Additional parameters needed to init streamstate 173 //! 174 //! \return MOS_STATUS 175 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 176 //! 177 static MOS_STATUS CreateOsStreamState( 178 MOS_STREAM_HANDLE *streamState, 179 MOS_DEVICE_HANDLE deviceContext, 180 MOS_INTERFACE_HANDLE osInterface, 181 MOS_COMPONENT component, 182 EXTRA_PARAMS extraParams = nullptr); 183 184 //! 185 //! \brief Destroy Os Stream State 186 //! \details Destroy the Os Stream State in stream level 187 //! \details Caller: DDI 188 //! 189 //! \param [in] streamState 190 //! Handle of Os Stream State to Destroy 191 //! 192 //! \return MOS_STATUS 193 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 194 //! 195 static MOS_STATUS DestroyOsStreamState( 196 MOS_STREAM_HANDLE streamState); 197 198 //! 199 //! \brief Get OS runtime interface version 200 //! \details [System info Interface] Get OS runtime interface version 201 //! \details Caller: DDI only 202 //! \details Only DDI can derive diff behavior due to OS runtime interface version 203 //! 204 //! \param [in] deviceContext 205 //! Handle of Os Device Context 206 //! 207 //! \return uint32_t 208 //! Read-only OS runtime interface version, it's meaning diff from OS and API 209 //! 210 static uint32_t GetInterfaceVersion(MOS_DEVICE_HANDLE deviceContext); 211 212 //! 213 //! \brief Get Platform 214 //! \details [System info Interface] Get Get Platform information 215 //! \details Caller: DDI & HAL & MHW 216 //! \details This func is called in DDI only to generate hal instance stand for specific platform. 217 //! This func can be used in HAL & MHW to get platfrom detailed info to judge the path of different behavior. 218 //! 219 //! \param [in] streamState 220 //! Handle of Os Stream State 221 //! 222 //! \return PLATFORM 223 //! Gfx driver shared enum of platform got. Read-only. 224 //! 225 static PLATFORM *GetPlatform(MOS_STREAM_HANDLE streamState); 226 227 //! 228 //! \brief Get SkuTable 229 //! \details [System info Interface] Get Sku Table 230 //! \details Caller: DDI & HAL & MHW 231 //! \details This func is called to differentiate the behavior according to SKU table. 232 //! 233 //! \param [in] streamState 234 //! Handle of Os Stream State 235 //! 236 //! \return MEDIA_FEATURE_TABLE* 237 //! Read-only SKU table got, nullptr if failed to get 238 //! 239 static MEDIA_FEATURE_TABLE *GetSkuTable(MOS_STREAM_HANDLE streamState); 240 241 //! 242 //! \brief Get WaTable 243 //! \details [System info Interface] Get WA Table 244 //! \details Caller: DDI & HAL & MHW 245 //! \details This func is called to differentiate the behavior according to WA table. 246 //! 247 //! \param [in] streamState 248 //! Handle of Os Stream State 249 //! 250 //! \return MEDIA_WA_TABLE* 251 //! Read-only WA table got, nullptr if failed to get 252 //! 253 static MEDIA_WA_TABLE *GetWaTable(MOS_STREAM_HANDLE streamState); 254 255 //! 256 //! \brief Get Gt System Info 257 //! \details [System info Interface] Get Gt System Info 258 //! \details Caller: HAL & MHW 259 //! \details This func is called to differentiate the behavior according to Gt System Info. 260 //! 261 //! \param [in] streamState 262 //! Handle of Os Stream State 263 //! 264 //! \return MEDIA_SYSTEM_INFO* 265 //! Read-only GT system info got, nullptr if failed to get 266 //! 267 static MEDIA_SYSTEM_INFO *GetGtSystemInfo(MOS_STREAM_HANDLE streamState); 268 269 //! 270 //! \brief Get Media Engine Info 271 //! \details [System info Interface] Get Media Engine Info 272 //! \details Caller: HAL & MHW 273 //! \details This func is called to differentiate the behavior according to Media Engine Info. 274 //! 275 //! \param [in] streamState 276 //! Handle of Os Stream State 277 //! \param [in] info 278 //! MEDIA_SYS_INFO 279 //! 280 //! \return MOS_STATUS 281 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 282 //! 283 static MOS_STATUS GetMediaEngineInfo(MOS_STREAM_HANDLE streamState, MEDIA_ENGINE_INFO &info); 284 285 //! 286 //! \brief Get Adapter Info 287 //! \details [System info Interface] Get Adapter Info 288 //! \details Caller: DDI & HAL 289 //! \details This func is called to differentiate the behavior according to Adapter Info. 290 //! 291 //! \param [in] streamState 292 //! Handle of Os Stream State 293 //! 294 //! \return ADAPTER_INFO* 295 //! Read-only Adapter Info got, nullptr if failed to get 296 //! 297 static ADAPTER_INFO *GetAdapterInfo(MOS_STREAM_HANDLE streamState); 298 299 //! 300 //! \brief Get current gmmclientcontext 301 //! \details Get current gmmclientcontext 302 //! 303 //! \param [in] streamState 304 //! Handle of Os Stream State 305 //! 306 //! \return GMM_CLIENT_CONTEXT 307 //! Current gmmclientcontext 308 //! 309 static GMM_CLIENT_CONTEXT *GetGmmClientContext( 310 MOS_STREAM_HANDLE streamState); 311 312 //! 313 //! \brief Get PAT index from gmm 314 //! 315 //! \param [in] gmmClient 316 //! GMM client context 317 //! \param [in] gmmResourceInfo 318 //! gmm resource info 319 //! 320 //! \return unsigned int 321 //! Pat index 322 //! 323 static unsigned int GetPATIndexFromGmm( 324 GMM_CLIENT_CONTEXT *gmmClient, 325 GMM_RESOURCE_INFO *gmmResourceInfo); 326 327 //! 328 //! \brief Get current Gpu context priority 329 //! \details Get current Gpu context priority 330 //! 331 //! \param [in] streamState 332 //! Handle of Os Stream State 333 //! 334 //! [out] 335 //! Current Gpu context priority 336 //! 337 static void GetGpuPriority(MOS_STREAM_HANDLE streamState, int32_t* priority); 338 339 //! 340 //! \brief Set current Gpu context priority 341 //! \details Set current Gpu context priority 342 //! 343 //! \param [in] streamState 344 //! Handle of Os Stream State 345 //! [in] priority 346 //! priority to set for gpu context 347 //! 348 static void SetGpuPriority(MOS_STREAM_HANDLE streamState, int32_t priority); 349 350 //! 351 //! \brief Get AuxTable base address 352 //! 353 //! \param [in] streamState 354 //! Handle of Os Stream State 355 //! \return uint64_t 356 //! 64bit base address value of AuxTable 357 //! 358 static uint64_t GetAuxTableBaseAddr( 359 MOS_STREAM_HANDLE streamState); 360 361 //! 362 //! \brief Create Gpu Context 363 //! \details [GPU Context Interface] Create Gpu Context to submit cmdbuffers 364 //! \details Caller: HAL (Media Context) only 365 //! \details This func is called when a stream (Hal instance) needs a SW queue to submit cmd buffers programmed with GPU cmds. 366 //! \details This queue contain options to indicate the properties of virtual GPU engine to execute these cmds. 367 //! \details Caller can use Usage & option & GPU_CONTEXT_HANDLE to track and re-use the GPU contexts. 368 //! 369 //! \param [in] streamState 370 //! Handle of Os Stream State 371 //! \param [in] createOption 372 //! Properties of Gpu context to create. They stand for the request from HAL on the Gpu context. 373 //! The request include engine type, pipe count, restrictions, etc. 374 //! \param [out] gpuContext 375 //! Handle of gpu Context created. If creation failed, it is INVALID_HANLE 376 //! GPU context stands for a SW queue in user space to submit cmd buffers FIFO. 377 //! 378 //! \return MOS_STATUS 379 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 380 //! 381 static MOS_STATUS CreateGpuContext( 382 MOS_STREAM_HANDLE streamState, 383 GpuContextCreateOption &createOption, 384 GPU_CONTEXT_HANDLE &gpuContext); 385 386 //! 387 //! \brief Destroy Gpu Context 388 //! \details [GPU Context Interface] Destroy Gpu Context to submit cmdbuffers 389 //! \details Caller: HAL (Media Context) only 390 //! \details This func is called when a stream (Hal instance) never needs this SW queue to submit cmd buffers 391 //! \details This func is called only in the destruction stage of Hal instance. 392 //! Never should be SetGpuContext called to set destroied Gpu Context. 393 //! 394 //! \param [in] streamState 395 //! Handle of Os Stream State 396 //! \param [in] gpuContext 397 //! Handle of gpu Context to destroy. 398 //! 399 //! \return MOS_STATUS 400 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 401 //! 402 static MOS_STATUS DestroyGpuContext( 403 MOS_STREAM_HANDLE streamState, 404 GPU_CONTEXT_HANDLE gpuContext); 405 406 //! 407 //! \brief Set Gpu Context 408 //! \details [GPU Context Interface] Set current Gpu Context to submit cmd buffers for the stream(Hal instance) 409 //! \details Caller: HAL (Media Context) only 410 //! \details This func is called when a stream (Hal instance) needs an existing GPU context to submit cmd buffers. 411 //! \details Current GPU context is the major state of Os Stream State. 412 //! \details Before getting a cmd buffer to program GPU cmds, a valid GPU context must be setted into the stream. 413 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 414 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 415 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 416 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 417 //! 418 //! \param [in] streamState 419 //! Handle of Os Stream State 420 //! \param [in] gpuContext 421 //! Current handle of gpu Context to set. 422 //! 423 //! \return MOS_STATUS 424 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 425 //! 426 static MOS_STATUS SetGpuContext( 427 MOS_STREAM_HANDLE streamState, 428 GPU_CONTEXT_HANDLE gpuContext); 429 430 //! \brief Sets the object capture flags for Linux OCA dump 431 //! \details Sets the object capture flags for Linux OCA dump 432 //! 433 //! \param PMOS_RESOURCE osResource 434 //! [in] osResource 435 //! \return MOS_STATUS 436 //! Return MOS_STATUS_SUCCESS if success else failure reason 437 //! 438 static MOS_STATUS SetObjectCapture( 439 PMOS_RESOURCE osResource); 440 441 //! 442 //! \brief Get GpuContext 443 //! \details MOS internal toolset func to get GPU context instance 444 //! 445 //! \param [in] streamState 446 //! Handle of Os Stream State 447 //! \param [in] gpuContext 448 //! MOS GPU Context handle 449 //! 450 //! \return GpuContextSpecificNext 451 //! GPU Context instance got by GPU context handle, nullptr if get failed 452 //! 453 static GpuContextSpecificNext *GetGpuContext(MOS_STREAM_HANDLE streamState, GPU_CONTEXT_HANDLE handle); 454 455 //! 456 //! \brief Add Command 457 //! \details [Cmd Buffer Interface] Add gpu commands into cmd buffer 458 //! \details Caller: MHW only 459 //! \details It is not device stated function and can be used in both APO MHW and NON-APO MOS. 460 //! \details This func is called when a stream (Hal instance) adds gpu cmds into cmd buffer. 461 //! \details Before getting a cmd buffer to program GPU cmds, a valid GPU context must be setted into the stream. 462 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 463 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 464 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 465 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 466 //! 467 //! \param [in] cmdBuffer 468 //! Handle of cmd buffer to add cmd. cmd buffer handle can be get by calling GetCommandBuffer. 469 //! \param [in] cmd 470 //! Pointer to the memory to indicate cmd, caller must make sure it's valid. 471 //! \param [in] cmdSize 472 //! Size of cmd to program. 473 //! 474 //! \return MOS_STATUS 475 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 476 //! 477 static MOS_STATUS AddCommand( 478 COMMAND_BUFFER_HANDLE cmdBuffer, 479 const void *cmd, 480 uint32_t cmdSize); 481 482 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED 483 //! 484 //! \brief Dump Indirect state in Command Buffer 485 //! 486 static MOS_STATUS DumpIndirectStates( 487 MOS_STREAM_HANDLE streamState, 488 const char *filePathPrefix, 489 std::time_t currentTime); 490 //! 491 //! \brief Dump Indirect state in Command Buffer 492 //! 493 //! \param [in] streamState 494 //! Handle of Os Stream State 495 //! \param [in] cmdBuffer 496 //! Handle of cmd buffer to add cmd. cmd buffer handle can be get by calling GetCommandBuffer. 497 //! \param [in] gpuNode 498 //! Gpu node. 499 //! \param [in] filePathPrefix 500 //! The prefix for indirect state dump file. 501 //! 502 //! \return MOS_STATUS 503 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 504 //! 505 static MOS_STATUS DumpBindingTable( 506 MOS_STREAM_HANDLE streamState, 507 COMMAND_BUFFER_HANDLE cmdBuffer, 508 MOS_GPU_NODE gpuNode, 509 const char *filePathPrefix); 510 511 //! 512 //! \brief Dump Command Buffer 513 //! \details [Cmd Buffer Interface] Dump an existing cmd buffer 514 //! \details Caller: HAL only 515 //! \details This func is called when a stream (Hal instance) needs to dump cmd buffer. 516 //! \details Only after ReturnCommandBuffer can Command Buffer being dumped 517 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 518 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 519 //! 520 //! \param [in] streamState 521 //! Handle of Os Stream State 522 //! \param [in] cmdBuffer 523 //! Handle of cmd buffer to add cmd. cmd buffer handle can be get by calling GetCommandBuffer. 524 //! 525 //! \return MOS_STATUS 526 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 527 //! 528 static MOS_STATUS DumpCommandBuffer( 529 MOS_STREAM_HANDLE streamState, 530 COMMAND_BUFFER_HANDLE cmdBuffer); 531 #endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED 532 533 //! 534 //! \brief Get Command Buffer 535 //! \details [Cmd Buffer Interface] Get current cmd buffer to program based on streamState 536 //! \details Caller: HAL only 537 //! \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. 538 //! \details Before getting a cmd buffer to program GPU cmds, a valid GPU context must be setted into the stream. 539 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 540 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 541 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 542 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 543 //! 544 //! \param [in] streamState 545 //! Handle of Os Stream State 546 //! \param [out] cmdBuffer 547 //! Handle of cmd buffer to get. If get failed, it is INVALID_HANLE. 548 //! \param [in] pipeIdx 549 //! Pipe index to indicate which pipe's cmdbuffer to get. 550 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 551 //! 552 //! \return MOS_STATUS 553 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 554 //! 555 static MOS_STATUS GetCommandBuffer( 556 MOS_STREAM_HANDLE streamState, 557 COMMAND_BUFFER_HANDLE &cmdBuffer, 558 uint32_t pipeIdx = 0); 559 560 //! 561 //! \brief Return Command Buffer 562 //! \details [Cmd Buffer Interface] Return current cmd buffer to the MOS 563 //! \details Caller: HAL only 564 //! \details This func is called when a stream (Hal instance) finished add cmds into a cmd buffer. 565 //! \details ReturnCommandBuffer must be called before submit cmd buffer. MOS will do necessary operations in this interface. 566 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 567 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 568 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 569 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 570 //! 571 //! \param [in] streamState 572 //! Handle of Os Stream State 573 //! \param [in] cmdBuffer 574 //! Handle of cmd buffer to return. 575 //! \param [in] pipeIdx 576 //! Pipe index to indicate which pipe's cmdbuffer to get. 577 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 578 //! 579 //! \return MOS_STATUS 580 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 581 //! 582 static MOS_STATUS ReturnCommandBuffer( 583 MOS_STREAM_HANDLE streamState, 584 COMMAND_BUFFER_HANDLE cmdBuffer, 585 uint32_t pipeIdx = 0); 586 587 //! 588 //! \brief Submit Command Buffer 589 //! \details [Cmd Buffer Interface] Submit current cmd buffer to current GPU context queue. 590 //! \details Caller: HAL only 591 //! \details When a stream (Hal instance) call this interface, cmd buffer is enqueued into current GPU context in streamState. 592 //! \details OS runtime and KMD will schedule the workload. HW cmds in the cmd buffer will be executed in HW engines. 593 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer -> AddCommand ... 594 //! -> ReturnCommandBuffer -> SubmitCommandBuffer -> SetGpuContext ... 595 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 596 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 597 //! \details Cmd buffer execution in GPU context is async with Hal programming. Return of this interface does not guarantee finish executing actual cmds. 598 //! 599 //! \param [in] streamState 600 //! Handle of Os Stream State 601 //! \param [in] cmdBuffer 602 //! Handle of cmd buffer to Submit. 603 //! If there is frame split case (more than 1 pipe) in current GPU context queue, this is primary cmd buffer handle. 604 //! \param [in] nullRendering 605 //! Flag to indicate if not actually submit workload into HW. 606 //! 607 //! \return MOS_STATUS 608 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 609 //! 610 static MOS_STATUS SubmitCommandBuffer( 611 MOS_STREAM_HANDLE streamState, 612 COMMAND_BUFFER_HANDLE cmdBuffer, 613 bool nullRendering = false); 614 615 //! 616 //! \brief Reset Command Buffer 617 //! \details [Cmd Buffer Interface] Reset cmd buffer to the initialized state. 618 //! \details Caller: HAL only 619 //! \details ResetCommandBuffer can be called after a stream (Hal instance) call GetCommandBuffer. 620 //! \details OS runtime and KMD will schedule the workload. HW cmds in the cmd buffer will be executed in HW engines. 621 //! \details Calling sequence is like: SetGpuContext -> GetCommandBuffer (-> ResetCommandBuffer) -> AddCommand ... 622 //! \details If Current GPU context is never set, all command buffer / resource interfaces cannot be used. 623 //! (They will return MOS_STATUS_INVALID_GPU_CONTEXT) 624 //! \details Cmd buffer reset means stream starts to program a new set of cmds into a cmd buffer got. 625 //! This interface must not be called when the cmd buffer already programed cmds and not submitted unless the stream needs to drop these cmds. 626 //! 627 //! \param [in] streamState 628 //! Handle of Os Stream State 629 //! \param [in, out] cmdBuffer 630 //! Handle of cmd buffer to reset. 631 //! If there is frame split case (more than 1 pipe) in current GPU context queue, this is primary cmd buffer handle. 632 //! 633 //! \return MOS_STATUS 634 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 635 //! 636 static MOS_STATUS ResetCommandBuffer( 637 MOS_STREAM_HANDLE streamState, 638 COMMAND_BUFFER_HANDLE cmdBuffer); 639 640 //! 641 //! \brief Verify Command Buffer Size 642 //! \details [Cmd Buffer Interface] Check if cmd buffer size is larger than the requested size 643 //! \details Caller: HAL only 644 //! 645 //! \param [in] streamState 646 //! Handle of Os Stream State 647 //! \param [in, out] cmdBuffer 648 //! Handle of cmd buffer to verify size 649 //! \param [in] requestedSize 650 //! Requested size 651 //! \param [in] pipeIdx 652 //! Pipe index to indicate which pipe's cmdbuffer to verify. 653 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 654 //! 655 //! \return MOS_STATUS 656 //! Return MOS_STATUS_SUCCESS if successful, MOS_STATUS_UNKNOWN if size does not meet the requirment, otherwise failed 657 //! 658 static MOS_STATUS VerifyCommandBufferSize( 659 MOS_STREAM_HANDLE streamState, 660 COMMAND_BUFFER_HANDLE cmdBuffer, 661 uint32_t requestedSize, 662 uint32_t pipeIdx = 0); 663 664 //! 665 //! \brief Resize Command Buffer and Patch List 666 //! \details [Cmd Buffer Interface] Resize the cmd buffer to contain more cmds. Resize the patch list to have more resource.s 667 //! \details Caller: HAL only 668 //! \details ResizeCommandBuffer can be called at any time if providing valid a cmd buffer. 669 //! When cmds number to be added is increased, this interface needs to be called. 670 //! MOS will make sure the existing cmds copied to the resized cmd buffer. 671 //! Patch list contain the entries to patch cmds. When cmds number to be added is increased, this interface needs to be called. 672 //! \details Recommand to call this interface only once for a specific cmd buffer with a conservative requestedSize. 673 //! 674 //! \param [in] streamState 675 //! Handle of Os Stream State 676 //! \param [in, out] cmdBuffer 677 //! Handle of cmd buffer to resize. 678 //! \param [in] requestedSize 679 //! Requested size. If the size already larger than the requirement, no operations is done to cmd buffer. 680 //! \param [in] requestedPatchListSize 681 //! Requested patch list size. If the size already larger than the requirement, no operations is done to cmd buffer. 682 //! \param [in] pipeIdx 683 //! Pipe index to indicate which pipe's cmdbuffer to resize. 684 //! In frame split, pipe index is indicated to get secondary cmd buffers. They are cmd buffers split to different engines. 685 //! 686 //! \return MOS_STATUS 687 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 688 //! 689 static MOS_STATUS ResizeCommandBufferAndPatchList( 690 MOS_STREAM_HANDLE streamState, 691 COMMAND_BUFFER_HANDLE cmdBuffer, 692 uint32_t requestedSize, 693 uint32_t requestedPatchListSize, 694 uint32_t pipeIdx = 0); 695 696 //! 697 //! \brief Set Patch Entry 698 //! \details [Cmd Buffer Interface] Set a patch entry in cmd buffer. 699 //! \details Caller: MHW only 700 //! \details This interface is called only when adding a resource into a cmd. 701 //! The entries in cmd buffer indicate the gfx address to be patched. 702 //! 703 //! \param [in] streamState 704 //! Handle of Os Stream State 705 //! \param [in] params 706 //! Pointer to the patch entry parameters. 707 //! 708 //! \return MOS_STATUS 709 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 710 //! 711 static MOS_STATUS SetPatchEntry( 712 MOS_STREAM_HANDLE streamState, 713 PMOS_PATCH_ENTRY_PARAMS params); 714 715 //! 716 //! \brief Get Indirect State 717 //! \details [Cmd Buffer Interface] Get the indirect state in cmd buffer. 718 //! \details Caller: MHW only 719 //! \details This interface is called when preparing indirect state data in cmd buffer. 720 //! Indirect state is a reserved region in cmd buffer which contains the data needed by execute Media kernel. 721 //! 722 //! \param [in] streamState 723 //! Handle of Os Stream State 724 //! \param [out] indirectState 725 //! Pointer to pointer to indirectState data. MHW can use this ptr to set data. 726 //! \param [out] offset 727 //! Offset of indirect state in the cmd buffer. 728 //! \param [out] size 729 //! Size of indirect state in the cmd buffer. 730 //! 731 //! \return MOS_STATUS 732 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 733 //! 734 static MOS_STATUS GetIndirectState( 735 MOS_STREAM_HANDLE streamState, 736 uint8_t **indirectState, 737 uint32_t &offset, 738 uint32_t &size); 739 740 //! 741 //! \brief Setup indirect state 742 //! \details [Cmd Buffer Interface] Setup the indirect state region in cmd buffer. 743 //! \details Caller: MHW only 744 //! \details This interface is called to reserve the region of indirect state data in cmd buffer. 745 //! \details Indirect state is a reserved region in cmd buffer which contains the data needed by execute Media kernel. 746 //! The region is at the end of cmd buffer, size is only needed. Between each SubmitCommandBuffer, this interface should only be call once. 747 //! 748 //! \param [in] streamState 749 //! Handle of Os Stream State 750 //! \param [in] size 751 //! Size of indirect state in the cmd buffer. 752 //! 753 //! \return MOS_STATUS 754 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 755 //! 756 static MOS_STATUS SetupIndirectState( 757 MOS_STREAM_HANDLE streamState, 758 uint32_t size); 759 760 //! 761 //! \brief Setup commandlist and command pool 762 //! \details Set the commandlist and commandPool used in this stream. 763 //! 764 //! \param [in] streamState 765 //! Handle of Os Stream State 766 //! \param [in] cmdList 767 //! pointer to the command list. 768 //! \param [in] cmdBufMgr 769 //! pointer to the command buffer manager. 770 //! 771 //! \return MOS_STATUS 772 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 773 //! 774 static MOS_STATUS SetupCurrentCmdListAndPool( 775 MOS_STREAM_HANDLE streamState, 776 CommandList *cmdList, 777 CmdBufMgrNext *cmdBufMgr); 778 779 //! 780 //! \brief Setup commandlist and command pool from os interface 781 //! \details Set the commandlist and commandPool used in this stream from os interface. 782 //! 783 //! \param [in] pMosInterface 784 //! pointer to the mos interface 785 //! \param [out] streamStateDst 786 //! Handle of Os Stream State. 787 //! 788 //! \return MOS_STATUS 789 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 790 //! 791 static MOS_STATUS SetupCurrentCmdListAndPoolFromOsInterface( 792 PMOS_INTERFACE pMosInterface, 793 MOS_STREAM_HANDLE streamState); 794 795 //! 796 //! \brief Is Device Async or not 797 //! \details Is Device Async or not. 798 //! 799 //! \param [in] streamStateDst 800 //! Handle of Os Stream State. 801 //! 802 //! \return bool 803 //! Return true if is async, otherwise false 804 //! 805 static bool IsAsyncDevice( 806 MOS_STREAM_HANDLE streamState); 807 808 //! 809 //! \brief Setup VE Attribute Buffer 810 //! \details [Cmd Buffer Interface] Setup VE Attribute Buffer into cmd buffer. 811 //! \details Caller: MHW only 812 //! \details This interface is called to setup into cmd buffer. 813 //! 814 //! \param [in] streamState 815 //! Handle of Os Stream State 816 //! \param [out] cmdBuffer 817 //! Cmd buffer to setup VE attribute. 818 //! 819 //! \return MOS_STATUS 820 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 821 //! 822 static MOS_STATUS SetupAttributeVeBuffer( 823 MOS_STREAM_HANDLE streamState, 824 COMMAND_BUFFER_HANDLE cmdBuffer); 825 826 //! 827 //! \brief Get VE Attribute Buffer 828 //! \details [Cmd Buffer Interface] Get VE Attribute Buffer from cmd buffer. 829 //! \details Caller: HAL only 830 //! \details This interface is called to get VE attribute buffer from cmd buffer if it contains one. 831 //! If there is no VE attribute buffer returned, it means the cmd buffer has no such buffer 832 //! in current MOS module. It is not error state if it is nullptr. 833 //! 834 //! \param [out] cmdBuffer 835 //! Cmd buffer to setup VE attribute. 836 //! 837 //! \return MOS_CMD_BUF_ATTRI_VE* 838 //! Return pointer of VE attribute buffer, nullptr if current cmdBuffer didn't contain attribute. 839 //! 840 static MOS_CMD_BUF_ATTRI_VE *GetAttributeVeBuffer( 841 COMMAND_BUFFER_HANDLE cmdBuffer); 842 843 //! 844 //! \brief Get Cache Policy Memory Object 845 //! \details [Resource Interface] Get Cache Policy Memory Object in GMM corresponding to the resource usage 846 //! Caller: HAL & MHW 847 //! 848 //! \param [in] mosUsage 849 //! Resource usage as index to the memory object table 850 //! If prociding unknown usage, default state will be returned 851 //! 852 //! \return MEMORY_OBJECT_CONTROL_STATE 853 //! The cache policy memory object got from MOS interface 854 //! 855 static GMM_RESOURCE_USAGE_TYPE GetGmmResourceUsageType( 856 MOS_HW_RESOURCE_DEF mosUsage); 857 858 //! 859 //! \brief Get MOS_HW_RESOURCE_DEF 860 //! \details [Resource Interface] Get Mos HW Resource DEF 861 //! Caller: HAL & MHW 862 //! 863 //! \param [in] gmmResUsage 864 //! Gmm Resource usage as index 865 //! 866 //! \return MOS_HW_RESOURCE_DEF 867 //! Mos HW resource definition 868 //! 869 static MOS_HW_RESOURCE_DEF GmmToMosResourceUsageType( 870 GMM_RESOURCE_USAGE_TYPE gmmResUsage); 871 872 //! 873 //! \brief Get Cache Policy Memory Object 874 //! \details [Resource Interface] Get Cache Policy Memory Object in GMM corresponding to the resource usage 875 //! Caller: HAL & MHW 876 //! 877 //! \param [in] gmmClientContext 878 //! Handle of gmmClientContext 879 //! \param [in] mosUsage 880 //! Resource usage as index to the memory object table 881 //! If prociding unknown usage, default state will be returned 882 //! 883 //! \return MEMORY_OBJECT_CONTROL_STATE 884 //! The cache policy memory object got from MOS interface 885 //! 886 static MEMORY_OBJECT_CONTROL_STATE GetCachePolicyMemoryObject( 887 GMM_CLIENT_CONTEXT *gmmClientContext, 888 MOS_HW_RESOURCE_DEF mosUsage); 889 890 //! 891 //! \brief Get default Cache Policy Memory Object 892 //! \details [Resource Interface] Get Cache Policy Memory Object in GMM corresponding to the resource usage 893 //! Caller: HAL & MHW 894 //! 895 //! \param [in] gmmClientContext 896 //! Handle of gmmClientContext 897 //! If prociding unknown usage, default state will be returned 898 //! 899 //! \return MEMORY_OBJECT_CONTROL_STATE 900 //! The cache policy memory object got from MOS interface 901 //! 902 static MEMORY_OBJECT_CONTROL_STATE GetDefaultCachePolicyMemoryObject( 903 GMM_CLIENT_CONTEXT *gmmClientContext); 904 905 //! 906 //! \brief Get Cache Policy Memory Object 907 //! \details [Resource Interface] Get Cache Policy Memory Object in GMM corresponding to the resource usage 908 //! Caller: MOS 909 //! 910 //! \param [in] gmmClientContext 911 //! Handle of gmmClientContext 912 //! \param [in] gmmUsage 913 //! Resource usage value defined in gmm 914 //! If prociding unknown usage, default state will be returned 915 //! 916 //! \return MEMORY_OBJECT_CONTROL_STATE 917 //! The cache policy memory object got from MOS interface 918 //! 919 static MEMORY_OBJECT_CONTROL_STATE GetGmmCachePolicyMemoryObject( 920 GMM_CLIENT_CONTEXT *gmmClientContext, 921 GMM_RESOURCE_USAGE_TYPE gmmUsage); 922 923 //! 924 //! \brief Get Cache Policy L1 Config 925 //! \details [Resource Interface] Get L1 Cache Config in GMM corresponding to the resource usage 926 //! Caller: HAL & MHW 927 //! 928 //! \param [in] streamState 929 //! Handle of Os Stream State 930 //! \param [in] mosUsage 931 //! Resource usage as index to the memory object table 932 //! If prociding unknown usage, default state will be returned 933 //! 934 //! \return uint8_t 935 //! The L1_Cache_Config got from MOS interface 936 //! 937 static uint8_t GetCachePolicyL1Config( 938 MOS_STREAM_HANDLE streamState, 939 MOS_HW_RESOURCE_DEF mosUsage); 940 941 //! 942 //! \brief Get Reserved info from resource 943 //! \details 944 //! 945 //! \param [in] resource 946 //! Handle of resource 947 //! \param [out] val 948 //! result of info. 949 //! 950 //! \return MOS_STATUS 951 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 952 //! 953 static MOS_STATUS GetReservedFromResource(MOS_RESOURCE_HANDLE resource, uint32_t &val); 954 955 //! 956 //! \brief Get Reserved info from Stream 957 //! \details 958 //! 959 //! \param [in] stream 960 //! Handle of stream 961 //! \param [out] val 962 //! result of info. 963 //! 964 //! \return MOS_STATUS 965 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 966 //! 967 static MOS_STATUS GetReservedFromStream(MOS_STREAM_HANDLE stream, uint32_t &val); 968 969 //! 970 //! \brief Get Reserved info from Device 971 //! \details 972 //! 973 //! \param [in] osDeivceContext 974 //! Handle of device 975 //! \param [out] val 976 //! result of info. 977 //! 978 //! \return MOS_STATUS 979 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 980 //! 981 static MOS_STATUS GetReservedFromDevice(MOS_DEVICE_HANDLE device, uint32_t &val); 982 983 //! 984 //! \brief Get preStreamParameters(mos context) info from streamState 985 //! \details 986 //! 987 //! \param [in] stream 988 //! Handle of stream 989 //! \param [out] perStreamParameters 990 //! pointer of mos conxtex. 991 //! 992 //! \return MOS_STATUS 993 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 994 //! 995 static MOS_STATUS GetperStreamParameters(MOS_STREAM_HANDLE stream, void **perStreamParameters); 996 997 //! 998 //! \brief Convert Resource From Ddi 999 //! \details [Resource Interface] Convert Resource structure From OS/API specific to MOS reource. 1000 //! \details Caller: DDI only 1001 //! \details It is not device stated function and can be used in both APO DDI and NON-APO MOS. 1002 //! \details MOS resoure is the structure inside MOS module. DDI specific resource depends on OS/API verison. 1003 //! DDI call this to convert external resources (not created by hal) to Mos resources so that HAL & MHW can use them. 1004 //! 1005 //! \param [in] osResource 1006 //! OS/API specific resource structure to convert. 1007 //! \param [out] resource 1008 //! Handle of Mos resource convert. 1009 //! \param UINT firstArraySlice 1010 //! [in] resource special info 1011 //! \param UINT mipSlice 1012 //! [in] resource special info 1013 //! 1014 //! \return MOS_STATUS 1015 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1016 //! 1017 static MOS_STATUS ConvertResourceFromDdi( 1018 OsSpecificRes osResource, 1019 MOS_RESOURCE_HANDLE &resource, 1020 uint32_t firstArraySlice, 1021 uint32_t mipSlice); 1022 1023 //! 1024 //! \brief Create Os Specific Resource Info 1025 //! \details [Resource Interface] Create OS/API specific resource info structures. 1026 //! \details Caller: DDI only 1027 //! \details Os Specific resource info must be created before uing in DDI or converting to MOS resource. 1028 //! This interface doesn't allocate Os Specific Resource. It only create the decorated structure of that resource. 1029 //! 1030 //! \param [in, out] resource 1031 //! OS/API specific resource structure to initialize. 1032 //! \param [in] isInternal 1033 //! Indicate if the resource is media internal. 1034 //! 1035 //! \return MOS_STATUS 1036 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1037 //! 1038 static MOS_STATUS CreateOsSpecificResourceInfo(OsSpecificRes resource, bool isInternal = false); 1039 1040 //! 1041 //! \brief Destroy Os Specific Resource Info 1042 //! \details [Resource Interface] Destroy OS/API specific resource structure. 1043 //! \details Caller: DDI only 1044 //! \details It is not device stated function and can be used in both APO DDI and NON-APO MOS. 1045 //! \details Os Specific resource info must be destroied if the resource is not used anymore. 1046 //! 1047 //! \param [in, out] resource 1048 //! OS/API specific resource structure to initialize. 1049 //! 1050 //! \return MOS_STATUS 1051 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1052 //! 1053 static MOS_STATUS DestroySpecificResourceInfo(OsSpecificRes resource); 1054 1055 //! 1056 //! \brief Allocate Resource 1057 //! \details [Resource Interface] Allocate a graphic resource. 1058 //! \details Caller: HAL only 1059 //! \details Graphic resource is a buffer contain data used in the HW cmds. 1060 //! This interface allocates the gfx resource and its internal data structure. 1061 //! RegisterResource must be called when cmds in cmd buffer programmed are using this resource. 1062 //! 1063 //! \param [in] streamState 1064 //! Handle of Os Stream State 1065 //! \param [in] params 1066 //! Pointer to the parameters for allocating resource 1067 //! \param [out] resource 1068 //! MOS Resource handle of the allocated resource. 1069 //! 1070 //! \return MOS_STATUS 1071 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1072 //! 1073 static MOS_STATUS AllocateResource( 1074 MOS_STREAM_HANDLE streamState, 1075 PMOS_ALLOC_GFXRES_PARAMS params, // user provided va 1076 MOS_RESOURCE_HANDLE &resource 1077 #if MOS_MESSAGES_ENABLED 1078 , 1079 const char *functionName, 1080 const char *filename, 1081 int32_t line 1082 #endif 1083 ); 1084 1085 //! 1086 //! \brief Convert HAL free flags to OS free flags 1087 //! 1088 //! \param [in] halFreeFlag 1089 //! bit definition in MOS_GFXRES_FREE_FLAGS 1090 //! 1091 //! \return uint32_t 1092 //! OS resource deallc flags 1093 //! 1094 static uint32_t ConvertHalFreeFlagsToOsFreeFlags( 1095 uint32_t halFreeFlag 1096 ); 1097 1098 //! 1099 //! \brief Free Resource 1100 //! \details [Resource Interface] Free a graphic resource. 1101 //! \details Caller: HAL only 1102 //! \details Graphic resource is a buffer contain data used in the HW cmds. 1103 //! This interface frees the gfx resource and its internal data structure. 1104 //! This interface must be called when the resource is not used anymore. 1105 //! 1106 //! \param [in] streamState 1107 //! Handle of Os Stream State 1108 //! \param [in] resource 1109 //! MOS Resource handle of the allocated resource. 1110 //! \param [in] flag 1111 //! User defined free flag of the resource. 1112 //! 1113 //! \return MOS_STATUS 1114 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1115 //! 1116 static MOS_STATUS FreeResource( 1117 MOS_STREAM_HANDLE streamState, 1118 MOS_RESOURCE_HANDLE resource, 1119 uint32_t flag 1120 #if MOS_MESSAGES_ENABLED 1121 , 1122 const char *functionName, 1123 const char *filename, 1124 int32_t line 1125 #endif // MOS_MESSAGES_ENABLED 1126 ); 1127 1128 static MOS_STATUS FreeResource( 1129 OsDeviceContext *osDeviceContext, 1130 MOS_RESOURCE_HANDLE resource, 1131 uint32_t flag 1132 #if MOS_MESSAGES_ENABLED 1133 , 1134 const char *functionName, 1135 const char *filename, 1136 int32_t line 1137 #endif // MOS_MESSAGES_ENABLED 1138 ); 1139 1140 //! 1141 //! \brief Get Resource Info 1142 //! \details [Resource Interface] Get the info of a graphic resource. 1143 //! \details Caller: HAL only 1144 //! \details This interface gets the read-only detailed info of a graphic resource. 1145 //! Any modification of details provided by this interface will not impact the actual resource. 1146 //! 1147 //! \param [in] streamState 1148 //! Handle of Os Stream State 1149 //! \param [in] resource 1150 //! MOS Resource handle of the allocated resource. 1151 //! \param [out] details 1152 //! Resource detailed info got. 1153 //! 1154 //! \return MOS_STATUS 1155 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1156 //! 1157 static MOS_STATUS GetResourceInfo( 1158 MOS_STREAM_HANDLE streamState, 1159 MOS_RESOURCE_HANDLE resource, 1160 MosResourceInfo &details); 1161 1162 //! 1163 //! \brief Lock Resource 1164 //! \details [Resource Interface] Lock the gfx resource for CPU to access 1165 //! \details Caller: HAL only 1166 //! \details A sys memory ptr will be provided by this interface if executed successfully. 1167 //! \details The sys memory is mapped to the gfx memory inside MOS module. 1168 //! \details This interface is usually for driver to read/write data into a resource directly (without program HW cmd). 1169 //! \details This interface will call the overloading LockMosResource for MOS. 1170 //! 1171 //! \param [in] streamState 1172 //! Handle of Os Stream State 1173 //! \param [in] resource 1174 //! MOS Resource handle of the resource to lock. 1175 //! \param [in] flags 1176 //! Control flags of locking resource. 1177 //! 1178 //! \return void * 1179 //! Locked memory data pointer, nullptr if lock failed. 1180 //! 1181 static void *LockMosResource( 1182 MOS_STREAM_HANDLE streamState, 1183 MOS_RESOURCE_HANDLE resource, 1184 PMOS_LOCK_PARAMS flags); 1185 //! 1186 //! \brief Lock Resource 1187 //! \details [Resource Interface] Lock the gfx resource for CPU to access 1188 //! \details Caller: MOS only 1189 //! \details A sys memory ptr will be provided by this interface if executed successfully. 1190 //! \details The sys memory is mapped to the gfx memory inside MOS module. 1191 //! \details This interface is usually for driver to read/write data into a resource directly (without program HW cmd). 1192 //! \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. 1193 //! A resource already been locked cannot be locked again. 1194 //! This is a blocking call if the resource is used by the cmdbuffer which already submitted to an existing GPU context. 1195 //! Unless SkipResourceSync is called. This interface will make sure the sync of Lock. 1196 //! \details If the resource is compressed, gfx memory decompression will be triggered. 1197 //! 1198 //! \param [in] OsDeviceContext 1199 //! Os Device Context 1200 //! \param [in] resource 1201 //! MOS Resource handle of the resource to lock. 1202 //! \param [in] flags 1203 //! Control flags of locking resource. 1204 //! 1205 //! \return void * 1206 //! Locked memory data pointer, nullptr if lock failed. 1207 //! 1208 static void *LockMosResource( 1209 OsDeviceContext *osDeviceContext, 1210 MOS_RESOURCE_HANDLE resource, 1211 PMOS_LOCK_PARAMS flags, 1212 bool isDumpPacket=0); 1213 1214 //! 1215 //! \brief Unlock Resource 1216 //! \details [Resource Interface] Unlock the gfx resource which is locked out. 1217 //! \details Caller: HAL only 1218 //! \details UnlockResource must be called when finished access the locked data of the resource. 1219 //! A resource already been unlocked cannot be unlocked again. 1220 //! \details Unlock resource will not trigger compressing or changing the layout of the resource. 1221 //! \details This interface will call the overloading UnlockMosResource for MOS. 1222 //! 1223 //! \param [in] streamState 1224 //! Handle of Os Stream State 1225 //! \param [in] resource 1226 //! MOS Resource handle of the allocated resource. 1227 //! 1228 //! \return MOS_STATUS 1229 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1230 //! 1231 static MOS_STATUS UnlockMosResource( 1232 MOS_STREAM_HANDLE streamState, 1233 MOS_RESOURCE_HANDLE resource); 1234 //! 1235 //! \brief Unlock Resource 1236 //! \details [Resource Interface] Unlock the gfx resource which is locked out. 1237 //! \details Caller: MOS only 1238 //! \details UnlockResource must be called when finished access the locked data of the resource. 1239 //! A resource already been unlocked cannot be unlocked again. 1240 //! \details Unlock resource will not trigger compressing or changing the layout of the resource. 1241 //! 1242 //! \param [in] OsDeviceContext 1243 //! Os Device Context 1244 //! \param [in] resource 1245 //! MOS Resource handle of the allocated resource. 1246 //! 1247 //! \return MOS_STATUS 1248 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1249 //! 1250 static MOS_STATUS UnlockMosResource( 1251 OsDeviceContext *osDeviceContext, 1252 MOS_RESOURCE_HANDLE resource); 1253 //! 1254 //! \brief Update resource usage type 1255 //! \details update the resource usage for cache policy 1256 //! \param PMOS_RESOURCE pOsResource 1257 //! [in/out] Pointer to OS Resource 1258 //! \param MOS_HW_RESOURCE_DEF resUsageType 1259 //! [in] MOS resosuce usage type 1260 //! \return MOS_STATUS 1261 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1262 //! 1263 static MOS_STATUS UpdateResourceUsageType( 1264 PMOS_RESOURCE pOsResource, 1265 MOS_HW_RESOURCE_DEF resUsageType); 1266 1267 //! 1268 //! \brief Register Resource 1269 //! \details [Resource Interface] Register the resource to current streamState. 1270 //! \details Caller: MHW only 1271 //! \details Register resource to inform MOS that the resource is read/written by current cmd buffer being programmed 1272 //! and this cmd buffer will be submitted into current GPU context in streamState. 1273 //! \details RegisterResource must be called when cmds in cmd buffer programmed are using this resource. 1274 //! \details This interface is to make the residency of the resource and handle resource sync harzad between GPU contexts. 1275 //! \details Calling sequence is like: SetGpuContext -> RegisterResource... -> SubmitCommandBuffer -> 1276 //! SetGpuContext(another) -> RegisterResource(another or same resource)... -> SubmitCommandBuffer 1277 //! \details If Register same resource to different GPU context when calling SetGpuContext, sync harzad will be handled. 1278 //! RegisterResource for the same resource can be called repeatedly. MOS will make sure no duplicated residency making and sync. 1279 //! 1280 //! \param [in] streamState 1281 //! Handle of Os Stream State 1282 //! \param [out] resource 1283 //! MOS Resource handle of the allocated resource. 1284 //! \param [in] write 1285 //! Indicate if the resource is written by HW or just read. 1286 //! 1287 //! \return MOS_STATUS 1288 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1289 //! 1290 static MOS_STATUS RegisterResource( 1291 MOS_STREAM_HANDLE streamState, 1292 MOS_RESOURCE_HANDLE resource, 1293 bool write); 1294 1295 //! 1296 //! \brief Get Resource Gfx Address 1297 //! \details [Resource Interface] Get the graphic virtual address of the resource. 1298 //! \details Caller: MHW only 1299 //! \details Only use this interface to add resource's address directly into cmd field. 1300 //! If MHW needs patch the address in the cmd field, GetResourceAllocationIndex should be called. 1301 //! 1302 //! \param [in] streamState 1303 //! Handle of Os Stream State 1304 //! \param [in] resource 1305 //! MOS Resource handle of the allocated resource. 1306 //! 1307 //! \return uint64_t 1308 //! 64bit virtual graphic address got. 0x00000000 if execution failed. 1309 //! 1310 static uint64_t GetResourceGfxAddress( 1311 MOS_STREAM_HANDLE streamState, 1312 MOS_RESOURCE_HANDLE resource); 1313 1314 //! 1315 //! \brief Get Resource Allocation Handle 1316 //! \details [Resource Interface] Get the allocation handle of a graphic resource. 1317 //! \details Caller: MHW Only 1318 //! \details This interface gets the read-only detailed info of a graphic resource. 1319 //! Any modification of details provided by this interface will not impact the actual resource. 1320 //! 1321 //! \param [in] resource 1322 //! MOS Resource handle of the allocated resource. 1323 //! 1324 //! \return uint32_t 1325 //! Allocation Handle. 0 if execution failed. 1326 //! 1327 static uint32_t GetResourceAllocationHandle( 1328 MOS_RESOURCE_HANDLE resource); 1329 1330 //! 1331 //! \brief Get Resource Allocation index 1332 //! \details [Resource Interface] Get the allocation index of the resource. 1333 //! \details Caller: MHW only 1334 //! \details Allocation index is used when calling SetPatchEntry to add resource into cmd. 1335 //! If MHW needs patch the address in the cmd field, GetResourceAllocationIndex should be called. 1336 //! 1337 //! \param [in] streamState 1338 //! Handle of Os Stream State 1339 //! \param [in] resource 1340 //! MOS Resource handle of the allocated resource. 1341 //! 1342 //! \return uint32_t 1343 //! Allocation index got. 0 if execution failed. 1344 //! 1345 static uint32_t GetResourceAllocationIndex( 1346 MOS_STREAM_HANDLE streamState, 1347 MOS_RESOURCE_HANDLE resource); 1348 1349 //! 1350 //! \brief Skip Resource Sync 1351 //! \details [Resource Interface] Skip the sync handling of the resource 1352 //! \details Caller: HAL only 1353 //! \details It is not device stated function and can be used in both APO HAL and NON-APO MOS. 1354 //! \details Indicate the resource provided needn't to be synced. 1355 //! The resource skipping sync can be accessed by different cmd buffers on different GPU contexts at the same time. 1356 //! \details RegisterResource and LockResource will not handling the sync of the resources between different GPU cotnexts. 1357 //! \details Usually the resource skipping sync is for the case like: 1358 //! Different cmd buffers at the same time access the non-overlapped region of the resource 1359 //! 1360 //! \param [in] streamState 1361 //! Handle of Os Stream State 1362 //! \param [in] params 1363 //! Pointer to the parameters for allocating resource 1364 //! \param [out] resource 1365 //! MOS Resource handle of the allocated resource. 1366 //! 1367 //! \return MOS_STATUS 1368 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1369 //! 1370 static MOS_STATUS SkipResourceSync( 1371 MOS_RESOURCE_HANDLE resource); 1372 1373 //! 1374 //! \brief Sync on resource 1375 //! \details [Resource Interface] Explicit sync on resource 1376 //! \details Caller: HAL only 1377 //! \details Resource is shared by different cmd buffers on different GPU contexts. 1378 //! Adding sync object into requestor GPU context queue to resolve the hazard if necessary. 1379 //! This func is called by hal to declare the resource to consider the sync explicitly. 1380 //! It is a strong sync request for the resource. 1381 //! 1382 //! \param [in] streamState 1383 //! Handle of Os Stream State 1384 //! \param [in] resource 1385 //! MOS Resource handle for the resource contain hazard of sync 1386 //! \param [in] writeOperation 1387 //! Indicate the current programming is to write resource or not 1388 //! \param [in] requsetorGpuContext 1389 //! GpuContext which programming the resource. Recommand not setting it and use current GPU context. 1390 //! 1391 //! \return MOS_STATUS 1392 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1393 //! 1394 static MOS_STATUS SyncOnResource( 1395 MOS_STREAM_HANDLE streamState, 1396 MOS_RESOURCE_HANDLE resource, 1397 bool writeOperation, 1398 GPU_CONTEXT_HANDLE requsetorGpuContext = MOS_GPU_CONTEXT_INVALID_HANDLE); 1399 1400 //! 1401 //! \brief Resource Sync call back between Media and 3D for resource Sync 1402 //! \details [Resource Interface] Sync Call Back based on resource 1403 //! \details Caller: DDI only 1404 //! \details Resource is shared by different cmd buffers on different GPU contexts. 1405 //! Adding sync object into requestor GPU context queue to resolve the hazard if necessary. 1406 //! If there is a hazard, one cmd buffer in requestor GPU context queue will wait for the other cmd buffer in busy GPU context. 1407 //! 1408 //! \param [in] resource 1409 //! OS specific resource handle for the resource contain hazard of sync 1410 //! \param [in] deviceContext 1411 //! Handle of Os Device Context 1412 //! \param [in] index 1413 //! Sub-resource index 1414 //! \param [in] hazardType 1415 //! Type of hazard: RAW, WAR, WAR 1416 //! \param [in] busyCtx 1417 //! GPU Context handle of the queue being waiting for. 1418 //! \param [in] requestorCtx 1419 //! GPU Context handle of current GPU which requesting to use the resoure and find the hazard to wait the busy context. 1420 //! \param [in] osRequestorHandle 1421 //! OS runtime handle of requestor context 1422 //! \param [in,out] fenceInfoTrinity 1423 //! if need to sync, it is fence handle and fence value 1424 //! 1425 //! \return MOS_STATUS 1426 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1427 //! 1428 static MOS_STATUS ResourceSyncCallback( 1429 OsSpecificRes resource, 1430 MOS_DEVICE_HANDLE deviceContext, 1431 uint32_t index, 1432 SYNC_HAZARD hazardType, 1433 GPU_CONTEXT_HANDLE busyCtx, 1434 GPU_CONTEXT_HANDLE requestorCtx, 1435 OS_HANDLE osRequestorHandle, 1436 SYNC_FENCE_INFO_TRINITY *fenceInfoTrinity); 1437 1438 //! 1439 //! \brief Lock Sync Callback between Media and 3D 1440 //! \details [Resource Interface] Lock Sync Call Back 1441 //! \details Caller: DDI only 1442 //! \details Resource is used in a cmd buffer on an existing GPU context. 1443 //! Before Locking the resource, make sure the resource finished used by all GPU contexts which are using this resource. 1444 //! If there is a hazard, CPU side will wait for the cmd buffer in busy GPU context. 1445 //! 1446 //! \param [in] resource 1447 //! OS specific resource handle for the resource contain hazard of sync 1448 //! \param [in] deviceContext 1449 //! Handle of Os Device Context 1450 //! \param [in] index 1451 //! Sub-resource index 1452 //! \param [in] hazardType 1453 //! Type of hazard: RAW, WAR, WAR 1454 //! \param [in] busyCtx 1455 //! GPU Context handle of the queue being waiting for. 1456 //! \param [in] doNotWait 1457 //! Indicate this is blocking call or not. When set to true, possibly return MOS_STATUS_STILL_DRAWING 1458 //! 1459 //! \return MOS_STATUS 1460 //! Return MOS_STATUS_SUCCESS if successful, MOS_STATUS_STILL_DRAWING if doNotWait 1461 //! is set to true and resoure is still being used in HW, otherwise failed 1462 //! 1463 static MOS_STATUS LockSyncCallback( 1464 OsSpecificRes resource, 1465 MOS_DEVICE_HANDLE deviceContext, 1466 uint32_t index, 1467 SYNC_HAZARD hazardType, 1468 GPU_CONTEXT_HANDLE busyCtx, 1469 bool doNotWait); 1470 1471 //! 1472 //! \brief Wait For cmd Completion 1473 //! \details [GPU Context Interface] Waiting for the completion of cmd in provided GPU context 1474 //! \details Caller: HAL only 1475 //! 1476 //! \param [in] streamState 1477 //! Handle of Os Stream State 1478 //! \param [in] gpuCtx 1479 //! GpuContext handle of the gpu context to wait cmd completion 1480 //! 1481 //! \return MOS_STATUS 1482 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1483 //! 1484 static MOS_STATUS WaitForCmdCompletion( 1485 MOS_STREAM_HANDLE streamState, 1486 GPU_CONTEXT_HANDLE gpuCtx); 1487 1488 //! 1489 //! \brief Trim Residency 1490 //! 1491 //! \param [in] device 1492 //! MOS device handle 1493 //! \param [in] periodicTrim 1494 //! Indicate if the trim is periodic 1495 //! \param [in] restartPeriodicTrim 1496 //! Indicate if restarting periodic trim 1497 //! \param [in] numBytesToTrim 1498 //! Number bytes to trim 1499 //! \param [in] trimToMinimum 1500 //! Indicate if trim to minimum 1501 //! \param [in] trimOnlyMediaResources 1502 //! Indicate if only trim media resources. 1503 //! 1504 //! \return MOS_STATUS 1505 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1506 //! 1507 static MOS_STATUS TrimResidency( 1508 MOS_DEVICE_HANDLE device, 1509 bool periodicTrim, 1510 bool restartPeriodicTrim, 1511 uint64_t &numBytesToTrim, 1512 bool trimToMinimum, 1513 bool trimOnlyMediaResources); 1514 1515 //! 1516 //! \brief Update Residency 1517 //! 1518 //! \param [in] device 1519 //! MOS device handle 1520 //! \param [in] resInfo 1521 //! Os specific resource info 1522 //! \param [in] index 1523 //! Resource index 1524 //! 1525 //! \return MOS_STATUS 1526 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1527 //! 1528 static MOS_STATUS UpdateResidency( 1529 MOS_DEVICE_HANDLE device, 1530 OsSpecificRes resInfo, 1531 uint32_t index, 1532 bool bypassAuxTableUpdate = false); 1533 1534 1535 // Memory compression interfaces 1536 1537 //! 1538 //! \brief Decompress resource 1539 //! 1540 //! \param [in] streamState 1541 //! Handle of Os Stream State 1542 //! \param [in] resource 1543 //! MOS Resource handle of the resource to decompress. 1544 //! \return MOS_STATUS 1545 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1546 //! 1547 static MOS_STATUS DecompResource( 1548 MOS_STREAM_HANDLE streamState, 1549 MOS_RESOURCE_HANDLE resource); 1550 1551 //! 1552 //! \brief Decompress resource 1553 //! 1554 //! \param [in] streamState 1555 //! Handle of Os Stream State 1556 //! \param [out] mosDecompression 1557 //! MosDecompression in stramStatate or in osDeviceContext. 1558 //! \return MOS_STATUS 1559 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1560 //! 1561 static MOS_STATUS GetMosDecompressionFromStreamState( 1562 MOS_STREAM_HANDLE streamState, 1563 MosDecompression* & mosDecompression); 1564 1565 //! 1566 //! \brief Set auxiliary resource to sync with decompression 1567 //! 1568 //! \param [in] streamState 1569 //! Handle of Os Stream State 1570 //! \param [in] resource 1571 //! MOS Resource handle of the resource. 1572 //! \return MOS_STATUS 1573 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1574 //! 1575 static MOS_STATUS SetDecompSyncRes( 1576 MOS_STREAM_HANDLE streamState, 1577 MOS_RESOURCE_HANDLE syncResource); 1578 1579 //! 1580 //! \brief Set Memory Compression Mode 1581 //! 1582 //! \param [in] streamState 1583 //! Handle of Os Stream State 1584 //! \param [in, out] resource 1585 //! MOS Resource handle 1586 //! \param [in] resMmcMode 1587 //! MMC mode 1588 //! 1589 //! \return MOS_STATUS 1590 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1591 //! 1592 static MOS_STATUS SetMemoryCompressionMode( 1593 MOS_STREAM_HANDLE streamState, 1594 MOS_RESOURCE_HANDLE resource, 1595 MOS_MEMCOMP_STATE resMmcMode); 1596 1597 //! 1598 //! \brief Get Memory Compression Mode 1599 //! 1600 //! \param [in] streamState 1601 //! Handle of Os Stream State 1602 //! \param [in] resource 1603 //! MOS Resource handle 1604 //! \param [out] resMmcMode 1605 //! MMC mode 1606 //! 1607 //! \return MOS_STATUS 1608 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1609 //! 1610 static MOS_STATUS GetMemoryCompressionMode( 1611 MOS_STREAM_HANDLE streamState, 1612 MOS_RESOURCE_HANDLE resource, 1613 MOS_MEMCOMP_STATE &resMmcMode); 1614 1615 //! 1616 //! \brief Set Memory Compression Hint 1617 //! 1618 //! \param [in] streamState 1619 //! Handle of Os Stream State 1620 //! \param [in, out] resource 1621 //! MOS Resource handle 1622 //! \param [in] hintOn 1623 //! Flag to set hint on or off 1624 //! 1625 //! \return MOS_STATUS 1626 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1627 //! 1628 static MOS_STATUS SetMemoryCompressionHint( 1629 MOS_STREAM_HANDLE streamState, 1630 MOS_RESOURCE_HANDLE resource, 1631 bool hintOn); 1632 1633 //! 1634 //! \brief Get Memory Compression Format 1635 //! 1636 //! \param [in] streamState 1637 //! Handle of Os Stream State 1638 //! \param [in, out] resource 1639 //! MOS Resource handle 1640 //! \param [out] resMmcFormat 1641 //! MMC format got 1642 //! 1643 //! \return MOS_STATUS 1644 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1645 //! 1646 static MOS_STATUS GetMemoryCompressionFormat( 1647 MOS_STREAM_HANDLE streamState, 1648 MOS_RESOURCE_HANDLE resource, 1649 uint32_t *resMmcFormat); 1650 1651 //! 1652 //! \brief Double buffer copy resource 1653 //! 1654 //! \param [in] streamState 1655 //! Handle of Os Stream State 1656 //! \param [in] inputResource 1657 //! Input resource to copy. 1658 //! \param [out] outputResource 1659 //! Output resource. 1660 //! \param [in] outputCompressed 1661 //! Insdicate if output resource is compressed. 1662 //! \return MOS_STATUS 1663 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1664 //! 1665 static MOS_STATUS DoubleBufferCopyResource( 1666 MOS_STREAM_HANDLE streamState, 1667 MOS_RESOURCE_HANDLE inputResource, 1668 MOS_RESOURCE_HANDLE outputResource, 1669 bool outputCompressed); 1670 1671 //! 1672 //! \brief Use media copy to copy resource 1673 //! 1674 //! \param [in] streamState 1675 //! Handle of Os Stream State 1676 //! \param [in] inputResource 1677 //! Source resource. 1678 //! \param [out] outputResource 1679 //! Destination resource. 1680 //! \param [in] preferMethod 1681 //! Preferred copy engine. 1682 //! \return MOS_STATUS 1683 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1684 //! 1685 static MOS_STATUS UnifiedMediaCopyResource( 1686 MOS_STREAM_HANDLE streamState, 1687 MOS_RESOURCE_HANDLE inputResource, 1688 MOS_RESOURCE_HANDLE outputResource, 1689 int preferMethod); 1690 1691 //! 1692 //! \brief Copy Resource to Another Buffer 1693 //! \details Decompress and Copy Resource to Another 2D Buffer 1694 //! 1695 //! \param [in] streamState 1696 //! Handle of Os Stream State 1697 //! \param inputResource 1698 //! [in] Input Resource object 1699 //! \param outputResource 1700 //! [out] output Resource object 1701 //! \param [in] copyPitch 1702 //! The 2D surface pitch 1703 //! \param [in] copyHeight 1704 //! The 2D surface height 1705 //! \param [in] copyInputOffset 1706 //! The offset of copied surface from 1707 //! \param [in] copyOutputOffset 1708 //! The offset of copied to 1709 //! \param [in] outputCompressed 1710 //! True means apply compression on output surface, else output uncompressed surface 1711 //! \return MOS_STATUS 1712 //! MOS_STATUS_SUCCESS if successful 1713 //! 1714 static MOS_STATUS MediaCopyResource2D( 1715 MOS_STREAM_HANDLE streamState, 1716 MOS_RESOURCE_HANDLE inputResource, 1717 MOS_RESOURCE_HANDLE outputResource, 1718 uint32_t copyPitch, 1719 uint32_t copyHeight, 1720 uint32_t bpp, 1721 bool outputCompressed); 1722 1723 //! 1724 //! \brief Copy Mono Resource to Another Buffer 1725 //! \details Decompress and Copy Mono Resource to Another 2D Buffer 1726 //! 1727 //! \param [in] streamState 1728 //! Handle of Os Stream State 1729 //! \param inputResource 1730 //! [in] Input Resource object 1731 //! \param outputResource 1732 //! [out] output Resource object 1733 //! \param [in] copyWidth 1734 //! The 2D surface Width 1735 //! \param [in] copyHeight 1736 //! The 2D surface height 1737 //! \param [in] copyInputOffset 1738 //! The offset of copied surface from 1739 //! \param [in] copyOutputOffset 1740 //! The offset of copied to 1741 //! \param [in] outputCompressed 1742 //! True means apply compression on output surface, else output uncompressed surface 1743 //! \return MOS_STATUS 1744 //! MOS_STATUS_SUCCESS if successful 1745 //! 1746 static MOS_STATUS MonoSurfaceCopy( 1747 MOS_STREAM_HANDLE streamState, 1748 MOS_RESOURCE_HANDLE inputResource, 1749 MOS_RESOURCE_HANDLE outputResource, 1750 uint32_t copyPitch, 1751 uint32_t copyHeight, 1752 uint32_t copyInputOffset, 1753 uint32_t copyOutputOffset, 1754 bool outputCompressed); 1755 1756 //! 1757 //! \brief Check whether the parameter of mos surface is valid for copy 1758 //! 1759 //! \param [in] mosSurface 1760 //! Pointer to MosSurface 1761 //! 1762 //! \return bool 1763 //! Whether the paramter of mosSurface is valid 1764 //! 1765 static MOS_STATUS VerifyMosSurface( 1766 PMOS_SURFACE mosSurface, 1767 bool &bIsValid); 1768 1769 // GPU Status interfaces 1770 //! 1771 //! \brief Get Gpu Status Tag 1772 //! 1773 //! \param [in] streamState 1774 //! Handle of Os Stream State 1775 //! \param [in] gpuContext 1776 //! MOS GPU Context handle 1777 //! 1778 //! \return uint32_t 1779 //! Tag got from GPU Context indicated, 0 if failed to get the tag 1780 //! 1781 static uint32_t GetGpuStatusTag( 1782 MOS_STREAM_HANDLE streamState, 1783 GPU_CONTEXT_HANDLE gpuContext); 1784 1785 //! 1786 //! \brief Increment Gpu Status Tag 1787 //! 1788 //! \param [in] streamState 1789 //! Handle of Os Stream State 1790 //! \param [in] gpuContext 1791 //! MOS GPU Context handle 1792 //! 1793 //! \return MOS_STATUS 1794 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1795 //! 1796 static MOS_STATUS IncrementGpuStatusTag( 1797 MOS_STREAM_HANDLE streamState, 1798 GPU_CONTEXT_HANDLE gpuContext); 1799 1800 //! 1801 //! \brief Get Gpu Status Sync Tag 1802 //! 1803 //! \param [in] streamState 1804 //! Handle of Os Stream State 1805 //! \param [in] gpuContext 1806 //! MOS GPU Context handle 1807 //! 1808 //! \return uint64_t 1809 //! HW tag got from GPU context, 0 if get failed 1810 //! 1811 static uint64_t GetGpuStatusSyncTag( 1812 MOS_STREAM_HANDLE streamState, 1813 GPU_CONTEXT_HANDLE gpuContext); 1814 1815 //! 1816 //! \brief Get Gpu Status Buffer Resource 1817 //! 1818 //! \param [in] streamState 1819 //! Handle of Os Stream State 1820 //! \param [out] resource 1821 //! MOS resource handle of GPU status buffer got from current GPU context 1822 //! \param [in] gpuContext 1823 //! MOS GPU Context handle 1824 //! 1825 //! \return MOS_STATUS 1826 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1827 //! 1828 1829 static MOS_STATUS GetGpuStatusBufferResource( 1830 MOS_STREAM_HANDLE streamState, 1831 MOS_RESOURCE_HANDLE &resource, 1832 GPU_CONTEXT_HANDLE gpuContext); 1833 1834 //! 1835 //! \brief Get CP Interface 1836 //! 1837 //! \param [in] streamState 1838 //! Handle of Os Stream State 1839 //! 1840 //! \return MosCpInterface 1841 //! CP Interface got from stream State, nullptr if get failed 1842 //! 1843 static MosCpInterface *GetCpInterface(MOS_STREAM_HANDLE streamState); 1844 1845 //! 1846 //! \brief Maps the specified executable module into the address space of 1847 //! the calling process. 1848 //! \param PMOS_INTERFACE pOsInterface 1849 //! [in] A handle to OS interface. This can be nullptr which allows a caller to 1850 //! always get library from specified library path (function will never check 1851 //! driver store) which is useful if there's a constant static path of a library 1852 //! \param const PCCHAR lpLibFileName 1853 //! [in] String containing resource name to load. Absolute path is given here 1854 //! if pOsInterface is nullptr, else only lib path is given, and driver will check store for path 1855 //! \param PHMODULE phModule 1856 //! [out] Handle to library given back to the caller 1857 //! \return MOS_STATUS 1858 //! Returns one of the MOS_STATUS error codes if failed, 1859 //! else MOS_STATUS_SUCCESS 1860 //! 1861 static MOS_STATUS MosLoadLibrary( 1862 MOS_STREAM_HANDLE streamState, 1863 PCCHAR pFileName, 1864 PHMODULE phModule); 1865 1866 //! 1867 //! \brief Free the loaded dynamic-link library 1868 //! \details Free the loaded dynamic-link library 1869 //! \param [in] hLibModule 1870 //! A handle to the loaded DLL module 1871 //! \return int32_t 1872 //! true if success else false 1873 //! 1874 static MOS_STATUS MosFreeLibrary(HMODULE hLibModule); 1875 1876 //! \brief Get Virtual Engine State 1877 //! \details [Virtual Engine Interface] Get Virtual Engine State from streamState 1878 //! \details Caller: Hal (Scalability) only 1879 //! \details This func is called when a stream (Hal instance) need to get a VE state 1880 //! \details corresponding to current GPU context. 1881 //! 1882 //! \param [in] streamState 1883 //! Handle of Os Stream State 1884 //! 1885 //! \return MOS_VE_HANDLE 1886 //! Handle of MOS virtual engine state, Invalid handle if get failed 1887 //! 1888 static MOS_VE_HANDLE GetVirtualEngineState( 1889 MOS_STREAM_HANDLE streamState); 1890 1891 //! 1892 //! \brief Set Virtual Engine State 1893 //! \details [Virtual Engine Interface] Set Virtual Engine State of provided streamState 1894 //! \details Caller: Hal (Scalability) only 1895 //! \details This func is called when a stream (Hal instance) need to set an existing VE state 1896 //! \details into provided stream. 1897 //! 1898 //! \param [in] streamState 1899 //! Handle of Os Stream State 1900 //! \param [in] veState 1901 //! Handle of Virtual Engine State to set 1902 //! 1903 //! \return MOS_STATUS 1904 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1905 //! 1906 static MOS_STATUS SetVirtualEngineState( 1907 MOS_STREAM_HANDLE streamState, 1908 MOS_VE_HANDLE veState); 1909 1910 //! 1911 //! \brief Create Virtual Engine State 1912 //! \details [Virtual Engine Interface] Create Virtual Engine State of provided streamState 1913 //! \details Caller: Hal (Scalability) only 1914 //! \details This func is called when a stream (Hal instance) need to create a VE state 1915 //! \details into provided stream. 1916 //! 1917 //! \param [in] streamState 1918 //! Handle of Os Stream State 1919 //! \param [in] veInitParms 1920 //! Pointer of parameters to init ve staet 1921 //! \param [out] veState 1922 //! Reference of the handle of Virtual Engine State to created 1923 //! 1924 //! \return MOS_STATUS 1925 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1926 //! 1927 static MOS_STATUS CreateVirtualEngineState( 1928 MOS_STREAM_HANDLE streamState, 1929 PMOS_VIRTUALENGINE_INIT_PARAMS veInitParms, 1930 MOS_VE_HANDLE &veState); 1931 1932 //! 1933 //! \brief Destroy Virtual Engine State 1934 //! \details [Virtual Engine Interface] Destroy Virtual Engine State of provided streamState 1935 //! \details Caller: Hal (Scalability) only 1936 //! \details This func is called when a stream (Hal instance) need to destroy a VE state 1937 //! \details into provided stream. 1938 //! 1939 //! \param [in] streamState 1940 //! Handle of Os Stream State 1941 //! \param [out] veState 1942 //! Reference of the handle of Virtual Engine State to created 1943 //! 1944 //! \return MOS_STATUS 1945 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 1946 //! 1947 static MOS_STATUS DestroyVirtualEngineState( 1948 MOS_STREAM_HANDLE streamState); 1949 1950 //! 1951 //! \brief Set hint parameters 1952 //! 1953 //! \details [Virtual Engine Interface] Set hint parameters into Virtual Engine State in provided stream 1954 //! \details Caller: Hal (Scalability) only 1955 //! \details Set hint parameters for virtual engine state 1956 //! 1957 //! \param [in] streamState 1958 //! Handle of Os Stream State 1959 //! \param [in] veParams 1960 //! pointer to VE parameter data structure to set 1961 //! \return MOS_STATUS 1962 //! MOS_STATUS_SUCCESS if success, else fail reason 1963 //! 1964 static MOS_STATUS SetVeHintParams( 1965 MOS_STREAM_HANDLE streamState, 1966 PMOS_VIRTUALENGINE_SET_PARAMS veParams); 1967 1968 //! 1969 //! \brief Get hint parameters 1970 //! 1971 //! \details [Virtual Engine Interface] Get hint parameters from Virtual Engine State in provided stream 1972 //! \details Caller: Hal (Scalability) only 1973 //! \details Get hint parameters from virtual engine state 1974 //! 1975 //! \param [in] streamState 1976 //! Handle of Os Stream State 1977 //! \param [in] scalableMode 1978 //! flag to indicate if scalability mode 1979 //! \param [out] hintParams 1980 //! pointer to VE hint parameter address 1981 //! \return MOS_STATUS 1982 //! MOS_STATUS_SUCCESS if success, else fail reason 1983 //! 1984 static MOS_STATUS GetVeHintParams( 1985 MOS_STREAM_HANDLE streamState, 1986 bool scalableMode, 1987 PMOS_VIRTUALENGINE_HINT_PARAMS *hintParams); 1988 1989 //! 1990 //! \brief Set Virtual Engine Submission Type 1991 //! 1992 //! \details [Virtual Engine Interface] Set submission type for the provided cmd buffer 1993 //! \details Caller: Hal (Scalability) only 1994 //! \details Set submission type as per cmd buffer hint parameter. Must be set before submission. 1995 //! Submission type is to set cmd buffer (primary or secondary) property to indicate 1996 //! which pipe it belongs. See MOS_SUBMISSION_TYPE. 1997 //! 1998 //! \param [in] streamState 1999 //! Handle of Os Stream State 2000 //! \param [out] cmdBuf 2001 //! Handle of cmd buffer to set submission type 2002 //! \param [in] type 2003 //! Submission type to set 2004 //! \return MOS_STATUS 2005 //! MOS_STATUS_SUCCESS if success, else fail reason 2006 //! 2007 static MOS_STATUS SetVeSubmissionType( 2008 MOS_STREAM_HANDLE streamState, 2009 COMMAND_BUFFER_HANDLE cmdBuf, 2010 MOS_SUBMISSION_TYPE type); 2011 2012 //! 2013 //! \brief Get Adapter BDF 2014 //! \details [System info Interface] Get Adapter BDF 2015 //! \details Caller: DDI & HAL 2016 //! \details This func is called to differentiate the behavior according to Adapter BDF. 2017 //! 2018 //! \param [in] mosCtx 2019 //! Pointer of Mos context 2020 //! \param [out] adapterBDF 2021 //! Adapter BDF info 2022 //! 2023 //! \return MOS_STATUS 2024 //! MOS_STATUS_SUCCESS if success, else fail reason 2025 //! 2026 static MOS_STATUS GetAdapterBDF(PMOS_CONTEXT mosCtx, ADAPTER_BDF *adapterBDF); 2027 2028 #if _DEBUG || _RELEASE_INTERNAL 2029 //! 2030 //! \brief Get engine count 2031 //! 2032 //! \details [Virtual Engine Interface] Get engine count from Virtual Engine State in provided stream 2033 //! \details Caller: Hal (Scalability) only 2034 //! \details Get engine count from virtual engine state 2035 //! 2036 //! \param [in] streamState 2037 //! Handle of Os Stream State 2038 //! \return uint8_t 2039 //! Engine count 2040 //! 2041 static uint8_t GetVeEngineCount( 2042 MOS_STREAM_HANDLE streamState); 2043 2044 //! 2045 //! \brief Get Engine Logic Id 2046 //! \details [Virtual Engine Interface] Get engine Logic Id from Virtual Engine State in provided stream 2047 //! \details Caller: Hal (Scalability) only 2048 //! \details Get engine Logic Id from virtual engine state 2049 //! 2050 //! \param [in] streamState 2051 //! Handle of Os Stream State 2052 //! \param [in] instanceIdx 2053 //! Engine instance index 2054 //! \return uint8_t 2055 //! 2056 static uint8_t GetEngineLogicId( 2057 MOS_STREAM_HANDLE streamState, 2058 uint32_t instanceIdx); 2059 2060 //! 2061 //! \brief Set Gpu Virtual Address for Debug 2062 //! \details Manually make page fault 2063 //! 2064 //! \param [in] pResource 2065 //! Resource to set Gpu Address 2066 //! \param [in] address 2067 //! Address to set 2068 //! \return MOS_STATUS 2069 //! 2070 static MOS_STATUS SetGpuVirtualAddress( 2071 PMOS_RESOURCE pResource, 2072 uint64_t address); 2073 2074 #endif // _DEBUG || _RELEASE_INTERNAL 2075 2076 //! 2077 //! \brief Sets the perf tag 2078 //! \details Sets the perf tag 2079 //! \param [in] streamState 2080 //! Handle of Os Stream State 2081 //! \param uint32_t perfTag 2082 //! [in] Perf tag 2083 //! \return void 2084 //! 2085 static void SetPerfTag( 2086 MOS_STREAM_HANDLE streamState, 2087 uint32_t perfTag); 2088 2089 //! 2090 //! \brief Gets the perf tag 2091 //! \details Gets the perf tag 2092 //! \param [in] streamState 2093 //! Handle of Os Stream State 2094 //! \return uint32_t 2095 //! Return perf tag 2096 //! 2097 static uint32_t GetPerfTag( 2098 MOS_STREAM_HANDLE streamState); 2099 2100 //! 2101 //! \brief Check if Perf Tag is already set 2102 //! \details Check if Perf Tag is already set 2103 //! \param [in] streamState 2104 //! Handle of Os Stream State 2105 //! \return int32_t 2106 //! 2107 static int32_t IsPerfTagSet( 2108 MOS_STREAM_HANDLE streamState); 2109 2110 //! 2111 //! \brief Increase performance data frame ID 2112 //! \details Increase performance data frame ID 2113 //! \param [in] streamState 2114 //! Handle of Os Stream State 2115 //! \return void 2116 //! 2117 static void IncPerfFrameID( 2118 MOS_STREAM_HANDLE streamState); 2119 2120 //! 2121 //! \brief Set Hybrid Kernel ID 2122 //! \details Set Hybrid Kernel ID 2123 //! \param [in] streamState 2124 //! Handle of Os Stream State 2125 //! \param uint32_t kernelID 2126 //! [in] Hybrid Decoder kernel ID 2127 //! \return void 2128 //! 2129 static void SetPerfHybridKernelID( 2130 MOS_STREAM_HANDLE streamState, 2131 uint32_t kernelID); 2132 2133 //! 2134 //! \brief Reset performance data buffer ID 2135 //! \details Reset performance data buffer ID 2136 //! \param [in] streamState 2137 //! Handle of Os Stream State 2138 //! \return void 2139 //! 2140 static void ResetPerfBufferID( 2141 MOS_STREAM_HANDLE streamState); 2142 2143 //! 2144 //! \brief Increase performance data buffer ID 2145 //! \details Increase performance data buffer ID 2146 //! \param [in] streamState 2147 //! Handle of Os Stream State 2148 //! \return VOID 2149 //! 2150 static void IncPerfBufferID( 2151 MOS_STREAM_HANDLE streamState); 2152 2153 //! 2154 //! \brief Determines if the GPU Hung 2155 //! \param [in] streamState 2156 //! Handle of Os Stream State 2157 //! \return int32_t 2158 //! Return if the GPU Hung 2159 //! 2160 static int32_t IsGPUHung( 2161 MOS_STREAM_HANDLE streamState); 2162 2163 //! 2164 //! \brief Get SetMarker enabled flag 2165 //! \details Get SetMarker enabled flag from streamState 2166 //! \param [in] streamState 2167 //! Handle of Os Stream State 2168 //! \return bool 2169 //! SetMarker enabled flag 2170 //! 2171 static bool IsSetMarkerEnabled( 2172 MOS_STREAM_HANDLE streamState); 2173 2174 //! 2175 //! \brief Get SetMarker resource address 2176 //! \details Get SetMarker resource address from streamState 2177 //! \param [in] streamState 2178 //! Handle of Os Stream State 2179 //! \return PMOS_RESOURCE 2180 //! SetMarker resource address 2181 //! 2182 static PMOS_RESOURCE GetMarkerResource( 2183 MOS_STREAM_HANDLE streamState); 2184 2185 //! 2186 //! \brief Check if OS resource is nullptr 2187 //! \details Check if OS resource is nullptr 2188 //! \param PMOS_RESOURCE pOsResource 2189 //! [in] Pointer to OS Resource 2190 //! \return int32_t 2191 //! Return true if nullptr, otherwise false 2192 //! 2193 static bool MosResourceIsNull(PMOS_RESOURCE resource); 2194 2195 //! 2196 //! \brief OS reset resource 2197 //! \details Resets the OS resource 2198 //! \param PMOS_RESOURCE pOsResource 2199 //! [in] Pointer to OS Resource 2200 //! \return void 2201 //! Return NONE 2202 //! 2203 static void MosResetResource(PMOS_RESOURCE resource); 2204 2205 //! 2206 //! \brief Get Gmm Resource Info 2207 //! \details Get Gmm Resource Info 2208 //! \param PMOS_RESOURCE resource 2209 //! [in/out] pointer to OS resource 2210 //! \return MOS_STATUS 2211 //! MOS_STATUS_SUCCESS if successful 2212 //! 2213 static MOS_STATUS GetGmmResourceInfo(PMOS_RESOURCE resource); 2214 2215 //! 2216 //! \brief Get plane offset inside surface 2217 //! \details Returns the offset 2218 //! \param MOS_PLANE_OFFSET planeOffset 2219 //! [in] Reference to MOS_PLANE_OFFSET structure 2220 //! \return int - offset of the plane 2221 //! 2222 static int GetPlaneSurfaceOffset( 2223 const MOS_PLANE_OFFSET &planeOffset); 2224 2225 //! 2226 //! \brief Get Resource array index 2227 //! \details Returns the array index 2228 //! \param PMOS_RESOURCE 2229 //! [in] Pointer to MOS_RESOURCE 2230 //! \return uint32_t - array index 2231 //! 2232 static uint32_t GetResourceArrayIndex( 2233 PMOS_RESOURCE resource); 2234 2235 //! 2236 //! \brief Translate MOS_FORMAT into GMM_RESOURCE_FORMAT 2237 //! 2238 static GMM_RESOURCE_FORMAT MosFmtToGmmFmt(MOS_FORMAT format); 2239 2240 //! 2241 //! \brief Translate GMM_RESOURCE_FORMAT into MOS_FORMAT 2242 //! 2243 static MOS_FORMAT GmmFmtToMosFmt(GMM_RESOURCE_FORMAT format); 2244 2245 //! 2246 //! \brief Translate MOS_FORMAT into MOS_OS_FORMAT 2247 //! 2248 static uint32_t MosFmtToOsFmt(MOS_FORMAT format); 2249 2250 //! 2251 //! \brief Translate MOS_OS_FORMT into MOS_FORMAT 2252 //! 2253 static MOS_FORMAT OsFmtToMosFmt(uint32_t format); 2254 2255 //! \brief Get usersetting instance for each stream 2256 //! \details the user setting instance 2257 //! \details call the overloading MosGetUserSettingInstance for osDeviceContext 2258 //! \param MOS_STREAM_HANDLE streamState 2259 //! [in] streamState 2260 //! \return MediaUserSettingSharedPtr - user setting instance 2261 //! 2262 static MediaUserSettingSharedPtr MosGetUserSettingInstance( 2263 MOS_STREAM_HANDLE streamState); 2264 2265 //! \brief Get usersetting instance for each stream 2266 //! \details the user setting instance 2267 //! \param OsDeviceContext osDeviceContext 2268 //! [in] osDeviceContext 2269 //! \return MediaUserSettingSharedPtr - user setting instance 2270 //! 2271 static MediaUserSettingSharedPtr MosGetUserSettingInstance( 2272 OsDeviceContext *osDeviceContext); 2273 2274 //! \brief Get usersetting instance for each stream 2275 //! \details the user setting instance 2276 //! \param PMOS_CONTEXT mosCtx 2277 //! [in] mosCtx 2278 //! \return MediaUserSettingSharedPtr - user setting instance 2279 //! 2280 static MediaUserSettingSharedPtr MosGetUserSettingInstance( 2281 PMOS_CONTEXT mosCtx); 2282 2283 //! 2284 //! \brief Translate MOS_OS_FORMT into MOS_FORMAT 2285 //! 2286 static bool IsCompressibelSurfaceSupported(MEDIA_FEATURE_TABLE *skuTable); 2287 2288 //! 2289 //! \brief Check if Mismatch Order Programming model is supported 2290 //! 2291 static bool IsMismatchOrderProgrammingSupported(); 2292 2293 //! 2294 //! \brief Translate GMM_TILE_TYPE to MOS_TILE_TYPE 2295 //! 2296 static MOS_TILE_TYPE MapTileType(GMM_RESOURCE_FLAG flags, GMM_TILE_TYPE type); 2297 2298 //! 2299 //! \brief Check if Multiple Codec Devices is in use 2300 //! 2301 static bool IsMultipleCodecDevicesInUse(PMOS_INTERFACE osInterface); 2302 2303 2304 static MOS_STATUS SetMultiEngineEnabled( 2305 PMOS_INTERFACE pOsInterface, 2306 MOS_COMPONENT component, 2307 bool enabled); 2308 2309 static MOS_STATUS GetMultiEngineStatus( 2310 PMOS_INTERFACE pOsInterface, 2311 PLATFORM *platform, 2312 MOS_COMPONENT component, 2313 bool &isMultiDevices, 2314 bool &isMultiEngine); 2315 2316 //! 2317 //! \brief get latest virtual node for encoder and decoder 2318 //! 2319 static MOS_GPU_NODE GetLatestVirtualNode(MOS_STREAM_HANDLE streamState, MOS_COMPONENT component); 2320 2321 //! 2322 //! \brief set latest virtual node for encoder and decoder 2323 //! 2324 static void SetLatestVirtualNode(MOS_STREAM_HANDLE streamState, MOS_GPU_NODE node); 2325 2326 //! 2327 //! \brief get virtual node for each decoder stream 2328 //! 2329 static MOS_GPU_NODE GetDecoderVirtualNodePerStream(MOS_STREAM_HANDLE streamState); 2330 2331 //! 2332 //! \brief set virtual node for each decoder stream 2333 //! 2334 static void SetDecoderVirtualNodePerStream(MOS_STREAM_HANDLE streamState, MOS_GPU_NODE node); 2335 2336 //! \brief Wait for the created Batch Buffer completion event 2337 //! \details Wait for the created Batch Buffer completion event, we will be 2338 //! woken up for every Batch Buffer completion or when TimeOut expires 2339 //! \param MOS_STREAM_HANDLE streamState 2340 //! [in] Pointer to streamState 2341 //! \param GPU_CONTEXT_HANDLE gpuContextHandle 2342 //! [in] gpuContextHandle 2343 //! \param uint32_t uiTimeOut 2344 //! [in] Wait until signaled or TimeOut ms 2345 //! \return MOS_STATUS 2346 //! Return MOS_STATUS_SUCCESS if success else failure reason 2347 //! 2348 static MOS_STATUS WaitForBBCompleteNotifyEvent( 2349 MOS_STREAM_HANDLE streamState, 2350 GPU_CONTEXT_HANDLE gpuContextHandle, 2351 uint32_t uiTimeOut); 2352 2353 //! 2354 //! \brief Register GPU Context with KMD BB Complete Event 2355 //! \details Register GPU Context with KMD BB Complete Event 2356 //! \param MOS_STREAM_HANDLE streamState 2357 //! [in] Pointer to streamState 2358 //! \param GPU_CONTEXT_HANDLE gpuContextHandle 2359 //! [in] GPU context handle 2360 //! \return MOS_STATUS 2361 //! MOS_STATUS_SUCCESS if success else fail reason 2362 //! 2363 static MOS_STATUS RegisterBBCompleteNotifyEvent( 2364 MOS_STREAM_HANDLE streamState, 2365 GPU_CONTEXT_HANDLE gpuContextHandle); 2366 2367 static void GetRtLogResourceInfo( 2368 PMOS_INTERFACE osInterface, 2369 PMOS_RESOURCE &osResource, 2370 uint32_t &size); 2371 2372 static bool IsPooledResource(MOS_STREAM_HANDLE streamState, PMOS_RESOURCE osResource); 2373 2374 static uint64_t GetResourceHandle(MOS_STREAM_HANDLE streamState, PMOS_RESOURCE osResource); 2375 2376 static void SetIsTrinityEnabled(bool bTrinity); 2377 2378 private: 2379 //! 2380 //! \brief Init per stream parameters 2381 //! \details Init per stream parameters 2382 //! 2383 //! \param [in] streamState 2384 //! Handle of Os Stream State 2385 //! \param [in] extraParams 2386 //! Additional parameters needed to init streamstate 2387 //! 2388 //! \return MOS_STATUS 2389 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 2390 //! 2391 static MOS_STATUS InitStreamParameters( 2392 MOS_STREAM_HANDLE streamState, 2393 EXTRA_PARAMS extraParams = nullptr); 2394 2395 //! 2396 //! \brief Compose Cmd buffer header 2397 //! \details Compose Cmd buffer header if it contains header 2398 //! 2399 //! \param [in] streamState 2400 //! Handle of Os Stream State 2401 //! \param [out] cmdBuffer 2402 //! Cmd buffer to compose header. 2403 //! 2404 //! \return MOS_STATUS 2405 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 2406 //! 2407 static MOS_STATUS ComposeCommandBufferHeader( 2408 MOS_STREAM_HANDLE streamState, 2409 COMMAND_BUFFER_HANDLE cmdBuffer); 2410 2411 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED 2412 //! \brief Unified dump command buffer initialization 2413 //! \details check if dump command buffer was enabled and create the output directory 2414 //! \param [in/out] streamState 2415 //! Os stream state to init cmd buffer dump 2416 //! \return MOS_STATUS 2417 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed 2418 //! 2419 static MOS_STATUS DumpCommandBufferInit( 2420 MOS_STREAM_HANDLE streamState); 2421 #endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED 2422 2423 #if (_DEBUG || _RELEASE_INTERNAL) 2424 2425 enum OS_API_FAIL_TYPE 2426 { 2427 OS_API_FAIL_TYPE_NONE = 0, 2428 OS_FAIL_ALLOC_GFX_RES = 1, 2429 OS_FAIL_REGISTER_GFX_RES = 1 << 1, 2430 OS_API_FAIL_TYPE_MAX = OS_FAIL_ALLOC_GFX_RES | OS_FAIL_REGISTER_GFX_RES, 2431 }; 2432 2433 enum OS_API_FAIL_SIMULATE_MODE 2434 { 2435 OS_API_FAIL_SIMULATE_MODE_DEFAULT = 0, 2436 OS_API_FAIL_SIMULATE_MODE_RANDOM = 1, 2437 OS_API_FAIL_SIMULATE_MODE_TRAVERSE = 1 << 1, 2438 OS_API_FAIL_SIMULATE_MODE_MAX = OS_API_FAIL_SIMULATE_MODE_RANDOM | OS_API_FAIL_SIMULATE_MODE_TRAVERSE, 2439 }; 2440 2441 #define MIN_OS_API_FAIL_FREQ (1) //max memory allcation fail rate 100% 2442 #define MAX_OS_API_FAIL_FREQ (10000) //min memory allcation fail rate 1/10000 2443 2444 #define MosOsApiFailSimulationEnabled(OsApiType) \ 2445 (m_mosOsApiFailSimulateType == OsApiType && \ 2446 m_mosOsApiFailSimulateMode & OS_API_FAIL_SIMULATE_MODE_MAX) 2447 2448 //! 2449 //! \brief Init OS API fail simulate flags 2450 //! \details Init OS API fail simulate flags according user feature value 2451 //! \param [in] mosCtx 2452 //! os device ctx handle 2453 //! \return void 2454 //! 2455 static void MosInitOsApiFailSimulateFlag(MediaUserSettingSharedPtr userSettingPtr); 2456 2457 //! 2458 //! \brief Deinit OS API fail simulate flags 2459 //! \details Reset OS API fail simulate flags 2460 //! \param none 2461 //! \return void 2462 //! 2463 static void MosDeinitOsApiFailSimulateFlag(); 2464 2465 static bool MosSimulateOsApiFail( 2466 OS_API_FAIL_TYPE type, 2467 const char *functionName, 2468 const char *filename, 2469 int32_t line); 2470 2471 static uint32_t m_mosOsApiFailSimulateType; 2472 static uint32_t m_mosOsApiFailSimulateMode; 2473 static uint32_t m_mosOsApiFailSimulateFreq; 2474 static uint32_t m_mosOsApiFailSimulateHint; 2475 static uint32_t m_mosOsApiFailSimulateCounter; 2476 #endif 2477 static bool m_bTrinity; 2478 MEDIA_CLASS_DEFINE_END(MosInterface) 2479 }; 2480 2481 #define Mos_ResetResource(resource) MosInterface::MosResetResource(resource) 2482 2483 #endif // __MOS_INTERFACE_H__ 2484