1 /*
2 * Copyright (c) 2024, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file vp_l0_fc_filter.cpp
24 //! \brief Defines the common interface for denoise
25 //! this file is for the base interface which is shared by all l0 fc in driver.
26 //!
27 #include "vp_l0_fc_filter.h"
28 #include "vp_render_cmd_packet.h"
29 #include "igvpfc_common_args.h"
30 #include "igvpfc_fp_args.h"
31 #include "igvpfc_444PL3_input_args.h"
32 #include <vector>
33
34 namespace vp
35 {
36
VpL0FcFilter(PVP_MHWINTERFACE vpMhwInterface)37 VpL0FcFilter::VpL0FcFilter(PVP_MHWINTERFACE vpMhwInterface) : VpFilter(vpMhwInterface)
38 {
39 }
40
Init()41 MOS_STATUS VpL0FcFilter::Init()
42 {
43 VP_FUNC_CALL();
44
45 return MOS_STATUS_SUCCESS;
46 }
47
Prepare()48 MOS_STATUS VpL0FcFilter::Prepare()
49 {
50 VP_FUNC_CALL();
51
52 return MOS_STATUS_SUCCESS;
53 }
54
Destroy()55 MOS_STATUS VpL0FcFilter::Destroy()
56 {
57 VP_FUNC_CALL();
58
59 if (m_renderL0FcParams)
60 {
61 MOS_Delete(m_renderL0FcParams);
62 m_renderL0FcParams = nullptr;
63 }
64
65 for (auto &handle : m_fcCommonKrnArgs)
66 {
67 KRN_ARG &krnArg = handle.second;
68 MOS_FreeMemAndSetNull(krnArg.pData);
69 }
70 for (auto &handle : m_fcFastExpressKrnArgs)
71 {
72 KRN_ARG &krnArg = handle.second;
73 MOS_FreeMemAndSetNull(krnArg.pData);
74 }
75 for (auto &handle : m_fc444PL3InputKrnArgs)
76 {
77 KRN_ARG &krnArg = handle.second;
78 MOS_FreeMemAndSetNull(krnArg.pData);
79 }
80
81 return MOS_STATUS_SUCCESS;
82 }
83
Init()84 void L0_FC_KERNEL_PARAM::Init()
85 {
86 kernelArgs.clear();
87 kernelName.clear();
88 kernelId = kernelCombinedFc;
89 threadWidth = 0;
90 threadHeight = 0;
91 kernelConfig = {};
92 kernelStatefulSurfaces.clear();
93 }
94
Init()95 void _RENDER_L0_FC_PARAMS::Init()
96 {
97 fc_kernelParams.clear();
98 }
99
SetExecuteEngineCaps(SwFilterPipe * executingPipe,VP_EXECUTE_CAPS vpExecuteCaps)100 MOS_STATUS VpL0FcFilter::SetExecuteEngineCaps(
101 SwFilterPipe *executingPipe,
102 VP_EXECUTE_CAPS vpExecuteCaps)
103 {
104 VP_FUNC_CALL();
105
106 m_executingPipe = executingPipe;
107 m_executeCaps = vpExecuteCaps;
108
109 return MOS_STATUS_SUCCESS;
110 }
111
InitKrnParams(L0_FC_KERNEL_PARAMS & krnParams,SwFilterPipe & executingPipe)112 MOS_STATUS VpL0FcFilter::InitKrnParams(L0_FC_KERNEL_PARAMS &krnParams, SwFilterPipe &executingPipe)
113 {
114 VP_FUNC_CALL();
115
116 krnParams.clear();
117
118 L0_FC_COMP_PARAM compParam = {};
119 VP_RENDER_CHK_STATUS_RETURN(InitCompParam(executingPipe, compParam));
120 PrintCompParam(compParam);
121 ReportDiffLog(compParam);
122
123 L0_FC_KERNEL_PARAM param = {};
124 for (uint32_t i = 0; i < compParam.layerNumber; ++i)
125 {
126 if (compParam.inputLayersParam[i].needIntermediaSurface)
127 {
128 VP_RENDER_CHK_STATUS_RETURN(GenerateFc444PL3InputParam(compParam.inputLayersParam[i], compParam.layerNumber, param, i));
129 krnParams.push_back(param);
130 }
131 }
132
133 if (FastExpressConditionMeet(compParam))
134 {
135 VP_RENDER_CHK_STATUS_RETURN(GenerateFcFastExpressKrnParam(compParam, param));
136 }
137 else
138 {
139 VP_RENDER_CHK_STATUS_RETURN(GenerateFcCommonKrnParam(compParam, param));
140 }
141 //Set Perf Tag should be called after Generate Krn Param
142 VP_PUBLIC_CHK_STATUS_RETURN(SetPerfTag(compParam, param.kernelConfig.perfTag));
143 krnParams.push_back(param);
144
145 return MOS_STATUS_SUCCESS;
146 }
147
GenerateFc444PL3InputParam(L0_FC_LAYER_PARAM & layer,uint32_t layerNumber,L0_FC_KERNEL_PARAM & param,uint32_t layerIndex)148 MOS_STATUS VpL0FcFilter::GenerateFc444PL3InputParam(L0_FC_LAYER_PARAM &layer, uint32_t layerNumber, L0_FC_KERNEL_PARAM ¶m, uint32_t layerIndex)
149 {
150 VP_FUNC_CALL();
151 VP_PUBLIC_CHK_NULL_RETURN(m_pvpMhwInterface);
152 VP_PUBLIC_CHK_NULL_RETURN(m_pvpMhwInterface->m_vpPlatformInterface);
153 param = {};
154 uint32_t localSize[3] = {128, 2, 1}; // localWidth, localHeight, localDepth
155 uint32_t threadWidth = layer.surf->osSurface->dwWidth / localSize[0] + (layer.surf->osSurface->dwWidth % localSize[0] != 0);
156 uint32_t threadHeight = layer.surf->osSurface->dwHeight / localSize[1] +(layer.surf->osSurface->dwHeight % localSize[1] != 0);
157 KERNEL_ARGS krnArgs = {};
158 KERNEL_ARG_INDEX_SURFACE_MAP krnStatefulSurfaces = {};
159 uint32_t inputChannelIndices[4] = {};
160 uint32_t outputChannelIndices[4] = {};
161 uint32_t planeChannelIndics = 0;
162 std::string krnName = "ImageRead_fc_444PL3_input";
163
164 auto handle = m_pvpMhwInterface->m_vpPlatformInterface->GetKernelPool().find(krnName);
165 VP_PUBLIC_CHK_NOT_FOUND_RETURN(handle, &m_pvpMhwInterface->m_vpPlatformInterface->GetKernelPool());
166 KERNEL_BTIS kernelBtis = handle->second.GetKernelBtis();
167 KERNEL_ARGS kernelArgs = handle->second.GetKernelArgs();
168
169 VP_PUBLIC_CHK_STATUS_RETURN(ConvertInputChannelIndicesToKrnParam(layer.surf->osSurface->Format, inputChannelIndices));
170 VP_PUBLIC_CHK_STATUS_RETURN(ConvertOuputChannelIndicesToKrnParam(layer.interMediaOverwriteSurface, outputChannelIndices));
171 for (auto const &kernelArg : kernelArgs)
172 {
173 uint32_t uIndex = kernelArg.uIndex;
174 auto argHandle = m_fc444PL3InputKrnArgs.find(uIndex);
175 if (argHandle == m_fc444PL3InputKrnArgs.end())
176 {
177 KRN_ARG krnArg = {};
178 argHandle = m_fc444PL3InputKrnArgs.insert(std::make_pair(uIndex, krnArg)).first;
179 VP_PUBLIC_CHK_NOT_FOUND_RETURN(argHandle, &m_fc444PL3InputKrnArgs);
180 }
181 KRN_ARG &krnArg = argHandle->second;
182 bool bInit = true;
183 krnArg.uIndex = uIndex;
184 krnArg.eArgKind = kernelArg.eArgKind;
185 if (krnArg.pData == nullptr)
186 {
187 if (kernelArg.uSize > 0)
188 {
189 krnArg.uSize = kernelArg.uSize;
190 krnArg.pData = MOS_AllocAndZeroMemory(kernelArg.uSize);
191 }
192 }
193 else
194 {
195 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, kernelArg.uSize);
196 MOS_ZeroMemory(krnArg.pData, krnArg.uSize);
197 }
198
199 VP_PUBLIC_CHK_STATUS_RETURN(SetupSingleFc444PL3InputKrnArg(localSize, krnArg, bInit, inputChannelIndices, outputChannelIndices, planeChannelIndics));
200
201 if (bInit)
202 {
203 krnArgs.push_back(krnArg);
204 }
205 }
206
207 for (auto const &kernelBti : kernelBtis)
208 {
209 uint32_t uIndex = kernelBti.first;
210 SURFACE_PARAMS surfaceParam = {};
211 bool bInit = true;
212
213 VP_PUBLIC_CHK_STATUS_RETURN(SetupSingleFc444PL3InputBti(uIndex, surfaceParam, layerIndex, bInit));
214
215 if (bInit)
216 {
217 krnStatefulSurfaces.insert(std::make_pair(uIndex, surfaceParam));
218 }
219 }
220
221 param.kernelArgs = krnArgs;
222 param.kernelName = krnName;
223 param.kernelId = kernelL0Fc444PL3Input;
224 param.threadWidth = threadWidth;
225 param.threadHeight = threadHeight;
226 param.localWidth = localSize[0];
227 param.localHeight = localSize[1];
228 param.kernelStatefulSurfaces = krnStatefulSurfaces;
229
230 return MOS_STATUS_SUCCESS;
231 }
232
SetupSingleFc444PL3InputKrnArg(uint32_t localSize[3],KRN_ARG & krnArg,bool & bInit,uint32_t inputChannelIndices[4],uint32_t outputChannelIndices[4],uint32_t planeChannelIndices)233 MOS_STATUS VpL0FcFilter::SetupSingleFc444PL3InputKrnArg(uint32_t localSize[3], KRN_ARG &krnArg, bool &bInit, uint32_t inputChannelIndices[4], uint32_t outputChannelIndices[4], uint32_t planeChannelIndices)
234 {
235 switch (krnArg.uIndex)
236 {
237 case FC_444PL3_INPUT_IMAGEREAD_INPUTINDEX:
238 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
239 static_cast<uint32_t *>(krnArg.pData)[0] = inputChannelIndices[0];
240 static_cast<uint32_t *>(krnArg.pData)[1] = inputChannelIndices[1];
241 static_cast<uint32_t *>(krnArg.pData)[2] = inputChannelIndices[2];
242 static_cast<uint32_t *>(krnArg.pData)[3] = inputChannelIndices[3];
243 break;
244 case FC_444PL3_INPUT_IMAGEREAD_OUTPUTINDEX:
245 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
246 static_cast<uint32_t *>(krnArg.pData)[0] = outputChannelIndices[0];
247 static_cast<uint32_t *>(krnArg.pData)[1] = outputChannelIndices[1];
248 static_cast<uint32_t *>(krnArg.pData)[2] = outputChannelIndices[2];
249 static_cast<uint32_t *>(krnArg.pData)[3] = outputChannelIndices[3];
250 break;
251 case FC_444PL3_INPUT_IMAGEREAD_PLANEINDEX:
252 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
253 *(uint32_t *)krnArg.pData = planeChannelIndices;
254 break;
255 case FC_444PL3_INPUT_IMAGEREAD_ENQUEUED_LOCAL_SIZE:
256 case FC_444PL3_INPUT_IMAGEREAD_LOCAL_SIZE:
257 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
258 static_cast<uint32_t *>(krnArg.pData)[0] = localSize[0];
259 static_cast<uint32_t *>(krnArg.pData)[1] = localSize[1];
260 static_cast<uint32_t *>(krnArg.pData)[2] = localSize[2];
261 break;
262 default:
263 bInit = false;
264 break;
265 }
266
267 return MOS_STATUS_SUCCESS;
268 }
269
SetupSingleFc444PL3InputBti(uint32_t uIndex,SURFACE_PARAMS & surfaceParam,uint32_t layerIndex,bool & bInit)270 MOS_STATUS VpL0FcFilter::SetupSingleFc444PL3InputBti(uint32_t uIndex, SURFACE_PARAMS &surfaceParam, uint32_t layerIndex, bool &bInit)
271 {
272 switch (uIndex)
273 {
274 case FC_444PL3_INPUT_IMAGEREAD_INPUTPLANE0:
275 surfaceParam.surfType = SurfaceType(SurfaceTypeFcInputLayer0 + layerIndex);
276 break;
277 case FC_444PL3_INPUT_IMAGEREAD_INPUTPLANE1:
278 case FC_444PL3_INPUT_IMAGEREAD_INPUTPLANE2:
279 surfaceParam.surfType = SurfaceTypeInvalid;
280 break;
281 case FC_444PL3_INPUT_IMAGEREAD_OUTPUTPLANE:
282 surfaceParam.surfType = SurfaceType(SurfaceTypeFcIntermediaInput + layerIndex);
283 surfaceParam.isOutput = true;
284 break;
285 default:
286 bInit = false;
287 break;
288 }
289
290 return MOS_STATUS_SUCCESS;
291 }
292
GenerateFcCommonKrnParam(L0_FC_COMP_PARAM & compParam,L0_FC_KERNEL_PARAM & param)293 MOS_STATUS VpL0FcFilter::GenerateFcCommonKrnParam(L0_FC_COMP_PARAM &compParam, L0_FC_KERNEL_PARAM ¶m)
294 {
295 VP_FUNC_CALL();
296 VP_PUBLIC_CHK_NULL_RETURN(m_pvpMhwInterface);
297 VP_PUBLIC_CHK_NULL_RETURN(m_pvpMhwInterface->m_vpPlatformInterface);
298
299 param = {};
300 std::vector<L0_FC_KRN_IMAGE_PARAM> imageParams(compParam.layerNumber);
301 L0_FC_KRN_TARGET_PARAM targetParam = {};
302 for (uint32_t i = 0; i < compParam.layerNumber; ++i)
303 {
304 VP_RENDER_CHK_STATUS_RETURN(GenerateInputImageParam(compParam.inputLayersParam[i], compParam.mainCSpace, imageParams.at(i)));
305 }
306 VP_RENDER_CHK_STATUS_RETURN(GenerateTargetParam(compParam, targetParam));
307 PrintKrnParam(imageParams, targetParam);
308
309 uint32_t localSize[3] = {128, 2, 1}; // localWidth, localHeight, localDepth
310 uint32_t threadWidth = targetParam.targetROI.right / localSize[0] + (targetParam.targetROI.right % localSize[0] != 0);
311 uint32_t threadHeight = targetParam.targetROI.bottom / localSize[1] + (targetParam.targetROI.bottom % localSize[1] != 0);
312 KERNEL_ARGS krnArgs = {};
313 KERNEL_ARG_INDEX_SURFACE_MAP krnStatefulSurfaces = {};
314
315 auto handle = m_pvpMhwInterface->m_vpPlatformInterface->GetKernelPool().find("FastComp_fc_common");
316 VP_PUBLIC_CHK_NOT_FOUND_RETURN(handle, &m_pvpMhwInterface->m_vpPlatformInterface->GetKernelPool());
317 KERNEL_BTIS kernelBtis = handle->second.GetKernelBtis();
318 KERNEL_ARGS kernelArgs = handle->second.GetKernelArgs();
319
320 for (auto const &kernelArg : kernelArgs)
321 {
322 uint32_t uIndex = kernelArg.uIndex;
323 auto argHandle = m_fcCommonKrnArgs.find(uIndex);
324 if (argHandle == m_fcCommonKrnArgs.end())
325 {
326 KRN_ARG krnArg = {};
327 argHandle = m_fcCommonKrnArgs.insert(std::make_pair(uIndex, krnArg)).first;
328 VP_PUBLIC_CHK_NOT_FOUND_RETURN(argHandle, &m_fcCommonKrnArgs);
329 }
330 KRN_ARG &krnArg = argHandle->second;
331 bool bInit = true;
332 krnArg.uIndex = uIndex;
333 krnArg.eArgKind = kernelArg.eArgKind;
334 if (krnArg.pData == nullptr)
335 {
336 if (kernelArg.uSize > 0)
337 {
338 krnArg.uSize = kernelArg.uSize;
339 krnArg.pData = MOS_AllocAndZeroMemory(kernelArg.uSize);
340 }
341 }
342 else
343 {
344 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, kernelArg.uSize);
345 MOS_ZeroMemory(krnArg.pData, krnArg.uSize);
346 }
347
348 VP_PUBLIC_CHK_STATUS_RETURN(SetupSingleFcCommonKrnArg(compParam.layerNumber, imageParams, targetParam, localSize, krnArg, bInit));
349
350 if (bInit)
351 {
352 krnArgs.push_back(krnArg);
353 }
354 }
355
356 for (auto const &kernelBti : kernelBtis)
357 {
358 uint32_t uIndex = kernelBti.first;
359 SURFACE_PARAMS surfaceParam = {};
360 bool bInit = true;
361
362 VP_PUBLIC_CHK_STATUS_RETURN(SetupSingleFcCommonBti(uIndex, compParam, surfaceParam, bInit));
363
364 if (bInit)
365 {
366 krnStatefulSurfaces.insert(std::make_pair(uIndex, surfaceParam));
367 }
368 }
369
370 param.kernelArgs = krnArgs;
371 param.kernelName = "FastComp_fc_common";
372 param.kernelId = kernelL0FcCommon;
373 param.threadWidth = threadWidth;
374 param.threadHeight = threadHeight;
375 param.localWidth = localSize[0];
376 param.localHeight = localSize[1];
377 param.kernelStatefulSurfaces = krnStatefulSurfaces;
378
379 return MOS_STATUS_SUCCESS;
380 }
381
SetupSingleFcCommonKrnArg(uint32_t layerNum,std::vector<L0_FC_KRN_IMAGE_PARAM> & imageParams,L0_FC_KRN_TARGET_PARAM & targetParam,uint32_t localSize[3],KRN_ARG & krnArg,bool & bInit)382 MOS_STATUS VpL0FcFilter::SetupSingleFcCommonKrnArg(uint32_t layerNum, std::vector<L0_FC_KRN_IMAGE_PARAM> &imageParams, L0_FC_KRN_TARGET_PARAM &targetParam, uint32_t localSize[3], KRN_ARG &krnArg, bool &bInit)
383 {
384 switch (krnArg.uIndex)
385 {
386 case FC_COMMON_FASTCOMP_LAYERNUMBER:
387 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
388 *(uint32_t *)krnArg.pData = layerNum;
389 break;
390 case FC_COMMON_FASTCOMP_IMAGEPARAM0:
391 if (imageParams.size() > 0)
392 {
393 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
394 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(0)));
395 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(0), sizeof(imageParams.at(0)));
396 }
397 break;
398 case FC_COMMON_FASTCOMP_IMAGEPARAM1:
399 if (imageParams.size() > 1)
400 {
401 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
402 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(1)));
403 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(1), sizeof(imageParams.at(1)));
404 }
405 break;
406 case FC_COMMON_FASTCOMP_IMAGEPARAM2:
407 if (imageParams.size() > 2)
408 {
409 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
410 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(2)));
411 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(2), sizeof(imageParams.at(2)));
412 }
413 break;
414 case FC_COMMON_FASTCOMP_IMAGEPARAM3:
415 if (imageParams.size() > 3)
416 {
417 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
418 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(3)));
419 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(3), sizeof(imageParams.at(3)));
420 }
421 break;
422 case FC_COMMON_FASTCOMP_IMAGEPARAM4:
423 if (imageParams.size() > 4)
424 {
425 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
426 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(4)));
427 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(4), sizeof(imageParams.at(4)));
428 }
429 break;
430 case FC_COMMON_FASTCOMP_IMAGEPARAM5:
431 if (imageParams.size() > 5)
432 {
433 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
434 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(5)));
435 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(5), sizeof(imageParams.at(5)));
436 }
437 break;
438 case FC_COMMON_FASTCOMP_IMAGEPARAM6:
439 if (imageParams.size() > 6)
440 {
441 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
442 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(6)));
443 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(6), sizeof(imageParams.at(6)));
444 }
445 break;
446 case FC_COMMON_FASTCOMP_IMAGEPARAM7:
447 if (imageParams.size() > 7)
448 {
449 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
450 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams.at(7)));
451 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams.at(7), sizeof(imageParams.at(7)));
452 }
453 break;
454
455 break;
456 case FC_COMMON_FASTCOMP_OUTPUTPARAM:
457 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
458 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(targetParam));
459 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &targetParam, sizeof(targetParam));
460 break;
461 case FC_COMMON_FASTCOMP_INLINE_SAMPLER_LINEAR_CLAMP_EDGE:
462 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
463 *(uint32_t *)krnArg.pData = MHW_SAMPLER_FILTER_BILINEAR;
464 break;
465 case FC_COMMON_FASTCOMP_INLINE_SAMPLER_NEAREST_CLAMP_EDGE:
466 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
467 *(uint32_t *)krnArg.pData = MHW_SAMPLER_FILTER_NEAREST;
468 break;
469 case FC_COMMON_FASTCOMP_ENQUEUED_LOCAL_SIZE:
470 case FC_COMMON_FASTCOMP_LOCAL_SIZE:
471 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
472 static_cast<uint32_t *>(krnArg.pData)[0] = localSize[0];
473 static_cast<uint32_t *>(krnArg.pData)[1] = localSize[1];
474 static_cast<uint32_t *>(krnArg.pData)[2] = localSize[2];
475 break;
476 default:
477 bInit = false;
478 break;
479 }
480
481 return MOS_STATUS_SUCCESS;
482 }
483
SetupSingleFcCommonBti(uint32_t uIndex,const L0_FC_COMP_PARAM & compParam,SURFACE_PARAMS & surfaceParam,bool & bInit)484 MOS_STATUS VpL0FcFilter::SetupSingleFcCommonBti(uint32_t uIndex, const L0_FC_COMP_PARAM &compParam, SURFACE_PARAMS &surfaceParam, bool &bInit)
485 {
486 switch (uIndex)
487 {
488 case FC_COMMON_FASTCOMP_INPUT0PL0:
489 if (compParam.layerNumber > 0)
490 {
491 surfaceParam.surfType = compParam.inputLayersParam[0].needIntermediaSurface ?
492 SurfaceTypeFcIntermediaInput : SurfaceTypeFcInputLayer0;
493 if (compParam.inputLayersParam[0].diParams.enabled &&
494 compParam.inputLayersParam[0].diParams.params.DIMode == DI_MODE_BOB)
495 {
496 surfaceParam.needVerticalStirde = true;
497 }
498 }
499 else
500 {
501 surfaceParam.surfType = SurfaceTypeInvalid;
502 }
503 break;
504 case FC_COMMON_FASTCOMP_INPUT1PL0:
505 if (compParam.layerNumber > 1)
506 {
507 surfaceParam.surfType = compParam.inputLayersParam[1].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 1) : SurfaceType(SurfaceTypeFcInputLayer0 + 1);
508 if (compParam.inputLayersParam[1].diParams.enabled &&
509 compParam.inputLayersParam[1].diParams.params.DIMode == DI_MODE_BOB)
510 {
511 surfaceParam.needVerticalStirde = true;
512 }
513 }
514 else
515 {
516 surfaceParam.surfType = SurfaceTypeInvalid;
517 }
518 break;
519 case FC_COMMON_FASTCOMP_INPUT2PL0:
520 if (compParam.layerNumber > 2)
521 {
522 surfaceParam.surfType = compParam.inputLayersParam[2].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 2) : SurfaceType(SurfaceTypeFcInputLayer0 + 2);
523 if (compParam.inputLayersParam[2].diParams.enabled &&
524 compParam.inputLayersParam[2].diParams.params.DIMode == DI_MODE_BOB)
525 {
526 surfaceParam.needVerticalStirde = true;
527 }
528 }
529 else
530 {
531 surfaceParam.surfType = SurfaceTypeInvalid;
532 }
533 break;
534 case FC_COMMON_FASTCOMP_INPUT3PL0:
535 if (compParam.layerNumber > 3)
536 {
537 surfaceParam.surfType = compParam.inputLayersParam[3].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 3) : SurfaceType(SurfaceTypeFcInputLayer0 + 3);
538 if (compParam.inputLayersParam[3].diParams.enabled &&
539 compParam.inputLayersParam[3].diParams.params.DIMode == DI_MODE_BOB)
540 {
541 surfaceParam.needVerticalStirde = true;
542 }
543 }
544 else
545 {
546 surfaceParam.surfType = SurfaceTypeInvalid;
547 }
548 break;
549 case FC_COMMON_FASTCOMP_INPUT4PL0:
550 if (compParam.layerNumber > 4)
551 {
552 surfaceParam.surfType = compParam.inputLayersParam[4].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 4) : SurfaceType(SurfaceTypeFcInputLayer0 + 4);
553 if (compParam.inputLayersParam[4].diParams.enabled &&
554 compParam.inputLayersParam[4].diParams.params.DIMode == DI_MODE_BOB)
555 {
556 surfaceParam.needVerticalStirde = true;
557 }
558 }
559 else
560 {
561 surfaceParam.surfType = SurfaceTypeInvalid;
562 }
563 break;
564 case FC_COMMON_FASTCOMP_INPUT5PL0:
565 if (compParam.layerNumber > 5)
566 {
567 surfaceParam.surfType = compParam.inputLayersParam[5].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 5) : SurfaceType(SurfaceTypeFcInputLayer0 + 5);
568 if (compParam.inputLayersParam[5].diParams.enabled &&
569 compParam.inputLayersParam[5].diParams.params.DIMode == DI_MODE_BOB)
570 {
571 surfaceParam.needVerticalStirde = true;
572 }
573 }
574 else
575 {
576 surfaceParam.surfType = SurfaceTypeInvalid;
577 }
578 break;
579 case FC_COMMON_FASTCOMP_INPUT6PL0:
580 if (compParam.layerNumber > 6)
581 {
582 surfaceParam.surfType = compParam.inputLayersParam[6].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 6) : SurfaceType(SurfaceTypeFcInputLayer0 + 6);
583 if (compParam.inputLayersParam[6].diParams.enabled &&
584 compParam.inputLayersParam[6].diParams.params.DIMode == DI_MODE_BOB)
585 {
586 surfaceParam.needVerticalStirde = true;
587 }
588 }
589 else
590 {
591 surfaceParam.surfType = SurfaceTypeInvalid;
592 }
593 break;
594 case FC_COMMON_FASTCOMP_INPUT7PL0:
595 if (compParam.layerNumber > 7)
596 {
597 surfaceParam.surfType = compParam.inputLayersParam[7].needIntermediaSurface ? SurfaceType(SurfaceTypeFcIntermediaInput + 7) : SurfaceType(SurfaceTypeFcInputLayer0 + 7);
598 if (compParam.inputLayersParam[7].diParams.enabled &&
599 compParam.inputLayersParam[7].diParams.params.DIMode == DI_MODE_BOB)
600 {
601 surfaceParam.needVerticalStirde = true;
602 }
603 }
604 else
605 {
606 surfaceParam.surfType = SurfaceTypeInvalid;
607 }
608 break;
609 case FC_COMMON_FASTCOMP_OUTPUTPL0:
610 surfaceParam.surfType = SurfaceTypeFcTarget0;
611 surfaceParam.isOutput = true;
612 break;
613 case FC_COMMON_FASTCOMP_INPUT0PL1:
614 case FC_COMMON_FASTCOMP_INPUT1PL1:
615 case FC_COMMON_FASTCOMP_INPUT2PL1:
616 case FC_COMMON_FASTCOMP_INPUT3PL1:
617 case FC_COMMON_FASTCOMP_INPUT4PL1:
618 case FC_COMMON_FASTCOMP_INPUT5PL1:
619 case FC_COMMON_FASTCOMP_INPUT6PL1:
620 case FC_COMMON_FASTCOMP_INPUT7PL1:
621 case FC_COMMON_FASTCOMP_OUTPUTPL1:
622 surfaceParam.surfType = SurfaceTypeInvalid;
623 break;
624 default:
625 bInit = false;
626 break;
627 }
628
629 return MOS_STATUS_SUCCESS;
630 }
631
InitCompParam(SwFilterPipe & executingPipe,L0_FC_COMP_PARAM & compParam)632 MOS_STATUS VpL0FcFilter::InitCompParam(SwFilterPipe &executingPipe, L0_FC_COMP_PARAM &compParam)
633 {
634 VP_FUNC_CALL();
635
636 auto &surfGroup = executingPipe.GetSurfacesSetting().surfGroup;
637 compParam.layerNumber = executingPipe.GetSurfaceCount(true);
638 if (SurfaceTypeFcInputLayer0 + compParam.layerNumber - 1 > SurfaceTypeFcInputLayerMax)
639 {
640 VP_RENDER_ASSERTMESSAGE("Invalid source count (%d)!", compParam.layerNumber);
641 VP_RENDER_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
642 }
643
644 // Select default scaling mode for 3D sampler.
645 VPHAL_SCALING_MODE defaultScalingMode = VPHAL_SCALING_NEAREST;
646 VP_PUBLIC_CHK_STATUS_RETURN(GetDefaultScalingMode(defaultScalingMode, executingPipe));
647
648 for (uint32_t i = 0; i < executingPipe.GetSurfaceCount(true); ++i)
649 {
650 VP_RENDER_CHK_STATUS_RETURN(InitLayer(executingPipe, true, i, defaultScalingMode, compParam.inputLayersParam[i]));
651 }
652
653 VP_RENDER_CHK_STATUS_RETURN(InitLayer(executingPipe, false, 0, defaultScalingMode, compParam.outputLayerParam));
654
655 //use target Cspace as main color space instead of using RGB as main Cspace for no obvious difference
656 compParam.mainCSpace = compParam.outputLayerParam.surf->ColorSpace;
657
658 SwFilterColorFill *colorFill = dynamic_cast<SwFilterColorFill *>(executingPipe.GetSwFilter(false, 0, FeatureType::FeatureTypeColorFill));
659 if (colorFill && colorFill->GetSwFilterParams().colorFillParams)
660 {
661 compParam.enableColorFill = true;
662 compParam.colorFillParams = *colorFill->GetSwFilterParams().colorFillParams;
663 }
664 else
665 {
666 compParam.enableColorFill = false;
667 }
668
669 SwFilterAlpha *alpha = dynamic_cast<SwFilterAlpha *>(executingPipe.GetSwFilter(false, 0, FeatureType::FeatureTypeAlpha));
670 if (alpha && alpha->GetSwFilterParams().compAlpha)
671 {
672 compParam.compAlpha = *alpha->GetSwFilterParams().compAlpha;
673 compParam.bAlphaCalculateEnable = alpha->GetSwFilterParams().calculatingAlpha;
674 }
675 else
676 {
677 compParam.bAlphaCalculateEnable = false;
678 compParam.compAlpha = {};
679 }
680
681 return MOS_STATUS_SUCCESS;
682 }
683
InitLayer(SwFilterPipe & executingPipe,bool isInputPipe,int index,VPHAL_SCALING_MODE defaultScalingMode,L0_FC_LAYER_PARAM & layer)684 MOS_STATUS VpL0FcFilter::InitLayer(SwFilterPipe& executingPipe, bool isInputPipe, int index, VPHAL_SCALING_MODE defaultScalingMode, L0_FC_LAYER_PARAM& layer)
685 {
686 VP_FUNC_CALL();
687 auto &surfGroup = executingPipe.GetSurfacesSetting().surfGroup;
688
689 SurfaceType surfId = isInputPipe ? (SurfaceType)(SurfaceTypeFcInputLayer0 + index) : SurfaceTypeFcTarget0;
690 auto surfHandle = surfGroup.find(surfId);
691 VP_PUBLIC_CHK_NOT_FOUND_RETURN(surfHandle, &surfGroup);
692 layer.surf = surfHandle->second;
693
694 VP_PUBLIC_CHK_NULL_RETURN(layer.surf);
695
696 layer.layerID = index;
697 layer.layerIDOrigin = index;
698
699 if (layer.surf->osSurface->Format == Format_RGBP ||
700 layer.surf->osSurface->Format == Format_BGRP)
701 {
702 layer.needIntermediaSurface = true;
703 layer.interMediaOverwriteSurface = Format_A8R8G8B8;
704 }
705 else if (layer.surf->osSurface->Format == Format_444P)
706 {
707 layer.needIntermediaSurface = true;
708 layer.interMediaOverwriteSurface = Format_AYUV;
709 }
710
711 SwFilterScaling *scaling = dynamic_cast<SwFilterScaling *>(executingPipe.GetSwFilter(isInputPipe, index, FeatureType::FeatureTypeScaling));
712 layer.scalingMode = scaling ? scaling->GetSwFilterParams().scalingMode : defaultScalingMode;
713
714 SwFilterRotMir *rotation = dynamic_cast<SwFilterRotMir *>(executingPipe.GetSwFilter(isInputPipe, index, FeatureType::FeatureTypeRotMir));
715 layer.rotation = rotation ? rotation->GetSwFilterParams().rotation : VPHAL_ROTATION_IDENTITY;
716
717 SwFilterDeinterlace *di = dynamic_cast<SwFilterDeinterlace *>(executingPipe.GetSwFilter(isInputPipe, index, FeatureType::FeatureTypeDi));
718 if (di && di->GetSwFilterParams().diParams)
719 {
720 layer.diParams.enabled = true;
721 layer.diParams.params = *di->GetSwFilterParams().diParams;
722 }
723 else
724 {
725 layer.diParams.enabled = false;
726 }
727
728 SwFilterLumakey *lumakey = dynamic_cast<SwFilterLumakey *>(executingPipe.GetSwFilter(isInputPipe, index, FeatureType::FeatureTypeLumakey));
729 if (lumakey && lumakey->GetSwFilterParams().lumaKeyParams)
730 {
731 layer.lumaKey.enabled = true;
732 layer.lumaKey.params = *lumakey->GetSwFilterParams().lumaKeyParams;
733 }
734 else
735 {
736 layer.lumaKey.enabled = false;
737 }
738
739 SwFilterBlending *blending = dynamic_cast<SwFilterBlending *>(executingPipe.GetSwFilter(isInputPipe, index, FeatureType::FeatureTypeBlending));
740 if (blending && blending->GetSwFilterParams().blendingParams)
741 {
742 layer.blendingParams = *blending->GetSwFilterParams().blendingParams;
743 }
744 else
745 {
746 layer.blendingParams.BlendType = BLEND_NONE;
747 }
748
749 //procamp is not enabled for L0 FC
750 SwFilterProcamp *procamp = dynamic_cast<SwFilterProcamp *>(executingPipe.GetSwFilter(isInputPipe, index, FeatureType::FeatureTypeProcamp));
751 if (procamp && procamp->GetSwFilterParams().procampParams)
752 {
753 layer.procampParams = *procamp->GetSwFilterParams().procampParams;
754 }
755 else
756 {
757 layer.procampParams.bEnabled = false;
758 }
759
760 return MOS_STATUS_SUCCESS;
761 }
762
GetDefaultScalingMode(VPHAL_SCALING_MODE & defaultScalingMode,SwFilterPipe & executedPipe)763 MOS_STATUS VpL0FcFilter::GetDefaultScalingMode(VPHAL_SCALING_MODE &defaultScalingMode, SwFilterPipe &executedPipe)
764 {
765 bool isInited = false;
766 // Select default scaling mode for 3D sampler.
767 defaultScalingMode = VPHAL_SCALING_NEAREST;
768
769 if (!PolicyFcHandler::s_forceNearestToBilinearIfBilinearExists)
770 {
771 return MOS_STATUS_SUCCESS;
772 }
773
774 for (uint32_t i = 0; i < executedPipe.GetSurfaceCount(true); ++i)
775 {
776 SwFilterScaling *scaling = dynamic_cast<SwFilterScaling *>(executedPipe.GetSwFilter(true, i, FeatureType::FeatureTypeScaling));
777 if (scaling &&
778 (VPHAL_SCALING_NEAREST == scaling->GetSwFilterParams().scalingMode ||
779 VPHAL_SCALING_BILINEAR == scaling->GetSwFilterParams().scalingMode))
780 {
781 if (isInited)
782 {
783 if (scaling->GetSwFilterParams().scalingMode != defaultScalingMode)
784 {
785 VP_PUBLIC_ASSERTMESSAGE("Different 3D sampler scaling mode being selected!");
786 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
787 }
788 }
789 else
790 {
791 defaultScalingMode = scaling->GetSwFilterParams().scalingMode;
792 isInited = true;
793 }
794 }
795 }
796
797 return MOS_STATUS_SUCCESS;
798 }
799
GetChromaSitingFactor(MOS_FORMAT format,uint8_t & hitSecPlaneFactorX,uint8_t & hitSecPlaneFactorY)800 MOS_STATUS VpL0FcFilter::GetChromaSitingFactor(MOS_FORMAT format, uint8_t& hitSecPlaneFactorX, uint8_t& hitSecPlaneFactorY)
801 {
802 switch (format)
803 {
804 case Format_A8R8G8B8:
805 case Format_X8R8G8B8:
806 case Format_A16R16G16B16:
807 case Format_R10G10B10A2:
808 case Format_AYUV:
809 case Format_A16R16G16B16F:
810 case Format_A8B8G8R8:
811 case Format_X8B8G8R8:
812 case Format_A16B16G16R16:
813 case Format_B10G10R10A2:
814 case Format_A16B16G16R16F:
815 case Format_Y410:
816 case Format_Y416:
817 case Format_400P:
818 case Format_R5G6B5:
819 case Format_R8G8B8:
820 hitSecPlaneFactorX = 1;
821 hitSecPlaneFactorY = 1;
822 break;
823 case Format_NV12:
824 case Format_P010:
825 case Format_P016:
826 case Format_P210:
827 case Format_P216:
828 hitSecPlaneFactorX = 2;
829 hitSecPlaneFactorY = 2;
830 break;
831 case Format_YUY2:
832 case Format_YUYV:
833 case Format_YVYU:
834 case Format_UYVY:
835 case Format_VYUY:
836 case Format_Y210:
837 case Format_Y216:
838 hitSecPlaneFactorX = 2;
839 hitSecPlaneFactorY = 1;
840 break;
841 default:
842 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
843 }
844
845 return MOS_STATUS_SUCCESS;
846 }
847
GetBitNumber(MOS_FORMAT format,uint8_t * pOriginBitNumber,uint8_t * pStoredBitNumber,uint8_t * pAlphaBitNumber)848 MOS_STATUS VpL0FcFilter::GetBitNumber(MOS_FORMAT format, uint8_t *pOriginBitNumber, uint8_t *pStoredBitNumber, uint8_t *pAlphaBitNumber)
849 {
850 uint8_t storedBitNumber = 0;
851 uint8_t originBitNumber = 0;
852 uint8_t alphaBitNumber = 0;
853
854 switch (format)
855 {
856 case Format_A8R8G8B8:
857 case Format_X8R8G8B8:
858 case Format_AYUV:
859 case Format_A8B8G8R8:
860 case Format_X8B8G8R8:
861 storedBitNumber = 8;
862 originBitNumber = 8;
863 alphaBitNumber = 8;
864 break;
865 case Format_A16R16G16B16:
866 case Format_A16B16G16R16:
867 case Format_Y416:
868 storedBitNumber = 16;
869 originBitNumber = 16;
870 alphaBitNumber = 16;
871 break;
872 case Format_R10G10B10A2:
873 case Format_B10G10R10A2:
874 case Format_Y410:
875 storedBitNumber = 10;
876 originBitNumber = 10;
877 alphaBitNumber = 2;
878 break;
879 case Format_A16R16G16B16F:
880 case Format_A16B16G16R16F:
881 storedBitNumber = 0;
882 originBitNumber = 0;
883 alphaBitNumber = 0;
884 break;
885 case Format_YUY2:
886 case Format_YUYV:
887 case Format_YVYU:
888 case Format_UYVY:
889 case Format_VYUY:
890 case Format_NV12:
891 case Format_400P:
892 case Format_R8G8B8:
893 storedBitNumber = 8;
894 originBitNumber = 8;
895 alphaBitNumber = 0;
896 break;
897 case Format_Y210:
898 case Format_P010:
899 case Format_P210:
900 storedBitNumber = 16;
901 originBitNumber = 10;
902 alphaBitNumber = 0;
903 break;
904 case Format_Y216:
905 case Format_P016:
906 case Format_P216:
907 storedBitNumber = 16;
908 originBitNumber = 16;
909 alphaBitNumber = 0;
910 break;
911 default:
912 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
913 }
914
915 if (pOriginBitNumber)
916 {
917 *pOriginBitNumber = originBitNumber;
918 }
919 if (pStoredBitNumber)
920 {
921 *pStoredBitNumber = storedBitNumber;
922 }
923 if (pAlphaBitNumber)
924 {
925 *pAlphaBitNumber = alphaBitNumber;
926 }
927
928 return MOS_STATUS_SUCCESS;
929 }
930
GenerateInputImageParam(L0_FC_LAYER_PARAM & layer,VPHAL_CSPACE mainCSpace,L0_FC_KRN_IMAGE_PARAM & imageParam)931 MOS_STATUS VpL0FcFilter::GenerateInputImageParam(L0_FC_LAYER_PARAM &layer, VPHAL_CSPACE mainCSpace, L0_FC_KRN_IMAGE_PARAM &imageParam)
932 {
933 VP_FUNC_CALL();
934 VP_PUBLIC_CHK_NULL_RETURN(layer.surf);
935 VP_PUBLIC_CHK_NULL_RETURN(layer.surf->osSurface);
936 MOS_FORMAT surfOverwriteFormat = layer.needIntermediaSurface ? layer.interMediaOverwriteSurface : layer.surf->osSurface->Format;
937 uint32_t inputWidth = MOS_MIN(static_cast<uint32_t>(layer.surf->osSurface->dwWidth), static_cast<uint32_t>(layer.surf->rcSrc.right));
938 uint32_t inputHeight = MOS_MIN(static_cast<uint32_t>(layer.surf->osSurface->dwHeight), static_cast<uint32_t>(layer.surf->rcSrc.bottom));
939 VP_PUBLIC_CHK_STATUS_RETURN(ConvertCscToKrnParam(layer.surf->ColorSpace, mainCSpace, imageParam.csc));
940 VP_PUBLIC_CHK_STATUS_RETURN(ConvertInputChannelIndicesToKrnParam(surfOverwriteFormat, imageParam.inputChannelIndices));
941 VP_PUBLIC_CHK_STATUS_RETURN(ConvertScalingRotToKrnParam(layer.surf->rcSrc, layer.surf->rcDst, layer.scalingMode, inputWidth, inputHeight, layer.rotation, imageParam.scale, imageParam.controlSetting.samplerType, imageParam.coordShift));
942 VP_PUBLIC_CHK_STATUS_RETURN(ConvertChromaUpsampleToKrnParam(surfOverwriteFormat, layer.surf->ChromaSiting, layer.scalingMode, inputWidth, inputHeight, imageParam.coordShift.chromaShiftX, imageParam.coordShift.chromaShiftY, imageParam.controlSetting.isChromaShift));
943 VP_PUBLIC_CHK_STATUS_RETURN(ConvertPlaneNumToKrnParam(surfOverwriteFormat, true, imageParam.inputPlaneNum));
944 VP_PUBLIC_CHK_STATUS_RETURN(ConvertBlendingToKrnParam(layer.blendingParams, imageParam.controlSetting.ignoreSrcPixelAlpha, imageParam.controlSetting.ignoreDstPixelAlpha, imageParam.constAlphs));
945
946 if (layer.lumaKey.enabled)
947 {
948 imageParam.lumaKey.low = (float)layer.lumaKey.params.LumaLow / 255;
949 imageParam.lumaKey.high = (float)layer.lumaKey.params.LumaHigh / 255;
950 }
951 else
952 {
953 imageParam.lumaKey.low = -1.f;
954 imageParam.lumaKey.high = -1.f;
955 }
956
957 return MOS_STATUS_SUCCESS;
958 }
959
ConvertRotationToKrnParam(VPHAL_ROTATION rotation,float strideX,float strideY,float startLeft,float startRight,float startTop,float startBottom,L0_FC_KRN_SCALE_PARAM & scaling)960 MOS_STATUS VpL0FcFilter::ConvertRotationToKrnParam(VPHAL_ROTATION rotation, float strideX, float strideY, float startLeft, float startRight, float startTop, float startBottom, L0_FC_KRN_SCALE_PARAM &scaling)
961 {
962 switch (rotation)
963 {
964 case VPHAL_ROTATION_IDENTITY:
965 scaling.rotateIndices[0] = 0;
966 scaling.rotateIndices[1] = 1;
967 scaling.src.startX = startLeft;
968 scaling.src.startY = startTop;
969 scaling.src.strideX = strideX;
970 scaling.src.strideY = strideY;
971 break;
972 case VPHAL_ROTATION_90:
973 scaling.rotateIndices[0] = 1;
974 scaling.rotateIndices[1] = 0;
975 scaling.src.startX = startLeft;
976 scaling.src.startY = startBottom;
977 scaling.src.strideX = strideX;
978 scaling.src.strideY = -strideY;
979 break;
980 case VPHAL_ROTATION_180:
981 scaling.rotateIndices[0] = 0;
982 scaling.rotateIndices[1] = 1;
983 scaling.src.startX = startRight;
984 scaling.src.startY = startBottom;
985 scaling.src.strideX = -strideX;
986 scaling.src.strideY = -strideY;
987 break;
988 case VPHAL_ROTATION_270:
989 scaling.rotateIndices[0] = 1;
990 scaling.rotateIndices[1] = 0;
991 scaling.src.startX = startRight;
992 scaling.src.startY = startTop;
993 scaling.src.strideX = -strideX;
994 scaling.src.strideY = strideY;
995 break;
996 case VPHAL_MIRROR_HORIZONTAL:
997 scaling.rotateIndices[0] = 0;
998 scaling.rotateIndices[1] = 1;
999 scaling.src.startX = startRight;
1000 scaling.src.startY = startTop;
1001 scaling.src.strideX = -strideX;
1002 scaling.src.strideY = strideY;
1003 break;
1004 case VPHAL_MIRROR_VERTICAL:
1005 scaling.rotateIndices[0] = 0;
1006 scaling.rotateIndices[1] = 1;
1007 scaling.src.startX = startLeft;
1008 scaling.src.startY = startBottom;
1009 scaling.src.strideX = strideX;
1010 scaling.src.strideY = -strideY;
1011 break;
1012 case VPHAL_ROTATE_90_MIRROR_VERTICAL:
1013 scaling.rotateIndices[0] = 1;
1014 scaling.rotateIndices[1] = 0;
1015 scaling.src.startX = startRight;
1016 scaling.src.startY = startBottom;
1017 scaling.src.strideX = -strideX;
1018 scaling.src.strideY = -strideY;
1019 break;
1020 case VPHAL_ROTATE_90_MIRROR_HORIZONTAL:
1021 scaling.rotateIndices[0] = 1;
1022 scaling.rotateIndices[1] = 0;
1023 scaling.src.startX = startLeft;
1024 scaling.src.startY = startTop;
1025 scaling.src.strideX = strideX;
1026 scaling.src.strideY = strideY;
1027 break;
1028 default:
1029 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
1030 }
1031
1032 return MOS_STATUS_SUCCESS;
1033 }
1034
ConvertCscToKrnParam(VPHAL_CSPACE srcColorSpace,VPHAL_CSPACE dstColorSpace,L0_FC_KRN_CSC_MATRIX & csc)1035 MOS_STATUS VpL0FcFilter::ConvertCscToKrnParam(VPHAL_CSPACE srcColorSpace, VPHAL_CSPACE dstColorSpace, L0_FC_KRN_CSC_MATRIX &csc)
1036 {
1037 VP_FUNC_CALL();
1038 csc = {};
1039 if (srcColorSpace == dstColorSpace)
1040 {
1041 csc.s0123[0] = csc.s4567[1] = csc.s89AB[2] = 1;
1042 return MOS_STATUS_SUCCESS;
1043 }
1044
1045 float cscMatrix[12] = {};
1046 KernelDll_GetCSCMatrix(srcColorSpace, dstColorSpace, cscMatrix);
1047 VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s0123, sizeof(csc.s0123), &cscMatrix[0], sizeof(float) * 3));
1048 VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s4567, sizeof(csc.s4567), &cscMatrix[4], sizeof(float) * 3));
1049 VP_PUBLIC_CHK_STATUS_RETURN(MOS_SecureMemcpy(csc.s89AB, sizeof(csc.s89AB), &cscMatrix[8], sizeof(float) * 3));
1050 csc.sCDEF[0] = cscMatrix[3] / 255;
1051 csc.sCDEF[1] = cscMatrix[7] / 255;
1052 csc.sCDEF[2] = cscMatrix[11] / 255;
1053
1054 return MOS_STATUS_SUCCESS;
1055 }
1056
ConvertScalingRotToKrnParam(RECT & rcSrc,RECT & rcDst,VPHAL_SCALING_MODE scalingMode,uint32_t inputWidth,uint32_t inputHeight,VPHAL_ROTATION rotation,L0_FC_KRN_SCALE_PARAM & scaling,uint8_t & samplerType,L0_FC_KRN_COORD_SHIFT_PARAM & coordShift)1057 MOS_STATUS VpL0FcFilter::ConvertScalingRotToKrnParam(
1058 RECT &rcSrc,
1059 RECT &rcDst,
1060 VPHAL_SCALING_MODE scalingMode,
1061 uint32_t inputWidth,
1062 uint32_t inputHeight,
1063 VPHAL_ROTATION rotation,
1064 L0_FC_KRN_SCALE_PARAM &scaling,
1065 uint8_t &samplerType,
1066 L0_FC_KRN_COORD_SHIFT_PARAM &coordShift)
1067
1068 {
1069 VP_FUNC_CALL();
1070 if (scalingMode == VPHAL_SCALING_BILINEAR)
1071 {
1072 coordShift.commonShiftX = VP_HW_LINEAR_SHIFT / inputWidth;
1073 coordShift.commonShiftY = VP_HW_LINEAR_SHIFT / inputHeight;
1074 samplerType = 1;
1075 }
1076 else if (scalingMode == VPHAL_SCALING_NEAREST)
1077 {
1078 coordShift.commonShiftX = VP_SAMPLER_BIAS / inputWidth;
1079 coordShift.commonShiftY = VP_SAMPLER_BIAS / inputHeight;
1080 samplerType = 0;
1081 }
1082 else
1083 {
1084 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
1085 }
1086
1087 scaling.trg.left = rcDst.left;
1088 scaling.trg.right = rcDst.right;
1089 scaling.trg.top = rcDst.top;
1090 scaling.trg.bottom = rcDst.bottom;
1091
1092 bool isVerticalRotate = VpUtils::IsVerticalRotation(rotation);
1093 float rcDstWidth = static_cast<float>(rcDst.right - rcDst.left);
1094 float rcDstHeight = static_cast<float>(rcDst.bottom - rcDst.top);
1095 float rcSrcWidth = static_cast<float>(rcSrc.right - rcSrc.left);
1096 float rcSrcHeight = static_cast<float>(rcSrc.bottom - rcSrc.top);
1097 float strideX = isVerticalRotate ? rcSrcWidth / rcDstHeight / inputWidth : rcSrcWidth / rcDstWidth / inputWidth;
1098 float strideY = isVerticalRotate ? rcSrcHeight / rcDstWidth / inputHeight : rcSrcHeight / rcDstHeight / inputHeight;
1099 float startLeft = (float)rcSrc.left / inputWidth;
1100 float startRight = (float)(rcSrc.right - 1) / inputWidth;
1101 float startTop = (float)rcSrc.top / inputHeight;
1102 float startBottom = (float)(rcSrc.bottom - 1) / inputHeight;
1103 VP_PUBLIC_CHK_STATUS_RETURN(ConvertRotationToKrnParam(rotation, strideX, strideY, startLeft, startRight, startTop, startBottom, scaling));
1104
1105 return MOS_STATUS_SUCCESS;
1106 }
1107
ConvertChromaUpsampleToKrnParam(MOS_FORMAT format,uint32_t chromaSitingLoc,VPHAL_SCALING_MODE scalingMode,uint32_t inputWidth,uint32_t inputHeight,float & chromaShiftX,float & chromaShiftY,uint8_t & isChromaShift)1108 MOS_STATUS VpL0FcFilter::ConvertChromaUpsampleToKrnParam(MOS_FORMAT format, uint32_t chromaSitingLoc, VPHAL_SCALING_MODE scalingMode, uint32_t inputWidth, uint32_t inputHeight, float &chromaShiftX, float &chromaShiftY, uint8_t &isChromaShift)
1109 {
1110 uint8_t hitSecPlaneFactorX = 0;
1111 uint8_t hitSecPlaneFactorY = 0;
1112 isChromaShift = 0;
1113 chromaShiftX = 0.5f;
1114 chromaShiftY = 0.5f;
1115 VP_PUBLIC_CHK_STATUS_RETURN(GetChromaSitingFactor(format, hitSecPlaneFactorX, hitSecPlaneFactorY));
1116
1117 // If there is no DDI setting, we use the Horizontal Left Vertical Center as default for PL2 surface.
1118 if (chromaSitingLoc == CHROMA_SITING_NONE)
1119 {
1120 // PL2 default to Horizontal Left, Vertical Center
1121 if (hitSecPlaneFactorX == 2 && hitSecPlaneFactorY == 2)
1122 {
1123 //Center Left
1124 isChromaShift = 1;
1125 chromaShiftY -= 0.5f;
1126 }
1127 }
1128 else
1129 {
1130 // PL2, 6 positions are available
1131 if (hitSecPlaneFactorX == 2 && hitSecPlaneFactorY == 2)
1132 {
1133 // Horizontal Left
1134 if (chromaSitingLoc & CHROMA_SITING_HORZ_LEFT)
1135 {
1136 if (chromaSitingLoc & CHROMA_SITING_VERT_TOP)
1137 {
1138 //Top Left
1139 isChromaShift = 1;
1140 }
1141 else if (chromaSitingLoc & CHROMA_SITING_VERT_CENTER)
1142 {
1143 //Center Left
1144 isChromaShift = 1;
1145 chromaShiftY -= 0.5f;
1146 }
1147 else if (chromaSitingLoc & CHROMA_SITING_VERT_BOTTOM)
1148 {
1149 //Bottom Left
1150 isChromaShift = 1;
1151 chromaShiftY -= 1.f;
1152 }
1153 }
1154 // Horizontal Center
1155 else if (chromaSitingLoc & CHROMA_SITING_HORZ_CENTER)
1156 {
1157 chromaShiftX -= 0.5f;
1158 if (chromaSitingLoc & CHROMA_SITING_VERT_TOP)
1159 {
1160 //Top Center
1161 isChromaShift = 1;
1162 }
1163 else if (chromaSitingLoc & CHROMA_SITING_VERT_CENTER)
1164 {
1165 //Center Center
1166 isChromaShift = 0;
1167 chromaShiftY -= 0.5f;
1168 }
1169 else if (chromaSitingLoc & CHROMA_SITING_VERT_BOTTOM)
1170 {
1171 //Bottom Center
1172 isChromaShift = 1;
1173 chromaShiftY -= 1.f;
1174 }
1175 }
1176 }
1177 else if (hitSecPlaneFactorX == 2 && hitSecPlaneFactorY == 1)
1178 {
1179 // For PA surface, only (H Left, V Top) and (H Center, V top) are needed.
1180 if (chromaSitingLoc & (CHROMA_SITING_HORZ_CENTER))
1181 {
1182 //Top Center
1183 isChromaShift = 1;
1184 chromaShiftX -= 0.5f;
1185 }
1186 }
1187 }
1188
1189 if (scalingMode == VPHAL_SCALING_NEAREST)
1190 {
1191 isChromaShift = 0;
1192 }
1193 chromaShiftX /= inputWidth;
1194 chromaShiftY /= inputHeight;
1195
1196 return MOS_STATUS_SUCCESS;
1197 }
1198
ConvertInputChannelIndicesToKrnParam(MOS_FORMAT format,uint32_t * inputChannelIndices)1199 MOS_STATUS VpL0FcFilter::ConvertInputChannelIndicesToKrnParam(MOS_FORMAT format, uint32_t* inputChannelIndices)
1200 {
1201 switch (format)
1202 {
1203 case Format_A8R8G8B8:
1204 case Format_X8R8G8B8:
1205 case Format_B10G10R10A2:
1206 case Format_A16R16G16B16:
1207 case Format_A16R16G16B16F:
1208 case Format_R5G6B5:
1209 case Format_R8G8B8:
1210 case Format_RGBP:
1211 case Format_444P:
1212 inputChannelIndices[0] = 0;
1213 inputChannelIndices[1] = 1;
1214 inputChannelIndices[2] = 2;
1215 inputChannelIndices[3] = 3;
1216 break;
1217 case Format_AYUV:
1218 inputChannelIndices[0] = 1;
1219 inputChannelIndices[1] = 2;
1220 inputChannelIndices[2] = 0;
1221 inputChannelIndices[3] = 3;
1222 break;
1223 case Format_A8B8G8R8:
1224 case Format_X8B8G8R8:
1225 case Format_R10G10B10A2:
1226 case Format_A16B16G16R16:
1227 case Format_A16B16G16R16F:
1228 inputChannelIndices[0] = 0;
1229 inputChannelIndices[1] = 1;
1230 inputChannelIndices[2] = 2;
1231 inputChannelIndices[3] = 3;
1232 break;
1233 case Format_YUY2:
1234 case Format_YUYV:
1235 case Format_Y210:
1236 case Format_Y216:
1237 inputChannelIndices[0] = 0;
1238 inputChannelIndices[1] = 5;
1239 inputChannelIndices[2] = 7;
1240 inputChannelIndices[3] = 3;
1241 break;
1242 case Format_YVYU:
1243 inputChannelIndices[0] = 0;
1244 inputChannelIndices[1] = 7;
1245 inputChannelIndices[2] = 5;
1246 inputChannelIndices[3] = 3;
1247 break;
1248 case Format_UYVY:
1249 inputChannelIndices[0] = 1;
1250 inputChannelIndices[1] = 4;
1251 inputChannelIndices[2] = 6;
1252 inputChannelIndices[3] = 3;
1253 break;
1254 case Format_VYUY:
1255 inputChannelIndices[0] = 1;
1256 inputChannelIndices[1] = 6;
1257 inputChannelIndices[2] = 4;
1258 inputChannelIndices[3] = 3;
1259 break;
1260 case Format_Y410:
1261 case Format_Y416:
1262 inputChannelIndices[0] = 1;
1263 inputChannelIndices[1] = 0;
1264 inputChannelIndices[2] = 2;
1265 inputChannelIndices[3] = 3;
1266 break;
1267 case Format_NV12:
1268 case Format_P010:
1269 case Format_P016:
1270 case Format_P210:
1271 case Format_P216:
1272 inputChannelIndices[0] = 0;
1273 inputChannelIndices[1] = 4;
1274 inputChannelIndices[2] = 5;
1275 inputChannelIndices[3] = 3;
1276 break;
1277 case Format_400P:
1278 inputChannelIndices[0] = 0;
1279 inputChannelIndices[1] = 0;
1280 inputChannelIndices[2] = 0;
1281 inputChannelIndices[3] = 3;
1282 break;
1283 case Format_BGRP:
1284 inputChannelIndices[0] = 2;
1285 inputChannelIndices[1] = 1;
1286 inputChannelIndices[2] = 0;
1287 inputChannelIndices[3] = 3;
1288 break;
1289 default:
1290 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
1291 }
1292
1293 return MOS_STATUS_SUCCESS;
1294 }
1295
ConvertPlaneNumToKrnParam(MOS_FORMAT format,bool isInput,uint32_t & planeNum)1296 MOS_STATUS VpL0FcFilter::ConvertPlaneNumToKrnParam(MOS_FORMAT format, bool isInput, uint32_t &planeNum)
1297 {
1298 switch (format)
1299 {
1300 case Format_A8R8G8B8:
1301 case Format_X8R8G8B8:
1302 case Format_A16R16G16B16:
1303 case Format_R10G10B10A2:
1304 case Format_AYUV:
1305 case Format_A16R16G16B16F:
1306 case Format_A8B8G8R8:
1307 case Format_X8B8G8R8:
1308 case Format_A16B16G16R16:
1309 case Format_B10G10R10A2:
1310 case Format_A16B16G16R16F:
1311 case Format_Y410:
1312 case Format_Y416:
1313 case Format_400P:
1314 case Format_R5G6B5:
1315 case Format_R8G8B8:
1316 planeNum = 1;
1317 break;
1318 case Format_NV12:
1319 case Format_P010:
1320 case Format_P016:
1321 case Format_P210:
1322 case Format_P216:
1323 planeNum = 2;
1324 break;
1325 case Format_YUY2:
1326 case Format_YUYV:
1327 case Format_YVYU:
1328 case Format_UYVY:
1329 case Format_VYUY:
1330 case Format_Y210:
1331 case Format_Y216:
1332 if (isInput)
1333 {
1334 planeNum = 2;
1335 }
1336 else
1337 {
1338 planeNum = 3;
1339 }
1340 break;
1341 default:
1342 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
1343 }
1344
1345 return MOS_STATUS_SUCCESS;
1346 }
1347
ConvertBlendingToKrnParam(VPHAL_BLENDING_PARAMS & blend,uint8_t & ignoreSrcPixelAlpha,uint8_t & ignoreDstPixelAlpha,float & constAlpha)1348 MOS_STATUS VpL0FcFilter::ConvertBlendingToKrnParam(VPHAL_BLENDING_PARAMS &blend, uint8_t &ignoreSrcPixelAlpha, uint8_t &ignoreDstPixelAlpha, float &constAlpha)
1349 {
1350 switch (blend.BlendType)
1351 {
1352 case BLEND_NONE:
1353 ignoreSrcPixelAlpha = 1;
1354 constAlpha = 1;
1355 ignoreDstPixelAlpha = 1;
1356 break;
1357 case BLEND_SOURCE:
1358 ignoreSrcPixelAlpha = 0;
1359 constAlpha = 1;
1360 ignoreDstPixelAlpha = 0;
1361 break;
1362 case BLEND_PARTIAL:
1363 ignoreSrcPixelAlpha = 1;
1364 constAlpha = 1;
1365 ignoreDstPixelAlpha = 0;
1366 break;
1367 case BLEND_CONSTANT:
1368 ignoreSrcPixelAlpha = 1;
1369 constAlpha = blend.fAlpha;
1370 ignoreDstPixelAlpha = 1;
1371 break;
1372 case BLEND_CONSTANT_SOURCE:
1373 ignoreSrcPixelAlpha = 0;
1374 constAlpha = blend.fAlpha;
1375 ignoreDstPixelAlpha = 0;
1376 break;
1377 case BLEND_CONSTANT_PARTIAL:
1378 ignoreSrcPixelAlpha = 1;
1379 constAlpha = blend.fAlpha;
1380 ignoreDstPixelAlpha = 0;
1381 break;
1382 default:
1383 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
1384 }
1385
1386 return MOS_STATUS_SUCCESS;
1387 }
1388
GenerateTargetParam(L0_FC_COMP_PARAM & compParam,L0_FC_KRN_TARGET_PARAM & targetParam)1389 MOS_STATUS VpL0FcFilter::GenerateTargetParam(L0_FC_COMP_PARAM &compParam, L0_FC_KRN_TARGET_PARAM &targetParam)
1390 {
1391 VP_FUNC_CALL();
1392 VP_SURFACE *targetSurf = compParam.outputLayerParam.surf;
1393 VP_PUBLIC_CHK_NULL_RETURN(targetSurf);
1394 VP_PUBLIC_CHK_NULL_RETURN(targetSurf->osSurface);
1395 VP_PUBLIC_CHK_STATUS_RETURN(ConvertPlaneNumToKrnParam(targetSurf->osSurface->Format, false, targetParam.planeNumber));
1396 VP_PUBLIC_CHK_STATUS_RETURN(ConvertOuputChannelIndicesToKrnParam(targetSurf->osSurface->Format, targetParam.dynamicChannelIndices));
1397 VP_PUBLIC_CHK_STATUS_RETURN(ConvertTargetRoiToKrnParam(targetSurf->rcDst, targetSurf->osSurface->dwWidth, targetSurf->osSurface->dwHeight, targetParam.targetROI));
1398 VP_PUBLIC_CHK_STATUS_RETURN(ConvertChromaDownsampleToKrnParam(targetSurf->osSurface->Format, targetSurf->ChromaSiting, targetParam.chromaSitingFactor, targetParam.controlSetting.hitSecPlaneFactorX, targetParam.controlSetting.hitSecPlaneFactorY));
1399 VP_PUBLIC_CHK_STATUS_RETURN(ConvertColorFillToKrnParam(compParam.enableColorFill, compParam.colorFillParams, compParam.mainCSpace, targetParam.controlSetting.isColorFill, targetParam.background));
1400 //ConvertAlphaToKrnParam must be called after ConvertColorFillToKrnParam
1401 VP_PUBLIC_CHK_STATUS_RETURN(ConvertAlphaToKrnParam(compParam.bAlphaCalculateEnable, compParam.compAlpha, targetParam.background[3], targetParam.controlSetting.alphaLayerIndex, targetParam.alpha));
1402
1403 return MOS_STATUS_SUCCESS;
1404 }
1405
ConvertOuputChannelIndicesToKrnParam(MOS_FORMAT format,uint32_t * dynamicChannelIndices)1406 MOS_STATUS VpL0FcFilter::ConvertOuputChannelIndicesToKrnParam(MOS_FORMAT format, uint32_t *dynamicChannelIndices)
1407 {
1408 switch (format)
1409 {
1410 case Format_A8R8G8B8:
1411 case Format_X8R8G8B8:
1412 case Format_B10G10R10A2:
1413 case Format_A16R16G16B16:
1414 case Format_A16R16G16B16F:
1415 case Format_R5G6B5:
1416 case Format_R8G8B8:
1417 dynamicChannelIndices[0] = 0;
1418 dynamicChannelIndices[1] = 1;
1419 dynamicChannelIndices[2] = 2;
1420 dynamicChannelIndices[3] = 3;
1421 break;
1422 case Format_AYUV:
1423 dynamicChannelIndices[0] = 2;
1424 dynamicChannelIndices[1] = 0;
1425 dynamicChannelIndices[2] = 1;
1426 dynamicChannelIndices[3] = 3;
1427 break;
1428 case Format_A8B8G8R8:
1429 case Format_X8B8G8R8:
1430 case Format_R10G10B10A2:
1431 case Format_A16B16G16R16:
1432 case Format_A16B16G16R16F:
1433 dynamicChannelIndices[0] = 0;
1434 dynamicChannelIndices[1] = 1;
1435 dynamicChannelIndices[2] = 2;
1436 dynamicChannelIndices[3] = 3;
1437 break;
1438 case Format_Y410:
1439 case Format_Y416:
1440 dynamicChannelIndices[0] = 1;
1441 dynamicChannelIndices[1] = 0;
1442 dynamicChannelIndices[2] = 2;
1443 dynamicChannelIndices[3] = 3;
1444 break;
1445 case Format_NV12:
1446 case Format_P010:
1447 case Format_P016:
1448 case Format_P210:
1449 case Format_P216:
1450 dynamicChannelIndices[0] = 1;
1451 dynamicChannelIndices[1] = 2;
1452 dynamicChannelIndices[2] = 3;
1453 dynamicChannelIndices[3] = 3;
1454 break;
1455 case Format_400P:
1456 dynamicChannelIndices[0] = 0;
1457 dynamicChannelIndices[1] = 0;
1458 dynamicChannelIndices[2] = 0;
1459 dynamicChannelIndices[3] = 3;
1460 break;
1461 case Format_YUY2:
1462 case Format_YUYV:
1463 case Format_Y210:
1464 case Format_Y216:
1465 dynamicChannelIndices[0] = 0;
1466 dynamicChannelIndices[1] = 1;
1467 dynamicChannelIndices[2] = 3;
1468 break;
1469 case Format_YVYU:
1470 dynamicChannelIndices[0] = 0;
1471 dynamicChannelIndices[1] = 3;
1472 dynamicChannelIndices[2] = 1;
1473 break;
1474 case Format_UYVY:
1475 dynamicChannelIndices[0] = 1;
1476 dynamicChannelIndices[1] = 0;
1477 dynamicChannelIndices[2] = 2;
1478 break;
1479 case Format_VYUY:
1480 dynamicChannelIndices[0] = 1;
1481 dynamicChannelIndices[1] = 2;
1482 dynamicChannelIndices[2] = 0;
1483 break;
1484 default:
1485 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNIMPLEMENTED);
1486 }
1487
1488 return MOS_STATUS_SUCCESS;
1489 }
1490
ConvertTargetRoiToKrnParam(RECT & outputRcDst,uint32_t outputWidth,uint32_t outputHeight,L0_FC_KRN_RECT & targetROI)1491 MOS_STATUS VpL0FcFilter::ConvertTargetRoiToKrnParam(RECT &outputRcDst, uint32_t outputWidth, uint32_t outputHeight, L0_FC_KRN_RECT &targetROI)
1492 {
1493
1494 targetROI.left = MOS_MAX(0, outputRcDst.left);
1495 targetROI.right = MOS_MIN((uint64_t)outputRcDst.right, outputWidth);
1496 targetROI.top = MOS_MAX(0, outputRcDst.top);
1497 targetROI.bottom = MOS_MIN((uint64_t)outputRcDst.bottom, outputHeight);
1498
1499 return MOS_STATUS_SUCCESS;
1500 }
1501
ConvertChromaDownsampleToKrnParam(MOS_FORMAT format,uint32_t chromaSitingLoc,float * chromaSitingFactor,uint8_t & hitSecPlaneFactorX,uint8_t & hitSecPlaneFactorY)1502 MOS_STATUS VpL0FcFilter::ConvertChromaDownsampleToKrnParam(MOS_FORMAT format, uint32_t chromaSitingLoc, float *chromaSitingFactor, uint8_t &hitSecPlaneFactorX, uint8_t &hitSecPlaneFactorY)
1503 {
1504 VP_PUBLIC_CHK_STATUS_RETURN(GetChromaSitingFactor(format, hitSecPlaneFactorX, hitSecPlaneFactorY));
1505
1506 //Left Top
1507 chromaSitingFactor[0] = 1;
1508 chromaSitingFactor[1] = 0;
1509 chromaSitingFactor[2] = 0;
1510 chromaSitingFactor[3] = 0;
1511
1512 if (chromaSitingLoc== CHROMA_SITING_NONE)
1513 {
1514 // PL2 default to Horizontal Left, Vertical Center
1515 if (hitSecPlaneFactorX == 2 && hitSecPlaneFactorY == 2)
1516 {
1517 //Center Left
1518 chromaSitingFactor[0] = 0.5;
1519 chromaSitingFactor[1] = 0;
1520 chromaSitingFactor[2] = 0.5;
1521 chromaSitingFactor[3] = 0;
1522 }
1523 }
1524 else
1525 {
1526 // PL2, 6 positions are avalibale
1527 if (hitSecPlaneFactorX == 2 && hitSecPlaneFactorY == 2)
1528 {
1529 // Horizontal Left
1530 if (chromaSitingLoc & CHROMA_SITING_HORZ_LEFT)
1531 {
1532 if (chromaSitingLoc & CHROMA_SITING_VERT_TOP)
1533 {
1534 //Top Left
1535 chromaSitingFactor[0] = 1;
1536 chromaSitingFactor[1] = 0;
1537 chromaSitingFactor[2] = 0;
1538 chromaSitingFactor[3] = 0;
1539 }
1540 else if (chromaSitingLoc & CHROMA_SITING_VERT_CENTER)
1541 {
1542 //Center Left
1543 chromaSitingFactor[0] = 0.5;
1544 chromaSitingFactor[1] = 0;
1545 chromaSitingFactor[2] = 0.5;
1546 chromaSitingFactor[3] = 0;
1547 }
1548 else if (chromaSitingLoc & CHROMA_SITING_VERT_BOTTOM)
1549 {
1550 //Bottom Left
1551 chromaSitingFactor[0] = 0;
1552 chromaSitingFactor[1] = 0;
1553 chromaSitingFactor[2] = 1;
1554 chromaSitingFactor[3] = 0;
1555 }
1556 }
1557 // Horizontal Center
1558 else if (chromaSitingLoc & CHROMA_SITING_HORZ_CENTER)
1559 {
1560 if (chromaSitingLoc & CHROMA_SITING_VERT_TOP)
1561 {
1562 //Top Center
1563 chromaSitingFactor[0] = 0.5;
1564 chromaSitingFactor[1] = 0.5;
1565 chromaSitingFactor[2] = 0;
1566 chromaSitingFactor[3] = 0;
1567 }
1568 else if (chromaSitingLoc & CHROMA_SITING_VERT_CENTER)
1569 {
1570 //Center Center
1571 chromaSitingFactor[0] = 0.25;
1572 chromaSitingFactor[1] = 0.25;
1573 chromaSitingFactor[2] = 0.25;
1574 chromaSitingFactor[3] = 0.25;
1575 }
1576 else if (chromaSitingLoc & CHROMA_SITING_VERT_BOTTOM)
1577 {
1578 //Bottom Center
1579 chromaSitingFactor[0] = 0;
1580 chromaSitingFactor[1] = 0;
1581 chromaSitingFactor[2] = 0.5;
1582 chromaSitingFactor[3] = 0.5;
1583 }
1584 }
1585 }
1586 else if (hitSecPlaneFactorX == 2 && hitSecPlaneFactorY == 1)
1587 {
1588 // For PA surface, only (H Left, V Top) and (H Center, V top) are needed.
1589 if (chromaSitingLoc & CHROMA_SITING_HORZ_CENTER)
1590 {
1591 //Top Center
1592 chromaSitingFactor[0] = 0.5;
1593 chromaSitingFactor[1] = 0.5;
1594 chromaSitingFactor[2] = 0;
1595 chromaSitingFactor[3] = 0;
1596 }
1597 }
1598 }
1599
1600 return MOS_STATUS_SUCCESS;
1601 }
1602
ConvertAlphaToKrnParam(bool bAlphaCalculateEnable,VPHAL_ALPHA_PARAMS & compAlpha,float colorFillAlpha,uint8_t & alphaLayerIndex,float & alpha)1603 MOS_STATUS VpL0FcFilter::ConvertAlphaToKrnParam(bool bAlphaCalculateEnable, VPHAL_ALPHA_PARAMS &compAlpha, float colorFillAlpha, uint8_t &alphaLayerIndex, float &alpha)
1604 {
1605 switch (compAlpha.AlphaMode)
1606 {
1607 case VPHAL_ALPHA_FILL_MODE_NONE:
1608 alpha = compAlpha.fAlpha;
1609 alphaLayerIndex = 8;
1610 break;
1611 case VPHAL_ALPHA_FILL_MODE_OPAQUE:
1612 alpha = 1.f;
1613 alphaLayerIndex = 8;
1614 break;
1615 case VPHAL_ALPHA_FILL_MODE_BACKGROUND:
1616 alpha = colorFillAlpha;
1617 alphaLayerIndex = 8;
1618 break;
1619 case VPHAL_ALPHA_FILL_MODE_SOURCE_STREAM:
1620 alphaLayerIndex = 0;
1621 break;
1622 default:
1623 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
1624 }
1625 if (!bAlphaCalculateEnable)
1626 {
1627 alpha = 0;
1628 alphaLayerIndex = 8;
1629 }
1630
1631 return MOS_STATUS_SUCCESS;
1632 }
1633
ConvertColorFillToKrnParam(bool enableColorFill,VPHAL_COLORFILL_PARAMS & colorFillParams,MEDIA_CSPACE dstCspace,uint8_t & isColorFill,float * background)1634 MOS_STATUS VpL0FcFilter::ConvertColorFillToKrnParam(bool enableColorFill, VPHAL_COLORFILL_PARAMS &colorFillParams, MEDIA_CSPACE dstCspace, uint8_t &isColorFill, float *background)
1635 {
1636 VP_FUNC_CALL();
1637 isColorFill = enableColorFill;
1638 if (enableColorFill)
1639 {
1640 MEDIA_CSPACE srcCspace = colorFillParams.CSpace;
1641 VPHAL_COLOR_SAMPLE_8 srcColor = {};
1642 VPHAL_COLOR_SAMPLE_8 dstColor = {};
1643 srcColor.dwValue = colorFillParams.Color;
1644 if (!VpUtils::GetCscMatrixForRender8Bit(&dstColor, &srcColor, srcCspace, dstCspace))
1645 {
1646 VP_PUBLIC_ASSERTMESSAGE("Color fill covert fail. srcCspace %d, dstCspace %d", srcCspace, dstCspace);
1647 }
1648 else
1649 {
1650 VP_PUBLIC_NORMALMESSAGE("Color fill background covert from srcCspace %d to dstCspace %d", srcCspace, dstCspace);
1651 }
1652
1653 if ((dstCspace == CSpace_sRGB) || (dstCspace == CSpace_stRGB) || IS_COLOR_SPACE_BT2020_RGB(dstCspace))
1654 {
1655 background[0] = (float)dstColor.R / 255;
1656 background[1] = (float)dstColor.G / 255;
1657 background[2] = (float)dstColor.B / 255;
1658 background[3] = (float)dstColor.A / 255;
1659 }
1660 else
1661 {
1662 background[0] = (float)dstColor.Y / 255;
1663 background[1] = (float)dstColor.U / 255;
1664 background[2] = (float)dstColor.V / 255;
1665 background[3] = (float)dstColor.a / 255;
1666 }
1667 }
1668
1669 return MOS_STATUS_SUCCESS;
1670 }
FastExpressConditionMeet(const L0_FC_COMP_PARAM & compParam)1671 bool VpL0FcFilter::FastExpressConditionMeet(const L0_FC_COMP_PARAM &compParam)
1672 {
1673 #if (_DEBUG || _RELEASE_INTERNAL)
1674 if (m_pvpMhwInterface &&
1675 m_pvpMhwInterface->m_userFeatureControl &&
1676 m_pvpMhwInterface->m_userFeatureControl->DisableL0FcFp())
1677 {
1678 return false;
1679 }
1680 #endif
1681 if (compParam.layerNumber != 1)
1682 {
1683 return false;
1684 }
1685 const L0_FC_LAYER_PARAM &inputLayer = compParam.inputLayersParam[0];
1686 const L0_FC_LAYER_PARAM &outputLayer = compParam.outputLayerParam;
1687 VP_SURFACE *inputSurf = inputLayer.surf;
1688 VP_SURFACE *outputSurf = outputLayer.surf;
1689 if (!outputSurf ||
1690 !outputSurf->osSurface ||
1691 !inputSurf ||
1692 !inputSurf->osSurface)
1693 {
1694 return false;
1695 }
1696 bool trgFormatSupport = outputSurf->osSurface->Format == Format_NV12 ||
1697 outputSurf->osSurface->Format == Format_P010 ||
1698 outputSurf->osSurface->Format == Format_P016;
1699 bool isAligned = false;
1700 if (compParam.enableColorFill)
1701 {
1702 isAligned = MOS_IS_ALIGNED(MOS_MAX(0, outputSurf->rcDst.left), 2) &&
1703 MOS_IS_ALIGNED(MOS_MIN(outputSurf->osSurface->dwWidth, (uint64_t)outputSurf->rcDst.right), 2) &&
1704 MOS_IS_ALIGNED(MOS_MAX(0, outputSurf->rcDst.top), 2) &&
1705 MOS_IS_ALIGNED(MOS_MIN(outputSurf->osSurface->dwHeight, (uint64_t)outputSurf->rcDst.bottom), 2);
1706 }
1707 else
1708 {
1709 isAligned = MOS_IS_ALIGNED(MOS_MAX(0, inputSurf->rcDst.left), 2) &&
1710 MOS_IS_ALIGNED(MOS_MIN(outputSurf->osSurface->dwWidth, (uint64_t)inputSurf->rcDst.right), 2) &&
1711 MOS_IS_ALIGNED(MOS_MAX(0, inputSurf->rcDst.top), 2) &&
1712 MOS_IS_ALIGNED(MOS_MIN(outputSurf->osSurface->dwHeight, (uint64_t)inputSurf->rcDst.bottom), 2);
1713 }
1714 if (!trgFormatSupport ||
1715 !isAligned ||
1716 inputLayer.blendingParams.BlendType != BLEND_NONE ||
1717 inputLayer.diParams.enabled ||
1718 inputLayer.lumaKey.enabled)
1719 {
1720 return false;
1721 }
1722
1723 return true;
1724 }
1725
GenerateFcFastExpressKrnParam(L0_FC_COMP_PARAM & compParam,L0_FC_KERNEL_PARAM & param)1726 MOS_STATUS VpL0FcFilter::GenerateFcFastExpressKrnParam(L0_FC_COMP_PARAM &compParam, L0_FC_KERNEL_PARAM ¶m)
1727 {
1728 VP_FUNC_CALL();
1729 VP_PUBLIC_CHK_NULL_RETURN(m_pvpMhwInterface);
1730 VP_PUBLIC_CHK_NULL_RETURN(m_pvpMhwInterface->m_vpPlatformInterface);
1731
1732 param = {};
1733 L0_FC_FP_KRN_IMAGE_PARAM imageParam = {};
1734 L0_FC_FP_KRN_TARGET_PARAM targetParam = {};
1735 VP_RENDER_CHK_STATUS_RETURN(GenerateFastExpressInputOutputParam(compParam, imageParam, targetParam));
1736 PrintFastExpressKrnParam(imageParam, targetParam);
1737
1738 uint32_t localSize[3] = {16, 2, 1}; // localWidth, localHeight, localDepth
1739 uint32_t workItemNum = targetParam.alignedTrgRectSize.width * targetParam.alignedTrgRectSize.height;
1740 uint32_t localWorkItemNum = localSize[0] * localSize[1];
1741 uint32_t groupNumber = workItemNum / localWorkItemNum + (workItemNum % localWorkItemNum != 0);
1742 uint32_t threadGroupWidth = 8;
1743 uint32_t threadGroupHeight = groupNumber / threadGroupWidth + (groupNumber % threadGroupWidth != 0);
1744 uint32_t globalSize[3] = {localSize[0] * threadGroupWidth, localSize[1] * threadGroupHeight, 1};
1745 KERNEL_ARGS krnArgs = {};
1746 KERNEL_ARG_INDEX_SURFACE_MAP krnStatefulSurfaces = {};
1747
1748 auto handle = m_pvpMhwInterface->m_vpPlatformInterface->GetKernelPool().find("FastExpress_fc_fp");
1749 VP_PUBLIC_CHK_NOT_FOUND_RETURN(handle, &m_pvpMhwInterface->m_vpPlatformInterface->GetKernelPool());
1750 KERNEL_BTIS kernelBtis = handle->second.GetKernelBtis();
1751 KERNEL_ARGS kernelArgs = handle->second.GetKernelArgs();
1752
1753 for (auto const &kernelArg : kernelArgs)
1754 {
1755 uint32_t uIndex = kernelArg.uIndex;
1756 auto argHandle = m_fcFastExpressKrnArgs.find(uIndex);
1757 if (argHandle == m_fcFastExpressKrnArgs.end())
1758 {
1759 KRN_ARG krnArg = {};
1760 argHandle = m_fcFastExpressKrnArgs.insert(std::make_pair(uIndex, krnArg)).first;
1761 VP_PUBLIC_CHK_NOT_FOUND_RETURN(argHandle, &m_fcFastExpressKrnArgs);
1762 }
1763 KRN_ARG &krnArg = argHandle->second;
1764 bool bInit = true;
1765 krnArg.uIndex = uIndex;
1766 krnArg.eArgKind = kernelArg.eArgKind;
1767 if (krnArg.pData == nullptr)
1768 {
1769 if (kernelArg.uSize > 0)
1770 {
1771 krnArg.uSize = kernelArg.uSize;
1772 krnArg.pData = MOS_AllocAndZeroMemory(kernelArg.uSize);
1773 }
1774 }
1775 else
1776 {
1777 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, kernelArg.uSize);
1778 MOS_ZeroMemory(krnArg.pData, krnArg.uSize);
1779 }
1780
1781 VP_PUBLIC_CHK_STATUS_RETURN(SetupSingleFcFastExpressKrnArg(imageParam, targetParam, localSize, globalSize, krnArg, bInit));
1782
1783 if (bInit)
1784 {
1785 krnArgs.push_back(krnArg);
1786 }
1787 }
1788
1789 for (auto const &kernelBti : kernelBtis)
1790 {
1791 uint32_t uIndex = kernelBti.first;
1792 SURFACE_PARAMS surfaceParam = {};
1793 bool bInit = true;
1794
1795 VP_PUBLIC_CHK_STATUS_RETURN(SetupSingleFcFastExpressBti(uIndex, compParam, surfaceParam, bInit));
1796
1797 if (bInit)
1798 {
1799 krnStatefulSurfaces.insert(std::make_pair(uIndex, surfaceParam));
1800 }
1801 }
1802
1803 param.kernelArgs = krnArgs;
1804 param.kernelName = "FastExpress_fc_fp";
1805 param.kernelId = kernelL0FcFP;
1806 param.threadWidth = threadGroupWidth;
1807 param.threadHeight = threadGroupHeight;
1808 param.localWidth = localSize[0];
1809 param.localHeight = localSize[1];
1810 param.kernelStatefulSurfaces = krnStatefulSurfaces;
1811
1812 return MOS_STATUS_SUCCESS;
1813 }
1814
SetupSingleFcFastExpressBti(uint32_t uIndex,const L0_FC_COMP_PARAM & compParam,SURFACE_PARAMS & surfaceParam,bool & bInit)1815 MOS_STATUS VpL0FcFilter::SetupSingleFcFastExpressBti(uint32_t uIndex, const L0_FC_COMP_PARAM &compParam, SURFACE_PARAMS &surfaceParam, bool &bInit)
1816 {
1817 switch (uIndex)
1818 {
1819 case FC_FP_FASTEXPRESS_INPUTPL0:
1820 surfaceParam.surfType = compParam.inputLayersParam[0].needIntermediaSurface ? SurfaceTypeFcIntermediaInput : SurfaceTypeFcInputLayer0;
1821 if (compParam.inputLayersParam[0].diParams.enabled &&
1822 compParam.inputLayersParam[0].diParams.params.DIMode == DI_MODE_BOB)
1823 {
1824 surfaceParam.needVerticalStirde = true;
1825 }
1826 break;
1827 case FC_FP_FASTEXPRESS_OUTPUTPL0:
1828 surfaceParam.surfType = SurfaceTypeFcTarget0;
1829 surfaceParam.isOutput = true;
1830 surfaceParam.combineChannelY = true;
1831 break;
1832 case FC_FP_FASTEXPRESS_INPUTPL1:
1833 case FC_FP_FASTEXPRESS_OUTPUTPL1:
1834 surfaceParam.surfType = SurfaceTypeInvalid;
1835 break;
1836 default:
1837 bInit = false;
1838 break;
1839 }
1840
1841 return MOS_STATUS_SUCCESS;
1842 }
1843
SetupSingleFcFastExpressKrnArg(L0_FC_FP_KRN_IMAGE_PARAM & imageParams,L0_FC_FP_KRN_TARGET_PARAM & targetParam,uint32_t localSize[3],uint32_t globalSize[3],KRN_ARG & krnArg,bool & bInit)1844 MOS_STATUS VpL0FcFilter::SetupSingleFcFastExpressKrnArg(L0_FC_FP_KRN_IMAGE_PARAM &imageParams, L0_FC_FP_KRN_TARGET_PARAM &targetParam, uint32_t localSize[3], uint32_t globalSize[3], KRN_ARG &krnArg, bool &bInit)
1845 {
1846 switch (krnArg.uIndex)
1847 {
1848 case FC_FP_FASTEXPRESS_IMAGEPARAM:
1849 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
1850 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(imageParams));
1851 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &imageParams, sizeof(imageParams));
1852 break;
1853 case FC_FP_FASTEXPRESS_OUTPUTPARAM:
1854 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
1855 VP_PUBLIC_CHK_VALUE_RETURN(krnArg.uSize, sizeof(targetParam));
1856 MOS_SecureMemcpy(krnArg.pData, krnArg.uSize, &targetParam, sizeof(targetParam));
1857 break;
1858 case FC_FP_FASTEXPRESS_INLINE_SAMPLER_LINEAR_CLAMP_EDGE:
1859 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
1860 *(uint32_t *)krnArg.pData = MHW_SAMPLER_FILTER_BILINEAR;
1861 break;
1862 case FC_FP_FASTEXPRESS_INLINE_SAMPLER_NEAREST_CLAMP_EDGE:
1863 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
1864 *(uint32_t *)krnArg.pData = MHW_SAMPLER_FILTER_NEAREST;
1865 break;
1866 case FC_FP_FASTEXPRESS_GLOBAL_SIZE:
1867 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
1868 static_cast<uint32_t *>(krnArg.pData)[0] = globalSize[0];
1869 static_cast<uint32_t *>(krnArg.pData)[1] = globalSize[1];
1870 static_cast<uint32_t *>(krnArg.pData)[2] = globalSize[2];
1871 break;
1872 case FC_FP_FASTEXPRESS_ENQUEUED_LOCAL_SIZE:
1873 case FC_FP_FASTEXPRESS_LOCAL_SIZE:
1874 VP_PUBLIC_CHK_NULL_RETURN(krnArg.pData);
1875 static_cast<uint32_t *>(krnArg.pData)[0] = localSize[0];
1876 static_cast<uint32_t *>(krnArg.pData)[1] = localSize[1];
1877 static_cast<uint32_t *>(krnArg.pData)[2] = localSize[2];
1878 break;
1879 default:
1880 bInit = false;
1881 break;
1882 }
1883
1884 return MOS_STATUS_SUCCESS;
1885 }
1886
GenerateFastExpressInputOutputParam(L0_FC_COMP_PARAM & compParam,L0_FC_FP_KRN_IMAGE_PARAM & imageParam,L0_FC_FP_KRN_TARGET_PARAM & targetParam)1887 MOS_STATUS VpL0FcFilter::GenerateFastExpressInputOutputParam(L0_FC_COMP_PARAM &compParam, L0_FC_FP_KRN_IMAGE_PARAM &imageParam, L0_FC_FP_KRN_TARGET_PARAM &targetParam)
1888 {
1889 VP_FUNC_CALL();
1890 L0_FC_LAYER_PARAM &inputLayer = compParam.inputLayersParam[0];
1891 L0_FC_LAYER_PARAM &outputLayer = compParam.outputLayerParam;
1892 MOS_FORMAT surfOverwriteFormat = inputLayer.needIntermediaSurface ? inputLayer.interMediaOverwriteSurface : inputLayer.surf->osSurface->Format;
1893 VP_PUBLIC_CHK_NULL_RETURN(inputLayer.surf);
1894 VP_PUBLIC_CHK_NULL_RETURN(inputLayer.surf->osSurface);
1895 VP_PUBLIC_CHK_NULL_RETURN(outputLayer.surf);
1896 VP_PUBLIC_CHK_NULL_RETURN(outputLayer.surf->osSurface);
1897
1898 uint32_t inputWidth = MOS_MIN(static_cast<uint32_t>(inputLayer.surf->osSurface->dwWidth), static_cast<uint32_t>(inputLayer.surf->rcSrc.right));
1899 uint32_t inputHeight = MOS_MIN(static_cast<uint32_t>(inputLayer.surf->osSurface->dwHeight), static_cast<uint32_t>(inputLayer.surf->rcSrc.bottom));
1900 VP_PUBLIC_CHK_STATUS_RETURN(ConvertCscToKrnParam(inputLayer.surf->ColorSpace, compParam.mainCSpace, imageParam.csc));
1901 VP_PUBLIC_CHK_STATUS_RETURN(ConvertInputChannelIndicesToKrnParam(surfOverwriteFormat, imageParam.inputChannelIndices));
1902 VP_PUBLIC_CHK_STATUS_RETURN(ConvertScalingRotToKrnParam(inputLayer.surf->rcSrc, inputLayer.surf->rcDst, inputLayer.scalingMode, inputWidth, inputHeight, inputLayer.rotation, imageParam.scaleParam, imageParam.controlSetting.samplerType, imageParam.coordShift));
1903 VP_PUBLIC_CHK_STATUS_RETURN(ConvertChromaUpsampleToKrnParam(surfOverwriteFormat, inputLayer.surf->ChromaSiting, inputLayer.scalingMode, inputWidth, inputHeight, imageParam.coordShift.chromaShiftX, imageParam.coordShift.chromaShiftY, imageParam.controlSetting.isChromaShift));
1904 VP_PUBLIC_CHK_STATUS_RETURN(ConvertPlaneNumToKrnParam(surfOverwriteFormat, true, imageParam.inputPlaneNum));
1905
1906 VP_PUBLIC_CHK_STATUS_RETURN(ConvertAlignedTrgRectToKrnParam(inputLayer.surf, outputLayer.surf, compParam.enableColorFill, targetParam));
1907 VP_PUBLIC_CHK_STATUS_RETURN(ConvertPlaneNumToKrnParam(outputLayer.surf->osSurface->Format, false, targetParam.planeNumber));
1908 VP_PUBLIC_CHK_STATUS_RETURN(ConvertOuputChannelIndicesToKrnParam(outputLayer.surf->osSurface->Format, targetParam.dynamicChannelIndices));
1909 targetParam.combineChannelIndices[0] = 0;
1910 targetParam.combineChannelIndices[1] = 1;
1911 VP_PUBLIC_CHK_STATUS_RETURN(ConvertTargetRoiToKrnParam(outputLayer.surf->rcDst, outputLayer.surf->osSurface->dwWidth, outputLayer.surf->osSurface->dwHeight, targetParam.targetROI));
1912 VP_PUBLIC_CHK_STATUS_RETURN(ConvertChromaDownsampleToKrnParam(outputLayer.surf->osSurface->Format, outputLayer.surf->ChromaSiting, targetParam.chromaSitingFactor, targetParam.controlSetting.hitSecPlaneFactorX, targetParam.controlSetting.hitSecPlaneFactorY));
1913 VP_PUBLIC_CHK_STATUS_RETURN(ConvertColorFillToKrnParam(compParam.enableColorFill, compParam.colorFillParams, compParam.mainCSpace, targetParam.controlSetting.isColorFill, targetParam.background));
1914 //ConvertAlphaToKrnParam must be called after ConvertColorFillToKrnParam
1915 uint8_t alphaLayerIndex = 0;
1916 VP_PUBLIC_CHK_STATUS_RETURN(ConvertAlphaToKrnParam(compParam.bAlphaCalculateEnable, compParam.compAlpha, targetParam.background[3], alphaLayerIndex, targetParam.alpha));
1917 targetParam.controlSetting.alphaLayerIndex = (alphaLayerIndex != 0);
1918
1919 return MOS_STATUS_SUCCESS;
1920 }
1921
ConvertAlignedTrgRectToKrnParam(VP_SURFACE * inputSurf,VP_SURFACE * outputSurf,bool enableColorFill,L0_FC_FP_KRN_TARGET_PARAM & targetParam)1922 MOS_STATUS VpL0FcFilter::ConvertAlignedTrgRectToKrnParam(VP_SURFACE *inputSurf, VP_SURFACE *outputSurf, bool enableColorFill, L0_FC_FP_KRN_TARGET_PARAM &targetParam)
1923 {
1924 VP_PUBLIC_CHK_NULL_RETURN(inputSurf);
1925 VP_PUBLIC_CHK_NULL_RETURN(inputSurf->osSurface);
1926 VP_PUBLIC_CHK_NULL_RETURN(outputSurf);
1927 VP_PUBLIC_CHK_NULL_RETURN(outputSurf->osSurface);
1928
1929
1930 RECT alignedRect = {};
1931 if (enableColorFill)
1932 {
1933 alignedRect.left = MOS_ALIGN_FLOOR(MOS_MAX(0, outputSurf->rcDst.left), 8);
1934 alignedRect.right = MOS_ALIGN_CEIL(MOS_MIN(outputSurf->osSurface->dwWidth, (uint64_t)outputSurf->rcDst.right), 8);
1935 alignedRect.top = MOS_ALIGN_FLOOR(MOS_MAX(0, outputSurf->rcDst.top), 4);
1936 alignedRect.bottom = MOS_ALIGN_CEIL(MOS_MIN(outputSurf->osSurface->dwHeight, (uint64_t)outputSurf->rcDst.bottom), 4);
1937 }
1938 else
1939 {
1940 alignedRect.left = MOS_ALIGN_FLOOR(MOS_MAX(0, inputSurf->rcDst.left), 8);
1941 alignedRect.right = MOS_ALIGN_CEIL(MOS_MIN(outputSurf->osSurface->dwWidth, (uint64_t)inputSurf->rcDst.right), 8);
1942 alignedRect.top = MOS_ALIGN_FLOOR(MOS_MAX(0, inputSurf->rcDst.top), 4);
1943 alignedRect.bottom = MOS_ALIGN_CEIL(MOS_MIN(outputSurf->osSurface->dwHeight, (uint64_t)inputSurf->rcDst.bottom), 4);
1944 }
1945 targetParam.alignedTrgRectStart.x = static_cast<uint16_t>(alignedRect.left);
1946 targetParam.alignedTrgRectStart.y = static_cast<uint16_t>(alignedRect.top);
1947 targetParam.alignedTrgRectSize.width = static_cast<uint16_t>(alignedRect.right - alignedRect.left) / 2;
1948 targetParam.alignedTrgRectSize.height = static_cast<uint16_t>(alignedRect.bottom - alignedRect.top) / 2;
1949
1950
1951 return MOS_STATUS_SUCCESS;
1952 }
1953
PrintFastExpressKrnParam(L0_FC_FP_KRN_IMAGE_PARAM & imageParam,L0_FC_FP_KRN_TARGET_PARAM & targetParam)1954 void VpL0FcFilter::PrintFastExpressKrnParam(L0_FC_FP_KRN_IMAGE_PARAM& imageParam, L0_FC_FP_KRN_TARGET_PARAM& targetParam)
1955 {
1956 #if (_DEBUG || _RELEASE_INTERNAL)
1957 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: CSC %f %f %f %f", imageParam.csc.s0123[0], imageParam.csc.s0123[1], imageParam.csc.s0123[2], imageParam.csc.s0123[3]);
1958 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: CSC %f %f %f %f", imageParam.csc.s4567[0], imageParam.csc.s4567[1], imageParam.csc.s4567[2], imageParam.csc.s4567[3]);
1959 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: CSC %f %f %f %f", imageParam.csc.s89AB[0], imageParam.csc.s89AB[1], imageParam.csc.s89AB[2], imageParam.csc.s89AB[3]);
1960 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: CSC %f %f %f %f", imageParam.csc.sCDEF[0], imageParam.csc.sCDEF[1], imageParam.csc.sCDEF[2], imageParam.csc.sCDEF[3]);
1961
1962 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: inputChannelIndices %u %u %u %u",
1963 imageParam.inputChannelIndices[0],
1964 imageParam.inputChannelIndices[1],
1965 imageParam.inputChannelIndices[2],
1966 imageParam.inputChannelIndices[3]);
1967
1968 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: Scaling Src, startX %f, StartY %f, StrideX %f, StrideY %f",
1969 imageParam.scaleParam.src.startX,
1970 imageParam.scaleParam.src.startY,
1971 imageParam.scaleParam.src.strideX,
1972 imageParam.scaleParam.src.strideY);
1973 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: Scaling Dst Rect, left %u, right %u, top %u, bottom %u",
1974 imageParam.scaleParam.trg.left,
1975 imageParam.scaleParam.trg.right,
1976 imageParam.scaleParam.trg.top,
1977 imageParam.scaleParam.trg.bottom);
1978 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: Rotation, indices[0] %u, indices[1] %u",
1979 imageParam.scaleParam.rotateIndices[0],
1980 imageParam.scaleParam.rotateIndices[1]);
1981 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: CoordShift isChromaShift %d, CommonShiftX %f, CommonShiftY %f, ChromaShiftX %f, ChromaShiftY %f",
1982 imageParam.controlSetting.isChromaShift,
1983 imageParam.coordShift.commonShiftX,
1984 imageParam.coordShift.commonShiftY,
1985 imageParam.coordShift.chromaShiftX,
1986 imageParam.coordShift.chromaShiftY);
1987
1988 VP_PUBLIC_NORMALMESSAGE("L0 FC FP ImageParam: inputPlaneNum %u, SamplerType %d, ignoreSrcPixelAlpha %d, ignoreDstPixelAlpha %d",
1989 imageParam.inputPlaneNum,
1990 imageParam.controlSetting.samplerType,
1991 imageParam.controlSetting.ignoreSrcPixelAlpha,
1992 imageParam.controlSetting.ignoreDstPixelAlpha);
1993
1994 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: dynamicChannelIndices %u %u %u %u",
1995 targetParam.dynamicChannelIndices[0],
1996 targetParam.dynamicChannelIndices[1],
1997 targetParam.dynamicChannelIndices[2],
1998 targetParam.dynamicChannelIndices[3]);
1999
2000 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: Combined Channel Indices %u %u",
2001 targetParam.combineChannelIndices[0],
2002 targetParam.combineChannelIndices[1]);
2003
2004 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: Target ROI Rect, left %u, right %u, top %u, bottom %u",
2005 targetParam.targetROI.left,
2006 targetParam.targetROI.right,
2007 targetParam.targetROI.top,
2008 targetParam.targetROI.bottom);
2009
2010 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: background %f %f %f %f",
2011 targetParam.background[0],
2012 targetParam.background[1],
2013 targetParam.background[2],
2014 targetParam.background[3]);
2015
2016 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: chromaSiting: secPlaneFactorX %d, secPlaneFactorY %d",
2017 targetParam.controlSetting.hitSecPlaneFactorX,
2018 targetParam.controlSetting.hitSecPlaneFactorY);
2019 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: chromaSiting: chromaSitingFactorLeftTop %f, chromaSitingFactorRightTop %f, chromaSitingFactorLeftBottom %f, chromaSitingFactorRightBottom %f",
2020 targetParam.chromaSitingFactor[0],
2021 targetParam.chromaSitingFactor[1],
2022 targetParam.chromaSitingFactor[2],
2023 targetParam.chromaSitingFactor[3]);
2024
2025 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: planeNum %u, enableColorFill %d, alphaLayerIndex %d, fAlpha %f",
2026 targetParam.planeNumber,
2027 targetParam.controlSetting.isColorFill,
2028 targetParam.controlSetting.alphaLayerIndex,
2029 targetParam.alpha);
2030
2031 VP_PUBLIC_NORMALMESSAGE("L0 FC FP TargeParam: Aligned RECT x %d, y %d, width %d, height %d",
2032 targetParam.alignedTrgRectStart.x,
2033 targetParam.alignedTrgRectStart.y,
2034 targetParam.alignedTrgRectSize.width,
2035 targetParam.alignedTrgRectSize.height);
2036 #endif
2037 }
2038
SetPerfTag(L0_FC_COMP_PARAM & compParam,VPHAL_PERFTAG & perfTag)2039 MOS_STATUS VpL0FcFilter::SetPerfTag(L0_FC_COMP_PARAM& compParam, VPHAL_PERFTAG& perfTag)
2040 {
2041 bool rotation = false;
2042 bool primary = false;
2043
2044 for (uint32_t i = 0; i < compParam.layerNumber; ++i)
2045 {
2046 L0_FC_LAYER_PARAM &layer = compParam.inputLayersParam[i];
2047 if (layer.surf && layer.surf->SurfType == SURF_IN_PRIMARY)
2048 {
2049 primary = true;
2050 }
2051 if (layer.rotation != VPHAL_ROTATION_IDENTITY)
2052 {
2053 rotation = true;
2054 }
2055 }
2056 if (rotation)
2057 {
2058 perfTag = VPHAL_PERFTAG(VPHAL_ROT + compParam.layerNumber);
2059 }
2060 else if (primary)
2061 {
2062 perfTag = VPHAL_PERFTAG(VPHAL_PRI + compParam.layerNumber);
2063 }
2064 else
2065 {
2066 perfTag = VPHAL_PERFTAG(VPHAL_NONE + compParam.layerNumber);
2067 }
2068
2069 return MOS_STATUS_SUCCESS;
2070 }
2071
PrintCompParam(L0_FC_COMP_PARAM & compParam)2072 void VpL0FcFilter::PrintCompParam(L0_FC_COMP_PARAM& compParam)
2073 {
2074 VP_FUNC_CALL();
2075 #if (_DEBUG || _RELEASE_INTERNAL)
2076 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: Layer Number %u", compParam.layerNumber);
2077 for (uint32_t i = 0; i < compParam.layerNumber; ++i)
2078 {
2079 PrintCompLayerParam(i, true, compParam.inputLayersParam[i]);
2080 }
2081 PrintCompLayerParam(0, false, compParam.outputLayerParam);
2082
2083 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: mainCSpace %d", compParam.mainCSpace);
2084 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: enableCalculateAlpha %d, alphaMode %d, alpha %f", compParam.bAlphaCalculateEnable, compParam.compAlpha.AlphaMode, compParam.compAlpha.fAlpha);
2085
2086 VPHAL_COLOR_SAMPLE_8 color = {};
2087 color.dwValue = compParam.colorFillParams.Color;
2088 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: enableColorFill %d, CSpace %d", compParam.enableColorFill, compParam.colorFillParams.CSpace);
2089 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: colorFill R %d, G %d, B %d, A %d", color.R, color.G, color.B, color.A);
2090 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: colorFill Y %d, U %d, V %d, A %d", color.Y, color.U, color.V, color.a);
2091 VP_PUBLIC_NORMALMESSAGE("L0 FC CompParam: colorFill YY %d, Cr %d, Cb %d, A %d", color.YY, color.Cr, color.Cb, color.Alpha);
2092 #endif
2093 }
2094
PrintCompLayerParam(uint32_t index,bool isInput,L0_FC_LAYER_PARAM & layerParam)2095 void VpL0FcFilter::PrintCompLayerParam(uint32_t index, bool isInput, L0_FC_LAYER_PARAM &layerParam)
2096 {
2097 #if (_DEBUG || _RELEASE_INTERNAL)
2098 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: isInput %d, layerIndex %u, layerID %u, layerOriginID %u", isInput, index, layerParam.layerID, layerParam.layerIDOrigin);
2099 VP_SURFACE *surf = layerParam.surf;
2100 if (surf)
2101 {
2102 if (surf->osSurface)
2103 {
2104 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: Format %d, Width %lu, Height %lu", surf->osSurface->Format, surf->osSurface->dwWidth, surf->osSurface->dwHeight);
2105 }
2106 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: CSpace %d, ChromaSiting 0x%x", surf->ColorSpace, surf->ChromaSiting);
2107 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: Src Rect, left %ld, right %ld, top %ld, bottom %ld", surf->rcSrc.left, surf->rcSrc.right, surf->rcSrc.top, surf->rcSrc.bottom);
2108 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: Dst Rect, left %ld, right %ld, top %ld, bottom %ld", surf->rcDst.left, surf->rcDst.right, surf->rcDst.top, surf->rcDst.bottom);
2109 }
2110
2111 if (isInput)
2112 {
2113 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: ScalingMode %d, RotationMir %d", layerParam.scalingMode, layerParam.rotation);
2114 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: LumaKey enable %d, low %d, high %d", layerParam.lumaKey.enabled, layerParam.lumaKey.params.LumaLow, layerParam.lumaKey.params.LumaHigh);
2115 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: Blending type %d, alpha %f", layerParam.blendingParams.BlendType, layerParam.blendingParams.fAlpha);
2116 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: Deinterlace enabled %d, FMD %d, SCD %d, SingleField %d, mode %d",
2117 layerParam.diParams.enabled,
2118 layerParam.diParams.params.bEnableFMD,
2119 layerParam.diParams.params.bSCDEnable,
2120 layerParam.diParams.params.bSingleField,
2121 layerParam.diParams.params.DIMode);
2122 VP_PUBLIC_NORMALMESSAGE("L0 FC CompLayerParam: Procamp enabled %d, brightness %f, contrast %f, hue %f, saturation %f",
2123 layerParam.procampParams.bEnabled,
2124 layerParam.procampParams.fBrightness,
2125 layerParam.procampParams.fContrast,
2126 layerParam.procampParams.fHue,
2127 layerParam.procampParams.fSaturation);
2128 }
2129
2130 VP_PUBLIC_NORMALMESSAGE("");
2131 #endif
2132 }
2133
PrintKrnParam(std::vector<L0_FC_KRN_IMAGE_PARAM> & imageParams,L0_FC_KRN_TARGET_PARAM & targetParam)2134 void VpL0FcFilter::PrintKrnParam(std::vector<L0_FC_KRN_IMAGE_PARAM>& imageParams, L0_FC_KRN_TARGET_PARAM& targetParam)
2135 {
2136 VP_FUNC_CALL();
2137 #if (_DEBUG || _RELEASE_INTERNAL)
2138 for (uint32_t i = 0; i < imageParams.size(); ++i)
2139 {
2140 PrintKrnImageParam(i, imageParams.at(i));
2141 }
2142 PrintKrnTargetParam(targetParam);
2143 #endif
2144 }
2145
PrintKrnImageParam(uint32_t index,L0_FC_KRN_IMAGE_PARAM & imageParam)2146 void VpL0FcFilter::PrintKrnImageParam(uint32_t index, L0_FC_KRN_IMAGE_PARAM &imageParam)
2147 {
2148 #if (_DEBUG || _RELEASE_INTERNAL)
2149 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam Layer Index %d", index);
2150 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: CSC %f %f %f %f", imageParam.csc.s0123[0], imageParam.csc.s0123[1], imageParam.csc.s0123[2], imageParam.csc.s0123[3]);
2151 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: CSC %f %f %f %f", imageParam.csc.s4567[0], imageParam.csc.s4567[1], imageParam.csc.s4567[2], imageParam.csc.s4567[3]);
2152 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: CSC %f %f %f %f", imageParam.csc.s89AB[0], imageParam.csc.s89AB[1], imageParam.csc.s89AB[2], imageParam.csc.s89AB[3]);
2153 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: CSC %f %f %f %f", imageParam.csc.sCDEF[0], imageParam.csc.sCDEF[1], imageParam.csc.sCDEF[2], imageParam.csc.sCDEF[3]);
2154
2155 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: inputChannelIndices %u %u %u %u",
2156 imageParam.inputChannelIndices[0],
2157 imageParam.inputChannelIndices[1],
2158 imageParam.inputChannelIndices[2],
2159 imageParam.inputChannelIndices[3]);
2160
2161 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: Scaling Src, startX %f, StartY %f, StrideX %f, StrideY %f",
2162 imageParam.scale.src.startX,
2163 imageParam.scale.src.startY,
2164 imageParam.scale.src.strideX,
2165 imageParam.scale.src.strideY);
2166 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: Scaling Dst Rect, left %u, right %u, top %u, bottom %u",
2167 imageParam.scale.trg.left,
2168 imageParam.scale.trg.right,
2169 imageParam.scale.trg.top,
2170 imageParam.scale.trg.bottom);
2171 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: Rotation, indices[0] %u, indices[1] %u",
2172 imageParam.scale.rotateIndices[0],
2173 imageParam.scale.rotateIndices[1]);
2174 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: CoordShift isChromaShift %d, CommonShiftX %f, CommonShiftY %f, ChromaShiftX %f, ChromaShiftY %f",
2175 imageParam.controlSetting.isChromaShift,
2176 imageParam.coordShift.commonShiftX,
2177 imageParam.coordShift.commonShiftY,
2178 imageParam.coordShift.chromaShiftX,
2179 imageParam.coordShift.chromaShiftY);
2180
2181 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: LumaKey min %f, max %f", imageParam.lumaKey.low, imageParam.lumaKey.high);
2182
2183 VP_PUBLIC_NORMALMESSAGE("L0 FC ImageParam: inputPlaneNum %u, SamplerType %d, ignoreSrcPixelAlpha %d, ignoreDstPixelAlpha %d, constAlpha %f",
2184 imageParam.inputPlaneNum,
2185 imageParam.controlSetting.samplerType,
2186 imageParam.controlSetting.ignoreSrcPixelAlpha,
2187 imageParam.controlSetting.ignoreDstPixelAlpha,
2188 imageParam.constAlphs);
2189
2190 VP_PUBLIC_NORMALMESSAGE("");
2191 #endif
2192 }
2193
PrintKrnTargetParam(L0_FC_KRN_TARGET_PARAM & targetParam)2194 void VpL0FcFilter::PrintKrnTargetParam(L0_FC_KRN_TARGET_PARAM& targetParam)
2195 {
2196 #if (_DEBUG || _RELEASE_INTERNAL)
2197 VP_PUBLIC_NORMALMESSAGE("L0 FC TargeParam: dynamicChannelIndices %u %u %u %u",
2198 targetParam.dynamicChannelIndices[0],
2199 targetParam.dynamicChannelIndices[1],
2200 targetParam.dynamicChannelIndices[2],
2201 targetParam.dynamicChannelIndices[3]);
2202
2203 VP_PUBLIC_NORMALMESSAGE("L0 FC TargeParam: Target ROI Rect, left %u, right %u, top %u, bottom %u",
2204 targetParam.targetROI.left,
2205 targetParam.targetROI.right,
2206 targetParam.targetROI.top,
2207 targetParam.targetROI.bottom);
2208
2209 VP_PUBLIC_NORMALMESSAGE("L0 FC TargeParam: background %f %f %f %f",
2210 targetParam.background[0],
2211 targetParam.background[1],
2212 targetParam.background[2],
2213 targetParam.background[3]);
2214
2215 VP_PUBLIC_NORMALMESSAGE("L0 FC TargeParam: chromaSiting: secPlaneFactorX %d, secPlaneFactorY %d",
2216 targetParam.controlSetting.hitSecPlaneFactorX,
2217 targetParam.controlSetting.hitSecPlaneFactorY);
2218 VP_PUBLIC_NORMALMESSAGE("L0 FC TargeParam: chromaSiting: chromaSitingFactorLeftTop %f, chromaSitingFactorRightTop %f, chromaSitingFactorLeftBottom %f, chromaSitingFactorRightBottom %f",
2219 targetParam.chromaSitingFactor[0],
2220 targetParam.chromaSitingFactor[1],
2221 targetParam.chromaSitingFactor[2],
2222 targetParam.chromaSitingFactor[3]);
2223
2224 VP_PUBLIC_NORMALMESSAGE("L0 FC TargeParam: planeNum %u, enableColorFill %d, alphaLayerIndex %d, fAlpha %f",
2225 targetParam.planeNumber,
2226 targetParam.controlSetting.isColorFill,
2227 targetParam.controlSetting.alphaLayerIndex,
2228 targetParam.alpha);
2229 #endif
2230 }
2231
ReportDiffLog(const L0_FC_COMP_PARAM & compParam)2232 void VpL0FcFilter::ReportDiffLog(const L0_FC_COMP_PARAM &compParam)
2233 {
2234 VP_FUNC_CALL();
2235 #if (_DEBUG || _RELEASE_INTERNAL)
2236 VpFeatureReport *vpFeatureReport = m_pvpMhwInterface->m_reporting;
2237 if (vpFeatureReport == nullptr)
2238 {
2239 VP_PUBLIC_ASSERTMESSAGE("vpFeatureReportExt is nullptr");
2240 return;
2241 }
2242 uint32_t &reportLog = vpFeatureReport->GetFeatures().diffLogL0FC;
2243 //check 422 input
2244 for (uint32_t i = 0; i < compParam.layerNumber; ++i)
2245 {
2246 const L0_FC_LAYER_PARAM &layer = compParam.inputLayersParam[i];
2247 VP_SURFACE *surf = layer.surf;
2248 if (surf)
2249 {
2250 if (surf->osSurface)
2251 {
2252 MOS_FORMAT format = surf->osSurface->Format;
2253 if (layer.scalingMode == VPHAL_SCALING_BILINEAR)
2254 {
2255 // bilinear scaling shift difference
2256 reportLog |= (1llu << 0);
2257 if (format == Format_NV12 ||
2258 format == Format_P010 ||
2259 format == Format_P016)
2260 {
2261 //1 plane and 2 plane surface state read difference
2262 reportLog |= (1llu << 1);
2263 }
2264 }
2265
2266 if (format == Format_400P)
2267 {
2268 //400P has issue on legacy FC even with nearest sampler
2269 reportLog |= (1llu << 2);
2270 }
2271 }
2272 }
2273 if (layer.rotation != VPHAL_ROTATION_IDENTITY)
2274 {
2275 //rotation shift place is different with legacy FC
2276 reportLog |= (1llu << 3);
2277 }
2278 if (layer.diParams.enabled || layer.procampParams.bEnabled)
2279 {
2280 //di and procamp is not enabled
2281 reportLog |= (1llu << 4);
2282 }
2283 if (layer.lumaKey.enabled)
2284 {
2285 //luma key cases will have difference for float(L0FC) vs int(FC)
2286 reportLog |= (1llu << 5);
2287 }
2288 }
2289
2290 VP_SURFACE *targetSurf = compParam.outputLayerParam.surf;
2291 if (targetSurf)
2292 {
2293 if (targetSurf->osSurface)
2294 {
2295 MOS_FORMAT format = targetSurf->osSurface->Format;
2296 if ((format == Format_Y210 ||
2297 format == Format_Y216 ||
2298 format == Format_YUY2 ||
2299 format == Format_YUYV ||
2300 format == Format_YVYU ||
2301 format == Format_UYVY ||
2302 format == Format_VYUY) &&
2303 targetSurf->ChromaSiting & CHROMA_SITING_HORZ_CENTER)
2304 {
2305 //422 packed no chromasiting on legacy FC
2306 reportLog |= (1llu << 6);
2307 }
2308
2309 if ((format == Format_A8R8G8B8 ||
2310 format == Format_A8B8G8R8 ||
2311 format == Format_R10G10B10A2 ||
2312 format == Format_B10G10R10A2 ||
2313 format == Format_Y410) &&
2314 compParam.compAlpha.AlphaMode == VPHAL_ALPHA_FILL_MODE_OPAQUE)
2315 {
2316 //fixed alpha not used in legacy FC
2317 reportLog |= (1llu << 7);
2318 }
2319 }
2320 }
2321 if (FastExpressConditionMeet(compParam))
2322 {
2323 reportLog |= (1llu << 16);
2324 }
2325
2326 //actually walked into L0 FC. Always set to 1 when L0 FC Filter take effect. "L0 FC Enabled" may be 1 but not walked into L0 FC, cause it may fall back in wrapper class
2327 reportLog |= (1llu << 31);
2328
2329 VP_PUBLIC_NORMALMESSAGE("L0FC vs FC Difference Report Log: 0x%x", reportLog);
2330 #endif
2331 }
2332
CalculateEngineParams()2333 MOS_STATUS VpL0FcFilter::CalculateEngineParams()
2334 {
2335 VP_FUNC_CALL();
2336 if (m_executeCaps.bRender)
2337 {
2338 // create a filter Param buffer
2339 if (!m_renderL0FcParams)
2340 {
2341 m_renderL0FcParams = (PRENDER_L0_FC_PARAMS)MOS_New(RENDER_L0_FC_PARAMS);
2342
2343 if (m_renderL0FcParams == nullptr)
2344 {
2345 VP_PUBLIC_ASSERTMESSAGE("render l0 fc Pamas buffer allocate failed, return nullpointer");
2346 return MOS_STATUS_NO_SPACE;
2347 }
2348 }
2349 else
2350 {
2351 m_renderL0FcParams->Init();
2352 }
2353
2354 InitKrnParams(m_renderL0FcParams->fc_kernelParams, *m_executingPipe);
2355 }
2356 else
2357 {
2358 VP_PUBLIC_ASSERTMESSAGE("Wrong engine caps! Vebox should be used for Dn");
2359 }
2360 return MOS_STATUS_SUCCESS;
2361 }
2362
2363
2364 /****************************************************************************************************/
2365 /* HwFilter L0 Fc Parameter */
2366 /****************************************************************************************************/
Create(HW_FILTER_L0_FC_PARAM & param,FeatureType featureType)2367 HwFilterParameter *HwFilterL0FcParameter::Create(HW_FILTER_L0_FC_PARAM ¶m, FeatureType featureType)
2368 {
2369 VP_FUNC_CALL();
2370
2371 HwFilterL0FcParameter *p = MOS_New(HwFilterL0FcParameter, featureType);
2372 if (p)
2373 {
2374 if (MOS_FAILED(p->Initialize(param)))
2375 {
2376 MOS_Delete(p);
2377 return nullptr;
2378 }
2379 }
2380 return p;
2381 }
2382
HwFilterL0FcParameter(FeatureType featureType)2383 HwFilterL0FcParameter::HwFilterL0FcParameter(FeatureType featureType) : HwFilterParameter(featureType)
2384 {
2385 }
2386
~HwFilterL0FcParameter()2387 HwFilterL0FcParameter::~HwFilterL0FcParameter()
2388 {
2389 }
2390
ConfigParams(HwFilter & hwFilter)2391 MOS_STATUS HwFilterL0FcParameter::ConfigParams(HwFilter &hwFilter)
2392 {
2393 VP_FUNC_CALL();
2394
2395 return hwFilter.ConfigParam(m_Params);
2396 }
2397
Initialize(HW_FILTER_L0_FC_PARAM & param)2398 MOS_STATUS HwFilterL0FcParameter::Initialize(HW_FILTER_L0_FC_PARAM ¶m)
2399 {
2400 VP_FUNC_CALL();
2401
2402 m_Params = param;
2403 return MOS_STATUS_SUCCESS;
2404 }
2405
2406
2407 /****************************************************************************************************/
2408 /* Packet L0 Fc Parameter */
2409 /****************************************************************************************************/
Create(HW_FILTER_L0_FC_PARAM & param)2410 VpPacketParameter *VpRenderL0FcParameter::Create(HW_FILTER_L0_FC_PARAM ¶m)
2411 {
2412 VP_FUNC_CALL();
2413
2414 if (nullptr == param.pPacketParamFactory)
2415 {
2416 return nullptr;
2417 }
2418 VpRenderL0FcParameter *p = dynamic_cast<VpRenderL0FcParameter *>(param.pPacketParamFactory->GetPacketParameter(param.pHwInterface));
2419 if (p)
2420 {
2421 if (MOS_FAILED(p->Initialize(param)))
2422 {
2423 VpPacketParameter *pParam = p;
2424 param.pPacketParamFactory->ReturnPacketParameter(pParam);
2425 return nullptr;
2426 }
2427 }
2428 return p;
2429 }
2430
VpRenderL0FcParameter(PVP_MHWINTERFACE pHwInterface,PacketParamFactoryBase * packetParamFactory)2431 VpRenderL0FcParameter::VpRenderL0FcParameter(PVP_MHWINTERFACE pHwInterface, PacketParamFactoryBase *packetParamFactory) : VpPacketParameter(packetParamFactory), m_fcFilter(pHwInterface)
2432 {
2433 }
~VpRenderL0FcParameter()2434 VpRenderL0FcParameter::~VpRenderL0FcParameter() {}
2435
SetPacketParam(VpCmdPacket * pPacket)2436 bool VpRenderL0FcParameter::SetPacketParam(VpCmdPacket *pPacket)
2437 {
2438 VP_FUNC_CALL();
2439
2440 VpRenderCmdPacket *renderPacket = dynamic_cast<VpRenderCmdPacket *>(pPacket);
2441 if (nullptr == renderPacket)
2442 {
2443 return false;
2444 }
2445
2446 PRENDER_L0_FC_PARAMS params = m_fcFilter.GetFcParams();
2447 if (nullptr == params)
2448 {
2449 return false;
2450 }
2451 return MOS_SUCCEEDED(renderPacket->SetL0FcParams(params));
2452 }
2453
Initialize(HW_FILTER_L0_FC_PARAM & params)2454 MOS_STATUS VpRenderL0FcParameter::Initialize(HW_FILTER_L0_FC_PARAM ¶ms)
2455 {
2456 VP_FUNC_CALL();
2457
2458 VP_PUBLIC_CHK_STATUS_RETURN(m_fcFilter.Init());
2459 VP_PUBLIC_CHK_STATUS_RETURN(m_fcFilter.SetExecuteEngineCaps(params.executingPipe, params.vpExecuteCaps));
2460 VP_PUBLIC_CHK_STATUS_RETURN(m_fcFilter.CalculateEngineParams());
2461 return MOS_STATUS_SUCCESS;
2462 }
2463
2464
2465 /****************************************************************************************************/
2466 /* Policy FC Feature Handler */
2467 /****************************************************************************************************/
2468
UpdateFeaturePipe(VP_EXECUTE_CAPS caps,SwFilter & feature,SwFilterPipe & featurePipe,SwFilterPipe & executePipe,bool isInputPipe,int index)2469 MOS_STATUS PolicyL0FcFeatureHandler::UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index)
2470 {
2471 VP_FUNC_CALL();
2472
2473 FeatureType type = feature.GetFeatureType();
2474
2475 if (caps.bRenderHdr)
2476 {
2477 // HDR Kernel
2478 return PolicyFeatureHandler::UpdateFeaturePipe(caps, feature, featurePipe, executePipe, isInputPipe, index);
2479 }
2480 else
2481 {
2482 // FC
2483 if (FeatureTypeLumakeyOnRender == type ||
2484 FeatureTypeBlendingOnRender == type ||
2485 FeatureTypeAlphaOnRender == type ||
2486 FeatureTypeCscOnRender == type ||
2487 FeatureTypeScalingOnRender == type ||
2488 FeatureTypeRotMirOnRender == type ||
2489 FeatureTypeDiOnRender == type ||
2490 FeatureTypeProcampOnRender == type)
2491 {
2492 return PolicyFeatureHandler::UpdateFeaturePipe(caps, feature, featurePipe, executePipe, isInputPipe, index);
2493 }
2494 else if (FeatureTypeColorFillOnRender == type)
2495 {
2496 // Only apply color fill on 1st pass.
2497 VP_PUBLIC_CHK_STATUS_RETURN(featurePipe.RemoveSwFilter(&feature));
2498 VP_PUBLIC_CHK_STATUS_RETURN(executePipe.AddSwFilterUnordered(&feature, isInputPipe, index));
2499 }
2500 else
2501 {
2502 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
2503 }
2504 }
2505
2506 return MOS_STATUS_SUCCESS;
2507 }
2508
UpdateUnusedFeature(VP_EXECUTE_CAPS caps,SwFilter & feature,SwFilterPipe & featurePipe,SwFilterPipe & executePipe,bool isInputPipe,int index)2509 MOS_STATUS PolicyL0FcFeatureHandler::UpdateUnusedFeature(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index)
2510 {
2511 // feature.GetFilterEngineCaps().bEnabled should be used here instead of feature.IsFeatureEnabled(caps)
2512 // to ensure the feature does not be enabled.
2513 // feature.IsFeatureEnabled(caps) being false means the feature is not being used in current workload,
2514 // in which case, the feature itself may be enable and need be processed in following workloads.
2515 if (0 == caps.bOutputPipeFeatureInuse &&
2516 !feature.GetFilterEngineCaps().bEnabled &&
2517 (feature.GetFilterEngineCaps().forceEnableForSfc ||
2518 feature.GetFilterEngineCaps().forceEnableForFc))
2519 {
2520 // To avoid filter being destroyed in Policy::UpdateFeaturePipe.
2521 feature.GetFilterEngineCaps().usedForNextPass = 1;
2522 }
2523 return MOS_STATUS_SUCCESS;
2524 }
2525
2526 /****************************************************************************************************/
2527 /* Policy FC Handler */
2528 /****************************************************************************************************/
PolicyL0FcHandler(VP_HW_CAPS & hwCaps)2529 PolicyL0FcHandler::PolicyL0FcHandler(VP_HW_CAPS &hwCaps) : PolicyFcHandler(hwCaps)
2530 {
2531 m_Type = FeatureTypeFc;
2532 }
~PolicyL0FcHandler()2533 PolicyL0FcHandler::~PolicyL0FcHandler()
2534 {
2535 }
2536
CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)2537 HwFilterParameter *PolicyL0FcHandler::CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface)
2538 {
2539 VP_FUNC_CALL();
2540
2541 if (IsFeatureEnabled(vpExecuteCaps))
2542 {
2543 HW_FILTER_L0_FC_PARAM param = {};
2544 param.type = m_Type;
2545 param.pHwInterface = pHwInterface;
2546 param.vpExecuteCaps = vpExecuteCaps;
2547 param.pPacketParamFactory = &m_PacketL0ParamFactory;
2548 param.executingPipe = &swFilterPipe;
2549 param.pfnCreatePacketParam = PolicyL0FcHandler::CreatePacketParam;
2550
2551 HwFilterParameter *pHwFilterParam = GetHwFeatureParameterFromPool();
2552
2553 if (pHwFilterParam)
2554 {
2555 if (MOS_FAILED(((HwFilterL0FcParameter *)pHwFilterParam)->Initialize(param)))
2556 {
2557 ReleaseHwFeatureParameter(pHwFilterParam);
2558 }
2559 }
2560 else
2561 {
2562 pHwFilterParam = HwFilterL0FcParameter::Create(param, m_Type);
2563 }
2564
2565 return pHwFilterParam;
2566 }
2567 else
2568 {
2569 return nullptr;
2570 }
2571 }
2572 }