Debian Codegraph @

media_softlet/agnostic/common/codec/hal/shared/huc_kernel_source.h

raw
1 /*
2 * Copyright (c) 2024, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file huc_kernel_source.h
24 //! \brief Defines the common interface for Huc kernel source management.
25 //! \details The Huc kernel source is further sub-divided by platforms.
26 //!
27 #ifndef __HUC_KERNEL_SOURCE_H__
28 #define __HUC_KERNEL_SOURCE_H__
29
30 #include <map>
31 #include "media_class_trace.h"
32 #include "media_pipeline.h"
33
34 #if defined(MEDIA_BIN_SUPPORT)
35 #define HUC_KERNEL_BIN_ELEMENT(bin) \
36 { \
37 (uint32_t * const *)&(bin), \
38 (uint32_t *)&(bin##_size) \
39 }
40 #else
41 #define HUC_KERNEL_BIN_ELEMENT(bin) \
42 { \
43 (uint32_t * const *)&(bin##_local), \
44 (uint32_t *)&(bin##_size_local) \
45 }
46 #define HUC_KERNEL_BIN_LOCAL(bin) \
47 const uint32_t * const bin##_local = &bin[0]; \
48 const uint32_t bin##_size_local = bin##_size;
49 #endif
50
51 //! \brief Interface of the Huc binary management.
52 class HucKernelSource
53 {
54 public:
55 struct HucManifest
56 {
57 const uint8_t *m_data = nullptr;
58 uint32_t m_size = 0;
59 };
60
61 struct HucBinary
62 {
63 const uint8_t *m_data = nullptr;
64 uint32_t m_size = 0;
65 };
66
67 enum KernelId
68 {
69 hevcS2lKernelId = 1,
70 drmKernelId = 2,
71 copyKernelId = 3,
72 vdencBrcInitKernelId = 4,
73 vdencBrcUpdateKernelId = 5,
74 vp9ProbUpdateKernelId = 6,
75 vp9EncKernelId = 7,
76 hevcBrcInitKernelId = 8,
77 hevcBrcUpdateKernelId = 9,
78 hevcBrcLowdelayKernelId = 10,
79 vp9VdencBrcInitKernelId = 11,
80 vp9VdencBrcUpdateKernelId = 12,
81 vp9VdencProbKernelId = 13,
82 cmdInitializerKernelId = 14,
83 pakIntegrationKernelId = 15,
84 hevcLaAnalysisKernelId = 16,
85 backAnnonationKernelId = 17,
86 av1BrcInitKernelId = 18,
87 av1BrcUpdateKernelId = 19,
88 vvcS2lKernelId = 20,
89 avcPxpBrcInitKernelId = 21,
90 avcPxpBrcUpdateKernelId = 22,
91 av1SlbbUpdateKernelId = 23, // AV1 SLBB update kernel
92 avcSlbbUpdateKernelId = 24, // AVC SLBB update kernel
93 hevcSlbbUpdateKernelId = 25 // HEVC SLBB update kernel
94 };
95
96 //!
97 //! \brief Copy constructor
98 //!
99 HucKernelSource(const HucKernelSource &) = delete;
100
101 //!
102 //! \brief Copy assignment operator
103 //!
104 HucKernelSource &operator=(const HucKernelSource &) = delete;
105
106 //!
107 //! \brief Destructor
108 //!
109 virtual ~HucKernelSource() {}
110
111 //!
112 //! \brief Return manifest for Huc kernels
113 //! \param [out] manifest
114 //! Manifest for Huc kernels in order
115 //! \return MOS_STATUS
116 //! MOS_STATUS_SUCCESS if success, else fail reason
117 //!
118 virtual MOS_STATUS GetManifest(HucManifest &manifest) = 0;
119
120 //!
121 //! \brief Return hash index for specified kernel
122 //! \param [in] kernelId
123 //! Kernel ID for hash index query
124 //! \param [out] hashIndex
125 //! Kernel hash index returned if kernel ID is valid
126 //! \return MOS_STATUS
127 //! MOS_STATUS_SUCCESS if success, else fail reason
128 //!
129 virtual MOS_STATUS GetKernelHashIdx(const uint32_t kernelId, uint32_t &hashIndex)
130 {
131 auto &hashIdxTable = GetHashIdxTable();
132 auto iter = hashIdxTable.find(kernelId);
133 if (iter == hashIdxTable.end())
134 {
135 return MOS_STATUS_INVALID_PARAMETER;
136 }
137
138 if (iter->second < GetMinHashIndex() || iter->second > GetMaxHashIndex())
139 {
140 MOS_OS_CRITICALMESSAGE("hask index %d out of range [%d, %d].",
141 iter->second, GetMinHashIndex(), GetMaxHashIndex());
142 return MOS_STATUS_INVALID_PARAMETER;
143 }
144
145 hashIndex = iter->second;
146 return MOS_STATUS_SUCCESS;
147 }
148
149 //!
150 //! \brief Return binary for specified kernel
151 //! \param [in] kernelId
152 //! Kernel ID for hash index query
153 //! \param [out] hucBinary
154 //! Kernel binary returned if kernel ID is valid
155 //! \return MOS_STATUS
156 //! MOS_STATUS_SUCCESS if success, else fail reason
157 //!
158 virtual MOS_STATUS GetKernelBin(const uint32_t kernelId, HucBinary &hucBinary)
159 {
160 auto &binTable = GetBinTable();
161 auto iter = binTable.find(kernelId);
162 if (iter == binTable.end())
163 {
164 return MOS_STATUS_INVALID_PARAMETER;
165 }
166
167 hucBinary.m_data = (iter->second.m_data == nullptr) ? nullptr : reinterpret_cast<const uint8_t *>(*(iter->second.m_data));
168 hucBinary.m_size = (iter->second.m_size == nullptr) ? 0 : *(iter->second.m_size);
169 return MOS_STATUS_SUCCESS;
170 }
171
172 virtual bool IsPpgttMode(MEDIA_FEATURE_TABLE *skuTable, MediaUserSettingSharedPtr userSettingPtr)
173 {
174 if (skuTable == nullptr)
175 {
176 return false;
177 }
178
179 if(!MEDIA_IS_SKU(skuTable, FtrPPGTTBasedHuCLoad))
180 {
181 return false;
182 }
183
184 #if (_DEBUG || _RELEASE_INTERNAL)
185 const std::string enableKey = "PPGTT Huc Enable";
186
187 MOS_STATUS status = DeclareUserSettingKeyForDebug(
188 userSettingPtr,
189 enableKey,
190 MediaUserSetting::Group::Device,
191 true, // enable by default
192 false);
193
194 if (status == MOS_STATUS_SUCCESS || status == MOS_STATUS_FILE_EXISTS)
195 {
196 // check if disabled by regkey
197 bool enablePpgtt = true;
198 ReadUserSettingForDebug(
199 userSettingPtr,
200 enablePpgtt,
201 enableKey,
202 MediaUserSetting::Group::Device);
203
204 if (!enablePpgtt)
205 {
206 return false;
207 }
208 }
209 #endif
210
211 return true;
212 }
213
214 virtual MOS_STATUS ReportMode(MEDIA_FEATURE_TABLE *skuTable, MediaUserSettingSharedPtr userSettingPtr)
215 {
216 MOS_CHK_NULL_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_PUBLIC, skuTable);
217
218 const std::string inUseKey = "PPGTT Huc In Use";
219
220 MOS_STATUS status = DeclareUserSettingKey(
221 userSettingPtr,
222 inUseKey,
223 MediaUserSetting::Group::Device,
224 (int32_t)0,
225 true);
226 if (status == MOS_STATUS_SUCCESS || status == MOS_STATUS_FILE_EXISTS)
227 {
228 bool isPpgttEnable = IsPpgttMode(skuTable, userSettingPtr);
229
230 ReportUserSetting(
231 userSettingPtr,
232 inUseKey,
233 isPpgttEnable ? 1 : 0,
234 MediaUserSetting::Group::Device);
235 }
236
237 return MOS_STATUS_SUCCESS;
238 }
239
240 protected:
241 //!
242 //! \brief Constructor
243 //!
244 HucKernelSource() {}
245
246 struct HucBinaryInternal
247 {
248 uint32_t * const *m_data = nullptr;
249 uint32_t *m_size = nullptr;
250 };
251
252 // Binary map table (kernel id, binay data point)
253 using BinaryTable = std::map<const uint32_t, const HucBinaryInternal>;
254
255 // Hash index table (kernel id, hash index)
256 using HashIdxTable = std::map<const uint32_t, const uint32_t>;
257
258 constexpr static HucBinaryInternal m_invalidKernelBin = { nullptr, nullptr };
259
260 constexpr static uint32_t m_invalidHashIndex = 0xff; //!< Invalid hash index
261
262 private:
263 virtual const BinaryTable &GetBinTable() = 0;
264 virtual const HashIdxTable &GetHashIdxTable() = 0;
265
266 virtual const uint32_t GetMinHashIndex() { return m_minHashIndex; }
267 virtual const uint32_t GetMaxHashIndex() { return m_maxHashIndex; }
268
269 constexpr static uint32_t m_minHashIndex = 1; //!< min hash index
270 constexpr static uint32_t m_maxHashIndex = 31; //!< max hash index
271
272 MEDIA_CLASS_DEFINE_END(HucKernelSource)
273 };
274
275 #endif // __HUC_KERNEL_SOURCE_H__