1 /*
2 * Copyright (c) 2020-2021, 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 //!
24 //! \file     vp_platform_interface.h
25 //! \brief    platform specific vp interfaces.
26 //!
27 #ifndef __VP_PLATFORM_INTERFACE_H__
28 #define __VP_PLATFORM_INTERFACE_H__
29 
30 #include "hal_kerneldll_next.h"
31 #include "vp_feature_manager.h"
32 #include "vp_render_common.h"
33 #include "vp_kernel_config.h"
34 #include "media_copy.h"
35 #include "vp_frametracker.h"
36 
37 namespace vp
38 {
39 class VPFeatureManager;
40 class SfcRenderBase;
41 class VpKernelSet;
42 typedef void (*DelayLoadedFunc)(vp::VpPlatformInterface &vpPlatformInterface);
43 
44 struct VP_KERNEL_BINARY_ENTRY
45 {
46     const uint32_t        *kernelBin    = nullptr;
47     uint32_t              kernelBinSize = 0;
48     std::string           postfix       = "";
49     DelayLoadedKernelType kernelType    = KernelNone;
50     uint32_t              payloadOffset = 0;
51 };
52 
53 struct VP_KERNEL_BINARY
54 {
55     const uint32_t        *kernelBin           = nullptr;
56     uint32_t              kernelBinSize        = 0;
57     const uint32_t        *fcPatchKernelBin    = nullptr;
58     uint32_t              fcPatchKernelBinSize = 0;
59 };
60 
61 class VpRenderKernel
62 {
63 public:
VpRenderKernel()64     VpRenderKernel() {};
~VpRenderKernel()65     virtual ~VpRenderKernel() {};
66 
67     MOS_STATUS InitVPKernel(
68         const Kdll_RuleEntry* kernelRules,
69         const uint32_t*       kernelBin,
70         uint32_t              kernelSize,
71         const uint32_t*       patchKernelBin,
72         uint32_t              patchKernelSize,
73         void(*ModifyFunctionPointers)(PKdll_State));
74 
75     MOS_STATUS Destroy();
76 
GetKdllState()77     Kdll_State* GetKdllState()
78     {
79         return m_kernelDllState;
80     }
81 
82     MOS_STATUS SetKernelName(std::string kernelname);
83 
GetKernelName()84     std::string& GetKernelName()
85     {
86         return m_kernelName;
87     }
88 
GetKernelSize()89     uint32_t& GetKernelSize()
90     {
91         return m_kernelBinSize;
92     }
93 
GetKernelBinOffset()94     uint32_t& GetKernelBinOffset()
95     {
96         return m_kernelBinOffset;
97     }
98 
GetKernelBinPointer()99     const void* GetKernelBinPointer()
100     {
101         return m_kernelBin;
102     }
103 
104     MOS_STATUS SetKernelBinOffset(uint32_t offset);
105 
106     MOS_STATUS SetKernelBinSize(uint32_t size);
107 
108     MOS_STATUS SetKernelBinPointer(void* pBin);
109 
110     MOS_STATUS AddKernelArg(KRN_ARG& arg);
111 
GetKernelArgs()112     KERNEL_ARGS GetKernelArgs()
113     {
114         return m_kernelArgs;
115     }
116 
117 
118     //for L0 use only
GetCurbeSize()119     uint32_t &GetCurbeSize()
120     {
121         return m_curbeSize;
122     }
123 
124     MOS_STATUS SetKernelExeEnv(KRN_EXECUTE_ENV &exeEnv);
125 
126     MOS_STATUS SetKernelCurbeSize(uint32_t size);
127 
128     MOS_STATUS AddKernelBti(KRN_BTI &bti);
129 
GetKernelBtis()130     KERNEL_BTIS GetKernelBtis()
131     {
132         return m_kernelBtis;
133     }
134 
GetKernelExeEnv()135     KRN_EXECUTE_ENV &GetKernelExeEnv()
136     {
137         return m_kernelExeEnv;
138     }
139 
140 protected:
141     // Compositing Kernel DLL/Search state
142     const Kdll_RuleEntry        *m_kernelDllRules = nullptr;
143     Kdll_State                  *m_kernelDllState = nullptr;
144     // Compositing Kernel buffer and size
145     const void                  *m_kernelBin = nullptr;
146     uint32_t                    m_kernelBinSize = 0;
147     // CM Kernel Execution Code Offset
148     uint32_t                    m_kernelBinOffset = 0;
149     // CM Kernel Arguments or L0 Kernel Arguments
150     KERNEL_ARGS                 m_kernelArgs;
151     std::string                 m_kernelName = {};
152     // CM Compositing Kernel patch file buffer and size
153     const void                  *m_fcPatchBin = nullptr;
154     uint32_t                    m_fcPatchBinSize = 0;
155 
156     //for L0 use only
157     uint32_t m_curbeSize = 0;
158     KERNEL_BTIS     m_kernelBtis;
159     KRN_EXECUTE_ENV m_kernelExeEnv = {};
160 
161 public:
162     const static std::string          s_kernelNameNonAdvKernels;
163 
164 MEDIA_CLASS_DEFINE_END(vp__VpRenderKernel)
165 };
166 
167 using KERNEL_POOL = std::map<std::string, VpRenderKernel>;
168 
169 class VpPlatformInterface
170 {
171 public:
172 
173     VpPlatformInterface(PMOS_INTERFACE pOsInterface, bool clearViewMode = false);
174 
175     virtual ~VpPlatformInterface();
176 
177     virtual MOS_STATUS InitVpCmKernels(
178         const uint32_t*       cisaCode,
179         uint32_t              cisaCodeSize,
180         std::string           postfix = "",
181         uint32_t              payloadOffset = CM_PAYLOAD_OFFSET);
182 
183     virtual MOS_STATUS InitVpNativeAdvKernels(
184         std::string kernelName,
185         VP_KERNEL_BINARY_ENTRY kernelBinaryEntry);
186 
InitVpHwCaps(VP_HW_CAPS & vpHwCaps)187     virtual MOS_STATUS InitVpHwCaps(VP_HW_CAPS &vpHwCaps)
188     {
189         VP_PUBLIC_CHK_STATUS_RETURN(InitVpVeboxSfcHwCaps(vpHwCaps.m_veboxHwEntry, Format_Count, vpHwCaps.m_sfcHwEntry, Format_Count));
190         VP_PUBLIC_CHK_STATUS_RETURN(InitVpRenderHwCaps());
191         VP_PUBLIC_CHK_STATUS_RETURN(InitPolicyRules(vpHwCaps.m_rules));
192         return MOS_STATUS_SUCCESS;
193     }
194 
195     virtual MOS_STATUS InitVPFCKernels(
196         const Kdll_RuleEntry* kernelRules,
197         const uint32_t* kernelBin,
198         uint32_t              kernelSize,
199         const uint32_t* patchKernelBin,
200         uint32_t              patchKernelSize,
201         void (*ModifyFunctionPointers)(PKdll_State) = nullptr);
202 
203     virtual MOS_STATUS InitPolicyRules(VP_POLICY_RULES &rules);
InitVpVeboxSfcHwCaps(VP_VEBOX_ENTRY_REC * veboxHwEntry,uint32_t veboxEntryCount,VP_SFC_ENTRY_REC * sfcHwEntry,uint32_t sfcEntryCount)204     virtual MOS_STATUS InitVpVeboxSfcHwCaps(VP_VEBOX_ENTRY_REC *veboxHwEntry, uint32_t veboxEntryCount, VP_SFC_ENTRY_REC *sfcHwEntry, uint32_t sfcEntryCount)
205     {
206         return MOS_STATUS_UNIMPLEMENTED;
207     }
208     virtual MOS_STATUS        InitVpRenderHwCaps();
CreateFeatureChecker(_VP_MHWINTERFACE * hwInterface)209     virtual VPFeatureManager *CreateFeatureChecker(_VP_MHWINTERFACE *hwInterface)
210     {
211         return nullptr;
212     }
CreateVeboxPacket(MediaTask * task,_VP_MHWINTERFACE * hwInterface,VpAllocator * & allocator,VPMediaMemComp * mmc)213     virtual VpCmdPacket *CreateVeboxPacket(MediaTask * task, _VP_MHWINTERFACE *hwInterface, VpAllocator *&allocator, VPMediaMemComp *mmc)
214     {
215         return nullptr;
216     }
CreateRenderPacket(MediaTask * task,_VP_MHWINTERFACE * hwInterface,VpAllocator * & allocator,VPMediaMemComp * mmc,VpKernelSet * kernel)217     virtual VpCmdPacket *CreateRenderPacket(MediaTask * task, _VP_MHWINTERFACE *hwInterface, VpAllocator *&allocator, VPMediaMemComp *mmc, VpKernelSet* kernel)
218     {
219         return nullptr;
220     }
221 
CreateMediaCopy()222     virtual MediaCopyBaseState* CreateMediaCopy()
223     {
224         return nullptr;
225     }
226 
CreateSfcRender(SfcRenderBase * & sfcRender,VP_MHWINTERFACE & vpMhwinterface,PVpAllocator allocator)227     virtual MOS_STATUS CreateSfcRender(SfcRenderBase *&sfcRender, VP_MHWINTERFACE &vpMhwinterface, PVpAllocator allocator)
228     {
229         return MOS_STATUS_UNIMPLEMENTED;
230     }
231 
GetKernelPool()232     KERNEL_POOL& GetKernelPool()
233     {
234         return m_kernelPool;
235     }
236 
GetOsInterface()237     PMOS_INTERFACE &GetOsInterface()
238     {
239         return m_pOsInterface;
240     }
241 
VeboxQueryStatLayout(VEBOX_STAT_QUERY_TYPE QueryType,uint32_t * pQuery)242     virtual MOS_STATUS VeboxQueryStatLayout(
243         VEBOX_STAT_QUERY_TYPE QueryType,
244         uint32_t* pQuery)
245     {
246         return MOS_STATUS_SUCCESS;
247     }
248 
249     virtual uint32_t VeboxQueryStaticSurfaceSize() = 0;
250 
IsPlatformCompressionEnabled()251     virtual bool IsPlatformCompressionEnabled()
252     {
253         return !m_vpMmcDisabled;
254     }
255 
IsGpuContextCreatedInPipelineInit()256     virtual bool IsGpuContextCreatedInPipelineInit()
257     {
258         return true;
259     }
260 
261     virtual MOS_STATUS GetInputFrameWidthHeightAlignUnit(
262         PVP_MHWINTERFACE          pvpMhwInterface,
263         uint32_t                 &widthAlignUnit,
264         uint32_t                 &heightAlignUnit,
265         bool                      bVdbox,
266         CODECHAL_STANDARD         codecStandard,
267         CodecDecodeJpegChromaType jpegChromaType);
268 
269     virtual bool IsVeboxScalabilityWith4KNotSupported(
270         VP_MHWINTERFACE           vpMhwInterface);
271 
272     virtual MOS_STATUS GetVeboxHeapInfo(
273         PVP_MHWINTERFACE          pvpMhwInterface,
274         const MHW_VEBOX_HEAP    **ppVeboxHeap);
275 
SetMhwSfcItf(std::shared_ptr<mhw::sfc::Itf> sfcItf)276     inline void SetMhwSfcItf(std::shared_ptr<mhw::sfc::Itf> sfcItf)
277     {
278         m_sfcItf = sfcItf;
279     }
280 
SetMhwVeboxItf(std::shared_ptr<mhw::vebox::Itf> veboxItf)281     inline void SetMhwVeboxItf(std::shared_ptr<mhw::vebox::Itf> veboxItf)
282     {
283         m_veboxItf = veboxItf;
284     }
285 
SetMhwRenderItf(std::shared_ptr<mhw::render::Itf> renderItf)286     inline void SetMhwRenderItf(std::shared_ptr<mhw::render::Itf> renderItf)
287     {
288         m_renderItf = renderItf;
289     }
290 
SetMhwMiItf(std::shared_ptr<mhw::mi::Itf> miItf)291     inline void SetMhwMiItf(std::shared_ptr<mhw::mi::Itf> miItf)
292     {
293         m_miItf = miItf;
294     }
295 
GetMhwSfcItf()296     inline std::shared_ptr<mhw::sfc::Itf> GetMhwSfcItf()
297     {
298         return m_sfcItf;
299     }
300 
GetMhwVeboxItf()301     inline std::shared_ptr<mhw::vebox::Itf> GetMhwVeboxItf()
302     {
303         return m_veboxItf;
304     }
305 
GetMhwRenderItf()306     inline std::shared_ptr<mhw::render::Itf> GetMhwRenderItf()
307     {
308         return m_renderItf;
309     }
310 
GetMhwMiItf()311     inline std::shared_ptr<mhw::mi::Itf> GetMhwMiItf()
312     {
313         return m_miItf;
314     }
315 
GetKernelConfig()316     virtual VpKernelConfig* GetKernelConfig()
317     {
318         return m_vpKernelConfig;
319     }
320 
SetKernelConfig(VpKernelConfig * vpKernelConfig)321     virtual MOS_STATUS SetKernelConfig(VpKernelConfig* vpKernelConfig)
322     {
323         m_vpKernelConfig = vpKernelConfig;
324         return MOS_STATUS_SUCCESS;
325     }
326 
327     MOS_STATUS GetKernelParam(VpKernelID kernlId, RENDERHAL_KERNEL_PARAM &param);
328 
329     void SetVpFCKernelBinary(
330                 const uint32_t   *kernelBin,
331                 uint32_t         kernelBinSize,
332                 const uint32_t   *fcPatchKernelBin,
333                 uint32_t         fcPatchKernelBinSize);
334 
335     virtual void AddVpIsaKernelEntryToList(
336         const uint32_t       *kernelBin,
337         uint32_t              kernelBinSize,
338         std::string           postfix         = "",
339         DelayLoadedKernelType delayKernelType = KernelNone,
340         uint32_t              payloadOffset   = CM_PAYLOAD_OFFSET);
341 
342     virtual void AddVpNativeAdvKernelEntryToList(
343                 const uint32_t *kernelBin,
344                 uint32_t        kernelBinSize,
345                 std::string     kernelName);
346 
347     virtual void InitVpDelayedNativeAdvKernel(
348         const uint32_t *kernelBin,
349         uint32_t        kernelBinSize,
350         std::string     kernelName);
351 
352     //for L0 kernel use only
353     virtual void InitVpDelayedNativeAdvKernel(
354         const uint32_t  *kernelBin,
355         uint32_t         kernelBinSize,
356         KRN_ARG         *kernelArgs,
357         uint32_t         kernelArgSize,
358         uint32_t         kernelCurbeSize,
359         KRN_EXECUTE_ENV& kernelExeEnv,
360         KRN_BTI         *kernelBtis,
361         uint32_t         kernelBtiSize,
362         std::string      kernelName);
363 
364     virtual void AddNativeAdvKernelToDelayedList(
365         DelayLoadedKernelType kernelType,
366         DelayLoadedFunc       func);
367 
368     //only for get kernel binary in legacy path not being used in APO path.
369     virtual MOS_STATUS GetKernelBinary(const void *&kernelBin, uint32_t &kernelSize, const void *&patchKernelBin, uint32_t &patchKernelSize);
370 
371     virtual MOS_STATUS InitializeDelayedKernels(DelayLoadedKernelType type);
372 
373     virtual MOS_STATUS ConfigVirtualEngine() = 0;
374 
375     virtual MOS_STATUS ConfigureVpScalability(VP_MHWINTERFACE &vpMhwInterface) = 0;
376 
IsEufusionBypassWaEnabled()377     virtual bool IsEufusionBypassWaEnabled()
378     {
379         return false;
380     }
381 
IsAdvanceNativeKernelSupported()382     virtual bool IsAdvanceNativeKernelSupported()
383     {
384         return true;
385     }
386 
IsRenderMMCLimitationCheckNeeded()387     virtual bool IsRenderMMCLimitationCheckNeeded()
388     {
389         return false;
390     }
391 
IsDecompForInterlacedSurfWaEnabled()392     virtual bool IsDecompForInterlacedSurfWaEnabled()
393     {
394         return true;
395     }
396 
IsLegacyEuCountInUse()397     virtual bool IsLegacyEuCountInUse()
398     {
399         return false;
400     }
401 
IsRenderDisabled()402     bool IsRenderDisabled()
403     {
404         return m_isRenderDisabled;
405     }
406 
407     void DisableRender();
408 
GetModelConfig(int eu,int width,int height,double fps)409     virtual int GetModelConfig(int eu, int width, int height, double fps)
410     {
411         return 0;
412     };
413 
InitFrameTracker()414     virtual MOS_STATUS InitFrameTracker()
415     {
416         return MOS_STATUS_SUCCESS;
417     }
418 
SupportL0FC()419     virtual bool SupportL0FC()
420     {
421         return false;
422     }
423 
424 protected:
425     PMOS_INTERFACE m_pOsInterface = nullptr;
426     VP_KERNEL_BINARY m_vpKernelBinary = {};                 //!< vp kernels
427     VpKernelConfig  *m_vpKernelConfig = nullptr;
428     KERNEL_POOL    m_kernelPool;
429     void (*m_modifyKdllFunctionPointers)(PKdll_State) = nullptr;
430     bool m_sfc2PassScalingEnabled = false;
431     bool m_sfc2PassScalingPerfMode = false;
432     bool m_vpMmcDisabled = false;
433 
434     MediaUserSettingSharedPtr m_userSettingPtr  = nullptr;  //!< usersettingInstance
435     std::shared_ptr<mhw::vebox::Itf>        m_veboxItf  = nullptr;
436     std::shared_ptr<mhw::sfc::Itf>          m_sfcItf    = nullptr;
437     std::shared_ptr<mhw::render::Itf>       m_renderItf = nullptr;
438     std::shared_ptr<mhw::mi::Itf>           m_miItf     = nullptr;
439 
440     std::vector<VP_KERNEL_BINARY_ENTRY>    m_vpIsaKernelBinaryList;
441     std::vector<VP_KERNEL_BINARY_ENTRY>    m_vpDelayLoadedBinaryList;
442     std::map<DelayLoadedKernelType, bool>  m_vpDelayLoadedFeatureSet;
443     std::map<std::string, VP_KERNEL_BINARY_ENTRY> m_vpNativeAdvKernelBinaryList;
444     std::map<DelayLoadedKernelType, DelayLoadedFunc> m_vpDelayLoadedNativeFunctionSet;
445 
446     bool m_isRenderDisabled = false;
447     VpFrameTracker *m_frameTracker     = nullptr;
448 
449     MEDIA_CLASS_DEFINE_END(vp__VpPlatformInterface)
450 };
451 
452 }
453 #endif // !__VP_PLATFORM_INTERFACE_H__
454