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_os.c
24 //! \brief
25 //!
26 //!
27 //! \file mos_os.c
28 //! \brief Unified OS Formats
29 //! \details Unified OS Formats
30 //!
31
32 #include "mos_os.h"
33 #include "mos_util_debug.h"
34 #include "mos_interface.h"
35 #include "media_user_setting.h"
36
37 #if MOS_MEDIASOLO_SUPPORTED
38 void * _MOS_INTERFACE::pvSoloContext = nullptr;
39 uint32_t _MOS_INTERFACE::soloRefCnt = 0;
40 #endif // MOS_MEDIASOLO_SUPPORTED
41
42 extern MhwCpInterface* Create_MhwCpInterface(PMOS_INTERFACE osInterface);
43 extern void Delete_MhwCpInterface(MhwCpInterface* mhwInterface);
44
45 #if !EMUL
46 extern CodechalSecureDecodeInterface* Create_SecureDecodeInterface(CodechalSetting* codechalSettings, CodechalHwInterface* hwInterfaceInput);
47 extern void Delete_SecureDecodeInterface(CodechalSecureDecodeInterface* codechalSecureDecodeInterface);
48 #endif
49
50 static constexpr GMM_RESOURCE_USAGE_TYPE GmmResourceUsage[MOS_HW_RESOURCE_DEF_MAX] =
51 {
52 //
53 // CODEC USAGES
54 //
55 GMM_RESOURCE_USAGE_BEGIN_CODEC,
56 GMM_RESOURCE_USAGE_PRE_DEBLOCKING_CODEC,
57 GMM_RESOURCE_USAGE_PRE_DEBLOCKING_CODEC_PARTIALENCSURFACE,
58 GMM_RESOURCE_USAGE_POST_DEBLOCKING_CODEC,
59 GMM_RESOURCE_USAGE_ORIGINAL_UNCOMPRESSED_PICTURE_ENCODE,
60 GMM_RESOURCE_USAGE_ORIGINAL_UNCOMPRESSED_PICTURE_DECODE,
61 GMM_RESOURCE_USAGE_STREAMOUT_DATA_CODEC,
62 GMM_RESOURCE_USAGE_INTRA_ROWSTORE_SCRATCH_BUFFER_CODEC,
63 GMM_RESOURCE_USAGE_DEBLOCKINGFILTER_ROWSTORE_SCRATCH_BUFFER_CODEC,
64 GMM_RESOURCE_USAGE_REFERENCE_PICTURE_CODEC,
65 GMM_RESOURCE_USAGE_MACROBLOCK_STATUS_BUFFER_CODEC,
66 GMM_RESOURCE_USAGE_MFX_INDIRECT_BITSTREAM_OBJECT_DECODE,
67 GMM_RESOURCE_USAGE_MFX_INDIRECT_MV_OBJECT_CODEC,
68 GMM_RESOURCE_USAGE_MFD_INDIRECT_IT_COEF_OBJECT_DECODE,
69 GMM_RESOURCE_USAGE_MFC_INDIRECT_PAKBASE_OBJECT_CODEC,
70 GMM_RESOURCE_USAGE_BSDMPC_ROWSTORE_SCRATCH_BUFFER_CODEC,
71 GMM_RESOURCE_USAGE_MPR_ROWSTORE_SCRATCH_BUFFER_CODEC,
72 GMM_RESOURCE_USAGE_BITPLANE_READ_CODEC,
73 GMM_RESOURCE_USAGE_DIRECTMV_BUFFER_CODEC,
74 GMM_RESOURCE_USAGE_SURFACE_CURR_ENCODE,
75 GMM_RESOURCE_USAGE_SURFACE_REF_ENCODE,
76 GMM_RESOURCE_USAGE_SURFACE_MV_DATA_ENCODE,
77 GMM_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE,
78 GMM_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE_FF,
79 GMM_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE_DST,
80 GMM_RESOURCE_USAGE_SURFACE_ME_DISTORTION_ENCODE,
81 GMM_RESOURCE_USAGE_SURFACE_BRC_ME_DISTORTION_ENCODE,
82 GMM_RESOURCE_USAGE_PAK_OBJECT_ENCODE,
83 GMM_RESOURCE_USAGE_SURFACE_FLATNESS_CHECK_ENCODE,
84 GMM_RESOURCE_USAGE_SURFACE_MBENC_CURBE_ENCODE,
85 GMM_RESOURCE_USAGE_SURFACE_MAD_ENCODE,
86 GMM_RESOURCE_USAGE_VP8_BLOCK_MODE_COST_ENCODE,
87 GMM_RESOURCE_USAGE_VP8_MB_MODE_COST_ENCODE,
88 GMM_RESOURCE_USAGE_VP8_MBENC_OUTPUT_ENCODE,
89 GMM_RESOURCE_USAGE_VP8_HISTOGRAM_ENCODE,
90 GMM_RESOURCE_USAGE_VP8_L3_LLC_ENCODE,
91 GMM_RESOURCE_USAGE_MFX_STANDALONE_DEBLOCKING_CODEC,
92 GMM_RESOURCE_USAGE_HCP_MD_CODEC,
93 GMM_RESOURCE_USAGE_HCP_SAO_CODEC,
94 GMM_RESOURCE_USAGE_HCP_MV_CODEC,
95 GMM_RESOURCE_USAGE_HCP_STATUS_ERROR_CODEC,
96 GMM_RESOURCE_USAGE_HCP_LCU_ILDB_STREAMOUT_CODEC,
97 GMM_RESOURCE_USAGE_VP9_PROBABILITY_BUFFER_CODEC,
98 GMM_RESOURCE_USAGE_VP9_SEGMENT_ID_BUFFER_CODEC,
99 GMM_RESOURCE_USAGE_VP9_HVD_ROWSTORE_BUFFER_CODEC,
100 GMM_RESOURCE_USAGE_MBDISABLE_SKIPMAP_CODEC,
101 GMM_RESOURCE_USAGE_VDENC_ROW_STORE_BUFFER_CODEC,
102 GMM_RESOURCE_USAGE_VDENC_STREAMIN_CODEC,
103 GMM_RESOURCE_USAGE_SURFACE_MB_QP_CODEC,
104 GMM_RESOURCE_USAGE_MACROBLOCK_ILDB_STREAM_OUT_BUFFER_CODEC,
105 GMM_RESOURCE_USAGE_SSE_SRC_PIXEL_ROW_STORE_BUFFER_CODEC,
106 GMM_RESOURCE_USAGE_SLICE_STATE_STREAM_OUT_BUFFER_CODEC,
107 GMM_RESOURCE_USAGE_CABAC_SYNTAX_STREAM_OUT_BUFFER_CODEC,
108 GMM_RESOURCE_USAGE_PRED_COL_STORE_BUFFER_CODEC,
109 GMM_RESOURCE_USAGE_SURFACE_PAK_IMAGESTATE_ENCODE,
110 GMM_RESOURCE_USAGE_SURFACE_MBENC_BRC_ENCODE,
111 GMM_RESOURCE_USAGE_SURFACE_MB_BRC_CONST_ENCODE,
112 GMM_RESOURCE_USAGE_SURFACE_BRC_MB_QP_ENCODE,
113 GMM_RESOURCE_USAGE_SURFACE_BRC_ROI_ENCODE,
114 GMM_RESOURCE_USAGE_SURFACE_SLICE_MAP_ENCODE,
115 GMM_RESOURCE_USAGE_SURFACE_WP_DOWNSAMPLED_ENCODE,
116 GMM_RESOURCE_USAGE_SURFACE_VDENC_IMAGESTATE_ENCODE,
117 GMM_RESOURCE_USAGE_SURFACE_UNCACHED,
118 GMM_RESOURCE_USAGE_SURFACE_ELLC_ONLY,
119 GMM_RESOURCE_USAGE_SURFACE_ELLC_LLC_ONLY,
120 GMM_RESOURCE_USAGE_SURFACE_ELLC_LLC_L3,
121 GMM_RESOURCE_USAGE_SURFACE_BRC_HISTORY_ENCODE,
122 GMM_RESOURCE_USAGE_SURFACE_SOFTWARE_SCOREBOARD_ENCODE,
123 GMM_RESOURCE_USAGE_SURFACE_ME_MV_DATA_ENCODE,
124 GMM_RESOURCE_USAGE_SURFACE_MV_DISTORTION_ENCODE,
125 GMM_RESOURCE_USAGE_SURFACE_4XME_DISTORTION_ENCODE,
126 GMM_RESOURCE_USAGE_SURFACE_INTRA_DISTORTION_ENCODE,
127 GMM_RESOURCE_USAGE_MB_STATS_ENCODE,
128 GMM_RESOURCE_USAGE_SURFACE_PAK_STATS_ENCODE,
129 GMM_RESOURCE_USAGE_SURFACE_PIC_STATE_READ_ENCODE,
130 GMM_RESOURCE_USAGE_SURFACE_PIC_STATE_WRITE_ENCODE,
131 GMM_RESOURCE_USAGE_SURFACE_COMBINED_ENC_ENCODE,
132 GMM_RESOURCE_USAGE_SURFACE_BRC_CONSTANT_DATA_ENCODE,
133 GMM_RESOURCE_USAGE_SURFACE_INTERMEDIATE_CU_RECORD_SURFACE_ENCODE,
134 GMM_RESOURCE_USAGE_SURFACE_SCRATCH_ENCODE,
135 GMM_RESOURCE_USAGE_SURFACE_LCU_LEVEL_DATA_ENCODE,
136 GMM_RESOURCE_USAGE_SURFACE_ENC_HISTORY_INPUT_ENCODE,
137 GMM_RESOURCE_USAGE_SURFACE_ENC_HISTORY_OUTPUT_ENCODE,
138 GMM_RESOURCE_USAGE_SURFACE_DEBUG_ENCODE,
139 GMM_RESOURCE_USAGE_SURFACE_ENC_CONSTANT_TABLE_ENCODE,
140 GMM_RESOURCE_USAGE_SURFACE_ENC_CU_RECORD_ENCODE,
141 GMM_RESOURCE_USAGE_SURFACE_ENC_MV_TEMPORAL_BUFFER_ENCODE,
142 GMM_RESOURCE_USAGE_SURFACE_ENC_CU_PACKET_FOR_PAK_ENCODE,
143 GMM_RESOURCE_USAGE_SURFACE_ENC_BCOMBINED1_ENCODE,
144 GMM_RESOURCE_USAGE_SURFACE_ENC_BCOMBINED2_ENCODE,
145 GMM_RESOURCE_USAGE_FRAME_STATS_STREAMOUT_DATA_CODEC,
146 GMM_RESOURCE_USAGE_DEBLOCKINGFILTER_ROWSTORE_TILE_LINE_BUFFER_CODEC,
147 GMM_RESOURCE_USAGE_DEBLOCKINGFILTER_ROWSTORE_TILE_COLUMN_BUFFER_CODEC,
148 GMM_RESOURCE_USAGE_HCP_MD_TILE_LINE_CODEC,
149 GMM_RESOURCE_USAGE_HCP_MD_TILE_COLUMN_CODEC,
150 GMM_RESOURCE_USAGE_HCP_SAO_TILE_LINE_CODEC,
151 GMM_RESOURCE_USAGE_HCP_SAO_TILE_COLUMN_CODEC,
152 GMM_RESOURCE_USAGE_VP9_PROBABILITY_COUNTER_BUFFER_CODEC,
153 GMM_RESOURCE_USAGE_HUC_VIRTUAL_ADDR_REGION_BUFFER_CODEC,
154 GMM_RESOURCE_USAGE_SIZE_STREAMOUT_CODEC,
155 GMM_RESOURCE_USAGE_COMPRESSED_HEADER_BUFFER_CODEC,
156 GMM_RESOURCE_USAGE_PROBABILITY_DELTA_BUFFER_CODEC,
157 GMM_RESOURCE_USAGE_TILE_RECORD_BUFFER_CODEC,
158 GMM_RESOURCE_USAGE_TILE_SIZE_STAS_BUFFER_CODEC,
159 GMM_RESOURCE_USAGE_END_CODEC,
160
161 //
162 // CM USAGES
163 //
164 CM_RESOURCE_USAGE_SurfaceState,
165 CM_RESOURCE_USAGE_StateHeap,
166 CM_RESOURCE_USAGE_NO_L3_SurfaceState,
167 CM_RESOURCE_USAGE_NO_LLC_ELLC_SurfaceState,
168 CM_RESOURCE_USAGE_NO_LLC_SurfaceState,
169 CM_RESOURCE_USAGE_NO_ELLC_SurfaceState,
170 CM_RESOURCE_USAGE_NO_LLC_L3_SurfaceState,
171 CM_RESOURCE_USAGE_NO_ELLC_L3_SurfaceState,
172 CM_RESOURCE_USAGE_NO_CACHE_SurfaceState,
173 CM_RESOURCE_USAGE_L1_Enabled_SurfaceState,
174
175 //
176 // MP USAGES
177 //
178 MP_RESOURCE_USAGE_BEGIN,
179 MP_RESOURCE_USAGE_DEFAULT,
180 MP_RESOURCE_USAGE_DEFAULT_FF,
181 MP_RESOURCE_USAGE_DEFAULT_RCS,
182 MP_RESOURCE_USAGE_SurfaceState,
183 MP_RESOURCE_USAGE_SurfaceState_FF,
184 MP_RESOURCE_USAGE_SurfaceState_RCS,
185 MP_RESOURCE_USAGE_AGE3_SurfaceState,
186 MP_RESOURCE_USAGE_EDRAM_SurfaceState,
187 MP_RESOURCE_USAGE_EDRAM_AGE3_SurfaceState,
188 MP_RESOURCE_USAGE_No_L3_SurfaceState,
189 MP_RESOURCE_USAGE_No_LLC_L3_SurfaceState,
190 MP_RESOURCE_USAGE_No_LLC_L3_AGE_SurfaceState,
191 MP_RESOURCE_USAGE_No_LLC_eLLC_L3_AGE_SurfaceState,
192 MP_RESOURCE_USAGE_PartialEnc_No_LLC_L3_AGE_SurfaceState,
193 MP_RESOURCE_USAGE_END,
194
195 // MHW - SFC
196 MHW_RESOURCE_USAGE_Sfc_CurrentOutputSurface, //!< SFC output surface
197 MHW_RESOURCE_USAGE_Sfc_CurrentOutputSurface_PartialEncSurface, //!< SFC output surface for partial secure surfaces
198 MHW_RESOURCE_USAGE_Sfc_AvsLineBufferSurface, //!< SFC AVS Line buffer Surface
199 MHW_RESOURCE_USAGE_Sfc_IefLineBufferSurface, //!< SFC IEF Line buffer Surface
200
201 // Camera caputure.
202 GMM_RESOURCE_USAGE_CAMERA_CAPTURE,
203 // Media GMM Resource USAGES
204 GMM_RESOURCE_USAGE_CCS_MEDIA_WRITABLE,
205
206 // Media BLT copy USAGES
207 GMM_RESOURCE_USAGE_BLT_SOURCE,
208 GMM_RESOURCE_USAGE_BLT_DESTINATION,
209
210 // PAT Media Usages
211 GMM_RESOURCE_USAGE_MEDIA_BATCH_BUFFERS,
212 // DECODE
213 GMM_RESOURCE_USAGE_DECODE_INPUT_BITSTREAM,
214 GMM_RESOURCE_USAGE_DECODE_INPUT_REFERENCE,
215 GMM_RESOURCE_USAGE_DECODE_INTERNAL_READ,
216 GMM_RESOURCE_USAGE_DECODE_INTERNAL_WRITE,
217 GMM_RESOURCE_USAGE_DECODE_INTERNAL_READ_WRITE_CACHE,
218 GMM_RESOURCE_USAGE_DECODE_INTERNAL_READ_WRITE_NOCACHE,
219 GMM_RESOURCE_USAGE_DECODE_OUTPUT_PICTURE,
220 GMM_RESOURCE_USAGE_DECODE_OUTPUT_STATISTICS_WRITE,
221 GMM_RESOURCE_USAGE_DECODE_OUTPUT_STATISTICS_READ_WRITE,
222 // ENCODE
223 GMM_RESOURCE_USAGE_ENCODE_INPUT_RAW,
224 GMM_RESOURCE_USAGE_ENCODE_INPUT_RECON,
225 GMM_RESOURCE_USAGE_ENCODE_INTERNAL_READ,
226 GMM_RESOURCE_USAGE_ENCODE_INTERNAL_WRITE,
227 GMM_RESOURCE_USAGE_ENCODE_INTERNAL_READ_WRITE_CACHE,
228 GMM_RESOURCE_USAGE_ENCODE_INTERNAL_READ_WRITE_NOCACHE,
229 GMM_RESOURCE_USAGE_ENCODE_EXTERNAL_READ,
230 GMM_RESOURCE_USAGE_ENCODE_OUTPUT_PICTURE,
231 GMM_RESOURCE_USAGE_ENCODE_OUTPUT_BITSTREAM,
232 GMM_RESOURCE_USAGE_ENCODE_OUTPUT_STATISTICS_WRITE,
233 GMM_RESOURCE_USAGE_ENCODE_OUTPUT_STATISTICS_READ_WRITE,
234 // VP
235 GMM_RESOURCE_USAGE_VP_INPUT_PICTURE_FF,
236 GMM_RESOURCE_USAGE_VP_INPUT_REFERENCE_FF,
237 GMM_RESOURCE_USAGE_VP_INTERNAL_READ_FF,
238 GMM_RESOURCE_USAGE_VP_INTERNAL_WRITE_FF,
239 GMM_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_FF,
240 GMM_RESOURCE_USAGE_VP_OUTPUT_PICTURE_FF,
241 GMM_RESOURCE_USAGE_VP_INPUT_PICTURE_RENDER,
242 GMM_RESOURCE_USAGE_VP_INPUT_REFERENCE_RENDER,
243 GMM_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER,
244 GMM_RESOURCE_USAGE_VP_INTERNAL_WRITE_RENDER,
245 GMM_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
246 GMM_RESOURCE_USAGE_VP_OUTPUT_PICTURE_RENDER,
247 // CP
248 GMM_RESOURCE_USAGE_CP_EXTERNAL_READ,
249 GMM_RESOURCE_USAGE_CP_INTERNAL_WRITE,
250 };
251
252 //! \brief Unified OS add command to command buffer
253 //! \details Offset returned is dword aligned but size requested can be byte aligned
254 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
255 //! [in/out] Pointer to Command Buffer
256 //! \param void *pCmd
257 //! [in] Command Pointer
258 //! \param uint32_t dwCmdSize
259 //! [in] Size of command in bytes
260 //! \return MOS_STATUS
261 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
262 //!
Mos_AddCommand(PMOS_COMMAND_BUFFER pCmdBuffer,const void * pCmd,uint32_t dwCmdSize)263 MOS_STATUS Mos_AddCommand(
264 PMOS_COMMAND_BUFFER pCmdBuffer,
265 const void *pCmd,
266 uint32_t dwCmdSize)
267 {
268 return MosInterface::AddCommand(pCmdBuffer, pCmd, dwCmdSize);
269 }
270
271 //!
272 //! \brief Unified OS fill Resource
273 //! \details Locks the surface and fills the resource with data
274 //! \param PMOS_INTERFACE pOsInterface
275 //! [in] Pointer to OS Interface
276 //! \param PMOS_RESOURCE pOsResource
277 //! [in] Pointer to OS Resource
278 //! \param uint32_t dwSize
279 //! [in] Size of the Buffer
280 //! \param uint8_t iValue
281 //! [in] Value to be filled
282 //! \return MOS_STATUS
283 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
284 //!
Mos_OsFillResource(PMOS_INTERFACE pOsInterface,PMOS_RESOURCE pOsResource,uint32_t dwSize,uint8_t iValue)285 MOS_STATUS Mos_OsFillResource(
286 PMOS_INTERFACE pOsInterface,
287 PMOS_RESOURCE pOsResource,
288 uint32_t dwSize,
289 uint8_t iValue)
290 {
291 MOS_OS_CHK_NULL_RETURN(pOsInterface);
292 MOS_OS_CHK_NULL_RETURN(pOsResource);
293 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
294
295 uint8_t * pByte = nullptr;
296 MOS_LOCK_PARAMS lockFlags = {};
297 uint32_t size = 0;
298 #ifndef VPSOLO_EMUL
299 if (pOsResource->pGmmResInfo)
300 {
301 size = (uint32_t)pOsResource->pGmmResInfo->GetSizeSurface();
302 }
303 if (dwSize > size)
304 {
305 MOS_OS_ASSERTMESSAGE("dwSize (%x)> size (%x)", dwSize, size);
306 }
307 #endif
308 // Lock the surface for writing
309 lockFlags.WriteOnly = 1;
310 pByte = (uint8_t*)pOsInterface->pfnLockResource(
311 pOsInterface,
312 pOsResource,
313 &lockFlags);
314
315 MOS_OS_CHK_NULL_RETURN(pByte);
316
317 MOS_FillMemory(pByte, dwSize, iValue);
318
319 // Unlock the surface
320 MOS_OS_CHK_STATUS_RETURN(pOsInterface->pfnUnlockResource(pOsInterface, pOsResource));
321
322 return eStatus;
323 }
324
325 //! \brief Unified OS Get bits per pixel
326 //! \details Gets Bits Per Pixel
327 //! \param PMOS_INTERFACE pOsInterface
328 //! [in] Pointer to OS Interface
329 //! \param PMOS_RESOURCE pOsResource
330 //! [in] Pointer to OS Resource
331 //! \param uint32_t *piBpp
332 //! [out] Bits per pixel
333 //! \return MOS_STATUS
334 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
335 //!
Mos_OsGetBitsPerPixel(PMOS_INTERFACE pOsInterface,MOS_FORMAT Format,uint32_t * piBpp)336 MOS_STATUS Mos_OsGetBitsPerPixel(
337 PMOS_INTERFACE pOsInterface,
338 MOS_FORMAT Format,
339 uint32_t *piBpp)
340 {
341 MOS_STATUS eStatus;
342 MOS_UNUSED(pOsInterface);
343
344 eStatus = MOS_STATUS_SUCCESS;
345
346 switch(Format)
347 {
348 case Format_A8R8G8B8:
349 case Format_X8R8G8B8:
350 case Format_A8B8G8R8:
351 case Format_X8B8G8R8:
352 case Format_AYUV:
353 case Format_R32U:
354 case Format_R32S:
355 case Format_R32F:
356 case Format_R10G10B10A2:
357 case Format_B10G10R10A2:
358 *piBpp = 32;
359 break;
360
361 case Format_P010:
362 case Format_P016:
363 case Format_R8G8B8:
364 *piBpp = 24;
365 break;
366
367 case Format_R5G6B5:
368 case Format_A8P8:
369 case Format_A8L8:
370 case Format_R16U:
371 case Format_V8U8:
372 case Format_R16F:
373 *piBpp = 16;
374 break;
375
376 case Format_YUY2:
377 case Format_YUYV:
378 case Format_YVYU:
379 case Format_UYVY:
380 case Format_VYUY:
381 *piBpp = 16;
382 break;
383
384 case Format_AI44:
385 case Format_IA44:
386 case Format_A8:
387 case Format_P8:
388 case Format_L8:
389 case Format_A4L4:
390 *piBpp = 8;
391 break;
392
393 case Format_IMC1:
394 case Format_IMC3:
395 case Format_IMC2:
396 case Format_IMC4:
397 case Format_NV12:
398 case Format_YV12:
399 case Format_I420:
400 case Format_IYUV:
401 *piBpp = 12;
402 break;
403
404 case Format_400P:
405 *piBpp = 8;
406 break;
407
408 case Format_411P:
409 *piBpp = 12;
410 break;
411
412 case Format_422H:
413 case Format_422V:
414 *piBpp = 16;
415 break;
416
417 case Format_444P:
418 case Format_RGBP:
419 case Format_BGRP:
420 *piBpp = 24;
421 break;
422
423 case Format_YVU9:
424 *piBpp = 9;
425 break;
426
427 case Format_Buffer:
428 case Format_RAW:
429 case Format_R8U:
430 case Format_R8UN:
431 *piBpp = 8;
432 break;
433
434 default:
435 MOS_OS_ASSERTMESSAGE("Format '%d' not supported.", Format);
436 *piBpp = 0;
437 eStatus = MOS_STATUS_UNKNOWN;
438 break;
439 }
440
441 return eStatus;
442 }
443
444 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED
445 //!
446 //! \brief Get Platform Name
447 //! \details This function retrieve the platform name
448 //! \param PMOS_RESOURCE pOsResource
449 //! [in] Pointer to OS Resource
450 //! \param buffer
451 //! [out] Buffer to contain platform name
452 //! \return MOS_STATUS
453 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
454 //!
Mos_GetPlatformName(PMOS_INTERFACE pOsInterface,char * buffer)455 MOS_STATUS Mos_GetPlatformName(
456 PMOS_INTERFACE pOsInterface,
457 char *buffer)
458 {
459 MOS_SecureStrcpy(buffer, MOS_COMMAND_BUFFER_PLATFORM_LEN, "N/A");
460
461 return MOS_STATUS_SUCCESS;
462 }
463
Mos_AddIndirectState(PMOS_INTERFACE pOsInterface,uint32_t stateSize,uint32_t * pIndirectState,uint32_t * gfxAddressBottom,uint32_t * gfxAddressTop,const char * stateName)464 void Mos_AddIndirectState(
465 PMOS_INTERFACE pOsInterface,
466 uint32_t stateSize,
467 uint32_t *pIndirectState,
468 uint32_t *gfxAddressBottom,
469 uint32_t *gfxAddressTop,
470 const char *stateName)
471 {
472 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface);
473 if (pOsInterface->apoMosEnabled)
474 {
475 MOS_OS_CHK_NULL_NO_STATUS_RETURN(pOsInterface->osStreamState);
476 INDIRECT_STATE_INFO stateinfoarray = {};
477 stateinfoarray.stateSize = stateSize;
478 stateinfoarray.indirectState = pIndirectState;
479 stateinfoarray.gfxAddressBottom = gfxAddressBottom;
480 stateinfoarray.gfxAddressTop = gfxAddressTop;
481 stateinfoarray.stateName = stateName;
482 pOsInterface->osStreamState->indirectStateInfo.push_back(stateinfoarray);
483 }
484 return;
485 }
486
487 //!
488 //! \brief Dump command buffers
489 //! \details This function dumps the command buffer just before rendering it to the GPU.
490 //! The output is saved to %TEMP%\Command_buffer_dumps.
491 //! A GPU engine prefix is printed for each command buffer, to let the user know which command streamer is being used.
492 //! \param PMOS_RESOURCE pOsResource
493 //! [in] Pointer to OS Resource
494 //! \param PMOS_COMMAND_BUFFER pCmdBuffer
495 //! [in] Pointer to command buffer structure
496 //! \return MOS_STATUS
497 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
498 //!
Mos_DumpCommandBuffer(PMOS_INTERFACE pOsInterface,PMOS_COMMAND_BUFFER pCmdBuffer)499 MOS_STATUS Mos_DumpCommandBuffer(
500 PMOS_INTERFACE pOsInterface,
501 PMOS_COMMAND_BUFFER pCmdBuffer)
502 {
503 static uint32_t dwCommandBufferNumber = 0;
504 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
505 char *pOutputBuffer = nullptr;
506 // Each hex value should have 9 chars.
507 uint32_t SIZE_OF_ONE_WORD = 9;
508 uint32_t dwBytesWritten = 0;
509 uint32_t dwNumberOfDwords = 0;
510 uint32_t dwSizeToAllocate = 0;
511 char sFileName[MOS_MAX_HLT_FILENAME_LEN];
512 // Maximum length of engine name is 6
513 char sEngName[6];
514 char *psFileNameAfterPrefix = nullptr;
515 size_t nSizeFileNamePrefix = 0;
516
517 MOS_OS_CHK_NULL_RETURN(pOsInterface);
518 MOS_OS_CHK_NULL_RETURN(pCmdBuffer);
519
520 if (pOsInterface->apoMosEnabled)
521 {
522 return MosInterface::DumpCommandBuffer(pOsInterface->osStreamState, pCmdBuffer);
523 }
524
525 // Set the name of the engine that is going to be used.
526 MOS_GPU_CONTEXT sGpuContext = pOsInterface->pfnGetGpuContext(pOsInterface);
527 switch (sGpuContext)
528 {
529 case MOS_GPU_CONTEXT_VIDEO:
530 case MOS_GPU_CONTEXT_VIDEO2:
531 case MOS_GPU_CONTEXT_VIDEO3:
532 case MOS_GPU_CONTEXT_VIDEO4:
533 case MOS_GPU_CONTEXT_VDBOX2_VIDEO:
534 case MOS_GPU_CONTEXT_VDBOX2_VIDEO2:
535 case MOS_GPU_CONTEXT_VDBOX2_VIDEO3:
536 case MOS_GPU_CONTEXT_VIDEO5:
537 case MOS_GPU_CONTEXT_VIDEO6:
538 case MOS_GPU_CONTEXT_VIDEO7:
539 MOS_SecureStrcpy(sEngName, sizeof(sEngName), MOS_COMMAND_BUFFER_VIDEO_ENGINE);
540 break;
541 case MOS_GPU_CONTEXT_TEE:
542 MOS_SecureStrcpy(sEngName, sizeof(sEngName), MOS_COMMAND_BUFFER_TEE_ENGINE);
543 break;
544 case MOS_GPU_CONTEXT_RENDER:
545 case MOS_GPU_CONTEXT_RENDER2:
546 case MOS_GPU_CONTEXT_RENDER3:
547 case MOS_GPU_CONTEXT_RENDER4:
548 case MOS_GPU_CONTEXT_RENDER_RA:
549 case MOS_GPU_CONTEXT_COMPUTE:
550 case MOS_GPU_CONTEXT_COMPUTE_RA:
551 case MOS_GPU_CONTEXT_CM_COMPUTE:
552 MOS_SecureStrcpy(sEngName, sizeof(sEngName), MOS_COMMAND_BUFFER_RENDER_ENGINE);
553 break;
554 case MOS_GPU_CONTEXT_VEBOX:
555 MOS_SecureStrcpy(sEngName, sizeof(sEngName), MOS_COMMAND_BUFFER_VEBOX_ENGINE);
556 break;
557 default:
558 MOS_OS_ASSERTMESSAGE("Unsupported GPU context.");
559 return MOS_STATUS_UNKNOWN;
560 }
561
562 dwNumberOfDwords = pCmdBuffer->iOffset / sizeof(uint32_t);
563
564 dwSizeToAllocate =
565 dwNumberOfDwords * (SIZE_OF_ONE_WORD + 1) // Add 1 byte for the space following each Dword.
566 + 3 * SIZE_OF_ONE_WORD; // For engine and platform names.
567
568 // Alloc output buffer.
569 pOutputBuffer = (char *)MOS_AllocAndZeroMemory(dwSizeToAllocate);
570 MOS_OS_CHK_NULL_RETURN(pOutputBuffer);
571
572 dwBytesWritten = MOS_SecureStringPrint(
573 pOutputBuffer,
574 SIZE_OF_ONE_WORD * 3,
575 SIZE_OF_ONE_WORD * 3,
576 "Eng=%s Plat=%s ",
577 sEngName, pOsInterface->sPlatformName);
578
579 if (pOsInterface->bDumpCommandBufferToFile)
580 {
581 // Set the file name.
582 memcpy(sFileName, pOsInterface->sDirName, MOS_MAX_HLT_FILENAME_LEN);
583 nSizeFileNamePrefix = strnlen(sFileName, sizeof(sFileName));
584 MOS_SecureStringPrint(
585 sFileName + nSizeFileNamePrefix,
586 sizeof(sFileName) - nSizeFileNamePrefix,
587 sizeof(sFileName) - nSizeFileNamePrefix,
588 "%c%s%c%s_%d.txt",
589 MOS_DIR_SEPERATOR, MOS_COMMAND_BUFFER_OUT_DIR,
590 MOS_DIR_SEPERATOR, MOS_COMMAND_BUFFER_OUT_FILE, dwCommandBufferNumber);
591
592 // Write the output buffer to file.
593 MOS_OS_CHK_STATUS_RETURN(MosUtilities::MosWriteFileFromPtr((const char *)sFileName, pOutputBuffer, dwBytesWritten));
594 }
595
596 if (pOsInterface->bDumpCommandBufferAsMessages)
597 {
598 MOS_OS_NORMALMESSAGE(pOutputBuffer);
599 }
600
601 MOS_ZeroMemory(pOutputBuffer, dwBytesWritten);
602 dwBytesWritten = 0;
603
604 // Fill in the output buffer with the command buffer dwords.
605 for (uint32_t dwIndex = 0; dwIndex < dwNumberOfDwords; dwIndex++)
606 {
607 dwBytesWritten += MOS_SecureStringPrint(
608 pOutputBuffer + dwBytesWritten,
609 SIZE_OF_ONE_WORD + 1,
610 SIZE_OF_ONE_WORD + 1,
611 "%.8x ",
612 pCmdBuffer->pCmdBase[dwIndex]);
613
614 if (dwBytesWritten % (SIZE_OF_ONE_WORD + 1) == 0)
615 {
616 if (pOsInterface->bDumpCommandBufferToFile)
617 {
618 MOS_OS_CHK_STATUS_RETURN(MosUtilities::MosAppendFileFromPtr((const char *)sFileName, pOutputBuffer, dwBytesWritten));
619 }
620 if (pOsInterface->bDumpCommandBufferAsMessages)
621 {
622 MOS_OS_NORMALMESSAGE(pOutputBuffer);
623 }
624
625 MOS_ZeroMemory(pOutputBuffer, dwBytesWritten);
626 dwBytesWritten = 0;
627 }
628 }
629
630 if (pOsInterface->bDumpCommandBufferToFile)
631 {
632 MOS_OS_CHK_STATUS_RETURN(MosUtilities::MosAppendFileFromPtr((const char *)sFileName, pOutputBuffer, dwBytesWritten));
633 }
634
635 if (pOsInterface->bDumpCommandBufferAsMessages)
636 {
637 MOS_OS_NORMALMESSAGE(pOutputBuffer);
638 }
639
640 dwCommandBufferNumber++;
641
642 eStatus = MOS_STATUS_SUCCESS;
643
644 // Free the memory.
645 if (pOutputBuffer)
646 {
647 MOS_FreeMemAndSetNull(pOutputBuffer);
648 }
649
650 return eStatus;
651 }
652
653 //! \brief Unified dump command buffer initialization
654 //! \details check if dump command buffer was enabled and create the output directory
655 //! \param PMOS_INTERFACE pOsInterface
656 //! [in/out] Pointer to OS Interface
657 //! \return MOS_STATUS
658 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
659 //!
Mos_DumpCommandBufferInit(PMOS_INTERFACE pOsInterface)660 MOS_STATUS Mos_DumpCommandBufferInit(
661 PMOS_INTERFACE pOsInterface)
662 {
663 char sFileName[MOS_MAX_HLT_FILENAME_LEN] = {};
664 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
665 size_t nSizeFileNamePrefix = 0;
666 MediaUserSettingSharedPtr userSettingPtr = nullptr;
667 uint32_t value = 0;
668 MOS_OS_CHK_NULL_RETURN(pOsInterface);
669
670 userSettingPtr = pOsInterface->pfnGetUserSettingInstance(pOsInterface);
671
672 // Setup member function and variable.
673 pOsInterface->pfnDumpCommandBuffer = Mos_DumpCommandBuffer;
674 pOsInterface->pfnAddIndirectState = Mos_AddIndirectState;
675
676 // Check if command buffer dump was enabled in user feature.
677 ReadUserSetting(
678 userSettingPtr,
679 value,
680 __MEDIA_USER_FEATURE_VALUE_DUMP_COMMAND_BUFFER_ENABLE,
681 MediaUserSetting::Group::Device);
682
683 pOsInterface->bDumpCommandBuffer = (value != 0);
684 pOsInterface->bDumpCommandBufferToFile = ((value & 1) != 0);
685 pOsInterface->bDumpCommandBufferAsMessages = ((value & 2) != 0);
686
687 if (pOsInterface->bDumpCommandBufferToFile)
688 {
689 // Create output directory.
690 eStatus = MosUtilDebug::MosLogFileNamePrefix(pOsInterface->sDirName, userSettingPtr);
691 if (eStatus != MOS_STATUS_SUCCESS)
692 {
693 MOS_OS_NORMALMESSAGE("Failed to create log file prefix. Status = %d", eStatus);
694 return eStatus;
695 }
696
697 memcpy(sFileName, pOsInterface->sDirName, MOS_MAX_HLT_FILENAME_LEN);
698 nSizeFileNamePrefix = strnlen(sFileName, sizeof(sFileName));
699 MOS_SecureStringPrint(
700 sFileName + nSizeFileNamePrefix,
701 sizeof(sFileName) - nSizeFileNamePrefix,
702 sizeof(sFileName) - nSizeFileNamePrefix,
703 "%c%s",
704 MOS_DIR_SEPERATOR, MOS_COMMAND_BUFFER_OUT_DIR);
705
706 eStatus = MosUtilities::MosCreateDirectory(sFileName);
707 if (eStatus != MOS_STATUS_SUCCESS)
708 {
709 MOS_OS_NORMALMESSAGE("Failed to create output directory. Status = %d", eStatus);
710 return eStatus;
711 }
712 }
713
714 Mos_GetPlatformName(pOsInterface, pOsInterface->sPlatformName);
715
716 return MOS_STATUS_SUCCESS;
717 }
718 #endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED
719
720 #if MOS_COMMAND_RESINFO_DUMP_SUPPORTED
721
722 std::shared_ptr<GpuCmdResInfoDump> GpuCmdResInfoDump::m_instance = nullptr;
723
GetInstance(PMOS_CONTEXT mosCtx)724 const GpuCmdResInfoDump *GpuCmdResInfoDump::GetInstance(PMOS_CONTEXT mosCtx)
725 {
726 if (m_instance == nullptr)
727 {
728 m_instance = std::make_shared<GpuCmdResInfoDump>(mosCtx);
729 }
730 return m_instance.get();
731 }
732
GpuCmdResInfoDump(PMOS_CONTEXT mosCtx)733 GpuCmdResInfoDump::GpuCmdResInfoDump(PMOS_CONTEXT mosCtx)
734 {
735 MediaUserSettingSharedPtr userSettingPtr = nullptr;
736 MediaUserSetting::Value value;
737
738 userSettingPtr = MosInterface::MosGetUserSettingInstance(mosCtx);
739
740 ReadUserSetting(
741 userSettingPtr,
742 m_dumpEnabled,
743 __MEDIA_USER_FEATURE_VALUE_DUMP_COMMAND_INFO_ENABLE,
744 MediaUserSetting::Group::Device);
745
746 if (!m_dumpEnabled)
747 {
748 return;
749 }
750
751 ReadUserSetting(
752 userSettingPtr,
753 value,
754 __MEDIA_USER_FEATURE_VALUE_DUMP_COMMAND_INFO_PATH,
755 MediaUserSetting::Group::Device);
756
757 auto path = value.ConstString();
758 if(path.size() > 0)
759 {
760 m_path = path;
761 if (path.back() != '/' && path.back() != '\\')
762 {
763 m_path += '/';
764 }
765 }
766 m_path = m_path + "gpuCmdResInfo_" + std::to_string(MosUtilities::MosGetPid()) + ".txt";
767 }
768
Dump(PMOS_INTERFACE pOsInterface) const769 void GpuCmdResInfoDump::Dump(PMOS_INTERFACE pOsInterface) const
770 {
771 if (!m_dumpEnabled)
772 {
773 return;
774 }
775
776 using std::endl;
777
778 std::ofstream outputFile;
779 outputFile.open(m_path, std::ios_base::app);
780 MOS_OS_ASSERT(outputFile.is_open());
781
782 auto &cmdResInfoPtrs = GetCmdResPtrs(pOsInterface);
783
784 outputFile << "--PerfTag: " << std::to_string(pOsInterface->pfnGetPerfTag(pOsInterface)) << " --Cmd Num: "
785 << cmdResInfoPtrs.size() << " --Dump Count: " << ++m_cnt << endl;
786
787 outputFile << "********************************CMD Paket Begin********************************" << endl;
788 for (auto e : cmdResInfoPtrs)
789 {
790 Dump(e, outputFile);
791 }
792 outputFile << "********************************CMD Paket End**********************************" << endl << endl;
793
794 outputFile.close();
795 }
796
GetResType(MOS_GFXRES_TYPE resType) const797 const char *GpuCmdResInfoDump::GetResType(MOS_GFXRES_TYPE resType) const
798 {
799 switch (resType)
800 {
801 case MOS_GFXRES_INVALID:
802 return "MOS_GFXRES_INVALID";
803 case MOS_GFXRES_BUFFER:
804 return "MOS_GFXRES_BUFFER";
805 case MOS_GFXRES_2D:
806 return "MOS_GFXRES_2D";
807 case MOS_GFXRES_VOLUME:
808 return "MOS_GFXRES_VOLUME";
809 default:
810 return "";
811 }
812 }
813
GetTileType(MOS_TILE_TYPE tileType) const814 const char *GpuCmdResInfoDump::GetTileType(MOS_TILE_TYPE tileType) const
815 {
816 switch (tileType)
817 {
818 case MOS_TILE_X:
819 return "MOS_TILE_X";
820 case MOS_TILE_Y:
821 return "MOS_TILE_Y";
822 case MOS_TILE_YF:
823 return "MOS_TILE_YF";
824 case MOS_TILE_YS:
825 return "MOS_TILE_YS";
826 case MOS_TILE_LINEAR:
827 return "MOS_TILE_LINEAR";
828 case MOS_TILE_INVALID:
829 return "MOS_TILE_INVALID";
830 default:
831 return "";
832 }
833 }
834 #endif // MOS_COMMAND_RESINFO_DUMP_SUPPORTED
835
836 //! \brief Unified OS Initializes OS Interface
837 //! \details OS Interface initilization
838 //! \param PMOS_INTERFACE pOsInterface
839 //! [in/out] Pointer to OS Interface
840 //! \param MOS_CONTEXT_HANDLE osDriverContext
841 //! [in] Pointer to Driver context
842 //! \param MOS_COMPONENT component
843 //! [in] OS component
844 //! \return MOS_STATUS
845 //! Return MOS_STATUS_SUCCESS if successful, otherwise failed
846 //!
Mos_InitOsInterface(PMOS_INTERFACE pOsInterface,MOS_CONTEXT_HANDLE osDriverContext,MOS_COMPONENT component)847 MOS_STATUS Mos_InitOsInterface(
848 PMOS_INTERFACE pOsInterface,
849 MOS_CONTEXT_HANDLE osDriverContext,
850 MOS_COMPONENT component)
851 {
852 MOS_OS_CHK_NULL_RETURN(pOsInterface);
853 #if !EMUL
854 MOS_OS_CHK_NULL_RETURN(osDriverContext);
855 #endif
856 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
857 MediaUserSettingSharedPtr userSettingPtr = nullptr;
858 PMOS_CONTEXT pOsDriverContext = (PMOS_CONTEXT)osDriverContext;
859 // Setup Member functions
860 pOsInterface->pfnFillResource = Mos_OsFillResource;
861 pOsInterface->pfnGetBitsPerPixel = Mos_OsGetBitsPerPixel;
862 pOsInterface->pfnAddCommand = Mos_AddCommand;
863 pOsInterface->pfnVirtualEngineSupported = Mos_CheckVirtualEngineSupported;
864 pOsInterface->pfnGetResourceCachePolicyMemoryObject = Mos_GetResourceCachePolicyMemoryObject;
865
866 pOsInterface->pfnIsAsyncDevice = Mos_IsAsyncDevice;
867 pOsInterface->pfnMosFmtToOsFmt = Mos_MosFmtToOsFmt;
868 pOsInterface->pfnOsFmtToMosFmt = Mos_OsFmtToMosFmt;
869 pOsInterface->pfnMosFmtToGmmFmt = Mos_MosFmtToGmmFmt;
870 pOsInterface->pfnGmmFmtToMosFmt = Mos_GmmFmtToMosFmt;
871 pOsInterface->pfnWaitForCmdCompletion = Mos_WaitForCmdCompletion;
872 pOsInterface->pfnGetResourceArrayIndex = Mos_GetResourceArrayIndex;
873 pOsInterface->pfnSetupAttributeVeBuffer = Mos_SetupAttributeVeBuffer;
874 pOsInterface->pfnGetAttributeVeBuffer = Mos_GetAttributeVeBuffer;
875 pOsInterface->pfnSetupCurrentCmdListAndPool = Mos_SetupCurrentCmdListAndPool;
876 pOsInterface->pfnGmmToMosResourceUsageType = Mos_GmmToMosResourceUsageType;
877 pOsInterface->pfnGetAdapterInfo = Mos_GetAdapterInfo;
878 pOsInterface->pfnIsCompressibelSurfaceSupported = Mos_IsCompressibelSurfaceSupported;
879 pOsInterface->pfnDestroyVirtualEngineState = Mos_DestroyVirtualEngineState;
880 pOsInterface->pfnGetResourceHandle = Mos_GetResourceHandle;
881 pOsInterface->pfnGetRtLogResourceInfo = Mos_GetRtLogResourceInfo;
882 pOsInterface->pfnResetResource = Mos_ResetMosResource;
883 pOsInterface->pfnVerifyMosSurface = Mos_VerifyMosSurface;
884
885 pOsInterface->pfnCreateMhwCpInterface = Create_MhwCpInterface;
886 pOsInterface->pfnDeleteMhwCpInterface = Delete_MhwCpInterface;
887 pOsInterface->pfnInsertCacheSetting = Mos_InsertCacheSetting;
888 pOsInterface->pfnGetCacheSetting = Mos_GetCacheSetting;
889 #if !EMUL
890 pOsInterface->pfnCreateSecureDecodeInterface = Create_SecureDecodeInterface;
891 pOsInterface->pfnDeleteSecureDecodeInterface = Delete_SecureDecodeInterface;
892 #endif
893 #if (_DEBUG || _RELEASE_INTERNAL)
894 pOsInterface->pfnGetVeEngineCount = Mos_GetVeEngineCount;
895 pOsInterface->pfnGetEngineLogicIdByIdx = Mos_GetEngineLogicId;
896 pOsInterface->pfnSetGpuVirtualAddress = MOS_SetGpuVirtualAddress;
897 #endif
898
899 pOsInterface->Component = component;
900 pOsInterface->modulizedMosEnabled = true;
901 pOsInterface->osContextPtr = nullptr;
902 pOsInterface->veDefaultEnable = true;
903
904 pOsInterface->streamIndex = 0;
905 pOsInterface->bSimIsActive = 0;
906
907 eStatus = Mos_Specific_InitInterface(pOsInterface, pOsDriverContext);
908 if (eStatus != MOS_STATUS_SUCCESS)
909 {
910 MOS_OS_ASSERTMESSAGE("Mos_Specific_InitInterface FAILED, errno = 0x%x", eStatus);
911 return eStatus;
912 }
913
914 userSettingPtr = pOsInterface->pfnGetUserSettingInstance(pOsInterface);
915
916 #if MOS_COMMAND_BUFFER_DUMP_SUPPORTED
917 Mos_DumpCommandBufferInit(pOsInterface);
918 #endif // MOS_COMMAND_BUFFER_DUMP_SUPPORTED
919
920 #if (_DEBUG || _RELEASE_INTERNAL)
921 // Report if pre-si environment is in use
922 ReportUserSettingForDebug(
923 userSettingPtr,
924 __MEDIA_USER_FEATURE_VALUE_SIM_IN_USE,
925 pOsInterface->bSimIsActive,
926 MediaUserSetting::Group::Device);
927 #endif
928
929 if (pOsInterface->apoMosEnabled)
930 {
931 pOsInterface->osStreamState->osCpInterface = pOsInterface->osCpInterface;
932 }
933
934 return eStatus;
935 }
936
937 #if !EMUL
Mos_CachePolicyGetMemoryObject(MOS_HW_RESOURCE_DEF MosUsage,GMM_CLIENT_CONTEXT * pGmmClientContext)938 MEMORY_OBJECT_CONTROL_STATE Mos_CachePolicyGetMemoryObject(
939 MOS_HW_RESOURCE_DEF MosUsage,
940 GMM_CLIENT_CONTEXT *pGmmClientContext)
941 {
942 MOS_OS_ASSERT(pGmmClientContext);
943
944 GMM_RESOURCE_USAGE_TYPE usage = GmmResourceUsage[MosUsage];
945 if (pGmmClientContext->GetCachePolicyElement(usage).Initialized)
946 {
947 return pGmmClientContext->CachePolicyGetMemoryObject(nullptr, usage);
948 }
949 else
950 {
951 return pGmmClientContext->GetCachePolicyUsage()[GMM_RESOURCE_USAGE_UNKNOWN].MemoryObjectOverride;
952 }
953 }
954 #endif
955
956 #ifndef SKIP_VE_DEFINE
Mos_CheckVirtualEngineSupported(PMOS_INTERFACE osInterface,bool isNotEncode,bool veDefaultEnable)957 MOS_STATUS Mos_CheckVirtualEngineSupported(
958 PMOS_INTERFACE osInterface,
959 bool isNotEncode,
960 bool veDefaultEnable)
961 {
962 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
963 MediaUserSettingSharedPtr userSettingPtr = nullptr;
964 uint32_t value = 0;
965
966 MOS_OS_CHK_NULL_RETURN(osInterface);
967
968 userSettingPtr = osInterface->pfnGetUserSettingInstance(osInterface);
969 if (isNotEncode)
970 {
971 //UMD Decode Virtual Engine Override
972 // 0: disable. can set to 1 only when KMD VE is enabled.
973 // Default value is 1 if not set this key
974 osInterface->bSupportVirtualEngine = true;
975 #if (_DEBUG || _RELEASE_INTERNAL)
976 ReadUserSettingForDebug(
977 userSettingPtr,
978 value,
979 __MEDIA_USER_FEATURE_VALUE_ENABLE_DECODE_VIRTUAL_ENGINE,
980 MediaUserSetting::Group::Device);
981 osInterface->bSupportVirtualEngine = value ? true : false;
982 #endif
983
984 auto skuTable = osInterface->pfnGetSkuTable(osInterface);
985 MOS_OS_CHK_NULL_RETURN(skuTable);
986 if (osInterface->bSupportVirtualEngine && MEDIA_IS_SKU(skuTable, FtrContextBasedScheduling))
987 {
988 osInterface->ctxBasedScheduling = true;
989 }
990 else
991 {
992 osInterface->ctxBasedScheduling = false;
993 }
994
995 if (osInterface->pfnCheckVirtualEngineSupported)
996 {
997 osInterface->pfnCheckVirtualEngineSupported(osInterface);
998 }
999
1000 osInterface->multiNodeScaling = osInterface->ctxBasedScheduling && MEDIA_IS_SKU(skuTable, FtrVcs2) ? true : false;
1001
1002 #if (_DEBUG || _RELEASE_INTERNAL)
1003 value = osInterface->ctxBasedScheduling ? true : false;
1004 ReportUserSettingForDebug(
1005 userSettingPtr,
1006 __MEDIA_USER_FEATURE_VALUE_ENABLE_DECODE_VE_CTXSCHEDULING,
1007 value,
1008 MediaUserSetting::Group::Device);
1009 #endif
1010 }
1011 else
1012 {
1013 //UMD Encode Virtual Engine Override
1014 osInterface->bSupportVirtualEngine = true;
1015 #if (_DEBUG || _RELEASE_INTERNAL)
1016 ReadUserSettingForDebug(
1017 userSettingPtr,
1018 value,
1019 __MEDIA_USER_FEATURE_VALUE_ENABLE_ENCODE_VIRTUAL_ENGINE,
1020 MediaUserSetting::Group::Device);
1021 osInterface->bSupportVirtualEngine = value ? true : false;
1022 #endif
1023
1024 auto skuTable = osInterface->pfnGetSkuTable(osInterface);
1025 MOS_OS_CHK_NULL_RETURN(skuTable);
1026 if (osInterface->bSupportVirtualEngine && MEDIA_IS_SKU(skuTable, FtrContextBasedScheduling))
1027 {
1028 osInterface->ctxBasedScheduling = true;
1029 }
1030 else
1031 {
1032 osInterface->ctxBasedScheduling = false;
1033 }
1034 osInterface->multiNodeScaling = osInterface->ctxBasedScheduling && MEDIA_IS_SKU(skuTable, FtrVcs2) ? true : false;
1035 }
1036
1037 if (osInterface->apoMosEnabled)
1038 {
1039 // Update ctx based scheduling flag also in APO MOS stream state
1040 MOS_OS_CHK_NULL_RETURN(osInterface->osStreamState);
1041 osInterface->osStreamState->ctxBasedScheduling = osInterface->ctxBasedScheduling;
1042 osInterface->osStreamState->multiNodeScaling = osInterface->multiNodeScaling;
1043 }
1044 MOS_OS_VERBOSEMESSAGE("Virtual Engine Context based SCheduling enabled:%d.\n", osInterface->ctxBasedScheduling);
1045 MOS_OS_VERBOSEMESSAGE("Virtual Engine Multi-node Scaling enabled:%d.\n", osInterface->multiNodeScaling);
1046
1047 return eStatus;
1048 }
1049 #endif // !SKIP_VE_DEFINE
1050
Mos_GetResourceCachePolicyMemoryObject(PMOS_INTERFACE osInterface,PMOS_RESOURCE resource)1051 MEMORY_OBJECT_CONTROL_STATE Mos_GetResourceCachePolicyMemoryObject(
1052 PMOS_INTERFACE osInterface,
1053 PMOS_RESOURCE resource)
1054 {
1055 MEMORY_OBJECT_CONTROL_STATE memObjCtrlState = {};
1056
1057 if(resource == nullptr)
1058 {
1059 MOS_OS_ASSERTMESSAGE("resource == nullptr");
1060 return memObjCtrlState;
1061 }
1062
1063 memObjCtrlState = resource->memObjCtrlState;
1064 if(osInterface == nullptr)
1065 {
1066 MOS_OS_ASSERTMESSAGE("osInterface == nullptr");
1067 return memObjCtrlState;
1068 }
1069
1070 auto gmmClientContext = osInterface->pfnGetGmmClientContext(osInterface);
1071
1072 if(resource->bConvertedFromDDIResource &&
1073 resource->mocsMosResUsageType >= MOS_HW_RESOURCE_USAGE_MEDIA_BATCH_BUFFERS)
1074 {
1075 memObjCtrlState = MosInterface::GetCachePolicyMemoryObject(gmmClientContext, resource->mocsMosResUsageType);
1076 }
1077
1078 if (resource->mocsMosResUsageType >= (sizeof(GmmResourceUsage) / sizeof(GmmResourceUsage[0])))
1079 {
1080 MOS_OS_ASSERTMESSAGE("mocsMosResUsageType out of bound");
1081 resource->mocsMosResUsageType = MOS_CODEC_RESOURCE_USAGE_BEGIN_CODEC;
1082 }
1083 GMM_RESOURCE_USAGE_TYPE usage = GmmResourceUsage[resource->mocsMosResUsageType];
1084 if ((memObjCtrlState.DwordValue == 0)
1085 #if !EMUL
1086 && !gmmClientContext->GetCachePolicyElement(usage).Initialized
1087 #endif
1088 )
1089 {
1090 memObjCtrlState = MosInterface::GetDefaultCachePolicyMemoryObject(gmmClientContext);
1091 }
1092 return memObjCtrlState;
1093 }
1094
Mos_IsAsyncDevice(MOS_STREAM_HANDLE streamState)1095 bool Mos_IsAsyncDevice(
1096 MOS_STREAM_HANDLE streamState)
1097 {
1098 return MosInterface::IsAsyncDevice(streamState);
1099 }
1100
Mos_MosFmtToOsFmt(MOS_FORMAT format)1101 uint32_t Mos_MosFmtToOsFmt(
1102 MOS_FORMAT format)
1103 {
1104 return MosInterface::MosFmtToOsFmt(format);
1105 }
1106
Mos_OsFmtToMosFmt(uint32_t format)1107 MOS_FORMAT Mos_OsFmtToMosFmt(
1108 uint32_t format)
1109 {
1110 return MosInterface::OsFmtToMosFmt(format);
1111 }
1112
Mos_MosFmtToGmmFmt(MOS_FORMAT format)1113 GMM_RESOURCE_FORMAT Mos_MosFmtToGmmFmt(
1114 MOS_FORMAT format)
1115 {
1116 return MosInterface::MosFmtToGmmFmt(format);
1117 }
1118
Mos_GmmFmtToMosFmt(GMM_RESOURCE_FORMAT format)1119 MOS_FORMAT Mos_GmmFmtToMosFmt(
1120 GMM_RESOURCE_FORMAT format)
1121 {
1122 return MosInterface::GmmFmtToMosFmt(format);
1123 }
1124
Mos_WaitForCmdCompletion(MOS_STREAM_HANDLE streamState,GPU_CONTEXT_HANDLE gpuCtx)1125 MOS_STATUS Mos_WaitForCmdCompletion(
1126 MOS_STREAM_HANDLE streamState,
1127 GPU_CONTEXT_HANDLE gpuCtx)
1128 {
1129 return MosInterface::WaitForCmdCompletion(streamState, gpuCtx);
1130 }
1131
Mos_GetResourceArrayIndex(PMOS_RESOURCE resource)1132 uint32_t Mos_GetResourceArrayIndex(
1133 PMOS_RESOURCE resource)
1134 {
1135 return MosInterface::GetResourceArrayIndex(resource);
1136 }
1137
Mos_SetupAttributeVeBuffer(MOS_STREAM_HANDLE streamState,COMMAND_BUFFER_HANDLE cmdBuffer)1138 MOS_STATUS Mos_SetupAttributeVeBuffer(
1139 MOS_STREAM_HANDLE streamState,
1140 COMMAND_BUFFER_HANDLE cmdBuffer)
1141 {
1142 return MosInterface::SetupAttributeVeBuffer(streamState, cmdBuffer);
1143 }
1144
Mos_GetAttributeVeBuffer(COMMAND_BUFFER_HANDLE cmdBuffer)1145 MOS_CMD_BUF_ATTRI_VE *Mos_GetAttributeVeBuffer(
1146 COMMAND_BUFFER_HANDLE cmdBuffer)
1147 {
1148 return MosInterface::GetAttributeVeBuffer(cmdBuffer);
1149 }
1150
Mos_SetupCurrentCmdListAndPool(PMOS_INTERFACE osInterface,MOS_STREAM_HANDLE streamState)1151 MOS_STATUS Mos_SetupCurrentCmdListAndPool(
1152 PMOS_INTERFACE osInterface,
1153 MOS_STREAM_HANDLE streamState)
1154 {
1155 return MosInterface::SetupCurrentCmdListAndPoolFromOsInterface(osInterface, streamState);
1156 }
1157
Mos_GmmToMosResourceUsageType(GMM_RESOURCE_USAGE_TYPE gmmResUsage)1158 MOS_HW_RESOURCE_DEF Mos_GmmToMosResourceUsageType(
1159 GMM_RESOURCE_USAGE_TYPE gmmResUsage)
1160 {
1161 return MosInterface::GmmToMosResourceUsageType(gmmResUsage);
1162 }
1163
Mos_GetAdapterInfo(MOS_STREAM_HANDLE streamState)1164 ADAPTER_INFO *Mos_GetAdapterInfo(
1165 MOS_STREAM_HANDLE streamState)
1166 {
1167 return MosInterface::GetAdapterInfo(streamState);
1168 }
1169
Mos_IsCompressibelSurfaceSupported(MEDIA_FEATURE_TABLE * skuTable)1170 bool Mos_IsCompressibelSurfaceSupported(
1171 MEDIA_FEATURE_TABLE *skuTable)
1172 {
1173 return MosInterface::IsCompressibelSurfaceSupported(skuTable);
1174 }
1175
Mos_DestroyVirtualEngineState(MOS_STREAM_HANDLE streamState)1176 MOS_STATUS Mos_DestroyVirtualEngineState(
1177 MOS_STREAM_HANDLE streamState)
1178 {
1179 return MosInterface::DestroyVirtualEngineState(streamState);
1180 }
1181
Mos_GetResourceHandle(MOS_STREAM_HANDLE streamState,PMOS_RESOURCE osResource)1182 uint64_t Mos_GetResourceHandle(
1183 MOS_STREAM_HANDLE streamState,
1184 PMOS_RESOURCE osResource)
1185 {
1186 return MosInterface::GetResourceHandle(streamState, osResource);
1187 }
1188
Mos_VerifyMosSurface(PMOS_SURFACE mosSurface,bool & bIsValid)1189 MOS_STATUS Mos_VerifyMosSurface(
1190 PMOS_SURFACE mosSurface,
1191 bool& bIsValid)
1192 {
1193 return MosInterface::VerifyMosSurface(mosSurface, bIsValid);
1194 }
1195
Mos_GetRtLogResourceInfo(PMOS_INTERFACE osInterface,PMOS_RESOURCE & osResource,uint32_t & size)1196 void Mos_GetRtLogResourceInfo(
1197 PMOS_INTERFACE osInterface,
1198 PMOS_RESOURCE &osResource,
1199 uint32_t &size)
1200 {
1201 return MosInterface::GetRtLogResourceInfo(osInterface, osResource, size);
1202 }
1203
Mos_ResetMosResource(PMOS_RESOURCE resource)1204 void Mos_ResetMosResource(
1205 PMOS_RESOURCE resource)
1206 {
1207 return MosInterface::MosResetResource(resource);
1208 }
1209
Mos_InsertCacheSetting(CACHE_COMPONENTS id,std::map<uint64_t,MOS_CACHE_ELEMENT> * cacheTablesPtr)1210 bool Mos_InsertCacheSetting(CACHE_COMPONENTS id, std::map<uint64_t, MOS_CACHE_ELEMENT> *cacheTablesPtr)
1211 {
1212 return RegisterCacheSettings(id, cacheTablesPtr);
1213 }
1214
Mos_GetCacheSetting(MOS_COMPONENT id,uint32_t feature,bool bOut,ENGINE_TYPE engineType,MOS_CACHE_ELEMENT & element,bool isHeapSurf)1215 bool Mos_GetCacheSetting(MOS_COMPONENT id, uint32_t feature, bool bOut, ENGINE_TYPE engineType, MOS_CACHE_ELEMENT &element, bool isHeapSurf)
1216 {
1217 return LoadCacheSettings(id, feature, bOut, engineType, element, isHeapSurf);
1218 }
1219
1220 #if (_DEBUG || _RELEASE_INTERNAL)
Mos_GetVeEngineCount(MOS_STREAM_HANDLE streamState)1221 uint8_t Mos_GetVeEngineCount(
1222 MOS_STREAM_HANDLE streamState)
1223 {
1224 return MosInterface::GetVeEngineCount(streamState);
1225 }
1226
Mos_GetEngineLogicId(MOS_STREAM_HANDLE streamState,uint32_t instanceIdx)1227 uint8_t Mos_GetEngineLogicId(
1228 MOS_STREAM_HANDLE streamState,
1229 uint32_t instanceIdx)
1230 {
1231 return MosInterface::GetEngineLogicId(streamState, instanceIdx);
1232 }
1233
MOS_SetGpuVirtualAddress(PMOS_RESOURCE pResource,uint64_t address)1234 MOS_STATUS MOS_SetGpuVirtualAddress(
1235 PMOS_RESOURCE pResource,
1236 uint64_t address)
1237 {
1238 return MosInterface::SetGpuVirtualAddress(pResource, address);
1239 }
1240
1241 #endif
1242
1243 void *MosStreamState::pvSoloContext = nullptr;
1244
1245