Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/frontends/va/config.c
4561 views
1
/**************************************************************************
2
*
3
* Copyright 2010 Thomas Balling Sørensen & Orasanu Lucian.
4
* Copyright 2014 Advanced Micro Devices, Inc.
5
* All Rights Reserved.
6
*
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the
9
* "Software"), to deal in the Software without restriction, including
10
* without limitation the rights to use, copy, modify, merge, publish,
11
* distribute, sub license, and/or sell copies of the Software, and to
12
* permit persons to whom the Software is furnished to do so, subject to
13
* the following conditions:
14
*
15
* The above copyright notice and this permission notice (including the
16
* next paragraph) shall be included in all copies or substantial portions
17
* of the Software.
18
*
19
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22
* IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
23
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
*
27
**************************************************************************/
28
29
#include "pipe/p_screen.h"
30
31
#include "util/u_video.h"
32
#include "util/u_memory.h"
33
34
#include "vl/vl_winsys.h"
35
36
#include "va_private.h"
37
38
#include "util/u_handle_table.h"
39
40
DEBUG_GET_ONCE_BOOL_OPTION(mpeg4, "VAAPI_MPEG4_ENABLED", false)
41
42
VAStatus
43
vlVaQueryConfigProfiles(VADriverContextP ctx, VAProfile *profile_list, int *num_profiles)
44
{
45
struct pipe_screen *pscreen;
46
enum pipe_video_profile p;
47
VAProfile vap;
48
49
if (!ctx)
50
return VA_STATUS_ERROR_INVALID_CONTEXT;
51
52
*num_profiles = 0;
53
54
pscreen = VL_VA_PSCREEN(ctx);
55
for (p = PIPE_VIDEO_PROFILE_MPEG2_SIMPLE; p <= PIPE_VIDEO_PROFILE_VP9_PROFILE2; ++p) {
56
if (u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 && !debug_get_option_mpeg4())
57
continue;
58
59
if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED) ||
60
pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED)) {
61
vap = PipeToProfile(p);
62
if (vap != VAProfileNone)
63
profile_list[(*num_profiles)++] = vap;
64
}
65
}
66
67
/* Support postprocessing through vl_compositor */
68
profile_list[(*num_profiles)++] = VAProfileNone;
69
70
return VA_STATUS_SUCCESS;
71
}
72
73
VAStatus
74
vlVaQueryConfigEntrypoints(VADriverContextP ctx, VAProfile profile,
75
VAEntrypoint *entrypoint_list, int *num_entrypoints)
76
{
77
struct pipe_screen *pscreen;
78
enum pipe_video_profile p;
79
80
if (!ctx)
81
return VA_STATUS_ERROR_INVALID_CONTEXT;
82
83
*num_entrypoints = 0;
84
85
if (profile == VAProfileNone) {
86
entrypoint_list[(*num_entrypoints)++] = VAEntrypointVideoProc;
87
return VA_STATUS_SUCCESS;
88
}
89
90
p = ProfileToPipe(profile);
91
if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||
92
(u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&
93
!debug_get_option_mpeg4()))
94
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
95
96
pscreen = VL_VA_PSCREEN(ctx);
97
if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
98
PIPE_VIDEO_CAP_SUPPORTED))
99
entrypoint_list[(*num_entrypoints)++] = VAEntrypointVLD;
100
101
if (pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE,
102
PIPE_VIDEO_CAP_SUPPORTED))
103
entrypoint_list[(*num_entrypoints)++] = VAEntrypointEncSlice;
104
105
if (*num_entrypoints == 0)
106
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
107
108
assert(*num_entrypoints <= ctx->max_entrypoints);
109
110
return VA_STATUS_SUCCESS;
111
}
112
113
VAStatus
114
vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
115
VAConfigAttrib *attrib_list, int num_attribs)
116
{
117
struct pipe_screen *pscreen;
118
int i;
119
120
if (!ctx)
121
return VA_STATUS_ERROR_INVALID_CONTEXT;
122
123
pscreen = VL_VA_PSCREEN(ctx);
124
125
for (i = 0; i < num_attribs; ++i) {
126
unsigned int value;
127
if ((entrypoint == VAEntrypointVLD) &&
128
(pscreen->get_video_param(pscreen, ProfileToPipe(profile),
129
PIPE_VIDEO_ENTRYPOINT_BITSTREAM, PIPE_VIDEO_CAP_SUPPORTED))) {
130
switch (attrib_list[i].type) {
131
case VAConfigAttribRTFormat:
132
value = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422;
133
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
134
ProfileToPipe(profile),
135
PIPE_VIDEO_ENTRYPOINT_BITSTREAM) ||
136
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
137
ProfileToPipe(profile),
138
PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
139
value |= VA_RT_FORMAT_YUV420_10BPP;
140
break;
141
default:
142
value = VA_ATTRIB_NOT_SUPPORTED;
143
break;
144
}
145
} else if ((entrypoint == VAEntrypointEncSlice) &&
146
(pscreen->get_video_param(pscreen, ProfileToPipe(profile),
147
PIPE_VIDEO_ENTRYPOINT_ENCODE, PIPE_VIDEO_CAP_SUPPORTED))) {
148
switch (attrib_list[i].type) {
149
case VAConfigAttribRTFormat:
150
value = VA_RT_FORMAT_YUV420;
151
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010,
152
ProfileToPipe(profile),
153
PIPE_VIDEO_ENTRYPOINT_ENCODE) ||
154
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016,
155
ProfileToPipe(profile),
156
PIPE_VIDEO_ENTRYPOINT_ENCODE))
157
value |= VA_RT_FORMAT_YUV420_10BPP;
158
break;
159
case VAConfigAttribRateControl:
160
value = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR;
161
break;
162
case VAConfigAttribEncPackedHeaders:
163
value = VA_ENC_PACKED_HEADER_NONE;
164
if (u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_MPEG4_AVC ||
165
u_reduce_video_profile(ProfileToPipe(profile)) == PIPE_VIDEO_FORMAT_HEVC)
166
value |= VA_ENC_PACKED_HEADER_SEQUENCE;
167
break;
168
case VAConfigAttribEncMaxRefFrames:
169
value = 1;
170
break;
171
default:
172
value = VA_ATTRIB_NOT_SUPPORTED;
173
break;
174
}
175
} else if (entrypoint == VAEntrypointVideoProc) {
176
switch (attrib_list[i].type) {
177
case VAConfigAttribRTFormat:
178
value = (VA_RT_FORMAT_YUV420 |
179
VA_RT_FORMAT_YUV420_10BPP |
180
VA_RT_FORMAT_RGB32);
181
break;
182
default:
183
value = VA_ATTRIB_NOT_SUPPORTED;
184
break;
185
}
186
} else {
187
value = VA_ATTRIB_NOT_SUPPORTED;
188
}
189
attrib_list[i].value = value;
190
}
191
192
return VA_STATUS_SUCCESS;
193
}
194
195
VAStatus
196
vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoint,
197
VAConfigAttrib *attrib_list, int num_attribs, VAConfigID *config_id)
198
{
199
vlVaDriver *drv;
200
vlVaConfig *config;
201
struct pipe_screen *pscreen;
202
enum pipe_video_profile p;
203
unsigned int supported_rt_formats;
204
205
if (!ctx)
206
return VA_STATUS_ERROR_INVALID_CONTEXT;
207
208
drv = VL_VA_DRIVER(ctx);
209
210
if (!drv)
211
return VA_STATUS_ERROR_INVALID_CONTEXT;
212
213
config = CALLOC(1, sizeof(vlVaConfig));
214
if (!config)
215
return VA_STATUS_ERROR_ALLOCATION_FAILED;
216
217
if (profile == VAProfileNone) {
218
if (entrypoint != VAEntrypointVideoProc) {
219
FREE(config);
220
return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
221
}
222
223
config->entrypoint = PIPE_VIDEO_ENTRYPOINT_UNKNOWN;
224
config->profile = PIPE_VIDEO_PROFILE_UNKNOWN;
225
supported_rt_formats = VA_RT_FORMAT_YUV420 |
226
VA_RT_FORMAT_YUV420_10BPP |
227
VA_RT_FORMAT_RGB32;
228
for (int i = 0; i < num_attribs; i++) {
229
if (attrib_list[i].type == VAConfigAttribRTFormat) {
230
if (attrib_list[i].value & supported_rt_formats) {
231
config->rt_format = attrib_list[i].value;
232
} else {
233
FREE(config);
234
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
235
}
236
} else {
237
/*other attrib_types are not supported.*/
238
FREE(config);
239
return VA_STATUS_ERROR_INVALID_VALUE;
240
}
241
}
242
243
/* Default value if not specified in the input attributes. */
244
if (!config->rt_format)
245
config->rt_format = supported_rt_formats;
246
247
mtx_lock(&drv->mutex);
248
*config_id = handle_table_add(drv->htab, config);
249
mtx_unlock(&drv->mutex);
250
return VA_STATUS_SUCCESS;
251
}
252
253
p = ProfileToPipe(profile);
254
if (p == PIPE_VIDEO_PROFILE_UNKNOWN ||
255
(u_reduce_video_profile(p) == PIPE_VIDEO_FORMAT_MPEG4 &&
256
!debug_get_option_mpeg4())) {
257
FREE(config);
258
return VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
259
}
260
261
pscreen = VL_VA_PSCREEN(ctx);
262
263
switch (entrypoint) {
264
case VAEntrypointVLD:
265
supported_rt_formats = VA_RT_FORMAT_YUV420 | VA_RT_FORMAT_YUV422;
266
if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
267
PIPE_VIDEO_CAP_SUPPORTED)) {
268
FREE(config);
269
return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
270
}
271
272
config->entrypoint = PIPE_VIDEO_ENTRYPOINT_BITSTREAM;
273
break;
274
275
case VAEntrypointEncSlice:
276
supported_rt_formats = VA_RT_FORMAT_YUV420;
277
if (!pscreen->get_video_param(pscreen, p, PIPE_VIDEO_ENTRYPOINT_ENCODE,
278
PIPE_VIDEO_CAP_SUPPORTED)) {
279
FREE(config);
280
return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
281
}
282
283
config->entrypoint = PIPE_VIDEO_ENTRYPOINT_ENCODE;
284
break;
285
286
default:
287
FREE(config);
288
return VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
289
}
290
291
config->profile = p;
292
if (pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P010, p,
293
config->entrypoint) ||
294
pscreen->is_video_format_supported(pscreen, PIPE_FORMAT_P016, p,
295
config->entrypoint))
296
supported_rt_formats |= VA_RT_FORMAT_YUV420_10BPP;
297
298
for (int i = 0; i <num_attribs ; i++) {
299
if (attrib_list[i].type != VAConfigAttribRTFormat &&
300
entrypoint == VAEntrypointVLD ) {
301
FREE(config);
302
return VA_STATUS_ERROR_INVALID_VALUE;
303
}
304
if (attrib_list[i].type == VAConfigAttribRateControl) {
305
if (attrib_list[i].value == VA_RC_CBR)
306
config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT;
307
else if (attrib_list[i].value == VA_RC_VBR)
308
config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE;
309
else if (attrib_list[i].value == VA_RC_CQP)
310
config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE;
311
else {
312
FREE(config);
313
return VA_STATUS_ERROR_INVALID_VALUE;
314
}
315
}
316
if (attrib_list[i].type == VAConfigAttribRTFormat) {
317
if (attrib_list[i].value & supported_rt_formats) {
318
config->rt_format = attrib_list[i].value;
319
} else {
320
FREE(config);
321
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
322
}
323
}
324
if (attrib_list[i].type == VAConfigAttribEncPackedHeaders) {
325
if (attrib_list[i].value > 1 ||
326
config->entrypoint != PIPE_VIDEO_ENTRYPOINT_ENCODE) {
327
FREE(config);
328
return VA_STATUS_ERROR_INVALID_VALUE;
329
}
330
}
331
}
332
333
/* Default value if not specified in the input attributes. */
334
if (!config->rt_format)
335
config->rt_format = supported_rt_formats;
336
337
mtx_lock(&drv->mutex);
338
*config_id = handle_table_add(drv->htab, config);
339
mtx_unlock(&drv->mutex);
340
341
return VA_STATUS_SUCCESS;
342
}
343
344
VAStatus
345
vlVaDestroyConfig(VADriverContextP ctx, VAConfigID config_id)
346
{
347
vlVaDriver *drv;
348
vlVaConfig *config;
349
350
if (!ctx)
351
return VA_STATUS_ERROR_INVALID_CONTEXT;
352
353
drv = VL_VA_DRIVER(ctx);
354
355
if (!drv)
356
return VA_STATUS_ERROR_INVALID_CONTEXT;
357
358
mtx_lock(&drv->mutex);
359
config = handle_table_get(drv->htab, config_id);
360
361
if (!config) {
362
mtx_unlock(&drv->mutex);
363
return VA_STATUS_ERROR_INVALID_CONFIG;
364
}
365
366
FREE(config);
367
handle_table_remove(drv->htab, config_id);
368
mtx_unlock(&drv->mutex);
369
370
return VA_STATUS_SUCCESS;
371
}
372
373
VAStatus
374
vlVaQueryConfigAttributes(VADriverContextP ctx, VAConfigID config_id, VAProfile *profile,
375
VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, int *num_attribs)
376
{
377
vlVaDriver *drv;
378
vlVaConfig *config;
379
380
if (!ctx)
381
return VA_STATUS_ERROR_INVALID_CONTEXT;
382
383
drv = VL_VA_DRIVER(ctx);
384
385
if (!drv)
386
return VA_STATUS_ERROR_INVALID_CONTEXT;
387
388
mtx_lock(&drv->mutex);
389
config = handle_table_get(drv->htab, config_id);
390
mtx_unlock(&drv->mutex);
391
392
if (!config)
393
return VA_STATUS_ERROR_INVALID_CONFIG;
394
395
*profile = PipeToProfile(config->profile);
396
397
switch (config->entrypoint) {
398
case PIPE_VIDEO_ENTRYPOINT_BITSTREAM:
399
*entrypoint = VAEntrypointVLD;
400
break;
401
case PIPE_VIDEO_ENTRYPOINT_ENCODE:
402
*entrypoint = VAEntrypointEncSlice;
403
break;
404
case PIPE_VIDEO_ENTRYPOINT_UNKNOWN:
405
*entrypoint = VAEntrypointVideoProc;
406
break;
407
default:
408
return VA_STATUS_ERROR_INVALID_CONFIG;
409
}
410
411
*num_attribs = 1;
412
attrib_list[0].type = VAConfigAttribRTFormat;
413
attrib_list[0].value = config->rt_format;
414
415
return VA_STATUS_SUCCESS;
416
}
417
418