xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/gen12/ddi/media_libva_caps_g12.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2018-2019, 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     media_libva_caps_g12.h
25 //! \brief    This file defines the C++ class/interface for gen12 media capbilities.
26 //!
27 
28 #ifndef __MEDIA_LIBVA_CAPS_G12_H__
29 #define __MEDIA_LIBVA_CAPS_G12_H__
30 
31 #include "media_libva_caps.h"
32 
33 //!
34 //! \class  MediaLibvaCapsG12
35 //! \brief  Media libva caps Gen12
36 //!
37 class MediaLibvaCapsG12 : public MediaLibvaCaps
38 {
39 public:
40     //!
41     //! \brief    Constructor
42     //!
MediaLibvaCapsG12(DDI_MEDIA_CONTEXT * mediaCtx)43     MediaLibvaCapsG12(DDI_MEDIA_CONTEXT *mediaCtx) : MediaLibvaCaps(mediaCtx)
44     {
45         // TGL supported Encode format
46         static struct EncodeFormatTable encodeFormatTableTGL[] =
47         {
48             {AVC, DualPipe, VA_RT_FORMAT_YUV420},
49             {AVC, Vdenc, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_RGB32},
50             {HEVC, DualPipe, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10BPP | VA_RT_FORMAT_YUV420_12 |
51              VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV422_10 |  VA_RT_FORMAT_YUV422_12},
52             {HEVC, Vdenc, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10BPP |
53              VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_YUV444_10 | VA_RT_FORMAT_RGB32 |
54              VA_RT_FORMAT_RGB32_10BPP | VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV422_10},
55             {VP9, Vdenc, VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV420_10BPP |
56              VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_YUV444_10 | VA_RT_FORMAT_RGB32 |
57              VA_RT_FORMAT_RGB32_10BPP},
58         };
59         m_encodeFormatTable = (struct EncodeFormatTable*)(&encodeFormatTableTGL[0]);
60         m_encodeFormatCount = sizeof(encodeFormatTableTGL)/sizeof(struct EncodeFormatTable);
61         return;
62     }
63 
64     //!
Init()65     virtual VAStatus Init() override
66     {
67         return LoadProfileEntrypoints();
68     }
69 
70     virtual VAStatus QueryImageFormats(VAImageFormat *formatList, int32_t *num_formats) override;
71 
72     virtual uint32_t GetImageFormatsMaxNum() override;
73 
74     virtual bool IsImageSupported(uint32_t fourcc) override;
75 
76     //!
77     //! \brief    Populate the color masks info
78     //!
79     //! \param    [in,out] Image format
80     //!           Pointer to a VAImageFormat array. Color masks information will be populated to this
81     //!           structure.
82     //!
83     //! \return   VAStatus
84     //!           VA_STATUS_SUCCESS if succeed
85     //!
86     virtual VAStatus PopulateColorMaskInfo(VAImageFormat *vaImgFmt) override;
87 
88     //!
89     //! \brief    Return internal encode mode for given profile and entrypoint
90     //!
91     //! \param    [in] profile
92     //!           Specify the VAProfile
93     //!
94     //! \param    [in] entrypoint
95     //!           Specify the VAEntrypoint
96     //!
97     //! \return   Codehal mode
98     //!
99     CODECHAL_MODE GetEncodeCodecMode(VAProfile profile, VAEntrypoint entrypoint) override;
100 
101     //!
102     //! \brief    Return the decode codec key for given profile
103     //!
104     //! \param    [in] profile
105     //!           Specify the VAProfile
106     //!
107     //! \return   Std::string decode codec key
108     //!
109     virtual std::string GetDecodeCodecKey(VAProfile profile)                     override;
110 
111     //!
112     //! \brief    Return the encode codec key for given profile and entrypoint
113     //!
114     //! \param    [in] profile
115     //!           Specify the VAProfile
116     //!
117     //! \param    [in] entrypoint
118     //!           Specify the entrypoint
119     //!
120     //! \param    [in] feiFunction
121     //!           Specify the feiFunction
122     //!
123     //! \return   Std::string encode codec key
124     //!
125     std::string GetEncodeCodecKey(VAProfile profile,
126                                   VAEntrypoint entrypoint,
127                                   uint32_t feiFunction)                          override;
128 
129     virtual CODECHAL_MODE GetDecodeCodecMode(VAProfile profile)                  override;
130 
131 
132     //!
133     //! \brief    Add surface attributes for Encoding
134     //!
135     //! \param    [in] profile
136     //!           VAProfile of the configuration
137     //!
138     //! \param    [in] entrypoint
139     //!           VAEntrypoint of the configuration
140     //!
141     //! \param    [in,out] attribList
142     //!           Pointer to VASurfaceAttrib array. It returns
143     //!           the supported  surface attributes
144     //!
145     //! \param    [in,out] numAttribs
146     //!           The number of elements allocated on input
147     //!           Return the number of elements actually filled in output
148     //!
149     //! \return   VAStatus
150     //!           VA_STATUS_SUCCESS if success
151     //!
152     virtual VAStatus AddEncSurfaceAttributes(VAProfile profile,
153                                              VAEntrypoint entrypoint,
154                                              VASurfaceAttrib  *attribList,
155                                              uint32_t &numAttribs);
156     //!
157     //! \brief    Get surface attributes for a given config ID
158     //!
159     //! \param    [in] configId
160     //!           VA configuration
161     //!
162     //! \param    [in,out] attribList
163     //!           Pointer to VASurfaceAttrib array. It returns
164     //!           the supported  surface attributes
165     //!
166     //! \param    [in,out] numAttribs
167     //!           The number of elements allocated on input
168     //!           Return the number of elements actually filled in output
169     //!
170     //! \return   VAStatus
171     //!           VA_STATUS_SUCCESS if success
172     //!           VA_STATUS_ERROR_MAX_NUM_EXCEEDED if size of attribList is too small
173     //!
174     VAStatus QuerySurfaceAttributes(VAConfigID configId,
175                                     VASurfaceAttrib *attribList,
176                                     uint32_t *numAttribs)                        override;
177 
178     virtual bool IsHevcProfile(VAProfile profile)                                override;
179 
180     virtual GMM_RESOURCE_FORMAT ConvertMediaFmtToGmmFmt(DDI_MEDIA_FORMAT format) override;
181 
182     //! \brief Get surface drm modifier
183     //!
184     //! \param    [in] mediaSurface
185     //!           Pointer to the media surface
186     //! \param    [out] modifier
187     //!           reference of the modifier
188     //!
189     //! \return   VAStatus
190     //!           VA_STATUS_SUCCESS if success
191     //!
192     virtual VAStatus GetSurfaceModifier(DDI_MEDIA_SURFACE* mediaSurface, uint64_t &modifier) override;
193 
194     //! \brief Set tile format according to external surface's modifier
195     //!
196     //! \param    [in] mediaSurface
197     //!           Pointer to the media surface
198     //! \param    [out] tileformat
199     //!           Reference to the tileformat
200     //! \param    [out] bMemCompEnable
201     //!           Reference to the memory compress flag
202     //! \param    [out] bMemCompRC
203     //!           Reference to the memory compress rate control
204     //!
205     //! \return   VAStatus
206     //!           VA_STATUS_SUCCESS if success
207     //!
208     virtual VAStatus SetExternalSurfaceTileFormat(DDI_MEDIA_SURFACE* mediaSurface,
209                                                             uint32_t &tileformat,
210                                                             bool &bMemCompEnable,
211                                                             bool &bMemCompRC) override;
212 
213 protected:
214     static const uint32_t m_maxHevcEncWidth =
215         CODEC_16K_MAX_PIC_WIDTH; //!< maxinum width for HEVC encode
216     static const uint32_t m_maxHevcEncHeight =
217         CODEC_12K_MAX_PIC_HEIGHT; //!< maxinum height for HEVC encode
218     static const uint32_t m_decAvcMaxWidth =
219         CODEC_4K_MAX_PIC_WIDTH; //!< Maximum width for AVC decode
220     static const uint32_t m_decAvcMaxHeight =
221         CODEC_4K_MAX_PIC_HEIGHT; //!< Maximum height for AVC decode
222     static const uint32_t m_decHevcMax16kWidth =
223         CODEC_16K_MAX_PIC_WIDTH; //!< Maximum width for HEVC decode
224     static const uint32_t m_decHevcMax16kHeight =
225         CODEC_16K_MAX_PIC_HEIGHT; //!< Maximum height for HEVC decode
226     static const uint32_t m_decVp9Max16kWidth =
227         CODEC_16K_MAX_PIC_WIDTH; //!< Maximum width for VP9 decode
228     static const uint32_t m_decVp9Max16kHeight =
229         CODEC_16K_MAX_PIC_HEIGHT; //!< Maximum height for VP9 decode
230     static const uint32_t m_decAv1Max16kWidth =
231         CODEC_16K_MAX_PIC_WIDTH; //!< Maximum width for AV1 decode
232     static const uint32_t m_decAv1Max16kHeight =
233         CODEC_16K_MAX_PIC_HEIGHT; //!< Maximum height for AV1 decode
234     static const uint32_t m_maxVp9EncWidth =
235         CODEC_8K_MAX_PIC_WIDTH; //!< maximum width for VP9 encode
236     static const uint32_t m_maxVp9EncHeight =
237         CODEC_8K_MAX_PIC_HEIGHT; //!< maximum height for VP9 encode
238     static const uint32_t m_minVp9EncWidth =
239         CODEC_128_MIN_PIC_WIDTH; //!< minimum width for VP9 encode
240     static const uint32_t m_minVp9EncHeight =
241         CODEC_96_MIN_PIC_HEIGHT; //!< minimum height for VP9 encode
242     static const VAImageFormat m_G12ImageFormats[]; //!< Gen12 supported image formats
243     static const VAConfigAttribValEncRateControlExt m_encVp9RateControlExt; //!< External enc rate control caps for VP9 encode
244     virtual VAStatus GetPlatformSpecificAttrib(VAProfile profile,
245                                                VAEntrypoint entrypoint,
246                                                VAConfigAttribType type,
247                                                unsigned int *value) override;
248 
249     virtual VAStatus LoadProfileEntrypoints() override;
250     virtual VAStatus LoadJpegDecProfileEntrypoints();
251     virtual VAStatus LoadVp9EncProfileEntrypoints() override;
252     virtual VAStatus LoadHevcEncProfileEntrypoints() override;
253 
254     virtual VAStatus CheckEncodeResolution(
255         VAProfile profile,
256         uint32_t width,
257         uint32_t height) override;
258     virtual VAStatus CheckDecodeResolution(
259         int32_t codecMode,
260         VAProfile profile,
261         uint32_t width,
262         uint32_t height) override;
263     virtual VAStatus CreateEncAttributes(
264         VAProfile profile,
265         VAEntrypoint entrypoint,
266         AttribMap **attributeList) override;
267     virtual VAStatus CreateDecAttributes(
268         VAProfile profile,
269         VAEntrypoint entrypoint,
270         AttribMap **attributeList)               override;
271 
272     virtual VAStatus LoadHevcDecProfileEntrypoints() override;
273 
274     //!
275     //! \brief        Initialize HEVC low-power encode profiles, entrypoints and attributes
276     //!
277     //! \return VAStatus
278     //!     if call succeeds
279     //!
280     virtual VAStatus LoadHevcEncLpProfileEntrypoints();
281 
282     //!
283     //! \brief    Check if the give profile is AV1
284     //!
285     //! \param    [in] profile
286     //!           Specify the VAProfile
287     //!
288     //! \return   True if the profile is a AV1 profile
289     //!           False if the profile isn't a AV1 profile
290     //!
291     static bool IsAV1Profile(VAProfile profile);
292 
293     //!
294     //! \brief    Initialize AV1 decode profiles, entrypoints and attributes
295     //!
296     VAStatus LoadAv1DecProfileEntrypoints();
297 
298     //!
299     //! \brief      Query AVC ROI maximum number
300     //!
301     //! \param      [in] rcMode
302     //!     RC mode
303     //! \param      [in] isVdenc
304     //!     vdenc
305     //! \param      [in] maxNum
306     //!     Maximum number
307     //! \param      [in] isRoiInDeltaQP
308     //!     Is ROI in delta QP
309     //!
310     //! \return VAStatus
311     //!     if call succeeds
312     //!
313     VAStatus QueryAVCROIMaxNum(uint32_t rcMode, bool isVdenc, uint32_t *maxNum, bool *isRoiInDeltaQP) override;
314 
315     //!
316     //! \brief    Get display attributes
317     //!           returns the current attributes values in "attribList"
318     //!
319     //! \param    [in, out] attribList
320     //!           the attrib type should be filled.
321     //!           returns the supported display attributes
322     //!
323     //! \param    [in] numAttribs
324     //!           the number of supported attributes
325     //!
326     //! \return   VAStatus
327     //!           VA_STATUS_SUCCESS if success
328     //!           VA_STATUS_ERROR_MAX_NUM_EXCEEDED if size of attribList is too small
329     //!
330     virtual VAStatus GetDisplayAttributes(
331             VADisplayAttribute *attribList,
332             int32_t numAttribs) override;
333 
334     //!
335     //! \brief    Check if the give profile is HEVC SCC
336     //!
337     //! \param    [in] profile
338     //!           Specify the VAProfile
339     //!
340     //! \return   True if the profile is a HEVC SCC profile
341     //!           False if the profile isn't a HEVC profile
342     //!
IsHevcSccProfile(VAProfile profile)343     bool IsHevcSccProfile(VAProfile profile)
344     {
345         return (
346             (profile == VAProfileHEVCSccMain)    ||
347             (profile == VAProfileHEVCSccMain10)  ||
348             (profile == VAProfileHEVCSccMain444) ||
349             (profile == VAProfileHEVCSccMain444_10)
350            );
351     }
352 };
353 #endif
354