Debian Codegraph @

media_driver/media_interface/media_interfaces_m12_tgllp/media_interfaces_g12_tgllp.cpp

raw
1 /*
2 * Copyright (c) 2017-2024, 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 media_interfaces_g12_tgllp.cpp
24 //! \brief Helps with TGL factory creation.
25 //!
26
27 #include "media_interfaces_g12_tgllp.h"
28 #include "codechal_debug.h"
29 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
30 #include "igcodeckrn_g12.h"
31 #endif
32 #include "vp_feature_manager.h"
33 #include "vp_platform_interface_g12_tgllp.h"
34
35 extern template class MediaFactory<uint32_t, MhwInterfaces>;
36 extern template class MediaFactory<uint32_t, MmdDevice>;
37 extern template class MediaFactory<uint32_t, McpyDevice>;
38 extern template class MediaFactory<uint32_t, CodechalDevice>;
39 extern template class MediaFactory<uint32_t, CMHalDevice>;
40 extern template class MediaFactory<uint32_t, VphalDevice>;
41 extern template class MediaFactory<uint32_t, RenderHalDevice>;
42 extern template class MediaFactory<uint32_t, Nv12ToP010Device>;
43 extern template class MediaFactory<uint32_t, DecodeHistogramDevice>;
44
45 static bool tgllpRegisteredVphal =
46 MediaFactory<uint32_t, VphalDevice>::
47 Register<VphalInterfacesG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
48
49 MOS_STATUS VphalInterfacesG12Tgllp::Initialize(
50 PMOS_INTERFACE osInterface,
51 bool bInitVphalState,
52 MOS_STATUS *eStatus,
53 bool clearViewMode)
54 {
55 MOS_OS_CHK_NULL_RETURN(eStatus);
56 MOS_OS_CHK_NULL_RETURN(osInterface);
57 #if LINUX
58 bool bApogeiosEnable = true;
59 MOS_USER_FEATURE_VALUE_DATA UserFeatureData;
60 MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
61
62 UserFeatureData.i32Data = bApogeiosEnable;
63 UserFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
64
65 MOS_UserFeature_ReadValue_ID(
66 nullptr,
67 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_ENABLE_ID,
68 &UserFeatureData,
69 osInterface ? osInterface->pOsContext : nullptr);
70 bApogeiosEnable = UserFeatureData.bData ? true : false;
71 if (bApogeiosEnable)
72 {
73 vp::VpPlatformInterface *vpPlatformInterface = MOS_New(vp::VpPlatformInterfaceG12Tgllp, osInterface);
74 if (nullptr == vpPlatformInterface)
75 {
76 *eStatus = MOS_STATUS_NULL_POINTER;
77 return *eStatus;
78 }
79
80 if (!bInitVphalState)
81 {
82 m_vpPipeline = MOS_New(vp::VpPipeline, osInterface);
83 if (nullptr == m_vpPipeline)
84 {
85 MOS_Delete(vpPlatformInterface);
86 MOS_OS_CHK_NULL_RETURN(m_vpPipeline);
87 }
88 m_vpPlatformInterface = vpPlatformInterface;
89 *eStatus = MOS_STATUS_SUCCESS;
90 return *eStatus;
91 }
92
93 m_vpBase = MOS_New(
94 VpPipelineG12Adapter,
95 osInterface,
96 *vpPlatformInterface,
97 *eStatus);
98 if (nullptr == m_vpBase)
99 {
100 MOS_Delete(vpPlatformInterface);
101 *eStatus = MOS_STATUS_NULL_POINTER;
102 return *eStatus;
103 }
104 }
105 else
106 #endif
107 {
108 m_vpBase = MOS_New(
109 VphalState,
110 osInterface,
111 eStatus);
112 }
113
114 return *eStatus;
115 }
116
117 MOS_STATUS VphalInterfacesG12Tgllp::CreateVpPlatformInterface(
118 PMOS_INTERFACE osInterface,
119 MOS_STATUS * eStatus)
120 {
121 vp::VpPlatformInterface *vpPlatformInterface = MOS_New(vp::VpPlatformInterfaceG12Tgllp, osInterface);
122 if (nullptr == vpPlatformInterface)
123 {
124 *eStatus = MOS_STATUS_NULL_POINTER;
125 }
126 else
127 {
128 m_vpPlatformInterface = vpPlatformInterface;
129 *eStatus = MOS_STATUS_SUCCESS;
130 }
131 return *eStatus;
132 }
133
134 static bool tgllpRegisteredMhw =
135 MediaFactory<uint32_t, MhwInterfaces>::
136 Register<MhwInterfacesG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
137
138 #define PLATFORM_INTEL_TGLLP 15
139 #define GENX_TGLLP 12
140
141 MOS_STATUS MhwInterfacesG12Tgllp::Initialize(
142 CreateParams params,
143 PMOS_INTERFACE osInterface)
144 {
145 #ifdef _MEDIA_RESERVED
146 bool useBaseVdencInterface = false;
147 #if (_DEBUG || _RELEASE_INTERNAL)
148 MOS_USER_FEATURE_VALUE_DATA UserFeatureData;
149 MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
150 MOS_UserFeature_ReadValue_ID(
151 nullptr,
152 __MEDIA_USER_FEATURE_VALUE_MHW_BASE_VDENC_INTERFACE_ID,
153 &UserFeatureData,
154 osInterface ? osInterface->pOsContext : nullptr);
155 useBaseVdencInterface = (UserFeatureData.i32Data == 1) ? true : false;
156 #endif
157 #endif
158 if (osInterface == nullptr)
159 {
160 MHW_ASSERTMESSAGE("The OS interface is not valid!");
161 return MOS_STATUS_INVALID_PARAMETER;
162 }
163 m_osInterface = osInterface;
164
165 auto gtSystemInfo = osInterface->pfnGetGtSystemInfo(osInterface);
166 if (gtSystemInfo == nullptr)
167 {
168 MHW_ASSERTMESSAGE("The OS interface is not valid!");
169 return MOS_STATUS_INVALID_PARAMETER;
170 }
171
172 if ((params.m_isCp == false) && (params.Flags.m_value == 0))
173 {
174 MHW_ASSERTMESSAGE("No MHW interfaces were requested for creation.");
175 return MOS_STATUS_INVALID_PARAMETER;
176 }
177
178 // MHW_CP and MHW_MI must always be created
179 MOS_STATUS status = MOS_STATUS_SUCCESS;
180 m_cpInterface = osInterface->pfnCreateMhwCpInterface(osInterface);
181 if(m_cpInterface == nullptr)
182 {
183 MOS_OS_ASSERTMESSAGE("new osInterface failed");
184 status = MOS_STATUS_NULL_POINTER;
185 goto finish;
186 }
187 m_miInterface = MOS_New(Mi, m_cpInterface, osInterface);
188 if (m_miInterface == nullptr)
189 {
190 MOS_OS_ASSERTMESSAGE("new MI interface failed");
191 status = MOS_STATUS_NULL_POINTER;
192 goto finish;
193 }
194
195 if (params.Flags.m_render)
196 {
197 m_renderInterface =
198 MOS_New(Render, m_miInterface, osInterface, gtSystemInfo, params.m_heapMode);
199 if (m_renderInterface == nullptr || m_renderInterface->m_stateHeapInterface == nullptr)
200 {
201 MOS_OS_ASSERTMESSAGE("new m_renderInterface failed");
202 status = MOS_STATUS_NULL_POINTER;
203 goto finish;
204 }
205 }
206 if (params.Flags.m_stateHeap)
207 {
208 m_stateHeapInterface =
209 MOS_New(StateHeap, osInterface, params.m_heapMode);
210 if (m_stateHeapInterface == nullptr)
211 {
212 MOS_OS_ASSERTMESSAGE("new m_stateHeapInterface failed");
213 status = MOS_STATUS_NULL_POINTER;
214 goto finish;
215 }
216 }
217 if (params.Flags.m_sfc)
218 {
219 m_sfcInterface = MOS_New(Sfc, osInterface);
220 if (m_sfcInterface == nullptr)
221 {
222 MOS_OS_ASSERTMESSAGE("new m_sfcInterface failed");
223 status = MOS_STATUS_NULL_POINTER;
224 goto finish;
225 }
226 }
227 if (params.Flags.m_vebox)
228 {
229 m_veboxInterface = MOS_New(Vebox, osInterface);
230 if (m_veboxInterface == nullptr)
231 {
232 MOS_OS_ASSERTMESSAGE("new m_veboxInterface failed");
233 status = MOS_STATUS_NULL_POINTER;
234 goto finish;
235 }
236 }
237
238 if (params.Flags.m_vdboxAll || params.Flags.m_mfx)
239 {
240 m_mfxInterface =
241 MOS_New(Mfx, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
242 if (m_mfxInterface == nullptr)
243 {
244 MOS_OS_ASSERTMESSAGE("new m_mfxInterface failed");
245 status = MOS_STATUS_NULL_POINTER;
246 goto finish;
247 }
248 }
249 if (params.Flags.m_vdboxAll || params.Flags.m_hcp)
250 {
251 m_hcpInterface =
252 MOS_New(Hcp, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
253 if (m_hcpInterface == nullptr)
254 {
255 MOS_OS_ASSERTMESSAGE("new m_hcpInterface failed");
256 status = MOS_STATUS_NULL_POINTER;
257 goto finish;
258 }
259 }
260 if (params.Flags.m_vdboxAll || params.Flags.m_avp)
261 {
262 m_avpInterface =
263 MOS_New(Avp, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
264 if (m_avpInterface == nullptr)
265 {
266 MOS_OS_ASSERTMESSAGE("new m_avpInterface failed");
267 status = MOS_STATUS_NULL_POINTER;
268 goto finish;
269 }
270 }
271 if (params.Flags.m_vdboxAll || params.Flags.m_huc)
272 {
273 m_hucInterface = MOS_New(Huc, osInterface, m_miInterface, m_cpInterface);
274 if (m_hucInterface == nullptr)
275 {
276 MOS_OS_ASSERTMESSAGE("new m_hucInterface failed");
277 status = MOS_STATUS_NULL_POINTER;
278 goto finish;
279 }
280 }
281 if (params.Flags.m_vdboxAll || params.Flags.m_vdenc)
282 {
283 #ifdef _MEDIA_RESERVED
284 #if (_DEBUG || _RELEASE_INTERNAL)
285 if(useBaseVdencInterface)
286 {
287 m_vdencInterface = MOS_New(MhwVdboxVdencInterfaceG12X, osInterface);
288 if (m_vdencInterface == nullptr)
289 {
290 MOS_OS_ASSERTMESSAGE("new m_vdencInterface failed");
291 status = MOS_STATUS_NULL_POINTER;
292 goto finish;
293 }
294 goto finish;
295 }
296 #endif
297 #endif
298 m_vdencInterface = MOS_New(Vdenc, osInterface);
299 if (m_vdencInterface == nullptr)
300 {
301 MOS_OS_ASSERTMESSAGE("new m_vdencInterface failed");
302 status = MOS_STATUS_NULL_POINTER;
303 goto finish;
304 }
305 }
306
307 if (params.Flags.m_blt)
308 {
309 m_bltInterface = MOS_New(Blt, osInterface);
310 if (m_bltInterface == nullptr)
311 {
312 MOS_OS_ASSERTMESSAGE("new m_bltInterface failed");
313 status = MOS_STATUS_NULL_POINTER;
314 goto finish;
315 }
316 }
317 finish:
318 if (status != MOS_STATUS_SUCCESS)
319 {
320 Destroy();
321 }
322 return status;
323 }
324
325 void MhwInterfacesG12Tgllp::Destroy()
326 {
327 MhwInterfaces::Destroy();
328
329 bool isMhwDestroyed = GetDestroyState();
330 if (!isMhwDestroyed)
331 {
332 MOS_Delete(m_avpInterface);
333 }
334 }
335
336 static bool tgllpRegisteredMmd =
337 MediaFactory<uint32_t, MmdDevice>::
338 Register<MmdDeviceG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
339
340 MOS_STATUS MmdDeviceG12Tgllp::Initialize(
341 PMOS_INTERFACE osInterface,
342 MhwInterfaces *mhwInterfaces)
343 {
344 #define MMD_FAILURE() \
345 { \
346 if (device != nullptr) \
347 { \
348 MOS_Delete(device); \
349 } \
350 return MOS_STATUS_NO_SPACE; \
351 }
352
353 MHW_FUNCTION_ENTER;
354
355 Mmd *device = nullptr;
356
357 if (mhwInterfaces->m_miInterface == nullptr)
358 {
359 MMD_FAILURE();
360 }
361
362 if (mhwInterfaces->m_veboxInterface == nullptr)
363 {
364 MMD_FAILURE();
365 }
366
367 device = MOS_New(Mmd);
368
369 if (device == nullptr)
370 {
371 MMD_FAILURE();
372 }
373
374 if (device->Initialize(
375 osInterface,
376 mhwInterfaces->m_cpInterface,
377 mhwInterfaces->m_miInterface,
378 mhwInterfaces->m_veboxInterface) != MOS_STATUS_SUCCESS)
379 {
380 // Vebox/mi/cp interface will gove control to mmd device, will release will be in destructure func
381 // set as null to avoid double free in driver
382 mhwInterfaces->m_cpInterface = nullptr;
383 mhwInterfaces->m_miInterface = nullptr;
384 mhwInterfaces->m_veboxInterface = nullptr;
385 MMD_FAILURE();
386 }
387
388 m_mmdDevice = device;
389
390 return MOS_STATUS_SUCCESS;
391 }
392
393 MhwInterfaces* MmdDeviceG12Tgllp::CreateMhwInterface(
394 PMOS_INTERFACE osInterface)
395 {
396 MhwInterfaces::CreateParams params;
397 params.Flags.m_vebox = true;
398
399 // the destroy of interfaces happens when the mmd deviced deconstructor funcs
400 MhwInterfaces *mhw = MhwInterfaces::CreateFactory(params, osInterface);
401
402 return mhw;
403 }
404
405 static bool tgllpRegisteredMcpy =
406 MediaFactory<uint32_t, McpyDevice>::
407 Register<McpyDeviceG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
408
409 MOS_STATUS McpyDeviceG12Tgllp::Initialize(
410 PMOS_INTERFACE osInterface)
411 {
412 MHW_FUNCTION_ENTER;
413
414 Mcpy *device = nullptr;
415 MhwInterfaces* mhwInterfaces = nullptr;
416
417 auto deleterOnFailure = [&](bool deleteOsInterface, bool deleteMhwInterface){
418 if (deleteOsInterface && osInterface != nullptr)
419 {
420 if (osInterface->pfnDestroy)
421 {
422 osInterface->pfnDestroy(osInterface, false);
423 }
424 MOS_FreeMemory(osInterface);
425 }
426
427 if (deleteMhwInterface && mhwInterfaces != nullptr)
428 {
429 mhwInterfaces->Destroy();
430 MOS_Delete(mhwInterfaces);
431 }
432
433 MOS_Delete(device);
434 };
435
436 device = MOS_New(Mcpy);
437 if (device == nullptr)
438 {
439 deleterOnFailure(true, false);
440 return MOS_STATUS_NO_SPACE;
441 }
442
443 mhwInterfaces = CreateMhwInterface(osInterface);
444 if (mhwInterfaces->m_miInterface == nullptr ||
445 mhwInterfaces->m_veboxInterface == nullptr ||
446 mhwInterfaces->m_bltInterface == nullptr)
447 {
448 deleterOnFailure(true, true);
449 return MOS_STATUS_NO_SPACE;
450 }
451
452 if (device->Initialize(
453 osInterface, mhwInterfaces) != MOS_STATUS_SUCCESS)
454 {
455 deleterOnFailure(false, false);
456 MOS_OS_CHK_STATUS_RETURN(MOS_STATUS_UNINITIALIZED);
457 }
458
459 m_mcpyDevice = device;
460
461 return MOS_STATUS_SUCCESS;
462 }
463
464 MhwInterfaces* McpyDeviceG12Tgllp::CreateMhwInterface(
465 PMOS_INTERFACE osInterface)
466 {
467 MhwInterfaces::CreateParams params;
468 params.Flags.m_vebox = true;
469 params.Flags.m_blt = true;
470
471 // the destroy of interfaces happens when the mcpy deviced deconstructor funcs
472 MhwInterfaces *mhw = MhwInterfaces::CreateFactory(params, osInterface);
473
474 return mhw;
475 }
476
477 static bool tgllpRegisteredNv12ToP010 =
478 MediaFactory<uint32_t, Nv12ToP010Device>::
479 Register<Nv12ToP010DeviceG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
480
481 MOS_STATUS Nv12ToP010DeviceG12Tgllp::Initialize(
482 PMOS_INTERFACE osInterface)
483 {
484 CODECHAL_PUBLIC_ASSERTMESSAGE("Not support Nv12 to P010 interfaces.")
485
486 return MOS_STATUS_INVALID_PARAMETER;
487 }
488
489 static bool tglRegisteredCodecHal =
490 MediaFactory<uint32_t, CodechalDevice>::
491 Register<CodechalInterfacesG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
492
493 MOS_STATUS CodechalInterfacesG12Tgllp::Initialize(
494 void *standardInfo,
495 void *settings,
496 MhwInterfaces *mhwInterfaces,
497 PMOS_INTERFACE osInterface)
498 {
499 if (standardInfo == nullptr ||
500 mhwInterfaces == nullptr ||
501 osInterface == nullptr)
502 {
503 CODECHAL_PUBLIC_ASSERTMESSAGE("CodecHal device is not valid!");
504 return MOS_STATUS_INVALID_PARAMETER;
505 }
506 PCODECHAL_STANDARD_INFO info = ((PCODECHAL_STANDARD_INFO)standardInfo);
507 CODECHAL_FUNCTION CodecFunction = info->CodecFunction;
508
509 bool disableScalability = false;
510 if(MEDIA_IS_SKU(osInterface->pfnGetSkuTable(osInterface), FtrLocalMemory))
511 {
512 PLATFORM platform = {};
513 osInterface->pfnGetPlatform(osInterface, &platform);
514 if((platform.usDeviceID != 0x4905)
515 && (platform.usDeviceID != 0x4906)
516 && (platform.usDeviceID != 0x4908))
517 {
518 disableScalability = true;
519 }
520 }
521 CodechalHwInterface *hwInterface = MOS_New(Hw, osInterface, CodecFunction, mhwInterfaces, disableScalability);
522 if (hwInterface == nullptr)
523 {
524 CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterface is not valid!");
525 return MOS_STATUS_NO_SPACE;
526 }
527 hwInterface->m_hwInterfaceNext = MOS_New(CodechalHwInterfaceNext, osInterface);
528 if (hwInterface->m_hwInterfaceNext == nullptr)
529 {
530 MOS_Delete(hwInterface);
531 CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterfaceNext is not valid!");
532 return MOS_STATUS_NO_SPACE;
533 }
534 hwInterface->m_hwInterfaceNext->pfnCreateDecodeSinglePipe = decode::DecodeScalabilitySinglePipe::CreateDecodeSinglePipe;
535 hwInterface->m_hwInterfaceNext->pfnCreateDecodeMultiPipe = decode::DecodeScalabilityMultiPipe::CreateDecodeMultiPipe;
536 hwInterface->m_hwInterfaceNext->SetMediaSfcInterface(hwInterface->GetMediaSfcInterface());
537
538 #if USE_CODECHAL_DEBUG_TOOL
539 CodechalDebugInterface *debugInterface = MOS_New(CodechalDebugInterface);
540 if (debugInterface == nullptr)
541 {
542 MOS_Delete(hwInterface);
543 CODECHAL_PUBLIC_ASSERTMESSAGE("debugInterface is not valid!");
544 return MOS_STATUS_NO_SPACE;
545 }
546 if (debugInterface->Initialize(hwInterface, CodecFunction) != MOS_STATUS_SUCCESS)
547 {
548 MOS_Delete(hwInterface);
549 mhwInterfaces->SetDestroyState(true);
550 MOS_Delete(debugInterface);
551 CODECHAL_PUBLIC_ASSERTMESSAGE("Debug interface creation failed!");
552 return MOS_STATUS_INVALID_PARAMETER;
553 }
554 #else
555 CodechalDebugInterface *debugInterface = nullptr;
556 #endif // USE_CODECHAL_DEBUG_TOOL
557
558 auto release_func = [&]()
559 {
560 MOS_Delete(hwInterface);
561 #if USE_CODECHAL_DEBUG_TOOL
562 MOS_Delete(debugInterface);
563 #endif // USE_CODECHAL_DEBUG_TOOL
564 };
565
566 if (CodecHalIsDecode(CodecFunction))
567 {
568 #ifdef _MPEG2_DECODE_SUPPORTED
569 if (info->Mode == CODECHAL_DECODE_MODE_MPEG2IDCT ||
570 info->Mode == CODECHAL_DECODE_MODE_MPEG2VLD)
571 {
572 #ifdef _MEDIA_RESERVED
573 bool apogeiosEnable = false;
574 MOS_USER_FEATURE_VALUE_DATA userFeatureData;
575 MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
576
577 userFeatureData.i32Data = apogeiosEnable;
578 userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
579 MOS_UserFeature_ReadValue_ID(
580 nullptr,
581 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_MPEG2D_ENABLE_ID,
582 &userFeatureData,
583 hwInterface->GetOsInterface()->pOsContext);
584 apogeiosEnable = userFeatureData.bData ? true : false;
585
586 if (apogeiosEnable)
587 {
588 m_codechalDevice = MOS_New(DecodeMpeg2PipelineAdapterM12, hwInterface, debugInterface);
589 }
590 else
591 #endif
592 {
593 m_codechalDevice = MOS_New(Decode::Mpeg2, hwInterface, debugInterface, info);
594 }
595 }
596 else
597 #endif
598 #ifdef _VC1_DECODE_SUPPORTED
599 if (info->Mode == CODECHAL_DECODE_MODE_VC1IT ||
600 info->Mode == CODECHAL_DECODE_MODE_VC1VLD)
601 {
602 m_codechalDevice = MOS_New(Decode::Vc1, hwInterface, debugInterface, info);
603 }
604 else
605 #endif
606 #ifdef _AVC_DECODE_SUPPORTED
607 if (info->Mode == CODECHAL_DECODE_MODE_AVCVLD)
608 {
609 bool apogeiosEnable = false;
610 #ifdef _MEDIA_RESERVED
611 MOS_USER_FEATURE_VALUE_DATA userFeatureData;
612 MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
613
614 userFeatureData.i32Data = apogeiosEnable;
615 userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
616 MOS_UserFeature_ReadValue_ID(
617 nullptr,
618 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_AVCD_ENABLE_ID,
619 &userFeatureData,
620 hwInterface->GetOsInterface()->pOsContext);
621 apogeiosEnable = userFeatureData.bData ? true : false;
622
623 if (apogeiosEnable)
624 {
625 m_codechalDevice = MOS_New(DecodeAvcPipelineAdapterM12, hwInterface, debugInterface);
626 }
627 else
628 #endif
629 {
630 m_codechalDevice = MOS_New(Decode::Avc, hwInterface, debugInterface, info);
631 }
632
633 if (m_codechalDevice == nullptr)
634 {
635 CODECHAL_PUBLIC_ASSERTMESSAGE("Failed to create decode device!");
636 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NO_SPACE, release_func);
637 }
638 #ifdef _DECODE_PROCESSING_SUPPORTED
639
640 #if defined(ENABLE_KERNELS) && defined(_FULL_OPEN_SOURCE)
641 ((CodechalSetting *)settings)->downsamplingHinted = false;
642 #endif
643
644 if (settings != nullptr && ((CodechalSetting *)settings)->downsamplingHinted && !apogeiosEnable)
645 {
646 CodechalDecode *decoder = dynamic_cast<CodechalDecode *>(m_codechalDevice);
647 if (decoder == nullptr)
648 {
649 CODECHAL_PUBLIC_ASSERTMESSAGE("Failed to create decode device!");
650 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NO_SPACE, release_func);
651 }
652 FieldScalingInterface *fieldScalingInterface =
653 MOS_New(Decode::FieldScaling, hwInterface);
654 if (fieldScalingInterface == nullptr)
655 {
656 CODECHAL_PUBLIC_ASSERTMESSAGE("Failed to create field scaling interface!");
657 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NO_SPACE, release_func);
658 }
659 decoder->m_fieldScalingInterface = fieldScalingInterface;
660 }
661 #endif
662 }
663 else
664 #endif
665 #ifdef _JPEG_DECODE_SUPPORTED
666 if (info->Mode == CODECHAL_DECODE_MODE_JPEG)
667 {
668 bool apogeiosEnable = false;
669 #ifdef _MEDIA_RESERVED
670 MOS_USER_FEATURE_VALUE_DATA userFeatureData;
671 MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
672
673 userFeatureData.i32Data = apogeiosEnable;
674 userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
675 MOS_UserFeature_ReadValue_ID(
676 nullptr,
677 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_JPEGD_ENABLE_ID,
678 &userFeatureData,
679 hwInterface->GetOsInterface()->pOsContext);
680 apogeiosEnable = userFeatureData.bData ? true : false;
681
682 if (apogeiosEnable)
683 {
684 m_codechalDevice = MOS_New(DecodeJpegPipelineAdapterM12, hwInterface, debugInterface);
685 }
686 else
687 #endif
688 {
689 m_codechalDevice = MOS_New(Decode::Jpeg, hwInterface, debugInterface, info);
690 }
691 }
692 else
693 #endif
694 #ifdef _VP8_DECODE_SUPPORTED
695 if (info->Mode == CODECHAL_DECODE_MODE_VP8VLD)
696 {
697 m_codechalDevice = MOS_New(Decode::Vp8, hwInterface, debugInterface, info);
698 }
699 else
700 #endif
701 #ifdef _HEVC_DECODE_SUPPORTED
702 if (info->Mode == CODECHAL_DECODE_MODE_HEVCVLD)
703 {
704 #ifdef _MEDIA_RESERVED
705 bool apogeiosEnable = false;
706 MOS_USER_FEATURE_VALUE_DATA userFeatureData;
707 MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
708
709 userFeatureData.i32Data = apogeiosEnable;
710 userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
711 MOS_UserFeature_ReadValue_ID(
712 nullptr,
713 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_HEVCD_ENABLE_ID,
714 &userFeatureData,
715 hwInterface->GetOsInterface()->pOsContext);
716 apogeiosEnable = userFeatureData.bData ? true : false;
717
718 if (apogeiosEnable)
719 {
720 m_codechalDevice = MOS_New(DecodeHevcPipelineAdapterM12, hwInterface, debugInterface);
721 }
722 else
723 #endif
724 {
725 m_codechalDevice = MOS_New(Decode::Hevc, hwInterface, debugInterface, info);
726 }
727 }
728 else
729 #endif
730 #ifdef _VP9_DECODE_SUPPORTED
731 if (info->Mode == CODECHAL_DECODE_MODE_VP9VLD)
732 {
733 #ifdef _MEDIA_RESERVED
734 bool apogeiosEnable = false;
735 MOS_USER_FEATURE_VALUE_DATA userFeatureData;
736 MOS_ZeroMemory(&userFeatureData, sizeof(userFeatureData));
737
738 userFeatureData.i32Data = apogeiosEnable;
739 userFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
740 MOS_UserFeature_ReadValue_ID(
741 nullptr,
742 __MEDIA_USER_FEATURE_VALUE_APOGEIOS_VP9D_ENABLE_ID,
743 &userFeatureData,
744 hwInterface->GetOsInterface()->pOsContext);
745
746 apogeiosEnable = userFeatureData.bData ? true : false;
747
748 if (apogeiosEnable)
749 {
750 m_codechalDevice = MOS_New(DecodeVp9PipelineAdapterG12, hwInterface, debugInterface);
751 }
752 else
753 #endif
754 {
755 m_codechalDevice = MOS_New(Decode::Vp9, hwInterface, debugInterface, info);
756 }
757 }
758 else
759 #endif
760 #ifdef _AV1_DECODE_SUPPORTED
761 if (info->Mode == CODECHAL_DECODE_MODE_AV1VLD)
762 {
763 m_codechalDevice = MOS_New(Decode::Av1, hwInterface, debugInterface);
764 }
765 else
766 #endif
767 {
768 CODECHAL_PUBLIC_ASSERTMESSAGE("Decode mode requested invalid!");
769 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
770 }
771
772 if (m_codechalDevice == nullptr)
773 {
774 CODECHAL_PUBLIC_ASSERTMESSAGE("Decoder device creation failed!");
775 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NO_SPACE, release_func);
776 }
777 }
778 else if (CodecHalIsEncode(CodecFunction))
779 {
780 CodechalEncoderState *encoder = nullptr;
781 bool mdfSupported = true;
782 #if (_DEBUG || _RELEASE_INTERNAL)
783 MOS_USER_FEATURE_VALUE_DATA UserFeatureData;
784 MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
785 MOS_UserFeature_ReadValue_ID(
786 nullptr,
787 __MEDIA_USER_FEATURE_VALUE_HEVC_ENCODE_MDF_DISABLE_ID,
788 &UserFeatureData,
789 hwInterface->GetOsInterface()->pOsContext);
790 mdfSupported = (UserFeatureData.i32Data == 1) ? false : true;
791 #endif // (_DEBUG || _RELEASE_INTERNAL)
792 #if defined (_AVC_ENCODE_VME_SUPPORTED) || defined (_AVC_ENCODE_VDENC_SUPPORTED)
793 if (info->Mode == CODECHAL_ENCODE_MODE_AVC)
794 {
795 if (CodecHalUsesVdencEngine(info->CodecFunction))
796 {
797 #ifdef _AVC_ENCODE_VDENC_SUPPORTED
798 encoder = MOS_New(Encode::AvcVdenc, hwInterface, debugInterface, info);
799 #endif
800 }
801 else
802 {
803 #ifdef _AVC_ENCODE_VME_SUPPORTED
804 encoder = MOS_New(Encode::AvcEnc, hwInterface, debugInterface, info);
805 #endif
806 }
807 if (encoder == nullptr)
808 {
809 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
810 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
811 }
812 else
813 {
814 m_codechalDevice = encoder;
815 }
816 }
817 else
818 #endif
819 #ifdef _VP9_ENCODE_VDENC_SUPPORTED
820 if (info->Mode == CODECHAL_ENCODE_MODE_VP9)
821 {
822 encoder = MOS_New(Encode::Vp9, hwInterface, debugInterface, info);
823 if (encoder == nullptr)
824 {
825 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
826 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
827 }
828 else
829 {
830 m_codechalDevice = encoder;
831 }
832 }
833 else
834 #endif
835 #ifdef _MPEG2_ENCODE_VME_SUPPORTED
836 if (info->Mode == CODECHAL_ENCODE_MODE_MPEG2)
837 {
838 // Setup encode interface functions
839 encoder = MOS_New(Encode::Mpeg2, hwInterface, debugInterface, info);
840 if (encoder == nullptr)
841 {
842 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode allocation failed!");
843 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
844 }
845 else
846 {
847 m_codechalDevice = encoder;
848 }
849 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
850 encoder->m_kernelBase = (uint8_t*)IGCODECKRN_G12;
851 #endif
852 }
853 else
854 #endif
855 #ifdef _JPEG_ENCODE_SUPPORTED
856 if (info->Mode == CODECHAL_ENCODE_MODE_JPEG)
857 {
858 encoder = MOS_New(Encode::Jpeg, hwInterface, debugInterface, info);
859 if (encoder == nullptr)
860 {
861 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
862 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
863 }
864 else
865 {
866 m_codechalDevice = encoder;
867 }
868 encoder->m_vdboxOneDefaultUsed = true;
869 }
870 else
871 #endif
872 #if defined (_HEVC_ENCODE_VME_SUPPORTED) || defined (_HEVC_ENCODE_VDENC_SUPPORTED)
873 if (info->Mode == CODECHAL_ENCODE_MODE_HEVC)
874 {
875 if (CodecHalUsesVdencEngine(info->CodecFunction))
876 {
877 #ifdef _HEVC_ENCODE_VDENC_SUPPORTED
878 encoder = MOS_New(Encode::HevcVdenc, hwInterface, debugInterface, info);
879 #endif
880 }
881 else
882 {
883 #ifdef _HEVC_ENCODE_VME_SUPPORTED
884 if (!mdfSupported)
885 {
886 encoder = MOS_New(Encode::HevcEnc, hwInterface, debugInterface, info);
887 }
888 else
889 {
890 encoder = MOS_New(Encode::HevcMbenc, hwInterface, debugInterface, info);
891 }
892 #endif
893 }
894
895 if (encoder == nullptr)
896 {
897 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
898 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
899 }
900 else
901 {
902 m_codechalDevice = encoder;
903 }
904 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
905 encoder->m_kernelBase = (uint8_t*)IGCODECKRN_G12;
906 #endif
907 }
908 else
909 #endif
910 {
911 CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported encode function requested.");
912 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
913 }
914 #if defined(ENABLE_KERNELS) && !defined(_FULL_OPEN_SOURCE)
915 if (info->Mode != CODECHAL_ENCODE_MODE_JPEG)
916 {
917 // use MDF RT to program CSC kernel for HEVC dual pipe
918 if (((mdfSupported && info->Mode == CODECHAL_ENCODE_MODE_HEVC)) && !CodecHalUsesVdencEngine(info->CodecFunction))
919 {
920 if ((encoder->m_cscDsState = MOS_New(Encode::CscDsMdf, encoder)) == nullptr)
921 {
922 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
923 }
924 }
925 else
926 {
927 // Create CSC and Downscaling interface
928 if ((encoder->m_cscDsState = MOS_New(Encode::CscDs, encoder)) == nullptr)
929 {
930 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
931 }
932 }
933 }
934 #endif
935 }
936 else
937 {
938 CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported codec function requested.");
939 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
940 }
941
942 return MOS_STATUS_SUCCESS;
943 }
944
945 static bool tgllpRegisteredCMHal =
946 MediaFactory<uint32_t, CMHalDevice>::
947 Register<CMHalInterfacesG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
948
949 MOS_STATUS CMHalInterfacesG12Tgllp::Initialize(CM_HAL_STATE *pCmState)
950 {
951 if (pCmState == nullptr)
952 {
953 MHW_ASSERTMESSAGE("pCmState is nullptr.")
954 return MOS_STATUS_INVALID_PARAMETER;
955 }
956
957 m_cmhalDevice = MOS_New(CMHal, pCmState);
958 if (m_cmhalDevice == nullptr)
959 {
960 MHW_ASSERTMESSAGE("Create CM Hal interfaces failed.")
961 return MOS_STATUS_NO_SPACE;
962 }
963
964 m_cmhalDevice->SetGenPlatformInfo(PLATFORM_INTEL_TGLLP, PLATFORM_INTEL_GT2, "TGLLP");
965 uint32_t cisaIDs[] = {GENX_TGLLP};
966 m_cmhalDevice->AddSupportedCisaIDs(cisaIDs, sizeof(cisaIDs)/sizeof(uint32_t));
967 m_cmhalDevice->m_l3Plane = TGL_L3_PLANE;
968 m_cmhalDevice->m_l3ConfigCount = TGL_L3_CONFIG_NUM;
969 return MOS_STATUS_SUCCESS;
970 }
971
972 static bool tgllpRegisteredRenderHal =
973 MediaFactory<uint32_t, RenderHalDevice>::
974 Register<RenderHalInterfacesG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
975
976 MOS_STATUS RenderHalInterfacesG12Tgllp::Initialize()
977 {
978 m_renderhalDevice = MOS_New(XRenderHal);
979 if (m_renderhalDevice == nullptr)
980 {
981 MHW_ASSERTMESSAGE("Create Render Hal interfaces failed.")
982 return MOS_STATUS_NO_SPACE;
983 }
984 return MOS_STATUS_SUCCESS;
985 }
986
987 static bool tgllpRegisteredDecodeHistogram =
988 MediaFactory<uint32_t, DecodeHistogramDevice>::
989 Register<DecodeHistogramDeviceG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
990
991 MOS_STATUS DecodeHistogramDeviceG12Tgllp::Initialize(
992 CodechalHwInterface *hwInterface,
993 PMOS_INTERFACE osInterface)
994 {
995 // For Gen12+, histogram is rendered inline SFC and just in the same context as decode.
996 // Create a bass class instance and will do nothing.
997 m_decodeHistogramDevice = MOS_New(DecodeHistogramG12, hwInterface, osInterface);
998
999 if (m_decodeHistogramDevice == nullptr)
1000 {
1001 MHW_ASSERTMESSAGE("Create decode histogram interfaces failed.")
1002 return MOS_STATUS_NO_SPACE;
1003 }
1004
1005 return MOS_STATUS_SUCCESS;
1006 }
1007
1008 #define IP_VERSION_M12_0 0x1200
1009 static bool tglRegisteredHwInfo =
1010 MediaFactory<uint32_t, MediaInterfacesHwInfoDevice>::Register<MediaInterfacesHwInfoDeviceG12Tgllp>((uint32_t)IGFX_TIGERLAKE_LP);
1011 MOS_STATUS MediaInterfacesHwInfoDeviceG12Tgllp::Initialize(PLATFORM platform)
1012 {
1013 m_hwInfo.SetDeviceInfo(IP_VERSION_M12_0, platform.usRevId);
1014 return MOS_STATUS_SUCCESS;
1015 }