-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathcodechal_utilities.h
276 lines (259 loc) · 9.88 KB
/
codechal_utilities.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file codechal_utilities.h
//! \brief Defines the common functions for codec.
//! \details This modules implements utilities which are shared by encoder and decoder
//!
#ifndef __CODECHAL_UTILITIES_H__
#define __CODECHAL_UTILITIES_H__
#include "codechal_hw.h"
#include "codec_def_common.h"
class CodechalHwInterface;
typedef struct _MHW_WALKER_PARAMS MHW_WALKER_PARAMS, *PMHW_WALKER_PARAMS;
typedef struct _MHW_STATE_HEAP_INTERFACE MHW_STATE_HEAP_INTERFACE, *PMHW_STATE_HEAP_INTERFACE;
typedef struct MHW_KERNEL_STATE *PMHW_KERNEL_STATE;
typedef struct _MHW_RCS_SURFACE_PARAMS MHW_RCS_SURFACE_PARAMS, *PMHW_RCS_SURFACE_PARAMS;
typedef struct _CODECHAL_SURFACE_CODEC_PARAMS CODECHAL_SURFACE_CODEC_PARAMS, *PCODECHAL_SURFACE_CODEC_PARAMS;
typedef enum _CODECHAL_WALKER_DEGREE
{
CODECHAL_NO_DEGREE,
CODECHAL_45_DEGREE,
CODECHAL_26_DEGREE,
CODECHAL_46_DEGREE, // VP8 HybridPak2Pattern
CODECHAL_26Z_DEGREE, // HEVC
CODECHAL_45Z_DEGREE, // VP9 MB ENC I 16x16, P
CODECHAL_26X_DEGREE, // HEVC
CODECHAL_26ZX_DEGREE, // HEVC
CODECHAL_45D_DEGREE, // HEVC 45 diamond walk pattern
CODECHAL_45XD_DEGREE, // HEVC 45X diamond walk pattern
CODECHAL_45X_DEGREE_ALT //HEVC 45X ALT walk pattern
} CODECHAL_WALKER_DEGREE;
typedef struct _CODECHAL_WALKER_CODEC_PARAMS
{
CODECHAL_WALKER_DEGREE WalkerDegree;
uint32_t WalkerMode;
uint32_t dwResolutionX;
uint32_t dwResolutionY;
uint32_t wPictureCodingType;
uint32_t bDirectSpatialMVPredFlag;
uint32_t dwNumSlices;
uint32_t ScoreboardMask;
bool bUseScoreboard;
bool bNoDependency;
bool bUseVerticalRasterScan;
bool bMbEncIFrameDistInUse;
bool bMbaff;
bool bColorbitSupported;
uint16_t usSliceHeight;
bool bGroupIdSelectSupported;
uint8_t ucGroupId;
uint16_t usTotalThreadNumPerLcu; //Used by Gen10 HEVC
} CODECHAL_WALKER_CODEC_PARAMS, *PCODECHAL_WALKER_CODEC_PARAMS;
typedef struct _CODECHAL_SURFACE_CODEC_PARAMS
{
PMOS_SURFACE psSurface; // 2D surface parameters
PMOS_RESOURCE presBuffer; // Buffer parameters
uint32_t dwSize; // Buffer size
uint32_t dwOffset; // Buffer offset
uint32_t dwBindingTableOffset; // Binding table offset for given surface
uint32_t dwUVBindingTableOffset; // Binding table offset for the UV plane
uint32_t dwVerticalLineStride;
uint32_t dwVerticalLineStrideOffset;
uint8_t ucVDirection;
uint32_t dwCacheabilityControl;
uint32_t ChromaType;
uint32_t Mode;
bool bIs2DSurface;
bool bUseUVPlane;
bool bUseAdvState;
bool bMediaBlockRW;
bool bUse16UnormSurfaceFormat; // Force surface format to R16_UNORM
bool bUse32UnormSurfaceFormat; // Force surface format to R32_UNORM
bool bUseARGB8Format; // Force surface format to ARGB8 for Ds+Copy kernel
bool bCheckCSC8Format; // Force surface format Y410/ARGB10/AYUV to R8*4 for Ds+Copy kernel
bool bUse32UINTSurfaceFormat;
bool bRenderTarget;
bool bIsWritable;
bool bUseHalfHeight;
bool bForceChromaFormat;
bool bRawSurface;
uint8_t ucSurfaceStateId;
uint32_t dwWidthInUse;
uint32_t dwHeightInUse;
} CODECHAL_SURFACE_CODEC_PARAMS, *PCODECHAL_SURFACE_CODEC_PARAMS;
typedef struct _CODECHAL_KERNEL_HEADER
{
union
{
struct
{
uint32_t : 6;
uint32_t KernelStartPointer : 26; // GTT 31:6
};
struct
{
uint32_t Value;
};
};
} CODECHAL_KERNEL_HEADER, *PCODECHAL_KERNEL_HEADER;
//!
//! \brief Initialize media object walker parameters
//!
//! \param [in] hwInterface
//! pointer to HW interface
//! \param [in,out] walkerParams
//! Pointer to MHW_WALKER_PARAM, which will be filled with media object walker parameters
//! \param [in] walkerCodecParams
//! Pointer to walkerCodecParams. Specify codec parameters
//!
//! \return MOS_STATUS
//! MOS_STATUS_SUCCESS if success, else fail reason
//!
MOS_STATUS CodecHalInitMediaObjectWalkerParams(
CodechalHwInterface *hwInterface,
PMHW_WALKER_PARAMS walkerParams,
PCODECHAL_WALKER_CODEC_PARAMS walkerCodecParams);
//!
//! \brief Gets a kernel information for a specific KUID from the combined kernel
//! \details Gets a kernel information for a specific KUID from the combined kernel
//!
//! \param [in] kernelBase
//! The combined kernel
//! \param [in] kernelUID
//! The unique kernel identifier in the combined kernel
//! \param [in,out] kernelBinary
//! The binary of the kernel specified by dwKUID
//! \param [in,out] size
//! The size of the kernel specified by dwKUID
//!
//! \return MOS_STATUS
//! MOS_STATUS_SUCCESS if success, else fail reason
//!
MOS_STATUS CodecHalGetKernelBinaryAndSize(
uint8_t* kernelBase,
uint32_t kernelUID,
uint8_t** kernelBinary,
uint32_t* size);
//!
//! \brief Get the surface width in bytes
//! \details Get the suface width in bytes
//!
//! \param [in] surface
//! Surface pointer
//! \param [out] widthInBytes
//! Output the surface width
//!
//! \return void
//!
void CodecHal_GetSurfaceWidthInBytes(
PMOS_SURFACE surface,
uint32_t *widthInBytes);
//!
//! \brief Set RCS surface state
//! \details Set RCS surface state
//!
//! \param [in] hwInterface
//! CodechalHwInterface pointer
//! \param [in,out] cmdBuffer
//! MOS_COMMAND_BUFFER pointer
//! \param [in] surfaceCodecParams
//! CODECHAL_SURFACE_CODEC_PARAMS pointer. Return
//! \param [in] kernelState
//! MHW_KERNEL_STATE pointer
//!
//! \return MOS_STATUS
//! MOS_STATUS_SUCCESS if success, else fail reason
//!
MOS_STATUS CodecHalSetRcsSurfaceState(
CodechalHwInterface *hwInterface,
PMOS_COMMAND_BUFFER cmdBuffer,
PCODECHAL_SURFACE_CODEC_PARAMS surfaceCodecParams,
PMHW_KERNEL_STATE kernelState);
//!
//! \brief Get surface information
//!
//! \param [in] osInterface
//! OS interface handle
//! \param [in,out] surface
//! Pointer to MOS_SURFACE. Specify the OsResource and return the surface info.
//!
//! \return MOS_STATUS
//! MOS_STATUS_SUCCESS if success, else fail reason
//!
MOS_STATUS CodecHalGetResourceInfo(
PMOS_INTERFACE osInterface,
PMOS_SURFACE surface);
//!
//! \brief Allocate data list with specific type and length
//!
//! \param [in,out] dataList
//! Pointer to a type * pointer. Specify the address of the memory handles
//! \param [in] length
//! Specify the number of data members
//!
//! \return MOS_STATUS
//! MOS_STATUS_SUCCESS if success, else fail reason
//!
template <class type>
MOS_STATUS CodecHalAllocateDataList(type **dataList, uint32_t length)
{
type *ptr;
ptr = (type *)MOS_AllocAndZeroMemory(sizeof(type) * length);
if (ptr == nullptr)
{
CODECHAL_PUBLIC_ASSERTMESSAGE("No memory to allocate CodecHal data list.");
return MOS_STATUS_NO_SPACE;
}
for (uint32_t i = 0; i < length; i++)
{
dataList[i] = &(ptr[i]);
}
return MOS_STATUS_SUCCESS;
}
//!
//! \brief Free data list
//!
//! \param [in,out] dataList
//! Pointer to a type * pointer. Specify the address of the memory handles
//! \param [in] length
//! Specify the number of data members
//!
//! \return MOS_STATUS
//! MOS_STATUS_SUCCESS if success, else fail reason
//!
template <class type>
MOS_STATUS CodecHalFreeDataList(type **dataList, uint32_t length)
{
type* ptr;
ptr = dataList[0];
if (ptr)
{
MOS_FreeMemory(ptr);
}
for (uint32_t i = 0; i < length; i++)
{
dataList[i] = nullptr;
}
return MOS_STATUS_SUCCESS;
}
#endif