1 /*
2 * Copyright (c) 2020-2022, 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     vp_platform_interface.cpp
24 //! \brief    render packet which used in by mediapipline.
25 //! \details  render packet provide the structures and generate the cmd buffer which mediapipline will used.
26 //!
27 #include "vp_platform_interface.h"
28 #include "vp_visa.h"
29 #include "vp_user_setting.h"
30 
31 using namespace vp;
32 extern const Kdll_RuleEntry g_KdllRuleTable_Next[];
33 const std::string VpRenderKernel::s_kernelNameNonAdvKernels = "vpFcKernels";
34 
VpPlatformInterface(PMOS_INTERFACE pOsInterface,bool clearViewMode)35 VpPlatformInterface::VpPlatformInterface(PMOS_INTERFACE pOsInterface, bool clearViewMode)
36 {
37     m_pOsInterface = pOsInterface;
38     if (m_pOsInterface)
39     {
40         m_userSettingPtr = m_pOsInterface->pfnGetUserSettingInstance(m_pOsInterface);
41     }
42     VpUserSetting::InitVpUserSetting(m_userSettingPtr, clearViewMode);
43 }
44 
InitVPKernel(const Kdll_RuleEntry * kernelRules,const uint32_t * kernelBin,uint32_t kernelSize,const uint32_t * patchKernelBin,uint32_t patchKernelSize,void (* ModifyFunctionPointers)(PKdll_State)=nullptr)45 MOS_STATUS VpRenderKernel::InitVPKernel(
46     const Kdll_RuleEntry *kernelRules,
47     const uint32_t *      kernelBin,
48     uint32_t              kernelSize,
49     const uint32_t *      patchKernelBin,
50     uint32_t              patchKernelSize,
51     void (*ModifyFunctionPointers)(PKdll_State) = nullptr)
52 {
53     VP_FUNC_CALL();
54     m_kernelDllRules = kernelRules;
55     m_kernelBin      = (const void *)kernelBin;
56     m_kernelBinSize  = kernelSize;
57     m_fcPatchBin     = (const void *)patchKernelBin;
58     m_fcPatchBinSize = patchKernelSize;
59 
60     void *pKernelBin  = nullptr;
61     void *pFcPatchBin = nullptr;
62 
63     pKernelBin = MOS_AllocMemory(m_kernelBinSize);
64     if (!pKernelBin)
65     {
66         VP_RENDER_ASSERTMESSAGE("local creat surface faile, retun no space");
67         MOS_SafeFreeMemory(pKernelBin);
68         return MOS_STATUS_NO_SPACE;
69     }
70 
71     MOS_SecureMemcpy(pKernelBin,
72         m_kernelBinSize,
73         m_kernelBin,
74         m_kernelBinSize);
75 
76     if ((m_fcPatchBin != nullptr) && (m_fcPatchBinSize != 0))
77     {
78         pFcPatchBin = MOS_AllocMemory(m_fcPatchBinSize);
79         if (!pFcPatchBin)
80         {
81             VP_RENDER_ASSERTMESSAGE("local creat surface faile, retun no space");
82             MOS_SafeFreeMemory(pKernelBin);
83             MOS_SafeFreeMemory(pFcPatchBin);
84             return MOS_STATUS_NO_SPACE;
85         }
86 
87         MOS_SecureMemcpy(pFcPatchBin,
88             m_fcPatchBinSize,
89             m_fcPatchBin,
90             m_fcPatchBinSize);
91     }
92 
93     // Allocate KDLL state (Kernel Dynamic Linking)
94     m_kernelDllState = KernelDll_AllocateStates(
95         pKernelBin,
96         m_kernelBinSize,
97         pFcPatchBin,
98         m_fcPatchBinSize,
99         m_kernelDllRules,
100         ModifyFunctionPointers);
101     if (!m_kernelDllState)
102     {
103         VP_RENDER_ASSERTMESSAGE("Failed to allocate KDLL state.");
104         MOS_SafeFreeMemory(pKernelBin);
105         MOS_SafeFreeMemory(pFcPatchBin);
106     }
107     else
108     {
109         KernelDll_SetupFunctionPointers_Ext(m_kernelDllState);
110     }
111 
112     SetKernelName(VpRenderKernel::s_kernelNameNonAdvKernels);
113 
114     return MOS_STATUS_SUCCESS;
115 }
116 
InitVPFCKernels(const Kdll_RuleEntry * kernelRules,const uint32_t * kernelBin,uint32_t kernelSize,const uint32_t * patchKernelBin,uint32_t patchKernelSize,void (* ModifyFunctionPointers)(PKdll_State))117 MOS_STATUS VpPlatformInterface::InitVPFCKernels(
118     const Kdll_RuleEntry *kernelRules,
119     const uint32_t *      kernelBin,
120     uint32_t              kernelSize,
121     const uint32_t *      patchKernelBin,
122     uint32_t              patchKernelSize,
123     void (*ModifyFunctionPointers)(PKdll_State))
124 {
125     VP_FUNC_CALL();
126 
127     // For non-adv kernels.
128     if (m_kernelPool.end() == m_kernelPool.find(VpRenderKernel::s_kernelNameNonAdvKernels))
129     {
130         // Need refine later. Should not push_back local variable, which will cause default
131         // assign operator being used and may cause issue if we release any internal members in destruction.
132         VpRenderKernel vpKernel;
133         vpKernel.InitVPKernel(
134             kernelRules,
135             kernelBin,
136             kernelSize,
137             patchKernelBin,
138             patchKernelSize,
139             ModifyFunctionPointers);
140 
141         m_kernelPool.insert(std::make_pair(vpKernel.GetKernelName(), vpKernel));
142     }
143 
144     return MOS_STATUS_SUCCESS;
145 }
146 
Destroy()147 MOS_STATUS VpRenderKernel::Destroy()
148 {
149     VP_FUNC_CALL();
150 
151     if (m_kernelDllState)
152     {
153         KernelDll_ReleaseStates(m_kernelDllState);
154     }
155 
156     return MOS_STATUS_SUCCESS;
157 }
158 
InitPolicyRules(VP_POLICY_RULES & rules)159 MOS_STATUS VpPlatformInterface::InitPolicyRules(VP_POLICY_RULES &rules)
160 {
161     VP_FUNC_CALL();
162     rules.sfcMultiPassSupport.csc.enable = false;
163     if (m_sfc2PassScalingEnabled)
164     {
165         rules.sfcMultiPassSupport.scaling.enable = true;
166         // one pass SFC scaling range is [1/8, 8], two pass cover[1/16, 16](AVS Removal) for both X and Y direction.
167         rules.sfcMultiPassSupport.scaling.downScaling.minRatioEnlarged = 0.5;
168         rules.sfcMultiPassSupport.scaling.upScaling.maxRatioEnlarged   = 2;
169 
170         // For 2 pass upscaling: first pass do 2X, rest for others.
171         rules.sfcMultiPassSupport.scaling.upScaling.ratioFor1stPass               = 2;
172         rules.sfcMultiPassSupport.scaling.upScaling.scalingIn1stPassIf1PassEnough = false;
173 
174         if (m_sfc2PassScalingPerfMode)
175         {
176             // for 2 pass downscaling: first pass do 1/8, rest for others.
177             rules.sfcMultiPassSupport.scaling.downScaling.ratioFor1stPass               = 1.0F / 8;
178             rules.sfcMultiPassSupport.scaling.downScaling.scalingIn1stPassIf1PassEnough = true;
179         }
180         else
181         {
182             // for 2 pass downscaling: first pass do 1/2, rest for others.
183             rules.sfcMultiPassSupport.scaling.downScaling.ratioFor1stPass               = 0.5;
184             rules.sfcMultiPassSupport.scaling.downScaling.scalingIn1stPassIf1PassEnough = false;
185         }
186     }
187     else
188     {
189         rules.sfcMultiPassSupport.scaling.enable = false;
190     }
191 
192     rules.isAvsSamplerSupported   = false;
193     rules.isHDR3DLutKernelEnabled = true;
194     rules.is1K1DLutSurfaceInUse   = false;
195 
196     return MOS_STATUS_SUCCESS;
197 }
198 
SetKernelName(std::string kernelname)199 MOS_STATUS VpRenderKernel::SetKernelName(std::string kernelname)
200 {
201     VP_FUNC_CALL();
202     m_kernelName.assign(kernelname);
203 
204     return MOS_STATUS_SUCCESS;
205 }
206 
SetKernelBinOffset(uint32_t offset)207 MOS_STATUS VpRenderKernel::SetKernelBinOffset(uint32_t offset)
208 {
209     VP_FUNC_CALL();
210     m_kernelBinOffset = offset;
211 
212     return MOS_STATUS_SUCCESS;
213 }
214 
SetKernelBinSize(uint32_t size)215 MOS_STATUS VpRenderKernel::SetKernelBinSize(uint32_t size)
216 {
217     VP_FUNC_CALL();
218     m_kernelBinSize = size;
219 
220     return MOS_STATUS_SUCCESS;
221 }
222 
SetKernelBinPointer(void * pBin)223 MOS_STATUS VpRenderKernel::SetKernelBinPointer(void *pBin)
224 {
225     VP_FUNC_CALL();
226     VP_RENDER_CHK_NULL_RETURN(pBin);
227     m_kernelBin = pBin;
228 
229     return MOS_STATUS_SUCCESS;
230 }
231 
AddKernelArg(KRN_ARG & kernelArg)232 MOS_STATUS VpRenderKernel::AddKernelArg(KRN_ARG &kernelArg)
233 {
234     VP_FUNC_CALL();
235 
236     m_kernelArgs.push_back(kernelArg);
237     return MOS_STATUS_SUCCESS;
238 }
239 
AddVpIsaKernelEntryToList(const uint32_t * kernelBin,uint32_t kernelBinSize,std::string postfix,DelayLoadedKernelType delayKernelType,uint32_t payloadOffset)240 void VpPlatformInterface::AddVpIsaKernelEntryToList(
241     const uint32_t *kernelBin,
242     uint32_t        kernelBinSize,
243     std::string     postfix,
244     DelayLoadedKernelType delayKernelType,
245     uint32_t              payloadOffset)
246 {
247     VP_FUNC_CALL();
248 
249     VP_KERNEL_BINARY_ENTRY tmpEntry = {};
250     tmpEntry.kernelBin     = kernelBin;
251     tmpEntry.kernelBinSize = kernelBinSize;
252     tmpEntry.postfix       = postfix;
253     tmpEntry.kernelType    = delayKernelType;
254     tmpEntry.payloadOffset = payloadOffset;
255 
256     if (delayKernelType == KernelNone)
257     {
258         m_vpIsaKernelBinaryList.push_back(tmpEntry);
259     }
260     else
261     {
262         m_vpDelayLoadedBinaryList.push_back(tmpEntry);
263         m_vpDelayLoadedFeatureSet.insert(std::make_pair(delayKernelType, false));
264     }
265 }
266 
AddVpNativeAdvKernelEntryToList(const uint32_t * kernelBin,uint32_t kernelBinSize,std::string kernelName)267 void VpPlatformInterface::AddVpNativeAdvKernelEntryToList(
268     const uint32_t *kernelBin,
269     uint32_t        kernelBinSize,
270     std::string     kernelName)
271 {
272     VP_FUNC_CALL();
273 
274     VP_KERNEL_BINARY_ENTRY tmpEntry = {};
275     tmpEntry.kernelBin     = kernelBin;
276     tmpEntry.kernelBinSize = kernelBinSize;
277 
278     m_vpNativeAdvKernelBinaryList.insert(std::make_pair(kernelName, tmpEntry));
279 }
280 
InitVpDelayedNativeAdvKernel(const uint32_t * kernelBin,uint32_t kernelBinSize,std::string kernelName)281 void VpPlatformInterface::InitVpDelayedNativeAdvKernel(
282     const uint32_t *kernelBin,
283     uint32_t        kernelBinSize,
284     std::string     kernelName)
285 {
286     VP_FUNC_CALL();
287 
288     VP_KERNEL_BINARY_ENTRY tmpEntry = {};
289     tmpEntry.kernelBin              = kernelBin;
290     tmpEntry.kernelBinSize          = kernelBinSize;
291     InitVpNativeAdvKernels(kernelName, tmpEntry);
292 }
293 
AddNativeAdvKernelToDelayedList(DelayLoadedKernelType kernelType,DelayLoadedFunc func)294 void VpPlatformInterface::AddNativeAdvKernelToDelayedList(
295     DelayLoadedKernelType kernelType,
296     DelayLoadedFunc       func)
297 {
298     VP_FUNC_CALL();
299     m_vpDelayLoadedNativeFunctionSet.insert(std::make_pair(kernelType, func));
300 }
301 
302 void       KernelDll_ModifyFunctionPointers_Next(Kdll_State *pState);
303 
InitVpRenderHwCaps()304 MOS_STATUS VpPlatformInterface::InitVpRenderHwCaps()
305 {
306     VP_FUNC_CALL();
307 
308     if (m_isRenderDisabled)
309     {
310         VP_PUBLIC_NORMALMESSAGE("Bypass InitVpRenderHwCaps, since render disabled.");
311         return MOS_STATUS_SUCCESS;
312     }
313 
314     VP_RENDER_CHK_NULL_RETURN(m_vpKernelBinary.kernelBin);
315     VP_RENDER_CHK_NULL_RETURN(m_vpKernelBinary.fcPatchKernelBin);
316     // Only Lpm Plus will use this base function
317     m_modifyKdllFunctionPointers = KernelDll_ModifyFunctionPointers_Next;
318 #if defined(ENABLE_KERNELS)
319     InitVPFCKernels(
320         g_KdllRuleTable_Next,
321         m_vpKernelBinary.kernelBin,
322         m_vpKernelBinary.kernelBinSize,
323         m_vpKernelBinary.fcPatchKernelBin,
324         m_vpKernelBinary.fcPatchKernelBinSize,
325         m_modifyKdllFunctionPointers);
326 #endif
327 
328     if (!m_vpIsaKernelBinaryList.empty())
329     {
330         // Init CM kernel form VP ISA Kernel Binary List
331         for (auto &curKernelEntry : m_vpIsaKernelBinaryList)
332         {
333             VP_PUBLIC_CHK_STATUS_RETURN(InitVpCmKernels(curKernelEntry.kernelBin, curKernelEntry.kernelBinSize, curKernelEntry.postfix, curKernelEntry.payloadOffset));
334         }
335     }
336 
337     if (!m_vpNativeAdvKernelBinaryList.empty())
338     {
339         // Init native adv kernel form VP Native adv kernel Binary List
340         for (auto &curKernelEntry : m_vpNativeAdvKernelBinaryList)
341         {
342             VP_PUBLIC_CHK_STATUS_RETURN(InitVpNativeAdvKernels(curKernelEntry.first, curKernelEntry.second));
343         }
344     }
345     return MOS_STATUS_SUCCESS;
346 }
347 
InitVpNativeAdvKernels(std::string kernelName,VP_KERNEL_BINARY_ENTRY kernelBinaryEntry)348 MOS_STATUS VpPlatformInterface::InitVpNativeAdvKernels(
349     std::string            kernelName,
350     VP_KERNEL_BINARY_ENTRY kernelBinaryEntry)
351 {
352     VP_FUNC_CALL();
353 
354     VpRenderKernel vpKernel;
355 
356     vpKernel.SetKernelBinPointer((void *)kernelBinaryEntry.kernelBin);
357     vpKernel.SetKernelName(kernelName);
358     vpKernel.SetKernelBinOffset(0x0);
359     vpKernel.SetKernelBinSize(kernelBinaryEntry.kernelBinSize);
360     m_kernelPool.insert(std::make_pair(vpKernel.GetKernelName(), vpKernel));
361 
362     return MOS_STATUS_SUCCESS;
363 }
364 
InitVpCmKernels(const uint32_t * cisaCode,uint32_t cisaCodeSize,std::string postfix,uint32_t payloadOffset)365 MOS_STATUS VpPlatformInterface::InitVpCmKernels(
366     const uint32_t *cisaCode,
367     uint32_t        cisaCodeSize,
368     std::string     postfix,
369     uint32_t        payloadOffset)
370 {
371     VP_FUNC_CALL();
372     VP_RENDER_CHK_NULL_RETURN(cisaCode);
373 
374     if (cisaCodeSize == 0)
375     {
376         return MOS_STATUS_INVALID_PARAMETER;
377     }
378 
379     uint8_t *pBuf             = (uint8_t *)cisaCode;
380     uint32_t bytePos          = 0;
381     uint32_t cisaMagicNumber  = 0;
382     uint8_t  cisaMajorVersion = 0;
383     uint8_t  cisaMinorVersion = 0;
384     vISA::ISAfile *isaFile    = nullptr;
385 
386     READ_FIELD_FROM_BUF(cisaMagicNumber, uint32_t);
387     READ_FIELD_FROM_BUF(cisaMajorVersion, uint8_t);
388     READ_FIELD_FROM_BUF(cisaMinorVersion, uint8_t);
389 
390     auto getVersionAsInt = [](int major, int minor) { return major * 100 + minor; };
391     if (getVersionAsInt(cisaMajorVersion, cisaMinorVersion) < getVersionAsInt(3, 2) ||
392         cisaMagicNumber != CISA_MAGIC_NUMBER)
393     {
394         return MOS_STATUS_INVALID_PARAMETER;
395     }
396 
397     isaFile = MOS_New(vISA::ISAfile, (uint8_t *)cisaCode, cisaCodeSize);
398     VP_RENDER_CHK_NULL_RETURN(isaFile);
399 
400     if (!isaFile->readFile())
401     {
402         MOS_Delete(isaFile);
403         return MOS_STATUS_INVALID_PARAMETER;
404     }
405 
406     vISA::Header *header = isaFile->getHeader();
407     if(!header)
408     {
409         MOS_Delete(isaFile);
410         VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER);
411     }
412 
413     for (uint32_t i = 0; i < header->getNumKernels(); i++)
414     {
415         vISA::Kernel *kernel = header->getKernelInfo()[i];
416 
417         if(!kernel)
418         {
419             MOS_Delete(isaFile);
420             VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER);
421         }
422 
423         if (kernel->getName() == nullptr || kernel->getNameLen() < 1 || kernel->getNameLen() > 256)
424         {
425             MOS_Delete(isaFile);
426             VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
427         }
428 
429         std::string kernelName(kernel->getName(), kernel->getNameLen());
430         std::string fullKernelName = kernelName;
431         if (!postfix.empty())
432         {
433             fullKernelName += ('_' + postfix);
434         }
435 
436         if (m_kernelPool.end() != m_kernelPool.find(fullKernelName))
437         {
438             continue;
439         }
440 
441         VpRenderKernel vpKernel;
442         vpKernel.SetKernelName(fullKernelName);
443         vpKernel.SetKernelBinPointer((void *)cisaCode);
444 
445         uint8_t          numGenBinaries = kernel->getNumGenBinaries();
446         vISA::GenBinary *genBinary      = kernel->getGenBinaryInfo()[numGenBinaries - 1];
447 
448         vpKernel.SetKernelBinOffset(genBinary->getBinaryOffset());
449         vpKernel.SetKernelBinSize(genBinary->getBinarySize());
450 
451         vISA::KernelBody *kernelBody = isaFile->getKernelsData().at(i);
452         if(!kernelBody)
453         {
454             MOS_Delete(isaFile);
455             VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER);
456         }
457 
458         if (kernelBody->getNumInputs() > CM_MAX_ARGS_PER_KERNEL)
459         {
460             MOS_Delete(isaFile);
461             VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
462         }
463 
464         for (uint32_t j = 0; j < kernelBody->getNumInputs(); j++)
465         {
466             KRN_ARG          kernelArg = {};
467             vISA::InputInfo *inputInfo = kernelBody->getInputInfo()[j];
468             if (!inputInfo)
469             {
470                 MOS_Delete(isaFile);
471                 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_NULL_POINTER);
472             }
473             uint8_t          kind      = inputInfo->getKind();
474 
475             if (kind == 0x2)  // compiler value for surface
476             {
477                 kind = ARG_KIND_SURFACE;  // runtime value for surface. surface will be further classified to 1D/2D/3D
478             }
479             else if (kind == 0x3)  // compiler value for vme index
480             {
481                 kind = ARG_KIND_VME_INDEX;
482             }
483             else if (kind == 0x8)
484             {
485                 kind = ARG_KIND_IMPLICT_LOCALSIZE;
486             }
487             else if (kind == 0x10)
488             {
489                 kind = ARG_KIND_IMPLICT_GROUPSIZE;
490             }
491             else if (kind == 0x18)
492             {
493                 kind = ARG_KIND_IMPLICIT_LOCALID;
494             }
495             else if (kind == 0x2A)
496             {
497                 kind = ARG_KIND_SURFACE_2D_SCOREBOARD;
498             }
499             else if (kind == 0x20)
500             {
501                 kind = ARG_KIND_GENERAL_DEPVEC;
502             }
503             else if (kind == 0x30)
504             {
505                 kind = ARG_KIND_GENERAL_DEPCNT;
506             }
507             else if (kind == 0x80)
508             {
509                 // IMP_PSEUDO_INPUT = 0x80 is pseudo input. All inputs after this
510                 // will be ignored by CMRT without checking and payload copied.
511                 // This resizes the argument count to achieve this.
512                 MOS_Delete(isaFile);
513                 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
514             }
515 
516             kernelArg.uIndex           = j;
517             kernelArg.eArgKind         = (KRN_ARG_KIND)kind;
518             kernelArg.uOffsetInPayload = inputInfo->getOffset() - payloadOffset;
519 
520             kernelArg.uSize            = inputInfo->getSize();
521 
522             vpKernel.AddKernelArg(kernelArg);
523         }
524 
525         m_kernelPool.insert(std::make_pair(vpKernel.GetKernelName(), vpKernel));
526     }
527 
528     MOS_Delete(isaFile);
529 
530     return MOS_STATUS_SUCCESS;
531 }
532 
~VpPlatformInterface()533 VpPlatformInterface::~VpPlatformInterface()
534 {
535     for (auto& kernel : m_kernelPool)
536     {
537         kernel.second.Destroy();
538     }
539 
540     if (!m_vpDelayLoadedBinaryList.empty())
541     {
542         m_vpDelayLoadedBinaryList.clear();
543     }
544 
545     if (!m_vpDelayLoadedNativeFunctionSet.empty())
546     {
547         m_vpDelayLoadedNativeFunctionSet.clear();
548     }
549 
550     if (m_frameTracker)
551     {
552         MOS_Delete(m_frameTracker);
553     }
554 
555 }
556 
GetKernelParam(VpKernelID kernlId,RENDERHAL_KERNEL_PARAM & param)557 MOS_STATUS VpPlatformInterface::GetKernelParam(VpKernelID kernlId, RENDERHAL_KERNEL_PARAM &param)
558 {
559     VP_FUNC_CALL();
560 
561     VpKernelConfig *vpKernelConfig = GetKernelConfig();
562     VP_PUBLIC_CHK_NULL_RETURN(vpKernelConfig);
563     VP_PUBLIC_CHK_STATUS_RETURN(vpKernelConfig->GetKernelParam(kernlId, param));
564     return MOS_STATUS_SUCCESS;
565 }
566 
SetVpFCKernelBinary(const uint32_t * kernelBin,uint32_t kernelBinSize,const uint32_t * fcPatchKernelBin,uint32_t fcPatchKernelBinSize)567 void VpPlatformInterface::SetVpFCKernelBinary(
568                 const uint32_t   *kernelBin,
569                 uint32_t         kernelBinSize,
570                 const uint32_t   *fcPatchKernelBin,
571                 uint32_t         fcPatchKernelBinSize)
572 {
573     VP_FUNC_CALL();
574 
575     m_vpKernelBinary.kernelBin            = kernelBin;
576     m_vpKernelBinary.kernelBinSize        = kernelBinSize;
577     m_vpKernelBinary.fcPatchKernelBin     = fcPatchKernelBin;
578     m_vpKernelBinary.fcPatchKernelBinSize = fcPatchKernelBinSize;
579 }
580 
InitializeDelayedKernels(DelayLoadedKernelType type)581 MOS_STATUS VpPlatformInterface::InitializeDelayedKernels(DelayLoadedKernelType type)
582 {
583     VP_FUNC_CALL();
584     auto feature = m_vpDelayLoadedFeatureSet.find(type);
585     if (feature != m_vpDelayLoadedFeatureSet.end() && feature->second == false && !m_vpDelayLoadedBinaryList.empty())
586     {
587         // Init CM kernel form VP ISA Kernel Binary List
588         for (auto it = m_vpDelayLoadedBinaryList.begin(); it != m_vpDelayLoadedBinaryList.end();)
589         {
590             if (it->kernelType == type)
591             {
592                 VP_PUBLIC_CHK_STATUS_RETURN(InitVpCmKernels(it->kernelBin, it->kernelBinSize, it->postfix, it->payloadOffset));
593                 m_vpDelayLoadedBinaryList.erase(it);
594             }
595             else
596             {
597                 ++it;
598             }
599         }
600         feature->second = true;
601     }
602 
603     if (!m_vpDelayLoadedNativeFunctionSet.empty())
604     {
605         auto delayLoadedKernel = m_vpDelayLoadedNativeFunctionSet.find(type);
606         if (delayLoadedKernel != m_vpDelayLoadedNativeFunctionSet.end())
607         {
608             DelayLoadedFunc func = delayLoadedKernel->second;
609             VP_PUBLIC_CHK_NULL_RETURN(func);
610             func(*this);
611             m_vpDelayLoadedNativeFunctionSet.erase(delayLoadedKernel->first);
612         }
613     }
614 
615     return MOS_STATUS_SUCCESS;
616 }
617 
618 //only for get kernel binary in legacy path not being used in APO path.
GetKernelBinary(const void * & kernelBin,uint32_t & kernelSize,const void * & patchKernelBin,uint32_t & patchKernelSize)619 MOS_STATUS VpPlatformInterface ::GetKernelBinary(const void *&kernelBin, uint32_t &kernelSize, const void *&patchKernelBin, uint32_t &patchKernelSize)
620 {
621     VP_FUNC_CALL();
622 
623     kernelBin       = nullptr;
624     kernelSize      = 0;
625     patchKernelBin  = nullptr;
626     patchKernelSize = 0;
627 
628     return MOS_STATUS_SUCCESS;
629 }
630 
GetInputFrameWidthHeightAlignUnit(PVP_MHWINTERFACE pvpMhwInterface,uint32_t & widthAlignUnit,uint32_t & heightAlignUnit,bool bVdbox,CODECHAL_STANDARD codecStandard,CodecDecodeJpegChromaType jpegChromaType)631 MOS_STATUS VpPlatformInterface::GetInputFrameWidthHeightAlignUnit(
632     PVP_MHWINTERFACE          pvpMhwInterface,
633     uint32_t                 &widthAlignUnit,
634     uint32_t                 &heightAlignUnit,
635     bool                      bVdbox,
636     CODECHAL_STANDARD         codecStandard,
637     CodecDecodeJpegChromaType jpegChromaType)
638 {
639     VP_FUNC_CALL();
640 
641     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
642     VP_PUBLIC_CHK_NULL_RETURN(m_sfcItf);
643     VP_PUBLIC_CHK_STATUS_RETURN(m_sfcItf->GetInputFrameWidthHeightAlignUnit(widthAlignUnit, heightAlignUnit, bVdbox, codecStandard, jpegChromaType));
644 
645     return eStatus;
646 }
647 
GetVeboxHeapInfo(PVP_MHWINTERFACE pvpMhwInterface,const MHW_VEBOX_HEAP ** ppVeboxHeap)648 MOS_STATUS VpPlatformInterface::GetVeboxHeapInfo(
649     PVP_MHWINTERFACE          pvpMhwInterface,
650     const MHW_VEBOX_HEAP    **ppVeboxHeap)
651 {
652     VP_FUNC_CALL();
653 
654     MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
655     const MHW_VEBOX_HEAP *pVeboxHeap = nullptr;
656     VP_PUBLIC_CHK_NULL_RETURN(m_veboxItf);
657 
658     VP_RENDER_CHK_STATUS_RETURN(m_veboxItf->GetVeboxHeapInfo(
659         &pVeboxHeap));
660     *ppVeboxHeap = (const MHW_VEBOX_HEAP *)pVeboxHeap;
661 
662     return eStatus;
663 }
664 
IsVeboxScalabilityWith4KNotSupported(VP_MHWINTERFACE vpMhwInterface)665 bool VpPlatformInterface::IsVeboxScalabilityWith4KNotSupported(
666     VP_MHWINTERFACE          vpMhwInterface)
667 {
668     if (m_veboxItf && !(m_veboxItf->IsVeboxScalabilitywith4K()))
669     {
670         return true;
671     }
672     else
673     {
674         return false;
675     }
676 }
677 
DisableRender()678 void VpPlatformInterface::DisableRender()
679 {
680     // media sfc interface should come to here.
681     VP_PUBLIC_NORMALMESSAGE("Disable Render.");
682     m_isRenderDisabled = true;
683 }
684 
685 //for L0 use only
SetKernelExeEnv(KRN_EXECUTE_ENV & exeEnv)686 MOS_STATUS VpRenderKernel::SetKernelExeEnv(KRN_EXECUTE_ENV &exeEnv)
687 {
688     VP_FUNC_CALL();
689     m_kernelExeEnv = exeEnv;
690     return MOS_STATUS_SUCCESS;
691 }
692 
693 //for L0 use only
AddKernelBti(KRN_BTI & bti)694 MOS_STATUS VpRenderKernel::AddKernelBti(KRN_BTI &bti)
695 {
696     VP_FUNC_CALL();
697     m_kernelBtis.emplace(bti.uIndex, bti.uBTI);
698     return MOS_STATUS_SUCCESS;
699 }
700 
701 //for L0 use only
SetKernelCurbeSize(uint32_t size)702 MOS_STATUS VpRenderKernel::SetKernelCurbeSize(uint32_t size)
703 {
704     VP_FUNC_CALL();
705 
706     m_curbeSize = size;
707     return MOS_STATUS_SUCCESS;
708 }
709 
710 //for L0 use only
InitVpDelayedNativeAdvKernel(const uint32_t * kernelBin,uint32_t kernelBinSize,KRN_ARG * kernelArgs,uint32_t kernelArgSize,uint32_t kernelCurbeSize,KRN_EXECUTE_ENV & kernelExeEnv,KRN_BTI * kernelBtis,uint32_t kernelBtiSize,std::string kernelName)711 void VpPlatformInterface::InitVpDelayedNativeAdvKernel(
712     const uint32_t  *kernelBin,
713     uint32_t         kernelBinSize,
714     KRN_ARG         *kernelArgs,
715     uint32_t         kernelArgSize,
716     uint32_t         kernelCurbeSize,
717     KRN_EXECUTE_ENV &kernelExeEnv,
718     KRN_BTI         *kernelBtis,
719     uint32_t         kernelBtiSize,
720     std::string      kernelName)
721 {
722     VP_FUNC_CALL();
723 
724     VpRenderKernel vpKernel;
725 
726     vpKernel.SetKernelBinPointer((void *)kernelBin);
727     vpKernel.SetKernelName(kernelName);
728     vpKernel.SetKernelBinOffset(kernelExeEnv.uOffsetToSkipPerThreadDataLoad);
729     vpKernel.SetKernelBinSize(kernelBinSize - kernelExeEnv.uOffsetToSkipPerThreadDataLoad);
730     vpKernel.SetKernelExeEnv(kernelExeEnv);
731     vpKernel.SetKernelCurbeSize(kernelCurbeSize);
732 
733     for (uint32_t i = 0; i < kernelArgSize; ++i)
734     {
735         vpKernel.AddKernelArg(kernelArgs[i]);
736     }
737 
738     for (uint32_t i = 0; i < kernelBtiSize; ++i)
739     {
740         vpKernel.AddKernelBti(kernelBtis[i]);
741     }
742 
743     m_kernelPool.insert(std::make_pair(vpKernel.GetKernelName(), vpKernel));
744 }