Debian Codegraph @

media_softlet/agnostic/common/vp/hal/bufferMgr/vp_resource_manager.cpp

raw
1 /*
2 * Copyright (c) 2018-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_resource_manager.cpp
24 //! \brief The source file of the base class of vp resource manager
25 //! \details all the vp resources will be traced here for usages using intermeida
26 //! surfaces.
27 //!
28 #include "vp_resource_manager.h"
29 #include "vp_vebox_cmd_packet.h"
30 #include "sw_filter_pipe.h"
31 #include "vp_utils.h"
32 #include "vp_platform_interface.h"
33
34 using namespace std;
35 namespace vp
36 {
37
38 #define VP_SAME_SAMPLE_THRESHOLD 0
39 #define VP_COMP_CMFC_COEFF_WIDTH 64
40 #define VP_COMP_CMFC_COEFF_HEIGHT 8
41
42 inline bool IsInterleaveFirstField(VPHAL_SAMPLE_TYPE sampleType)
43 {
44 VP_FUNC_CALL();
45 return ((sampleType == SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD) ||
46 (sampleType == SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD) ||
47 (sampleType == SAMPLE_SINGLE_TOP_FIELD));
48 }
49
50 extern const VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATION g_cInit_VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATIONS =
51 {
52 // DWORD 0
53 {
54 {NOISE_BLF_RANGE_THRESHOLD_S0_DEFAULT}, // RangeThrStart0
55 },
56
57 // DWORD 1
58 {
59 {NOISE_BLF_RANGE_THRESHOLD_S1_DEFAULT}, // RangeThrStart1
60 },
61
62 // DWORD 2
63 {
64 {NOISE_BLF_RANGE_THRESHOLD_S2_DEFAULT}, // RangeThrStart2
65 },
66
67 // DWORD 3
68 {
69 {NOISE_BLF_RANGE_THRESHOLD_S3_DEFAULT}, // RangeThrStart3
70 },
71
72 // DWORD 4
73 {
74 {NOISE_BLF_RANGE_THRESHOLD_S4_DEFAULT}, // RangeThrStart4
75 },
76
77 // DWORD 5
78 {
79 {NOISE_BLF_RANGE_THRESHOLD_S5_DEFAULT}, // RangeThrStart5
80 },
81
82 // DWORD 6
83 {
84 {0}, // Reserved
85 },
86
87 // DWORD 7
88 {
89 {0}, // Reserved
90 },
91
92 // DWORD 8
93 {
94 {NOISE_BLF_RANGE_WGTS0_DEFAULT}, // RangeWgt0
95 },
96
97 // DWORD 9
98 {
99 {NOISE_BLF_RANGE_WGTS1_DEFAULT}, // RangeWgt1
100 },
101
102 // DWORD 10
103 {
104 {NOISE_BLF_RANGE_WGTS2_DEFAULT}, // RangeWgt2
105 },
106
107 // DWORD 11
108 {
109 {NOISE_BLF_RANGE_WGTS3_DEFAULT}, // RangeWgt3
110 },
111
112 // DWORD 12
113 {
114 {NOISE_BLF_RANGE_WGTS4_DEFAULT}, // RangeWgt4
115 },
116
117 // DWORD 13
118 {
119 {NOISE_BLF_RANGE_WGTS5_DEFAULT}, // RangeWgt5
120 },
121
122 // DWORD 14
123 {
124 {0}, // Reserved
125 },
126
127 // DWORD 15
128 {
129 {0}, // Reserved
130 },
131
132 // DWORD 16 - 41: DistWgt[5][5]
133 {
134 {NOISE_BLF_DISTANCE_WGTS00_DEFAULT, NOISE_BLF_DISTANCE_WGTS01_DEFAULT, NOISE_BLF_DISTANCE_WGTS02_DEFAULT, NOISE_BLF_DISTANCE_WGTS01_DEFAULT, NOISE_BLF_DISTANCE_WGTS00_DEFAULT},
135 {NOISE_BLF_DISTANCE_WGTS10_DEFAULT, NOISE_BLF_DISTANCE_WGTS11_DEFAULT, NOISE_BLF_DISTANCE_WGTS12_DEFAULT, NOISE_BLF_DISTANCE_WGTS11_DEFAULT, NOISE_BLF_DISTANCE_WGTS10_DEFAULT},
136 {NOISE_BLF_DISTANCE_WGTS20_DEFAULT, NOISE_BLF_DISTANCE_WGTS21_DEFAULT, NOISE_BLF_DISTANCE_WGTS22_DEFAULT, NOISE_BLF_DISTANCE_WGTS21_DEFAULT, NOISE_BLF_DISTANCE_WGTS20_DEFAULT},
137 {NOISE_BLF_DISTANCE_WGTS10_DEFAULT, NOISE_BLF_DISTANCE_WGTS11_DEFAULT, NOISE_BLF_DISTANCE_WGTS12_DEFAULT, NOISE_BLF_DISTANCE_WGTS11_DEFAULT, NOISE_BLF_DISTANCE_WGTS10_DEFAULT},
138 {NOISE_BLF_DISTANCE_WGTS00_DEFAULT, NOISE_BLF_DISTANCE_WGTS01_DEFAULT, NOISE_BLF_DISTANCE_WGTS02_DEFAULT, NOISE_BLF_DISTANCE_WGTS01_DEFAULT, NOISE_BLF_DISTANCE_WGTS00_DEFAULT},
139 },
140
141 // Padding
142 {
143 0, // Padding
144 0, // Padding
145 0, // Padding
146 0, // Padding
147 0, // Padding
148 0, // Padding
149 0, // Padding
150 }
151 };
152
153 VpResourceManager::VpResourceManager(MOS_INTERFACE &osInterface, VpAllocator &allocator, VphalFeatureReport &reporting, vp::VpPlatformInterface &vpPlatformInterface, MediaCopyWrapper *mediaCopyWrapper, vp::VpUserFeatureControl *vpUserFeatureControl, VpGraphManager *graphManager)
154 : m_osInterface(osInterface), m_allocator(allocator), m_reporting(reporting), m_vpPlatformInterface(vpPlatformInterface), m_graphManager(graphManager), m_mediaCopyWrapper(mediaCopyWrapper)
155 {
156 InitSurfaceConfigMap();
157 m_userSettingPtr = m_osInterface.pfnGetUserSettingInstance(&m_osInterface);
158 m_vpUserFeatureControl = vpUserFeatureControl;
159 }
160
161 VpResourceManager::~VpResourceManager()
162 {
163 // Clean all intermedia Resource
164 DestoryVeboxOutputSurface();
165 DestoryVeboxDenoiseOutputSurface();
166
167 for (uint32_t i = 0; i < VP_NUM_STMM_SURFACES; i++)
168 {
169 if (m_veboxSTMMSurface[i])
170 {
171 m_allocator.DestroyVpSurface(m_veboxSTMMSurface[i]);
172 }
173 }
174
175 if (m_veboxStatisticsSurface)
176 {
177 m_allocator.DestroyVpSurface(m_veboxStatisticsSurface);
178 }
179
180 if (m_veboxStatisticsSurfacefor1stPassofSfc2Pass)
181 {
182 m_allocator.DestroyVpSurface(m_veboxStatisticsSurfacefor1stPassofSfc2Pass);
183 }
184
185 if (m_veboxRgbHistogram)
186 {
187 m_allocator.DestroyVpSurface(m_veboxRgbHistogram);
188 }
189
190 if (m_veboxDNTempSurface)
191 {
192 m_allocator.DestroyVpSurface(m_veboxDNTempSurface);
193 }
194
195 if (m_veboxDNSpatialConfigSurface)
196 {
197 m_allocator.DestroyVpSurface(m_veboxDNSpatialConfigSurface);
198 }
199
200 if (m_vebox3DLookUpTables)
201 {
202 m_allocator.DestroyVpSurface(m_vebox3DLookUpTables);
203 }
204
205 if (m_vebox3DLookUpTables2D)
206 {
207 m_allocator.DestroyVpSurface(m_vebox3DLookUpTables2D);
208 }
209
210 if (m_3DLutKernelCoefSurface)
211 {
212 m_allocator.DestroyVpSurface(m_3DLutKernelCoefSurface);
213 }
214
215 if (m_veboxDnHVSTables)
216 {
217 m_allocator.DestroyVpSurface(m_veboxDnHVSTables);
218 }
219
220 if (m_vebox1DLookUpTables)
221 {
222 m_allocator.DestroyVpSurface(m_vebox1DLookUpTables);
223 }
224
225 if (m_innerTileConvertInput)
226 {
227 m_allocator.DestroyVpSurface(m_innerTileConvertInput);
228 }
229
230 if (m_temperalInput)
231 {
232 m_allocator.DestroyVpSurface(m_temperalInput);
233 }
234
235 if (m_hdrResourceManager)
236 {
237 MOS_Delete(m_hdrResourceManager);
238 }
239
240 while (!m_intermediaSurfaces.empty())
241 {
242 VP_SURFACE * surf = m_intermediaSurfaces.back();
243 m_allocator.DestroyVpSurface(surf);
244 m_intermediaSurfaces.pop_back();
245 }
246
247 for (int i = 0; i < VP_NUM_FC_INTERMEDIA_SURFACES; ++i)
248 {
249 m_allocator.DestroyVpSurface(m_fcIntermediateSurface[i]);
250 }
251
252 m_allocator.DestroyVpSurface(m_cmfcCoeff);
253 m_allocator.DestroyVpSurface(m_decompressionSyncSurface);
254 for (int i = 0; i < VP_COMP_MAX_LAYERS; ++i)
255 {
256 if (m_fcIntermediaSurfaceInput[i])
257 {
258 m_allocator.DestroyVpSurface(m_fcIntermediaSurfaceInput[i]);
259 }
260 if (m_fcSeparateIntermediaSurfaceSecPlaneInput[i])
261 {
262 m_allocator.DestroyVpSurface(m_fcSeparateIntermediaSurfaceSecPlaneInput[i]);
263 }
264 }
265 if (m_fcIntermediaSurfaceOutput)
266 {
267 m_allocator.DestroyVpSurface(m_fcIntermediaSurfaceOutput);
268 }
269
270 while (!m_aiIntermediateSurface.empty())
271 {
272 auto it = m_aiIntermediateSurface.begin();
273 m_allocator.DestroyVpSurface(it->second);
274 m_aiIntermediateSurface.erase(it);
275 }
276 while (!m_aiNpuCopiedSurface.empty())
277 {
278 auto it = m_aiNpuCopiedSurface.begin();
279 m_allocator.DestroyVpSurface(it->second);
280 m_aiNpuCopiedSurface.erase(it);
281 }
282 while (!m_crossPipeContextSurfaces.empty())
283 {
284 auto it = m_crossPipeContextSurfaces.begin();
285 auto vpSurf = *it;
286
287 if (vpSurf->zeNpuHostMem)
288 {
289 m_allocator.DestroyNpuBuffer(vpSurf);
290 }
291 else
292 {
293 m_allocator.DestroyVpSurface(vpSurf);
294 }
295
296 m_crossPipeContextSurfaces.erase(it);
297 }
298
299 m_allocator.CleanRecycler();
300 }
301
302 void VpResourceManager::CleanTempSurfaces()
303 {
304 VP_FUNC_CALL();
305
306 while (!m_tempSurface.empty())
307 {
308 auto it = m_tempSurface.begin();
309 m_allocator.DestroyVpSurface(it->second);
310 m_tempSurface.erase(it);
311 }
312 while (!m_aiNpuCopiedSurface.empty())
313 {
314 auto it = m_aiNpuCopiedSurface.begin();
315 m_allocator.DestroyVpSurface(it->second);
316 m_aiNpuCopiedSurface.erase(it);
317 }
318 }
319
320 MOS_STATUS VpResourceManager::OnNewFrameProcessStart(SwFilterPipe &pipe)
321 {
322 VP_FUNC_CALL();
323
324 MT_LOG1(MT_VP_HAL_ONNEWFRAME_PROC_START, MT_NORMAL, MT_FUNC_START, 1);
325 VP_SURFACE *inputSurface = pipe.GetSurface(true, 0);
326 VP_SURFACE *outputSurface = pipe.GetSurface(false, 0);
327 SwFilter *diFilter = pipe.GetSwFilter(true, 0, FeatureTypeDi);
328
329 if (nullptr == inputSurface && nullptr == outputSurface)
330 {
331 VP_PUBLIC_ASSERTMESSAGE("Both input and output surface being nullptr!");
332 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
333 }
334
335 if (0 != m_currentPipeIndex)
336 {
337 VP_PUBLIC_ASSERTMESSAGE("m_currentPipeIndex(%d) is not 0. May caused by OnNewFrameProcessEnd not paired with OnNewFrameProcessStart!");
338 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
339 }
340
341 VP_SURFACE *pastSurface = pipe.GetPastSurface(0);
342 VP_SURFACE *futureSurface = pipe.GetFutureSurface(0);
343
344 int32_t currentFrameId = inputSurface ? inputSurface->FrameID : outputSurface->FrameID;
345 int32_t pastFrameId = pastSurface ? pastSurface->FrameID : 0;
346 int32_t futureFrameId = futureSurface ? futureSurface->FrameID : 0;
347
348 m_currentFrameIds.valid = true;
349 m_currentFrameIds.diEnabled = nullptr != diFilter;
350 m_currentFrameIds.currentFrameId = currentFrameId;
351 m_currentFrameIds.pastFrameId = pastFrameId;
352 m_currentFrameIds.futureFrameId = futureFrameId;
353 m_currentFrameIds.pastFrameAvailable = pastSurface ? true : false;
354 m_currentFrameIds.futureFrameAvailable = futureSurface ? true : false;
355
356 // Only set sameSamples flag DI enabled frames.
357 if (m_pastFrameIds.valid && m_currentFrameIds.pastFrameAvailable &&
358 m_pastFrameIds.diEnabled && m_currentFrameIds.diEnabled && m_isPastFrameVeboxDiUsed)
359 {
360 m_sameSamples =
361 WITHIN_BOUNDS(
362 m_currentFrameIds.currentFrameId - m_pastFrameIds.currentFrameId,
363 -VP_SAME_SAMPLE_THRESHOLD,
364 VP_SAME_SAMPLE_THRESHOLD) &&
365 WITHIN_BOUNDS(
366 m_currentFrameIds.pastFrameId - m_pastFrameIds.pastFrameId,
367 -VP_SAME_SAMPLE_THRESHOLD,
368 VP_SAME_SAMPLE_THRESHOLD);
369
370 if (m_sameSamples)
371 {
372 m_outOfBound = false;
373 }
374 else
375 {
376 m_outOfBound =
377 OUT_OF_BOUNDS(
378 m_currentFrameIds.pastFrameId - m_pastFrameIds.currentFrameId,
379 -VP_SAME_SAMPLE_THRESHOLD,
380 VP_SAME_SAMPLE_THRESHOLD);
381 }
382 }
383 // bSameSamples flag also needs to be set for no reference case
384 else if (m_pastFrameIds.valid && !m_currentFrameIds.pastFrameAvailable &&
385 m_pastFrameIds.diEnabled && m_currentFrameIds.diEnabled && m_isPastFrameVeboxDiUsed)
386 {
387 m_sameSamples =
388 WITHIN_BOUNDS(
389 m_currentFrameIds.currentFrameId - m_pastFrameIds.currentFrameId,
390 -VP_SAME_SAMPLE_THRESHOLD,
391 VP_SAME_SAMPLE_THRESHOLD);
392 m_outOfBound = false;
393 }
394 else
395 {
396 m_sameSamples = false;
397 m_outOfBound = false;
398 }
399
400 if (inputSurface)
401 {
402 m_maxSrcRect.right = MOS_MAX(m_maxSrcRect.right, inputSurface->rcSrc.right);
403 m_maxSrcRect.bottom = MOS_MAX(m_maxSrcRect.bottom, inputSurface->rcSrc.bottom);
404 }
405
406 // Swap buffers for next iteration
407 if (!m_sameSamples)
408 {
409 m_currentDnOutput = (m_currentDnOutput + 1) & 1;
410 m_currentStmmIndex = (m_currentStmmIndex + 1) & 1;
411 }
412
413 m_pastFrameIds = m_currentFrameIds;
414
415 m_isFcIntermediateSurfacePrepared = false;
416
417 return MOS_STATUS_SUCCESS;
418 }
419
420 MOS_STATUS VpResourceManager::GetFormatForFcIntermediaSurface(MOS_FORMAT& format,
421 MEDIA_CSPACE &colorSpace, SwFilterPipe &featurePipe)
422 {
423 VP_FUNC_CALL();
424
425 PVP_SURFACE target = nullptr;
426 int32_t surfCount = (int32_t)featurePipe.GetSurfaceCount(true);
427 PVP_SURFACE src = nullptr;
428 int32_t i = 0, j = 0;
429 int32_t csc_count = 0;
430 int32_t csc_min = surfCount + 1;
431 int32_t cspace_in_use[CSpace_Count] = {};
432 bool bYUVTarget = false;
433 MEDIA_CSPACE cs = CSpace_Any;
434 MEDIA_CSPACE tempColorSpace = CSpace_Any;
435 MEDIA_CSPACE mainColorSpace = CSpace_None;
436
437 auto PostProcess = [&](MOS_STATUS status)
438 {
439 VP_PUBLIC_NORMALMESSAGE("Main_ColorSpace %d, Temp_ColorSpace %d, csc_count %d.",
440 mainColorSpace, tempColorSpace, csc_count);
441 colorSpace = tempColorSpace;
442 // Set AYUV or ARGB output depending on intermediate cspace
443 if (KernelDll_IsCspace(colorSpace, CSpace_RGB))
444 {
445 format = Format_A8R8G8B8;
446 }
447 else
448 {
449 format = Format_AYUV;
450 }
451 return status;
452 };
453
454 // Check if target is YUV
455 target = featurePipe.GetSurface(false, 0);
456
457 VP_PUBLIC_CHK_NULL_RETURN(target);
458 VP_PUBLIC_CHK_NULL_RETURN(target->osSurface);
459
460 bYUVTarget = IS_RGB_FORMAT(target->osSurface->Format) ? false : true;
461
462 // Gets primary video cspace
463 // Implements xvYCC passthrough mode
464 // Set Color Spaces in use
465 MOS_ZeroMemory(cspace_in_use, sizeof(cspace_in_use));
466 for (i = 0; i < surfCount; i++)
467 {
468 // Get current source
469 src = featurePipe.GetSurface(true, i);
470 VP_PUBLIC_CHK_NULL_RETURN(src);
471 VP_PUBLIC_CHK_NULL_RETURN(src->osSurface);
472
473 // Save Main Video color space
474 if (src->SurfType == SURF_IN_PRIMARY &&
475 mainColorSpace == CSpace_None)
476 {
477 mainColorSpace = src->ColorSpace;
478 }
479
480 // Set xvYCC pass through mode
481 if (bYUVTarget &&
482 (src->ColorSpace == CSpace_xvYCC709 ||
483 src->ColorSpace == CSpace_xvYCC601))
484 {
485 tempColorSpace = src->ColorSpace;
486 return PostProcess(MOS_STATUS_SUCCESS);
487 }
488
489 // Don't take PAL formats into consideration
490 if ((!IS_PAL_FORMAT(src->osSurface->Format)) &&
491 src->ColorSpace > CSpace_Any &&
492 src->ColorSpace < CSpace_Count)
493 {
494 cs = KernelDll_TranslateCspace(src->ColorSpace);
495 if (cs >= CSpace_Any)
496 {
497 cspace_in_use[cs]++;
498 }
499 }
500 }
501
502 // For every CS in use, iterate through source CS and keep a
503 // count of number of CSC operation needed. Determine the Temporary
504 // color space as the one requiring min. # of CSC ops.
505 for (j = (CSpace_Any + 1); j < CSpace_Count; j++)
506 {
507 // Skip color spaces not in use
508 if (!cspace_in_use[j])
509 {
510 continue;
511 }
512
513 // Count # of CS conversions
514 cs = (MEDIA_CSPACE) j;
515 csc_count = 0;
516 for (i = 0; i < surfCount; i++)
517 {
518 // Get current source
519 src = featurePipe.GetSurface(true, i);
520 VP_PUBLIC_CHK_NULL_RETURN(src);
521 VP_PUBLIC_CHK_NULL_RETURN(src->osSurface);
522
523 auto featureSubPipe = featurePipe.GetSwFilterSubPipe(true, i);
524 VP_PUBLIC_CHK_NULL_RETURN(featureSubPipe);
525
526 // Ignore palletized layers
527 if (IS_PAL_FORMAT(src->osSurface->Format) ||
528 src->ColorSpace == CSpace_Any)
529 {
530 continue;
531 }
532
533 auto procamp = dynamic_cast<SwFilterProcamp *>(featureSubPipe->GetSwFilter(FeatureTypeProcamp));
534 // Check if CSC/PA is required
535 if (KernelDll_TranslateCspace(src->ColorSpace) != cs ||
536 (procamp &&
537 procamp->GetSwFilterParams().procampParams &&
538 procamp->GetSwFilterParams().procampParams->bEnabled))
539 {
540 csc_count++;
541 }
542 }
543
544 // Save best choice as requiring minimum number of CSC operations
545 // Use main cspace as default if same CSC count
546 if ((csc_count < csc_min) ||
547 (csc_count == csc_min && cs == mainColorSpace))
548 {
549 tempColorSpace = cs;
550 csc_min = csc_count;
551 }
552 }
553
554 // If all layers are palletized, use the CS from first layer (as good as any other)
555 if (tempColorSpace == CSpace_Any && surfCount > 0)
556 {
557 src = featurePipe.GetSurface(true, 0);
558 VP_PUBLIC_CHK_NULL_RETURN(src);
559 tempColorSpace = src->ColorSpace;
560 }
561
562 return PostProcess(MOS_STATUS_SUCCESS);
563 }
564
565 MOS_STATUS VpResourceManager::PrepareFcIntermediateSurface(SwFilterPipe &featurePipe)
566 {
567 VP_FUNC_CALL();
568
569 if (m_isFcIntermediateSurfacePrepared)
570 {
571 return MOS_STATUS_SUCCESS;
572 }
573
574 m_isFcIntermediateSurfacePrepared = true;
575
576 MOS_FORMAT format = Format_Any;
577 MEDIA_CSPACE colorSpace = CSpace_Any;
578
579 VP_PUBLIC_CHK_STATUS_RETURN(GetFormatForFcIntermediaSurface(format, colorSpace, featurePipe));
580
581 auto target = featurePipe.GetSurface(false, 0);
582 VP_PUBLIC_CHK_NULL_RETURN(target);
583 VP_PUBLIC_CHK_NULL_RETURN(target->osSurface);
584
585 uint32_t tempWidth = target->osSurface->dwWidth;
586 uint32_t tempHeight = target->osSurface->dwHeight;
587
588 uint32_t curWidth = 0;
589 uint32_t curHeight = 0;
590
591 if (m_fcIntermediateSurface[0])
592 {
593 VP_PUBLIC_CHK_NULL_RETURN(m_fcIntermediateSurface[0]->osSurface);
594 curWidth = m_fcIntermediateSurface[0]->osSurface->dwWidth;
595 curHeight = m_fcIntermediateSurface[0]->osSurface->dwHeight;
596 }
597
598 // Allocate buffer in fixed increments
599 tempWidth = MOS_ALIGN_CEIL(tempWidth , VPHAL_BUFFER_SIZE_INCREMENT);
600 tempHeight = MOS_ALIGN_CEIL(tempHeight, VPHAL_BUFFER_SIZE_INCREMENT);
601
602 for (int i = 0; i < VP_NUM_FC_INTERMEDIA_SURFACES; ++i)
603 {
604 if (tempWidth > curWidth || tempHeight > curHeight)
605 {
606 bool allocated = false;
607 // Get surface parameter.
608 // Use A8R8G8B8 instead of real surface format to ensure the surface can be reused for both AYUV and A8R8G8B8,
609 // since for A8R8G8B8, tile64 is used, while for AYUV, both tile4 and tile64 is ok.
610 if (m_fcIntermediateSurface[i] && m_fcIntermediateSurface[i]->osSurface)
611 {
612 m_fcIntermediateSurface[i]->osSurface->Format = Format_A8R8G8B8;
613 }
614 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
615 m_fcIntermediateSurface[i],
616 "fcIntermediaSurface",
617 Format_A8R8G8B8,
618 MOS_GFXRES_2D,
619 MOS_TILE_Y,
620 tempWidth,
621 tempHeight,
622 false,
623 MOS_MMC_DISABLED,
624 allocated,
625 false,
626 IsDeferredResourceDestroyNeeded(),
627 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
628 MOS_TILE_UNSET_GMM,
629 MOS_MEMPOOL_DEVICEMEMORY,
630 true));
631 m_fcIntermediateSurface[i]->osSurface->Format = format;
632 m_fcIntermediateSurface[i]->ColorSpace = colorSpace;
633 }
634 else
635 {
636 m_fcIntermediateSurface[i]->osSurface->dwWidth = tempWidth;
637 m_fcIntermediateSurface[i]->osSurface->dwHeight = tempHeight;
638 m_fcIntermediateSurface[i]->osSurface->Format = format;
639 m_fcIntermediateSurface[i]->ColorSpace = colorSpace;
640 }
641 m_fcIntermediateSurface[i]->rcSrc = target->rcSrc;
642 m_fcIntermediateSurface[i]->rcDst = target->rcDst;
643 }
644
645 return MOS_STATUS_SUCCESS;
646 }
647
648 void VpResourceManager::OnNewFrameProcessEnd()
649 {
650 VP_FUNC_CALL();
651 MT_LOG1(MT_VP_HAL_ONNEWFRAME_PROC_END, MT_NORMAL, MT_FUNC_END, 1);
652 m_allocator.CleanRecycler();
653 m_currentPipeIndex = 0;
654 CleanTempSurfaces();
655 }
656
657 void VpResourceManager::InitSurfaceConfigMap()
658 {
659 VP_FUNC_CALL();
660 ///* _b64DI
661 // | _sfcEnable
662 // | | _sameSample
663 // | | | _outOfBound
664 // | | | | _pastRefAvailable
665 // | | | | | _futureRefAvailable
666 // | | | | | | _firstDiField
667 // | | | | | | | _currentInputSurface
668 // | | | | | | | | _pastInputSurface
669 // | | | | | | | | | _currentOutputSurface
670 // | | | | | | | | | | _pastOutputSurface*/
671 // | | | | | | | | | | | */
672 // sfc Enable
673 AddSurfaceConfig(true, true, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
674 AddSurfaceConfig(true, true, true, false, true, false, false, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL);
675 AddSurfaceConfig(true, true, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
676 AddSurfaceConfig(true, true, false, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
677 AddSurfaceConfig(true, true, false, false, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
678 AddSurfaceConfig(true, true, true, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
679 AddSurfaceConfig(true, true, true, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
680 AddSurfaceConfig(true, true, true, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
681
682 // outOfBound
683 AddSurfaceConfig(true, true, false, true, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
684 AddSurfaceConfig(true, true, false, true, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
685
686 // sfc disable
687 AddSurfaceConfig(true, false, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_OUTPUT);
688 AddSurfaceConfig(true, false, true, false, true, false, false, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL);
689 AddSurfaceConfig(true, false, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
690 AddSurfaceConfig(true, false, false, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
691 AddSurfaceConfig(true, false, false, false, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
692 AddSurfaceConfig(true, false, true, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
693 AddSurfaceConfig(true, false, true, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
694
695 //30i -> 30p sfc Enable
696 AddSurfaceConfig(false, true, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
697 AddSurfaceConfig(false, true, false, false, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
698 AddSurfaceConfig(false, true, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
699 AddSurfaceConfig(false, true, false, true, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
700 AddSurfaceConfig(false, true, false, true, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
701
702 //30i -> 30p sfc disable
703 AddSurfaceConfig(false, false, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
704 AddSurfaceConfig(false, false, false, true, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
705 AddSurfaceConfig(false, false, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
706 }
707
708 uint32_t VpResourceManager::GetHistogramSurfaceSize(VP_EXECUTE_CAPS& caps, uint32_t inputWidth, uint32_t inputHeight)
709 {
710 VP_FUNC_CALL();
711
712 // Allocate Rgb Histogram surface----------------------------------------------
713 // Size of RGB histograms, 1 set for each slice. For single slice, other set will be 0
714 uint32_t dwSize = VP_VEBOX_RGB_HISTOGRAM_SIZE;
715 dwSize += VP_VEBOX_RGB_ACE_HISTOGRAM_SIZE_RESERVED;
716 // Size of ACE histograms, 1 set for each slice. For single slice, other set will be 0
717 dwSize += VP_VEBOX_ACE_HISTOGRAM_SIZE_PER_FRAME_PER_SLICE * // Ace histogram size per slice
718 VP_NUM_FRAME_PREVIOUS_CURRENT * // Ace for Prev + Curr
719 VP_VEBOX_HISTOGRAM_SLICES_COUNT; // Total number of slices
720 return dwSize;
721 }
722
723 MOS_STATUS VpResourceManager::GetResourceHint(std::vector<FeatureType> &featurePool, SwFilterPipe& executedFilters, RESOURCE_ASSIGNMENT_HINT &hint)
724 {
725 VP_FUNC_CALL();
726
727 uint32_t index = 0;
728 SwFilterSubPipe *inputPipe = executedFilters.GetSwFilterSubPipe(true, index);
729
730 // only process Primary surface
731 if (inputPipe == nullptr)
732 {
733 VP_PUBLIC_NORMALMESSAGE("No inputPipe, so there is no hint message!");
734 return MOS_STATUS_SUCCESS;
735 }
736 for (auto filterID : featurePool)
737 {
738 SwFilter* feature = (SwFilter*)inputPipe->GetSwFilter(FeatureType(filterID));
739 if (feature)
740 {
741 VP_PUBLIC_CHK_STATUS_RETURN(feature->SetResourceAssignmentHint(hint));
742 }
743 }
744 return MOS_STATUS_SUCCESS;
745 }
746
747 MOS_STATUS VpResourceManager::GetIntermediaColorAndFormat3DLutOutput(VPHAL_CSPACE &colorSpace, MOS_FORMAT &format, SwFilterPipe &executedFilters)
748 {
749 SwFilterHdr *hdr = dynamic_cast<SwFilterHdr *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeHdr));
750 if (hdr)
751 {
752 colorSpace = hdr->GetSwFilterParams().dstColorSpace;
753 format = hdr->GetSwFilterParams().formatOutput;
754 }
755 else
756 { // caps.b3DlutOutput =1, in hdr tests hdr flag should not be false.
757 VP_PUBLIC_ASSERTMESSAGE("It is unexcepted for HDR case with caps.b3DlutOutput as true, return INVALID_PARAMETER");
758 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
759
760 }
761 return MOS_STATUS_SUCCESS;
762 }
763
764 MOS_STATUS VpResourceManager::GetIntermediaColorAndFormatBT2020toRGB(VP_EXECUTE_CAPS &caps, VPHAL_CSPACE &colorSpace, MOS_FORMAT &format, SwFilterPipe &executedFilters)
765 {
766 SwFilterCsc *cscOnSfc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnSfc));
767 SwFilterCgc *cgc = dynamic_cast<SwFilterCgc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCgc));
768
769 if (caps.bSFC && nullptr == cscOnSfc)
770 {
771 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
772 }
773
774 if (cscOnSfc)
775 {
776 colorSpace = cscOnSfc->GetSwFilterParams().output.colorSpace;
777 format = cscOnSfc->GetSwFilterParams().formatOutput;
778 }
779 else
780 {
781 VP_PUBLIC_CHK_NULL_RETURN(cgc);
782 colorSpace = cgc->GetSwFilterParams().dstColorSpace;
783 format = cgc->GetSwFilterParams().formatOutput;
784 }
785
786 return MOS_STATUS_SUCCESS;
787 }
788
789
790 MOS_STATUS VpResourceManager::GetIntermediaOutputSurfaceColorAndFormat(VP_EXECUTE_CAPS &caps, SwFilterPipe &executedFilters, MOS_FORMAT &format, VPHAL_CSPACE &colorSpace)
791 {
792 VP_SURFACE *inputSurface = executedFilters.GetSurface(true, 0);
793 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
794 if (caps.bRender)
795 {
796 SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnRender));
797 if (csc)
798 {
799 format = csc->GetSwFilterParams().formatOutput;
800 colorSpace = csc->GetSwFilterParams().output.colorSpace;
801 return MOS_STATUS_SUCCESS;
802 }
803
804 }
805 else if (caps.bSFC)
806 {
807 SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnSfc));
808 if (csc)
809 {
810 format = csc->GetSwFilterParams().formatOutput;
811 colorSpace = csc->GetSwFilterParams().output.colorSpace;
812 return MOS_STATUS_SUCCESS;
813 }
814 }
815 else if (caps.b3DlutOutput)
816 {
817 VP_PUBLIC_CHK_STATUS_RETURN(GetIntermediaColorAndFormat3DLutOutput(colorSpace, format, executedFilters));
818 return MOS_STATUS_SUCCESS;
819 }
820 else if (caps.bBt2020ToRGB)
821 {
822 VP_PUBLIC_CHK_STATUS_RETURN(GetIntermediaColorAndFormatBT2020toRGB(caps, colorSpace, format, executedFilters));
823 return MOS_STATUS_SUCCESS;
824 }
825 else if (caps.bVebox)
826 {
827 SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnVebox));
828 if (csc)
829 {
830 format = csc->GetSwFilterParams().formatOutput;
831 colorSpace = csc->GetSwFilterParams().output.colorSpace;
832 return MOS_STATUS_SUCCESS;
833 }
834 }
835
836 format = inputSurface->osSurface->Format;
837 colorSpace = inputSurface->ColorSpace;
838 return MOS_STATUS_SUCCESS;
839 }
840
841 MOS_STATUS VpResourceManager::GetIntermediaOutputSurfaceParams(VP_EXECUTE_CAPS& caps, VP_SURFACE_PARAMS &params, SwFilterPipe &executedFilters)
842 {
843 VP_FUNC_CALL();
844
845 SwFilterScaling *scaling = dynamic_cast<SwFilterScaling *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeScaling));
846 SwFilterRotMir *rotMir = dynamic_cast<SwFilterRotMir *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeRotMir));
847 SwFilterDeinterlace *di = dynamic_cast<SwFilterDeinterlace *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeDi));
848 VP_SURFACE *inputSurface = executedFilters.GetSurface(true, 0);
849
850 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
851
852 if (scaling)
853 {
854 params.width = scaling->GetSwFilterParams().output.dwWidth;
855 params.height = scaling->GetSwFilterParams().output.dwHeight;
856 params.sampleType = scaling->GetSwFilterParams().output.sampleType;
857 params.rcSrc = scaling->GetSwFilterParams().output.rcSrc;
858 params.rcDst = scaling->GetSwFilterParams().output.rcDst;
859 params.rcMaxSrc = scaling->GetSwFilterParams().output.rcMaxSrc;
860
861 if (scaling->GetSwFilterParams().interlacedScalingType == ISCALING_INTERLEAVED_TO_FIELD)
862 {
863 params.height = scaling->GetSwFilterParams().output.dwHeight / 2;
864 params.rcDst.bottom = params.rcDst.bottom / 2;
865 params.rcMaxSrc.bottom = params.rcMaxSrc.bottom / 2;
866 }
867 }
868 else
869 {
870 params.width = inputSurface->osSurface->dwWidth;
871 params.height = inputSurface->osSurface->dwHeight;
872 params.sampleType = di ? SAMPLE_PROGRESSIVE : inputSurface->SampleType;
873 params.rcSrc = inputSurface->rcSrc;
874 params.rcDst = inputSurface->rcDst;
875 params.rcMaxSrc = inputSurface->rcMaxSrc;
876 }
877
878 // Do not use rotatoin flag in scaling swfilter as it has not been initialized here.
879 // It will be initialized during pipe update after resource being assigned.
880 if (rotMir &&
881 (rotMir->GetSwFilterParams().rotation == VPHAL_ROTATION_90 ||
882 rotMir->GetSwFilterParams().rotation == VPHAL_ROTATION_270 ||
883 rotMir->GetSwFilterParams().rotation == VPHAL_ROTATE_90_MIRROR_VERTICAL ||
884 rotMir->GetSwFilterParams().rotation == VPHAL_ROTATE_90_MIRROR_HORIZONTAL))
885 {
886 swap(params.width, params.height);
887 RECT tmp = params.rcSrc;
888 RECT_ROTATE(params.rcSrc, tmp);
889 tmp = params.rcDst;
890 RECT_ROTATE(params.rcDst, tmp);
891 tmp = params.rcMaxSrc;
892 RECT_ROTATE(params.rcMaxSrc, tmp);
893 }
894
895 VP_PUBLIC_CHK_STATUS_RETURN(GetIntermediaOutputSurfaceColorAndFormat(caps, executedFilters, params.format, params.colorSpace));
896
897 params.tileType = MOS_TILE_Y;
898
899 if (SAMPLE_PROGRESSIVE == params.sampleType)
900 {
901 params.surfCompressionMode = caps.bRender ? MOS_MMC_RC : MOS_MMC_MC;
902 params.surfCompressible = true;
903 }
904 else
905 {
906 // MMC does not support interleaved surface.
907 VP_PUBLIC_NORMALMESSAGE("Disable MMC for interleaved intermedia surface, sampleType = %d.", params.sampleType);
908 params.surfCompressionMode = MOS_MMC_DISABLED;
909 params.surfCompressible = false;
910 }
911
912 return MOS_STATUS_SUCCESS;
913 }
914
915 MOS_STATUS VpResourceManager::GetFcIntermediateSurfaceForOutput(VP_SURFACE *&intermediaSurface, SwFilterPipe &executedFilters)
916 {
917 VP_FUNC_CALL();
918
919 if (!m_isFcIntermediateSurfacePrepared)
920 {
921 VP_PUBLIC_ASSERTMESSAGE("Fc intermediate surface is not allocated.");
922 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
923 }
924
925 intermediaSurface = nullptr;
926
927 for (uint32_t i = 0; i < executedFilters.GetSurfaceCount(true); ++i)
928 {
929 uint32_t j = 0;
930 auto surf = executedFilters.GetSurface(true, i);
931 VP_PUBLIC_CHK_NULL_RETURN(surf);
932 for (j = 0; j < VP_NUM_FC_INTERMEDIA_SURFACES; ++j)
933 {
934 auto intermediateSurface = m_fcIntermediateSurface[j];
935 VP_PUBLIC_CHK_NULL_RETURN(intermediateSurface);
936 if (surf->GetAllocationHandle(&m_osInterface) == intermediateSurface->GetAllocationHandle(&m_osInterface))
937 {
938 uint32_t selIndex = (j + 1) % VP_NUM_FC_INTERMEDIA_SURFACES;
939 intermediaSurface = m_fcIntermediateSurface[selIndex];
940 break;
941 }
942 }
943 if (j < VP_NUM_FC_INTERMEDIA_SURFACES)
944 {
945 break;
946 }
947 }
948 // If intermediate surface not in use in current pipe, use first one by default.
949 if (nullptr == intermediaSurface)
950 {
951 intermediaSurface = m_fcIntermediateSurface[0];
952 }
953
954 return MOS_STATUS_SUCCESS;
955 }
956
957 MOS_STATUS VpResourceManager::AssignIntermediaSurface(VP_EXECUTE_CAPS& caps, SwFilterPipe &executedFilters)
958 {
959 VP_FUNC_CALL();
960
961 VP_SURFACE *outputSurface = executedFilters.GetSurface(false, 0);
962 VP_SURFACE *intermediaSurface = nullptr;
963 VP_SURFACE_PARAMS params = {};
964 if (outputSurface)
965 {
966 // No need intermedia surface.
967 return MOS_STATUS_SUCCESS;
968 }
969
970 if (caps.bComposite)
971 {
972 VP_PUBLIC_CHK_STATUS_RETURN(GetFcIntermediateSurfaceForOutput(intermediaSurface, executedFilters));
973 }
974 else
975 {
976 while (m_currentPipeIndex >= m_intermediaSurfaces.size())
977 {
978 m_intermediaSurfaces.push_back(nullptr);
979 }
980 bool allocated = false;
981 // Get surface parameter.
982 GetIntermediaOutputSurfaceParams(caps, params, executedFilters);
983
984 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
985 m_intermediaSurfaces[m_currentPipeIndex],
986 "IntermediaSurface",
987 params.format,
988 MOS_GFXRES_2D,
989 params.tileType,
990 params.width,
991 params.height,
992 params.surfCompressible,
993 params.surfCompressionMode,
994 allocated,
995 false,
996 IsDeferredResourceDestroyNeeded(),
997 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
998
999 VP_PUBLIC_CHK_NULL_RETURN(m_intermediaSurfaces[m_currentPipeIndex]);
1000
1001 m_intermediaSurfaces[m_currentPipeIndex]->ColorSpace = params.colorSpace;
1002 m_intermediaSurfaces[m_currentPipeIndex]->rcDst = params.rcDst;
1003 m_intermediaSurfaces[m_currentPipeIndex]->rcSrc = params.rcSrc;
1004 m_intermediaSurfaces[m_currentPipeIndex]->rcMaxSrc = params.rcMaxSrc;
1005 m_intermediaSurfaces[m_currentPipeIndex]->SampleType = params.sampleType;
1006
1007 intermediaSurface = m_intermediaSurfaces[m_currentPipeIndex];
1008 }
1009
1010 VP_PUBLIC_CHK_NULL_RETURN(intermediaSurface);
1011 VP_SURFACE *output = m_allocator.AllocateVpSurface(*intermediaSurface);
1012 VP_PUBLIC_CHK_NULL_RETURN(output);
1013 output->SurfType = SURF_OUT_RENDERTARGET;
1014
1015 executedFilters.AddSurface(output, false, 0);
1016
1017 return MOS_STATUS_SUCCESS;
1018 }
1019
1020 VP_SURFACE * VpResourceManager::GetCopyInstOfExtSurface(VP_SURFACE* surf)
1021 {
1022 VP_FUNC_CALL();
1023
1024 if (nullptr == surf || 0 == surf->GetAllocationHandle(&m_osInterface))
1025 {
1026 return nullptr;
1027 }
1028 // Do not use allocation handle as key as some parameters in VP_SURFACE
1029 // may be different for same allocation, e.g. SurfType for intermedia surface.
1030 auto it = m_tempSurface.find((uint64_t)surf);
1031 if (it != m_tempSurface.end())
1032 {
1033 return it->second;
1034 }
1035 VP_SURFACE *surface = m_allocator.AllocateVpSurface(*surf);
1036 if (surface)
1037 {
1038 m_tempSurface.emplace((uint64_t)surf, surface);
1039 }
1040 else
1041 {
1042 VP_PUBLIC_ASSERTMESSAGE("Allocate temp surface faild!");
1043 }
1044
1045 return surface;
1046 }
1047
1048 MOS_STATUS VpResourceManager::AssignFcResources(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface,
1049 std::vector<VP_SURFACE *> &pastSurfaces, std::vector<VP_SURFACE *> &futureSurfaces,
1050 RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting)
1051 {
1052 VP_FUNC_CALL();
1053
1054 bool allocated = false;
1055 auto *skuTable = m_osInterface.pfnGetSkuTable(&m_osInterface);
1056 Mos_MemPool memTypeSurfVideoMem = MOS_MEMPOOL_VIDEOMEMORY;
1057
1058 if (skuTable && MEDIA_IS_SKU(skuTable, FtrLimitedLMemBar))
1059 {
1060 memTypeSurfVideoMem = MOS_MEMPOOL_DEVICEMEMORY;
1061 }
1062
1063 if (caps.bTemperalInputInuse)
1064 {
1065 if (inputSurfaces.size() > 1)
1066 {
1067 VP_PUBLIC_ASSERTMESSAGE("Temperal input only has 1 layer, do not support multi-layer case!");
1068 return MOS_STATUS_INVALID_PARAMETER;
1069 }
1070 surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeFcInputLayer0), m_temperalInput);
1071 }
1072 else
1073 {
1074 for (size_t i = 0; i < inputSurfaces.size(); ++i)
1075 {
1076 surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeFcInputLayer0 + i), inputSurfaces[i]);
1077
1078 if (!resHint.isIScalingTypeNone)
1079 {
1080 // For Interlaced scaling, 2nd field is part of the same frame.
1081 // For Field weaving, 2nd field is passed in as a ref.
1082 VP_SURFACE *surfField1Dual = nullptr;
1083 if (resHint.isFieldWeaving)
1084 {
1085 surfField1Dual = pastSurfaces[i];
1086 VP_PUBLIC_NORMALMESSAGE("Field weaving case. 2nd field is passed in as a ref.");
1087 }
1088 else
1089 {
1090 surfField1Dual = GetCopyInstOfExtSurface(inputSurfaces[i]);
1091 VP_PUBLIC_NORMALMESSAGE("Interlaced scaling. 2nd field is part of the same frame.");
1092 }
1093 VP_PUBLIC_CHK_NULL_RETURN(surfField1Dual);
1094 surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeFcInputLayer0Field1Dual + i), surfField1Dual);
1095 }
1096 }
1097 }
1098 surfSetting.surfGroup.emplace(SurfaceTypeFcTarget0, outputSurface);
1099
1100 // Allocate auto CSC Coeff Surface
1101 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1102 m_cmfcCoeff,
1103 "CSCCoeffSurface",
1104 Format_L8,
1105 MOS_GFXRES_2D,
1106 MOS_TILE_LINEAR,
1107 VP_COMP_CMFC_COEFF_WIDTH,
1108 VP_COMP_CMFC_COEFF_HEIGHT,
1109 false,
1110 MOS_MMC_DISABLED,
1111 allocated,
1112 false,
1113 IsDeferredResourceDestroyNeeded(),
1114 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_RENDER,
1115 MOS_TILE_UNSET_GMM,
1116 memTypeSurfVideoMem,
1117 VPP_INTER_RESOURCE_NOTLOCKABLE));
1118
1119 surfSetting.surfGroup.emplace(SurfaceTypeFcCscCoeff, m_cmfcCoeff);
1120
1121 //for decompreesion sync on interlace input of FC
1122 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1123 m_decompressionSyncSurface,
1124 "AuxDecompressSyncSurface",
1125 Format_Buffer,
1126 MOS_GFXRES_BUFFER,
1127 MOS_TILE_LINEAR,
1128 32,
1129 1,
1130 false,
1131 MOS_MMC_DISABLED,
1132 allocated));
1133 surfSetting.surfGroup.emplace(SurfaceTypeDecompressionSync, m_decompressionSyncSurface);
1134
1135 if (m_vpUserFeatureControl && m_vpUserFeatureControl->EnableOclFC())
1136 {
1137 // Allocate OCL FC intermedia inputSurface
1138 for (uint32_t i = 0; i < inputSurfaces.size(); ++i)
1139 {
1140 VP_PUBLIC_CHK_NULL_RETURN(inputSurfaces[i]);
1141 VP_PUBLIC_CHK_NULL_RETURN(inputSurfaces[i]->osSurface);
1142 MOS_FORMAT fcIntermediaInputFormat = Format_Any;
1143 MOS_FORMAT fcSeparateIntermediaSecPlaneInputFormat = Format_Any;
1144 uint32_t widthPL1Factor = 1;
1145 uint32_t heightPL1Factor = 1;
1146 switch (inputSurfaces[i]->osSurface->Format)
1147 {
1148 case Format_RGBP:
1149 case Format_BGRP:
1150 fcIntermediaInputFormat = Format_A8R8G8B8;
1151 break;
1152 case Format_444P:
1153 fcIntermediaInputFormat = Format_AYUV;
1154 break;
1155 case Format_I420:
1156 case Format_YV12:
1157 case Format_IYUV:
1158 case Format_IMC3:
1159 fcIntermediaInputFormat = Format_NV12;
1160 break;
1161 case Format_422H:
1162 fcIntermediaInputFormat = Format_R8UN;
1163 fcSeparateIntermediaSecPlaneInputFormat = Format_R8G8UN;
1164 widthPL1Factor = 2;
1165 break;
1166 case Format_422V:
1167 fcIntermediaInputFormat = Format_R8UN;
1168 fcSeparateIntermediaSecPlaneInputFormat = Format_R8G8UN;
1169 heightPL1Factor = 2;
1170 break;
1171 case Format_411P:
1172 fcIntermediaInputFormat = Format_R8UN;
1173 fcSeparateIntermediaSecPlaneInputFormat = Format_R8G8UN;
1174 widthPL1Factor = 4;
1175 break;
1176 default:
1177 break;
1178 }
1179 if (fcIntermediaInputFormat != Format_Any)
1180 {
1181 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1182 m_fcIntermediaSurfaceInput[i],
1183 "fcIntermediaSurfaceInput",
1184 fcIntermediaInputFormat,
1185 MOS_GFXRES_2D,
1186 MOS_TILE_Y,
1187 inputSurfaces[i]->osSurface->dwWidth,
1188 inputSurfaces[i]->osSurface->dwHeight,
1189 false,
1190 MOS_MMC_DISABLED,
1191 allocated,
1192 false,
1193 IsDeferredResourceDestroyNeeded(),
1194 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
1195
1196 m_fcIntermediaSurfaceInput[i]->rcSrc = inputSurfaces[i]->rcSrc;
1197 m_fcIntermediaSurfaceInput[i]->rcDst = inputSurfaces[i]->rcDst;
1198 m_fcIntermediaSurfaceInput[i]->SampleType = inputSurfaces[i]->SampleType;
1199 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeFcIntermediaInput + i), m_fcIntermediaSurfaceInput[i]));
1200 }
1201 if (fcSeparateIntermediaSecPlaneInputFormat != Format_Any)
1202 {
1203 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1204 m_fcSeparateIntermediaSurfaceSecPlaneInput[i],
1205 "fcSeparateIntermediaSurfaceSecPlaneInput",
1206 fcSeparateIntermediaSecPlaneInputFormat,
1207 MOS_GFXRES_2D,
1208 MOS_TILE_Y,
1209 inputSurfaces[i]->osSurface->dwWidth / widthPL1Factor,
1210 inputSurfaces[i]->osSurface->dwHeight / heightPL1Factor,
1211 false,
1212 MOS_MMC_DISABLED,
1213 allocated,
1214 false,
1215 IsDeferredResourceDestroyNeeded(),
1216 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
1217
1218 m_fcSeparateIntermediaSurfaceSecPlaneInput[i]->rcSrc.top = inputSurfaces[i]->rcSrc.top / heightPL1Factor;
1219 m_fcSeparateIntermediaSurfaceSecPlaneInput[i]->rcSrc.bottom = inputSurfaces[i]->rcSrc.bottom / heightPL1Factor;
1220 m_fcSeparateIntermediaSurfaceSecPlaneInput[i]->rcSrc.left = inputSurfaces[i]->rcSrc.left / widthPL1Factor;
1221 m_fcSeparateIntermediaSurfaceSecPlaneInput[i]->rcSrc.right = inputSurfaces[i]->rcSrc.right / widthPL1Factor;
1222 m_fcSeparateIntermediaSurfaceSecPlaneInput[i]->rcDst = inputSurfaces[i]->rcDst;
1223 m_fcSeparateIntermediaSurfaceSecPlaneInput[i]->SampleType = inputSurfaces[i]->SampleType;
1224 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeFcSeparateIntermediaInputSecPlane + i), m_fcSeparateIntermediaSurfaceSecPlaneInput[i]));
1225 }
1226 }
1227 // Allocate OCL FC intermedia outputSurface
1228 {
1229 MOS_FORMAT fcIntermediaSurfaceOutputFormat = Format_Any;
1230 VP_PUBLIC_CHK_NULL_RETURN(outputSurface);
1231 VP_PUBLIC_CHK_NULL_RETURN(outputSurface->osSurface);
1232 switch (outputSurface->osSurface->Format)
1233 {
1234 case Format_RGBP:
1235 case Format_BGRP:
1236 fcIntermediaSurfaceOutputFormat = Format_A8R8G8B8;
1237 break;
1238 case Format_444P:
1239 fcIntermediaSurfaceOutputFormat = Format_AYUV;
1240 break;
1241 case Format_I420:
1242 case Format_IMC3:
1243 case Format_YV12:
1244 case Format_IYUV:
1245 fcIntermediaSurfaceOutputFormat = Format_NV12;
1246 break;
1247 default:
1248 break;
1249 }
1250 if (fcIntermediaSurfaceOutputFormat != Format_Any)
1251 {
1252 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1253 m_fcIntermediaSurfaceOutput,
1254 "fcIntermediaSurfaceOutput",
1255 fcIntermediaSurfaceOutputFormat,
1256 MOS_GFXRES_2D,
1257 MOS_TILE_Y,
1258 outputSurface->osSurface->dwWidth,
1259 outputSurface->osSurface->dwHeight,
1260 false,
1261 MOS_MMC_DISABLED,
1262 allocated,
1263 false,
1264 IsDeferredResourceDestroyNeeded(),
1265 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
1266 m_fcIntermediaSurfaceOutput->rcSrc = outputSurface->rcSrc;
1267 m_fcIntermediaSurfaceOutput->rcDst = outputSurface->rcDst;
1268 m_fcIntermediaSurfaceOutput->SampleType = outputSurface->SampleType;
1269 surfSetting.surfGroup.emplace((SurfaceType)(SurfaceTypeFcIntermediaOutput), m_fcIntermediaSurfaceOutput);
1270 }
1271 }
1272 }
1273 return MOS_STATUS_SUCCESS;
1274 }
1275
1276 MOS_STATUS VpResourceManager::AssignAiNpuResource(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface, std::vector<VP_SURFACE *> &pastSurfaces, std::vector<VP_SURFACE *> &futureSurfaces, SwFilterPipe &executedFilters, VP_SURFACE_SETTING &surfSetting)
1277 {
1278 VP_FUNC_CALL();
1279
1280 SwFilterSubPipe *subPipe = executedFilters.GetSwFilterSubPipe(true, 0);
1281 VP_PUBLIC_CHK_NULL_RETURN(subPipe);
1282 VP_PUBLIC_CHK_VALUE_RETURN(inputSurfaces.empty(), false);
1283 for (uint32_t i = 0; i < inputSurfaces.size(); ++i)
1284 {
1285 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiInput0 + i), inputSurfaces.at(i)));
1286 if (pastSurfaces.size() > i && pastSurfaces.at(i))
1287 {
1288 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiPastInput0 + i), pastSurfaces.at(i)));
1289 }
1290 if (futureSurfaces.size() > i && futureSurfaces.at(i))
1291 {
1292 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiFutureInput0 + i), futureSurfaces.at(i)));
1293 }
1294 }
1295 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiTarget0), outputSurface));
1296 SwFilterAiBase *ai = nullptr;
1297 VP_PUBLIC_CHK_STATUS_RETURN(subPipe->GetAiSwFilter(ai));
1298 VP_PUBLIC_CHK_NULL_RETURN(ai);
1299 FeatureParamAi &aiParam = ai->GetSwFilterParams();
1300 for (uint32_t stageIndex = 0; stageIndex < (aiParam.splitGroupIndex.size() + 1); ++stageIndex)
1301 {
1302 std::vector<AI_SINGLE_NPU_GRAPH_SETTING> graphGroup = {};
1303 std::vector<AI_SINGLE_LAYER_BASE_SETTING *> settings = {};
1304 VP_PUBLIC_CHK_STATUS_RETURN(ai->GetStagePipeSettings(stageIndex, settings));
1305 if (settings.empty() || settings.at(0) == nullptr || settings.at(0)->engine == FEATURE_AI_ENGINE::GPU)
1306 {
1307 continue;
1308 }
1309 for (auto &setting : settings)
1310 {
1311 AI_SINGLE_NPU_GRAPH_SETTING *npuSetting = dynamic_cast<AI_SINGLE_NPU_GRAPH_SETTING *>(setting);
1312 VP_PUBLIC_CHK_NULL_RETURN(npuSetting); //Put a gpu setting into npu stage is not allowed
1313 graphGroup.push_back(*npuSetting);
1314 }
1315 VP_PUBLIC_CHK_VALUE_RETURN(graphGroup.empty(), false);
1316 VP_PUBLIC_CHK_NULL_RETURN(m_graphManager);
1317 GraphPackage *package = nullptr;
1318 VP_PUBLIC_CHK_STATUS_RETURN(m_graphManager->GetGraphPackage(graphGroup, executedFilters, package));
1319 for (auto& intermediateSurfaceHandle : package->IntermiedateSurfaces())
1320 {
1321 VP_PUBLIC_CHK_NULL_RETURN(intermediateSurfaceHandle.second);
1322 auto handle = m_aiNpuCopiedSurface.find(intermediateSurfaceHandle.first);
1323 if (handle == m_aiNpuCopiedSurface.end())
1324 {
1325 PVP_SURFACE surface = m_allocator.AllocateVpSurface();
1326 VP_PUBLIC_CHK_NULL_RETURN(surface);
1327 handle = m_aiNpuCopiedSurface.insert(std::make_pair(intermediateSurfaceHandle.first, surface)).first;
1328 VP_PUBLIC_CHK_NOT_FOUND_RETURN(handle, &m_aiNpuCopiedSurface);
1329 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.CopyVpSurface(*handle-> second, *intermediateSurfaceHandle.second));
1330 }
1331 VP_PUBLIC_CHK_NULL_RETURN(handle->second);
1332 surfSetting.surfGroup.insert(std::make_pair(handle->first, handle->second));
1333 }
1334 }
1335
1336 return MOS_STATUS_SUCCESS;
1337 }
1338
1339 MOS_STATUS VpResourceManager::AssignAiKernelResource(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface, std::vector<VP_SURFACE *> &pastSurfaces, std::vector<VP_SURFACE *> &futureSurfaces, SwFilterPipe &executedFilters, VP_SURFACE_SETTING &surfSetting)
1340 {
1341 VP_FUNC_CALL();
1342 bool allocated = false;
1343
1344 SwFilterSubPipe *subPipe = executedFilters.GetSwFilterSubPipe(true, 0);
1345 VP_PUBLIC_CHK_NULL_RETURN(subPipe);
1346 VP_PUBLIC_CHK_VALUE_RETURN(inputSurfaces.empty(), false);
1347 for (uint32_t i = 0; i < inputSurfaces.size(); ++i)
1348 {
1349 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiInput0 + i), inputSurfaces.at(i)));
1350 if (pastSurfaces.size() > i && pastSurfaces.at(i))
1351 {
1352 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiPastInput0 + i), pastSurfaces.at(i)));
1353 }
1354 if (futureSurfaces.size() > i && futureSurfaces.at(i))
1355 {
1356 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiFutureInput0 + i), futureSurfaces.at(i)));
1357 }
1358 }
1359 surfSetting.surfGroup.insert(std::make_pair((SurfaceType)(SurfaceTypeAiTarget0), outputSurface));
1360 SwFilterAiBase *ai = nullptr;
1361 VP_PUBLIC_CHK_STATUS_RETURN(subPipe->GetAiSwFilter(ai));
1362 VP_PUBLIC_CHK_NULL_RETURN(ai)
1363 FeatureParamAi &aiParam = ai->GetSwFilterParams();
1364 // Only Allocate Render Only Resource, for NPU/Render Shared Resource will allocated in AssignAiNpuResource
1365 for (auto &singleLayerSettingHandle : aiParam.settings)
1366 {
1367 AI_SINGLE_GPU_LAYER_SETTING *singleLayerSettingPtr = dynamic_cast<AI_SINGLE_GPU_LAYER_SETTING *>(singleLayerSettingHandle.get());
1368 if (singleLayerSettingPtr == nullptr)
1369 {
1370 continue;
1371 }
1372 AI_SINGLE_GPU_LAYER_SETTING &singleLayerSetting = *singleLayerSettingPtr;
1373 AI_SURFACE_ALLOCATION_MAP aiSurfaceMap = {};
1374 VP_PUBLIC_CHK_NULL_RETURN(singleLayerSetting.pfnGetIntermediateSurfaceSetting);
1375 VP_PUBLIC_CHK_STATUS_RETURN(singleLayerSetting.pfnGetIntermediateSurfaceSetting(executedFilters, aiSurfaceMap));
1376 for (auto const &aiSurfaceSetting : aiSurfaceMap)
1377 {
1378 auto handle = m_aiIntermediateSurface.find(aiSurfaceSetting.first);
1379 if (handle == m_aiIntermediateSurface.end())
1380 {
1381 handle = m_aiIntermediateSurface.insert(std::make_pair(aiSurfaceSetting.first, nullptr)).first;
1382 VP_PUBLIC_CHK_NOT_FOUND_RETURN(handle, &m_aiIntermediateSurface);
1383 }
1384 VP_SURFACE *&intermediateSurface = handle->second;
1385 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1386 intermediateSurface,
1387 aiSurfaceSetting.second.surfaceName.c_str(),
1388 aiSurfaceSetting.second.format,
1389 aiSurfaceSetting.second.resourceType,
1390 aiSurfaceSetting.second.tileType,
1391 aiSurfaceSetting.second.width,
1392 aiSurfaceSetting.second.height,
1393 false,
1394 MOS_MMC_DISABLED,
1395 allocated,
1396 false,
1397 IsDeferredResourceDestroyNeeded(),
1398 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
1399
1400 surfSetting.surfGroup.insert(std::make_pair(aiSurfaceSetting.first, intermediateSurface));
1401
1402 if (allocated && aiSurfaceSetting.second.fillContentSize > 0)
1403 {
1404 VP_PUBLIC_CHK_NULL_RETURN(aiSurfaceSetting.second.fillContent);
1405 VP_PUBLIC_CHK_VALUE_RETURN((aiSurfaceSetting.second.width * aiSurfaceSetting.second.height >= aiSurfaceSetting.second.fillContentSize), true);
1406 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.Write1DSurface(intermediateSurface, aiSurfaceSetting.second.fillContent, aiSurfaceSetting.second.fillContentSize));
1407 }
1408 }
1409 }
1410
1411 return MOS_STATUS_SUCCESS;
1412 }
1413
1414 MOS_STATUS VpResourceManager::AssignRenderResource(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface,
1415 std::vector<VP_SURFACE *> &pastSurfaces, std::vector<VP_SURFACE *> &futureSurfaces, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting, SwFilterPipe& executedFilters)
1416 {
1417 VP_FUNC_CALL();
1418
1419 if (caps.bComposite)
1420 {
1421 VP_PUBLIC_CHK_STATUS_RETURN(AssignFcResources(caps, inputSurfaces, outputSurface, pastSurfaces, futureSurfaces, resHint, surfSetting));
1422 }
1423 else if (caps.b3DLutCalc)
1424 {
1425 VP_PUBLIC_CHK_STATUS_RETURN(Assign3DLutKernelResource(caps, resHint, surfSetting));
1426 }
1427 else if (caps.bHVSCalc)
1428 {
1429 VP_PUBLIC_CHK_STATUS_RETURN(AssignHVSKernelResource(caps, resHint, surfSetting));
1430 }
1431 else if (caps.bRenderHdr)
1432 {
1433 VP_PUBLIC_CHK_STATUS_RETURN(AssignHdrResource(caps, inputSurfaces, outputSurface, resHint, surfSetting, executedFilters));
1434 }
1435 else if (caps.bAiPath)
1436 {
1437 //Npu Resource need to be used as render input/out intermediate surface, so also need to be allocated in render path
1438 VP_PUBLIC_CHK_STATUS_RETURN(AssignAiNpuResource(caps, inputSurfaces, outputSurface, pastSurfaces, futureSurfaces, executedFilters, surfSetting));
1439 VP_PUBLIC_CHK_STATUS_RETURN(AssignAiKernelResource(caps, inputSurfaces, outputSurface, pastSurfaces, futureSurfaces, executedFilters, surfSetting));
1440 }
1441 else
1442 {
1443 if (1 != inputSurfaces.size())
1444 {
1445 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
1446 }
1447 surfSetting.surfGroup.emplace(SurfaceTypeRenderInput, inputSurfaces[0]);
1448 VP_PUBLIC_CHK_STATUS_RETURN(AssignVeboxResourceForRender(caps, inputSurfaces[0], resHint, surfSetting));
1449 }
1450 return MOS_STATUS_SUCCESS;
1451 }
1452
1453 MOS_STATUS VpResourceManager::AssignNpuResource(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface, std::vector<VP_SURFACE *> &pastSurfaces, std::vector<VP_SURFACE *> &futureSurfaces, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting, SwFilterPipe &executedFilters)
1454 {
1455 VP_FUNC_CALL();
1456
1457 if (caps.bAiPath)
1458 {
1459 VP_PUBLIC_CHK_STATUS_RETURN(AssignAiNpuResource(caps, inputSurfaces, outputSurface, pastSurfaces, futureSurfaces, executedFilters, surfSetting));
1460 }
1461
1462 return MOS_STATUS_SUCCESS;
1463 }
1464
1465 MOS_STATUS VpResourceManager::AssignVeboxResourceForRender(VP_EXECUTE_CAPS &caps, VP_SURFACE *inputSurface, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting)
1466 {
1467 VP_FUNC_CALL();
1468
1469 if (!caps.bRender)
1470 {
1471 return MOS_STATUS_INVALID_PARAMETER;
1472 }
1473
1474 return MOS_STATUS_SUCCESS;
1475 }
1476
1477 MOS_STATUS VpResourceManager::AssignExecuteResource(std::vector<FeatureType> &featurePool, VP_EXECUTE_CAPS& caps, SwFilterPipe &executedFilters)
1478 {
1479 VP_FUNC_CALL();
1480
1481 std::vector<VP_SURFACE *> inputSurfaces, pastSurfaces, futureSurfaces;
1482 for (uint32_t i = 0; i < executedFilters.GetSurfaceCount(true); ++i)
1483 {
1484 VP_SURFACE *inputSurface = GetCopyInstOfExtSurface(executedFilters.GetSurface(true, i));
1485 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
1486 inputSurfaces.push_back(inputSurface);
1487
1488 VP_SURFACE *pastSurface = GetCopyInstOfExtSurface(executedFilters.GetPastSurface(i));
1489 pastSurfaces.push_back(pastSurface ? pastSurface : nullptr);
1490
1491 VP_SURFACE *futureSurface = GetCopyInstOfExtSurface(executedFilters.GetFutureSurface(i));
1492 futureSurfaces.push_back(futureSurface ? futureSurface : nullptr);
1493 }
1494 VP_SURFACE *outputSurface = GetCopyInstOfExtSurface(executedFilters.GetSurface(false, 0));
1495
1496 RESOURCE_ASSIGNMENT_HINT resHint = {};
1497
1498 if (caps.bVebox && (caps.bDI || caps.bDiProcess2ndField))
1499 {
1500 m_isPastFrameVeboxDiUsed = true;
1501 }
1502 else
1503 {
1504 m_isPastFrameVeboxDiUsed = false;
1505 }
1506
1507 VP_PUBLIC_CHK_STATUS_RETURN(GetResourceHint(featurePool, executedFilters, resHint));
1508
1509 if (nullptr == outputSurface && IsOutputSurfaceNeeded(caps))
1510 {
1511 VP_PUBLIC_CHK_STATUS_RETURN(AssignIntermediaSurface(caps, executedFilters));
1512 outputSurface = GetCopyInstOfExtSurface(executedFilters.GetSurface(false, 0));
1513 VP_PUBLIC_CHK_NULL_RETURN(outputSurface);
1514 }
1515
1516 VP_PUBLIC_CHK_STATUS_RETURN(AssignExecuteResource(caps, inputSurfaces, outputSurface,
1517 pastSurfaces, futureSurfaces, resHint, executedFilters.GetSurfacesSetting(), executedFilters));
1518 ++m_currentPipeIndex;
1519 return MOS_STATUS_SUCCESS;
1520 }
1521
1522 MOS_STATUS VpResourceManager::GetUpdatedExecuteResource(std::vector<FeatureType> &featurePool, VP_EXECUTE_CAPS &caps, SwFilterPipe &swfilterPipe, VP_SURFACE_SETTING &surfSetting)
1523 {
1524 VP_FUNC_CALL();
1525
1526 std::vector<VP_SURFACE *> inputSurfaces, pastSurfaces, futureSurfaces;
1527 for (uint32_t i = 0; i < swfilterPipe.GetSurfaceCount(true); ++i)
1528 {
1529 VP_SURFACE *inputSurface = GetCopyInstOfExtSurface(swfilterPipe.GetSurface(true, i));
1530 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
1531 inputSurfaces.push_back(inputSurface);
1532
1533 VP_SURFACE *pastSurface = GetCopyInstOfExtSurface(swfilterPipe.GetPastSurface(i));
1534 pastSurfaces.push_back(pastSurface ? pastSurface : nullptr);
1535
1536 VP_SURFACE *futureSurface = GetCopyInstOfExtSurface(swfilterPipe.GetFutureSurface(i));
1537 futureSurfaces.push_back(futureSurface ? futureSurface : nullptr);
1538 }
1539 VP_SURFACE *outputSurface = GetCopyInstOfExtSurface(swfilterPipe.GetSurface(false, 0));
1540
1541 RESOURCE_ASSIGNMENT_HINT resHint = {};
1542
1543 VP_PUBLIC_CHK_STATUS_RETURN(GetResourceHint(featurePool, swfilterPipe, resHint));
1544
1545 VP_PUBLIC_CHK_STATUS_RETURN(AssignExecuteResource(caps, inputSurfaces, outputSurface,
1546 pastSurfaces, futureSurfaces, resHint, surfSetting, swfilterPipe));
1547 ++m_currentPipeIndex;
1548
1549 return MOS_STATUS_SUCCESS;
1550 }
1551
1552 MOS_STATUS VpResourceManager::AssignExecuteResource(VP_EXECUTE_CAPS& caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface,
1553 std::vector<VP_SURFACE *> &pastSurfaces, std::vector<VP_SURFACE *> &futureSurfaces, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting, SwFilterPipe& executedFilters)
1554 {
1555 VP_FUNC_CALL();
1556
1557 surfSetting.Clean();
1558
1559 if (caps.bVebox || caps.bDnKernelUpdate)
1560 {
1561 // Create Vebox Resources
1562 VP_PUBLIC_CHK_STATUS_RETURN(AssignVeboxResource(caps, inputSurfaces[0], outputSurface, pastSurfaces[0], futureSurfaces[0], resHint, surfSetting, executedFilters));
1563 }
1564
1565 if (caps.bRender)
1566 {
1567 VP_PUBLIC_CHK_STATUS_RETURN(AssignRenderResource(caps, inputSurfaces, outputSurface, pastSurfaces, futureSurfaces, resHint, surfSetting, executedFilters));
1568 }
1569
1570 if (caps.bNpu)
1571 {
1572 VP_PUBLIC_CHK_STATUS_RETURN(AssignNpuResource(caps, inputSurfaces, outputSurface, pastSurfaces, futureSurfaces, resHint, surfSetting, executedFilters));
1573 }
1574
1575 return MOS_STATUS_SUCCESS;
1576 }
1577
1578 VPHAL_CSPACE GetDemosaicOutputColorSpace(VPHAL_CSPACE colorSpace)
1579 {
1580 return IS_COLOR_SPACE_BT2020(colorSpace) ? CSpace_BT2020_RGB : CSpace_sRGB;
1581 }
1582
1583 MOS_FORMAT GetDemosaicOutputFormat(VPHAL_CSPACE colorSpace)
1584 {
1585 return IS_COLOR_SPACE_BT2020(colorSpace) ? Format_R10G10B10A2 : Format_A8B8G8R8;
1586 }
1587
1588 MOS_STATUS GetVeboxOutputParams(VP_EXECUTE_CAPS &executeCaps, MOS_FORMAT inputFormat, MOS_TILE_TYPE inputTileType, MOS_FORMAT outputFormat,
1589 MOS_FORMAT &veboxOutputFormat, MOS_TILE_TYPE &veboxOutputTileType, VPHAL_CSPACE colorSpaceOutput)
1590 {
1591 VP_FUNC_CALL();
1592
1593 // Vebox Chroma Co-Sited downsampleing is part of VEO. It only affects format of vebox output surface, but not
1594 // affect sfc input format, that's why different logic between GetSfcInputFormat and GetVeboxOutputParams.
1595 // Check DI first and downsampling to NV12 if possible to save bandwidth no matter IECP enabled or not.
1596 if (executeCaps.b3DlutOutput)
1597 {
1598 if (IS_RGB64_FLOAT_FORMAT(outputFormat)) // SFC output FP16, YUV->ABGR16
1599 {
1600 veboxOutputFormat = Format_A16B16G16R16;
1601 }
1602 else
1603 {
1604 veboxOutputFormat = IS_COLOR_SPACE_BT2020(colorSpaceOutput) ? Format_R10G10B10A2 : Format_A8B8G8R8;
1605 }
1606 veboxOutputTileType = inputTileType;
1607 }
1608 else if (executeCaps.bDI || executeCaps.bDiProcess2ndField)
1609 {
1610 // NV12 will be used if target output is not YUV2 to save bandwidth.
1611 if (outputFormat == Format_YUY2)
1612 {
1613 veboxOutputFormat = Format_YUY2;
1614 }
1615 else
1616 {
1617 veboxOutputFormat = Format_NV12;
1618 }
1619 veboxOutputTileType = MOS_TILE_Y;
1620 }
1621 else if (executeCaps.bIECP && executeCaps.bCGC && executeCaps.bBt2020ToRGB)
1622 {
1623 veboxOutputFormat = Format_A8B8G8R8;
1624 veboxOutputTileType = inputTileType;
1625 }
1626 else if (executeCaps.bIECP)
1627 {
1628 // Upsampling to yuv444 for IECP input/output.
1629 // To align with legacy path, need to check whether inputFormat can also be used for IECP case,
1630 // in which case IECP down sampling will be applied.
1631 veboxOutputFormat = Format_AYUV;
1632 veboxOutputTileType = inputTileType;
1633 }
1634 else if (executeCaps.bDemosaicInUse)
1635 {
1636 veboxOutputFormat = GetDemosaicOutputFormat(colorSpaceOutput);
1637 veboxOutputTileType = inputTileType;
1638 }
1639 else
1640 {
1641 veboxOutputFormat = inputFormat;
1642 veboxOutputTileType = inputTileType;
1643 }
1644
1645 return MOS_STATUS_SUCCESS;
1646 }
1647
1648
1649 MOS_FORMAT GetSfcInputFormat(VP_EXECUTE_CAPS &executeCaps, MOS_FORMAT inputFormat, VPHAL_CSPACE colorSpaceOutput, MOS_FORMAT outputFormat)
1650 {
1651 VP_FUNC_CALL();
1652
1653 // Vebox Chroma Co-Sited downsampling is part of VEO. It only affects format of vebox output surface, but not
1654 // affect sfc input format, that's why different logic between GetSfcInputFormat and GetVeboxOutputParams.
1655 // Check HDR case first, since 3DLUT output is fixed RGB32.
1656 // Then Check IECP, since IECP is done after DI, and the vebox downsampling not affect the vebox input.
1657 if (executeCaps.b3DlutOutput)
1658 {
1659 if (executeCaps.bFeCSC)
1660 {
1661 // When front end csc is enabled, the csc will be done in IECP front end csc. Then SFC only need to do scaling. So here return the output format as SFC input format
1662 // This path cannot be walked in for executeCaps.bFeCSC only is true when no sfc is needed, which is decided in Policy::UpdateExeCaps
1663 // Just in case fecsc+sfc is enabled in the future
1664 VP_PUBLIC_ASSERTMESSAGE("VEBOX Front End CSC should not be combined with SFC. When SFC is enabled, Front End CSC should be disabled. CSC should be done on SFC");
1665 return outputFormat;
1666 }
1667 else
1668 {
1669 if (IS_RGB64_FLOAT_FORMAT(outputFormat)) // SFC output FP16, YUV->ABGR16
1670 {
1671 return Format_A16B16G16R16;
1672 }
1673 else
1674 {
1675 return IS_COLOR_SPACE_BT2020(colorSpaceOutput) ? Format_R10G10B10A2 : Format_A8B8G8R8;
1676 }
1677 }
1678 }
1679 else if (executeCaps.bIECP && executeCaps.bCGC && executeCaps.bBt2020ToRGB)
1680 {
1681 // Upsampling to RGB444, and using ABGR as Vebox output
1682 return Format_A8B8G8R8;
1683 }
1684 else if (executeCaps.bIECP)
1685 {
1686 // Upsampling to yuv444 for IECP input/output.
1687 // To align with legacy path, need to check whether inputFormat can also be used for IECP case,
1688 // in which case IECP down sampling will be applied.
1689 return Format_AYUV;
1690 }
1691 else if (executeCaps.bDI)
1692 {
1693 // If the input is 4:2:0, then chroma data is doubled vertically to 4:2:2
1694 // For executeCaps.bDiProcess2ndField, no DI enabled in vebox, so no need
1695 // set to YUY2 here.
1696 return Format_YUY2;
1697 }
1698 else if (executeCaps.bDemosaicInUse)
1699 {
1700 return GetDemosaicOutputFormat(colorSpaceOutput);
1701 }
1702
1703 return inputFormat;
1704 }
1705
1706 MOS_STATUS VpResourceManager::ReAllocateVeboxOutputSurface(VP_EXECUTE_CAPS& caps, VP_SURFACE *inputSurface, VP_SURFACE *outputSurface, bool &allocated)
1707 {
1708 VP_FUNC_CALL();
1709
1710 MOS_RESOURCE_MMC_MODE surfCompressionMode = MOS_MMC_DISABLED;
1711 bool bSurfCompressible = false;
1712 uint32_t i = 0;
1713 auto *skuTable = m_osInterface.pfnGetSkuTable(&m_osInterface);
1714 Mos_MemPool memTypeSurfVideoMem = MOS_MEMPOOL_VIDEOMEMORY;
1715
1716 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
1717 VP_PUBLIC_CHK_NULL_RETURN(inputSurface->osSurface);
1718 VP_PUBLIC_CHK_NULL_RETURN(outputSurface);
1719 VP_PUBLIC_CHK_NULL_RETURN(outputSurface->osSurface);
1720
1721 if (skuTable && MEDIA_IS_SKU(skuTable, FtrLimitedLMemBar))
1722 {
1723 memTypeSurfVideoMem = MOS_MEMPOOL_DEVICEMEMORY;
1724 }
1725
1726 MOS_FORMAT veboxOutputFormat = inputSurface->osSurface->Format;
1727 MOS_TILE_TYPE veboxOutputTileType = inputSurface->osSurface->TileType;
1728
1729 VP_PUBLIC_CHK_STATUS_RETURN(GetVeboxOutputParams(caps, inputSurface->osSurface->Format, inputSurface->osSurface->TileType,
1730 outputSurface->osSurface->Format, veboxOutputFormat, veboxOutputTileType, outputSurface->ColorSpace));
1731
1732 allocated = false;
1733
1734 bool enableVeboxOutputSurf = false;
1735 if (m_vpUserFeatureControl)
1736 {
1737 enableVeboxOutputSurf = m_vpUserFeatureControl->IsVeboxOutputSurfEnabled();
1738 }
1739
1740 bSurfCompressible = inputSurface->osSurface->bCompressible;
1741 surfCompressionMode = inputSurface->osSurface->CompressionMode;
1742
1743 if (m_currentFrameIds.pastFrameAvailable && m_currentFrameIds.futureFrameAvailable)
1744 {
1745 // Not switch back to 2 after being set to 4.
1746 m_veboxOutputCount = 4;
1747 }
1748
1749 bool isVppInterResourceLocakable = enableVeboxOutputSurf ? VPP_INTER_RESOURCE_LOCKABLE : VPP_INTER_RESOURCE_NOTLOCKABLE;
1750
1751 for (i = 0; i < m_veboxOutputCount; i++)
1752 {
1753 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1754 m_veboxOutput[i],
1755 "VeboxSurfaceOutput",
1756 veboxOutputFormat,
1757 MOS_GFXRES_2D,
1758 veboxOutputTileType,
1759 inputSurface->osSurface->dwWidth,
1760 inputSurface->osSurface->dwHeight,
1761 bSurfCompressible,
1762 surfCompressionMode,
1763 allocated,
1764 false,
1765 IsDeferredResourceDestroyNeeded(),
1766 MOS_HW_RESOURCE_USAGE_VP_OUTPUT_PICTURE_FF,
1767 MOS_TILE_UNSET_GMM,
1768 memTypeSurfVideoMem,
1769 isVppInterResourceLocakable));
1770
1771 m_veboxOutput[i]->ColorSpace = inputSurface->ColorSpace;
1772 m_veboxOutput[i]->rcDst = inputSurface->rcDst;
1773 m_veboxOutput[i]->rcSrc = inputSurface->rcSrc;
1774 m_veboxOutput[i]->rcMaxSrc = inputSurface->rcMaxSrc;
1775
1776 m_veboxOutput[i]->SampleType = SAMPLE_PROGRESSIVE;
1777 }
1778
1779 if (allocated)
1780 {
1781 // Report Compress Status
1782 if (m_veboxOutput[0]->osSurface)
1783 {
1784 m_reporting.GetFeatures().ffdiCompressible = m_veboxOutput[0]->osSurface->bIsCompressed;
1785 m_reporting.GetFeatures().ffdiCompressMode = (uint8_t)m_veboxOutput[0]->osSurface->CompressionMode;
1786 }
1787 }
1788
1789 return MOS_STATUS_SUCCESS;
1790 }
1791
1792 MOS_STATUS VpResourceManager::ReAllocateVeboxDenoiseOutputSurface(VP_EXECUTE_CAPS& caps, VP_SURFACE *inputSurface, bool &allocated)
1793 {
1794 VP_FUNC_CALL();
1795
1796 MOS_RESOURCE_MMC_MODE surfCompressionMode = MOS_MMC_DISABLED;
1797 bool bSurfCompressible = false;
1798 MOS_TILE_MODE_GMM tileModeByForce = MOS_TILE_UNSET_GMM;
1799 auto * skuTable = m_osInterface.pfnGetSkuTable(&m_osInterface);
1800 auto * waTable = m_osInterface.pfnGetWaTable(&m_osInterface);
1801 Mos_MemPool memTypeSurfVideoMem = MOS_MEMPOOL_VIDEOMEMORY;
1802 uint32_t dwHeight;
1803 MOS_TILE_TYPE TileType;
1804
1805 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
1806 VP_PUBLIC_CHK_NULL_RETURN(inputSurface->osSurface);
1807
1808 if (skuTable)
1809 {
1810 //DN output surface must be tile64 only when input format is bayer
1811 if (!MEDIA_IS_SKU(skuTable, FtrTileY) &&
1812 IS_BAYER_FORMAT(inputSurface->osSurface->Format))
1813 {
1814 tileModeByForce = MOS_TILE_64_GMM;
1815 }
1816
1817 if (MEDIA_IS_SKU(skuTable, FtrLimitedLMemBar))
1818 {
1819 memTypeSurfVideoMem = MOS_MEMPOOL_DEVICEMEMORY;
1820 }
1821 }
1822
1823 allocated = false;
1824
1825 bSurfCompressible = inputSurface->osSurface->bCompressible;
1826 surfCompressionMode = inputSurface->osSurface->CompressionMode;
1827
1828 if (caps.bCappipe)
1829 {
1830 bSurfCompressible = false;
1831 surfCompressionMode = MOS_MMC_DISABLED;
1832 // Add 4 to input height for DN and STMM if Bayer Pattern offset is 10 or 11
1833 if (IS_BAYER_GRBG_FORMAT(inputSurface->osSurface->Format) ||
1834 IS_BAYER_GBRG_FORMAT(inputSurface->osSurface->Format))
1835 {
1836 dwHeight = inputSurface->osSurface->dwHeight + 4;
1837 }
1838 else
1839 {
1840 dwHeight = inputSurface->osSurface->dwHeight;
1841 }
1842 // For Bayer pattern inputs only the Current Denoised Output/Previous Denoised Input are in Tile-Y
1843 TileType = IS_BAYER_FORMAT(inputSurface->osSurface->Format) ? MOS_TILE_Y : inputSurface->osSurface->TileType;
1844 }
1845 else
1846 {
1847 dwHeight = inputSurface->osSurface->dwHeight;
1848 TileType = inputSurface->osSurface->TileType;
1849 }
1850
1851 for (uint32_t i = 0; i < VP_NUM_DN_SURFACES; i++)
1852 {
1853 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1854 m_veboxDenoiseOutput[i],
1855 "VeboxFFDNSurface",
1856 inputSurface->osSurface->Format,
1857 MOS_GFXRES_2D,
1858 TileType,
1859 inputSurface->osSurface->dwWidth,
1860 dwHeight,
1861 bSurfCompressible,
1862 surfCompressionMode,
1863 allocated,
1864 false,
1865 IsDeferredResourceDestroyNeeded(),
1866 MOS_HW_RESOURCE_USAGE_VP_INPUT_REFERENCE_FF,
1867 tileModeByForce,
1868 memTypeSurfVideoMem,
1869 VPP_INTER_RESOURCE_NOTLOCKABLE));
1870
1871 // DN output surface state should be able to share with vebox input surface state
1872 if (m_veboxDenoiseOutput[i]->osSurface &&
1873 (m_veboxDenoiseOutput[i]->osSurface->YoffsetForUplane != inputSurface->osSurface->YoffsetForUplane || m_veboxDenoiseOutput[i]->osSurface->YoffsetForVplane != inputSurface->osSurface->YoffsetForVplane))
1874 {
1875 VP_PUBLIC_ASSERTMESSAGE("Vebox surface state of DN output surface doesn't align with input surface!");
1876 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_UNKNOWN);
1877 }
1878
1879 // if allocated, pVeboxState->PastSurface is not valid for DN reference.
1880 if (allocated)
1881 {
1882 // If DI is enabled, try to use app's reference if provided
1883 if (caps.bRefValid && caps.bDI)
1884 {
1885 //CopySurfaceValue(pVeboxState->m_previousSurface, pVeboxState->m_currentSurface->pBwdRef);
1886 }
1887 else
1888 {
1889 caps.bRefValid = false;
1890 }
1891 // Report Compress Status
1892 if (m_veboxDenoiseOutput[i]->osSurface)
1893 {
1894 m_reporting.GetFeatures().ffdnCompressible = m_veboxDenoiseOutput[i]->osSurface->bIsCompressed;
1895 m_reporting.GetFeatures().ffdnCompressMode = (uint8_t)m_veboxDenoiseOutput[i]->osSurface->CompressionMode;
1896 }
1897 }
1898 else
1899 {
1900 caps.bRefValid = true;
1901 }
1902
1903 // DN's output format should be same to input
1904 m_veboxDenoiseOutput[i]->SampleType =
1905 inputSurface->SampleType;
1906
1907 // Set Colorspace of FFDN
1908 m_veboxDenoiseOutput[i]->ColorSpace = inputSurface->ColorSpace;
1909
1910 // Copy FrameID and parameters, as DN output will be used as next blt's current
1911 m_veboxDenoiseOutput[i]->FrameID = inputSurface->FrameID;
1912
1913 // Place Holder to update report for debug purpose
1914 }
1915 return MOS_STATUS_SUCCESS;
1916 }
1917
1918 // Allocate STMM (Spatial-Temporal Motion Measure) Surfaces
1919 MOS_STATUS VpResourceManager::ReAllocateVeboxSTMMSurface(VP_EXECUTE_CAPS& caps, VP_SURFACE *inputSurface, bool &allocated)
1920 {
1921 VP_FUNC_CALL();
1922
1923 MOS_RESOURCE_MMC_MODE surfCompressionMode = MOS_MMC_DISABLED;
1924 bool bSurfCompressible = false;
1925 uint32_t i = 0;
1926 MOS_TILE_MODE_GMM tileModeByForce = MOS_TILE_UNSET_GMM;
1927 auto * skuTable = m_osInterface.pfnGetSkuTable(&m_osInterface);
1928 Mos_MemPool memTypeHistStat = GetHistStatMemType(caps);
1929 uint32_t dwHeight;
1930
1931 //STMM surface can be not lockable, if secure mode is enabled
1932 bool isSTMMNotLockable = caps.bSecureVebox;
1933
1934 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
1935 VP_PUBLIC_CHK_NULL_RETURN(inputSurface->osSurface);
1936
1937 if (skuTable && !MEDIA_IS_SKU(skuTable, FtrTileY))
1938 {
1939 tileModeByForce = MOS_TILE_64_GMM;
1940 }
1941
1942 if (caps.bCappipe)
1943 {
1944 // Add 4 to input height for DN and STMM if Bayer Pattern offset is 10 or 11
1945 if (IS_BAYER_GRBG_FORMAT(inputSurface->osSurface->Format) ||
1946 IS_BAYER_GBRG_FORMAT(inputSurface->osSurface->Format))
1947 {
1948 dwHeight = inputSurface->osSurface->dwHeight + 4;
1949 }
1950 else
1951 {
1952 dwHeight = inputSurface->osSurface->dwHeight;
1953 }
1954 }
1955 else
1956 {
1957 dwHeight = inputSurface->osSurface->dwHeight;
1958 }
1959
1960 allocated = false;
1961 for (i = 0; i < VP_NUM_STMM_SURFACES; i++)
1962 {
1963 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
1964 m_veboxSTMMSurface[i],
1965 "VeboxSTMMSurface",
1966 Format_STMM,
1967 MOS_GFXRES_2D,
1968 MOS_TILE_Y,
1969 inputSurface->osSurface->dwWidth,
1970 dwHeight,
1971 bSurfCompressible,
1972 surfCompressionMode,
1973 allocated,
1974 false,
1975 IsDeferredResourceDestroyNeeded(),
1976 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_FF,
1977 tileModeByForce,
1978 memTypeHistStat,
1979 isSTMMNotLockable));
1980
1981 if (allocated)
1982 {
1983 VP_PUBLIC_CHK_NULL_RETURN(m_veboxSTMMSurface[i]);
1984 // Report Compress Status
1985 m_reporting.GetFeatures().stmmCompressible = bSurfCompressible;
1986 m_reporting.GetFeatures().stmmCompressMode = (uint8_t)surfCompressionMode;
1987 }
1988 }
1989 return MOS_STATUS_SUCCESS;
1990 }
1991
1992 void VpResourceManager::DestoryVeboxOutputSurface()
1993 {
1994 VP_FUNC_CALL();
1995
1996 for (uint32_t i = 0; i < VP_MAX_NUM_VEBOX_SURFACES; i++)
1997 {
1998 m_allocator.DestroyVpSurface(m_veboxOutput[i], IsDeferredResourceDestroyNeeded());
1999 }
2000 }
2001
2002 void VpResourceManager::DestoryVeboxDenoiseOutputSurface()
2003 {
2004 VP_FUNC_CALL();
2005
2006 for (uint32_t i = 0; i < VP_NUM_DN_SURFACES; i++)
2007 {
2008 m_allocator.DestroyVpSurface(m_veboxDenoiseOutput[i], IsDeferredResourceDestroyNeeded());
2009 }
2010 }
2011
2012 void VpResourceManager::DestoryVeboxSTMMSurface()
2013 {
2014 VP_FUNC_CALL();
2015
2016 // Free DI history buffers (STMM = Spatial-temporal motion measure)
2017 for (uint32_t i = 0; i < VP_NUM_STMM_SURFACES; i++)
2018 {
2019 m_allocator.DestroyVpSurface(m_veboxSTMMSurface[i], IsDeferredResourceDestroyNeeded());
2020 }
2021 }
2022
2023 MOS_STATUS VpResourceManager::FillLinearBufferWithEncZero(VP_SURFACE *surface, uint32_t width, uint32_t height)
2024 {
2025 VP_FUNC_CALL();
2026
2027 return MOS_STATUS_SUCCESS;
2028 }
2029
2030 uint32_t VpResourceManager::Get3DLutSize(bool is33LutSizeEnabled, uint32_t &lutWidth, uint32_t &lutHeight)
2031 {
2032 VP_FUNC_CALL();
2033
2034 if (is33LutSizeEnabled)
2035 {
2036 lutWidth = LUT33_SEG_SIZE * 2;
2037 lutHeight = LUT33_SEG_SIZE * LUT33_MUL_SIZE;
2038 VP_RENDER_NORMALMESSAGE("3DLut table is used 33 lutsize.");
2039 return VP_VEBOX_HDR_3DLUT33;
2040 }
2041 else
2042 {
2043 lutWidth = LUT65_SEG_SIZE * 2;
2044 lutHeight = LUT65_SEG_SIZE * LUT65_MUL_SIZE;
2045 return VP_VEBOX_HDR_3DLUT65;
2046 }
2047 }
2048
2049 uint32_t VpResourceManager::Get1DLutSize()
2050 {
2051 VP_FUNC_CALL();
2052
2053 return SHAPE_1K_LOOKUP_SIZE;
2054 }
2055
2056 Mos_MemPool VpResourceManager::GetHistStatMemType(VP_EXECUTE_CAPS &caps)
2057 {
2058 VP_FUNC_CALL();
2059
2060 return MOS_MEMPOOL_VIDEOMEMORY;
2061 }
2062
2063 MOS_STATUS VpResourceManager::AllocateVeboxResource(VP_EXECUTE_CAPS& caps, VP_SURFACE *inputSurface, VP_SURFACE *outputSurface)
2064 {
2065 VP_FUNC_CALL();
2066 MOS_FORMAT format;
2067 MOS_TILE_TYPE TileType;
2068 uint32_t dwWidth;
2069 uint32_t dwHeight;
2070 uint32_t dwSize;
2071 uint32_t i;
2072 MOS_RESOURCE_MMC_MODE surfCompressionMode = MOS_MMC_DISABLED;
2073 bool bSurfCompressible = false;
2074 bool bAllocated = false;
2075 uint8_t InitValue = 0;
2076 Mos_MemPool memTypeHistStat = GetHistStatMemType(caps);
2077 bool isStatisticsBufNotLockable = false;
2078
2079 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
2080 VP_PUBLIC_CHK_NULL_RETURN(inputSurface->osSurface);
2081 VP_PUBLIC_CHK_NULL_RETURN(outputSurface);
2082 VP_PUBLIC_CHK_NULL_RETURN(outputSurface->osSurface);
2083
2084 // change the init value when null hw is enabled
2085 if (m_osInterface.bNullHwIsEnabled)
2086 {
2087 InitValue = 0x80;
2088 }
2089
2090 if (IS_VP_VEBOX_DN_ONLY(caps))
2091 {
2092 bSurfCompressible = inputSurface->osSurface->bCompressible;
2093 surfCompressionMode = inputSurface->osSurface->CompressionMode;
2094 }
2095 else
2096 {
2097 bSurfCompressible = true;
2098 surfCompressionMode = MOS_MMC_MC;
2099 }
2100
2101 // Decide DN output surface
2102 if (VeboxOutputNeeded(caps))
2103 {
2104 VP_PUBLIC_CHK_STATUS_RETURN(ReAllocateVeboxOutputSurface(caps, inputSurface, outputSurface, bAllocated));
2105 }
2106 else
2107 {
2108 DestoryVeboxOutputSurface();
2109 }
2110
2111 if (VeboxDenoiseOutputNeeded(caps))
2112 {
2113 VP_PUBLIC_CHK_STATUS_RETURN(ReAllocateVeboxDenoiseOutputSurface(caps, inputSurface, bAllocated));
2114 if (bAllocated)
2115 {
2116 m_currentDnOutput = 0;
2117 m_pastDnOutputValid = false;
2118 }
2119 }
2120 else
2121 {
2122 DestoryVeboxDenoiseOutputSurface();
2123 m_pastDnOutputValid = false;
2124 }
2125
2126 if (VeboxSTMMNeeded(caps, false))
2127 {
2128 VP_PUBLIC_CHK_STATUS_RETURN(ReAllocateVeboxSTMMSurface(caps, inputSurface, bAllocated));
2129 if (bAllocated)
2130 {
2131 m_currentStmmIndex = 0;
2132 }
2133 }
2134 else
2135 {
2136 DestoryVeboxSTMMSurface();
2137 }
2138
2139 #if VEBOX_AUTO_DENOISE_SUPPORTED
2140 if (caps.bDnKernelUpdate)
2141 {
2142 // Allocate Temp Surface for Vebox Update kernels----------------------------------------
2143 // the surface size is one Page
2144 dwSize = MHW_PAGE_SIZE;
2145 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2146 m_veboxDNTempSurface,
2147 "VeboxDNTempSurface",
2148 Format_Buffer,
2149 MOS_GFXRES_BUFFER,
2150 MOS_TILE_LINEAR,
2151 dwSize,
2152 1,
2153 false,
2154 MOS_MMC_DISABLED,
2155 bAllocated,
2156 true,
2157 IsDeferredResourceDestroyNeeded(),
2158 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_FF));
2159
2160 // Allocate Spatial Attributes Configuration Surface for DN kernel Gen9+-----------
2161 dwSize = MHW_PAGE_SIZE;
2162 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2163 m_veboxDNSpatialConfigSurface,
2164 "VeboxSpatialAttributesConfigurationSurface",
2165 Format_RAW,
2166 MOS_GFXRES_BUFFER,
2167 MOS_TILE_LINEAR,
2168 dwSize,
2169 1,
2170 false,
2171 MOS_MMC_DISABLED,
2172 bAllocated,
2173 false,
2174 IsDeferredResourceDestroyNeeded(),
2175 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_FF));
2176
2177 if (bAllocated)
2178 {
2179 // initialize Spatial Attributes Configuration Surface
2180 VP_PUBLIC_CHK_STATUS_RETURN(InitVeboxSpatialAttributesConfiguration());
2181 }
2182 }
2183 #endif
2184
2185 dwSize = GetHistogramSurfaceSize(caps, inputSurface->osSurface->dwWidth, inputSurface->osSurface->dwHeight);
2186
2187 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2188 m_veboxRgbHistogram,
2189 "VeboxLaceAceRgbHistogram",
2190 Format_Buffer,
2191 MOS_GFXRES_BUFFER,
2192 MOS_TILE_LINEAR,
2193 dwSize,
2194 1,
2195 false,
2196 MOS_MMC_DISABLED,
2197 bAllocated,
2198 false,
2199 IsDeferredResourceDestroyNeeded(),
2200 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_WRITE_FF,
2201 MOS_TILE_UNSET_GMM,
2202 (caps.bDI ? MOS_MEMPOOL_SYSTEMMEMORY : MOS_MEMPOOL_VIDEOMEMORY)));
2203
2204 m_isHistogramReallocated = bAllocated;
2205
2206 if (bAllocated && m_osInterface.bNullHwIsEnabled)
2207 {
2208 // Initialize veboxRgbHistogram Surface
2209 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.OsFillResource(
2210 &(m_veboxRgbHistogram->osSurface->OsResource),
2211 dwSize,
2212 InitValue));
2213 }
2214
2215 // Allocate Statistics State Surface----------------------------------------
2216 // Width to be a aligned on 64 bytes and height is 1/4 the height
2217 // Per frame information written twice per frame for 2 slices
2218 // Surface to be a rectangle aligned with dwWidth to get proper dwSize
2219 // APG PAth need to make sure input surface width/height is what to processed width/Height
2220 uint32_t statistic_size = m_vpPlatformInterface.VeboxQueryStaticSurfaceSize();
2221 dwWidth = MOS_ALIGN_CEIL(inputSurface->osSurface->dwWidth, 64);
2222 dwHeight = MOS_ROUNDUP_DIVIDE(inputSurface->osSurface->dwHeight, 4) +
2223 MOS_ROUNDUP_DIVIDE(statistic_size * sizeof(uint32_t), dwWidth);
2224
2225 if (caps.b1stPassOfSfc2PassScaling)
2226 {
2227 VP_PUBLIC_CHK_STATUS_RETURN(ReAllocateVeboxStatisticsSurface(m_veboxStatisticsSurfacefor1stPassofSfc2Pass, caps, inputSurface, dwWidth, dwHeight));
2228 }
2229 else
2230 {
2231 VP_PUBLIC_CHK_STATUS_RETURN(ReAllocateVeboxStatisticsSurface(m_veboxStatisticsSurface, caps, inputSurface, dwWidth, dwHeight));
2232 }
2233
2234 VP_PUBLIC_CHK_STATUS_RETURN(Allocate3DLut(caps));
2235
2236 if (caps.b1K1DLutInUse)
2237 {
2238 dwSize = Get1DLutSize();
2239 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2240 m_vebox1DLookUpTables,
2241 "Dv1K1DLutTableSurface",
2242 Format_Buffer,
2243 MOS_GFXRES_BUFFER,
2244 MOS_TILE_LINEAR,
2245 dwSize,
2246 1,
2247 false,
2248 MOS_MMC_DISABLED,
2249 bAllocated,
2250 false,
2251 IsDeferredResourceDestroyNeeded()));
2252 if (!bAllocated && !caps.bDV)
2253 {
2254 caps.b1K1DLutInited = 1;
2255 }
2256 }
2257 // cappipe
2258 if (caps.enableSFCLinearOutputByTileConvert)
2259 {
2260 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2261 m_innerTileConvertInput,
2262 "TempTargetSurface",
2263 outputSurface->osSurface->Format,
2264 MOS_GFXRES_2D,
2265 MOS_TILE_Y,
2266 outputSurface->osSurface->dwWidth,
2267 outputSurface->osSurface->dwHeight,
2268 false,
2269 MOS_MMC_DISABLED,
2270 bAllocated,
2271 false,
2272 IsDeferredResourceDestroyNeeded()));
2273
2274 m_innerTileConvertInput->ColorSpace = outputSurface->ColorSpace;
2275 m_innerTileConvertInput->rcSrc = outputSurface->rcSrc;
2276 m_innerTileConvertInput->rcDst = outputSurface->rcDst;
2277 m_innerTileConvertInput->rcMaxSrc = outputSurface->rcMaxSrc;
2278 }
2279 return MOS_STATUS_SUCCESS;
2280 }
2281
2282 MOS_STATUS VpResourceManager::Allocate3DLut(VP_EXECUTE_CAPS& caps)
2283 {
2284 VP_FUNC_CALL();
2285 uint32_t size = 0;
2286 bool isAllocated = false;
2287
2288 if (caps.bHDR3DLUT || caps.b3DLutCalc)
2289 {
2290 #if (_DEBUG || _RELEASE_INTERNAL)
2291 // 3D LUT new layout feature - only available in debug and release-internal builds
2292 // Check if 3DLUT new layout feature is enabled
2293 bool useNewLayout = m_vpUserFeatureControl && m_vpUserFeatureControl->Is3DLutNewLayoutEnabled();
2294
2295 // Determine LUT segment size based on caps
2296 uint32_t lutSegSize = caps.bHdr33lutsize ? LUT33_SEG_SIZE : LUT65_SEG_SIZE;
2297
2298 if (useNewLayout)
2299 {
2300 // New layout: Create volume surface with cubic dimensions
2301 VP_PUBLIC_NORMALMESSAGE("Allocating 3DLUT as volume surface with dimensions %dx%dx%d",
2302 lutSegSize, lutSegSize, lutSegSize);
2303
2304 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2305 m_vebox3DLookUpTables,
2306 "Vebox3DLutTableSurface",
2307 Format_A16B16G16R16,
2308 MOS_GFXRES_VOLUME,
2309 MOS_TILE_LINEAR,
2310 lutSegSize,
2311 lutSegSize,
2312 false,
2313 MOS_MMC_DISABLED,
2314 isAllocated,
2315 false,
2316 IsDeferredResourceDestroyNeeded(),
2317 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
2318 MOS_TILE_UNSET_GMM,
2319 MOS_MEMPOOL_VIDEOMEMORY,
2320 false,
2321 nullptr,
2322 lutSegSize));
2323 }
2324 else
2325 #endif
2326 {
2327 // Existing buffer logic: Create buffer surface (always compiled as default fallback)
2328 uint32_t lutWidth = 0;
2329 uint32_t lutHeight = 0;
2330 size = Get3DLutSize(caps.bHdr33lutsize, lutWidth, lutHeight);
2331
2332 VP_PUBLIC_NORMALMESSAGE("Allocating 3DLUT as buffer surface with size %d bytes", size);
2333
2334 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2335 m_vebox3DLookUpTables,
2336 "Vebox3DLutTableSurface",
2337 Format_Buffer,
2338 MOS_GFXRES_BUFFER,
2339 MOS_TILE_LINEAR,
2340 size,
2341 1,
2342 false,
2343 MOS_MMC_DISABLED,
2344 isAllocated,
2345 false,
2346 IsDeferredResourceDestroyNeeded(),
2347 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
2348 }
2349 }
2350
2351 return MOS_STATUS_SUCCESS;
2352 }
2353
2354 MOS_STATUS VpResourceManager::AllocateResourceFor3DLutKernel(VP_EXECUTE_CAPS& caps)
2355 {
2356 VP_FUNC_CALL();
2357 uint32_t size = 0;
2358 bool isAllocated = false;
2359 uint32_t lutWidth = 0;
2360 uint32_t lutHeight = 0;
2361
2362 uint32_t sizeOf3DLut = Get3DLutSize(caps.bHdr33lutsize, lutWidth, lutHeight);
2363
2364 if (caps.bHdr33lutsize)
2365 {
2366 if (VP_VEBOX_HDR_3DLUT33 != sizeOf3DLut)
2367 {
2368 VP_PUBLIC_ASSERTMESSAGE("3DLutSize(%x) != VP_VEBOX_HDR_3DLUT33(%x)", sizeOf3DLut, VP_VEBOX_HDR_3DLUT33);
2369 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
2370 }
2371 }
2372 else
2373 {
2374 if (VP_VEBOX_HDR_3DLUT65 != sizeOf3DLut)
2375 {
2376 VP_PUBLIC_ASSERTMESSAGE("3DLutSize(%x) != VP_VEBOX_HDR_3DLUT65(%x)", sizeOf3DLut, VP_VEBOX_HDR_3DLUT65);
2377 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
2378 }
2379 }
2380
2381 VP_PUBLIC_CHK_STATUS_RETURN(Allocate3DLut(caps));
2382
2383 uint32_t size_coef = 8 * 8 * 4;
2384
2385 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2386 m_3DLutKernelCoefSurface,
2387 "3DLutKernelCoefSurface",
2388 Format_Buffer,
2389 MOS_GFXRES_BUFFER,
2390 MOS_TILE_LINEAR,
2391 size_coef,
2392 1,
2393 false,
2394 MOS_MMC_DISABLED,
2395 isAllocated,
2396 false,
2397 IsDeferredResourceDestroyNeeded(),
2398 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
2399
2400 return MOS_STATUS_SUCCESS;
2401 }
2402
2403 MOS_STATUS VpResourceManager::Assign3DLutKernelResource(VP_EXECUTE_CAPS &caps, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting)
2404 {
2405 VP_FUNC_CALL();
2406
2407 VP_PUBLIC_CHK_STATUS_RETURN(AllocateResourceFor3DLutKernel(caps));
2408
2409 surfSetting.surfGroup.emplace(SurfaceType3DLut, m_vebox3DLookUpTables);
2410 surfSetting.surfGroup.emplace(SurfaceType3DLutCoef, m_3DLutKernelCoefSurface);
2411
2412 return MOS_STATUS_SUCCESS;
2413 }
2414
2415 MOS_STATUS VpResourceManager::AllocateResourceForHVSKernel(VP_EXECUTE_CAPS &caps)
2416 {
2417 VP_FUNC_CALL();
2418 bool isAllocated = false;
2419
2420 uint32_t size = 40 * 4;
2421
2422 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2423 m_veboxDnHVSTables,
2424 "HVSKernelTableSurface",
2425 Format_Buffer,
2426 MOS_GFXRES_BUFFER,
2427 MOS_TILE_LINEAR,
2428 size,
2429 1,
2430 false,
2431 MOS_MMC_DISABLED,
2432 isAllocated,
2433 false,
2434 IsDeferredResourceDestroyNeeded(),
2435 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
2436
2437 return MOS_STATUS_SUCCESS;
2438 }
2439
2440 MOS_STATUS VpResourceManager::AssignHVSKernelResource(VP_EXECUTE_CAPS &caps, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting)
2441 {
2442 VP_FUNC_CALL();
2443
2444 VP_PUBLIC_CHK_STATUS_RETURN(AllocateResourceForHVSKernel(caps));
2445
2446 surfSetting.surfGroup.emplace(SurfaceTypeHVSTable, m_veboxDnHVSTables);
2447
2448 return MOS_STATUS_SUCCESS;
2449 }
2450
2451 MOS_STATUS VpResourceManager::AssignSurface(VP_EXECUTE_CAPS caps, VEBOX_SURFACE_ID &surfaceId, SurfaceType surfaceType, VP_SURFACE *inputSurface, VP_SURFACE *outputSurface, VP_SURFACE *pastSurface, VP_SURFACE *futureSurface, VP_SURFACE_GROUP &surfGroup)
2452 {
2453 VP_FUNC_CALL();
2454
2455 switch (surfaceId)
2456 {
2457 case VEBOX_SURFACE_INPUT:
2458 if (nullptr == inputSurface)
2459 {
2460 VP_PUBLIC_ASSERTMESSAGE("inputSurface should not be nullptr when surfaceId being VEBOX_SURFACE_INPUT.");
2461 break;
2462 }
2463 surfGroup.emplace(surfaceType, inputSurface);
2464 break;
2465 case VEBOX_SURFACE_OUTPUT:
2466 if (nullptr == outputSurface)
2467 {
2468 VP_PUBLIC_ASSERTMESSAGE("outputSurface should not be nullptr when surfaceId being VEBOX_SURFACE_OUTPUT.");
2469 break;
2470 }
2471 surfGroup.emplace(surfaceType, outputSurface);
2472 break;
2473 case VEBOX_SURFACE_PAST_REF:
2474 if (caps.bDN && m_pastDnOutputValid)
2475 {
2476 surfGroup.emplace(surfaceType, m_veboxDenoiseOutput[(m_currentDnOutput + 1) & 1]);
2477 }
2478 else
2479 {
2480 auto curDnOutputSurface = m_veboxDenoiseOutput[m_currentDnOutput];
2481
2482 if (nullptr == pastSurface)
2483 {
2484 VP_PUBLIC_ASSERTMESSAGE("pastSurface should not be nullptr when surfaceId being VEBOX_SURFACE_PAST_REF.");
2485 break;
2486 }
2487
2488 if (!caps.bDN ||
2489 nullptr == curDnOutputSurface ||
2490 // When FtrTileY is false, DN output surface will be tile64 when input is bayer format,
2491 // while pastSurface passed by OS maybe tile4, which is different from DN output surface.
2492 // For such case, passSurface cannot be used, as vebox previous input surface and vebox
2493 // DN output surface must share same setting. The derive pitch in vebox output surface
2494 // state is for both of them. Check pitch to handle it.
2495 pastSurface->osSurface->dwPitch == curDnOutputSurface->osSurface->dwPitch)
2496 {
2497 surfGroup.emplace(surfaceType, pastSurface);
2498 }
2499 else
2500 {
2501 // DN case with m_pastDnOutputValid being false. pastSurface cannot be used here as pitch
2502 // of pastSurface is different from current DN output surface.
2503 VP_PUBLIC_NORMALMESSAGE("Do not use pastSurface. pastSurf (TileModeGmm: %d, pitch: %d) vs curDnOutputSurface (TileModeGmm: %d, pitch: %d)",
2504 pastSurface->osSurface->TileModeGMM,
2505 pastSurface->osSurface->dwPitch,
2506 curDnOutputSurface->osSurface->TileModeGMM,
2507 curDnOutputSurface->osSurface->dwPitch);
2508 }
2509 }
2510 break;
2511 case VEBOX_SURFACE_FUTURE_REF:
2512 if (nullptr == futureSurface)
2513 {
2514 VP_PUBLIC_ASSERTMESSAGE("futureSurface should not be nullptr when surfaceId being VEBOX_SURFACE_FUTURE_REF.");
2515 break;
2516 }
2517 surfGroup.emplace(surfaceType, futureSurface);
2518 break;
2519 case VEBOX_SURFACE_FRAME0:
2520 surfGroup.emplace(surfaceType, m_veboxOutput[(m_currentDnOutput + 0) % m_veboxOutputCount]);
2521 break;
2522 case VEBOX_SURFACE_FRAME1:
2523 surfGroup.emplace(surfaceType, m_veboxOutput[(m_currentDnOutput + 1) % m_veboxOutputCount]);
2524 break;
2525 case VEBOX_SURFACE_FRAME2:
2526 surfGroup.emplace(surfaceType, m_veboxOutput[(m_currentDnOutput + 2) % m_veboxOutputCount]);
2527 break;
2528 case VEBOX_SURFACE_FRAME3:
2529 surfGroup.emplace(surfaceType, m_veboxOutput[(m_currentDnOutput + 3) % m_veboxOutputCount]);
2530 break;
2531 default:
2532 break;
2533 }
2534 return MOS_STATUS_SUCCESS;
2535 }
2536
2537 MOS_STATUS VpResourceManager::AssignVeboxResource(VP_EXECUTE_CAPS& caps, VP_SURFACE *inputSurface, VP_SURFACE *outputSurface,
2538 VP_SURFACE *pastSurface, VP_SURFACE *futureSurface, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting, SwFilterPipe& executedFilters)
2539 {
2540 VP_FUNC_CALL();
2541 VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
2542 VP_PUBLIC_CHK_NULL_RETURN(inputSurface->osSurface);
2543 VP_PUBLIC_CHK_NULL_RETURN(outputSurface);
2544 VP_PUBLIC_CHK_NULL_RETURN(outputSurface->osSurface);
2545
2546 MOS_FORMAT format;
2547 MOS_TILE_TYPE TileType;
2548 uint32_t dwWidth;
2549 uint32_t dwHeight;
2550 uint32_t dwSize;
2551 uint32_t i;
2552 auto& surfGroup = surfSetting.surfGroup;
2553
2554 // Render case reuse vebox resource, and don`t need re-allocate.
2555 if (!caps.bRender ||
2556 (caps.bRender && caps.bDnKernelUpdate))
2557 {
2558 VP_PUBLIC_CHK_STATUS_RETURN(AllocateVeboxResource(caps, inputSurface, outputSurface));
2559 }
2560
2561 if (caps.bDI || caps.bDiProcess2ndField)
2562 {
2563 bool b60fpsDi = resHint.b60fpsDi || caps.bDiProcess2ndField;
2564 VEBOX_SURFACES_CONFIG cfg(b60fpsDi, caps.bSFC, m_sameSamples, m_outOfBound, m_currentFrameIds.pastFrameAvailable,
2565 m_currentFrameIds.futureFrameAvailable, IsInterleaveFirstField(inputSurface->SampleType));
2566 auto it = m_veboxSurfaceConfigMap.find(cfg.value);
2567 if (m_veboxSurfaceConfigMap.end() == it)
2568 {
2569 VP_PUBLIC_ASSERTMESSAGE("SurfaceConfig is invalid, cfg.value = %d", cfg.value);
2570 VP_PUBLIC_ASSERTMESSAGE("b64Di = %d, sfcEnable = %d, sameSample = %d, outOfBound = %d, pastframeAvailable = %d, future frameAvaliable = %d, FirstDiFiels = %d",
2571 cfg.b64DI,
2572 cfg.sfcEnable,
2573 cfg.sameSample,
2574 cfg.outOfBound,
2575 cfg.pastFrameAvailable,
2576 cfg.futureFrameAvailable,
2577 cfg.firstDiField);
2578 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
2579 }
2580 auto surfaces = it->second;
2581 VP_PUBLIC_CHK_STATUS_RETURN(AssignSurface(caps, surfaces.currentInputSurface, SurfaceTypeVeboxInput, inputSurface, outputSurface, pastSurface, futureSurface, surfSetting.surfGroup));
2582 VP_PUBLIC_CHK_STATUS_RETURN(AssignSurface(caps, surfaces.pastInputSurface, SurfaceTypeVeboxPreviousInput, inputSurface, outputSurface, pastSurface, futureSurface, surfSetting.surfGroup));
2583 VP_PUBLIC_CHK_STATUS_RETURN(AssignSurface(caps, surfaces.currentOutputSurface, SurfaceTypeVeboxCurrentOutput, inputSurface, outputSurface, pastSurface, futureSurface, surfSetting.surfGroup));
2584 VP_PUBLIC_CHK_STATUS_RETURN(AssignSurface(caps, surfaces.pastOutputSurface, SurfaceTypeVeboxPreviousOutput, inputSurface, outputSurface, pastSurface, futureSurface, surfSetting.surfGroup));
2585
2586 if (caps.bDN)
2587 {
2588 // Insert DN output surface
2589 surfGroup.emplace(SurfaceTypeDNOutput, m_veboxDenoiseOutput[m_currentDnOutput]);
2590 }
2591
2592 caps.bRefValid = surfGroup.find(SurfaceTypeVeboxPreviousInput) != surfGroup.end();
2593 }
2594 else
2595 {
2596 surfGroup.emplace(SurfaceTypeVeboxInput, inputSurface);
2597 surfGroup.emplace(SurfaceTypeVeboxCurrentOutput, GetVeboxOutputSurface(caps, outputSurface));
2598
2599 if (caps.bDN)
2600 {
2601 // Insert DN output surface
2602 surfGroup.emplace(SurfaceTypeDNOutput, m_veboxDenoiseOutput[m_currentDnOutput]);
2603 // Insert DN Reference surface
2604 if (caps.bRefValid)
2605 {
2606 surfGroup.emplace(SurfaceTypeVeboxPreviousInput, m_veboxDenoiseOutput[(m_currentDnOutput + 1) & 1]);
2607 }
2608 }
2609 }
2610
2611 if (VeboxSTMMNeeded(caps, true))
2612 {
2613 // Insert STMM input surface
2614 surfGroup.emplace(SurfaceTypeSTMMIn, m_veboxSTMMSurface[m_currentStmmIndex]);
2615 // Insert STMM output surface
2616 surfGroup.emplace(SurfaceTypeSTMMOut, m_veboxSTMMSurface[(m_currentStmmIndex + 1) & 1]);
2617 }
2618
2619 #if VEBOX_AUTO_DENOISE_SUPPORTED
2620 if (caps.bDnKernelUpdate)
2621 {
2622 // Insert Vebox auto DN noise level surface
2623 surfGroup.emplace(SurfaceTypeAutoDNNoiseLevel, m_veboxDNTempSurface);
2624 // Insert Vebox auto DN spatial config surface/buffer
2625 surfGroup.emplace(SurfaceTypeAutoDNSpatialConfig, m_veboxDNSpatialConfigSurface);
2626 }
2627 #endif
2628
2629 // Insert Vebox histogram surface
2630 surfGroup.emplace(SurfaceTypeLaceAceRGBHistogram, m_veboxRgbHistogram);
2631
2632 // Insert Vebox statistics surface
2633 if (caps.b1stPassOfSfc2PassScaling)
2634 {
2635 surfGroup.emplace(SurfaceTypeStatistics, m_veboxStatisticsSurfacefor1stPassofSfc2Pass);
2636 }
2637 else
2638 {
2639 surfGroup.emplace(SurfaceTypeStatistics, m_veboxStatisticsSurface);
2640 }
2641 surfSetting.dwVeboxPerBlockStatisticsHeight = m_dwVeboxPerBlockStatisticsHeight;
2642 surfSetting.dwVeboxPerBlockStatisticsWidth = m_dwVeboxPerBlockStatisticsWidth;
2643
2644 if (VeboxHdr3DlutNeeded(caps))
2645 {
2646 // Insert Vebox 3Dlut surface
2647 surfGroup.emplace(SurfaceType3DLut, m_vebox3DLookUpTables);
2648 }
2649
2650 if (resHint.isHVSTableNeeded)
2651 {
2652 VP_PUBLIC_CHK_NULL_RETURN(m_veboxDnHVSTables);
2653 // Insert Vebox HVS DN surface
2654 surfGroup.emplace(SurfaceTypeHVSTable, m_veboxDnHVSTables);
2655 }
2656
2657 if (caps.b1K1DLutInUse)
2658 {
2659 // Insert DV 1Dlut surface
2660 surfGroup.emplace(SurfaceType1k1dLut, m_vebox1DLookUpTables);
2661 }
2662
2663 if (caps.enableSFCLinearOutputByTileConvert)
2664 {
2665 surfGroup.emplace(SurfaceTypeInnerTileConvertInput, m_innerTileConvertInput);
2666 }
2667
2668 // Update previous Dn output flag for next frame to use.
2669 if (surfGroup.find(SurfaceTypeDNOutput) != surfGroup.end() || m_sameSamples && m_pastDnOutputValid)
2670 {
2671 m_pastDnOutputValid = true;
2672 }
2673 else
2674 {
2675 m_pastDnOutputValid = false;
2676 }
2677
2678 return MOS_STATUS_SUCCESS;
2679 }
2680
2681 bool VpResourceManager::IsOutputSurfaceNeeded(VP_EXECUTE_CAPS caps)
2682 {
2683 VP_FUNC_CALL();
2684
2685 // check whether intermedia surface needed to create based on caps
2686 if (caps.bDnKernelUpdate || // State Heap as putput, but it was not tracked in resource manager yet
2687 caps.bVeboxSecureCopy) // State Heap as putput, but it was not tracked in resource manager yet
2688 {
2689 return false;
2690 }
2691 else
2692 {
2693 return true;
2694 }
2695 }
2696
2697 VP_SURFACE* VpResourceManager::GetVeboxOutputSurface(VP_EXECUTE_CAPS& caps, VP_SURFACE *outputSurface)
2698 {
2699 VP_FUNC_CALL();
2700
2701 bool enableVeboxOutputSurf = false;
2702 if (m_vpUserFeatureControl)
2703 {
2704 enableVeboxOutputSurf = m_vpUserFeatureControl->IsVeboxOutputSurfEnabled();
2705 }
2706
2707 if (caps.bRender)
2708 {
2709 // Place Holder when enable DI
2710 return nullptr;
2711 }
2712
2713 if (!caps.bSFC) // Vebox output directlly to output surface
2714 {
2715 // RenderTarget will be assigned in VpVeboxCmdPacket::GetSurface.
2716 return outputSurface;
2717 }
2718 else if (caps.bDI && caps.bVebox) // Vebox DI enable
2719 {
2720 // Place Holder when enable DI
2721 return nullptr;
2722 }
2723 else if (caps.bIECP) // SFC + IECP enabled, output to internal surface
2724 {
2725 return m_veboxOutput[m_currentDnOutput];
2726 }
2727 else if (enableVeboxOutputSurf || caps.bDN) // SFC + DN case
2728 {
2729 // DN + SFC scenario needs IECP implicitly, which need vebox output surface being assigned.
2730 // Use m_currentDnOutput to ensure m_veboxOutput surface paired with DN output surface.
2731 return m_veboxOutput[m_currentDnOutput];
2732 }
2733 else
2734 {
2735 // Write to SFC cases, Vebox output is not needed.
2736 VP_PUBLIC_NORMALMESSAGE("No need output for Vebox output");
2737 return nullptr;
2738 }
2739 }
2740
2741 MOS_STATUS VpResourceManager::InitVeboxSpatialAttributesConfiguration()
2742 {
2743 VP_FUNC_CALL();
2744
2745 VP_PUBLIC_CHK_NULL_RETURN(m_veboxDNSpatialConfigSurface);
2746 VP_PUBLIC_CHK_NULL_RETURN(m_veboxDNSpatialConfigSurface->osSurface);
2747
2748 uint8_t* data = (uint8_t*)& g_cInit_VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATIONS;
2749 return m_allocator.Write1DSurface(m_veboxDNSpatialConfigSurface, data,
2750 (uint32_t)sizeof(VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATION));
2751 }
2752
2753 bool VpResourceManager::VeboxOutputNeeded(VP_EXECUTE_CAPS& caps)
2754 {
2755 VP_FUNC_CALL();
2756 bool enableVeboxOutputSurf = false;
2757 if (m_vpUserFeatureControl)
2758 {
2759 enableVeboxOutputSurf = m_vpUserFeatureControl->IsVeboxOutputSurfEnabled();
2760 }
2761
2762 // If DN and/or Hotpixel are the only functions enabled then the only output is the Denoised Output
2763 // and no need vebox output.
2764 // For any other vebox features being enabled, vebox output surface is needed.
2765 if (enableVeboxOutputSurf ||
2766 caps.bDI ||
2767 caps.bQueryVariance ||
2768 caps.bDiProcess2ndField ||
2769 caps.bIECP ||
2770 caps.bCappipe ||
2771 (caps.bDN && caps.bSFC)) // DN + SFC needs IECP implicitly and outputs to DI surface
2772 {
2773 return true;
2774 }
2775 else
2776 {
2777 return false;
2778 }
2779 }
2780
2781 bool VpResourceManager::VeboxDenoiseOutputNeeded(VP_EXECUTE_CAPS& caps)
2782 {
2783 VP_FUNC_CALL();
2784
2785 return caps.bDN;
2786 }
2787
2788 bool VpResourceManager::VeboxHdr3DlutNeeded(VP_EXECUTE_CAPS &caps)
2789 {
2790 VP_FUNC_CALL();
2791
2792 return caps.bHDR3DLUT;
2793 }
2794
2795 bool VpResourceManager::Vebox1DlutNeeded(VP_EXECUTE_CAPS &caps)
2796 {
2797 VP_FUNC_CALL();
2798
2799 return caps.bDV;
2800 }
2801
2802 // In some case, STMM should not be destroyed even when not being used by current workload to maintain data,
2803 // e.g. DI second field case.
2804 // If queryAssignment == true, query whether STMM needed by current workload.
2805 // If queryAssignment == false, query whether STMM needed to be allocated.
2806 bool VpResourceManager::VeboxSTMMNeeded(VP_EXECUTE_CAPS& caps, bool queryAssignment)
2807 {
2808 VP_FUNC_CALL();
2809
2810 if (queryAssignment)
2811 {
2812 return caps.bDI || caps.bDN;
2813 }
2814 else
2815 {
2816 return caps.bDI || caps.bDiProcess2ndField || caps.bDN;
2817 }
2818 }
2819
2820 MOS_STATUS VpResourceManager::ReAllocateVeboxStatisticsSurface(VP_SURFACE *&statisticsSurface, VP_EXECUTE_CAPS &caps, VP_SURFACE *inputSurface, uint32_t dwWidth, uint32_t dwHeight)
2821 {
2822 VP_FUNC_CALL();
2823
2824 bool bAllocated = false;
2825 Mos_MemPool memTypeHistStat = GetHistStatMemType(caps);
2826 //Statistics surface can be not lockable, if secure mode is enabled
2827 bool isStatisticsBufNotLockable = caps.bSecureVebox;
2828 uint8_t InitValue = 0;
2829
2830 // change the init value when null hw is enabled
2831 if (m_osInterface.bNullHwIsEnabled)
2832 {
2833 InitValue = 0x80;
2834 }
2835
2836 VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
2837 statisticsSurface,
2838 "m_veboxStatisticsSurface",
2839 Format_Buffer,
2840 MOS_GFXRES_BUFFER,
2841 MOS_TILE_LINEAR,
2842 dwWidth,
2843 dwHeight,
2844 false,
2845 MOS_MMC_DISABLED,
2846 bAllocated,
2847 false,
2848 IsDeferredResourceDestroyNeeded(),
2849 MOS_HW_RESOURCE_USAGE_VP_INTERNAL_WRITE_FF,
2850 MOS_TILE_UNSET_GMM,
2851 memTypeHistStat,
2852 isStatisticsBufNotLockable));
2853
2854 if (bAllocated)
2855 {
2856 if (caps.bSecureVebox)
2857 {
2858 VP_PUBLIC_CHK_STATUS_RETURN(FillLinearBufferWithEncZero(statisticsSurface, dwWidth, dwHeight));
2859 }
2860 }
2861
2862 m_dwVeboxPerBlockStatisticsWidth = dwWidth;
2863 m_dwVeboxPerBlockStatisticsHeight = MOS_ROUNDUP_DIVIDE(inputSurface->osSurface->dwHeight, 4);
2864
2865 return MOS_STATUS_SUCCESS;
2866 }
2867
2868 MOS_STATUS VpResourceManager::AssignHdrResource(VP_EXECUTE_CAPS &caps, std::vector<VP_SURFACE *> &inputSurfaces, VP_SURFACE *outputSurface, RESOURCE_ASSIGNMENT_HINT resHint, VP_SURFACE_SETTING &surfSetting, SwFilterPipe &executedFilters)
2869 {
2870 VP_FUNC_CALL();
2871
2872 if (m_hdrResourceManager == nullptr)
2873 {
2874 m_hdrResourceManager = MOS_New(VphdrResourceManager, m_allocator);
2875 }
2876
2877 VP_PUBLIC_CHK_STATUS_RETURN(m_hdrResourceManager->AssignRenderResource(caps, inputSurfaces, outputSurface, resHint, surfSetting, executedFilters, m_osInterface, m_reporting, IsDeferredResourceDestroyNeeded()));
2878
2879 return MOS_STATUS_SUCCESS;
2880 }
2881
2882 MOS_STATUS VpResourceManager::EmplaceCrossPipeContextResource(PVP_SURFACE surface, PVP_SURFACE originSurface)
2883 {
2884 if (originSurface)
2885 {
2886 m_crossPipeContextSurfaces.erase(originSurface);
2887 }
2888 m_crossPipeContextSurfaces.insert(surface);
2889 return MOS_STATUS_SUCCESS;
2890 }
2891 };