1 /*===================== begin_copyright_notice ==================================
2 
3 # Copyright (c) 2021-2024, Intel Corporation
4 
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 # OTHER DEALINGS IN THE SOFTWARE.
22 
23 ======================= end_copyright_notice ==================================*/
24 //!
25 //! \file     media_interfaces_dg2.cpp
26 
27 //! \brief    Helps with DG2 factory creation.
28 //!
29 
30 #include "media_interfaces_dg2.h"
31 #include "codechal.h"
32 #include "codechal_debug.h"
33 #if defined(ENABLE_KERNELS) && defined(_MEDIA_RESERVED)
34 #include "cm_gpucopy_kernel_xe_hpm.h"
35 #include "cm_gpuinit_kernel_xe_hpm.h"
36 #else
37 unsigned int iGPUCopy_kernel_isa_size_dg2 = 0;
38 unsigned int iGPUInit_kernel_isa_size_dg2 = 0;
39 unsigned char *pGPUCopy_kernel_isa_dg2 = nullptr;
40 unsigned char *pGPUInit_kernel_isa_dg2 = nullptr;
41 #endif
42 #include "vp_pipeline_adapter_xe_hpm.h"
43 #include "vp_platform_interface_xe_hpm.h"
44 #include "vp_kernel_config_g12_base.h"
45 #include "encode_av1_vdenc_pipeline_adapter_xe_hpm.h"
46 
47 #if defined(ENABLE_KERNELS)
48 #include "igvpkrn_xe_hpg.h"
49 #include "igvpkrn_xe_hpg_cmfcpatch.h"
50 #if !defined(_FULL_OPEN_SOURCE)
51 #include "igvpkrn_isa_xe_hpg.h"
52 #endif
53 #endif
54 #include "codechal_hw_next_xe_hpm.h"
55 
56 using namespace mhw::vdbox::avp::xe_hpm;
57 using namespace mhw::vdbox::vdenc::xe_hpm;
58 using namespace mhw::vdbox::huc::xe_hpm;
59 
60 extern template class MediaFactory<uint32_t, MhwInterfaces>;
61 extern template class MediaFactory<uint32_t, MmdDevice>;
62 extern template class MediaFactory<uint32_t, McpyDevice>;
63 extern template class MediaFactory<uint32_t, CodechalDevice>;
64 extern template class MediaFactory<uint32_t, CodechalDeviceNext>;
65 extern template class MediaFactory<uint32_t, CMHalDevice>;
66 extern template class MediaFactory<uint32_t, VphalDevice>;
67 extern template class MediaFactory<uint32_t, RenderHalDevice>;
68 extern template class MediaFactory<uint32_t, Nv12ToP010Device>;
69 extern template class MediaFactory<uint32_t, DecodeHistogramDevice>;
70 extern template class MediaFactory<uint32_t, MediaInterfacesHwInfoDevice>;
71 
72 // Swith to use new media factory template
73 extern template class MediaFactory<uint32_t, MhwInterfacesNext>;
74 
75 static bool dg2RegisteredVphal =
76 MediaFactory<uint32_t, VphalDevice>::
77 Register<VphalInterfacesXe_Hpm>((uint32_t)IGFX_DG2);
78 
Initialize(PMOS_INTERFACE osInterface,bool bInitVphalState,MOS_STATUS * eStatus,bool clearViewMode)79 MOS_STATUS VphalInterfacesXe_Hpm::Initialize(
80     PMOS_INTERFACE  osInterface,
81     bool            bInitVphalState,
82     MOS_STATUS      *eStatus,
83     bool            clearViewMode)
84 {
85     bool bApogeiosEnable = true;
86     MOS_USER_FEATURE_VALUE_DATA         UserFeatureData;
87     MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
88 
89     UserFeatureData.i32Data = bApogeiosEnable;
90     UserFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE;
91 
92     MOS_UserFeature_ReadValue_ID(
93         nullptr,
94         __MEDIA_USER_FEATURE_VALUE_APOGEIOS_ENABLE_ID,
95         &UserFeatureData,
96         osInterface->pOsContext);
97     bApogeiosEnable = UserFeatureData.bData ? true : false;
98     if (bApogeiosEnable)
99     {
100         vp::VpPlatformInterface *vpPlatformInterface = MOS_New(vp::VpPlatformInterfaceXe_Hpm, osInterface);
101         if (nullptr == vpPlatformInterface)
102         {
103             *eStatus = MOS_STATUS_NULL_POINTER;
104             return *eStatus;
105         }
106 
107         InitPlatformKernelBinary(vpPlatformInterface);
108 
109         if (!bInitVphalState)
110         {
111             m_vpPipeline = MOS_New(vp::VpPipeline, osInterface);
112             if (nullptr == m_vpPipeline)
113             {
114                 MOS_Delete(vpPlatformInterface);
115                 MOS_OS_CHK_NULL_RETURN(m_vpPipeline);
116             }
117             m_vpPlatformInterface = vpPlatformInterface;
118             *eStatus = MOS_STATUS_SUCCESS;
119             return *eStatus;
120         }
121 
122         m_vpBase = MOS_New(
123             VpPipelineAdapterXe_Hpm,
124             osInterface,
125             *vpPlatformInterface,
126             *eStatus);
127         if (nullptr == m_vpBase)
128         {
129             MOS_Delete(vpPlatformInterface);
130             *eStatus = MOS_STATUS_NULL_POINTER;
131             return *eStatus;
132         }
133         m_isNextEnabled = true;
134     }
135     else
136     {
137         m_vpBase = MOS_New(
138             VphalState,
139             osInterface,
140             eStatus);
141     }
142 
143     return *eStatus;
144 }
145 
CreateVpPlatformInterface(PMOS_INTERFACE osInterface,MOS_STATUS * eStatus)146 MOS_STATUS VphalInterfacesXe_Hpm::CreateVpPlatformInterface(
147     PMOS_INTERFACE osInterface,
148     MOS_STATUS *   eStatus)
149 {
150     vp::VpPlatformInterface *vpPlatformInterface = MOS_New(vp::VpPlatformInterfaceXe_Hpm, osInterface);
151     if (nullptr == vpPlatformInterface)
152     {
153         *eStatus = MOS_STATUS_NULL_POINTER;
154     }
155     else
156     {
157         InitPlatformKernelBinary(vpPlatformInterface);
158 
159         m_vpPlatformInterface = vpPlatformInterface;
160         *eStatus              = MOS_STATUS_SUCCESS;
161     }
162     return *eStatus;
163 }
164 
InitPlatformKernelBinary(vp::VpPlatformInterface * & vpPlatformInterface)165 void VphalInterfacesXe_Hpm::InitPlatformKernelBinary(
166     vp::VpPlatformInterface  *&vpPlatformInterface)
167 {
168     static vp::VpKernelConfigG12_Base kernelConfig;
169     vpPlatformInterface->SetKernelConfig(&kernelConfig);
170 #if defined(ENABLE_KERNELS)
171     vpPlatformInterface->SetVpFCKernelBinary(
172                         IGVPKRN_XE_HPG,
173                         IGVPKRN_XE_HPG_SIZE,
174                         IGVPKRN_XE_HPG_CMFCPATCH,
175                         IGVPKRN_XE_HPG_CMFCPATCH_SIZE);
176 #if !defined(_FULL_OPEN_SOURCE)
177     vpPlatformInterface->AddVpIsaKernelEntryToList(IGVP3DLUT_GENERATION_XE_HPG, IGVP3DLUT_GENERATION_XE_HPG_SIZE);
178     vpPlatformInterface->AddVpIsaKernelEntryToList(IGVPHVS_DENOISE_XE_HPG, IGVPHVS_DENOISE_XE_HPG_SIZE);
179 #endif
180 #endif
181 }
182 
183 static bool dg2RegisteredMhw =
184     MediaFactory<uint32_t, MhwInterfaces>::
185     Register<MhwInterfacesDg2>((uint32_t)IGFX_DG2);
186 
187 #define PLATFORM_INTEL_DG2    22
188 #define GENX_XEHP              11
189 #define GENX_DG2              13
190 
Initialize(CreateParams params,PMOS_INTERFACE osInterface)191 MOS_STATUS MhwInterfacesDg2::Initialize(
192     CreateParams params,
193     PMOS_INTERFACE osInterface)
194 {
195     if (osInterface == nullptr)
196     {
197         MHW_ASSERTMESSAGE("The OS interface is not valid!");
198         return MOS_STATUS_INVALID_PARAMETER;
199     }
200     m_osInterface = osInterface;
201 
202     auto gtSystemInfo = osInterface->pfnGetGtSystemInfo(osInterface);
203     if (gtSystemInfo == nullptr)
204     {
205         MHW_ASSERTMESSAGE("The OS interface is not valid!");
206         return MOS_STATUS_INVALID_PARAMETER;
207     }
208 
209     if ((params.m_isCp == false) && (params.Flags.m_value == 0))
210     {
211         MHW_ASSERTMESSAGE("No MHW interfaces were requested for creation.");
212         return MOS_STATUS_INVALID_PARAMETER;
213     }
214 
215     // MHW_CP and MHW_MI must always be created
216     MOS_STATUS status;
217     m_cpInterface = osInterface->pfnCreateMhwCpInterface(osInterface);
218     MHW_MI_CHK_NULL(m_cpInterface);
219     m_miInterface = MOS_New(Mi, m_cpInterface, osInterface);
220 
221     if (params.Flags.m_render)
222     {
223         m_renderInterface =
224             MOS_New(Render, m_miInterface, osInterface, gtSystemInfo, params.m_heapMode);
225     }
226     if (params.Flags.m_stateHeap)
227     {
228         m_stateHeapInterface =
229             MOS_New(StateHeap, osInterface, params.m_heapMode);
230     }
231     if (params.Flags.m_sfc)
232     {
233         m_sfcInterface = MOS_New(Sfc, osInterface);
234     }
235     if (params.Flags.m_vebox)
236     {
237         m_veboxInterface = MOS_New(Vebox, osInterface);
238     }
239 
240     if (params.Flags.m_vdboxAll || params.Flags.m_mfx)
241     {
242         m_mfxInterface =
243             MOS_New(Mfx, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
244     }
245     if (params.Flags.m_vdboxAll || params.Flags.m_hcp)
246     {
247         m_hcpInterface =
248             MOS_New(Hcp, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
249     }
250     if (params.Flags.m_vdboxAll || params.Flags.m_avp)
251     {
252         m_avpInterface =
253             MOS_New(Avp, osInterface, m_miInterface, m_cpInterface, params.m_isDecode);
254     }
255     if (params.Flags.m_vdboxAll || params.Flags.m_huc)
256     {
257         m_hucInterface = MOS_New(Huc, osInterface, m_miInterface, m_cpInterface);
258     }
259     if (params.Flags.m_vdboxAll || params.Flags.m_vdenc)
260     {
261         m_vdencInterface = MOS_New(Vdenc, osInterface);
262     }
263     if (params.Flags.m_blt)
264     {
265         m_bltInterface = MOS_New(Blt, osInterface);
266     }
267 
268     return MOS_STATUS_SUCCESS;
269 }
270 
271 #ifdef _MMC_SUPPORTED
272 static bool dg2RegisteredMmd =
273     MediaFactory<uint32_t, MmdDevice>::
274     Register<MmdDeviceXe_Hpm>((uint32_t)IGFX_DG2);
275 
Initialize(PMOS_INTERFACE osInterface,MhwInterfaces * mhwInterfaces)276 MOS_STATUS MmdDeviceXe_Hpm::Initialize(
277     PMOS_INTERFACE osInterface,
278     MhwInterfaces *mhwInterfaces)
279 {
280     MHW_FUNCTION_ENTER;
281 
282     if (mhwInterfaces->m_miInterface == nullptr || mhwInterfaces->m_veboxInterface == nullptr)
283     {
284         if (osInterface != nullptr)
285         {
286             if (osInterface->pfnDestroy)
287             {
288                 osInterface->pfnDestroy(osInterface, false);
289             }
290             MOS_FreeMemory(osInterface);
291         }
292         return MOS_STATUS_NULL_POINTER;
293     }
294 
295     Mmd *device = nullptr;
296     device = MOS_New(Mmd);
297 
298     if (device == nullptr)
299     {
300         if (osInterface != nullptr)
301         {
302             if (osInterface->pfnDestroy)
303             {
304                 osInterface->pfnDestroy(osInterface, false);
305             }
306             MOS_FreeMemory(osInterface);
307         }
308         return MOS_STATUS_NO_SPACE;
309     }
310 
311     // transfer ownership of osinterface to device. device will have exclusive ownership of osinterface and free it.
312     if (device->Initialize(
313         osInterface,
314         mhwInterfaces->m_cpInterface,
315         mhwInterfaces->m_miInterface,
316         mhwInterfaces->m_veboxInterface) != MOS_STATUS_SUCCESS)
317     {
318         // Vebox/mi/cp interface will gove control to mmd device, will release will be in destructure func
319         // set as null to avoid double free in driver
320         mhwInterfaces->m_cpInterface = nullptr;
321         mhwInterfaces->m_miInterface = nullptr;
322         mhwInterfaces->m_veboxInterface = nullptr;
323         MOS_Delete(device);
324         return MOS_STATUS_UNKNOWN;
325     }
326 
327     m_mmdDevice = device;
328 
329     return MOS_STATUS_SUCCESS;
330 }
331 
CreateMhwInterface(PMOS_INTERFACE osInterface)332 MhwInterfaces* MmdDeviceXe_Hpm::CreateMhwInterface(
333     PMOS_INTERFACE osInterface)
334 {
335     MhwInterfaces::CreateParams params;
336     params.Flags.m_vebox = true;
337 
338     // the destroy of interfaces happens when the mmd deviced deconstructor funcs
339     MhwInterfaces *mhw = MhwInterfaces::CreateFactory(params, osInterface);
340 
341     return mhw;
342 }
343 #endif
344 
345 static bool dg2RegisteredMcpy =
346     MediaFactory<uint32_t, McpyDevice>::
347     Register<McpyDeviceXe_Hpm>((uint32_t)IGFX_DG2);
348 
Initialize(PMOS_INTERFACE osInterface,MhwInterfaces * mhwInterfaces)349 MOS_STATUS McpyDeviceXe_Hpm::Initialize(
350     PMOS_INTERFACE osInterface,
351     MhwInterfaces *mhwInterfaces)
352 {
353 #define MCPY_FAILURE()                                       \
354 {                                                           \
355     if (device != nullptr)                                  \
356     {                                                       \
357         MOS_Delete(device);                                 \
358     }                                                       \
359     return MOS_STATUS_NO_SPACE;                             \
360 }
361     MHW_FUNCTION_ENTER;
362 
363     Mcpy *device = nullptr;
364 
365     if (mhwInterfaces->m_miInterface == nullptr)
366     {
367         MCPY_FAILURE();
368     }
369 
370     if (mhwInterfaces->m_veboxInterface == nullptr)
371     {
372         MCPY_FAILURE();
373     }
374 
375     if (mhwInterfaces->m_bltInterface == nullptr)
376     {
377         MCPY_FAILURE();
378     }
379 
380     device = MOS_New(Mcpy);
381 
382     if (device == nullptr)
383     {
384         MCPY_FAILURE();
385     }
386 
387     if (device->Initialize(
388         osInterface, mhwInterfaces) != MOS_STATUS_SUCCESS)
389     {
390         MOS_Delete(device);
391         MOS_OS_CHK_STATUS_RETURN(MOS_STATUS_UNINITIALIZED);
392     }
393 
394     m_mcpyDevice = device;
395 
396     return MOS_STATUS_SUCCESS;
397 }
398 
CreateMhwInterface(PMOS_INTERFACE osInterface)399 MhwInterfaces* McpyDeviceXe_Hpm::CreateMhwInterface(
400     PMOS_INTERFACE osInterface)
401 {
402     MhwInterfaces::CreateParams params;
403     params.Flags.m_vebox = true;
404     params.Flags.m_blt   = true;
405 
406     // the destroy of interfaces happens when the mcpy deviced deconstructor funcs
407     MhwInterfaces *mhw = MhwInterfaces::CreateFactory(params, osInterface);
408 
409     return mhw;
410 }
411 
412 static bool dg2RegisteredNv12ToP010 =
413     MediaFactory<uint32_t, Nv12ToP010Device>::
414     Register<Nv12ToP010DeviceXe_Hpm>((uint32_t)IGFX_DG2);
415 
Initialize(PMOS_INTERFACE osInterface)416 MOS_STATUS Nv12ToP010DeviceXe_Hpm::Initialize(
417     PMOS_INTERFACE            osInterface)
418 {
419     CODECHAL_PUBLIC_ASSERTMESSAGE("Not support Nv12 to P010 interfaces.")
420 
421     return MOS_STATUS_INVALID_PARAMETER;
422 }
423 
424 static bool dg2RegisteredCodecHal =
425     MediaFactory<uint32_t, CodechalDevice>::
426     Register<CodechalInterfacesXe_Hpm>((uint32_t)IGFX_DG2);
427 
428 static bool dg2RegisteredCodecHalNext =
429     MediaFactory<uint32_t, CodechalDeviceNext>::
430         Register<CodechalInterfacesNextXe_Hpm>((uint32_t)IGFX_DG2);
431 
432 static bool dg2RegisteredMhwNext =
433     MediaFactory<uint32_t, MhwInterfacesNext>::
434         Register<MhwInterfacesDg2_Next>((uint32_t)IGFX_DG2);
435 
Initialize(CreateParams params,PMOS_INTERFACE osInterface)436 MOS_STATUS MhwInterfacesDg2_Next::Initialize(
437     CreateParams   params,
438     PMOS_INTERFACE osInterface)
439 {
440     if (osInterface == nullptr)
441     {
442         MHW_ASSERTMESSAGE("The OS interface is not valid!");
443         return MOS_STATUS_INVALID_PARAMETER;
444     }
445     m_osInterface = osInterface;
446 
447     auto gtSystemInfo = osInterface->pfnGetGtSystemInfo(osInterface);
448     if (gtSystemInfo == nullptr)
449     {
450         MHW_ASSERTMESSAGE("The OS interface is not valid!");
451         return MOS_STATUS_INVALID_PARAMETER;
452     }
453 
454     if ((params.m_isCp == false) && (params.Flags.m_value == 0))
455     {
456         MHW_ASSERTMESSAGE("No MHW interfaces were requested for creation.");
457         return MOS_STATUS_INVALID_PARAMETER;
458     }
459 
460     // MHW_CP and MHW_MI must always be created
461     MOS_STATUS status;
462     m_cpInterface = osInterface->pfnCreateMhwCpInterface(osInterface);
463     MHW_MI_CHK_NULL(m_cpInterface);
464     m_miInterface = std::make_shared<Mi>(m_cpInterface, osInterface);
465 
466     auto ptr = std::make_shared<mhw::mi::xe_xpm_base::Impl>(osInterface);
467     m_miItf       = std::static_pointer_cast<mhw::mi::Itf>(ptr);
468     ptr->SetCpInterface(m_cpInterface, m_miItf);
469 
470     if (params.Flags.m_render)
471     {
472         m_renderInterface =
473             MOS_New(Render, m_miInterface.get(), osInterface, gtSystemInfo, params.m_heapMode);
474         auto renderPtr = std::make_shared<mhw::render::xe_hpg::Impl>(osInterface);
475         m_renderItf    = std::static_pointer_cast<mhw::render::Itf>(renderPtr);
476     }
477     if (params.Flags.m_stateHeap)
478     {
479         m_stateHeapInterface =
480             MOS_New(StateHeap, osInterface, params.m_heapMode);
481     }
482     if (params.Flags.m_sfc)
483     {
484         m_sfcInterface = MOS_New(Sfc, osInterface);
485     }
486     if (params.Flags.m_vebox)
487     {
488         m_veboxInterface = MOS_New(Vebox, osInterface);
489     }
490 
491     if (params.Flags.m_vdboxAll || params.Flags.m_mfx)
492     {
493         m_mfxItf = nullptr;
494     }
495     if (params.Flags.m_vdboxAll || params.Flags.m_hcp)
496     {
497         m_hcpItf = std::make_shared<mhw::vdbox::hcp::xe_xpm_base::xe_hpm::Impl>(osInterface);
498     }
499     if (params.Flags.m_vdboxAll)
500     {
501         auto ptr = std::make_shared<mhw::vdbox::avp::xe_hpm::Impl>(osInterface);
502         m_avpItf = std::static_pointer_cast<mhw::vdbox::avp::Itf>(ptr);
503     }
504     if (params.Flags.m_vdboxAll || params.Flags.m_huc)
505     {
506         auto ptr = std::make_shared<mhw::vdbox::huc::xe_hpm::Impl>(osInterface, m_cpInterface);
507         m_hucItf = std::static_pointer_cast<mhw::vdbox::huc::Itf>(ptr);
508     }
509     if (params.Flags.m_vdboxAll || params.Flags.m_vdenc)
510     {
511         auto ptr = std::make_shared<mhw::vdbox::vdenc::xe_hpm::Impl>(osInterface);
512         m_vdencItf = std::static_pointer_cast<mhw::vdbox::vdenc::Itf>(ptr);
513     }
514     if (params.Flags.m_blt)
515     {
516         m_bltInterface = MOS_New(Blt, osInterface);
517     }
518 
519     return MOS_STATUS_SUCCESS;
520 }
521 
522 //!
523 //! \brief    Destroys all created MHW interfaces
524 //! \details  If the HAL creation fails, this is used for cleanup
525 //!
Destroy()526 void MhwInterfacesDg2_Next::Destroy()
527 {
528     MhwInterfacesNext::Destroy();
529     MOS_Delete(m_sfcInterface);
530     MOS_Delete(m_veboxInterface);
531     MOS_Delete(m_bltInterface);
532     if (m_renderInterface != nullptr)
533     {
534         MOS_Delete(m_renderInterface);
535     }
536 }
537 
Initialize(void * standardInfo,void * settings,MhwInterfaces * mhwInterfaces,PMOS_INTERFACE osInterface)538 MOS_STATUS CodechalInterfacesXe_Hpm::Initialize(
539     void *standardInfo,
540     void *settings,
541     MhwInterfaces *mhwInterfaces,
542     PMOS_INTERFACE osInterface)
543 {
544     if (standardInfo    == nullptr ||
545         mhwInterfaces   == nullptr ||
546         osInterface     == nullptr)
547     {
548         CODECHAL_PUBLIC_ASSERTMESSAGE("CodecHal device is not valid!");
549         return MOS_STATUS_INVALID_PARAMETER;
550     }
551 
552     PCODECHAL_STANDARD_INFO info = ((PCODECHAL_STANDARD_INFO)standardInfo);
553     CODECHAL_FUNCTION CodecFunction = info->CodecFunction;
554 
555     bool disableScalability = false;
556     PLATFORM platform = {};
557     osInterface->pfnGetPlatform(osInterface, &platform);
558     if((platform.usDeviceID >= 0x56C0)
559         && (platform.usDeviceID <= 0x56CF))
560     {
561         disableScalability = true;
562     }
563 
564     CodechalHwInterface    *hwInterface    = nullptr;
565     CodechalDebugInterface *debugInterface = nullptr;
566     CodechalHwInterfaceNext    *hwInterface_next    = nullptr;
567 
568     auto release_func = [&]()
569     {
570         MOS_Delete(hwInterface);
571 #if USE_CODECHAL_DEBUG_TOOL
572         MOS_Delete(debugInterface);
573 #endif  // USE_CODECHAL_DEBUG_TOOL
574     };
575 
576     if (CodecHalIsDecode(CodecFunction))
577     {
578         if(osInterface->bHcpDecScalabilityMode == MOS_SCALABILITY_ENABLE_MODE_USER_FORCE)
579         {
580             disableScalability = false;
581         }
582         CODECHAL_PUBLIC_CHK_STATUS_RETURN(CreateCodecHalInterface(mhwInterfaces, hwInterface, debugInterface, osInterface, CodecFunction, disableScalability));
583 
584     #ifdef _MPEG2_DECODE_SUPPORTED
585         if (info->Mode == CODECHAL_DECODE_MODE_MPEG2IDCT ||
586             info->Mode == CODECHAL_DECODE_MODE_MPEG2VLD)
587         {
588             m_codechalDevice = MOS_New(Decode::Mpeg2, hwInterface, debugInterface);
589         }
590         else
591     #endif
592     #ifdef _VC1_DECODE_SUPPORTED
593         if (info->Mode == CODECHAL_DECODE_MODE_VC1IT ||
594             info->Mode == CODECHAL_DECODE_MODE_VC1VLD)
595         {
596             m_codechalDevice = MOS_New(Decode::Vc1, hwInterface, debugInterface, info);
597         }
598         else
599     #endif
600     #ifdef _AVC_DECODE_SUPPORTED
601         if (info->Mode == CODECHAL_DECODE_MODE_AVCVLD)
602         {
603             m_codechalDevice = MOS_New(Decode::Avc, hwInterface, debugInterface);
604         }
605         else
606     #endif
607     #ifdef _JPEG_DECODE_SUPPORTED
608         if (info->Mode == CODECHAL_DECODE_MODE_JPEG)
609         {
610             m_codechalDevice = MOS_New(Decode::Jpeg, hwInterface, debugInterface);
611         }
612         else
613     #endif
614     #ifdef _VP8_DECODE_SUPPORTED
615         if (info->Mode == CODECHAL_DECODE_MODE_VP8VLD)
616         {
617             m_codechalDevice = MOS_New(Decode::Vp8, hwInterface, debugInterface, info);
618         }
619         else
620     #endif
621     #ifdef _HEVC_DECODE_SUPPORTED
622         if (info->Mode == CODECHAL_DECODE_MODE_HEVCVLD)
623         {
624             m_codechalDevice = MOS_New(Decode::Hevc, hwInterface, debugInterface);
625         }
626         else
627     #endif
628     #ifdef _VP9_DECODE_SUPPORTED
629         if (info->Mode == CODECHAL_DECODE_MODE_VP9VLD)
630         {
631             m_codechalDevice = MOS_New(Decode::Vp9, hwInterface, debugInterface);
632         }
633         else
634     #endif
635     #ifdef _AV1_DECODE_SUPPORTED
636         if (info->Mode == CODECHAL_DECODE_MODE_AV1VLD)
637         {
638             m_codechalDevice = MOS_New(Decode::Av1, hwInterface, debugInterface);
639         }
640         else
641     #endif
642         {
643             CODECHAL_PUBLIC_ASSERTMESSAGE("Decode mode requested invalid!");
644             CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
645         }
646 
647         if (m_codechalDevice == nullptr)
648         {
649             CODECHAL_PUBLIC_ASSERTMESSAGE("Decoder device creation failed!");
650             CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NO_SPACE, release_func);
651         }
652     }
653     else if (CodecHalIsEncode(CodecFunction))
654     {
655         MhwInterfacesNext      *mhwInterfacesNext = nullptr;
656 
657         #define RETURN_STATUS_WITH_DELETE(stmt)    \
658         {                                          \
659             MOS_Delete(mhwInterfacesNext);         \
660             return stmt;                           \
661         }
662 
663         auto release_func_next = [&]()
664         {
665             MOS_Delete(mhwInterfacesNext);
666             MOS_Delete(hwInterface_next);
667 #if USE_CODECHAL_DEBUG_TOOL
668             MOS_Delete(debugInterface);
669 #endif  // USE_CODECHAL_DEBUG_TOOL
670         };
671 
672         CodechalEncoderState *encoder = nullptr;
673 
674 #if defined (_AVC_ENCODE_VDENC_SUPPORTED)
675         if (info->Mode == CODECHAL_ENCODE_MODE_AVC)
676         {
677             CODECHAL_PUBLIC_CHK_STATUS_RETURN(CreateCodecHalInterface(mhwInterfaces, hwInterface, debugInterface, osInterface, CodecFunction, disableScalability));
678 
679             if (CodecHalUsesVdencEngine(info->CodecFunction))
680             {
681                 encoder = MOS_New(Encode::AvcVdenc, hwInterface, debugInterface, info);
682             }
683             else
684             {
685                 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode allocation failed, AVC VME Encoder is not supported, please use AVC LowPower Encoder instead!");
686                 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
687             }
688             if (encoder == nullptr)
689             {
690                 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
691                 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
692             }
693             else
694             {
695                 m_codechalDevice = encoder;
696             }
697         }
698         else
699 #endif
700 #ifdef _JPEG_ENCODE_SUPPORTED
701         if (info->Mode == CODECHAL_ENCODE_MODE_JPEG)
702         {
703             CODECHAL_PUBLIC_CHK_STATUS_RETURN(CreateCodecHalInterface(mhwInterfaces, hwInterface, debugInterface, osInterface, CodecFunction, disableScalability));
704 
705             encoder = MOS_New(Encode::Jpeg, hwInterface, debugInterface, info);
706             if (encoder == nullptr)
707             {
708                 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
709                 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
710             }
711             else
712             {
713                 m_codechalDevice = encoder;
714             }
715             encoder->m_vdboxOneDefaultUsed = true;
716         }
717         else
718 #endif
719         if (info->Mode == CODECHAL_ENCODE_MODE_MPEG2)
720         {
721             CODECHAL_PUBLIC_ASSERTMESSAGE("Encode allocation failed, MPEG2 Encoder is not supported!");
722             CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
723         }
724         else
725 #ifdef _VP9_ENCODE_VDENC_SUPPORTED
726         if (info->Mode == CODECHAL_ENCODE_MODE_VP9)
727         {
728             CODECHAL_PUBLIC_CHK_STATUS_RETURN(CreateCodecHalInterface(mhwInterfaces, hwInterface, debugInterface, osInterface, CodecFunction, disableScalability));
729 
730             encoder = MOS_New(Encode::Vp9, hwInterface, debugInterface, info);
731 
732             if (encoder == nullptr)
733             {
734                 CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
735                 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
736             }
737             else
738             {
739                 m_codechalDevice = encoder;
740             }
741         }
742         else
743 #endif
744 #if defined (_AV1_ENCODE_VDENC_SUPPORTED)
745         if (info->Mode == codechalEncodeModeAv1)
746         {
747             CODECHAL_PUBLIC_CHK_STATUS_RETURN(CreateCodecHalInterface(mhwInterfaces, mhwInterfacesNext, hwInterface_next, debugInterface, osInterface, CodecFunction, disableScalability));
748 
749             if (CodecHalUsesVdencEngine(info->CodecFunction))
750             {
751                 m_codechalDevice = MOS_New(Encode::Av1Vdenc, hwInterface_next, debugInterface);
752                 if (m_codechalDevice == nullptr)
753                 {
754                     CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NULL_POINTER, release_func_next);
755                 }
756                 else
757                 {
758                     RETURN_STATUS_WITH_DELETE(MOS_STATUS_SUCCESS);
759                 }
760             }
761             else
762             {
763                 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func_next);
764             }
765         }
766         else
767 #endif
768 #if defined (_HEVC_ENCODE_VDENC_SUPPORTED)
769         if (info->Mode == CODECHAL_ENCODE_MODE_HEVC)
770         {
771             CODECHAL_PUBLIC_CHK_STATUS_RETURN(CreateCodecHalInterface(mhwInterfaces, mhwInterfacesNext, hwInterface_next, debugInterface, osInterface, CodecFunction, disableScalability));
772 
773             if (CodecHalUsesVdencEngine(info->CodecFunction))
774             {
775                 m_codechalDevice = MOS_New(Encode::HevcVdenc, hwInterface_next, debugInterface);
776                 if (m_codechalDevice == nullptr)
777                 {
778                     CODECHAL_PUBLIC_ASSERTMESSAGE("Encode state creation failed!");
779                     CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func_next);
780                 }
781                 RETURN_STATUS_WITH_DELETE(MOS_STATUS_SUCCESS);
782             }
783         }
784         else
785 #endif
786         {
787             CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported encode function requested.");
788             CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
789         }
790 
791         if (mhwInterfacesNext != nullptr)
792         {
793             MOS_Delete(mhwInterfacesNext);
794         }
795     }
796     else
797     {
798         CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported codec function requested.");
799         CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
800     }
801 
802     return MOS_STATUS_SUCCESS;
803 }
804 
Initialize(void * standardInfo,void * settings,MhwInterfacesNext * mhwInterfaces,PMOS_INTERFACE osInterface)805 MOS_STATUS CodechalInterfacesNextXe_Hpm::Initialize(
806     void *standardInfo,
807     void *settings,
808     MhwInterfacesNext *mhwInterfaces,
809     PMOS_INTERFACE osInterface)
810 {
811      bool mdfSupported = true;
812 #if (_DEBUG || _RELEASE_INTERNAL)
813     MOS_USER_FEATURE_VALUE_DATA UserFeatureData;
814     MOS_ZeroMemory(&UserFeatureData, sizeof(UserFeatureData));
815     MOS_UserFeature_ReadValue_ID(
816         nullptr,
817         __MEDIA_USER_FEATURE_VALUE_HEVC_ENCODE_MDF_DISABLE_ID,
818         &UserFeatureData,
819         osInterface->pOsContext);
820     mdfSupported = (UserFeatureData.i32Data == 1) ? false : true;
821 #endif  // (_DEBUG || _RELEASE_INTERNAL)
822     if (standardInfo == nullptr ||
823         mhwInterfaces == nullptr ||
824         osInterface == nullptr)
825     {
826         CODECHAL_PUBLIC_ASSERTMESSAGE("CodecHal device is not valid!");
827         return MOS_STATUS_INVALID_PARAMETER;
828     }
829 
830     // This part should be moved back to media_intefaces.cpp for softlet build
831     PCODECHAL_STANDARD_INFO info          = ((PCODECHAL_STANDARD_INFO)standardInfo);
832     CODECHAL_FUNCTION       CodecFunction = info->CodecFunction;
833 
834     bool disableScalability = false;
835 #ifdef _VP9_ENCODE_VDENC_SUPPORTED
836     if (info->Mode == CODECHAL_ENCODE_MODE_VP9)
837         disableScalability = true;
838 #endif
839     CodechalHwInterfaceNext *hwInterface = MOS_New(Hw, osInterface, CodecFunction, mhwInterfaces, disableScalability);
840 
841     if (hwInterface == nullptr)
842     {
843         CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterface is not valid!");
844         return MOS_STATUS_NO_SPACE;
845     }
846 
847 #if USE_CODECHAL_DEBUG_TOOL
848     CodechalDebugInterface *debugInterface = MOS_New(CodechalDebugInterface);
849     if (debugInterface == nullptr)
850     {
851         MOS_Delete(hwInterface);
852         CODECHAL_PUBLIC_ASSERTMESSAGE("debugInterface is not valid!");
853         return MOS_STATUS_NO_SPACE;
854     }
855     if (debugInterface->Initialize(hwInterface, CodecFunction) != MOS_STATUS_SUCCESS)
856     {
857         MOS_Delete(hwInterface);
858         MOS_Delete(debugInterface);
859         CODECHAL_PUBLIC_ASSERTMESSAGE("Debug interface creation failed!");
860         return MOS_STATUS_INVALID_PARAMETER;
861     }
862 #else
863     CodechalDebugInterface *debugInterface = nullptr;
864 #endif  // USE_CODECHAL_DEBUG_TOOL
865 
866     auto release_func = [&]()
867     {
868         MOS_Delete(hwInterface);
869 #if USE_CODECHAL_DEBUG_TOOL
870         MOS_Delete(debugInterface);
871 #endif  // USE_CODECHAL_DEBUG_TOOL
872     };
873 
874     if (CodecHalIsDecode(CodecFunction))
875     {
876         CODECHAL_PUBLIC_ASSERTMESSAGE("Decode allocation failed, Decoder with CodechalDeviceNext is not supported!");
877         CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
878 
879     }
880     else if (CodecHalIsEncode(CodecFunction))
881     {
882         CodechalEncoderState *encoder = nullptr;
883 
884 #if defined (_AV1_ENCODE_VDENC_SUPPORTED)
885         if (info->Mode == codechalEncodeModeAv1)
886         {
887             //TODO, use create
888             if (CodecHalUsesVdencEngine(info->CodecFunction))
889             {
890                 m_codechalDevice = MOS_New(Encode::Av1Vdenc, hwInterface, debugInterface);
891                 if (m_codechalDevice == nullptr)
892                 {
893                     CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_NULL_POINTER, release_func);
894                 }
895                 return MOS_STATUS_SUCCESS;
896             }
897             else
898             {
899                 CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
900             }
901         }
902         else
903 #endif
904         {
905             CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported encode function requested.");
906             CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
907         }
908 
909     }
910     else
911     {
912         CODECHAL_PUBLIC_ASSERTMESSAGE("Unsupported codec function requested.");
913         CODECHAL_PUBLIC_CHK_STATUS_WITH_DESTROY_RETURN(MOS_STATUS_INVALID_PARAMETER, release_func);
914     }
915 
916     return MOS_STATUS_SUCCESS;
917 }
918 
919 #ifdef _MEDIA_RESERVED
920 static bool dg2RegisteredCMHal =
921     MediaFactory<uint32_t, CMHalDevice>::
922     Register<CMHalInterfacesXe_Hpm>((uint32_t)IGFX_DG2);
Initialize(CM_HAL_STATE * pCmState)923 MOS_STATUS CMHalInterfacesXe_Hpm::Initialize(CM_HAL_STATE *pCmState)
924 {
925     if (pCmState == nullptr)
926     {
927         MHW_ASSERTMESSAGE("pCmState is nullptr.")
928         return MOS_STATUS_INVALID_PARAMETER;
929     }
930     CMHal *device = MOS_New(CMHal, pCmState);
931     if (device == nullptr)
932     {
933         MHW_ASSERTMESSAGE("Create CM Hal interfaces failed.")
934         return MOS_STATUS_NO_SPACE;
935     }
936     device->SetCopyKernelIsa((void*)pGPUCopy_kernel_isa_dg2, iGPUCopy_kernel_isa_size_dg2);
937     device->SetInitKernelIsa((void*)pGPUInit_kernel_isa_dg2, iGPUInit_kernel_isa_size_dg2);
938 
939     m_cmhalDevice = device;
940     m_cmhalDevice->SetGenPlatformInfo(PLATFORM_INTEL_DG2, PLATFORM_INTEL_GT2, "DG2");
941     uint32_t cisaIDs[] = { GENX_DG2 , GENX_XEHP };
942     m_cmhalDevice->AddSupportedCisaIDs(cisaIDs, sizeof(cisaIDs)/sizeof(uint32_t));
943 
944     if (pCmState->skuTable && MEDIA_IS_SKU(pCmState->skuTable, FtrCCSNode))
945     {
946         m_cmhalDevice->SetRedirectRcsToCcs(true);
947     }
948 
949     m_cmhalDevice->SetDefaultMOCS(MOS_CM_RESOURCE_USAGE_L1_Enabled_SurfaceState);
950     m_cmhalDevice->m_l3Plane = DG2_L3_PLANES;
951     m_cmhalDevice->m_l3ConfigCount = DG2_L3_CONFIG_COUNT;
952     return MOS_STATUS_SUCCESS;
953 }
954 #endif
955 
956 static bool dg2RegisteredRenderHal =
957     MediaFactory<uint32_t, RenderHalDevice>::
958     Register<RenderHalInterfacesXe_Hpg>((uint32_t)IGFX_DG2);
Initialize()959 MOS_STATUS RenderHalInterfacesXe_Hpg::Initialize()
960 {
961     m_renderhalDevice = MOS_New(XRenderHal);
962     if (m_renderhalDevice == nullptr)
963     {
964         MHW_ASSERTMESSAGE("Create Render Hal interfaces failed.")
965         return MOS_STATUS_NO_SPACE;
966     }
967     return MOS_STATUS_SUCCESS;
968 }
969 static bool dg2RegisteredDecodeHistogram =
970 MediaFactory<uint32_t, DecodeHistogramDevice>::
971 Register<DecodeHistogramDeviceXe_Hpm>((uint32_t)IGFX_DG2);
Initialize(CodechalHwInterface * hwInterface,PMOS_INTERFACE osInterface)972 MOS_STATUS DecodeHistogramDeviceXe_Hpm::Initialize(
973     CodechalHwInterface       *hwInterface,
974     PMOS_INTERFACE            osInterface)
975 {
976     m_decodeHistogramDevice = MOS_New(DecodeHistogramG12, hwInterface, osInterface);
977     if (m_decodeHistogramDevice == nullptr)
978     {
979         MHW_ASSERTMESSAGE("Create decode histogram  interfaces failed.")
980             return MOS_STATUS_NO_SPACE;
981     }
982 
983     return MOS_STATUS_SUCCESS;
984 }
985 
986 static bool dg2RegisteredHwInfo =
987     MediaFactory<uint32_t, MediaInterfacesHwInfoDevice>::Register<MediaInterfacesHwInfoDeviceDg2>((uint32_t)IGFX_DG2);
988 
989 #define IP_VERSION_XE_HPM      0x1207
990 
RefreshRevId(PLATFORM & platform,MEDIA_WA_TABLE * waTable)991 MOS_STATUS MediaInterfacesHwInfoDeviceDg2::RefreshRevId(PLATFORM &platform, MEDIA_WA_TABLE *waTable)
992 {
993     if (waTable == nullptr)
994     {
995         CODECHAL_PUBLIC_ASSERTMESSAGE("waTable is null!");
996         return MOS_STATUS_INVALID_PARAMETER;
997     }
998     if (!MEDIA_IS_WA(waTable, WaEnableOnlyASteppingFeatures) && (platform.usRevId == 0 || platform.usRevId == 1))
999     {
1000         platform.usRevId = 4;
1001     }
1002 
1003     return MOS_STATUS_SUCCESS;
1004 };
1005 
Initialize(PLATFORM platform)1006 MOS_STATUS MediaInterfacesHwInfoDeviceDg2::Initialize(PLATFORM platform)
1007 {
1008     m_hwInfo.SetDeviceInfo(IP_VERSION_XE_HPM, platform.usRevId);
1009     return MOS_STATUS_SUCCESS;
1010 }
1011 
CreateCodecHalInterface(MhwInterfaces * mhwInterfaces,CodechalHwInterface * & pHwInterface,CodechalDebugInterface * & pDebugInterface,PMOS_INTERFACE osInterface,CODECHAL_FUNCTION CodecFunction,bool disableScalability)1012 MOS_STATUS CodechalInterfacesXe_Hpm::CreateCodecHalInterface(MhwInterfaces *mhwInterfaces,
1013                                                              CodechalHwInterface    *&pHwInterface,
1014                                                              CodechalDebugInterface *&pDebugInterface,
1015                                                              PMOS_INTERFACE         osInterface,
1016                                                              CODECHAL_FUNCTION      CodecFunction,
1017                                                              bool                   disableScalability)
1018 {
1019     pHwInterface = MOS_New(Hw, osInterface, CodecFunction, mhwInterfaces, disableScalability);
1020     if (pHwInterface == nullptr)
1021     {
1022         CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterface is not valid!");
1023         return MOS_STATUS_NO_SPACE;
1024     }
1025     pHwInterface->m_hwInterfaceNext                            = MOS_New(CodechalHwInterfaceNext, osInterface, pHwInterface->IsDisableScalability());
1026     if (pHwInterface->m_hwInterfaceNext == nullptr)
1027     {
1028         MOS_Delete(pHwInterface);
1029         CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterfaceNext is not valid!");
1030         return MOS_STATUS_NO_SPACE;
1031     }
1032     pHwInterface->m_hwInterfaceNext->pfnCreateDecodeSinglePipe = decode::DecodeScalabilitySinglePipe::CreateDecodeSinglePipe;
1033     pHwInterface->m_hwInterfaceNext->pfnCreateDecodeMultiPipe  = decode::DecodeScalabilityMultiPipe::CreateDecodeMultiPipe;
1034     pHwInterface->m_hwInterfaceNext->SetMediaSfcInterface(pHwInterface->GetMediaSfcInterface());
1035 
1036 #if USE_CODECHAL_DEBUG_TOOL
1037     pDebugInterface = MOS_New(CodechalDebugInterface);
1038     if (pDebugInterface == nullptr)
1039     {
1040         MOS_Delete(pHwInterface);
1041         CODECHAL_PUBLIC_ASSERTMESSAGE("debugInterface is not valid!");
1042         return MOS_STATUS_NO_SPACE;
1043     }
1044     if ((pDebugInterface)->Initialize(pHwInterface, CodecFunction) != MOS_STATUS_SUCCESS)
1045     {
1046         MOS_Delete(pHwInterface);
1047         MOS_Delete(pDebugInterface);
1048         CODECHAL_PUBLIC_ASSERTMESSAGE("Debug interface creation failed!");
1049         return MOS_STATUS_INVALID_PARAMETER;
1050     }
1051 #endif // USE_CODECHAL_DEBUG_TOOL
1052     return MOS_STATUS_SUCCESS;
1053 }
1054 
CreateCodecHalInterface(MhwInterfaces * mhwInterfaces,MhwInterfacesNext * & pMhwInterfacesNext,CodechalHwInterfaceNext * & pHwInterface,CodechalDebugInterface * & pDebugInterface,PMOS_INTERFACE osInterface,CODECHAL_FUNCTION CodecFunction,bool disableScalability)1055 MOS_STATUS CodechalInterfacesXe_Hpm::CreateCodecHalInterface(MhwInterfaces *mhwInterfaces,
1056     MhwInterfacesNext                                                     *&pMhwInterfacesNext,
1057     CodechalHwInterfaceNext                                               *&pHwInterface,
1058     CodechalDebugInterface                                                *&pDebugInterface,
1059     PMOS_INTERFACE                                                          osInterface,
1060     CODECHAL_FUNCTION                                                       CodecFunction,
1061     bool                                                                    disableScalability)
1062 {
1063     if (mhwInterfaces != nullptr)
1064     {
1065         if (((MhwInterfacesDg2 *)mhwInterfaces)->m_avpInterface != nullptr)
1066         {
1067             MOS_Delete(((MhwInterfacesDg2 *)mhwInterfaces)->m_avpInterface);
1068         }
1069         mhwInterfaces->Destroy();
1070     }
1071 
1072     pMhwInterfacesNext = nullptr;
1073     MhwInterfacesNext::CreateParams params;
1074     MOS_ZeroMemory(&params, sizeof(params));
1075     params.Flags.m_render   = true;
1076     params.Flags.m_sfc      = true;
1077     params.Flags.m_vdboxAll = true;
1078     params.Flags.m_vebox    = true;
1079     params.m_heapMode       = (uint8_t)2;
1080     params.m_isDecode       = CodecHalIsDecode(CodecFunction);
1081     pMhwInterfacesNext      = MhwInterfacesNext::CreateFactory(params, osInterface);
1082 
1083     if (pMhwInterfacesNext == nullptr)
1084     {
1085         CODECHAL_PUBLIC_ASSERTMESSAGE("mhwInterfacesNext is not valid!");
1086         return MOS_STATUS_NO_SPACE;
1087     }
1088 
1089     pHwInterface = MOS_New(CodechalHwInterfaceNextXe_Hpm, osInterface, CodecFunction, pMhwInterfacesNext, disableScalability);
1090 
1091     if (pHwInterface == nullptr)
1092     {
1093         CODECHAL_PUBLIC_ASSERTMESSAGE("hwInterface is not valid!");
1094         return MOS_STATUS_NO_SPACE;
1095     }
1096 #if USE_CODECHAL_DEBUG_TOOL
1097     pDebugInterface = MOS_New(CodechalDebugInterface);
1098     if (pDebugInterface == nullptr)
1099     {
1100         MOS_Delete(pHwInterface);
1101         CODECHAL_PUBLIC_ASSERTMESSAGE("debugInterface is not valid!");
1102         return MOS_STATUS_NO_SPACE;
1103     }
1104     if ((pDebugInterface)->Initialize(pHwInterface, CodecFunction) != MOS_STATUS_SUCCESS)
1105     {
1106         MOS_Delete(pHwInterface);
1107         MOS_Delete(pDebugInterface);
1108         CODECHAL_PUBLIC_ASSERTMESSAGE("Debug interface creation failed!");
1109         return MOS_STATUS_INVALID_PARAMETER;
1110     }
1111 #endif  // USE_CODECHAL_DEBUG_TOOL
1112     return MOS_STATUS_SUCCESS;
1113 }