Debian Codegraph @

media_driver/linux/common/vp/ddi/media_libva_vp.c

raw
1 /*
2 * Copyright (c) 2009-2022, 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 media_libva_vp.c
24 //! \brief LibVA Video Processing extension interface implementation
25 //!
26
27 #include <va/va.h>
28 #include <va/va_vpp.h>
29 #include <va/va_backend.h>
30
31 #include <dlfcn.h>
32 #include <limits.h>
33
34 #include "vphal_ddi.h"
35
36 #include "media_libva.h"
37 #include "media_libva_vp.h"
38 #include "media_libva_util.h"
39 #include "hwinfo_linux.h"
40 #include "mos_solo_generic.h"
41
42 #include "media_libva_vp_tools.h"
43
44 #define VP_SETTING_MAX_PHASES 1
45 #define VP_SETTING_MEDIA_STATES 32
46 #define VP_SETTING_SAME_SAMPLE_THRESHOLD 1000
47
48 // ITU-T H.265 Table E.3: Colour Primaries
49 #define COLOUR_PRIMARY_BT2020 9
50 #define COLOUR_PRIMARY_BT709 1
51 #define COLOUR_PRIMARY_BT601 5
52 // ITU-T H.265 Table E.4 Transfer characteristics
53 #define TRANSFER_CHARACTERISTICS_BT709 1
54 #define TRANSFER_CHARACTERISTICS_GMAMA2P2 4
55 #define TRANSFER_CHARACTERISTICS_LINEAR 8
56 #define TRANSFER_CHARACTERISTICS_BT2020 14
57 #define TRANSFER_CHARACTERISTICS_ST2084 16
58
59 VAStatus DdiMedia_MapBuffer (
60 VADriverContextP ctx,
61 VABufferID buf_id,
62 void **pbuf
63 );
64 VAStatus DdiMedia_UnMapBuffer (
65 VADriverContextP ctx,
66 VABufferID buf_id
67 );
68
69 // VP internal APIs to access VP acceleration capability in VPG drivers
70 VAStatus DdiVp_InitVpHal(PDDI_VP_CONTEXT);
71 VAStatus DdiVp_DestroyVpHal(PDDI_VP_CONTEXT);
72 VAStatus DdiVp_DestroyVpHalSurface(PVPHAL_SURFACE pSurf);
73 VAStatus DdiVp_DestroySrcParams(PDDI_VP_CONTEXT pVpCtx);
74 VAStatus DdiVp_DestroyTargetParams(PDDI_VP_CONTEXT pVpCtx);
75 VAStatus DdiVp_DestroyRenderParams(PDDI_VP_CONTEXT pVpCtx);
76 VAStatus DdiVp_InitCtx(VADriverContextP, PDDI_VP_CONTEXT);
77 VAStatus DdiVp_UpdateFilterParamBuffer(VADriverContextP, PDDI_VP_CONTEXT, uint32_t, int32_t, void *, uint32_t, DDI_VP_STATE*);
78 VAStatus DdiVp_ClearFilterParamBuffer(PDDI_VP_CONTEXT , uint32_t, DDI_VP_STATE);
79 VAStatus DdiVp_SetProcFilterDinterlaceParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBufferDeinterlacing*);
80 VAStatus DdiVp_SetProcFilterDenoiseParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBuffer*);
81 VAStatus DdiVp_SetProcFilterHVSDenoiseParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBufferHVSNoiseReduction*);
82 VAStatus DdiVp_SetProcFilterSharpnessParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBuffer*);
83 VAStatus DdiVp_SetProcFilterColorBalanceParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBufferColorBalance*, uint32_t );
84 VAStatus DdiVp_SetProcFilterSkinToneEnhancementParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBuffer*);
85 VAStatus DdiVp_SetProcFilterTotalColorCorrectionParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBufferTotalColorCorrection*, uint32_t);
86 VAStatus DdiVp_SetProcFilterHdrTmParams(PDDI_VP_CONTEXT, uint32_t, VAProcFilterParameterBufferHDRToneMapping*);
87 VAStatus DdiVp_SetProcPipelineBlendingParams(PDDI_VP_CONTEXT pVpCtx, uint32_t uiSurfIndex, VAProcPipelineParameterBuffer* pPipelineParam);
88 VAStatus DdiVp_ConvertSurface (VADriverContextP ctx, DDI_MEDIA_SURFACE *srcSurface, int16_t srcx, int16_t srcy, uint16_t srcw, uint16_t srch, DDI_MEDIA_SURFACE *dstSurface, int16_t destx, int16_t desty, uint16_t destw, uint16_t desth );
89 VAStatus DdiVp_UpdateProcPipelineFutureReferenceFrames(PDDI_VP_CONTEXT pVpCtx, VADriverContextP pVaDrvCtx, PVPHAL_SURFACE pVpHalSrcSurf, VAProcPipelineParameterBuffer* pPipelineParam);
90 VAStatus DdiVp_UpdateProcPipelinePastReferenceFrames(PDDI_VP_CONTEXT pVpCtx, VADriverContextP pVaDrvCtx, PVPHAL_SURFACE pVpHalSrcSurf, VAProcPipelineParameterBuffer* pPipelineParam);
91 VAStatus DdiVp_UpdateVphalTargetSurfColorSpace(VADriverContextP, PDDI_VP_CONTEXT, VAProcPipelineParameterBuffer*, uint32_t targetIndex);
92 VAStatus DdiVp_BeginPictureInt(VADriverContextP pVaDrvCtx, PDDI_VP_CONTEXT pVpCtx, VASurfaceID vaSurfID);
93 #if VA_CHECK_VERSION(1, 12, 0)
94 VAStatus DdiVp_SetProcFilter3DLutParams(VADriverContextP pVaDrvCtx, PDDI_VP_CONTEXT pVpCtx, uint32_t uSurfIndex, VAProcFilterParameterBuffer3DLUT* p3DLutParamBuff);
95 #endif
96 #if (VA_MAJOR_VERSION < 1)
97 VAStatus DdiVp_GetColorSpace(PVPHAL_SURFACE pVpHalSurf, VAProcColorStandardType colorStandard, uint32_t flag);
98 #else
99 VAStatus DdiVp_GetColorSpace(PVPHAL_SURFACE pVpHalSurf, VAProcColorStandardType colorStandard, VAProcColorProperties colorProperties);
100 #endif
101
102
103 /////////////////////////////////////////////////////////////////////////////
104 //! \purpose Get vp context form context ID
105 //! \params
106 //! [in] VADriverContextP
107 //! [in] VAContextID
108 //! \returns PDDI_VP_CONTEXT
109 /////////////////////////////////////////////////////////////////////////////
110 PDDI_VP_CONTEXT DdiVp_GetVpContextFromContextID(VADriverContextP ctx, VAContextID vaCtxID)
111 {
112 uint32_t uiCtxType;
113 return (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID(ctx, vaCtxID, &uiCtxType);
114 }
115
116 ////////////////////////////////////////////////////////////////////////////////
117 //! \purpose judge whether the pitch size match 16aligned usrptr path require or not
118 //! \params
119 //! [in] pitch: surface pitch size.
120 //! [in] format : surface foramt
121 //! \returns true if matched
122 //! for YV12 format, if pitch aligned with 128, go legacy path; if aligned with 16/32/64, go 16usrptr path
123 //! for other formats, legcy path for aligned with 64, 16usrpt path for aligned with 16/32
124 ////////////////////////////////////////////////////////////////////////////////
125 bool VpIs16UsrPtrPitch(uint32_t pitch, DDI_MEDIA_FORMAT format)
126 {
127 uint32_t PitchAligned = 64;
128 bool status = false;
129
130 if (Media_Format_YV12 == format)
131 {
132 PitchAligned = 128;
133 }
134
135 if (!(pitch % 16) && (pitch % PitchAligned))
136 {
137 status = true;
138 }
139 else
140 {
141 status = false;
142 }
143
144 VP_DDI_NORMALMESSAGE("[VP] 16Usrptr check, surface pitch is %d, go to %s path.", pitch, status?"16Usrptr":"legacy");
145
146 return status;
147 }
148
149 /////////////////////////////////////////////////////////////////////////////
150 //! \purpose map from media format to vphal format
151 //! \params
152 //! [in] DDI_MEDIA_FORMAT
153 //! [out] None
154 //! \returns MOS_FORMAT
155 /////////////////////////////////////////////////////////////////////////////
156 MOS_FORMAT VpGetFormatFromMediaFormat(DDI_MEDIA_FORMAT mf)
157 {
158 MOS_FORMAT format = Format_Invalid;
159
160 VP_DDI_FUNCTION_ENTER;
161
162 switch (mf)
163 {
164 case Media_Format_NV12:
165 format = Format_NV12;
166 break;
167 case Media_Format_NV21:
168 format = Format_NV21;
169 break;
170 case Media_Format_X8R8G8B8:
171 format = Format_X8R8G8B8;
172 break;
173 case Media_Format_X8B8G8R8:
174 format = Format_X8B8G8R8;
175 break;
176 case Media_Format_A8R8G8B8:
177 format = Format_A8R8G8B8;
178 break;
179 case Media_Format_A8B8G8R8:
180 case Media_Format_R8G8B8A8:
181 format = Format_A8B8G8R8;
182 break;
183 case Media_Format_R5G6B5:
184 format = Format_R5G6B5;
185 break;
186 case Media_Format_R8G8B8:
187 format = Format_R8G8B8;
188 break;
189 case Media_Format_YUY2 :
190 format = Format_YUY2;
191 break;
192 case Media_Format_UYVY:
193 format = Format_UYVY;
194 break;
195 case Media_Format_YV12 :
196 format = Format_YV12;
197 break;
198 case Media_Format_I420 :
199 format = Format_I420;
200 break;
201 case Media_Format_IYUV :
202 format = Format_IYUV;
203 break;
204 case Media_Format_422H:
205 format = Format_422H;
206 break;
207 case Media_Format_422V:
208 format = Format_422V;
209 break;
210 case Media_Format_400P:
211 format = Format_400P;
212 break;
213 case Media_Format_411P:
214 format = Format_411P;
215 break;
216 case Media_Format_444P:
217 format = Format_444P;
218 break;
219 case Media_Format_IMC3:
220 format = Format_IMC3;
221 break;
222 case Media_Format_P010:
223 format = Format_P010;
224 break;
225 case Media_Format_P012:
226 case Media_Format_P016:
227 format = Format_P016;
228 break;
229 case Media_Format_R10G10B10A2:
230 case Media_Format_R10G10B10X2:
231 format = Format_R10G10B10A2;
232 break;
233 case Media_Format_B10G10R10A2:
234 case Media_Format_B10G10R10X2:
235 format =Format_B10G10R10A2;
236 break;
237 case Media_Format_RGBP:
238 format = Format_RGBP;
239 break;
240 case Media_Format_BGRP:
241 format = Format_BGRP;
242 break;
243 case Media_Format_Y210:
244 format = Format_Y210;
245 break;
246 #if VA_CHECK_VERSION(1, 9, 0)
247 case Media_Format_Y212:
248 #endif
249 case Media_Format_Y216:
250 format = Format_Y216;
251 break;
252 case Media_Format_Y410:
253 format = Format_Y410;
254 break;
255 #if VA_CHECK_VERSION(1, 9, 0)
256 case Media_Format_Y412:
257 #endif
258 case Media_Format_Y416:
259 format = Format_Y416;
260 break;
261 case Media_Format_AYUV:
262 #if VA_CHECK_VERSION(1, 13, 0)
263 case Media_Format_XYUV:
264 #endif
265 format = Format_AYUV;
266 break;
267 case Media_Format_Y8:
268 format = Format_Y8;
269 break;
270 case Media_Format_Y16S:
271 format = Format_Y16S;
272 break;
273 case Media_Format_Y16U:
274 format = Format_Y16U;
275 break;
276 case Media_Format_VYUY:
277 format = Format_VYUY;
278 break;
279 case Media_Format_YVYU:
280 format = Format_YVYU;
281 break;
282 case Media_Format_A16R16G16B16:
283 format = Format_A16R16G16B16;
284 break;
285 case Media_Format_A16B16G16R16:
286 format = Format_A16B16G16R16;
287 break;
288 default:
289 VP_DDI_ASSERTMESSAGE("ERROR media format to vphal format.");
290 format = Format_Invalid;
291 break;
292 }
293
294 return format;
295 }
296
297 /////////////////////////////////////////////////////////////////////////////
298 //! \purpose Get the VP Tile Type from Media Tile Type.
299 //! \params
300 //! [in] mediaTileType : input mediaTileType
301 //! [out] None
302 //! \returns Vp tile Type if call succeeds
303 /////////////////////////////////////////////////////////////////////////////
304
305 MOS_TILE_TYPE VpGetTileTypeFromMediaTileType(uint32_t mediaTileType)
306 {
307 MOS_TILE_TYPE tileType;
308
309 VP_DDI_FUNCTION_ENTER;
310
311 switch(mediaTileType)
312 {
313 case TILING_Y:
314 tileType = MOS_TILE_Y;
315 break;
316 case TILING_X:
317 tileType = MOS_TILE_X;
318 break;
319 case TILING_NONE:
320 tileType = MOS_TILE_LINEAR;
321 break;
322 default:
323 tileType = MOS_TILE_LINEAR;
324 }
325
326 return tileType;
327 }
328
329 /////////////////////////////////////////////////////////////////////////////
330 //! \purpose Get the render parameters from Va Driver Context.
331 //! \params
332 //! [in] pVpCtx : VP context
333 //! [out] None
334 //! \returns Pointer of render parameters
335 /////////////////////////////////////////////////////////////////////////////
336 PVPHAL_RENDER_PARAMS VpGetRenderParams(PDDI_VP_CONTEXT pVpCtx)
337 {
338 VP_DDI_FUNCTION_ENTER;
339
340 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", nullptr);
341 return pVpCtx->pVpHalRenderParams;
342 }
343
344 /////////////////////////////////////////////////////////////////////////////
345 //! \purpose Destroy VPHAL Driver Reference Params
346 //! \params
347 //! [in] pSurf : VPHAL surface
348 //! [out] None
349 //! \returns VA_STATUS_SUCCESS if call succeeds
350 /////////////////////////////////////////////////////////////////////////////
351 VAStatus DdiVp_DestroyVpHalSurface(PVPHAL_SURFACE pSurf)
352 {
353 VP_DDI_FUNCTION_ENTER;
354 DDI_CHK_NULL(pSurf, "Null pSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
355
356 if (pSurf->pFwdRef)
357 {
358 DdiVp_DestroyVpHalSurface(pSurf->pFwdRef);
359 }
360 if (pSurf->pBwdRef)
361 {
362 DdiVp_DestroyVpHalSurface(pSurf->pBwdRef);
363 }
364
365 MOS_FreeMemAndSetNull(pSurf);
366
367 return VA_STATUS_SUCCESS;
368 }
369
370 /////////////////////////////////////////////////////////////////////////////
371 //! \purpose Destroy VPHAL Driver Source Params
372 //! \params
373 //! [in] pVpCtx : VP context
374 //! [out] None
375 //! \returns VA_STATUS_SUCCESS if call succeeds
376 /////////////////////////////////////////////////////////////////////////////
377 VAStatus
378 DdiVp_DestroySrcParams(PDDI_VP_CONTEXT pVpCtx)
379 {
380 uint32_t uSurfIndex;
381
382 VP_DDI_FUNCTION_ENTER;
383
384 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
385
386 // initialize
387 uSurfIndex = 0;
388
389 if (nullptr != pVpCtx)
390 {
391 if (nullptr != pVpCtx->pVpHalRenderParams)
392 {
393 for (uSurfIndex = 0; uSurfIndex < VPHAL_MAX_SOURCES; uSurfIndex++)
394 {
395 if (nullptr != pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex])
396 {
397 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pProcampParams);
398 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pDeinterlaceParams);
399 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pDenoiseParams);
400 if (pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pIEFParams)
401 {
402 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pIEFParams->pExtParam);
403 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pIEFParams);
404 }
405 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pBlendingParams);
406 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pLumaKeyParams);
407 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pColorPipeParams);
408 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pHDRParams);
409 if (pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->p3DLutParams)
410 {
411 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->p3DLutParams->pExt3DLutSurface);
412 }
413 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->p3DLutParams);
414 DdiVp_DestroyVpHalSurface(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]);
415 pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex] = nullptr;
416 }
417 }
418 }
419 }
420
421 return VA_STATUS_SUCCESS;
422 }
423
424 /////////////////////////////////////////////////////////////////////////////
425 //! \purpose Destroy VPHAL Driver Target Params
426 //! \params
427 //! [in] pVpCtx : VP context
428 //! [out] None
429 //! \returns VA_STATUS_SUCCESS if call succeeds
430 /////////////////////////////////////////////////////////////////////////////
431 VAStatus
432 DdiVp_DestroyTargetParams(PDDI_VP_CONTEXT pVpCtx)
433 {
434 PVPHAL_RENDER_PARAMS pParams;
435 PVPHAL_SURFACE pTarget;
436 uint32_t targetIndex;
437
438 VP_DDI_FUNCTION_ENTER;
439
440 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
441
442 if (pVpCtx->pVpHalRenderParams)
443 {
444 pParams = pVpCtx->pVpHalRenderParams;
445 for (targetIndex = 0; targetIndex < VPHAL_MAX_TARGETS; targetIndex++)
446 {
447 pTarget = pParams->pTarget[targetIndex];
448 if (pTarget)
449 {
450 if (pTarget->OsResource.bo)
451 {
452 pTarget->OsResource.bo = nullptr;
453 }
454 if (pTarget->pProcampParams)
455 {
456 MOS_FreeMemAndSetNull(pTarget->pProcampParams);
457 }
458 if (pTarget->pDeinterlaceParams)
459 {
460 MOS_FreeMemAndSetNull(pTarget->pDeinterlaceParams);
461 }
462 if (pTarget->pDenoiseParams)
463 {
464 MOS_FreeMemAndSetNull(pTarget->pDenoiseParams);
465 }
466 if (pTarget->pHDRParams)
467 {
468 MOS_FreeMemAndSetNull(pTarget->pHDRParams);
469 }
470
471 MOS_FreeMemAndSetNull(pParams->pTarget[targetIndex]);
472 }
473 }
474 // reset render target count
475 pParams->uDstCount = 0;
476 }
477
478 return VA_STATUS_SUCCESS;
479 }
480
481 /////////////////////////////////////////////////////////////////////////////
482 //! \purpose Destroy VPHAL Driver Render Params
483 //! \params
484 //! [in] pVpCtx : VP context
485 //! [out] None
486 //! \returns VA_STATUS_SUCCESS if call succeeds
487 /////////////////////////////////////////////////////////////////////////////
488 VAStatus
489 DdiVp_DestroyRenderParams(PDDI_VP_CONTEXT pVpCtx)
490 {
491 VP_DDI_FUNCTION_ENTER;
492
493 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
494
495 DdiVp_DestroySrcParams(pVpCtx);
496 DdiVp_DestroyTargetParams(pVpCtx);
497
498 if (nullptr != pVpCtx)
499 {
500 if (nullptr != pVpCtx->pVpHalRenderParams)
501 {
502 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSplitScreenDemoModeParams);
503 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pCompAlpha);
504 if (nullptr != pVpCtx->pVpHalRenderParams->pColorFillParams)
505 {
506 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pColorFillParams);
507 }
508 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams);
509 }
510 }
511
512 return VA_STATUS_SUCCESS;
513 }
514
515 /////////////////////////////////////////////////////////////////////////////
516 //! \purpose Destroy VPHAL Driver context
517 //! \params
518 //! [in] pVpCtx : VP context
519 //! [out] None
520 //! \returns VA_STATUS_SUCCESS if call succeeds
521 /////////////////////////////////////////////////////////////////////////////
522 VAStatus
523 DdiVp_DestroyVpHal(PDDI_VP_CONTEXT pVpCtx)
524 {
525 VP_DDI_FUNCTION_ENTER;
526
527 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
528
529 DdiVp_DestroyRenderParams(pVpCtx);
530
531 // Destroy VPHAL context
532 if (nullptr != pVpCtx)
533 {
534 pVpCtx->MosDrvCtx.m_skuTable.reset();
535 pVpCtx->MosDrvCtx.m_waTable.reset();
536 if (nullptr != pVpCtx->pVpHal)
537 {
538 MOS_Delete(pVpCtx->pVpHal);
539 pVpCtx->pVpHal = nullptr;
540 }
541
542 #if (_DEBUG || _RELEASE_INTERNAL)
543 VpDestoryDumpConfig(pVpCtx);
544 #endif //(_DEBUG || _RELEASE_INTERNAL)
545 }
546
547 return VA_STATUS_SUCCESS;
548 }
549
550 //////////////////////////////////////////////////////////////////////////////////////////////
551 //! \purpose Map VA Rotation flags to appropriate VPHAL Rotation params
552 //! \params
553 //! [in] pVpHalSrcSurf
554 //! [in] rotation_state
555 //! [out] None
556 //! \returns VA_STATUS_SUCCESS if call succeeds
557 /////////////////////////////////////////////////////////////////////////////////////////////
558 VAStatus
559 VpUpdateProcRotateState(PVPHAL_SURFACE pVpHalSrcSurf, uint32_t rotation_state)
560 {
561 VP_DDI_FUNCTION_ENTER;
562 DDI_CHK_NULL(pVpHalSrcSurf, "Null pVpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
563
564 switch(rotation_state)
565 {
566 case VA_ROTATION_NONE:
567 pVpHalSrcSurf->Rotation = VPHAL_ROTATION_IDENTITY;
568 break;
569 case VA_ROTATION_90:
570 pVpHalSrcSurf->Rotation = VPHAL_ROTATION_90;
571 break;
572 case VA_ROTATION_180:
573 pVpHalSrcSurf->Rotation = VPHAL_ROTATION_180;
574 break;
575 case VA_ROTATION_270:
576 pVpHalSrcSurf->Rotation = VPHAL_ROTATION_270;
577 break;
578 default:
579 VP_DDI_ASSERTMESSAGE("VpUpdateProcRotateState rotation_state = %d is out of range.", rotation_state);
580 return VA_STATUS_ERROR_INVALID_PARAMETER;
581 }
582
583 return VA_STATUS_SUCCESS;
584 }
585
586 //////////////////////////////////////////////////////////////////////////////////////////////
587 //! \purpose Map VA Mirroring flags to appropriate VPHAL Mirroring params
588 //! \params
589 //! [in] pVpHalSrcSurf
590 //! [in] mirror_state
591 //! [out] None
592 //! \returns VA_STATUS_SUCCESS if call succeeds
593 /////////////////////////////////////////////////////////////////////////////////////////////
594 VAStatus
595 VpUpdateProcMirrorState(PVPHAL_SURFACE pVpHalSrcSurf, uint32_t mirror_state)
596 {
597 VP_DDI_FUNCTION_ENTER;
598 DDI_CHK_NULL(pVpHalSrcSurf, "Null pVpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
599
600 if(mirror_state > VA_MIRROR_VERTICAL)
601 {
602 VP_DDI_ASSERTMESSAGE("VpUpdateProcMirrorState mirror_state = %d is out of range.", mirror_state);
603 VP_DDI_ASSERTMESSAGE("VpUpdateProcMirrorState reset mirror_state to VA_MIRROR_NONE.");
604 mirror_state = VA_MIRROR_NONE;
605 }
606
607 // Rotation must be a valid angle
608 switch(pVpHalSrcSurf->Rotation)
609 {
610 case VPHAL_ROTATION_IDENTITY:
611 if(mirror_state == VA_MIRROR_HORIZONTAL)
612 {
613 pVpHalSrcSurf->Rotation = VPHAL_MIRROR_HORIZONTAL;
614 }
615 else if(mirror_state == VA_MIRROR_VERTICAL)
616 {
617 pVpHalSrcSurf->Rotation = VPHAL_MIRROR_VERTICAL;
618 }
619 break;
620 case VPHAL_ROTATION_90:
621 if(mirror_state == VA_MIRROR_HORIZONTAL)
622 {
623 pVpHalSrcSurf->Rotation = VPHAL_ROTATE_90_MIRROR_HORIZONTAL;
624 }
625 else if(mirror_state == VA_MIRROR_VERTICAL)
626 {
627 pVpHalSrcSurf->Rotation = VPHAL_ROTATE_90_MIRROR_VERTICAL;
628 }
629 break;
630 case VPHAL_ROTATION_180:
631 if(mirror_state == VA_MIRROR_HORIZONTAL)
632 {
633 pVpHalSrcSurf->Rotation = VPHAL_MIRROR_VERTICAL;
634 }
635 else if(mirror_state == VA_MIRROR_VERTICAL)
636 {
637 pVpHalSrcSurf->Rotation = VPHAL_MIRROR_HORIZONTAL;
638 }
639 break;
640 case VPHAL_ROTATION_270:
641 if(mirror_state == VA_MIRROR_HORIZONTAL)
642 {
643 pVpHalSrcSurf->Rotation = VPHAL_ROTATE_90_MIRROR_VERTICAL;
644 }
645 else if(mirror_state == VA_MIRROR_VERTICAL)
646 {
647 pVpHalSrcSurf->Rotation = VPHAL_ROTATE_90_MIRROR_HORIZONTAL;
648 }
649 break;
650 default:
651 VP_DDI_ASSERTMESSAGE("VpUpdateProcMirrorState Unexpected Invalid Rotation = %d.", pVpHalSrcSurf->Rotation);
652 return VA_STATUS_ERROR_INVALID_PARAMETER;
653
654 }
655
656 return VA_STATUS_SUCCESS;
657 }
658
659 //////////////////////////////////////////////////////////////////////////////////////////////
660 //! \purpose Check whether there is only Procamp with adjusting Brightness
661 //! \params
662 //! [in] pVpHalSrcSurf
663 //! [out] None
664 //! \returns true if call succeeds
665 /////////////////////////////////////////////////////////////////////////////////////////////
666 bool IsProcmpEnable(PVPHAL_SURFACE pVpHalSrcSurf)
667 {
668 DDI_CHK_NULL(pVpHalSrcSurf, "Null pVpHalSrcSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
669
670 if ((pVpHalSrcSurf->pProcampParams && pVpHalSrcSurf->pProcampParams->bEnabled) &&
671 (pVpHalSrcSurf->pProcampParams->fContrast == 1 && pVpHalSrcSurf->pProcampParams->fHue == 0 && pVpHalSrcSurf->pProcampParams->fSaturation == 1) &&
672 !pVpHalSrcSurf->pBlendingParams && !pVpHalSrcSurf->pLumaKeyParams && (!pVpHalSrcSurf->pIEFParams || !pVpHalSrcSurf->pIEFParams->bEnabled) &&
673 !pVpHalSrcSurf->pDeinterlaceParams && (!pVpHalSrcSurf->pDenoiseParams || (!pVpHalSrcSurf->pDenoiseParams->bEnableChroma && !pVpHalSrcSurf->pDenoiseParams->bEnableLuma)) &&
674 (!pVpHalSrcSurf->pColorPipeParams || (!pVpHalSrcSurf->pColorPipeParams->bEnableACE && !pVpHalSrcSurf->pColorPipeParams->bEnableSTE && !pVpHalSrcSurf->pColorPipeParams->bEnableTCC)) &&
675 !pVpHalSrcSurf->pHDRParams)
676 {
677 return true;
678 }
679
680 return false;
681 }
682
683 //////////////////////////////////////////////////////////////////////////////////////////////
684 //! \purpose Map Chroma Sitting flags to appropriate VPHAL chroma sitting params
685 //! \params
686 //! [in] pVpHalSurf
687 //! [in] chromasiting_state
688 //! [out] None
689 //! \returns VA_STATUS_SUCCESS if call succeeds
690 /////////////////////////////////////////////////////////////////////////////////////////////
691 VAStatus
692 VpUpdateProcChromaSittingState(PVPHAL_SURFACE pVpHalSurf, uint8_t chromasiting_state)
693 {
694 uint32_t uChromaSitingFlags = 0;
695
696 VP_DDI_FUNCTION_ENTER;
697 DDI_CHK_NULL(pVpHalSurf, "Null pVpHalSurf.", VA_STATUS_ERROR_INVALID_PARAMETER);
698
699 // Chroma siting
700 // The lower 4 bits are still used as chroma-siting flag for output/input_surface_flag
701 // Set the vertical chroma siting info at bit 1:0
702 uChromaSitingFlags = chromasiting_state & 0x3;
703
704 switch (uChromaSitingFlags)
705 {
706 case VA_CHROMA_SITING_VERTICAL_TOP:
707 pVpHalSurf->ChromaSiting = CHROMA_SITING_VERT_TOP;
708 break;
709 case VA_CHROMA_SITING_VERTICAL_CENTER:
710 pVpHalSurf->ChromaSiting = CHROMA_SITING_VERT_CENTER;
711 break;
712 case VA_CHROMA_SITING_VERTICAL_BOTTOM:
713 pVpHalSurf->ChromaSiting = CHROMA_SITING_VERT_BOTTOM;
714 break;
715 default:
716 pVpHalSurf->ChromaSiting = CHROMA_SITING_NONE;
717 break;
718 }
719
720 if (pVpHalSurf->ChromaSiting != CHROMA_SITING_NONE)
721 {
722 // Set the horizontal chroma siting info at bit 3:2
723 uChromaSitingFlags = chromasiting_state & 0xc;
724
725 switch (uChromaSitingFlags)
726 {
727 case VA_CHROMA_SITING_HORIZONTAL_LEFT:
728 pVpHalSurf->ChromaSiting = pVpHalSurf->ChromaSiting | CHROMA_SITING_HORZ_LEFT;
729 break;
730 case VA_CHROMA_SITING_HORIZONTAL_CENTER:
731 pVpHalSurf->ChromaSiting = pVpHalSurf->ChromaSiting | CHROMA_SITING_HORZ_CENTER;
732 break;
733 default:
734 pVpHalSurf->ChromaSiting = CHROMA_SITING_NONE;
735 break;
736 }
737 }
738
739 return VA_STATUS_SUCCESS;
740 }
741
742 //////////////////////////////////////////////////////////////////////////////////////////////
743 //! \purpose Set the appropriate HDR params according to colour standard, HDR metadata.
744 //! \params
745 //! [in] pVpHalSurf : VPHAL Surface
746 //! [in] pHdrMetadata: HDR metadata
747 //! [out] None
748 //! \returns VA_STATUS_SUCCESS if call succeeds
749 /////////////////////////////////////////////////////////////////////////////////////////////
750 VAStatus VpUpdateProcHdrState(
751 const PVPHAL_SURFACE pVpHalSurf,
752 const VAHdrMetaData* pHdrMetadata)
753 {
754 DDI_CHK_NULL(pVpHalSurf, "Null pVpHalSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
755
756 // pass HDR metadata
757 if ((pHdrMetadata != nullptr) && (pHdrMetadata->metadata_size != 0))
758 {
759 if (pVpHalSurf->pHDRParams == nullptr)
760 {
761 pVpHalSurf->pHDRParams = (PVPHAL_HDR_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_HDR_PARAMS));
762 DDI_CHK_NULL(pVpHalSurf->pHDRParams, "VPHAL_HDR_PARAMS MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
763 }
764
765 // HDR10 Meta Data
766 if (pHdrMetadata->metadata_type == VAProcHighDynamicRangeMetadataHDR10)
767 {
768 VP_DDI_NORMALMESSAGE("VpSetHdrParams HDR10 metadata.");
769 VAHdrMetaDataHDR10* pHDR10MetaData = (VAHdrMetaDataHDR10*)pHdrMetadata->metadata;
770 if (pHDR10MetaData)
771 {
772 pVpHalSurf->pHDRParams->white_point_x = pHDR10MetaData->white_point_x;
773 pVpHalSurf->pHDRParams->white_point_y = pHDR10MetaData->white_point_y;
774 VP_DDI_NORMALMESSAGE("pHDR10MetaData white_point_x %d, white_point_y %d.", pHDR10MetaData->white_point_x, pHDR10MetaData->white_point_y);
775
776 // From VAAPI defintion which is following video spec, max/min_display_mastering_luminance are in units of 0.0001 candelas per square metre.
777 uint32_t max_display_mastering_luminance = (pHDR10MetaData->max_display_mastering_luminance > 655350000 ) ? 655350000 : pHDR10MetaData->max_display_mastering_luminance;
778 uint32_t min_display_mastering_luminance = (pHDR10MetaData->min_display_mastering_luminance > 655350000 ) ? 655350000 : pHDR10MetaData->min_display_mastering_luminance;
779 pVpHalSurf->pHDRParams->max_display_mastering_luminance = (uint16_t)(max_display_mastering_luminance / 10000);
780 pVpHalSurf->pHDRParams->min_display_mastering_luminance = (uint16_t)(min_display_mastering_luminance / 10000);
781 VP_DDI_NORMALMESSAGE("pHDR10MetaData max_display_mastering_luminance %d, min_display_mastering_luminance %d.", pHDR10MetaData->max_display_mastering_luminance, pHDR10MetaData->min_display_mastering_luminance);
782
783 pVpHalSurf->pHDRParams->MaxCLL = pHDR10MetaData->max_content_light_level;
784 pVpHalSurf->pHDRParams->MaxFALL = pHDR10MetaData->max_pic_average_light_level;
785 VP_DDI_NORMALMESSAGE("pHDR10MetaData MaxCLL %d, MaxFALL %d.", pHDR10MetaData->max_content_light_level, pHDR10MetaData->max_pic_average_light_level);
786
787 pVpHalSurf->pHDRParams->bAutoMode = false;
788
789 pVpHalSurf->pHDRParams->MaxCLL = (pVpHalSurf->pHDRParams->MaxCLL == 0) ? HDR_DEFAULT_MAXCLL : pVpHalSurf->pHDRParams->MaxCLL;
790 pVpHalSurf->pHDRParams->MaxFALL = (pVpHalSurf->pHDRParams->MaxFALL == 0) ? HDR_DEFAULT_MAXFALL : pVpHalSurf->pHDRParams->MaxFALL;
791
792 MOS_SecureMemcpy(pVpHalSurf->pHDRParams->display_primaries_x, 3 * sizeof(uint16_t), pHDR10MetaData->display_primaries_x, 3 * sizeof(uint16_t));
793 MOS_SecureMemcpy(pVpHalSurf->pHDRParams->display_primaries_y, 3 * sizeof(uint16_t), pHDR10MetaData->display_primaries_y, 3 * sizeof(uint16_t));
794
795 switch (pVpHalSurf->GammaType)
796 {
797 case VPHAL_GAMMA_SMPTE_ST2084:
798 pVpHalSurf->pHDRParams->EOTF = VPHAL_HDR_EOTF_SMPTE_ST2084;
799 break;
800 case VPHAL_GAMMA_BT1886:
801 pVpHalSurf->pHDRParams->EOTF = VPHAL_HDR_EOTF_BT1886;
802 break;
803 default:
804 pVpHalSurf->pHDRParams->EOTF = VPHAL_HDR_EOTF_TRADITIONAL_GAMMA_SDR;
805 break;
806 }
807 VP_DDI_NORMALMESSAGE("max_display_mastering_luminance %d.", pVpHalSurf->pHDRParams->max_display_mastering_luminance);
808 VP_DDI_NORMALMESSAGE("min_display_mastering_luminance %d.", pVpHalSurf->pHDRParams->min_display_mastering_luminance);
809 VP_DDI_NORMALMESSAGE("GammaType %d.", pVpHalSurf->GammaType);
810 }
811 }
812 }
813
814 return VA_STATUS_SUCCESS;
815 }
816
817 //////////////////////////////////////////////////////////////////////////////////////////////
818 //! \purpose Extract VAProcPipelineParameterBuffer params for target surface and set the appropriate VPHAL params
819 //! \params
820 //! [in] pVaDrvCtx : VA Driver context
821 //! [in] pVpCtx : VP context
822 //! [in] pPipelineParam : Pipeline parameters from application (VAProcPipelineParameterBuffer)
823 //! [out] None
824 //! \returns VA_STATUS_SUCCESS if call succeeds
825 /////////////////////////////////////////////////////////////////////////////////////////////
826
827 VAStatus
828 VpSetRenderTargetParams(
829 VADriverContextP pVaDrvCtx,
830 PDDI_VP_CONTEXT pVpCtx,
831 VAProcPipelineParameterBuffer* pPipelineParam)
832 {
833 PVPHAL_RENDER_PARAMS VpHalRenderParams;
834 PDDI_MEDIA_CONTEXT pMediaCtx;
835 PDDI_MEDIA_SURFACE pMediaSrcSurf;
836 PVPHAL_SURFACE pVpHalTgtSurf;
837
838 VP_DDI_FUNCTION_ENTER;
839 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
840 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
841 DDI_CHK_NULL(pPipelineParam, "Null pPipelineParam.", VA_STATUS_ERROR_INVALID_BUFFER);
842
843 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
844 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
845 pMediaSrcSurf = DdiMedia_GetSurfaceFromVASurfaceID(pMediaCtx, pPipelineParam->surface);
846 DDI_CHK_NULL(pMediaSrcSurf, "Null pMediaSrcSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
847 VpHalRenderParams = pVpCtx->pVpHalRenderParams;
848 DDI_CHK_NULL(VpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
849
850 DDI_ASSERT(VpHalRenderParams->uDstCount >= 1);
851 DDI_CHK_NULL(VpHalRenderParams->pTarget, "Null VpHalRenderParams->pTarget.", VA_STATUS_ERROR_INVALID_BUFFER);
852 pVpHalTgtSurf = VpHalRenderParams->pTarget[VpHalRenderParams->uDstCount-1];
853 DDI_CHK_NULL(pVpHalTgtSurf, "Null pVpHalTgtSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
854
855 if (pPipelineParam->surface_region != nullptr)
856 {
857 pVpHalTgtSurf->rcSrc.left = pPipelineParam->surface_region->x;
858 pVpHalTgtSurf->rcSrc.top = pPipelineParam->surface_region->y;
859 pVpHalTgtSurf->rcSrc.right = pPipelineParam->surface_region->x + pPipelineParam->surface_region->width;
860 pVpHalTgtSurf->rcSrc.bottom = pPipelineParam->surface_region->y + pPipelineParam->surface_region->height;
861
862 if (pVpHalTgtSurf->rcSrc.top < 0)
863 {
864 pVpHalTgtSurf->rcSrc.top = 0;
865 }
866
867 if (pVpHalTgtSurf->rcSrc.left < 0)
868 {
869 pVpHalTgtSurf->rcSrc.left = 0;
870 }
871
872 if (pVpHalTgtSurf->rcSrc.right > pMediaSrcSurf->iWidth)
873 {
874 pVpHalTgtSurf->rcSrc.right = pMediaSrcSurf->iWidth;
875 }
876
877 if (pVpHalTgtSurf->rcSrc.bottom > pMediaSrcSurf->iHeight)
878 {
879 pVpHalTgtSurf->rcSrc.bottom = pMediaSrcSurf->iHeight;
880 }
881 }
882
883 // Set dest rect
884 if (pPipelineParam->output_region != nullptr)
885 {
886 pVpHalTgtSurf->rcDst.left = pPipelineParam->output_region->x;
887 pVpHalTgtSurf->rcDst.top = pPipelineParam->output_region->y;
888 pVpHalTgtSurf->rcDst.right = pPipelineParam->output_region->x + pPipelineParam->output_region->width;
889 pVpHalTgtSurf->rcDst.bottom = pPipelineParam->output_region->y + pPipelineParam->output_region->height;
890 if (pVpHalTgtSurf->rcDst.top < 0)
891 {
892 pVpHalTgtSurf->rcDst.top = 0;
893 }
894
895 if (pVpHalTgtSurf->rcDst.left < 0)
896 {
897 pVpHalTgtSurf->rcDst.left = 0;
898 }
899
900 if (pVpHalTgtSurf->rcDst.right > pMediaSrcSurf->iWidth)
901 {
902 pVpHalTgtSurf->rcDst.right = pMediaSrcSurf->iWidth;
903 }
904
905 if (pVpHalTgtSurf->rcDst.bottom > pMediaSrcSurf->iHeight)
906 {
907 pVpHalTgtSurf->rcDst.bottom = pMediaSrcSurf->iHeight;
908 }
909 }
910
911 if (IsProcmpEnable(pVpHalTgtSurf))
912 {
913 // correct the ChromaSitting location if Procamp is enabled.
914 #if (VA_MAJOR_VERSION < 1)
915 pPipelineParam->output_surface_flag = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
916 #else
917 pPipelineParam->output_color_properties.chroma_sample_location = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
918 #endif
919 }
920
921 #if (VA_MAJOR_VERSION < 1)
922 VpUpdateProcChromaSittingState(pVpHalTgtSurf, (uint8_t)(pPipelineParam->output_surface_flag & 0xff));
923 #else
924 VpUpdateProcChromaSittingState(pVpHalTgtSurf, pPipelineParam->output_color_properties.chroma_sample_location);
925 #endif
926 return VA_STATUS_SUCCESS;
927
928 }
929
930 //////////////////////////////////////////////////////////////////////////////////////////////
931 //! \purpose Set Interpolation Method according to the flag
932 //! \params
933 //! [in] PVPHAL_SURFACE : VA Surface
934 //! [in] uInterpolationflags : Interpolation Flag
935 //! [out] None
936 //! \returns VA_STATUS_SUCCESS if call succeeds
937 /////////////////////////////////////////////////////////////////////////////////////////////
938 VAStatus
939 VpSetInterpolationParams(
940 PVPHAL_SURFACE pSurface,
941 uint32_t uInterpolationflags)
942 {
943 DDI_CHK_NULL(pSurface, "Null pSurface.", VA_STATUS_ERROR_INVALID_SURFACE);
944 switch (uInterpolationflags)
945 {
946 #if VA_CHECK_VERSION(1, 9, 0)
947 case VA_FILTER_INTERPOLATION_NEAREST_NEIGHBOR:
948 pSurface->ScalingMode = VPHAL_SCALING_NEAREST;
949 break;
950 case VA_FILTER_INTERPOLATION_BILINEAR:
951 pSurface->ScalingMode = VPHAL_SCALING_BILINEAR;
952 break;
953 case VA_FILTER_INTERPOLATION_ADVANCED:
954 case VA_FILTER_INTERPOLATION_DEFAULT:
955 #endif
956 default:
957 pSurface->ScalingMode = VPHAL_SCALING_AVS;
958 break;
959 }
960
961 return VA_STATUS_SUCCESS;
962 }
963
964 //////////////////////////////////////////////////////////////////////////////////////////////
965 //! \purpose Extract VAProcPipelineParameterBuffer params and set the appropriate VPHAL params
966 //! \params
967 //! [in] pVaDrvCtx : VA Driver context
968 //! [in] pVpCtx : VP context
969 //! [in] pPipelineParam : Pipeline parameters from application (VAProcPipelineParameterBuffer)
970 //! [out] None
971 //! \returns VA_STATUS_SUCCESS if call succeeds
972 /////////////////////////////////////////////////////////////////////////////////////////////
973 VAStatus
974 DdiVp_SetProcPipelineParams(
975 VADriverContextP pVaDrvCtx,
976 PDDI_VP_CONTEXT pVpCtx,
977 VAProcPipelineParameterBuffer* pPipelineParam)
978 {
979 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
980 PDDI_MEDIA_CONTEXT pMediaCtx;
981 PDDI_MEDIA_SURFACE pMediaSrcSurf;
982 PDDI_MEDIA_BUFFER pFilterBuf;
983 void *pData;
984 uint32_t i;
985 PVPHAL_SURFACE pVpHalSrcSurf;
986 PVPHAL_SURFACE pVpHalTgtSurf;
987 uint32_t uSurfIndex;
988 uint32_t uScalingflags;
989 uint32_t uInterpolationflags;
990 uint32_t uChromaSitingFlags;
991 VAStatus vaStatus;
992 MOS_STATUS eStatus;
993 DDI_VP_STATE vpStateFlags = {};
994 PMOS_INTERFACE pOsInterface;
995
996 VP_DDI_FUNCTION_ENTER;
997 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
998
999 // initialize
1000 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
1001 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1002 pMediaSrcSurf = DdiMedia_GetSurfaceFromVASurfaceID(pMediaCtx, pPipelineParam->surface);
1003 pVpHalRenderParams = pVpCtx->pVpHalRenderParams;
1004 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1005 pFilterBuf = nullptr;
1006 pData = nullptr;
1007 uSurfIndex = 0;
1008 pOsInterface = pVpCtx->pVpHal->GetOsInterface();
1009 uInterpolationflags = 0;
1010
1011 DDI_CHK_NULL(pMediaSrcSurf, "Null pMediaSrcSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
1012 DDI_CHK_NULL(pOsInterface, "Null pOsInterface.", VA_STATUS_ERROR_INVALID_BUFFER);
1013
1014 // increment surface count
1015 pVpHalRenderParams->uSrcCount++;
1016
1017 // check if the surface count exceeded maximum VPHAL surfaces
1018 DDI_CHK_CONDITION((pVpHalRenderParams->uSrcCount > VPHAL_MAX_SOURCES),
1019 "Surface count exceeds maximum!", VA_STATUS_ERROR_MAX_NUM_EXCEEDED);
1020
1021 // update surface uSurfIndex
1022 uSurfIndex = pVpHalRenderParams->uSrcCount - 1;
1023
1024 pVpHalSrcSurf = pVpHalRenderParams->pSrc[uSurfIndex];
1025
1026 pVpHalSrcSurf->Format = VpGetFormatFromMediaFormat(pMediaSrcSurf->format);
1027 pVpHalSrcSurf->TileType = VpGetTileTypeFromMediaTileType(pMediaSrcSurf->TileType);
1028
1029 DDI_CHK_CONDITION((Format_Invalid == pVpHalSrcSurf->Format),
1030 "Invalid surface media format!", VA_STATUS_ERROR_INVALID_PARAMETER);
1031
1032 #if (_DEBUG || _RELEASE_INTERNAL)
1033 if (pVpCtx->pCurVpDumpDDIParam != nullptr &&
1034 pVpCtx->pCurVpDumpDDIParam->pPipelineParamBuffers[uSurfIndex] != nullptr)
1035 {
1036 MOS_SecureMemcpy(pVpCtx->pCurVpDumpDDIParam->pPipelineParamBuffers[uSurfIndex], sizeof(VAProcPipelineParameterBuffer), pPipelineParam, sizeof(VAProcPipelineParameterBuffer));
1037 pVpCtx->pCurVpDumpDDIParam->SrcFormat[uSurfIndex] = pVpHalSrcSurf->Format;
1038 }
1039 #endif //(_DEBUG || _RELEASE_INTERNAL)
1040
1041 // Currently we only support 1 primary surface in VP
1042 if (pVpCtx->iPriSurfs < VP_MAX_PRIMARY_SURFS)
1043 {
1044 pVpHalSrcSurf->SurfType = SURF_IN_PRIMARY;
1045 pVpCtx->iPriSurfs++;
1046 }
1047 else
1048 {
1049 pVpHalSrcSurf->SurfType = SURF_IN_SUBSTREAM;
1050 }
1051
1052 // Set workload path using pipeline_flags VA_PROC_PIPELINE_FAST flag
1053 if (pPipelineParam->pipeline_flags & VA_PROC_PIPELINE_FAST)
1054 {
1055 pVpHalRenderParams->bForceToRender = true;
1056 }
1057
1058 // Set src rect
1059 if (pPipelineParam->surface_region != nullptr)
1060 {
1061 pVpHalSrcSurf->rcSrc.top = pPipelineParam->surface_region->y;
1062 pVpHalSrcSurf->rcSrc.left = pPipelineParam->surface_region->x;
1063 pVpHalSrcSurf->rcSrc.right = pPipelineParam->surface_region->x + pPipelineParam->surface_region->width;
1064 pVpHalSrcSurf->rcSrc.bottom = pPipelineParam->surface_region->y + pPipelineParam->surface_region->height;
1065
1066 if (pVpHalSrcSurf->rcSrc.top < 0)
1067 {
1068 pVpHalSrcSurf->rcSrc.top = 0;
1069 }
1070
1071 if (pVpHalSrcSurf->rcSrc.left < 0)
1072 {
1073 pVpHalSrcSurf->rcSrc.left = 0;
1074 }
1075
1076 if (pVpHalSrcSurf->rcSrc.right > pMediaSrcSurf->iWidth)
1077 {
1078 pVpHalSrcSurf->rcSrc.right = pMediaSrcSurf->iWidth;
1079 }
1080
1081 if (pVpHalSrcSurf->rcSrc.bottom > pMediaSrcSurf->iRealHeight)
1082 {
1083 pVpHalSrcSurf->rcSrc.bottom = pMediaSrcSurf->iRealHeight;
1084 }
1085 }
1086 else
1087 {
1088 // nullptr surface_region implies the whole surface
1089 pVpHalSrcSurf->rcSrc.top = 0;
1090 pVpHalSrcSurf->rcSrc.left = 0;
1091 pVpHalSrcSurf->rcSrc.right = pMediaSrcSurf->iWidth;
1092 pVpHalSrcSurf->rcSrc.bottom = pMediaSrcSurf->iRealHeight;
1093 }
1094
1095 pVpHalTgtSurf = pVpHalRenderParams->pTarget[0];
1096 DDI_CHK_NULL(pVpHalTgtSurf, "Null pVpHalTgtSurf.", VA_STATUS_ERROR_UNKNOWN);
1097 // Set dest rect
1098 if (pPipelineParam->output_region != nullptr)
1099 {
1100 pVpHalSrcSurf->rcDst.top = pPipelineParam->output_region->y;
1101 pVpHalSrcSurf->rcDst.left = pPipelineParam->output_region->x;
1102 pVpHalSrcSurf->rcDst.right = pPipelineParam->output_region->x + pPipelineParam->output_region->width;
1103 pVpHalSrcSurf->rcDst.bottom = pPipelineParam->output_region->y + pPipelineParam->output_region->height;
1104 }
1105 else
1106 {
1107 pVpHalSrcSurf->rcDst.top = 0;
1108 pVpHalSrcSurf->rcDst.left = 0;
1109 pVpHalSrcSurf->rcDst.right = pVpHalTgtSurf->rcDst.right;
1110 pVpHalSrcSurf->rcDst.bottom = pVpHalTgtSurf->rcDst.bottom;
1111 }
1112
1113 if ((pVpHalTgtSurf->rcSrc.right < pVpHalSrcSurf->rcDst.right) ||
1114 (pVpHalTgtSurf->rcSrc.bottom < pVpHalSrcSurf->rcDst.bottom))
1115 {
1116 DDI_CHK_CONDITION(true, "Invalid color fill parameter!", VA_STATUS_ERROR_INVALID_PARAMETER);
1117 }
1118
1119 //set the frame_id
1120 pVpHalSrcSurf->FrameID = pMediaSrcSurf->frame_idx;
1121
1122 //In order to refresh the frame ID in DdiVp_UpdateFilterParamBuffer when run ADI case,
1123 //we need to set the OS resource here.
1124 pVpHalSrcSurf->OsResource.bo = pMediaSrcSurf->bo;
1125
1126 // csc option
1127 //---------------------------------------
1128 // Set color space for src
1129 #if (VA_MAJOR_VERSION < 1)
1130 vaStatus = DdiVp_GetColorSpace(pVpHalSrcSurf, pPipelineParam->surface_color_standard, pPipelineParam->input_surface_flag);
1131 #else
1132 vaStatus = DdiVp_GetColorSpace(pVpHalSrcSurf, pPipelineParam->surface_color_standard, pPipelineParam->input_color_properties);
1133 #endif
1134 DDI_CHK_RET(vaStatus, "Unsupport Color space!");
1135
1136 if(pMediaSrcSurf->format == Media_Format_400P)
1137 {
1138 pVpHalSrcSurf->ColorSpace = CSpace_BT601Gray;
1139 }
1140
1141 // extended gamut? RGB can't have extended gamut flag
1142 pVpHalSrcSurf->ExtendedGamut = false;
1143
1144 // Background Colorfill
1145 // According to libva definition, if alpha in output background color is zero, then colorfill is not needed
1146 if ((pPipelineParam->output_background_color >> 24) != 0 || pVpHalTgtSurf->ColorSpace == CSpace_sRGB)
1147 {
1148 if (pVpHalRenderParams->pColorFillParams == nullptr)
1149 {
1150 pVpHalRenderParams->pColorFillParams = (PVPHAL_COLORFILL_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_COLORFILL_PARAMS));
1151 }
1152
1153 DDI_CHK_NULL(pVpHalRenderParams->pColorFillParams, "Null pColorFillParams.", VA_STATUS_ERROR_UNKNOWN);
1154
1155 if (pVpHalTgtSurf->ColorSpace == CSpace_sRGB && (pPipelineParam->output_background_color >> 24) == 0)
1156 {
1157 // set color space for sRGB output
1158 pVpHalRenderParams->pColorFillParams->CSpace = CSpace_sRGB;
1159 }
1160 else
1161 {
1162 // set background colorfill option
1163 pVpHalRenderParams->pColorFillParams->Color = pPipelineParam->output_background_color;
1164 pVpHalRenderParams->pColorFillParams->bYCbCr = false;
1165 pVpHalRenderParams->pColorFillParams->CSpace = CSpace_sRGB;
1166 }
1167 }else
1168 {
1169 MOS_FreeMemAndSetNull(pVpHalRenderParams->pColorFillParams);
1170 }
1171
1172 // Set Demo Mode option
1173 if (pVpHalRenderParams->bDisableDemoMode == false)
1174 {
1175 eStatus = VpHal_DdiSetupSplitScreenDemoMode(
1176 0, // No DDI setting on Linux. Set it when Linux DDI supports it
1177 0, // No DDI setting on Linux. Set it when Linux DDI supports it
1178 &pVpHalRenderParams->pSplitScreenDemoModeParams,
1179 &pVpHalRenderParams->bDisableDemoMode,
1180 pOsInterface);
1181 if (MOS_STATUS_SUCCESS != eStatus)
1182 {
1183 VP_DDI_ASSERTMESSAGE("Failed to setup Split-Screen Demo Mode.");
1184 MOS_FreeMemAndSetNull(pVpHalRenderParams->pSplitScreenDemoModeParams);
1185 }
1186 }
1187
1188 // Update fwd and bkward ref frames: Required for Advanced processing - will be supported in the future
1189
1190 pVpHalSrcSurf->uFwdRefCount = pPipelineParam->num_backward_references;
1191
1192 vaStatus = DdiVp_UpdateProcPipelineFutureReferenceFrames(pVpCtx, pVaDrvCtx, pVpHalSrcSurf, pPipelineParam);
1193 DDI_CHK_RET(vaStatus, "Failed to update future reference frames!");
1194
1195 pVpHalSrcSurf->uBwdRefCount = pPipelineParam->num_forward_references;
1196
1197 vaStatus = DdiVp_UpdateProcPipelinePastReferenceFrames(pVpCtx, pVaDrvCtx, pVpHalSrcSurf, pPipelineParam);
1198 DDI_CHK_RET(vaStatus, "Failed to update past reference frames!");
1199
1200 // Check if filter values changed,if yes, then reset all filters for this surface
1201
1202 // intialize the filter parameter
1203 // Parameters once set in the surface will be keep till video complete
1204 // so the parameter of rendered surface should be intialized every time
1205 if (pVpHalRenderParams->bStereoMode)
1206 {
1207 pVpHalSrcSurf->Rotation = VPHAL_ROTATION_IDENTITY;
1208 }
1209
1210 // Progressive or interlaced - Check filter_flags
1211 // if the deinterlace parameters is not set, manipulate it as a progressive video.
1212 if (pPipelineParam->filter_flags & VA_TOP_FIELD)
1213 {
1214 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
1215 }
1216 else if (pPipelineParam->filter_flags & VA_BOTTOM_FIELD)
1217 {
1218 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD;
1219 }
1220 else // VA_FRAME_PICTURE
1221 {
1222 pVpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
1223
1224 //if the deinterlace parameters is set, clear it.
1225 if (pVpHalSrcSurf->pDeinterlaceParams != nullptr)
1226 {
1227 MOS_FreeMemAndSetNull(pVpHalSrcSurf->pDeinterlaceParams);
1228 }
1229 }
1230
1231 for (i = 0; i < pPipelineParam->num_filters; i++)
1232 {
1233 VABufferID filter = pPipelineParam->filters[i];
1234
1235 pFilterBuf = DdiMedia_GetBufferFromVABufferID(pMediaCtx, filter);
1236 DDI_CHK_NULL(pFilterBuf, "Null pFilterBuf!", VA_STATUS_ERROR_INVALID_BUFFER);
1237
1238 DDI_CHK_CONDITION((VAProcFilterParameterBufferType != pFilterBuf->uiType),
1239 "Invalid parameter buffer type!", VA_STATUS_ERROR_INVALID_PARAMETER);
1240
1241 // Map Buffer data to virtual addres space
1242 DdiMedia_MapBuffer(pVaDrvCtx, filter, &pData);
1243
1244 VAProcFilterParameterBufferBase* filter_param = (VAProcFilterParameterBufferBase*) pData;
1245
1246 // HSBC can only be applied to the primary layer
1247 if (!((filter_param->type == VAProcFilterColorBalance)
1248 && pVpHalSrcSurf->SurfType != SURF_IN_PRIMARY))
1249 {
1250 // Pass the filter type
1251 vaStatus = DdiVp_UpdateFilterParamBuffer(pVaDrvCtx, pVpCtx, uSurfIndex, filter_param->type, pData, pFilterBuf->uiNumElements, &vpStateFlags);
1252 DDI_CHK_RET(vaStatus, "Failed to update parameter buffer!");
1253 }
1254 }
1255
1256 DdiVp_ClearFilterParamBuffer(pVpCtx, uSurfIndex, vpStateFlags);
1257
1258 // Update the Deinterlace params
1259 //vaStatus = DdiVp_UpdateProcDeinterlaceParams(pVaDrvCtx, pVpHalSrcSurf, pPipelineParam);
1260 //DDI_CHK_RET(vaStatus, "Failed to update vphal advance deinterlace!");
1261
1262 // Use Render to do scaling for resolution larger than 8K
1263 if(MEDIA_IS_WA(&pMediaCtx->WaTable, WaDisableVeboxFor8K))
1264 {
1265 pVpHalRenderParams->bDisableVeboxFor8K = true;
1266 }
1267
1268 // Scaling algorithm
1269 uScalingflags = pPipelineParam->filter_flags & VA_FILTER_SCALING_MASK;
1270 pVpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_SFC; // default
1271 // Interpolation method
1272 #if VA_CHECK_VERSION(1, 9, 0)
1273 uInterpolationflags = pPipelineParam->filter_flags & VA_FILTER_INTERPOLATION_MASK;
1274 #endif
1275 switch (uScalingflags)
1276 {
1277 case VA_FILTER_SCALING_FAST:
1278 if (pVpHalSrcSurf->SurfType == SURF_IN_PRIMARY)
1279 {
1280 VpSetInterpolationParams(pVpHalSrcSurf, uInterpolationflags);
1281 pVpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_SFC_FOR_VEBOX;
1282 }
1283 else
1284 {
1285 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
1286 }
1287 break;
1288 case VA_FILTER_SCALING_HQ:
1289 if (pVpHalSrcSurf->SurfType == SURF_IN_PRIMARY)
1290 {
1291 VpSetInterpolationParams(pVpHalSrcSurf, uInterpolationflags);
1292 pVpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_COMP;
1293 }
1294 else
1295 {
1296 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
1297 }
1298 break;
1299 case VA_FILTER_SCALING_DEFAULT:
1300 case VA_FILTER_SCALING_NL_ANAMORPHIC:
1301 default:
1302 if (pVpHalSrcSurf->SurfType == SURF_IN_PRIMARY)
1303 {
1304 VpSetInterpolationParams(pVpHalSrcSurf, uInterpolationflags);
1305 pVpHalSrcSurf->ScalingPreference = VPHAL_SCALING_PREFER_SFC;
1306 }
1307 else
1308 {
1309 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
1310 }
1311 break;
1312 }
1313 //init interlace scaling flag
1314 pVpHalSrcSurf->bInterlacedScaling = false;
1315 pVpHalSrcSurf->bFieldWeaving = false;
1316
1317 if (pVpHalSrcSurf->pDeinterlaceParams == nullptr)
1318 {
1319 if (pPipelineParam->input_surface_flag & VA_TOP_FIELD_FIRST)
1320 {
1321 if (pPipelineParam->output_surface_flag & VA_TOP_FIELD_FIRST)
1322 {
1323 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
1324 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
1325 pVpHalSrcSurf->bInterlacedScaling = true;
1326 pVpHalSrcSurf->bFieldWeaving = false;
1327 }else if (pPipelineParam->output_surface_flag & VA_TOP_FIELD)
1328 {
1329 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
1330 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
1331 pVpHalTgtSurf->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1332 pVpHalSrcSurf->bInterlacedScaling = false;
1333 pVpHalSrcSurf->bFieldWeaving = false;
1334 }else if (pPipelineParam->output_surface_flag & VA_BOTTOM_FIELD)
1335 {
1336 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
1337 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD;
1338 pVpHalTgtSurf->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1339 pVpHalSrcSurf->bInterlacedScaling = false;
1340 pVpHalSrcSurf->bFieldWeaving = false;
1341 }else
1342 {
1343 VP_DDI_ASSERTMESSAGE("output_surface_flag need to be set for interlaced scaling.");
1344 pVpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
1345 pVpHalSrcSurf->InterlacedScalingType = ISCALING_NONE;
1346 pVpHalSrcSurf->bInterlacedScaling = false;
1347 pVpHalSrcSurf->bFieldWeaving = false;
1348 }
1349 }
1350 else if (pPipelineParam->input_surface_flag & VA_BOTTOM_FIELD_FIRST)
1351 {
1352 if (pPipelineParam->output_surface_flag & VA_BOTTOM_FIELD_FIRST)
1353 {
1354 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
1355 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
1356 pVpHalSrcSurf->bInterlacedScaling = true;
1357 pVpHalSrcSurf->bFieldWeaving = false;
1358 }else if (pPipelineParam->output_surface_flag & VA_TOP_FIELD)
1359 {
1360 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
1361 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD;
1362 pVpHalTgtSurf->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1363 pVpHalSrcSurf->bInterlacedScaling = false;
1364 pVpHalSrcSurf->bFieldWeaving = false;
1365 }else if (pPipelineParam->output_surface_flag & VA_BOTTOM_FIELD)
1366 {
1367 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_FIELD;
1368 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
1369 pVpHalTgtSurf->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1370 pVpHalSrcSurf->bInterlacedScaling = false;
1371 pVpHalSrcSurf->bFieldWeaving = false;
1372 }else
1373 {
1374 VP_DDI_ASSERTMESSAGE("output_surface_flag need to be set for interlaced scaling.");
1375 pVpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
1376 pVpHalSrcSurf->InterlacedScalingType = ISCALING_NONE;
1377 pVpHalSrcSurf->bInterlacedScaling = false;
1378 pVpHalSrcSurf->bFieldWeaving = false;
1379 }
1380 }else if (pPipelineParam->input_surface_flag & VA_TOP_FIELD)
1381 {
1382 if (pPipelineParam->output_surface_flag & VA_TOP_FIELD_FIRST)
1383 {
1384 pVpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
1385 pVpHalSrcSurf->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1386 pVpHalTgtSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
1387
1388 DDI_CHK_NULL(pVpHalSrcSurf->pBwdRef, "No Ref Field!", VA_STATUS_ERROR_UNIMPLEMENTED);
1389 pVpHalSrcSurf->pBwdRef->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
1390 pVpHalSrcSurf->pBwdRef->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1391
1392 pVpHalSrcSurf->bInterlacedScaling = false;
1393 pVpHalSrcSurf->bFieldWeaving = true;
1394 }else if(pPipelineParam->output_surface_flag & VA_TOP_FIELD)
1395 {
1396 pVpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_FIELD;
1397 pVpHalSrcSurf->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1398 pVpHalSrcSurf->bInterlacedScaling = false;
1399 pVpHalSrcSurf->bFieldWeaving = false;
1400 }else
1401 {
1402 pVpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
1403 pVpHalSrcSurf->bInterlacedScaling = false;
1404 pVpHalSrcSurf->bFieldWeaving = false;
1405 }
1406 }else if (pPipelineParam->input_surface_flag & VA_BOTTOM_FIELD)
1407 {
1408 if (pPipelineParam->output_surface_flag & VA_BOTTOM_FIELD_FIRST)
1409 {
1410 pVpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
1411 pVpHalSrcSurf->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1412 pVpHalTgtSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
1413
1414 DDI_CHK_NULL(pVpHalSrcSurf->pBwdRef, "No Ref Field!", VA_STATUS_ERROR_UNIMPLEMENTED);
1415 pVpHalSrcSurf->pBwdRef->InterlacedScalingType = ISCALING_FIELD_TO_INTERLEAVED;
1416 pVpHalSrcSurf->pBwdRef->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1417
1418 pVpHalSrcSurf->bInterlacedScaling = false;
1419 pVpHalSrcSurf->bFieldWeaving = true;
1420 }else if(pPipelineParam->output_surface_flag & VA_BOTTOM_FIELD)
1421 {
1422 pVpHalSrcSurf->InterlacedScalingType = ISCALING_FIELD_TO_FIELD;
1423 pVpHalSrcSurf->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1424 pVpHalSrcSurf->bInterlacedScaling = false;
1425 pVpHalSrcSurf->bFieldWeaving = false;
1426 }else
1427 {
1428 pVpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
1429 pVpHalSrcSurf->bInterlacedScaling = false;
1430 pVpHalSrcSurf->bFieldWeaving = false;
1431 }
1432 }else
1433 {
1434 pVpHalSrcSurf->SampleType = SAMPLE_PROGRESSIVE;
1435 pVpHalSrcSurf->InterlacedScalingType = ISCALING_NONE;
1436 pVpHalSrcSurf->bInterlacedScaling = false;
1437 pVpHalSrcSurf->bFieldWeaving = false;
1438 }
1439 }
1440
1441 // For legacy interlace scaling
1442 if (pVpHalSrcSurf->pDeinterlaceParams == nullptr && pVpHalSrcSurf->InterlacedScalingType == ISCALING_NONE)
1443 {
1444 if (pPipelineParam->filter_flags & VA_TOP_FIELD)
1445 {
1446 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
1447 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_AVS;
1448 pVpHalSrcSurf->bInterlacedScaling = true;
1449 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
1450 }
1451 else if (pPipelineParam->filter_flags & VA_BOTTOM_FIELD)
1452 {
1453 pVpHalSrcSurf->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
1454 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_AVS;
1455 pVpHalSrcSurf->bInterlacedScaling = true;
1456 pVpHalSrcSurf->InterlacedScalingType = ISCALING_INTERLEAVED_TO_INTERLEAVED;
1457 }
1458
1459 // Kernel does not support 3-plane interlaced AVS, so for 3-plane interlaced scaling, need to use bilinear.
1460 if (pVpHalSrcSurf->bInterlacedScaling && IS_PL3_FORMAT(pVpHalSrcSurf->Format))
1461 {
1462 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
1463 }
1464 }
1465 // For weave DI
1466 if (pVpHalSrcSurf->pDeinterlaceParams == nullptr)
1467 {
1468 if ((pPipelineParam->filter_flags & 0x00000004) || ((pPipelineParam->filter_flags & VA_TOP_FIELD) && pVpHalSrcSurf->bFieldWeaving))
1469 {
1470 pVpHalSrcSurf->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1471 if (pVpHalSrcSurf->pBwdRef != nullptr)
1472 {
1473 pVpHalSrcSurf->pBwdRef->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1474 }
1475 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
1476 pVpHalSrcSurf->bFieldWeaving = true;
1477 }
1478
1479 if ((pPipelineParam->filter_flags & 0x00000008) || ((pPipelineParam->filter_flags & VA_BOTTOM_FIELD) && pVpHalSrcSurf->bFieldWeaving))
1480 {
1481 pVpHalSrcSurf->SampleType = SAMPLE_SINGLE_BOTTOM_FIELD;
1482 if (pVpHalSrcSurf->pBwdRef != nullptr)
1483 {
1484 pVpHalSrcSurf->pBwdRef->SampleType = SAMPLE_SINGLE_TOP_FIELD;
1485 }
1486 pVpHalSrcSurf->ScalingMode = VPHAL_SCALING_BILINEAR;
1487 pVpHalSrcSurf->bFieldWeaving = true;
1488 }
1489 }
1490
1491 // Rotation
1492 vaStatus = VpUpdateProcRotateState(pVpHalSrcSurf,pPipelineParam->rotation_state);
1493 DDI_CHK_RET(vaStatus, "Failed to update rotate state!");
1494
1495 // Mirror
1496 vaStatus = VpUpdateProcMirrorState(pVpHalSrcSurf,pPipelineParam->mirror_state);
1497 DDI_CHK_RET(vaStatus, "Failed to update mirror state!");
1498
1499 // Alpha blending
1500 // Note: the alpha blending region cannot overlay
1501 vaStatus = DdiVp_SetProcPipelineBlendingParams(pVpCtx, uSurfIndex, pPipelineParam);
1502 DDI_CHK_RET(vaStatus, "Failed to update Alpha Blending parameter!");
1503
1504 if (IsProcmpEnable(pVpHalSrcSurf))
1505 {
1506 // correct the ChromaSitting location if Procamp is enabled.
1507 #if (VA_MAJOR_VERSION < 1)
1508 pPipelineParam->input_surface_flag = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
1509 pPipelineParam->output_surface_flag = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
1510 #else
1511 pPipelineParam->input_color_properties.chroma_sample_location = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
1512 pPipelineParam->output_color_properties.chroma_sample_location = VA_CHROMA_SITING_HORIZONTAL_LEFT | VA_CHROMA_SITING_VERTICAL_TOP;
1513 #endif
1514 }
1515
1516 #if (VA_MAJOR_VERSION < 1)
1517 VpUpdateProcChromaSittingState(pVpHalSrcSurf, (uint8_t)(pPipelineParam->input_surface_flag&0xff));
1518 VpUpdateProcChromaSittingState(pVpHalTgtSurf, (uint8_t)(pPipelineParam->output_surface_flag&0xff));
1519 #else
1520 VpUpdateProcChromaSittingState(pVpHalSrcSurf, pPipelineParam->input_color_properties.chroma_sample_location);
1521 VpUpdateProcChromaSittingState(pVpHalTgtSurf, pPipelineParam->output_color_properties.chroma_sample_location);
1522 #endif
1523 // update OsResource for src surface
1524 pVpHalSrcSurf->OsResource.Format = VpGetFormatFromMediaFormat(pMediaSrcSurf->format);
1525 pVpHalSrcSurf->OsResource.iWidth = pMediaSrcSurf->iWidth;
1526 pVpHalSrcSurf->OsResource.iHeight = pMediaSrcSurf->iHeight;
1527 pVpHalSrcSurf->OsResource.iPitch = pMediaSrcSurf->iPitch;
1528 pVpHalSrcSurf->OsResource.iCount = pMediaSrcSurf->iRefCount;
1529 pVpHalSrcSurf->OsResource.bo = pMediaSrcSurf->bo;
1530 pVpHalSrcSurf->OsResource.TileType = VpGetTileTypeFromMediaTileType(pMediaSrcSurf->TileType);
1531 pVpHalSrcSurf->OsResource.pGmmResInfo = pMediaSrcSurf->pGmmResourceInfo;
1532
1533 Mos_Solo_SetOsResource(pMediaSrcSurf->pGmmResourceInfo, &pVpHalSrcSurf->OsResource);
1534
1535 //Set encryption bit for input surface
1536 //This setting only used for secure VPP test app which do secure VP and provide secure YUV as input
1537 //Since APP cannot set encryption flag, it will set input_surface_flag to ask driver add encryption bit to input surface
1538 if (pOsInterface->osCpInterface->IsHMEnabled() && (pPipelineParam->input_surface_flag & VPHAL_SURFACE_ENCRYPTION_FLAG))
1539 {
1540 pOsInterface->osCpInterface->SetResourceEncryption(&(pVpHalSrcSurf->OsResource), true);
1541 }
1542
1543 // Update the Render Target params - this needs to be done once when Render Target is passed via BeginPicture
1544 vaStatus = DdiVp_UpdateVphalTargetSurfColorSpace(pVaDrvCtx, pVpCtx, pPipelineParam, 0);
1545 DDI_CHK_RET(vaStatus, "Failed to update vphal target surface color space!");
1546 // Update the Render Target HDR params - this needs to be done once when Render Target is passed via BeginPicture
1547 vaStatus = VpUpdateProcHdrState(pVpHalTgtSurf, pPipelineParam->output_hdr_metadata);
1548 DDI_CHK_RET(vaStatus, "Failed to update vphal target surface HDR metadata!");
1549
1550 // Using additional_outputs processing as 1:N case.
1551 for (i = 0; i < pPipelineParam->num_additional_outputs; i++)
1552 {
1553 vaStatus = DdiVp_BeginPictureInt(pVaDrvCtx, pVpCtx, pPipelineParam->additional_outputs[i]);
1554 DDI_CHK_RET(vaStatus, "Failed to update vphal target surface buffers!");
1555 vaStatus = DdiVp_UpdateVphalTargetSurfColorSpace(pVaDrvCtx, pVpCtx, pPipelineParam, i+1);
1556 DDI_CHK_RET(vaStatus, "Failed to update vphal target surface color space!");
1557 }
1558
1559 // add 16aligned UsrPtr mode support
1560 if (pMediaSrcSurf->pSurfDesc && (pMediaSrcSurf->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR))
1561 {
1562 pVpHalSrcSurf->b16UsrPtr = VpIs16UsrPtrPitch(pMediaSrcSurf->iPitch, pMediaSrcSurf->format);
1563 }
1564 else
1565 {
1566 pVpHalSrcSurf->b16UsrPtr = false;
1567 }
1568
1569 return VA_STATUS_SUCCESS;
1570 }
1571
1572 //////////////////////////////////////////////////////////////////////////////////////////////
1573 //! \purpose: Get resource informaton from target surface, set OS Resource for VPHAL
1574 //! \[in] pVpCtx : VP context
1575 //! \[in] pboRt : media surface
1576 //! \[in] targetIndex : index of target surface in VpHal RenderParams.
1577 //! \[out] None
1578 //! \returns: Result of operation
1579 //////////////////////////////////////////////////////////////////////////////////////////////
1580 VAStatus VpSetOsResource(
1581 PDDI_VP_CONTEXT pVpCtx,
1582 PDDI_MEDIA_SURFACE pboRt,
1583 uint32_t targetIndex)
1584 {
1585 PMOS_RESOURCE pOsResource;
1586 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
1587
1588 VP_DDI_FUNCTION_ENTER;
1589 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1590
1591 // get vphal render parameters
1592 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
1593 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
1594
1595 // set render target os resource information according to target surface
1596 pOsResource = &pVpHalRenderParams->pTarget[targetIndex]->OsResource;
1597 DDI_CHK_NULL(pOsResource, "Null pOsResource.", VA_STATUS_ERROR_INVALID_PARAMETER);
1598 pOsResource->bo = pboRt->bo;
1599 pOsResource->bMapped = pboRt->bMapped;
1600 pOsResource->Format = VpGetFormatFromMediaFormat( pboRt->format );
1601 pOsResource->iWidth = pboRt->iWidth;
1602 pOsResource->iHeight = pboRt->iHeight;
1603 pOsResource->iPitch = pboRt->iPitch;
1604 pOsResource->iCount = pboRt->iRefCount;
1605 pOsResource->TileType = VpGetTileTypeFromMediaTileType(pboRt->TileType);
1606 pOsResource->pGmmResInfo = pboRt->pGmmResourceInfo;
1607
1608 Mos_Solo_SetOsResource(pboRt->pGmmResourceInfo, pOsResource);
1609
1610 return VA_STATUS_SUCCESS;
1611 }
1612
1613 //////////////////////////////////////////////////////////////////////////////////////////////
1614 //! \purpose Helper function for VpAllocateDrvCtxExt to Allocate PDDI_VP_CONTEXT
1615 //! \params
1616 //! [in] pVaDrvCtx : VA Driver context
1617 //! [in] pVpCtx : VP context
1618 //! [out] None
1619 //! \returns VA_STATUS_SUCCESS if call succeeds
1620 /////////////////////////////////////////////////////////////////////////////////////////////
1621 VAStatus DdiVp_InitCtx(VADriverContextP pVaDrvCtx, PDDI_VP_CONTEXT pVpCtx)
1622 {
1623 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
1624
1625 PVPHAL_RENDER_PARAMS pVpHalRenderParams = nullptr;
1626 int32_t uSurfIndex;
1627 PDDI_MEDIA_CONTEXT pMediaCtx;
1628 VAStatus vaStatus;
1629
1630 VP_DDI_FUNCTION_ENTER;
1631 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1632
1633 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
1634 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1635
1636 // initialize VPHAL
1637 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1638 pVpCtx->MosDrvCtx.bufmgr = pMediaCtx->pDrmBufMgr;
1639 pVpCtx->MosDrvCtx.m_gpuContextMgr = pMediaCtx->m_gpuContextMgr;
1640 pVpCtx->MosDrvCtx.m_cmdBufMgr = pMediaCtx->m_cmdBufMgr;
1641 pVpCtx->MosDrvCtx.fd = pMediaCtx->fd;
1642 pVpCtx->MosDrvCtx.iDeviceId = pMediaCtx->iDeviceId;
1643 pVpCtx->MosDrvCtx.m_skuTable = pMediaCtx->SkuTable;
1644 pVpCtx->MosDrvCtx.m_waTable = pMediaCtx->WaTable;
1645 pVpCtx->MosDrvCtx.m_gtSystemInfo = *pMediaCtx->pGtSystemInfo;
1646 pVpCtx->MosDrvCtx.m_platform = pMediaCtx->platform;
1647 pVpCtx->MosDrvCtx.m_auxTableMgr = pMediaCtx->m_auxTableMgr;
1648 pVpCtx->MosDrvCtx.pGmmClientContext = pMediaCtx->pGmmClientContext;
1649 pVpCtx->MosDrvCtx.ppMediaMemDecompState = &pMediaCtx->pMediaMemDecompState;
1650 pVpCtx->MosDrvCtx.pfnMediaMemoryCopy = pMediaCtx->pfnMediaMemoryCopy;
1651 pVpCtx->MosDrvCtx.pfnMediaMemoryCopy2D = pMediaCtx->pfnMediaMemoryCopy2D;
1652 pVpCtx->MosDrvCtx.pfnMemoryDecompress = pMediaCtx->pfnMemoryDecompress;
1653 pVpCtx->MosDrvCtx.ppMediaCopyState = &pMediaCtx->pMediaCopyState;
1654
1655 pVpCtx->MosDrvCtx.m_osDeviceContext = pMediaCtx->m_osDeviceContext;
1656 pVpCtx->MosDrvCtx.m_apoMosEnabled = pMediaCtx->m_apoMosEnabled;
1657 pVpCtx->MosDrvCtx.m_userSettingPtr = pMediaCtx->m_userSettingPtr;
1658
1659 pVpCtx->MosDrvCtx.pPerfData = (PERF_DATA *)MOS_AllocAndZeroMemory(sizeof(PERF_DATA));
1660 if (nullptr == pVpCtx->MosDrvCtx.pPerfData)
1661 {
1662 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1663 }
1664
1665 // initialize DDI level cp interface
1666 pVpCtx->pCpDdiInterface = Create_DdiCpInterface(pVpCtx->MosDrvCtx);
1667 if (nullptr == pVpCtx->pCpDdiInterface)
1668 {
1669 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1670 goto FINISH;
1671 }
1672
1673
1674 DDI_CHK_RET(DdiVp_InitVpHal(pVpCtx), "Call DdiVp_InitVpHal failed");
1675
1676 // allocate vphal render param
1677 pVpHalRenderParams = (PVPHAL_RENDER_PARAMS)(MOS_AllocAndZeroMemory(sizeof(VPHAL_RENDER_PARAMS)));
1678 if( nullptr == pVpHalRenderParams)
1679 {
1680 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1681 goto FINISH;
1682 }
1683
1684 // initialize vphal render params
1685 for (uSurfIndex = 0; uSurfIndex < VPHAL_MAX_SOURCES; uSurfIndex++)
1686 {
1687 pVpHalRenderParams->pSrc[uSurfIndex] = (PVPHAL_SURFACE)MOS_AllocAndZeroMemory(sizeof(VPHAL_SURFACE));
1688 if( nullptr == pVpHalRenderParams->pSrc[uSurfIndex])
1689 {
1690 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1691 goto FINISH;
1692 }
1693 }
1694
1695 for (uSurfIndex = 0; uSurfIndex < VPHAL_MAX_TARGETS; uSurfIndex++)
1696 {
1697 pVpHalRenderParams->pTarget[uSurfIndex] = (PVPHAL_SURFACE)MOS_AllocAndZeroMemory(sizeof(VPHAL_SURFACE));
1698 if( nullptr == pVpHalRenderParams->pTarget[uSurfIndex])
1699 {
1700 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1701 goto FINISH;
1702 }
1703 }
1704
1705 // background Colorfill
1706 pVpHalRenderParams->pColorFillParams = (PVPHAL_COLORFILL_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_COLORFILL_PARAMS));
1707 if( nullptr == pVpHalRenderParams->pColorFillParams)
1708 {
1709 vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED;
1710 goto FINISH;
1711 }
1712
1713 // reset source surface count
1714 pVpHalRenderParams->uSrcCount = 0;
1715 pVpCtx->MosDrvCtx.wRevision = 0;
1716 pVpCtx->iPriSurfs = 0;
1717
1718 // Add the render param for calculating alpha value.
1719 // Because can not pass the alpha calculate flag from iVP,
1720 // need to hardcode here for both Android and Linux.
1721 pVpHalRenderParams->bCalculatingAlpha = true;
1722
1723 // put the render param in vp context
1724 pVpCtx->pVpHalRenderParams = pVpHalRenderParams;
1725
1726 #if (_DEBUG || _RELEASE_INTERNAL)
1727 vaStatus = VpInitDumpConfig(pVpCtx);
1728 DDI_CHK_RET( vaStatus, "Init Dump Config failed");
1729 #endif //(_DEBUG || _RELEASE_INTERNAL)
1730
1731 return VA_STATUS_SUCCESS;
1732
1733 FINISH:
1734
1735 if(pVpHalRenderParams)
1736 {
1737 for (uSurfIndex = 0; uSurfIndex < VPHAL_MAX_SOURCES; uSurfIndex++)
1738 {
1739 MOS_FreeMemory(pVpHalRenderParams->pSrc[uSurfIndex]);
1740 }
1741 for (uSurfIndex = 0; uSurfIndex < VPHAL_MAX_TARGETS; uSurfIndex++)
1742 {
1743 MOS_FreeMemory(pVpHalRenderParams->pTarget[uSurfIndex]);
1744 }
1745
1746 MOS_FreeMemory(pVpHalRenderParams->pColorFillParams);
1747 MOS_FreeMemory(pVpHalRenderParams);
1748 }
1749
1750 if (pVpCtx->pCpDdiInterface)
1751 {
1752 Delete_DdiCpInterface(pVpCtx->pCpDdiInterface);
1753 pVpCtx->pCpDdiInterface = NULL;
1754 }
1755
1756 #if (_DEBUG || _RELEASE_INTERNAL)
1757 VpDestoryDumpConfig(pVpCtx);
1758 #endif //(_DEBUG || _RELEASE_INTERNAL)
1759
1760 return vaStatus;
1761 }
1762
1763 //////////////////////////////////////////////////////////////////////////////////////////////
1764 //! \purpose Initialize VPHAL State and VPHAL settings per VP context
1765 //! \params
1766 //! [in] pVpCtx : VP context
1767 //! [out] None
1768 //! \returns VA_STATUS_SUCCESS if call succeeds
1769 /////////////////////////////////////////////////////////////////////////////////////////////
1770 VAStatus
1771 DdiVp_InitVpHal(
1772 PDDI_VP_CONTEXT pVpCtx
1773 )
1774 {
1775 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
1776
1777 VpBase *pVpHal;
1778 VphalSettings VpHalSettings;
1779
1780 VAStatus vaStatus;
1781
1782 VP_DDI_FUNCTION_ENTER;
1783 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
1784
1785 // initialize
1786 vaStatus = VA_STATUS_ERROR_UNKNOWN;
1787 pVpHal = nullptr;
1788
1789 // Create VpHal state
1790 MOS_STATUS eStatus = MOS_STATUS_UNKNOWN;
1791 pVpHal = VpBase::VphalStateFactory( nullptr, &(pVpCtx->MosDrvCtx), &eStatus);
1792
1793 if (pVpHal && MOS_FAILED(eStatus))
1794 {
1795 MOS_Delete(pVpHal);
1796 pVpHal = nullptr;
1797 }
1798
1799 if (!pVpHal)
1800 {
1801 VP_DDI_ASSERTMESSAGE("Failed to create vphal.");
1802 MOS_Delete(pVpCtx);
1803 return VA_STATUS_ERROR_ALLOCATION_FAILED;
1804 }
1805
1806 if (nullptr != pVpHal)
1807 {
1808 VpHalSettings.maxPhases = VP_SETTING_MAX_PHASES;
1809 VpHalSettings.mediaStates = VP_SETTING_MEDIA_STATES;
1810 VpHalSettings.sameSampleThreshold = VP_SETTING_SAME_SAMPLE_THRESHOLD;
1811 VpHalSettings.disableDnDi = false;
1812
1813 // Allocate resources (state heaps, resources, KDLL)
1814 if (MOS_FAILED(pVpHal->Allocate(&VpHalSettings)))
1815 {
1816 VP_DDI_ASSERTMESSAGE("Failed to allocate resources for vphal.");
1817 MOS_Delete(pVpHal);
1818 pVpHal = nullptr;
1819 return vaStatus;
1820 }
1821 }
1822
1823 pVpCtx->pVpHal = pVpHal;
1824
1825 return VA_STATUS_SUCCESS;
1826 }
1827
1828 //////////////////////////////////////////////////////////////////////////////////////////////
1829 ////! \purpose Set Color Standard Explictly.
1830 ////! \params
1831 ////! [in] pVpHalSurf : src/target surface
1832 ////! [in] colorStandard : VA color standard VAProcColorStandardType
1833 ////! [in] colorProperties : input/output surface color properties
1834 ////! [out] None
1835 ////! \returns appropriate VA_STATUS_SUCCESS if call succeeds
1836 ///////////////////////////////////////////////////////////////////////////////////////////////
1837 VAStatus VpSetColorStandardExplictly(PVPHAL_SURFACE pVpHalSurf, VAProcColorStandardType colorStandard, VAProcColorProperties colorProperties)
1838 {
1839 DDI_CHK_NULL(pVpHalSurf, "Null pVpHalSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
1840 DDI_CHK_CONDITION((colorStandard != VAProcColorStandardExplicit), "Not Explict color standard, Exit!", VA_STATUS_ERROR_INVALID_PARAMETER);
1841
1842 if (IS_RGB_FORMAT(pVpHalSurf->Format))
1843 {
1844 switch(colorProperties.colour_primaries)
1845 {
1846 case COLOUR_PRIMARY_BT2020:
1847 pVpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_REDUCED) ? CSpace_BT2020_stRGB : CSpace_BT2020_RGB;
1848 break;
1849 case COLOUR_PRIMARY_BT709:
1850 case COLOUR_PRIMARY_BT601:
1851 pVpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_REDUCED) ? CSpace_stRGB: CSpace_sRGB;
1852 break;
1853 default:
1854 pVpHalSurf->ColorSpace = CSpace_sRGB;
1855 VP_DDI_ASSERTMESSAGE("unknown Color Standard for RGB format.");
1856 break;
1857 }
1858 }
1859
1860 if (IS_YUV_FORMAT(pVpHalSurf->Format) || IS_ALPHA_YUV_FORMAT(pVpHalSurf->Format))
1861 {
1862 switch(colorProperties.colour_primaries)
1863 {
1864 case COLOUR_PRIMARY_BT2020:
1865 pVpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_FULL) ? CSpace_BT2020_FullRange : CSpace_BT2020;
1866 break;
1867 case COLOUR_PRIMARY_BT709:
1868 pVpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_FULL) ? CSpace_BT709_FullRange : CSpace_BT709;
1869 break;
1870 case COLOUR_PRIMARY_BT601:
1871 pVpHalSurf->ColorSpace = (colorProperties.color_range & VA_SOURCE_RANGE_FULL) ? CSpace_BT601_FullRange : CSpace_BT601;
1872 break;
1873 default:
1874 pVpHalSurf->ColorSpace = CSpace_BT601;
1875 VP_DDI_ASSERTMESSAGE("unknown Color Standard for YUV format.");
1876 break;
1877 }
1878 }
1879
1880 switch(colorProperties.transfer_characteristics)
1881 {
1882 case TRANSFER_CHARACTERISTICS_ST2084:
1883 pVpHalSurf->GammaType = VPHAL_GAMMA_SMPTE_ST2084;
1884 break;
1885 default:
1886 pVpHalSurf->GammaType = VPHAL_GAMMA_TRADITIONAL_GAMMA;
1887 break;
1888 }
1889
1890 return VA_STATUS_SUCCESS;
1891 }
1892
1893 //////////////////////////////////////////////////////////////////////////////////////////////
1894 ////! \purpose Convert VAProcColorStandardType to VPHAL_CSPACE
1895 ////! \params
1896 ////! [in] pVpHalSurf : src/target surface
1897 ////! [in] colorStandard : VA color standard VAProcColorStandardType
1898 ////! [in] flag : input/output surface flag for full/reduced color range
1899 ////! [out] None
1900 ////! \returns appropriate VPHAL_CSPACE if call succeeds
1901 ///////////////////////////////////////////////////////////////////////////////////////////////
1902 #if (VA_MAJOR_VERSION < 1)
1903 VAStatus DdiVp_GetColorSpace(PVPHAL_SURFACE pVpHalSurf, VAProcColorStandardType colorStandard, uint32_t flag)
1904 #else
1905 VAStatus DdiVp_GetColorSpace(PVPHAL_SURFACE pVpHalSurf, VAProcColorStandardType colorStandard, VAProcColorProperties colorProperties)
1906 #endif
1907 {
1908 uint8_t color_range = colorProperties.color_range;
1909
1910 pVpHalSurf->ColorSpace = CSpace_None;
1911
1912 VP_DDI_FUNCTION_ENTER;
1913
1914 // Convert VAProcColorStandardType to VPHAL_CSPACE
1915 if (IS_RGB_FORMAT(pVpHalSurf->Format) || (pVpHalSurf->Format == Format_P8))
1916 {
1917 switch (colorStandard)
1918 {
1919 case VAProcColorStandardBT2020:
1920 #if (VA_MAJOR_VERSION < 1)
1921 if (flag & VA_SOURCE_RANGE_FULL)
1922 #else
1923 if (color_range == VA_SOURCE_RANGE_FULL)
1924 #endif
1925 {
1926 pVpHalSurf->ColorSpace = CSpace_BT2020_RGB;
1927 }
1928 else
1929 {
1930 pVpHalSurf->ColorSpace = CSpace_BT2020_stRGB;
1931 }
1932 break;
1933 case VAProcColorStandardSTRGB:
1934 pVpHalSurf->ColorSpace = CSpace_stRGB;
1935 break;
1936 case VAProcColorStandardExplicit:
1937 VpSetColorStandardExplictly(pVpHalSurf, colorStandard, colorProperties);
1938 break;
1939 case VAProcColorStandardSRGB:
1940 default:
1941 pVpHalSurf->ColorSpace = CSpace_sRGB;
1942 break;
1943 }
1944 }
1945 else
1946 {
1947 // Set colorspace by default to avoid application don't set ColorStandard
1948 if (colorStandard == 0)
1949 {
1950 if ((pVpHalSurf->rcSrc.right - pVpHalSurf->rcSrc.left) <= 1280 && (pVpHalSurf->rcSrc.bottom - pVpHalSurf->rcSrc.top) <= 720)
1951 {
1952 pVpHalSurf->ColorSpace = CSpace_BT601;
1953 }//720p
1954 else if ((pVpHalSurf->rcSrc.right - pVpHalSurf->rcSrc.left) <= 1920 && (pVpHalSurf->rcSrc.bottom - pVpHalSurf->rcSrc.top) <= 1080)
1955 {
1956 pVpHalSurf->ColorSpace = CSpace_BT709;
1957 }//1080p
1958 else
1959 {
1960 if (pVpHalSurf->Format == Format_P010 || pVpHalSurf->Format == Format_P016)
1961 {
1962 pVpHalSurf->ColorSpace = CSpace_BT2020;
1963 }
1964 else
1965 {
1966 pVpHalSurf->ColorSpace = CSpace_BT709;
1967 }
1968 }//4K
1969 }
1970 else
1971 {
1972 switch (colorStandard)
1973 {
1974 case VAProcColorStandardBT709:
1975 #if (VA_MAJOR_VERSION < 1)
1976 if (flag & VA_SOURCE_RANGE_FULL)
1977 #else
1978 if (color_range == VA_SOURCE_RANGE_FULL)
1979 #endif
1980 {
1981 pVpHalSurf->ColorSpace = CSpace_BT709_FullRange;
1982 }
1983 else
1984 {
1985 pVpHalSurf->ColorSpace = CSpace_BT709;
1986 }
1987 break;
1988 case VAProcColorStandardBT601:
1989 #if (VA_MAJOR_VERSION < 1)
1990 if (flag & VA_SOURCE_RANGE_FULL)
1991 #else
1992 if (color_range == VA_SOURCE_RANGE_FULL)
1993 #endif
1994 {
1995 pVpHalSurf->ColorSpace = CSpace_BT601_FullRange;
1996 }
1997 else
1998 {
1999 pVpHalSurf->ColorSpace = CSpace_BT601;
2000 }
2001 break;
2002 case VAProcColorStandardBT2020:
2003 #if (VA_MAJOR_VERSION < 1)
2004 if (flag & VA_SOURCE_RANGE_FULL)
2005 #else
2006 if (color_range == VA_SOURCE_RANGE_FULL)
2007 #endif
2008 {
2009 pVpHalSurf->ColorSpace = CSpace_BT2020_FullRange;
2010 }
2011 else
2012 {
2013 pVpHalSurf->ColorSpace = CSpace_BT2020;
2014 }
2015 break;
2016 case VAProcColorStandardBT470M:
2017 case VAProcColorStandardBT470BG:
2018 case VAProcColorStandardSMPTE170M:
2019 case VAProcColorStandardSMPTE240M:
2020 case VAProcColorStandardGenericFilm:
2021 case VAProcColorStandardXVYCC601:
2022 case VAProcColorStandardXVYCC709:
2023 pVpHalSurf->ColorSpace == CSpace_None;
2024 break;
2025 case VAProcColorStandardExplicit:
2026 VpSetColorStandardExplictly(pVpHalSurf, colorStandard, colorProperties);
2027 break;
2028 default:
2029 pVpHalSurf->ColorSpace == CSpace_BT601;
2030 break;
2031 }
2032 }
2033 }
2034 DDI_CHK_CONDITION((pVpHalSurf->ColorSpace == CSpace_None), "Invalid color standard", VA_STATUS_ERROR_INVALID_PARAMETER);
2035
2036 return VA_STATUS_SUCCESS;
2037 }
2038
2039
2040 //////////////////////////////////////////////////////////////////////////////////////////////
2041 //! \purpose Get ColorSpace from the media format
2042 //! \params
2043 //! [in] format : media format
2044 //! [out] None
2045 //! \returns appropriate VPHAL_CSPACE if call succeeds, CSpace_None otherwise
2046 /////////////////////////////////////////////////////////////////////////////////////////////
2047 VPHAL_CSPACE DdiVp_GetColorSpaceFromMediaFormat(DDI_MEDIA_FORMAT format)
2048 {
2049 MOS_FORMAT mosFormat = VpGetFormatFromMediaFormat(format);
2050
2051 if (IS_RGB_FORMAT(mosFormat))
2052 {
2053 return CSpace_sRGB;
2054 }
2055 else
2056 {
2057 return CSpace_BT601;
2058 }
2059 }
2060
2061 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2062 //! \purpose Extract Render Target params from VAProcPipelineParameterBuffer and set the appropriate VPHAL params for RT
2063 //! \params
2064 //! [in] pVaDrvCtx : VA Driver context
2065 //! [in] pVpCtx : VP context
2066 //! [in] pPipelineParam : VAProcPipelineParameterBuffer Pipeline paramseter from application
2067 //! [out] None
2068 //! \returns VA_STATUS_SUCCESS if call succeeds
2069 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2070 VAStatus
2071 DdiVp_UpdateVphalTargetSurfColorSpace(
2072 VADriverContextP pVaDrvCtx,
2073 PDDI_VP_CONTEXT pVpCtx,
2074 VAProcPipelineParameterBuffer* pPipelineParam,
2075 uint32_t targetIndex)
2076 {
2077 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2078 PVPHAL_SURFACE pVpHalSrcSurf;
2079 PVPHAL_SURFACE pVpHalTgtSurf;
2080 VAStatus vaStatus;
2081 DDI_UNUSED(pVaDrvCtx);
2082
2083 VP_DDI_FUNCTION_ENTER;
2084 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2085
2086 // initialize
2087 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2088 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2089 pVpHalTgtSurf = pVpHalRenderParams->pTarget[targetIndex];
2090 DDI_CHK_NULL(pVpHalTgtSurf, "Null pVpHalTgtSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
2091
2092 // update target surface color space
2093 #if (VA_MAJOR_VERSION < 1)
2094 vaStatus = DdiVp_GetColorSpace(pVpHalTgtSurf, pPipelineParam->output_color_standard, pPipelineParam->output_surface_flag);
2095 #else
2096 vaStatus = DdiVp_GetColorSpace(pVpHalTgtSurf, pPipelineParam->output_color_standard, pPipelineParam->output_color_properties);
2097 #endif
2098
2099 pVpHalSrcSurf = pVpHalRenderParams->pSrc[0];
2100 // Not support BT601/BT709 -> BT2020 colorspace conversion, if colorspace is not set, will keep it same with input.
2101 if(pVpHalSrcSurf != nullptr &&
2102 pPipelineParam->output_color_standard == 0 &&
2103 IS_COLOR_SPACE_BT2020(pVpHalTgtSurf->ColorSpace) &&
2104 !IS_COLOR_SPACE_BT2020(pVpHalSrcSurf->ColorSpace))
2105 {
2106 pVpHalTgtSurf->ColorSpace = pVpHalSrcSurf->ColorSpace;
2107 }
2108
2109 // extended gamut?
2110 pVpHalRenderParams->pTarget[0]->ExtendedGamut = false;
2111
2112 return vaStatus;
2113 }
2114
2115 //////////////////////////////////////////////////////////////////////////////////////////////
2116 //! \purpose Setup the appropriate filter params for VPHAL input surface based on Filter type
2117 //! \params
2118 //! [in] pVaDrvCtx : Driver context
2119 //! [in] pVpCtx : VP context
2120 //! [in] uSurfIndex : uSurfIndex to the input surface array
2121 //! [in] FilterType : Filter type
2122 //! [in] pData : Buffer data
2123 //! [in] uElementNum : number of elements in the buffer(FilterParameter)
2124 //! [in] vpStateFlags : filter enable status
2125 //! [out] None
2126 //! \returns VA_STATUS_SUCCESS if call succeeds
2127 //////////////////////////////////////////////////////////////////////////////////////////////
2128 VAStatus
2129 DdiVp_UpdateFilterParamBuffer(
2130 VADriverContextP pVaDrvCtx,
2131 PDDI_VP_CONTEXT pVpCtx,
2132 uint32_t uSurfIndex,
2133 int32_t FilterType,
2134 void *pData,
2135 uint32_t uElementNum,
2136 DDI_VP_STATE* vpStateFlags)
2137 {
2138 VAStatus vaStatus;
2139
2140 VP_DDI_FUNCTION_ENTER;
2141 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2142
2143 vaStatus = VA_STATUS_SUCCESS;
2144
2145 switch (FilterType){
2146 case VAProcFilterDeinterlacing:
2147 vpStateFlags->bDeinterlaceEnable = true;
2148 vaStatus = DdiVp_SetProcFilterDinterlaceParams(
2149 pVpCtx,
2150 uSurfIndex,
2151 (VAProcFilterParameterBufferDeinterlacing*) pData);
2152 break;
2153 case VAProcFilterNoiseReduction:
2154 vpStateFlags->bDenoiseEnable = true;
2155 vaStatus = DdiVp_SetProcFilterDenoiseParams(
2156 pVpCtx,
2157 uSurfIndex,
2158 (VAProcFilterParameterBuffer*) pData);
2159 break;
2160 case VAProcFilterHVSNoiseReduction:
2161 vpStateFlags->bDenoiseEnable = true;
2162 vaStatus = DdiVp_SetProcFilterHVSDenoiseParams(
2163 pVpCtx,
2164 uSurfIndex,
2165 (VAProcFilterParameterBufferHVSNoiseReduction*) pData);
2166 break;
2167 case VAProcFilterSharpening:
2168 vpStateFlags->bIEFEnable = true;
2169 vaStatus = DdiVp_SetProcFilterSharpnessParams(
2170 pVpCtx,
2171 uSurfIndex,
2172 (VAProcFilterParameterBuffer*) pData);
2173 break;
2174 case VAProcFilterColorBalance:
2175 vpStateFlags->bProcampEnable = true;
2176 vaStatus = DdiVp_SetProcFilterColorBalanceParams(
2177 pVpCtx,
2178 uSurfIndex,
2179 (VAProcFilterParameterBufferColorBalance*) pData,
2180 uElementNum);
2181 break;
2182 case VAProcFilterSkinToneEnhancement:
2183 vaStatus = DdiVp_SetProcFilterSkinToneEnhancementParams(
2184 pVpCtx,
2185 uSurfIndex,
2186 (VAProcFilterParameterBuffer*) pData);
2187 break;
2188 case VAProcFilterTotalColorCorrection:
2189 vaStatus = DdiVp_SetProcFilterTotalColorCorrectionParams(
2190 pVpCtx,
2191 uSurfIndex,
2192 (VAProcFilterParameterBufferTotalColorCorrection*) pData,
2193 uElementNum);
2194 break;
2195 case VAProcFilterHighDynamicRangeToneMapping:
2196 vaStatus = DdiVp_SetProcFilterHdrTmParams(
2197 pVpCtx,
2198 uSurfIndex,
2199 (VAProcFilterParameterBufferHDRToneMapping*) pData);
2200 break;
2201 #if VA_CHECK_VERSION(1, 12, 0)
2202 case VAProcFilter3DLUT:
2203 vaStatus = DdiVp_SetProcFilter3DLutParams(
2204 pVaDrvCtx,
2205 pVpCtx,
2206 uSurfIndex,
2207 (VAProcFilterParameterBuffer3DLUT*) pData);
2208 break;
2209 #endif
2210 case VAProcFilterNone:
2211 vaStatus = VA_STATUS_ERROR_INVALID_PARAMETER;
2212 break;
2213 default:
2214 VP_DDI_ASSERTMESSAGE("VAProcFilterType is unknown.");
2215 vaStatus = VA_STATUS_ERROR_UNSUPPORTED_FILTER;
2216 break;
2217 }// switch (type)
2218
2219 return vaStatus;
2220 }
2221
2222 //////////////////////////////////////////////////////////////////////////////////////////////
2223 //! \purpose clear filter params which is disabled for VPHAL input surface
2224 //! \params
2225 //! [in] pVpCtx : VP context
2226 //! [in] uSurfIndex : uSurfIndex to the input surface array
2227 //! [in] vpStateFlags : filter enable status
2228 //! [out] None
2229 //! \returns VA_STATUS_SUCCESS if call succeeds
2230 //////////////////////////////////////////////////////////////////////////////////////////////
2231 VAStatus DdiVp_ClearFilterParamBuffer(
2232 PDDI_VP_CONTEXT pVpCtx,
2233 uint32_t uSurfIndex,
2234 DDI_VP_STATE vpStateFlags)
2235 {
2236 if(!vpStateFlags.bProcampEnable)
2237 {
2238 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pProcampParams);
2239 }
2240 if(!vpStateFlags.bDeinterlaceEnable)
2241 {
2242 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pDeinterlaceParams);
2243 }
2244 if(!vpStateFlags.bDenoiseEnable)
2245 {
2246 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pDenoiseParams);
2247 }
2248 if(!vpStateFlags.bIEFEnable)
2249 {
2250 if (pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pIEFParams)
2251 {
2252 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pIEFParams->pExtParam);
2253 MOS_FreeMemAndSetNull(pVpCtx->pVpHalRenderParams->pSrc[uSurfIndex]->pIEFParams);
2254 }
2255 }
2256
2257 return VA_STATUS_SUCCESS;
2258 }
2259
2260 ////////////////////////////////////////////////////////////////////////////////
2261 //! \purpose Set DI filter params for input VPHAL surface
2262 //! \params
2263 //! [in] pVpCtx : VP context
2264 //! [in] uSurfIndex : uSurfIndex to the input surface array
2265 //! [in] pDiParamBuff : Pointer to DI param buffer data
2266 //! [out] None
2267 //! \returns VA_STATUS_SUCCESS if call succeeds
2268 ////////////////////////////////////////////////////////////////////////////////
2269 VAStatus
2270 DdiVp_SetProcFilterDinterlaceParams(
2271 PDDI_VP_CONTEXT pVpCtx,
2272 uint32_t uSurfIndex,
2273 VAProcFilterParameterBufferDeinterlacing* pDiParamBuff)
2274 {
2275 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2276 PVPHAL_SURFACE pTarget;
2277 PVPHAL_SURFACE pSrc;
2278 VPHAL_DI_MODE DIMode;
2279
2280 VP_DDI_FUNCTION_ENTER;
2281 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2282 DDI_CHK_NULL(pDiParamBuff,
2283 "Null pDiParamBuff.",
2284 VA_STATUS_ERROR_INVALID_BUFFER);
2285
2286 // initialize
2287 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2288 DDI_CHK_NULL(pVpHalRenderParams,
2289 "Null pVpHalRenderParams.",
2290 VA_STATUS_ERROR_INVALID_PARAMETER);
2291
2292 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2293 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2294 pTarget = pVpHalRenderParams->pTarget[0];
2295 DDI_CHK_NULL(pTarget, "Null pTarget.", VA_STATUS_ERROR_INVALID_SURFACE);
2296
2297 switch (pDiParamBuff->algorithm)
2298 {
2299 case VAProcDeinterlacingBob:
2300 DIMode = DI_MODE_BOB;
2301 break;
2302 case VAProcDeinterlacingMotionAdaptive:
2303 case VAProcDeinterlacingMotionCompensated:
2304 DIMode = DI_MODE_ADI;
2305 break;
2306 case VAProcDeinterlacingWeave:
2307 pSrc->bFieldWeaving = true;;
2308 return VA_STATUS_SUCCESS;
2309 case VAProcDeinterlacingNone:
2310 return VA_STATUS_SUCCESS;
2311 default:
2312 VP_DDI_ASSERTMESSAGE("Deinterlacing type is unsupported.");
2313 return VA_STATUS_ERROR_UNIMPLEMENTED;
2314 }// switch (pDiParamBuff->algorithm)
2315
2316 if (nullptr == pSrc->pDeinterlaceParams)
2317 {
2318 pSrc->pDeinterlaceParams = (PVPHAL_DI_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_DI_PARAMS));
2319 DDI_CHK_NULL(pSrc->pDeinterlaceParams, "pSrc->pDeinterlaceParams is NULL", VA_STATUS_ERROR_ALLOCATION_FAILED);
2320 }
2321
2322 if (nullptr == pTarget->pDeinterlaceParams)
2323 {
2324 pTarget->pDeinterlaceParams = (PVPHAL_DI_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_DI_PARAMS));
2325 DDI_CHK_NULL(pTarget->pDeinterlaceParams, "pTarget->pDeinterlaceParams is NULL", VA_STATUS_ERROR_ALLOCATION_FAILED);
2326 }
2327 //application detect scene change and then pass parameter to driver.
2328 if (pDiParamBuff->flags & VA_DEINTERLACING_SCD_ENABLE)
2329 {
2330 DIMode = DI_MODE_BOB;
2331 pSrc->pDeinterlaceParams->bSCDEnable = true;
2332 }
2333 else
2334 {
2335 pSrc->pDeinterlaceParams->bSCDEnable = false;
2336 }
2337
2338 pSrc->pDeinterlaceParams->DIMode = DIMode;
2339
2340 pSrc->pDeinterlaceParams->bSingleField = (pDiParamBuff->flags & VA_DEINTERLACING_ONE_FIELD) ? true : false;
2341
2342 pSrc->pDeinterlaceParams->bEnableFMD = (pDiParamBuff->flags & VA_DEINTERLACING_FMD_ENABLE) ? true : false;
2343
2344 //update sample type
2345 if (pDiParamBuff->flags & VA_DEINTERLACING_BOTTOM_FIELD_FIRST)
2346 {
2347 if (pDiParamBuff->flags & VA_DEINTERLACING_BOTTOM_FIELD)
2348 {
2349 pSrc->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
2350 }
2351 else
2352 {
2353 pSrc->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_TOP_FIELD;
2354 }
2355 }
2356 else
2357 {
2358 if (pDiParamBuff->flags & VA_DEINTERLACING_BOTTOM_FIELD)
2359 {
2360 pSrc->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_BOTTOM_FIELD;
2361 }
2362 else
2363 {
2364 pSrc->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
2365 }
2366 }
2367
2368 if (pSrc->pDeinterlaceParams->DIMode == DI_MODE_ADI)
2369 {
2370 //When pBwdRef is not nullptr and uBwdRefCount is nonzero, ADI can use Bwd Ref frame.
2371 //Otherwise, ADI shouldn't use Bwd Ref frame.
2372 if (pSrc->uBwdRefCount && pSrc->pBwdRef != nullptr)
2373 {
2374 pSrc->uBwdRefCount = 1;
2375
2376 //When the bo of the current frame's SRC and reference are same with previous frame's,
2377 //we should set the frame ID same as previous frame's setting.
2378 if ( pVpCtx->FrameIDTracer.pLastSrcSurfBo == pSrc->OsResource.bo &&
2379 pVpCtx->FrameIDTracer.pLastBwdSurfBo == pSrc->pBwdRef->OsResource.bo &&
2380 pVpCtx->FrameIDTracer.uiLastSampleType != pSrc->SampleType)
2381 {
2382 pSrc->FrameID = pVpCtx->FrameIDTracer.uiLastSrcSurfFrameID;
2383 pSrc->pBwdRef->FrameID = pVpCtx->FrameIDTracer.uiLastBwdSurfFrameID;
2384 }
2385 //Otherwise, we should update the values of frame ID and FrameID tracer.
2386 else
2387 {
2388 pSrc->pBwdRef->FrameID = (VP_SETTING_SAME_SAMPLE_THRESHOLD + 1) * pVpCtx->FrameIDTracer.uiFrameIndex;
2389 pSrc->FrameID = pSrc->pBwdRef->FrameID + ( VP_SETTING_SAME_SAMPLE_THRESHOLD + 1);
2390
2391 pVpCtx->FrameIDTracer.pLastSrcSurfBo = pSrc->OsResource.bo;
2392 pVpCtx->FrameIDTracer.pLastBwdSurfBo = pSrc->pBwdRef->OsResource.bo;
2393
2394 pVpCtx->FrameIDTracer.uiLastSrcSurfFrameID = pSrc->FrameID;
2395 pVpCtx->FrameIDTracer.uiLastBwdSurfFrameID = pSrc->pBwdRef->FrameID;
2396
2397 pVpCtx->FrameIDTracer.uiLastSampleType = pSrc->SampleType;
2398 }
2399 }
2400 else
2401 {
2402 //ADI no reference frame driver only care EVEN/ODD
2403 if (pDiParamBuff->flags & VA_DEINTERLACING_BOTTOM_FIELD)
2404 {
2405 pSrc->SampleType = SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD;
2406 }
2407 else
2408 {
2409 pSrc->SampleType = SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD;
2410 }
2411 }
2412
2413 //int32_t overflow process
2414 pVpCtx->FrameIDTracer.uiFrameIndex = (pVpCtx->FrameIDTracer.uiFrameIndex + 1 == INT_MAX) ? 1 : pVpCtx->FrameIDTracer.uiFrameIndex + 1;
2415 }
2416
2417 return VA_STATUS_SUCCESS;
2418 }
2419
2420 ////////////////////////////////////////////////////////////////////////////////
2421 //! \purpose Set DN filter params for VPHAL input surface
2422 //! \params
2423 //! [in] pVpCtx : VP context
2424 //! [in] uSurfIndex : uSurfIndex to the input surface array
2425 //! [in] pDnParamBuff : Pointer to DN param buffer data
2426 //! [out] None
2427 //! \returns VA_STATUS_SUCCESS if call succeeds
2428 ////////////////////////////////////////////////////////////////////////////////
2429 VAStatus
2430 DdiVp_SetProcFilterDenoiseParams(
2431 PDDI_VP_CONTEXT pVpCtx,
2432 uint32_t uSurfIndex,
2433 VAProcFilterParameterBuffer* pDnParamBuff)
2434 {
2435 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2436 PVPHAL_SURFACE pSrc;
2437
2438 VP_DDI_FUNCTION_ENTER;
2439 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2440
2441 // initialize
2442 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2443 DDI_CHK_NULL(pVpHalRenderParams,
2444 "Null pVpHalRenderParams.",
2445 VA_STATUS_ERROR_INVALID_PARAMETER);
2446 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2447 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2448
2449 if (nullptr == pSrc->pDenoiseParams)
2450 {
2451 pSrc->pDenoiseParams = (PVPHAL_DENOISE_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_DENOISE_PARAMS));
2452 }
2453 DDI_CHK_NULL(pSrc->pDenoiseParams, "pDenoiseParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2454
2455 // denoise caps range is from 0 to 64, out of range parameter is treated as an error
2456 if (pDnParamBuff->value < NOISEREDUCTION_MIN || pDnParamBuff->value > NOISEREDUCTION_MAX)
2457 {
2458 return VA_STATUS_ERROR_INVALID_PARAMETER;
2459 }
2460
2461 pSrc->pDenoiseParams->fDenoiseFactor = pDnParamBuff->value;
2462
2463 // Luma and chroma denoise should be always enabled when noise reduction is needed
2464 pSrc->pDenoiseParams->bEnableLuma = true;
2465 pSrc->pDenoiseParams->bEnableChroma = true;
2466 pSrc->pDenoiseParams->bAutoDetect = false;
2467 pSrc->pDenoiseParams->NoiseLevel = NOISELEVEL_DEFAULT;
2468
2469 return VA_STATUS_SUCCESS;
2470 }
2471
2472 ////////////////////////////////////////////////////////////////////////////////
2473 //! \purpose Set DN filter params for VPHAL input surface
2474 //! \params
2475 //! [in] pVpCtx : VP context
2476 //! [in] uSurfIndex : uSurfIndex to the input surface array
2477 //! [in] pDnParamBuff : Pointer to DN param buffer data
2478 //! [out] None
2479 //! \returns VA_STATUS_SUCCESS if call succeeds
2480 ////////////////////////////////////////////////////////////////////////////////
2481 VAStatus
2482 DdiVp_SetProcFilterHVSDenoiseParams(
2483 PDDI_VP_CONTEXT pVpCtx,
2484 uint32_t uSurfIndex,
2485 VAProcFilterParameterBufferHVSNoiseReduction* pHVSDnParamBuff)
2486 {
2487 PVPHAL_RENDER_PARAMS pVpHalRenderParams = nullptr;
2488 PVPHAL_SURFACE pSrc = nullptr;
2489
2490 VP_DDI_FUNCTION_ENTER;
2491 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2492 DDI_CHK_NULL(pHVSDnParamBuff,
2493 "Null pHVSDnParamBuff.",
2494 VA_STATUS_ERROR_INVALID_PARAMETER);
2495
2496 // initialize
2497 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2498 DDI_CHK_NULL(pVpHalRenderParams,
2499 "Null pVpHalRenderParams.",
2500 VA_STATUS_ERROR_INVALID_PARAMETER);
2501 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2502 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2503
2504 if (nullptr == pSrc->pDenoiseParams)
2505 {
2506 pSrc->pDenoiseParams = (PVPHAL_DENOISE_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_DENOISE_PARAMS));
2507 }
2508 DDI_CHK_NULL(pSrc->pDenoiseParams, "pDenoiseParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2509
2510 // Luma and chroma denoise should be always enabled when noise reduction is needed
2511 pSrc->pDenoiseParams->bEnableLuma = true;
2512 pSrc->pDenoiseParams->bEnableChroma = true;
2513 pSrc->pDenoiseParams->bEnableHVSDenoise = true;
2514
2515 switch (pHVSDnParamBuff->mode)
2516 {
2517 case VA_PROC_HVS_DENOISE_AUTO_SUBJECTIVE:
2518 pSrc->pDenoiseParams->HVSDenoise.Mode = HVSDENOISE_AUTO_SUBJECTIVE;
2519 pSrc->pDenoiseParams->bAutoDetect = true;
2520 break;
2521 case VA_PROC_HVS_DENOISE_MANUAL:
2522 pSrc->pDenoiseParams->HVSDenoise.Mode = HVSDENOISE_MANUAL;
2523 break;
2524 case VA_PROC_HVS_DENOISE_DEFAULT:
2525 case VA_PROC_HVS_DENOISE_AUTO_BDRATE:
2526 default:
2527 pSrc->pDenoiseParams->HVSDenoise.Mode = HVSDENOISE_AUTO_BDRATE;
2528 pSrc->pDenoiseParams->bAutoDetect = true;
2529 }// switch (pHVSDnParamBuff->mode)
2530
2531 if (pSrc->pDenoiseParams->HVSDenoise.Mode == HVSDENOISE_AUTO_BDRATE)
2532 {
2533 pSrc->pDenoiseParams->HVSDenoise.QP = pHVSDnParamBuff->qp;
2534 if (pSrc->pDenoiseParams->HVSDenoise.QP == 0)
2535 {
2536 //If didn't set value, HVS Auto Bdrate Mode default qp 27
2537 pSrc->pDenoiseParams->HVSDenoise.QP = 27;
2538 }
2539 }
2540 else if (pSrc->pDenoiseParams->HVSDenoise.Mode == HVSDENOISE_AUTO_SUBJECTIVE)
2541 {
2542 //HVS Subjective Mode default qp 32
2543 pSrc->pDenoiseParams->HVSDenoise.QP = 32;
2544 }
2545 else
2546 {
2547 pSrc->pDenoiseParams->HVSDenoise.QP = 32;
2548 pSrc->pDenoiseParams->HVSDenoise.Strength = pHVSDnParamBuff->strength;
2549 }
2550
2551 VP_DDI_NORMALMESSAGE("HVS Denoise is enabled with qp %d, strength %d, mode %d!", pSrc->pDenoiseParams->HVSDenoise.QP, pSrc->pDenoiseParams->HVSDenoise.Strength, pSrc->pDenoiseParams->HVSDenoise.Mode);
2552
2553 return VA_STATUS_SUCCESS;
2554 }
2555 /////////////////////////////////////////////////////////////////////////////////////////////////
2556 //! \purpose Set Sharpness (Image Enhancement Filter, IEF) filter params for VPHAL input surface
2557 //! \params
2558 //! [in] pVpCtx : VP context
2559 //! [in] uSurfIndex : uSurfIndex to the input surface array
2560 //! [in] pDnParamBuff : Pointer to Sharpness param buffer data
2561 //! [out] None
2562 //! \returns VA_STATUS_SUCCESS if call succeeds
2563 //////////////////////////////////////////////////////////////////////////////////////////////////
2564 VAStatus
2565 DdiVp_SetProcFilterSharpnessParams(
2566 PDDI_VP_CONTEXT pVpCtx,
2567 uint32_t uSurfIndex,
2568 VAProcFilterParameterBuffer* pSharpParamBuff)
2569 {
2570 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2571 PVPHAL_SURFACE pSrc;
2572
2573 VP_DDI_FUNCTION_ENTER;
2574 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2575 DDI_CHK_NULL(pSharpParamBuff, "Null pSharpParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2576
2577 // initialize
2578 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2579 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2580 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2581 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2582
2583 if (nullptr == pSrc->pIEFParams)
2584 {
2585 pSrc->pIEFParams = (PVPHAL_IEF_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_IEF_PARAMS));
2586 DDI_CHK_NULL(pSrc->pIEFParams, "pIEFParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2587 }
2588
2589 // out of range parameter is treated as an error
2590 if (pSharpParamBuff->value < EDGEENHANCEMENT_MIN || pSharpParamBuff->value > EDGEENHANCEMENT_MAX)
2591 {
2592 return VA_STATUS_ERROR_INVALID_PARAMETER;
2593 }
2594
2595 // sharpness option
2596 // setting with hard code in mplayer side.
2597 // refer to sharpening section of render_picture_vp() defined in vaapi.c.
2598 // change flag and factor for testing.
2599 VpHal_DdiInitIEFParams(pSrc->pIEFParams);
2600 pSrc->bIEF = true;
2601 pSrc->pIEFParams->bEnabled = true;
2602 pSrc->pIEFParams->fIEFFactor = pSharpParamBuff->value;
2603
2604 return VA_STATUS_SUCCESS;
2605 }
2606
2607 ////////////////////////////////////////////////////////////////////////////////
2608 //! \purpose Set Color Balance (procamp) filter params for VPHAL input surface
2609 //! \params
2610 //! [in] pVpCtx : VP context
2611 //! [in] uSurfIndex : uSurfIndex to the input surface array
2612 //! [in] pColorBalanceParamBuff : Pointer to Colorbalance param buffer data
2613 //! [in] uElementNum : number of elements in the Colorbalance param buffer data
2614 //! [out] None
2615 //! \returns VA_STATUS_SUCCESS if call succeeds
2616 ////////////////////////////////////////////////////////////////////////////////
2617 VAStatus
2618 DdiVp_SetProcFilterColorBalanceParams(
2619 PDDI_VP_CONTEXT pVpCtx,
2620 uint32_t uSurfIndex,
2621 VAProcFilterParameterBufferColorBalance* pColorBalanceParamBuff,
2622 uint32_t uElementNum)
2623 {
2624 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2625 PVPHAL_SURFACE pSrc;
2626 uint32_t i;
2627 bool bProcamp;
2628
2629 VP_DDI_FUNCTION_ENTER;
2630 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
2631 DDI_CHK_NULL(pColorBalanceParamBuff,
2632 "Null pColorBalanceParamBuff.",
2633 VA_STATUS_ERROR_INVALID_BUFFER);
2634
2635 // initialize
2636 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2637 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2638 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2639 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2640
2641 bProcamp = false;
2642 for (i = 0; i < uElementNum; i++)
2643 {
2644 if ((VAProcColorBalanceHue == pColorBalanceParamBuff[i].attrib) ||
2645 (VAProcColorBalanceSaturation == pColorBalanceParamBuff[i].attrib) ||
2646 (VAProcColorBalanceBrightness == pColorBalanceParamBuff[i].attrib) ||
2647 (VAProcColorBalanceContrast == pColorBalanceParamBuff[i].attrib))
2648 {
2649 bProcamp = true;
2650 break;
2651 }
2652 }
2653
2654 if (nullptr == pSrc->pProcampParams &&
2655 true == bProcamp)
2656 {
2657 pSrc->pProcampParams = (PVPHAL_PROCAMP_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_PROCAMP_PARAMS));
2658 DDI_CHK_NULL(pSrc->pProcampParams, "Source pProcampParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2659 }
2660
2661 if (nullptr == pVpHalRenderParams->pTarget[0]->pProcampParams)
2662 {
2663 pVpHalRenderParams->pTarget[0]->pProcampParams = (PVPHAL_PROCAMP_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_PROCAMP_PARAMS));
2664 DDI_CHK_NULL(pVpHalRenderParams->pTarget[0]->pProcampParams, "Target pProcampParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2665 }
2666
2667 // Needed for ACE
2668 if (nullptr == pSrc->pColorPipeParams &&
2669 SURF_IN_PRIMARY == pSrc->SurfType)
2670 {
2671 pSrc->pColorPipeParams = (PVPHAL_COLORPIPE_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_COLORPIPE_PARAMS));
2672 DDI_CHK_NULL(pSrc->pColorPipeParams, "pColorPipeParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2673 }
2674
2675 // set default value
2676 if (nullptr != pSrc->pProcampParams)
2677 {
2678 pSrc->pProcampParams->fHue = PROCAMP_HUE_DEFAULT;
2679 pSrc->pProcampParams->fSaturation = PROCAMP_SATURATION_DEFAULT;
2680 pSrc->pProcampParams->fBrightness = PROCAMP_BRIGHTNESS_DEFAULT;
2681 pSrc->pProcampParams->fContrast = PROCAMP_CONTRAST_DEFAULT;
2682 }
2683
2684 for (i = 0; i < uElementNum; i++)
2685 {
2686 switch (pColorBalanceParamBuff[i].attrib)
2687 {
2688 case VAProcColorBalanceHue:
2689 if (pColorBalanceParamBuff[i].value < PROCAMP_HUE_MIN || pColorBalanceParamBuff[i].value > PROCAMP_HUE_MAX)
2690 {
2691 VP_DDI_ASSERTMESSAGE("%d: Hue is out of bounds.", i);
2692 return VA_STATUS_ERROR_INVALID_PARAMETER;
2693 }
2694 if (true == bProcamp)
2695 {
2696 pSrc->pProcampParams->bEnabled = true;
2697 pSrc->pProcampParams->fHue = pColorBalanceParamBuff[i].value;
2698 }
2699 break;
2700 case VAProcColorBalanceSaturation:
2701 if (pColorBalanceParamBuff[i].value < PROCAMP_SATURATION_MIN || pColorBalanceParamBuff[i].value > PROCAMP_SATURATION_MAX)
2702 {
2703 VP_DDI_ASSERTMESSAGE("%d: Saturation is out of bounds.", i);
2704 return VA_STATUS_ERROR_INVALID_PARAMETER;
2705 }
2706 if (true == bProcamp)
2707 {
2708 pSrc->pProcampParams->bEnabled = true;
2709 pSrc->pProcampParams->fSaturation = pColorBalanceParamBuff[i].value;
2710 }
2711 break;
2712 case VAProcColorBalanceBrightness:
2713 if (pColorBalanceParamBuff[i].value < PROCAMP_BRIGHTNESS_MIN || pColorBalanceParamBuff[i].value > PROCAMP_BRIGHTNESS_MAX)
2714 {
2715 VP_DDI_ASSERTMESSAGE("%d: Brightness is out of bounds.", i);
2716 return VA_STATUS_ERROR_INVALID_PARAMETER;
2717 }
2718 if (true == bProcamp)
2719 {
2720 pSrc->pProcampParams->bEnabled = true;
2721 pSrc->pProcampParams->fBrightness = pColorBalanceParamBuff[i].value;
2722 }
2723 break;
2724 case VAProcColorBalanceContrast:
2725 if (pColorBalanceParamBuff[i].value < PROCAMP_CONTRAST_MIN || pColorBalanceParamBuff[i].value > PROCAMP_CONTRAST_MAX)
2726 {
2727 VP_DDI_ASSERTMESSAGE("%d: Contrast is out of bounds.", i);
2728 return VA_STATUS_ERROR_INVALID_PARAMETER;
2729 }
2730 if (true == bProcamp)
2731 {
2732 pSrc->pProcampParams->bEnabled = true;
2733 pSrc->pProcampParams->fContrast = pColorBalanceParamBuff[i].value;
2734 }
2735 break;
2736 case VAProcColorBalanceAutoContrast:
2737 if (SURF_IN_PRIMARY == pSrc->SurfType)
2738 {
2739 pSrc->pColorPipeParams->bEnableACE = true;
2740 pSrc->pColorPipeParams->dwAceLevel = ACE_LEVEL_DEFAULT;
2741 pSrc->pColorPipeParams->dwAceStrength = ACE_STRENGTH_DEFAULT;
2742 }
2743 break;
2744 case VAProcColorBalanceAutoSaturation:
2745 case VAProcColorBalanceAutoBrightness:
2746 return VA_STATUS_ERROR_UNIMPLEMENTED;
2747 case VAProcColorBalanceNone:
2748 case VAProcColorBalanceCount:
2749 default:
2750 VP_DDI_ASSERTMESSAGE("pColorBalanceParamBuff[%d].attrib is unknown.", i);
2751 return VA_STATUS_ERROR_INVALID_PARAMETER;
2752 }// switch (attrib)
2753 }
2754
2755 return VA_STATUS_SUCCESS;
2756 }
2757
2758 /////////////////////////////////////////////////////////////////////////////////////////////////
2759 //! \purpose Set Skin Tone Enhancement (STE) filter params for VPHAL input surface
2760 //! \params
2761 //! [in] pVpCtx : VP context
2762 //! [in] uSurfIndex : uSurfIndex to the input surface array
2763 //! [in] pSTEParamBuff : Pointer to Skin Tone Enhancement param buffer data
2764 //! [out] None
2765 //! \returns VA_STATUS_SUCCESS if call succeeds
2766 //////////////////////////////////////////////////////////////////////////////////////////////////
2767 VAStatus
2768 DdiVp_SetProcFilterSkinToneEnhancementParams(
2769 PDDI_VP_CONTEXT pVpCtx,
2770 uint32_t uSurfIndex,
2771 VAProcFilterParameterBuffer* pSTEParamBuff)
2772 {
2773 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2774 PVPHAL_SURFACE pSrc;
2775
2776 VP_DDI_FUNCTION_ENTER;
2777 DDI_CHK_NULL(pSTEParamBuff, "Null pSTEParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2778
2779 // initialize
2780 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2781 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2782 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2783 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2784
2785 if (SURF_IN_PRIMARY == pSrc->SurfType)
2786 {
2787 if (nullptr == pSrc->pColorPipeParams)
2788 {
2789 pSrc->pColorPipeParams = (PVPHAL_COLORPIPE_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_COLORPIPE_PARAMS));
2790 DDI_CHK_NULL(pSrc->pColorPipeParams, "pColorPipeParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2791 }
2792
2793 // out of range parameter is treated as an error
2794 if (pSTEParamBuff->value < STE_MIN || pSTEParamBuff->value > STE_MAX)
2795 {
2796 return VA_STATUS_ERROR_INVALID_PARAMETER;
2797 }
2798
2799 pSrc->pColorPipeParams->bEnableSTE = true;
2800 pSrc->pColorPipeParams->SteParams.dwSTEFactor = (uint32_t)pSTEParamBuff->value;
2801 }
2802
2803 return VA_STATUS_SUCCESS;
2804 }
2805
2806 /////////////////////////////////////////////////////////////////////////////////////////////////
2807 //! \purpose Total Color Correction (TCC) filter params for VPHAL input surface
2808 //! \params
2809 //! [in] pVpCtx : VP context
2810 //! [in] uSurfIndex : uSurfIndex to the input surface array
2811 //! [in] pTCCParamBuff : Pointer to Total Color Correction param buffer data
2812 //! [in] uElementNum : number of elements in the Total Color Correction param buffer data
2813 //! [out] None
2814 //! \returns VA_STATUS_SUCCESS if call succeeds
2815 //////////////////////////////////////////////////////////////////////////////////////////////////
2816 VAStatus
2817 DdiVp_SetProcFilterTotalColorCorrectionParams(
2818 PDDI_VP_CONTEXT pVpCtx,
2819 uint32_t uSurfIndex,
2820 VAProcFilterParameterBufferTotalColorCorrection* pTCCParamBuff,
2821 uint32_t uElementNum)
2822 {
2823 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
2824 PVPHAL_SURFACE pSrc;
2825 uint32_t i;
2826
2827 VP_DDI_FUNCTION_ENTER;
2828 DDI_CHK_NULL(pTCCParamBuff, "Null pTCCParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2829
2830 // initialize
2831 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2832 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2833 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2834 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2835
2836 if (SURF_IN_PRIMARY == pSrc->SurfType)
2837 {
2838 if (nullptr == pSrc->pColorPipeParams)
2839 {
2840 pSrc->pColorPipeParams = (PVPHAL_COLORPIPE_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_COLORPIPE_PARAMS));
2841 DDI_CHK_NULL(pSrc->pColorPipeParams, "pColorPipeParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2842 }
2843
2844 // set default values
2845 pSrc->pColorPipeParams->TccParams.Red = (uint8_t)TCC_DEFAULT;
2846 pSrc->pColorPipeParams->TccParams.Green = (uint8_t)TCC_DEFAULT;
2847 pSrc->pColorPipeParams->TccParams.Blue = (uint8_t)TCC_DEFAULT;
2848 pSrc->pColorPipeParams->TccParams.Cyan = (uint8_t)TCC_DEFAULT;
2849 pSrc->pColorPipeParams->TccParams.Magenta = (uint8_t)TCC_DEFAULT;
2850 pSrc->pColorPipeParams->TccParams.Yellow = (uint8_t)TCC_DEFAULT;
2851
2852 for (i = 0; i < uElementNum; i++)
2853 {
2854 if (pTCCParamBuff[i].value < TCC_MIN || pTCCParamBuff[i].value > TCC_MAX)
2855 return VA_STATUS_ERROR_INVALID_PARAMETER;
2856
2857 pSrc->pColorPipeParams->bEnableTCC = true;
2858
2859 switch (pTCCParamBuff[i].attrib)
2860 {
2861 case VAProcTotalColorCorrectionRed:
2862 pSrc->pColorPipeParams->TccParams.Red = (uint8_t)pTCCParamBuff[i].value;
2863 break;
2864
2865 case VAProcTotalColorCorrectionGreen:
2866 pSrc->pColorPipeParams->TccParams.Green = (uint8_t)pTCCParamBuff[i].value;
2867 break;
2868
2869 case VAProcTotalColorCorrectionBlue:
2870 pSrc->pColorPipeParams->TccParams.Blue = (uint8_t)pTCCParamBuff[i].value;
2871 break;
2872
2873 case VAProcTotalColorCorrectionCyan:
2874 pSrc->pColorPipeParams->TccParams.Cyan = (uint8_t)pTCCParamBuff[i].value;
2875 break;
2876
2877 case VAProcTotalColorCorrectionMagenta:
2878 pSrc->pColorPipeParams->TccParams.Magenta = (uint8_t)pTCCParamBuff[i].value;
2879 break;
2880
2881 case VAProcTotalColorCorrectionYellow:
2882 pSrc->pColorPipeParams->TccParams.Yellow = (uint8_t)pTCCParamBuff[i].value;
2883 break;
2884
2885 case VAProcTotalColorCorrectionNone:
2886 case VAProcTotalColorCorrectionCount:
2887 default:
2888 VP_DDI_ASSERTMESSAGE("pTCCParamBuff[%d].attrib is unknown.", i);
2889 return VA_STATUS_ERROR_INVALID_PARAMETER;
2890 }
2891 }
2892 }
2893
2894 return VA_STATUS_SUCCESS;
2895 }
2896
2897 /////////////////////////////////////////////////////////////////////////////////////////////////
2898 //! \purpose High Dynamic Range (HDR) Tone Mapping filter params for VPHAL input surface
2899 //! \params
2900 //! [in] pVpCtx : VP context
2901 //! [in] uSurfIndex : uSurfIndex to the input surface array
2902 //! [in] pHDRParamBuff : Pointer to High Dynamic Range Tone Mapping param buffer data
2903 //! [in] uElementNum : number of elements in the High Dynamic Range Tone Mapping param buffer data
2904 //! [out] None
2905 //! \returns VA_STATUS_SUCCESS if call succeeds
2906 //////////////////////////////////////////////////////////////////////////////////////////////////
2907 VAStatus
2908 DdiVp_SetProcFilterHdrTmParams(
2909 PDDI_VP_CONTEXT pVpCtx,
2910 uint32_t uSurfIndex,
2911 VAProcFilterParameterBufferHDRToneMapping* pHdrTmParamBuff)
2912 {
2913 PVPHAL_RENDER_PARAMS pVpHalRenderParams = nullptr;
2914 PVPHAL_SURFACE pSrc = nullptr;
2915 VAStatus eStatus;
2916
2917 VP_DDI_FUNCTION_ENTER;
2918 DDI_CHK_NULL(pHdrTmParamBuff, "Null pHdrTmParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2919
2920 // initialize
2921 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2922 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2923 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2924 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2925
2926 eStatus = VpUpdateProcHdrState(pSrc, &pHdrTmParamBuff->data);
2927
2928 return eStatus;
2929 }
2930 #if VA_CHECK_VERSION(1, 12, 0)
2931 /////////////////////////////////////////////////////////////////////////////////////////////////
2932 //! \purpose Three Three-Dimensional Look Up Table(3DLUT) filter params for VPHAL input surface
2933 //! \params
2934 //! [in] pVaDrvCtx: Driver context
2935 //! [in] pVpCtx : VP context
2936 //! [in] uSurfIndex : uSurfIndex to the input surface array
2937 //! [in] p3DLutParamBuff : Pointer to 3DLUT param buffer data
2938 //! [out] None
2939 //! \returns VA_STATUS_SUCCESS if call succeeds
2940 //////////////////////////////////////////////////////////////////////////////////////////////////
2941 VAStatus
2942 DdiVp_SetProcFilter3DLutParams(
2943 VADriverContextP pVaDrvCtx,
2944 PDDI_VP_CONTEXT pVpCtx,
2945 uint32_t uSurfIndex,
2946 VAProcFilterParameterBuffer3DLUT* p3DLutParamBuff)
2947 {
2948 PVPHAL_RENDER_PARAMS pVpHalRenderParams = nullptr;
2949 PVPHAL_SURFACE pSrc = nullptr;
2950 VAStatus eStatus = VA_STATUS_SUCCESS;
2951
2952 PDDI_MEDIA_SURFACE pMedia3DLutSurf = nullptr;
2953 PDDI_MEDIA_CONTEXT pMediaCtx = nullptr;
2954
2955 VP_DDI_FUNCTION_ENTER;
2956 DDI_CHK_NULL(p3DLutParamBuff, "Null p3DLutParamBuff.", VA_STATUS_ERROR_INVALID_BUFFER);
2957 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx.", VA_STATUS_ERROR_INVALID_BUFFER);
2958
2959 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
2960
2961 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
2962 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
2963 pSrc = pVpHalRenderParams->pSrc[uSurfIndex];
2964 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
2965
2966 pMedia3DLutSurf = DdiMedia_GetSurfaceFromVASurfaceID(pMediaCtx, p3DLutParamBuff->lut_surface);
2967 DDI_CHK_NULL(pMedia3DLutSurf, "Null pMedia3DLutSurf.", VA_STATUS_ERROR_INVALID_SURFACE);
2968
2969 // only primary surface takes effect if 3DLUT filter
2970 if (SURF_IN_PRIMARY == pSrc->SurfType)
2971 {
2972 if (nullptr == pSrc->p3DLutParams)
2973 {
2974 pSrc->p3DLutParams = (PVPHAL_3DLUT_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_3DLUT_PARAMS));
2975 DDI_CHK_NULL(pSrc->p3DLutParams, "p3DLutParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2976 }
2977
2978 pSrc->p3DLutParams->LutSize = (uint32_t)p3DLutParamBuff->lut_size;
2979 pSrc->p3DLutParams->BitDepthPerChannel = (uint16_t)p3DLutParamBuff->bit_depth;
2980 pSrc->p3DLutParams->ByteCountPerEntry = (uint16_t)(p3DLutParamBuff->num_channel * (pSrc->p3DLutParams->BitDepthPerChannel / 8));
2981 if (nullptr == pSrc->p3DLutParams->pExt3DLutSurface)
2982 {
2983 pSrc->p3DLutParams->pExt3DLutSurface = (PVPHAL_SURFACE)MOS_AllocAndZeroMemory(sizeof(VPHAL_SURFACE));
2984 DDI_CHK_NULL(pSrc->p3DLutParams->pExt3DLutSurface, "p3DLutParams MOS_AllocAndZeroMemory failed.", VA_STATUS_ERROR_ALLOCATION_FAILED);
2985 }
2986
2987 if (pSrc->p3DLutParams->pExt3DLutSurface)
2988 {
2989 PMOS_RESOURCE pOsResource = nullptr;
2990 pOsResource = &(pSrc->p3DLutParams->pExt3DLutSurface->OsResource);
2991 DDI_CHK_NULL(pOsResource, "Null pOsResource.", VA_STATUS_ERROR_INVALID_PARAMETER);
2992
2993 DdiMedia_MediaSurfaceToMosResource(pMedia3DLutSurf, pOsResource);
2994 Mos_Solo_SetOsResource(pMedia3DLutSurf->pGmmResourceInfo, pOsResource);
2995 }
2996 }
2997
2998 return eStatus;
2999 }
3000 #endif
3001 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3002 //! \purpose Create Media Buffer
3003 //! \params
3004 //! [in] pVaDrvCtx : VA Driver context
3005 //! [in] pVpCtx : VP context
3006 //! [in] vaBufType : VA buffer type
3007 //! [in] uiSize : element size
3008 //! [in] uiNumElements : number of elements
3009 //! [in] pDataClient : client data
3010 //! [inout] pVaBufID : buffer ID
3011 //! \returns VA_STATUS_SUCCESS if call succeeds
3012 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3013 VAStatus DdiVp_CreateBuffer(
3014 VADriverContextP pVaDrvCtx,
3015 void *pCtx,
3016 VABufferType vaBufType,
3017 uint32_t uiSize,
3018 uint32_t uiNumElements,
3019 void *pDataClient,
3020 VABufferID* pVaBufID
3021 )
3022 {
3023 PDDI_MEDIA_CONTEXT pMediaCtx;
3024 PDDI_MEDIA_BUFFER pBuf;
3025 VAStatus vaStatus;
3026 PDDI_MEDIA_BUFFER_HEAP_ELEMENT pBufferHeapElement;
3027 MOS_STATUS eStatus = MOS_STATUS_SUCCESS;
3028
3029 VP_DDI_FUNCTION_ENTER;
3030 DDI_CHK_NULL(pCtx, "Null pCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3031 DDI_CHK_NULL(pVaDrvCtx,
3032 "Null pVaDrvCtx.",
3033 VA_STATUS_ERROR_INVALID_CONTEXT);
3034
3035 vaStatus = VA_STATUS_SUCCESS;
3036 *pVaBufID = VA_INVALID_ID;
3037
3038 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3039 DDI_CHK_NULL(pMediaCtx,
3040 "Null pMediaCtx.",
3041 VA_STATUS_ERROR_INVALID_CONTEXT);
3042
3043 PDDI_VP_CONTEXT pVpCtx = (PDDI_VP_CONTEXT)pCtx;
3044
3045 // only for VAProcFilterParameterBufferType and VAProcPipelineParameterBufferType
3046 if (vaBufType != VAProcFilterParameterBufferType
3047 && vaBufType != VAProcPipelineParameterBufferType
3048 #if VA_CHECK_VERSION(1, 10, 0)
3049 && vaBufType != VAContextParameterUpdateBufferType
3050 #endif
3051 )
3052 {
3053 VP_DDI_ASSERTMESSAGE("Unsupported Va Buffer Type.");
3054 return VA_STATUS_ERROR_INVALID_PARAMETER;
3055 }
3056
3057 // allocate new buf and init
3058 pBuf = (DDI_MEDIA_BUFFER *)MOS_AllocAndZeroMemory(sizeof(DDI_MEDIA_BUFFER));
3059 DDI_CHK_NULL(pBuf, "Null pBuf.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3060 pBuf->pMediaCtx = pMediaCtx;
3061 pBuf->iSize = uiSize * uiNumElements;
3062 pBuf->uiNumElements = uiNumElements;
3063 pBuf->uiType = vaBufType;
3064 pBuf->format = Media_Format_Buffer;
3065 pBuf->uiOffset = 0;
3066 pBuf->pData = (uint8_t*)MOS_AllocAndZeroMemory(uiSize * uiNumElements);
3067 if (nullptr == pBuf->pData)
3068 {
3069 MOS_FreeMemAndSetNull(pBuf);
3070 return VA_STATUS_ERROR_ALLOCATION_FAILED;
3071 }
3072 pBuf->format = Media_Format_CPU;
3073
3074 pBufferHeapElement = DdiMediaUtil_AllocPMediaBufferFromHeap(pMediaCtx->pBufferHeap);
3075 if (nullptr == pBufferHeapElement)
3076 {
3077 MOS_FreeMemAndSetNull(pBuf->pData);
3078 MOS_FreeMemAndSetNull(pBuf);
3079 VP_DDI_ASSERTMESSAGE("Invalid buffer index.");
3080 return VA_STATUS_ERROR_INVALID_BUFFER;
3081 }
3082 pBufferHeapElement->pBuffer = pBuf;
3083 pBufferHeapElement->pCtx = (void *)pVpCtx;
3084 pBufferHeapElement->uiCtxType = DDI_MEDIA_CONTEXT_TYPE_VP;
3085 *pVaBufID = pBufferHeapElement->uiVaBufferID;
3086 pMediaCtx->uiNumBufs++;
3087
3088 // if there is data from client, then dont need to copy data from client
3089 if (pDataClient)
3090 {
3091 // copy client data to new buf
3092 eStatus = MOS_SecureMemcpy(pBuf->pData, uiSize * uiNumElements, pDataClient, uiSize * uiNumElements);
3093 DDI_CHK_CONDITION((eStatus != MOS_STATUS_SUCCESS), "DDI: Failed to copy client data!", VA_STATUS_ERROR_MAX_NUM_EXCEEDED);
3094 }
3095 else
3096 {
3097 // do nothing if there is no data from client
3098 vaStatus = VA_STATUS_SUCCESS;
3099 }
3100
3101 return vaStatus;
3102 }
3103
3104 /////////////////////////////////////////////////////////////////////////////
3105 //! \purpose Create a new VP context, and put in pVpCtx array
3106 //! \params
3107 //! [in] pVaDrvCtx : VA Driver context
3108 //! [in] vaConfigID :
3109 //! [in] iWidth :
3110 //! [in] iHeight :
3111 //! [in] iFlag :
3112 //! [in] vaSurfIDs :
3113 //! [in] iNumSurfs :
3114 //! [inout] pVaCtxID : VA context ID
3115 //! \returns VA_STATUS_SUCCESS if call succeeds
3116 /////////////////////////////////////////////////////////////////////////////
3117 VAStatus DdiVp_CreateContext (
3118 VADriverContextP pVaDrvCtx,
3119 VAConfigID vaConfigID,
3120 int32_t iWidth,
3121 int32_t iHeight,
3122 int32_t iFlag,
3123 VASurfaceID *vaSurfIDs,
3124 int32_t iNumSurfs,
3125 VAContextID *pVaCtxID
3126 )
3127 {
3128 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
3129
3130 PDDI_MEDIA_CONTEXT pMediaCtx;
3131 VAStatus vaStatus;
3132 PDDI_VP_CONTEXT pVpCtx;
3133 PDDI_MEDIA_VACONTEXT_HEAP_ELEMENT pVaCtxHeapElmt;
3134 DDI_UNUSED(vaConfigID);
3135 DDI_UNUSED(iWidth);
3136 DDI_UNUSED(iHeight);
3137 DDI_UNUSED(iFlag);
3138 DDI_UNUSED(vaSurfIDs);
3139 DDI_UNUSED(iNumSurfs);
3140
3141 VP_DDI_FUNCTION_ENTER;
3142 DDI_CHK_NULL(pVaDrvCtx,
3143 "Null pVaDrvCtx.",
3144 VA_STATUS_ERROR_INVALID_CONTEXT);
3145
3146 pVpCtx = nullptr;
3147 *pVaCtxID = VA_INVALID_ID;
3148
3149 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3150 DDI_CHK_NULL(pMediaCtx,
3151 "Null pMediaCtx.",
3152 VA_STATUS_ERROR_INVALID_CONTEXT);
3153
3154 // allocate pVpCtx
3155 pVpCtx = MOS_New(DDI_VP_CONTEXT);
3156 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3157
3158 // init pVpCtx
3159 vaStatus = DdiVp_InitCtx(pVaDrvCtx, pVpCtx);
3160 DDI_CHK_RET(vaStatus, "VA_STATUS_ERROR_OPERATION_FAILED");
3161
3162 DdiMediaUtil_LockMutex(&pMediaCtx->VpMutex);
3163
3164 // get Free VP context index
3165 pVaCtxHeapElmt = DdiMediaUtil_AllocPVAContextFromHeap(pMediaCtx->pVpCtxHeap);
3166 if (nullptr == pVaCtxHeapElmt)
3167 {
3168 MOS_Delete(pVpCtx);
3169 DdiMediaUtil_UnLockMutex(&pMediaCtx->VpMutex);
3170 VP_DDI_ASSERTMESSAGE("VP Context number exceeds maximum.");
3171 return VA_STATUS_ERROR_INVALID_CONTEXT;
3172 }
3173
3174 // store pVpCtx in pMedia
3175 pVaCtxHeapElmt->pVaContext = (void *)pVpCtx;
3176 *pVaCtxID = (VAContextID)(pVaCtxHeapElmt->uiVaContextID + DDI_MEDIA_VACONTEXTID_OFFSET_VP);
3177
3178 // increate VP context number
3179 pMediaCtx->uiNumVPs++;
3180
3181 DdiMediaUtil_UnLockMutex(&pMediaCtx->VpMutex);
3182
3183 return VA_STATUS_SUCCESS;
3184 }
3185
3186 /////////////////////////////////////////////////////////////////////////////
3187 //! \purpose Destroy VP context
3188 //! \params
3189 //! [in] pVaDrvCtx : VA Driver context
3190 //! [in] vaCtxID : VA Context ID
3191 //! [out] None
3192 //! \returns VA_STATUS_SUCCESS if call succeeds
3193 /////////////////////////////////////////////////////////////////////////////
3194 VAStatus DdiVp_DestroyContext (
3195 VADriverContextP pVaDrvCtx,
3196 VAContextID vaCtxID
3197 )
3198 {
3199 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
3200
3201 PDDI_MEDIA_CONTEXT pMediaCtx;
3202 PDDI_VP_CONTEXT pVpCtx;
3203 uint32_t uiVpIndex;
3204 uint32_t ctxType;
3205 VAStatus vaStatus;
3206
3207 VP_DDI_FUNCTION_ENTER;
3208 DDI_CHK_NULL(pVaDrvCtx,
3209 "Null pVaDrvCtx.",
3210 VA_STATUS_ERROR_INVALID_CONTEXT);
3211
3212 // initialize
3213 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3214 DDI_CHK_NULL(pMediaCtx,
3215 "Null pMediaCtx.",
3216 VA_STATUS_ERROR_INVALID_CONTEXT);
3217 pVpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID(pVaDrvCtx, vaCtxID, &ctxType);
3218 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3219
3220 MOS_FreeMemory(pVpCtx->MosDrvCtx.pPerfData);
3221 pVpCtx->MosDrvCtx.pPerfData = nullptr;
3222
3223 if (pVpCtx->pCpDdiInterface)
3224 {
3225 Delete_DdiCpInterface(pVpCtx->pCpDdiInterface);
3226 pVpCtx->pCpDdiInterface = NULL;
3227 }
3228
3229 // destroy vphal
3230 vaStatus = DdiVp_DestroyVpHal(pVpCtx);
3231
3232 // Get VP context index
3233 uiVpIndex = vaCtxID & DDI_MEDIA_MASK_VACONTEXTID;
3234
3235 // remove from context array
3236 DdiMediaUtil_LockMutex(&pMediaCtx->VpMutex);
3237 // destroy vp context
3238 MOS_Delete(pVpCtx);
3239 DdiMediaUtil_ReleasePVAContextFromHeap(pMediaCtx->pVpCtxHeap, uiVpIndex);
3240
3241 pMediaCtx->uiNumVPs--;
3242 DdiMediaUtil_UnLockMutex(&pMediaCtx->VpMutex);
3243
3244 return vaStatus;
3245 }
3246
3247 ////////////////////////////////////////////////////////////////////////////////
3248 //! \purpose Get ready to process a picture to a target surface
3249 //! \params
3250 //! [in] pVaDrvCtx : VA Driver Context
3251 //! [in] vaCtxID : VA context ID
3252 //! [in] vaSurfID : target surface ID
3253 //! [out] None
3254 //! \returns VA_STATUS_SUCCESS if call succeeds
3255 ////////////////////////////////////////////////////////////////////////////////
3256 VAStatus DdiVp_BeginPicture(
3257 VADriverContextP pVaDrvCtx,
3258 VAContextID vaCtxID,
3259 VASurfaceID vaSurfID)
3260 {
3261 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
3262
3263 PDDI_MEDIA_CONTEXT pMediaDrvCtx;
3264 PDDI_VP_CONTEXT pVpCtx;
3265 uint32_t ctxType;
3266 VAStatus vaStatus;
3267 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
3268 PVPHAL_SURFACE pVpHalTgtSurf;
3269 PDDI_MEDIA_SURFACE pMediaTgtSurf;
3270
3271 VP_DDI_FUNCTION_ENTER;
3272 DDI_CHK_NULL(pVaDrvCtx,
3273 "Null pVaDrvCtx.",
3274 VA_STATUS_ERROR_INVALID_CONTEXT);
3275
3276 // initialize
3277 pMediaDrvCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3278 DDI_CHK_NULL(pMediaDrvCtx,
3279 "Null pMediaDrvCtx.",
3280 VA_STATUS_ERROR_INVALID_CONTEXT);
3281 pVpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID (
3282 pVaDrvCtx, vaCtxID, &ctxType);
3283 DDI_CHK_NULL(pVpCtx,
3284 "Null pVpCtx.",
3285 VA_STATUS_ERROR_INVALID_CONTEXT);
3286 pVpCtx->TargetSurfID = vaSurfID;
3287 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
3288 DDI_CHK_NULL(pVpHalRenderParams,
3289 "Null pVpHalRenderParams.",
3290 VA_STATUS_ERROR_INVALID_PARAMETER);
3291
3292 // uDstCount == 0 means no render target is set yet.
3293 // uDstCount == 1 means 1 render target has been set already.
3294 // uDstCount == 2 means 2 render targets have been set already.
3295 DDI_CHK_LESS(pVpHalRenderParams->uDstCount, VPHAL_MAX_TARGETS,
3296 "Too many render targets for VP.",
3297 VA_STATUS_ERROR_INVALID_PARAMETER);
3298
3299 pVpHalTgtSurf = pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount];
3300 DDI_CHK_NULL(pVpHalTgtSurf,
3301 "Null pVpHalTgtSurf.",
3302 VA_STATUS_ERROR_INVALID_SURFACE);
3303 pMediaTgtSurf = DdiMedia_GetSurfaceFromVASurfaceID(pMediaDrvCtx, vaSurfID);
3304 DDI_CHK_NULL(pMediaTgtSurf,
3305 "Null pMediaTgtSurf.",
3306 VA_STATUS_ERROR_INVALID_SURFACE);
3307
3308 pMediaTgtSurf->pVpCtx = pVpCtx;
3309
3310 // Setup Target VpHal Surface
3311 pVpHalTgtSurf->SurfType = SURF_OUT_RENDERTARGET;
3312 pVpHalTgtSurf->rcSrc.top = 0;
3313 pVpHalTgtSurf->rcSrc.left = 0;
3314 pVpHalTgtSurf->rcSrc.right = pMediaTgtSurf->iWidth;
3315 pVpHalTgtSurf->rcSrc.bottom = pMediaTgtSurf->iRealHeight;
3316 pVpHalTgtSurf->rcDst.top = 0;
3317 pVpHalTgtSurf->rcDst.left = 0;
3318 pVpHalTgtSurf->rcDst.right = pMediaTgtSurf->iWidth;
3319 pVpHalTgtSurf->rcDst.bottom = pMediaTgtSurf->iRealHeight;
3320 pVpHalTgtSurf->ExtendedGamut = false;
3321
3322 // Set os resource for VPHal render
3323 vaStatus = VpSetOsResource(pVpCtx, pMediaTgtSurf, pVpHalRenderParams->uDstCount);
3324 DDI_CHK_RET(vaStatus, "Call VpSetOsResource failed");
3325
3326 pVpHalTgtSurf->Format = pVpHalTgtSurf->OsResource.Format;
3327 pVpHalTgtSurf->TileType = pVpHalTgtSurf->OsResource.TileType;
3328
3329 // reset source surface count
3330 pVpHalRenderParams->uSrcCount = 0;
3331
3332 pVpHalRenderParams->bReportStatus = true;
3333 pVpHalRenderParams->StatusFeedBackID = vaSurfID;
3334
3335 if (pMediaTgtSurf->pSurfDesc && (pMediaTgtSurf->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR))
3336 {
3337 pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount]->b16UsrPtr = VpIs16UsrPtrPitch(pMediaTgtSurf->iPitch, pMediaTgtSurf->format);
3338 }
3339 else
3340 {
3341 pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount]->b16UsrPtr = false;
3342 }
3343
3344 // increase render target count
3345 pVpHalRenderParams->uDstCount++;
3346
3347 return VA_STATUS_SUCCESS;
3348 }
3349
3350 ////////////////////////////////////////////////////////////////////////////////
3351 //! \purpose Get ready to process a picture to a target surface
3352 //! \params
3353 //! [in] pVaDrvCtx : VA Driver Context
3354 //! [in] vaCtxID : VA context ID
3355 //! [in] vaSurfID : target surface ID
3356 //! [out] None
3357 //! \returns VA_STATUS_SUCCESS if call succeeds
3358 ////////////////////////////////////////////////////////////////////////////////
3359 VAStatus DdiVp_BeginPictureInt(
3360 VADriverContextP pVaDrvCtx,
3361 PDDI_VP_CONTEXT pVpCtx,
3362 VASurfaceID vaSurfID)
3363 {
3364 PDDI_MEDIA_CONTEXT pMediaDrvCtx;
3365 uint32_t ctxType;
3366 VAStatus vaStatus;
3367 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
3368 PVPHAL_SURFACE pVpHalTgtSurf;
3369 PDDI_MEDIA_SURFACE pMediaTgtSurf;
3370
3371 VP_DDI_FUNCTION_ENTER;
3372 DDI_CHK_NULL(pVaDrvCtx,
3373 "Null pVaDrvCtx.",
3374 VA_STATUS_ERROR_INVALID_CONTEXT);
3375
3376 // initialize
3377 pMediaDrvCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3378 DDI_CHK_NULL(pMediaDrvCtx,
3379 "Null pMediaDrvCtx.",
3380 VA_STATUS_ERROR_INVALID_CONTEXT);
3381 DDI_CHK_NULL(pVpCtx,
3382 "Null pVpCtx.",
3383 VA_STATUS_ERROR_INVALID_CONTEXT);
3384 pVpCtx->TargetSurfID = vaSurfID;
3385 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
3386 DDI_CHK_NULL(pVpHalRenderParams,
3387 "Null pVpHalRenderParams.",
3388 VA_STATUS_ERROR_INVALID_PARAMETER);
3389
3390 // uDstCount == 0 means no render target is set yet.
3391 // uDstCount == 1 means 1 render target has been set already.
3392 // uDstCount == 2 means 2 render targets have been set already.
3393 DDI_CHK_LESS(pVpHalRenderParams->uDstCount, VPHAL_MAX_TARGETS,
3394 "Too many render targets for VP.",
3395 VA_STATUS_ERROR_INVALID_PARAMETER);
3396
3397 pVpHalTgtSurf = pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount];
3398 DDI_CHK_NULL(pVpHalTgtSurf,
3399 "Null pVpHalTgtSurf.",
3400 VA_STATUS_ERROR_INVALID_SURFACE);
3401 pMediaTgtSurf = DdiMedia_GetSurfaceFromVASurfaceID(pMediaDrvCtx, vaSurfID);
3402 DDI_CHK_NULL(pMediaTgtSurf,
3403 "Null pMediaTgtSurf.",
3404 VA_STATUS_ERROR_INVALID_SURFACE);
3405
3406 pMediaTgtSurf->pVpCtx = pVpCtx;
3407
3408 // Setup Target VpHal Surface
3409 pVpHalTgtSurf->SurfType = SURF_OUT_RENDERTARGET;
3410 pVpHalTgtSurf->rcSrc.top = 0;
3411 pVpHalTgtSurf->rcSrc.left = 0;
3412 pVpHalTgtSurf->rcSrc.right = pMediaTgtSurf->iWidth;
3413 pVpHalTgtSurf->rcSrc.bottom = pMediaTgtSurf->iRealHeight;
3414 pVpHalTgtSurf->rcDst.top = 0;
3415 pVpHalTgtSurf->rcDst.left = 0;
3416 pVpHalTgtSurf->rcDst.right = pMediaTgtSurf->iWidth;
3417 pVpHalTgtSurf->rcDst.bottom = pMediaTgtSurf->iRealHeight;
3418 pVpHalTgtSurf->ExtendedGamut = false;
3419
3420 // Set os resource for VPHal render
3421 vaStatus = VpSetOsResource(pVpCtx, pMediaTgtSurf, pVpHalRenderParams->uDstCount);
3422 DDI_CHK_RET(vaStatus, "Call VpSetOsResource failed");
3423
3424 pVpHalTgtSurf->Format = pVpHalTgtSurf->OsResource.Format;
3425
3426 pVpHalRenderParams->bReportStatus = true;
3427 pVpHalRenderParams->StatusFeedBackID = vaSurfID;
3428 if (pMediaTgtSurf->pSurfDesc && (pMediaTgtSurf->pSurfDesc->uiVaMemType == VA_SURFACE_ATTRIB_MEM_TYPE_USER_PTR))
3429 {
3430 pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount]->b16UsrPtr = VpIs16UsrPtrPitch(pMediaTgtSurf->iPitch, pMediaTgtSurf->format);
3431 }
3432 else
3433 {
3434 pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount]->b16UsrPtr = false;
3435 }
3436 // increase render target count
3437 pVpHalRenderParams->uDstCount++;
3438
3439 return VA_STATUS_SUCCESS;
3440 }
3441
3442 ////////////////////////////////////////////////////////////////////////////////
3443 //! \purpose judge whether the PipelineParam buffer is for target or not
3444 //! \params
3445 //! [in] pVaDrvCtx : VA Driver context
3446 //! [in] pVpCtx : VP context
3447 //! [in] pPipelineParam : Pipeline parameters from application (VAProcPipelineParameterBuffer)
3448 //! [out] None
3449 //! \returns VA_STATUS_SUCCESS if call succeeds
3450 ////////////////////////////////////////////////////////////////////////////////
3451 bool VpIsRenderTarget(
3452 VADriverContextP pVaDrvCtx,
3453 PDDI_VP_CONTEXT pVpCtx,
3454 VAProcPipelineParameterBuffer* pPipelineParam)
3455 {
3456 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
3457 PDDI_MEDIA_CONTEXT pMediaCtx;
3458 PDDI_MEDIA_SURFACE pMediaSrcSurf;
3459 PVPHAL_SURFACE pVpHalTgtSurf;
3460 bool IsTarget = false;
3461
3462 VP_DDI_FUNCTION_ENTER;
3463 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3464 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3465 DDI_CHK_NULL(pPipelineParam, "Null pPipelineParam.", VA_STATUS_ERROR_INVALID_BUFFER);
3466
3467 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3468 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3469 pMediaSrcSurf = DdiMedia_GetSurfaceFromVASurfaceID(pMediaCtx, pPipelineParam->surface);
3470 DDI_CHK_NULL(pMediaSrcSurf, "Null pMediaSrcSurf.", VA_STATUS_ERROR_INVALID_BUFFER);
3471 pVpHalRenderParams = pVpCtx->pVpHalRenderParams;
3472 DDI_CHK_NULL(pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3473
3474 if(pPipelineParam->pipeline_flags == 0 && pVpHalRenderParams->uDstCount >= 1)
3475 {
3476 pVpHalTgtSurf = pVpHalRenderParams->pTarget[pVpHalRenderParams->uDstCount-1];
3477
3478 IsTarget = ((pVpHalTgtSurf->OsResource.bo != nullptr)
3479 &&(pVpHalTgtSurf->OsResource.bo == pMediaSrcSurf->bo));
3480 }
3481
3482 return IsTarget;
3483 }
3484 ////////////////////////////////////////////////////////////////////////////////
3485 //! \purpose Send buffers to the server
3486 //! \params
3487 //! [in] pVaDrvCtx : VA Driver context
3488 //! [in] vpCtxID : context ID
3489 //! [in] buffers : array of buffer IDs
3490 //! [in] num_buffers : number of buffers IDs in the array
3491 //! [out] None
3492 //! \returns VA_STATUS_SUCCESS if call succeeds
3493 ////////////////////////////////////////////////////////////////////////////////
3494 VAStatus DdiVp_RenderPicture (
3495 VADriverContextP pVaDrvCtx,
3496 VAContextID vpCtxID,
3497 VABufferID* buffers,
3498 int32_t num_buffers
3499 )
3500 {
3501 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
3502
3503 PDDI_MEDIA_CONTEXT pMediaCtx;
3504 PDDI_VP_CONTEXT pVpCtx;
3505 PDDI_MEDIA_BUFFER pBuf;
3506 int32_t i;
3507 void *pData;
3508 uint32_t ctxType;
3509 VAStatus vaStatus;
3510 int32_t numOfBuffers = num_buffers;
3511 int32_t priority = 0;
3512 int32_t priorityIndexInBuffers = -1;
3513 bool updatePriority = false;
3514
3515 VP_DDI_FUNCTION_ENTER;
3516 DDI_CHK_NULL(pVaDrvCtx,
3517 "Null pVaDrvCtx.",
3518 VA_STATUS_ERROR_INVALID_CONTEXT);
3519
3520 vaStatus = VA_STATUS_SUCCESS;
3521
3522 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3523 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx", VA_STATUS_ERROR_OPERATION_FAILED);
3524
3525 pVpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID (pVaDrvCtx, vpCtxID, &ctxType);
3526 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3527
3528 //num_buffers check
3529 DDI_CHK_CONDITION(((numOfBuffers > VPHAL_MAX_SOURCES) || (numOfBuffers <= 0)),
3530 "numOfBuffers is Invalid.",
3531 VA_STATUS_ERROR_INVALID_PARAMETER);
3532
3533 priorityIndexInBuffers = DdiMedia_GetGpuPriority(pVaDrvCtx, buffers, numOfBuffers, &updatePriority, &priority);
3534 if (priorityIndexInBuffers != -1)
3535 {
3536 if(updatePriority)
3537 {
3538 vaStatus = DdiVp_SetGpuPriority(pVpCtx, priority);
3539 if(vaStatus != VA_STATUS_SUCCESS)
3540 return vaStatus;
3541 }
3542 MovePriorityBufferIdToEnd(buffers, priorityIndexInBuffers, numOfBuffers);
3543 numOfBuffers--;
3544 }
3545 if (numOfBuffers == 0)
3546 return vaStatus;
3547
3548 for (i = 0; i < numOfBuffers; i++)
3549 {
3550 pBuf = DdiMedia_GetBufferFromVABufferID(pMediaCtx, buffers[i]);
3551 DDI_CHK_NULL(pBuf, "Null pBuf.", VA_STATUS_ERROR_INVALID_BUFFER);
3552
3553 DdiMedia_MapBuffer(pVaDrvCtx, buffers[i], &pData);
3554 DDI_CHK_NULL(pData, "Null pData.", VA_STATUS_ERROR_INVALID_BUFFER);
3555
3556 switch ((int32_t)pBuf->uiType)
3557 {
3558 // VP Buffer Types
3559 case VAProcPipelineParameterBufferType:
3560 if(VpIsRenderTarget(pVaDrvCtx, pVpCtx,(VAProcPipelineParameterBuffer*)pData))
3561 {
3562 vaStatus=VpSetRenderTargetParams(pVaDrvCtx, pVpCtx,
3563 (VAProcPipelineParameterBuffer*)pData);
3564 }
3565 else
3566 {
3567 vaStatus = DdiVp_SetProcPipelineParams(pVaDrvCtx, pVpCtx,
3568 (VAProcPipelineParameterBuffer*)pData);
3569 DDI_CHK_RET(vaStatus, "Unable to set pipeline parameters");
3570 }
3571 break;
3572 case VAProcFilterParameterBufferType:
3573 // User is not supposed to pass this buffer type:Refer va_vpp.h
3574 VP_DDI_ASSERTMESSAGE("Invalid buffer type.");
3575 vaStatus = VA_STATUS_ERROR_INVALID_BUFFER;
3576 break;
3577
3578 default:
3579 DDI_CHK_RET(vaStatus,"Unsupported buffer type!");
3580 break;
3581 }
3582 DdiMedia_UnmapBuffer(pVaDrvCtx, buffers[i]);
3583 }
3584 return vaStatus;
3585 }
3586
3587 ////////////////////////////////////////////////////////////////////////////////
3588 //! \purpose
3589 //! Make the end of rendering for a picture.
3590 //! The server should start processing all pending operations for this
3591 //! surface. This call is non-blocking. The client can start another
3592 //! Begin/Render/End sequence on a different render target.
3593 //! \params
3594 //! [in] pVaDrvCtx : VA Driver Context
3595 //! [in] vaCtxID : VA Context ID
3596 //! [out] None
3597 //! \returns VA_STATUS_SUCCESS if call succeeds
3598 ////////////////////////////////////////////////////////////////////////////////
3599 VAStatus DdiVp_EndPicture (
3600 VADriverContextP pVaDrvCtx,
3601 VAContextID vaCtxID)
3602 {
3603 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
3604
3605 PDDI_VP_CONTEXT pVpCtx;
3606 uint32_t uiCtxType;
3607 VpBase *pVpHal;
3608 MOS_STATUS eStatus;
3609
3610 VP_DDI_FUNCTION_ENTER;
3611 DDI_CHK_NULL(pVaDrvCtx,
3612 "Null pVaDrvCtx.",
3613 VA_STATUS_ERROR_INVALID_CONTEXT);
3614
3615 //get VP Context
3616 pVpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID (pVaDrvCtx, vaCtxID, &uiCtxType);
3617 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3618
3619 //Add component tag for VP
3620 DDI_CHK_NULL(pVpCtx->pVpHalRenderParams, "Null pVpHalRenderParams.", VA_STATUS_ERROR_INVALID_PARAMETER);
3621 pVpCtx->pVpHalRenderParams->Component = COMPONENT_VPCommon;
3622
3623 pVpHal = pVpCtx->pVpHal;
3624 DDI_CHK_NULL(pVpHal, "Null pVpHal.", VA_STATUS_ERROR_INVALID_PARAMETER);
3625 eStatus = pVpHal->Render(pVpCtx->pVpHalRenderParams);
3626
3627 #if (_DEBUG || _RELEASE_INTERNAL)
3628 VpDumpProcPipelineParams(pVaDrvCtx, pVpCtx);
3629 #endif //(_DEBUG || _RELEASE_INTERNAL)
3630
3631 VpReportFeatureMode(pVpCtx);
3632
3633 // Reset primary surface count for next render call
3634 pVpCtx->iPriSurfs = 0;
3635
3636 // Reset render target count for next render call
3637 pVpCtx->pVpHalRenderParams->uDstCount = 0;
3638
3639 if (MOS_FAILED(eStatus))
3640 {
3641 VP_DDI_ASSERTMESSAGE("Failed to call render function.");
3642 return VA_STATUS_ERROR_OPERATION_FAILED;
3643 }
3644
3645 return VA_STATUS_SUCCESS;
3646
3647 }
3648
3649 ////////////////////////////////////////////////////////////////////////////////
3650 //! \purpose
3651 //! Execute video processing pipeline.
3652 //! For CSC/Scaling after decode by decode context.
3653 //! \params
3654 //! [in] pVaDrvCtxv : VA Driver Context
3655 //! [in] vaCtxID : VA Context ID
3656 //! [in] srcSurface : Input surface ID
3657 //! [in] srcRect : Rectangle of the input surface region
3658 //! [in] dstSurface : Output surface ID
3659 //! [in] dstRect : Rectangle of the output surface region
3660 //! [out] None
3661 //! \returns VA_STATUS_SUCCESS if call succeeds
3662 ////////////////////////////////////////////////////////////////////////////////
3663 VAStatus DdiVp_VideoProcessPipeline(
3664 VADriverContextP pVaDrvCtx,
3665 VAContextID vpCtxID,
3666 VASurfaceID srcSurface,
3667 VARectangle *srcRect,
3668 VASurfaceID dstSurface,
3669 VARectangle *dstRect)
3670 {
3671 PERF_UTILITY_AUTO(__FUNCTION__, PERF_VP, PERF_LEVEL_DDI);
3672
3673 VAStatus vaStatus;
3674 uint32_t ctxType;
3675 PDDI_VP_CONTEXT pVpCtx;
3676
3677 VP_DDI_FUNCTION_ENTER;
3678 vaStatus = VA_STATUS_SUCCESS;
3679 DDI_CHK_NULL(pVaDrvCtx, "nullptr pVaDrvCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
3680
3681 pVpCtx = (PDDI_VP_CONTEXT)DdiMedia_GetContextFromContextID(pVaDrvCtx, vpCtxID, &ctxType);
3682 DDI_CHK_NULL(pVpCtx, "nullptr pVpCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
3683
3684 vaStatus = DdiVp_BeginPicture(pVaDrvCtx, vpCtxID, dstSurface);
3685 DDI_CHK_RET(vaStatus, "VP BeginPicture failed");
3686
3687 //Set parameters
3688 VAProcPipelineParameterBuffer* pInputPipelineParam = (VAProcPipelineParameterBuffer*)MOS_AllocAndZeroMemory(sizeof(VAProcPipelineParameterBuffer));
3689 DDI_CHK_NULL(pInputPipelineParam, "nullptr pInputPipelineParam", VA_STATUS_ERROR_ALLOCATION_FAILED);
3690
3691 pInputPipelineParam->surface_region = srcRect;
3692 pInputPipelineParam->output_region = dstRect;
3693 pInputPipelineParam->surface = srcSurface;
3694
3695 vaStatus = DdiVp_SetProcPipelineParams(pVaDrvCtx, pVpCtx, pInputPipelineParam);
3696 if(vaStatus != VA_STATUS_SUCCESS)
3697 {
3698 MOS_FreeMemory(pInputPipelineParam);
3699 DDI_ASSERTMESSAGE("VP SetProcPipelineParams failed.");
3700 return vaStatus;
3701 }
3702
3703 vaStatus = DdiVp_EndPicture(pVaDrvCtx, vpCtxID);
3704 if(vaStatus != VA_STATUS_SUCCESS)
3705 {
3706 MOS_FreeMemory(pInputPipelineParam);
3707 DDI_ASSERTMESSAGE("VP EndPicture failed.");
3708 return vaStatus;
3709 }
3710
3711 MOS_FreeMemory(pInputPipelineParam);
3712 return vaStatus;
3713 }
3714
3715 ////////////////////////////////////////////////////////////////////////////////
3716 //! \purpose Check if the format contains alpha channel
3717 //! \params
3718 //! [in] pSurface : VpHal Surface
3719 //! [out] None
3720 //! \returns true if the format of surface contains alpha channel
3721 ////////////////////////////////////////////////////////////////////////////////
3722 static bool hasAlphaInSurface(PVPHAL_SURFACE pSurface)
3723 {
3724 if (pSurface != nullptr)
3725 {
3726 switch (pSurface->Format)
3727 {
3728 case Format_P8: //P8_UNORM: An 8-bit color index which is used to lookup a 32-bit ARGB value in the texture palette.
3729 case Format_AI44:
3730 case Format_IA44:
3731 case Format_A8R8G8B8:
3732 case Format_A8B8G8R8:
3733 case Format_A8P8:
3734 case Format_AYUV:
3735 case Format_Y410:
3736 case Format_Y416:
3737 case Format_R10G10B10A2:
3738 case Format_B10G10R10A2:
3739 return true;
3740 default:
3741 return false;
3742 }
3743 }
3744
3745 VP_DDI_ASSERTMESSAGE("No surface handle passed in.\n");
3746 return false;
3747 }
3748
3749 ////////////////////////////////////////////////////////////////////////////////
3750 //! \purpose Set alpha blending params for VPHAL input surface
3751 //! \params
3752 //! [in] pVpCtx : VP context
3753 //! [in] uiSurfIndex : uiSurfIndex to the input surface array
3754 //! [in] pPipelineParam : Pipeline paramseter from application (VAProcPipelineParameterBuffer)
3755 //! [out] None
3756 //! \returns VA_STATUS_SUCCESS if call succeeds
3757 ////////////////////////////////////////////////////////////////////////////////
3758 VAStatus
3759 DdiVp_SetProcPipelineBlendingParams(
3760 PDDI_VP_CONTEXT pVpCtx,
3761 uint32_t uiSurfIndex,
3762 VAProcPipelineParameterBuffer* pPipelineParam)
3763 {
3764 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
3765 PVPHAL_SURFACE pSrc;
3766 PVPHAL_SURFACE pTarget;
3767 bool bGlobalAlpha;
3768 bool bPreMultAlpha;
3769
3770 const VABlendState * blend_state = pPipelineParam->blend_state;
3771 bGlobalAlpha = false;
3772 bPreMultAlpha = false;
3773
3774 VP_DDI_FUNCTION_ENTER;
3775 DDI_CHK_NULL(pVpCtx, "Null pVpCtx.", VA_STATUS_ERROR_INVALID_CONTEXT);
3776 DDI_CHK_NULL(pPipelineParam,
3777 "Null pPipelineParam.",
3778 VA_STATUS_ERROR_INVALID_BUFFER);
3779
3780 // initialize
3781 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
3782 DDI_CHK_NULL(pVpHalRenderParams,
3783 "Null pVpHalRenderParams.",
3784 VA_STATUS_ERROR_INVALID_PARAMETER);
3785
3786 pSrc = pVpHalRenderParams->pSrc[uiSurfIndex];
3787 DDI_CHK_NULL(pSrc, "Null pSrc.", VA_STATUS_ERROR_INVALID_SURFACE);
3788
3789 if(nullptr == pVpHalRenderParams->pCompAlpha)
3790 {
3791 pVpHalRenderParams->pCompAlpha = (PVPHAL_ALPHA_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_ALPHA_PARAMS));
3792 DDI_CHK_NULL(pVpHalRenderParams->pCompAlpha, "Null pCompAlpha.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3793 }
3794
3795 // So far vaapi does not have alpha fill mode API.
3796 // And for blending support, we use VPHAL_ALPHA_FILL_MODE_NONE by default.
3797 pTarget = pVpHalRenderParams->pTarget[0];
3798 DDI_CHK_NULL(pTarget, "Null pTarget.", VA_STATUS_ERROR_INVALID_SURFACE);
3799
3800 //For surface with alpha, we need to bypass SFC that could change the output alpha.
3801 if (hasAlphaInSurface(pSrc) &&
3802 hasAlphaInSurface(pTarget))
3803 {
3804 pVpHalRenderParams->pCompAlpha->fAlpha = 0.0f;
3805 pVpHalRenderParams->pCompAlpha->AlphaMode = VPHAL_ALPHA_FILL_MODE_SOURCE_STREAM;
3806 }
3807 else
3808 {
3809 pVpHalRenderParams->pCompAlpha->fAlpha = 1.0f;
3810 pVpHalRenderParams->pCompAlpha->AlphaMode = VPHAL_ALPHA_FILL_MODE_NONE;
3811 }
3812
3813 // First, no Blending
3814 if(!blend_state)
3815 {
3816 if (pSrc->pBlendingParams)
3817 {
3818 pSrc->pBlendingParams->BlendType = BLEND_NONE;
3819 pSrc->pBlendingParams->fAlpha = 1.0;
3820 }
3821
3822 if (pSrc->pLumaKeyParams)
3823 {
3824 pSrc->pLumaKeyParams->LumaLow = 0;
3825 pSrc->pLumaKeyParams->LumaHigh = 0;
3826 }
3827
3828 return VA_STATUS_SUCCESS;
3829 }
3830
3831 // Then, process all blending types
3832
3833 if(blend_state->flags & VA_BLEND_GLOBAL_ALPHA)
3834 bGlobalAlpha = true;
3835
3836 if(blend_state->flags & VA_BLEND_PREMULTIPLIED_ALPHA)
3837 bPreMultAlpha = true;
3838
3839 if(nullptr == pSrc->pBlendingParams)
3840 {
3841 pSrc->pBlendingParams = (PVPHAL_BLENDING_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_BLENDING_PARAMS));
3842 DDI_CHK_NULL(pSrc->pBlendingParams, "Null pBlendingParams.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3843 }
3844
3845 ///////////////////////////////////////////////////////////////////////////////////////////////////
3846 // Surfaces contains alpha value, will be devide into premultiplied and non-premultiplied:
3847 // For premultiplied surface, will support:
3848 // a. per-pixel alpha blending;
3849 // b. per-pixel plus per-plane alpha blending;
3850 // For non-promultilied surface, will support:
3851 // a. per-plane alpha blending;
3852 // b. per-pixel alpha blending;
3853 // c. NOT support per-pixel plus per-plane alpha blending;
3854 // Surfaces NOT contains alpha value, will not be devided into premultiplied or non-premultiplied:
3855 // Will only support per-plane alpha blending.
3856 ///////////////////////////////////////////////////////////////////////////////////////////////////
3857 if(hasAlphaInSurface(pSrc))
3858 {
3859 // For premultiplied surface, we just support four blending types until now
3860 if(bPreMultAlpha && !bGlobalAlpha) // Do per-pixel alpha blending for premultiplied surface.
3861 {
3862 pSrc->pBlendingParams->BlendType = BLEND_PARTIAL;
3863 }
3864 else if(bPreMultAlpha && bGlobalAlpha) // Do per-pixel plus per-plane alpha blending For premultiplied surface.
3865 {
3866 if(blend_state->global_alpha < 1.0f)
3867 {
3868 pSrc->pBlendingParams->BlendType = BLEND_CONSTANT_PARTIAL;
3869 }
3870 else
3871 {
3872 // Optimization when per-plane alpha value is 1.0
3873 pSrc->pBlendingParams->BlendType = BLEND_PARTIAL;
3874 }
3875 pSrc->pBlendingParams->fAlpha = blend_state->global_alpha;
3876 }
3877 else if(!bPreMultAlpha && bGlobalAlpha) // Do per-plane alpha blending for non-premultiplied surface, not do per-pixel blending
3878 {
3879 pSrc->pBlendingParams->BlendType = BLEND_CONSTANT;
3880 pSrc->pBlendingParams->fAlpha = blend_state->global_alpha;
3881 VP_DDI_ASSERTMESSAGE("BLEND_CONSTANT do not support alpha calculating.\n");
3882 }
3883 else if(!bPreMultAlpha && !bGlobalAlpha) // Do per-pixel alpha blending for non-premultiplied surface
3884 {
3885 pSrc->pBlendingParams->BlendType = BLEND_SOURCE;
3886 VP_DDI_ASSERTMESSAGE("BLEND_SOURCE do not support alpha calculating.\n");
3887 }
3888
3889 // Not support per-plane plus per-pixel alpha blending for non-premultiplied surface.
3890 }
3891 else
3892 {
3893 if(bGlobalAlpha) // Do per-plane alpha blending for surface which not contain alpha value
3894 {
3895 if(blend_state->global_alpha < 1.0f)
3896 {
3897 pSrc->pBlendingParams->BlendType = BLEND_CONSTANT;
3898 pSrc->pBlendingParams->fAlpha = blend_state->global_alpha;
3899 VP_DDI_ASSERTMESSAGE("BLEND_CONSTANT do not support alpha calculating.\n");
3900 }
3901 else
3902 {
3903 pSrc->pBlendingParams->BlendType = BLEND_PARTIAL;
3904 VP_DDI_NORMALMESSAGE("Because BLEND_CONSTANT do not support alpha calculating, use BLEND_PARTIAL instead.\n");
3905 }
3906
3907 // bPreMultAlpha should not be true for surfaces which do not contain alpha value,
3908 // but inorder to make the driver more usable, choose the most reasonable blending mode, but print out a message.
3909 if(bPreMultAlpha)
3910 {
3911 VP_DDI_NORMALMESSAGE("Should not set VA_BLEND_PREMULTIPLIED_ALPHA for surface which do not contain alpha value.\n");
3912 }
3913 }
3914 else
3915 {
3916 pSrc->pBlendingParams->BlendType = BLEND_NONE;
3917 pSrc->pBlendingParams->fAlpha = 1.0;
3918
3919 // bPreMultAlpha should not be true for surfaces which do not contain alpha value,
3920 // but inorder to make the driver more usable, choose the most reasonable blending mode, but print out a message.
3921 if(bPreMultAlpha)
3922 {
3923 VP_DDI_NORMALMESSAGE("Should not set VA_BLEND_PREMULTIPLIED_ALPHA for surface which do not contain alpha value.\n");
3924 }
3925 }
3926 }
3927
3928 if(blend_state->flags & VA_BLEND_LUMA_KEY)
3929 {
3930 if(nullptr == pSrc->pLumaKeyParams)
3931 {
3932 pSrc->pLumaKeyParams = (PVPHAL_LUMAKEY_PARAMS)MOS_AllocAndZeroMemory(sizeof(VPHAL_LUMAKEY_PARAMS));
3933 DDI_CHK_NULL(pSrc->pLumaKeyParams, "Null pLumaKeyParams.", VA_STATUS_ERROR_ALLOCATION_FAILED);
3934 }
3935 pSrc->pLumaKeyParams->LumaLow = (int16_t)(pPipelineParam->blend_state->min_luma * 255);
3936 pSrc->pLumaKeyParams->LumaHigh = (int16_t)(pPipelineParam->blend_state->max_luma * 255);
3937 }
3938
3939 return VA_STATUS_SUCCESS;
3940 }
3941
3942 ////////////////////////////////////////////////////////////////////////////////
3943 //! \purpose Update the future reference frames for VPHAL input surface
3944 //! \params
3945 //! [in] pVpCtx : VP context
3946 //! [in] pVaDrvCtx : VA Driver context
3947 //! [in] pVpHalSrcSurf : VpHal source surface
3948 //! [in] pPipelineParam : Pipeline parameter from application (VAProcPipelineParameterBuffer)
3949 //! [out] None
3950 //! \returns VA_STATUS_SUCCESS if call succeeds
3951 ////////////////////////////////////////////////////////////////////////////////
3952 VAStatus
3953 DdiVp_UpdateProcPipelineFutureReferenceFrames(
3954 PDDI_VP_CONTEXT pVpCtx,
3955 VADriverContextP pVaDrvCtx,
3956 PVPHAL_SURFACE pVpHalSrcSurf,
3957 VAProcPipelineParameterBuffer* pPipelineParam)
3958 {
3959 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
3960 PVPHAL_SURFACE pSurface;
3961 uint32_t i;
3962
3963 PDDI_MEDIA_CONTEXT pMediaCtx;
3964
3965 VP_DDI_FUNCTION_ENTER;
3966
3967 DDI_CHK_NULL(pVpCtx, "Null pVpCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
3968 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
3969 DDI_CHK_NULL(pVpHalSrcSurf, "Null pVpHalSrcSurf!", VA_STATUS_ERROR_INVALID_PARAMETER);
3970 DDI_CHK_NULL(pPipelineParam, "Null pPipelineParam!", VA_STATUS_ERROR_INVALID_PARAMETER);
3971
3972 // initialize
3973 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
3974 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
3975
3976 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
3977 DDI_CHK_NULL(pVpHalRenderParams,
3978 "Null pVpHalRenderParams!",
3979 VA_STATUS_ERROR_INVALID_PARAMETER);
3980
3981 pSurface = pVpHalSrcSurf;
3982
3983 // DDI regard backward_references as future frame, but VPHAL regard pFwdRef as future frame
3984 if (pPipelineParam->backward_references != nullptr)
3985 {
3986 for (i = 0;i < pPipelineParam->num_backward_references; i++)
3987 {
3988 PDDI_MEDIA_SURFACE pRefSurfBuffObj = nullptr;
3989 if(pSurface->pFwdRef == nullptr)
3990 {
3991 pSurface->pFwdRef = (PVPHAL_SURFACE) MOS_AllocAndZeroMemory(sizeof(VPHAL_SURFACE));
3992 DDI_CHK_NULL(pSurface->pFwdRef, "Null pSurface->pFwdRef!", VA_STATUS_ERROR_ALLOCATION_FAILED);
3993
3994 pSurface->pFwdRef->Format = pVpHalSrcSurf->Format;
3995 pSurface->pFwdRef->SurfType = pVpHalSrcSurf->SurfType;
3996 pSurface->pFwdRef->rcSrc = pVpHalSrcSurf->rcSrc;
3997 pSurface->pFwdRef->rcDst = pVpHalSrcSurf->rcDst;
3998 pSurface->pFwdRef->ColorSpace = pVpHalSrcSurf->ColorSpace;
3999 pSurface->pFwdRef->ExtendedGamut = pVpHalSrcSurf->ExtendedGamut;
4000 pSurface->pFwdRef->SampleType = pVpHalSrcSurf->SampleType;
4001 pSurface->pFwdRef->ScalingMode = pVpHalSrcSurf->ScalingMode;
4002 pSurface->pFwdRef->OsResource = pVpHalSrcSurf->OsResource;
4003 pSurface->pFwdRef->dwWidth = pVpHalSrcSurf->dwWidth;
4004 pSurface->pFwdRef->dwHeight = pVpHalSrcSurf->dwHeight;
4005 pSurface->pFwdRef->dwPitch = pVpHalSrcSurf->dwPitch;
4006 pSurface->uFwdRefCount = pPipelineParam->num_backward_references - i;
4007 }
4008 pRefSurfBuffObj = DdiMedia_GetSurfaceFromVASurfaceID(pMediaCtx, pPipelineParam->backward_references[i]);
4009 DDI_CHK_NULL(pRefSurfBuffObj,
4010 "Null pRefSurfBuffObj!",
4011 VA_STATUS_ERROR_INVALID_SURFACE);
4012
4013 pSurface->pFwdRef->OsResource.bo = pRefSurfBuffObj->bo;
4014 pSurface->pFwdRef->OsResource.Format = VpGetFormatFromMediaFormat(pRefSurfBuffObj->format);
4015 pSurface->pFwdRef->OsResource.iWidth = pRefSurfBuffObj->iWidth;
4016 pSurface->pFwdRef->OsResource.iHeight = pRefSurfBuffObj->iHeight;
4017 pSurface->pFwdRef->OsResource.iPitch = pRefSurfBuffObj->iPitch;
4018 pSurface->pFwdRef->OsResource.TileType = VpGetTileTypeFromMediaTileType(pRefSurfBuffObj->TileType);
4019 pSurface->pFwdRef->OsResource.pGmmResInfo = pRefSurfBuffObj->pGmmResourceInfo;
4020
4021 Mos_Solo_SetOsResource(pRefSurfBuffObj->pGmmResourceInfo, &pSurface->OsResource);
4022
4023 pSurface->pFwdRef->FrameID = pRefSurfBuffObj->frame_idx;
4024
4025 pSurface = pSurface->pFwdRef;
4026 }
4027 }
4028
4029 return VA_STATUS_SUCCESS;
4030 }
4031
4032 ////////////////////////////////////////////////////////////////////////////////
4033 //! \purpose Update the past reference frames for VPHAL input surface
4034 //! \params
4035 //! [in] pVpCtx : VP context
4036 //! [in] pVaDrvCtx : VA Driver context
4037 //! [in] pVpHalSrcSurf : VpHal source surface
4038 //! [in] pPipelineParam : Pipeline parameter from application (VAProcPipelineParameterBuffer)
4039 //! [out] None
4040 //! \returns VA_STATUS_SUCCESS if call succeeds
4041 ////////////////////////////////////////////////////////////////////////////////
4042 VAStatus
4043 DdiVp_UpdateProcPipelinePastReferenceFrames(
4044 PDDI_VP_CONTEXT pVpCtx,
4045 VADriverContextP pVaDrvCtx,
4046 PVPHAL_SURFACE pVpHalSrcSurf,
4047 VAProcPipelineParameterBuffer* pPipelineParam)
4048 {
4049 PVPHAL_RENDER_PARAMS pVpHalRenderParams;
4050 PVPHAL_SURFACE pSurface;
4051 uint32_t i;
4052
4053 PDDI_MEDIA_CONTEXT pMediaCtx;
4054
4055 VP_DDI_FUNCTION_ENTER;
4056
4057 DDI_CHK_NULL(pVpCtx, "Null pVpCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
4058 DDI_CHK_NULL(pVaDrvCtx, "Null pVaDrvCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
4059 DDI_CHK_NULL(pVpHalSrcSurf, "Null pVpHalSrcSurf!", VA_STATUS_ERROR_INVALID_PARAMETER);
4060 DDI_CHK_NULL(pPipelineParam, "Null pPipelineParam!", VA_STATUS_ERROR_INVALID_PARAMETER);
4061
4062 // initialize
4063 pMediaCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
4064 DDI_CHK_NULL(pMediaCtx, "Null pMediaCtx!", VA_STATUS_ERROR_INVALID_CONTEXT);
4065
4066 pVpHalRenderParams = VpGetRenderParams(pVpCtx);
4067 DDI_CHK_NULL(pVpHalRenderParams,
4068 "Null pVpHalRenderParams!",
4069 VA_STATUS_ERROR_INVALID_PARAMETER);
4070
4071 pSurface = pVpHalSrcSurf;
4072
4073 // DDI regard forward_references as past frame, but VPHAL regard pBwdRef as past frame
4074 if (pPipelineParam->forward_references != nullptr)
4075 {
4076 for (i = 0;i < pPipelineParam->num_forward_references ; i++)
4077 {
4078 PDDI_MEDIA_SURFACE pRefSurfBuffObj = nullptr;
4079 if(pSurface->pBwdRef == nullptr)
4080 {
4081 pSurface->pBwdRef = (PVPHAL_SURFACE) MOS_AllocAndZeroMemory(sizeof(VPHAL_SURFACE));
4082 DDI_CHK_NULL(pSurface->pBwdRef, "Null pSurface->pBwdRef!", VA_STATUS_ERROR_ALLOCATION_FAILED);
4083
4084 pSurface->pBwdRef->Format = pVpHalSrcSurf->Format;
4085 pSurface->pBwdRef->SurfType = pVpHalSrcSurf->SurfType;
4086 pSurface->pBwdRef->rcSrc = pVpHalSrcSurf->rcSrc;
4087 pSurface->pBwdRef->rcDst = pVpHalSrcSurf->rcDst;
4088 pSurface->pBwdRef->ColorSpace = pVpHalSrcSurf->ColorSpace;
4089 pSurface->pBwdRef->ExtendedGamut = pVpHalSrcSurf->ExtendedGamut;
4090 pSurface->pBwdRef->SampleType = pVpHalSrcSurf->SampleType;
4091 pSurface->pBwdRef->ScalingMode = pVpHalSrcSurf->ScalingMode;
4092 pSurface->pBwdRef->OsResource = pVpHalSrcSurf->OsResource;
4093 pSurface->pBwdRef->dwWidth = pVpHalSrcSurf->dwWidth;
4094 pSurface->pBwdRef->dwHeight = pVpHalSrcSurf->dwHeight;
4095 pSurface->pBwdRef->dwPitch = pVpHalSrcSurf->dwPitch;
4096 pSurface->uBwdRefCount = pPipelineParam->num_forward_references - i;;
4097 }
4098 pRefSurfBuffObj = DdiMedia_GetSurfaceFromVASurfaceID(pMediaCtx, pPipelineParam->forward_references [i]);
4099 DDI_CHK_NULL(pRefSurfBuffObj,
4100 "Null pRefSurfBuffObj!",
4101 VA_STATUS_ERROR_INVALID_SURFACE);
4102
4103 pSurface->pBwdRef->OsResource.bo = pRefSurfBuffObj->bo;
4104 pSurface->pBwdRef->OsResource.Format = VpGetFormatFromMediaFormat(pRefSurfBuffObj->format);
4105 pSurface->pBwdRef->OsResource.iWidth = pRefSurfBuffObj->iWidth;
4106 pSurface->pBwdRef->OsResource.iHeight = pRefSurfBuffObj->iHeight;
4107 pSurface->pBwdRef->OsResource.iPitch = pRefSurfBuffObj->iPitch;
4108 pSurface->pBwdRef->OsResource.TileType = VpGetTileTypeFromMediaTileType(pRefSurfBuffObj->TileType);
4109 pSurface->pBwdRef->OsResource.pGmmResInfo = pRefSurfBuffObj->pGmmResourceInfo;
4110
4111 Mos_Solo_SetOsResource(pRefSurfBuffObj->pGmmResourceInfo, &pSurface->OsResource);
4112
4113 pSurface->pBwdRef->FrameID = pRefSurfBuffObj->frame_idx;
4114
4115 pSurface = pSurface->pBwdRef;
4116 }
4117 }
4118
4119 return VA_STATUS_SUCCESS;
4120 }
4121
4122 /** \brief Capabilities specification for the color balance filter. */
4123 static VAProcFilterCapColorBalance VpColorBalCap[] = {
4124 /** \brief Hue. */
4125 {VAProcColorBalanceHue,
4126 { PROCAMP_HUE_MIN,
4127 PROCAMP_HUE_MAX,
4128 PROCAMP_HUE_DEFAULT,
4129 PROCAMP_HUE_STEP }
4130 },
4131 /** \brief Saturation. */
4132 {VAProcColorBalanceSaturation,
4133 { PROCAMP_SATURATION_MIN,
4134 PROCAMP_SATURATION_MAX,
4135 PROCAMP_SATURATION_DEFAULT,
4136 PROCAMP_SATURATION_STEP }
4137 },
4138 /** \brief Brightness. */
4139 {VAProcColorBalanceBrightness,
4140 { PROCAMP_BRIGHTNESS_MIN,
4141 PROCAMP_BRIGHTNESS_MAX,
4142 PROCAMP_BRIGHTNESS_DEFAULT,
4143 PROCAMP_BRIGHTNESS_STEP }
4144 },
4145 /** \brief Contrast. */
4146 {VAProcColorBalanceContrast,
4147 { PROCAMP_CONTRAST_MIN,
4148 PROCAMP_CONTRAST_MAX,
4149 PROCAMP_CONTRAST_DEFAULT,
4150 PROCAMP_CONTRAST_STEP }
4151 },
4152 /** \brief Automatically adjusted contrast. */
4153 {VAProcColorBalanceAutoContrast,
4154 { 0.0F, 0.0F, 0.0F, 0.0F }
4155 }
4156 };
4157
4158 ////////////////////////////////////////////////////////////////////////////////
4159 //! \purpose Query video processing filter capabilities
4160 //! \params
4161 //! [in] pVaDrvCtx : VA Driver context
4162 //! [in] pVaCtxID : VA context ID
4163 //! [in] type :
4164 //! [inout] filter_caps :
4165 //! [inout] num_filter_caps :
4166 //! [out] None
4167 //! \returns VA_STATUS_SUCCESS if call succeeds
4168 //! THIS
4169 ////////////////////////////////////////////////////////////////////////////////
4170 VAStatus
4171 DdiVp_QueryVideoProcFilterCaps (
4172 VADriverContextP pVaDrvCtx,
4173 VAContextID pVaCtxID,
4174 int32_t type,
4175 void *filter_caps,
4176 uint32_t *num_filter_caps
4177 )
4178 {
4179 #define QUERY_CAPS_ATTRIBUTE 1 /* query the actual filter caps attribute in vp module */
4180
4181 uint32_t uCnt = 0; /* used for loop */
4182 uint32_t uQueryCapsNum = 0; /* the filter caps number queried by app layer */
4183 uint32_t uExistCapsNum = 0; /* the actual number of filters in vp module */
4184 uint32_t uQueryFlag = 0; /* QUERY_CAPS_ATTRIBUTE: search caps attribute */
4185 PDDI_MEDIA_CONTEXT mediaDrvCtx = nullptr;
4186
4187 VP_DDI_FUNCTION_ENTER;
4188
4189 DDI_CHK_NULL (num_filter_caps, "Null num_filter_caps.", VA_STATUS_ERROR_INVALID_PARAMETER);
4190 DDI_CHK_NULL (pVaDrvCtx, "Null pVaDrvCtx.", VA_STATUS_ERROR_INVALID_PARAMETER);
4191
4192 mediaDrvCtx = DdiMedia_GetMediaContext(pVaDrvCtx);
4193 DDI_CHK_NULL (mediaDrvCtx, "Null mediaDrvCtx.", VA_STATUS_ERROR_INVALID_PARAMETER);
4194
4195 if (*num_filter_caps != 0)
4196 {
4197 /* return filter caps attribute */
4198 uQueryFlag = QUERY_CAPS_ATTRIBUTE;
4199 /* check filter_caps pointer to fill in the filter_caps */
4200 DDI_CHK_NULL (filter_caps, "Null filter_caps.", VA_STATUS_ERROR_INVALID_PARAMETER);
4201 }
4202
4203 uQueryCapsNum = *num_filter_caps;
4204
4205 switch (type)
4206 {
4207 /* Noise reduction filter */
4208 case VAProcFilterNoiseReduction:
4209 uExistCapsNum = 1;
4210 /* set input filter caps number to the actual number of filters in vp module */
4211 *num_filter_caps = uExistCapsNum;
4212 /* set the actual filter caps attribute in vp module */
4213 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4214 {
4215 VAProcFilterCap* baseCap = (VAProcFilterCap*) filter_caps;
4216
4217 if (uQueryCapsNum < uExistCapsNum)
4218 {
4219 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4220 }
4221
4222 baseCap->range.min_value = NOISEREDUCTION_MIN;
4223 baseCap->range.max_value = NOISEREDUCTION_MAX;
4224 baseCap->range.default_value = NOISEREDUCTION_DEFAULT;
4225 baseCap->range.step = NOISEREDUCTION_STEP;
4226 }
4227 break;
4228
4229 /* HVS Noise reduction filter */
4230 case VAProcFilterHVSNoiseReduction:
4231 if (mediaDrvCtx)
4232 {
4233 if (MEDIA_IS_SKU(&mediaDrvCtx->SkuTable, FtrHVSDenoise))
4234 {
4235 uExistCapsNum = 4;
4236 *num_filter_caps = uExistCapsNum;
4237 }
4238 else
4239 {
4240 uExistCapsNum = 0;
4241 *num_filter_caps = uExistCapsNum;
4242 }
4243 }
4244 else
4245 {
4246 VP_DDI_ASSERTMESSAGE("mediaDrvCtx is null pointer.\n");
4247 return VA_STATUS_ERROR_INVALID_CONTEXT;
4248 }
4249 break;
4250
4251 /* Deinterlacing filter */
4252 case VAProcFilterDeinterlacing:
4253 uExistCapsNum = 3;
4254 /* set input filter caps number to the actual number of filters in vp module */
4255 *num_filter_caps = uExistCapsNum;
4256 /* set the actual filter caps attribute in vp module */
4257 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4258 {
4259 VAProcFilterCapDeinterlacing* diCap = (VAProcFilterCapDeinterlacing*) filter_caps;
4260
4261 if (uQueryCapsNum < uExistCapsNum)
4262 {
4263 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4264 }
4265
4266 diCap[0].type = VAProcDeinterlacingBob;
4267 diCap[1].type = VAProcDeinterlacingMotionAdaptive;
4268 diCap[2].type = VAProcDeinterlacingMotionCompensated;
4269 }
4270 break;
4271
4272 /* Sharpening filter. */
4273 case VAProcFilterSharpening:
4274 uExistCapsNum = 1;
4275 /* set input filter caps number to the actual number of filters in vp module */
4276 *num_filter_caps = uExistCapsNum;
4277 /* set the actual filter caps attribute in vp module */
4278 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4279 {
4280 VAProcFilterCap* baseCap;
4281
4282 if (uQueryCapsNum < uExistCapsNum)
4283 {
4284 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4285 }
4286
4287 baseCap = (VAProcFilterCap*) filter_caps;
4288 baseCap->range.min_value = EDGEENHANCEMENT_MIN;
4289 baseCap->range.max_value = EDGEENHANCEMENT_MAX;
4290 baseCap->range.default_value = EDGEENHANCEMENT_DEFAULT;
4291 baseCap->range.step = EDGEENHANCEMENT_STEP;
4292 }
4293 break;
4294
4295 /* Color balance parameters. */
4296 case VAProcFilterColorBalance:
4297 uExistCapsNum = sizeof (VpColorBalCap)/sizeof (VAProcFilterCapColorBalance);
4298 /* set input filter caps number to the actual number of filters in vp module */
4299 *num_filter_caps = uExistCapsNum;
4300 /* set the actual filter caps attribute in vp module */
4301 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4302 {
4303 VAProcFilterCapColorBalance* ColorBalCap;
4304
4305 if (uQueryCapsNum < uExistCapsNum)
4306 {
4307 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4308 }
4309
4310 for (uCnt=0 ; uCnt<uQueryCapsNum ; uCnt++)
4311 {
4312 /* the actual filter caps attribute is not enough */
4313 if (uCnt >= uExistCapsNum)
4314 {
4315 break;
4316 }
4317
4318 ColorBalCap = (VAProcFilterCapColorBalance*) filter_caps+uCnt;
4319 ColorBalCap->type = VpColorBalCap[uCnt].type;
4320 ColorBalCap->range.default_value = VpColorBalCap[uCnt].range.default_value;
4321 ColorBalCap->range.max_value = VpColorBalCap[uCnt].range.max_value;
4322 ColorBalCap->range.min_value = VpColorBalCap[uCnt].range.min_value;
4323 ColorBalCap->range.step = VpColorBalCap[uCnt].range.step;
4324 }
4325 }
4326 break;
4327 case VAProcFilterSkinToneEnhancement:
4328 uExistCapsNum = 1;
4329 *num_filter_caps = uExistCapsNum;
4330 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4331 {
4332 VAProcFilterCap* baseCap = (VAProcFilterCap *)filter_caps;
4333
4334 if (uQueryCapsNum < uExistCapsNum)
4335 {
4336 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4337 }
4338
4339 baseCap->range.min_value = STE_MIN;
4340 baseCap->range.max_value = STE_MAX;
4341 baseCap->range.default_value = STE_DEFAULT;
4342 baseCap->range.step = STE_STEP;
4343 }
4344 break;
4345
4346 case VAProcFilterTotalColorCorrection:
4347 uExistCapsNum = 6;
4348 *num_filter_caps = uExistCapsNum;
4349 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4350 {
4351 VAProcFilterCapTotalColorCorrection* TccCap;
4352
4353 if (uQueryCapsNum < uExistCapsNum)
4354 {
4355 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4356 }
4357
4358 for (uCnt = 0; uCnt < uQueryCapsNum; uCnt++)
4359 {
4360 if (uCnt >= uExistCapsNum)
4361 break;
4362
4363 TccCap = (VAProcFilterCapTotalColorCorrection *)filter_caps + uCnt;
4364 TccCap->type = (VAProcTotalColorCorrectionType)((uint32_t)VAProcTotalColorCorrectionRed + uCnt);
4365 TccCap->range.min_value = TCC_MIN;
4366 TccCap->range.max_value = TCC_MAX;
4367 TccCap->range.default_value = TCC_DEFAULT;
4368 TccCap->range.step = TCC_STEP;
4369 }
4370 }
4371 break;
4372 case VAProcFilterHighDynamicRangeToneMapping:
4373 {
4374 if (mediaDrvCtx)
4375 {
4376 if (MEDIA_IS_SKU(&mediaDrvCtx->SkuTable, FtrHDR))
4377 {
4378 uExistCapsNum = 1;
4379 *num_filter_caps = uExistCapsNum;
4380 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4381 {
4382 VAProcFilterCapHighDynamicRange *HdrTmCap = (VAProcFilterCapHighDynamicRange *)filter_caps;
4383
4384 if (uQueryCapsNum < uExistCapsNum)
4385 {
4386 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4387 }
4388
4389 if (HdrTmCap)
4390 {
4391 HdrTmCap->metadata_type = VAProcHighDynamicRangeMetadataHDR10;
4392 HdrTmCap->caps_flag = VA_TONE_MAPPING_HDR_TO_HDR | VA_TONE_MAPPING_HDR_TO_SDR | VA_TONE_MAPPING_HDR_TO_EDR;
4393 }
4394 }
4395 }
4396 else
4397 {
4398 uExistCapsNum = 0;
4399 *num_filter_caps = uExistCapsNum;
4400 }
4401 }
4402 else
4403 {
4404 VP_DDI_ASSERTMESSAGE("mediaDrvCtx is null pointer.\n");
4405 return VA_STATUS_ERROR_INVALID_CONTEXT;
4406 }
4407 break;
4408 }
4409 #if VA_CHECK_VERSION(1, 12, 0)
4410 case VAProcFilter3DLUT:
4411 uExistCapsNum = 0;
4412 *num_filter_caps = uExistCapsNum;
4413 /* 3DLUT is supported in VEBOX on Gen11+*/
4414 if (!MEDIA_IS_SKU(&mediaDrvCtx->SkuTable, FtrDisableVEBoxFeatures))
4415 {
4416 /* 3DLUT exposes 3 kinds of caps on Gen11+*/
4417 if (mediaDrvCtx->platform.eRenderCoreFamily >= IGFX_GEN12_CORE)
4418 {
4419 uExistCapsNum = 3;
4420 *num_filter_caps = uExistCapsNum;
4421 /* set the actual filter caps attribute in vp module */
4422 if (uQueryFlag == QUERY_CAPS_ATTRIBUTE)
4423 {
4424 if (uQueryCapsNum < uExistCapsNum)
4425 {
4426 return VA_STATUS_ERROR_MAX_NUM_EXCEEDED;
4427 }
4428 uint32_t channel_mapping = VA_3DLUT_CHANNEL_RGB_RGB |
4429 VA_3DLUT_CHANNEL_YUV_RGB |
4430 VA_3DLUT_CHANNEL_VUY_RGB;
4431
4432 VAProcFilterCap3DLUT* lut3DCap = nullptr;
4433 /* 17^3 */
4434 lut3DCap = (VAProcFilterCap3DLUT *)filter_caps + 0;
4435 lut3DCap->lut_size = 17;
4436 lut3DCap->lut_stride[0] = 17;
4437 lut3DCap->lut_stride[1] = 17;
4438 lut3DCap->lut_stride[2] = 32;
4439 lut3DCap->bit_depth = 16;
4440 lut3DCap->num_channel = 4;
4441 lut3DCap->channel_mapping = channel_mapping;
4442 /* 33^3 */
4443 lut3DCap = (VAProcFilterCap3DLUT *)filter_caps + 1;
4444 lut3DCap->lut_size = 33;
4445 lut3DCap->lut_stride[0] = 33;
4446 lut3DCap->lut_stride[1] = 33;
4447 lut3DCap->lut_stride[2] = 64;
4448 lut3DCap->bit_depth = 16;
4449 lut3DCap->num_channel = 4;
4450 lut3DCap->channel_mapping = channel_mapping;
4451 /* 65^3 */
4452 lut3DCap = (VAProcFilterCap3DLUT *)filter_caps + 2;
4453 lut3DCap->lut_size = 65;
4454 lut3DCap->lut_stride[0] = 65;
4455 lut3DCap->lut_stride[1] = 65;
4456 lut3DCap->lut_stride[2] = 128;
4457 lut3DCap->bit_depth = 16;
4458 lut3DCap->num_channel = 4;
4459 lut3DCap->channel_mapping = channel_mapping;
4460 }
4461 }
4462 }
4463 break;
4464 #endif
4465 case VAProcFilterCount:
4466 case VAProcFilterNone:
4467 return VA_STATUS_ERROR_INVALID_VALUE;
4468
4469 default:
4470 return VA_STATUS_ERROR_UNSUPPORTED_FILTER;
4471
4472 }
4473
4474 return VA_STATUS_SUCCESS;
4475 }// DdiVp_QueryVideoProcFilterCaps()
4476
4477 VAStatus DdiVp_SetGpuPriority(
4478 PDDI_VP_CONTEXT pVpCtx,
4479 int32_t priority
4480 )
4481 {
4482 DDI_CHK_NULL(pVpCtx, "nullptr pVpCtx", VA_STATUS_ERROR_INVALID_CONTEXT);
4483
4484 //Set the priority for Gpu
4485 if(pVpCtx->pVpHal != nullptr)
4486 {
4487 PMOS_INTERFACE osInterface = pVpCtx->pVpHal->GetOsInterface();
4488 DDI_CHK_NULL(osInterface, "nullptr osInterface.", VA_STATUS_ERROR_ALLOCATION_FAILED);
4489 osInterface->pfnSetGpuPriority(osInterface, priority);
4490 }
4491
4492 return VA_STATUS_SUCCESS;
4493 }
4494