1 /* Copyright (c) 2020-2022, Intel Corporation
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included
11 * in all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
17 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
18 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19 * OTHER DEALINGS IN THE SOFTWARE.
20 */
21 //!
22 //! \file     vp_render_kernelset.h
23 //! \brief    The header file of the base class of kernel set
24 //! \details  The kernel set will include kernel generation from binary.
25 //!           It's responsible for setting up HW states and generating the SFC
26 //!           commands.
27 //!
28 #ifndef __VP_KERNEL_SET_H__
29 #define __VP_KERNEL_SET_H__
30 
31 #include "vp_platform_interface.h"
32 #include "vp_pipeline_common.h"
33 #include "vp_render_kernel_obj.h"
34 #include <map>
35 
36 namespace vp {
37 
38 // KernelIndex is the index in KERNEL_PARAMS_LIST
39 using KERNEL_OBJECTS = std::map<KernelIndex, VpRenderKernelObj*>;
40 using KERNEL_RENDER_DATA = std::map<KernelIndex, KERNEL_PACKET_RENDER_DATA>;
41 using KERNEL_PARAMS_LIST = std::vector<KERNEL_PARAMS>;
42 
43 class VpKernelSet
44 {
45 public:
46     VpKernelSet(PVP_MHWINTERFACE hwInterface, PVpAllocator allocator);
~VpKernelSet()47     virtual ~VpKernelSet()
48     {
49         for (auto &it : m_cachedKernels)
50         {
51             MOS_Delete(it.second);
52         }
53     };
54 
Clean()55     virtual MOS_STATUS Clean()
56     {
57         return MOS_STATUS_SUCCESS;
58     }
59 
Destroy()60     virtual MOS_STATUS Destroy()
61     {
62         return MOS_STATUS_SUCCESS;
63     }
64 
65     virtual MOS_STATUS CreateSingleKernelObject(
66         VpRenderKernelObj *&kernel,
67         VpKernelID kernelId,
68         KernelIndex kernelIndex);
69 
70     virtual MOS_STATUS CreateKernelObjects(
71         KERNEL_PARAMS_LIST& kernelParams,
72         VP_SURFACE_GROUP& surfacesGroup,
73         KERNEL_SAMPLER_STATE_GROUP& samplerStateGroup,
74         KERNEL_CONFIGS& kernelConfigs,
75         KERNEL_OBJECTS& kernelObjs,
76         VP_RENDER_CACHE_CNTL& surfMemCacheCtl,
77         VP_PACKET_SHARED_CONTEXT* sharedContext);
78 
DestroyKernelObjects(KERNEL_OBJECTS & kernelObjs)79     virtual MOS_STATUS DestroyKernelObjects(KERNEL_OBJECTS& kernelObjs)
80     {
81         while (!kernelObjs.empty())
82         {
83             auto it = kernelObjs.begin();
84             if (m_cachedKernels.size() == 0 || m_cachedKernels.end() == m_cachedKernels.find(it->second->GetKernelId()))
85             {
86                 // Only destroy the kernels not exists in m_cachedKernels.
87                 MOS_Delete(it->second);
88             }
89             kernelObjs.erase(it);
90         }
91 
92         return MOS_STATUS_SUCCESS;
93     }
94 protected:
95 
96     MOS_STATUS GetKernelInfo(std::string kernalName, uint32_t kuid, uint32_t &size, void *&kernel);
97 
98     MOS_STATUS FindAndInitKernelObj(VpRenderKernelObj* kernelObj);
99 
100 protected:
101     KERNEL_POOL*          m_pKernelPool = nullptr;
102     PVP_MHWINTERFACE      m_hwInterface = nullptr;
103     PVpAllocator          m_allocator   = nullptr;
104     std::map<VpKernelID, VpRenderKernelObj *> m_cachedKernels;
105 
106 MEDIA_CLASS_DEFINE_END(vp__VpKernelSet)
107 };
108 }
109 
110 #endif //__VP_KERNEL_SET_H__
111