-
Notifications
You must be signed in to change notification settings - Fork 351
/
Copy pathvp_resource_manager.cpp
2580 lines (2252 loc) · 93.7 KB
/
vp_resource_manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2018-2024, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file vp_resource_manager.cpp
//! \brief The source file of the base class of vp resource manager
//! \details all the vp resources will be traced here for usages using intermeida
//! surfaces.
//!
#include "vp_resource_manager.h"
#include "vp_vebox_cmd_packet.h"
#include "sw_filter_pipe.h"
#include "vp_utils.h"
#include "vp_platform_interface.h"
using namespace std;
namespace vp
{
#define VP_SAME_SAMPLE_THRESHOLD 0
#define VP_COMP_CMFC_COEFF_WIDTH 64
#define VP_COMP_CMFC_COEFF_HEIGHT 8
inline bool IsInterleaveFirstField(VPHAL_SAMPLE_TYPE sampleType)
{
VP_FUNC_CALL();
return ((sampleType == SAMPLE_INTERLEAVED_ODD_FIRST_BOTTOM_FIELD) ||
(sampleType == SAMPLE_INTERLEAVED_EVEN_FIRST_TOP_FIELD) ||
(sampleType == SAMPLE_SINGLE_TOP_FIELD));
}
extern const VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATION g_cInit_VEBOX_SPATIAL_ATTRIBUTES_CONFIGURATIONS =
{
// DWORD 0
{
{NOISE_BLF_RANGE_THRESHOLD_S0_DEFAULT}, // RangeThrStart0
},
// DWORD 1
{
{NOISE_BLF_RANGE_THRESHOLD_S1_DEFAULT}, // RangeThrStart1
},
// DWORD 2
{
{NOISE_BLF_RANGE_THRESHOLD_S2_DEFAULT}, // RangeThrStart2
},
// DWORD 3
{
{NOISE_BLF_RANGE_THRESHOLD_S3_DEFAULT}, // RangeThrStart3
},
// DWORD 4
{
{NOISE_BLF_RANGE_THRESHOLD_S4_DEFAULT}, // RangeThrStart4
},
// DWORD 5
{
{NOISE_BLF_RANGE_THRESHOLD_S5_DEFAULT}, // RangeThrStart5
},
// DWORD 6
{
{0}, // Reserved
},
// DWORD 7
{
{0}, // Reserved
},
// DWORD 8
{
{NOISE_BLF_RANGE_WGTS0_DEFAULT}, // RangeWgt0
},
// DWORD 9
{
{NOISE_BLF_RANGE_WGTS1_DEFAULT}, // RangeWgt1
},
// DWORD 10
{
{NOISE_BLF_RANGE_WGTS2_DEFAULT}, // RangeWgt2
},
// DWORD 11
{
{NOISE_BLF_RANGE_WGTS3_DEFAULT}, // RangeWgt3
},
// DWORD 12
{
{NOISE_BLF_RANGE_WGTS4_DEFAULT}, // RangeWgt4
},
// DWORD 13
{
{NOISE_BLF_RANGE_WGTS5_DEFAULT}, // RangeWgt5
},
// DWORD 14
{
{0}, // Reserved
},
// DWORD 15
{
{0}, // Reserved
},
// DWORD 16 - 41: DistWgt[5][5]
{
{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},
{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},
{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},
{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},
{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},
},
// Padding
{
0, // Padding
0, // Padding
0, // Padding
0, // Padding
0, // Padding
0, // Padding
0, // Padding
}
};
VpResourceManager::VpResourceManager(MOS_INTERFACE &osInterface, VpAllocator &allocator, VphalFeatureReport &reporting, vp::VpPlatformInterface &vpPlatformInterface, MediaCopyWrapper *mediaCopyWrapper, vp::VpUserFeatureControl *vpUserFeatureControl)
: m_osInterface(osInterface), m_allocator(allocator), m_reporting(reporting), m_vpPlatformInterface(vpPlatformInterface), m_mediaCopyWrapper(mediaCopyWrapper)
{
InitSurfaceConfigMap();
m_userSettingPtr = m_osInterface.pfnGetUserSettingInstance(&m_osInterface);
m_vpUserFeatureControl = vpUserFeatureControl;
}
VpResourceManager::~VpResourceManager()
{
// Clean all intermedia Resource
DestoryVeboxOutputSurface();
DestoryVeboxDenoiseOutputSurface();
for (uint32_t i = 0; i < VP_NUM_STMM_SURFACES; i++)
{
if (m_veboxSTMMSurface[i])
{
m_allocator.DestroyVpSurface(m_veboxSTMMSurface[i]);
}
}
if (m_veboxStatisticsSurface)
{
m_allocator.DestroyVpSurface(m_veboxStatisticsSurface);
}
if (m_veboxStatisticsSurfacefor1stPassofSfc2Pass)
{
m_allocator.DestroyVpSurface(m_veboxStatisticsSurfacefor1stPassofSfc2Pass);
}
if (m_veboxRgbHistogram)
{
m_allocator.DestroyVpSurface(m_veboxRgbHistogram);
}
if (m_veboxDNTempSurface)
{
m_allocator.DestroyVpSurface(m_veboxDNTempSurface);
}
if (m_veboxDNSpatialConfigSurface)
{
m_allocator.DestroyVpSurface(m_veboxDNSpatialConfigSurface);
}
if (m_vebox3DLookUpTables)
{
m_allocator.DestroyVpSurface(m_vebox3DLookUpTables);
}
if (m_vebox3DLookUpTables2D)
{
m_allocator.DestroyVpSurface(m_vebox3DLookUpTables2D);
}
if (m_3DLutKernelCoefSurface)
{
m_allocator.DestroyVpSurface(m_3DLutKernelCoefSurface);
}
if (m_veboxDnHVSTables)
{
m_allocator.DestroyVpSurface(m_veboxDnHVSTables);
}
if (m_vebox1DLookUpTables)
{
m_allocator.DestroyVpSurface(m_vebox1DLookUpTables);
}
if (m_innerTileConvertInput)
{
m_allocator.DestroyVpSurface(m_innerTileConvertInput);
}
if (m_temperalInput)
{
m_allocator.DestroyVpSurface(m_temperalInput);
}
if (m_hdrResourceManager)
{
MOS_Delete(m_hdrResourceManager);
}
while (!m_intermediaSurfaces.empty())
{
VP_SURFACE * surf = m_intermediaSurfaces.back();
m_allocator.DestroyVpSurface(surf);
m_intermediaSurfaces.pop_back();
}
for (int i = 0; i < VP_NUM_FC_INTERMEDIA_SURFACES; ++i)
{
m_allocator.DestroyVpSurface(m_fcIntermediateSurface[i]);
}
m_allocator.DestroyVpSurface(m_cmfcCoeff);
m_allocator.DestroyVpSurface(m_decompressionSyncSurface);
for (int i = 0; i < VP_COMP_MAX_LAYERS; ++i)
{
if (m_fcIntermediaSurfaceInput[i])
{
m_allocator.DestroyVpSurface(m_fcIntermediaSurfaceInput[i]);
}
}
if (m_fcIntermediaSurfaceOutput)
{
m_allocator.DestroyVpSurface(m_fcIntermediaSurfaceOutput);
}
m_allocator.CleanRecycler();
}
void VpResourceManager::CleanTempSurfaces()
{
VP_FUNC_CALL();
while (!m_tempSurface.empty())
{
auto it = m_tempSurface.begin();
m_allocator.DestroyVpSurface(it->second);
m_tempSurface.erase(it);
}
}
MOS_STATUS VpResourceManager::OnNewFrameProcessStart(SwFilterPipe &pipe)
{
VP_FUNC_CALL();
MT_LOG1(MT_VP_HAL_ONNEWFRAME_PROC_START, MT_NORMAL, MT_FUNC_START, 1);
VP_SURFACE *inputSurface = pipe.GetSurface(true, 0);
VP_SURFACE *outputSurface = pipe.GetSurface(false, 0);
SwFilter *diFilter = pipe.GetSwFilter(true, 0, FeatureTypeDi);
if (nullptr == inputSurface && nullptr == outputSurface)
{
VP_PUBLIC_ASSERTMESSAGE("Both input and output surface being nullptr!");
VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
}
if (0 != m_currentPipeIndex)
{
VP_PUBLIC_ASSERTMESSAGE("m_currentPipeIndex(%d) is not 0. May caused by OnNewFrameProcessEnd not paired with OnNewFrameProcessStart!");
VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
}
VP_SURFACE *pastSurface = pipe.GetPastSurface(0);
VP_SURFACE *futureSurface = pipe.GetFutureSurface(0);
int32_t currentFrameId = inputSurface ? inputSurface->FrameID : outputSurface->FrameID;
int32_t pastFrameId = pastSurface ? pastSurface->FrameID : 0;
int32_t futureFrameId = futureSurface ? futureSurface->FrameID : 0;
m_currentFrameIds.valid = true;
m_currentFrameIds.diEnabled = nullptr != diFilter;
m_currentFrameIds.currentFrameId = currentFrameId;
m_currentFrameIds.pastFrameId = pastFrameId;
m_currentFrameIds.futureFrameId = futureFrameId;
m_currentFrameIds.pastFrameAvailable = pastSurface ? true : false;
m_currentFrameIds.futureFrameAvailable = futureSurface ? true : false;
// Only set sameSamples flag DI enabled frames.
if (m_pastFrameIds.valid && m_currentFrameIds.pastFrameAvailable &&
m_pastFrameIds.diEnabled && m_currentFrameIds.diEnabled && m_isPastFrameVeboxDiUsed)
{
m_sameSamples =
WITHIN_BOUNDS(
m_currentFrameIds.currentFrameId - m_pastFrameIds.currentFrameId,
-VP_SAME_SAMPLE_THRESHOLD,
VP_SAME_SAMPLE_THRESHOLD) &&
WITHIN_BOUNDS(
m_currentFrameIds.pastFrameId - m_pastFrameIds.pastFrameId,
-VP_SAME_SAMPLE_THRESHOLD,
VP_SAME_SAMPLE_THRESHOLD);
if (m_sameSamples)
{
m_outOfBound = false;
}
else
{
m_outOfBound =
OUT_OF_BOUNDS(
m_currentFrameIds.pastFrameId - m_pastFrameIds.currentFrameId,
-VP_SAME_SAMPLE_THRESHOLD,
VP_SAME_SAMPLE_THRESHOLD);
}
}
// bSameSamples flag also needs to be set for no reference case
else if (m_pastFrameIds.valid && !m_currentFrameIds.pastFrameAvailable &&
m_pastFrameIds.diEnabled && m_currentFrameIds.diEnabled && m_isPastFrameVeboxDiUsed)
{
m_sameSamples =
WITHIN_BOUNDS(
m_currentFrameIds.currentFrameId - m_pastFrameIds.currentFrameId,
-VP_SAME_SAMPLE_THRESHOLD,
VP_SAME_SAMPLE_THRESHOLD);
m_outOfBound = false;
}
else
{
m_sameSamples = false;
m_outOfBound = false;
}
if (inputSurface)
{
m_maxSrcRect.right = MOS_MAX(m_maxSrcRect.right, inputSurface->rcSrc.right);
m_maxSrcRect.bottom = MOS_MAX(m_maxSrcRect.bottom, inputSurface->rcSrc.bottom);
}
// Swap buffers for next iteration
if (!m_sameSamples)
{
m_currentDnOutput = (m_currentDnOutput + 1) & 1;
m_currentStmmIndex = (m_currentStmmIndex + 1) & 1;
}
m_pastFrameIds = m_currentFrameIds;
m_isFcIntermediateSurfacePrepared = false;
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::GetFormatForFcIntermediaSurface(MOS_FORMAT& format,
MEDIA_CSPACE &colorSpace, SwFilterPipe &featurePipe)
{
VP_FUNC_CALL();
PVP_SURFACE target = nullptr;
int32_t surfCount = (int32_t)featurePipe.GetSurfaceCount(true);
PVP_SURFACE src = nullptr;
int32_t i = 0, j = 0;
int32_t csc_count = 0;
int32_t csc_min = surfCount + 1;
int32_t cspace_in_use[CSpace_Count] = {};
bool bYUVTarget = false;
MEDIA_CSPACE cs = CSpace_Any;
MEDIA_CSPACE tempColorSpace = CSpace_Any;
MEDIA_CSPACE mainColorSpace = CSpace_None;
auto PostProcess = [&](MOS_STATUS status)
{
VP_PUBLIC_NORMALMESSAGE("Main_ColorSpace %d, Temp_ColorSpace %d, csc_count %d.",
mainColorSpace, tempColorSpace, csc_count);
colorSpace = tempColorSpace;
// Set AYUV or ARGB output depending on intermediate cspace
if (KernelDll_IsCspace(colorSpace, CSpace_RGB))
{
format = Format_A8R8G8B8;
}
else
{
format = Format_AYUV;
}
return status;
};
// Check if target is YUV
target = featurePipe.GetSurface(false, 0);
VP_PUBLIC_CHK_NULL_RETURN(target);
VP_PUBLIC_CHK_NULL_RETURN(target->osSurface);
bYUVTarget = IS_RGB_FORMAT(target->osSurface->Format) ? false : true;
// Gets primary video cspace
// Implements xvYCC passthrough mode
// Set Color Spaces in use
MOS_ZeroMemory(cspace_in_use, sizeof(cspace_in_use));
for (i = 0; i < surfCount; i++)
{
// Get current source
src = featurePipe.GetSurface(true, i);
VP_PUBLIC_CHK_NULL_RETURN(src);
VP_PUBLIC_CHK_NULL_RETURN(src->osSurface);
// Save Main Video color space
if (src->SurfType == SURF_IN_PRIMARY &&
mainColorSpace == CSpace_None)
{
mainColorSpace = src->ColorSpace;
}
// Set xvYCC pass through mode
if (bYUVTarget &&
(src->ColorSpace == CSpace_xvYCC709 ||
src->ColorSpace == CSpace_xvYCC601))
{
tempColorSpace = src->ColorSpace;
return PostProcess(MOS_STATUS_SUCCESS);
}
// Don't take PAL formats into consideration
if ((!IS_PAL_FORMAT(src->osSurface->Format)) &&
src->ColorSpace > CSpace_Any &&
src->ColorSpace < CSpace_Count)
{
cs = KernelDll_TranslateCspace(src->ColorSpace);
if (cs >= CSpace_Any)
{
cspace_in_use[cs]++;
}
}
}
// For every CS in use, iterate through source CS and keep a
// count of number of CSC operation needed. Determine the Temporary
// color space as the one requiring min. # of CSC ops.
for (j = (CSpace_Any + 1); j < CSpace_Count; j++)
{
// Skip color spaces not in use
if (!cspace_in_use[j])
{
continue;
}
// Count # of CS conversions
cs = (MEDIA_CSPACE) j;
csc_count = 0;
for (i = 0; i < surfCount; i++)
{
// Get current source
src = featurePipe.GetSurface(true, i);
VP_PUBLIC_CHK_NULL_RETURN(src);
VP_PUBLIC_CHK_NULL_RETURN(src->osSurface);
auto featureSubPipe = featurePipe.GetSwFilterSubPipe(true, i);
VP_PUBLIC_CHK_NULL_RETURN(featureSubPipe);
// Ignore palletized layers
if (IS_PAL_FORMAT(src->osSurface->Format) ||
src->ColorSpace == CSpace_Any)
{
continue;
}
auto procamp = dynamic_cast<SwFilterProcamp *>(featureSubPipe->GetSwFilter(FeatureTypeProcamp));
// Check if CSC/PA is required
if (KernelDll_TranslateCspace(src->ColorSpace) != cs ||
(procamp &&
procamp->GetSwFilterParams().procampParams &&
procamp->GetSwFilterParams().procampParams->bEnabled))
{
csc_count++;
}
}
// Save best choice as requiring minimum number of CSC operations
// Use main cspace as default if same CSC count
if ((csc_count < csc_min) ||
(csc_count == csc_min && cs == mainColorSpace))
{
tempColorSpace = cs;
csc_min = csc_count;
}
}
// If all layers are palletized, use the CS from first layer (as good as any other)
if (tempColorSpace == CSpace_Any && surfCount > 0)
{
src = featurePipe.GetSurface(true, 0);
VP_PUBLIC_CHK_NULL_RETURN(src);
tempColorSpace = src->ColorSpace;
}
return PostProcess(MOS_STATUS_SUCCESS);
}
MOS_STATUS VpResourceManager::PrepareFcIntermediateSurface(SwFilterPipe &featurePipe)
{
VP_FUNC_CALL();
if (m_isFcIntermediateSurfacePrepared)
{
return MOS_STATUS_SUCCESS;
}
m_isFcIntermediateSurfacePrepared = true;
MOS_FORMAT format = Format_Any;
MEDIA_CSPACE colorSpace = CSpace_Any;
VP_PUBLIC_CHK_STATUS_RETURN(GetFormatForFcIntermediaSurface(format, colorSpace, featurePipe));
auto target = featurePipe.GetSurface(false, 0);
VP_PUBLIC_CHK_NULL_RETURN(target);
VP_PUBLIC_CHK_NULL_RETURN(target->osSurface);
uint32_t tempWidth = target->osSurface->dwWidth;
uint32_t tempHeight = target->osSurface->dwHeight;
uint32_t curWidth = 0;
uint32_t curHeight = 0;
if (m_fcIntermediateSurface[0])
{
VP_PUBLIC_CHK_NULL_RETURN(m_fcIntermediateSurface[0]->osSurface);
curWidth = m_fcIntermediateSurface[0]->osSurface->dwWidth;
curHeight = m_fcIntermediateSurface[0]->osSurface->dwHeight;
}
// Allocate buffer in fixed increments
tempWidth = MOS_ALIGN_CEIL(tempWidth , VPHAL_BUFFER_SIZE_INCREMENT);
tempHeight = MOS_ALIGN_CEIL(tempHeight, VPHAL_BUFFER_SIZE_INCREMENT);
for (int i = 0; i < VP_NUM_FC_INTERMEDIA_SURFACES; ++i)
{
if (tempWidth > curWidth || tempHeight > curHeight)
{
bool allocated = false;
// Get surface parameter.
// Use A8R8G8B8 instead of real surface format to ensure the surface can be reused for both AYUV and A8R8G8B8,
// since for A8R8G8B8, tile64 is used, while for AYUV, both tile4 and tile64 is ok.
if (m_fcIntermediateSurface[i] && m_fcIntermediateSurface[i]->osSurface)
{
m_fcIntermediateSurface[i]->osSurface->Format = Format_A8R8G8B8;
}
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
m_fcIntermediateSurface[i],
"fcIntermediaSurface",
Format_A8R8G8B8,
MOS_GFXRES_2D,
MOS_TILE_Y,
tempWidth,
tempHeight,
false,
MOS_MMC_DISABLED,
allocated,
false,
IsDeferredResourceDestroyNeeded(),
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER,
MOS_TILE_UNSET_GMM,
MOS_MEMPOOL_DEVICEMEMORY,
true));
m_fcIntermediateSurface[i]->osSurface->Format = format;
m_fcIntermediateSurface[i]->ColorSpace = colorSpace;
}
else
{
m_fcIntermediateSurface[i]->osSurface->dwWidth = tempWidth;
m_fcIntermediateSurface[i]->osSurface->dwHeight = tempHeight;
m_fcIntermediateSurface[i]->osSurface->Format = format;
m_fcIntermediateSurface[i]->ColorSpace = colorSpace;
}
m_fcIntermediateSurface[i]->rcSrc = target->rcSrc;
m_fcIntermediateSurface[i]->rcDst = target->rcDst;
}
return MOS_STATUS_SUCCESS;
}
void VpResourceManager::OnNewFrameProcessEnd()
{
VP_FUNC_CALL();
MT_LOG1(MT_VP_HAL_ONNEWFRAME_PROC_END, MT_NORMAL, MT_FUNC_END, 1);
m_allocator.CleanRecycler();
m_currentPipeIndex = 0;
CleanTempSurfaces();
}
void VpResourceManager::InitSurfaceConfigMap()
{
VP_FUNC_CALL();
///* _b64DI
// | _sfcEnable
// | | _sameSample
// | | | _outOfBound
// | | | | _pastRefAvailable
// | | | | | _futureRefAvailable
// | | | | | | _firstDiField
// | | | | | | | _currentInputSurface
// | | | | | | | | _pastInputSurface
// | | | | | | | | | _currentOutputSurface
// | | | | | | | | | | _pastOutputSurface*/
// | | | | | | | | | | | */
// sfc Enable
AddSurfaceConfig(true, true, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(true, true, true, false, true, false, false, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, true, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, true, false, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, true, false, false, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(true, true, true, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, true, true, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, true, true, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
// outOfBound
AddSurfaceConfig(true, true, false, true, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(true, true, false, true, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
// sfc disable
AddSurfaceConfig(true, false, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_OUTPUT);
AddSurfaceConfig(true, false, true, false, true, false, false, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, false, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, false, false, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, false, false, false, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(true, false, true, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
AddSurfaceConfig(true, false, true, false, false, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
//30i -> 30p sfc Enable
AddSurfaceConfig(false, true, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_NULL);
AddSurfaceConfig(false, true, false, false, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(false, true, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(false, true, false, true, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
AddSurfaceConfig(false, true, false, true, true, false, false, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_PAST_REF, VEBOX_SURFACE_FRAME1, VEBOX_SURFACE_FRAME0);
//30i -> 30p sfc disable
AddSurfaceConfig(false, false, false, false, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
AddSurfaceConfig(false, false, false, true, true, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
AddSurfaceConfig(false, false, false, false, false, false, true, VEBOX_SURFACE_INPUT, VEBOX_SURFACE_NULL, VEBOX_SURFACE_OUTPUT, VEBOX_SURFACE_NULL);
}
uint32_t VpResourceManager::GetHistogramSurfaceSize(VP_EXECUTE_CAPS& caps, uint32_t inputWidth, uint32_t inputHeight)
{
VP_FUNC_CALL();
// Allocate Rgb Histogram surface----------------------------------------------
// Size of RGB histograms, 1 set for each slice. For single slice, other set will be 0
uint32_t dwSize = VP_VEBOX_RGB_HISTOGRAM_SIZE;
dwSize += VP_VEBOX_RGB_ACE_HISTOGRAM_SIZE_RESERVED;
// Size of ACE histograms, 1 set for each slice. For single slice, other set will be 0
dwSize += VP_VEBOX_ACE_HISTOGRAM_SIZE_PER_FRAME_PER_SLICE * // Ace histogram size per slice
VP_NUM_FRAME_PREVIOUS_CURRENT * // Ace for Prev + Curr
VP_VEBOX_HISTOGRAM_SLICES_COUNT; // Total number of slices
return dwSize;
}
MOS_STATUS VpResourceManager::GetResourceHint(std::vector<FeatureType> &featurePool, SwFilterPipe& executedFilters, RESOURCE_ASSIGNMENT_HINT &hint)
{
VP_FUNC_CALL();
uint32_t index = 0;
SwFilterSubPipe *inputPipe = executedFilters.GetSwFilterSubPipe(true, index);
// only process Primary surface
if (inputPipe == nullptr)
{
VP_PUBLIC_NORMALMESSAGE("No inputPipe, so there is no hint message!");
return MOS_STATUS_SUCCESS;
}
for (auto filterID : featurePool)
{
SwFilter* feature = (SwFilter*)inputPipe->GetSwFilter(FeatureType(filterID));
if (feature)
{
VP_PUBLIC_CHK_STATUS_RETURN(feature->SetResourceAssignmentHint(hint));
}
}
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::GetIntermediaColorAndFormat3DLutOutput(VPHAL_CSPACE &colorSpace, MOS_FORMAT &format, SwFilterPipe &executedFilters)
{
SwFilterHdr *hdr = dynamic_cast<SwFilterHdr *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeHdr));
if (hdr)
{
colorSpace = hdr->GetSwFilterParams().dstColorSpace;
format = hdr->GetSwFilterParams().formatOutput;
}
else
{ // caps.b3DlutOutput =1, in hdr tests hdr flag should not be false.
VP_PUBLIC_ASSERTMESSAGE("It is unexcepted for HDR case with caps.b3DlutOutput as true, return INVALID_PARAMETER");
VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
}
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::GetIntermediaColorAndFormatBT2020toRGB(VP_EXECUTE_CAPS &caps, VPHAL_CSPACE &colorSpace, MOS_FORMAT &format, SwFilterPipe &executedFilters)
{
SwFilterCsc *cscOnSfc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnSfc));
SwFilterCgc *cgc = dynamic_cast<SwFilterCgc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCgc));
if (caps.bSFC && nullptr == cscOnSfc)
{
VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
}
if (cscOnSfc)
{
colorSpace = cscOnSfc->GetSwFilterParams().output.colorSpace;
format = cscOnSfc->GetSwFilterParams().formatOutput;
}
else
{
VP_PUBLIC_CHK_NULL_RETURN(cgc);
colorSpace = cgc->GetSwFilterParams().dstColorSpace;
format = cgc->GetSwFilterParams().formatOutput;
}
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::GetIntermediaOutputSurfaceColorAndFormat(VP_EXECUTE_CAPS &caps, SwFilterPipe &executedFilters, MOS_FORMAT &format, VPHAL_CSPACE &colorSpace)
{
VP_SURFACE *inputSurface = executedFilters.GetSurface(true, 0);
VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
if (caps.bRender)
{
SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnRender));
if (csc)
{
format = csc->GetSwFilterParams().formatOutput;
colorSpace = csc->GetSwFilterParams().output.colorSpace;
return MOS_STATUS_SUCCESS;
}
}
else if (caps.bSFC)
{
SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnSfc));
if (csc)
{
format = csc->GetSwFilterParams().formatOutput;
colorSpace = csc->GetSwFilterParams().output.colorSpace;
return MOS_STATUS_SUCCESS;
}
}
else if (caps.b3DlutOutput)
{
VP_PUBLIC_CHK_STATUS_RETURN(GetIntermediaColorAndFormat3DLutOutput(colorSpace, format, executedFilters));
return MOS_STATUS_SUCCESS;
}
else if (caps.bBt2020ToRGB)
{
VP_PUBLIC_CHK_STATUS_RETURN(GetIntermediaColorAndFormatBT2020toRGB(caps, colorSpace, format, executedFilters));
return MOS_STATUS_SUCCESS;
}
else if (caps.bVebox)
{
SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeCscOnVebox));
if (csc)
{
format = csc->GetSwFilterParams().formatOutput;
colorSpace = csc->GetSwFilterParams().output.colorSpace;
return MOS_STATUS_SUCCESS;
}
}
format = inputSurface->osSurface->Format;
colorSpace = inputSurface->ColorSpace;
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::GetIntermediaOutputSurfaceParams(VP_EXECUTE_CAPS& caps, VP_SURFACE_PARAMS ¶ms, SwFilterPipe &executedFilters)
{
VP_FUNC_CALL();
SwFilterScaling *scaling = dynamic_cast<SwFilterScaling *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeScaling));
SwFilterRotMir *rotMir = dynamic_cast<SwFilterRotMir *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeRotMir));
SwFilterDeinterlace *di = dynamic_cast<SwFilterDeinterlace *>(executedFilters.GetSwFilter(true, 0, FeatureType::FeatureTypeDi));
VP_SURFACE *inputSurface = executedFilters.GetSurface(true, 0);
VP_PUBLIC_CHK_NULL_RETURN(inputSurface);
if (scaling)
{
params.width = scaling->GetSwFilterParams().output.dwWidth;
params.height = scaling->GetSwFilterParams().output.dwHeight;
params.sampleType = scaling->GetSwFilterParams().output.sampleType;
params.rcSrc = scaling->GetSwFilterParams().output.rcSrc;
params.rcDst = scaling->GetSwFilterParams().output.rcDst;
params.rcMaxSrc = scaling->GetSwFilterParams().output.rcMaxSrc;
if (scaling->GetSwFilterParams().interlacedScalingType == ISCALING_INTERLEAVED_TO_FIELD)
{
params.height = scaling->GetSwFilterParams().output.dwHeight / 2;
params.rcDst.bottom = params.rcDst.bottom / 2;
params.rcMaxSrc.bottom = params.rcMaxSrc.bottom / 2;
}
}
else
{
params.width = inputSurface->osSurface->dwWidth;
params.height = inputSurface->osSurface->dwHeight;
params.sampleType = di ? SAMPLE_PROGRESSIVE : inputSurface->SampleType;
params.rcSrc = inputSurface->rcSrc;
params.rcDst = inputSurface->rcDst;
params.rcMaxSrc = inputSurface->rcMaxSrc;
}
// Do not use rotatoin flag in scaling swfilter as it has not been initialized here.
// It will be initialized during pipe update after resource being assigned.
if (rotMir &&
(rotMir->GetSwFilterParams().rotation == VPHAL_ROTATION_90 ||
rotMir->GetSwFilterParams().rotation == VPHAL_ROTATION_270 ||
rotMir->GetSwFilterParams().rotation == VPHAL_ROTATE_90_MIRROR_VERTICAL ||
rotMir->GetSwFilterParams().rotation == VPHAL_ROTATE_90_MIRROR_HORIZONTAL))
{
swap(params.width, params.height);
RECT tmp = params.rcSrc;
RECT_ROTATE(params.rcSrc, tmp);
tmp = params.rcDst;
RECT_ROTATE(params.rcDst, tmp);
tmp = params.rcMaxSrc;
RECT_ROTATE(params.rcMaxSrc, tmp);
}
VP_PUBLIC_CHK_STATUS_RETURN(GetIntermediaOutputSurfaceColorAndFormat(caps, executedFilters, params.format, params.colorSpace));
params.tileType = MOS_TILE_Y;
if (SAMPLE_PROGRESSIVE == params.sampleType)
{
params.surfCompressionMode = caps.bRender ? MOS_MMC_RC : MOS_MMC_MC;
params.surfCompressible = true;
}
else
{
// MMC does not support interleaved surface.
VP_PUBLIC_NORMALMESSAGE("Disable MMC for interleaved intermedia surface, sampleType = %d.", params.sampleType);
params.surfCompressionMode = MOS_MMC_DISABLED;
params.surfCompressible = false;
}
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::GetFcIntermediateSurfaceForOutput(VP_SURFACE *&intermediaSurface, SwFilterPipe &executedFilters)
{
VP_FUNC_CALL();
if (!m_isFcIntermediateSurfacePrepared)
{
VP_PUBLIC_ASSERTMESSAGE("Fc intermediate surface is not allocated.");
VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
}
intermediaSurface = nullptr;
for (uint32_t i = 0; i < executedFilters.GetSurfaceCount(true); ++i)
{
uint32_t j = 0;
auto surf = executedFilters.GetSurface(true, i);
VP_PUBLIC_CHK_NULL_RETURN(surf);
for (j = 0; j < VP_NUM_FC_INTERMEDIA_SURFACES; ++j)
{
auto intermediateSurface = m_fcIntermediateSurface[j];
VP_PUBLIC_CHK_NULL_RETURN(intermediateSurface);
if (surf->GetAllocationHandle(&m_osInterface) == intermediateSurface->GetAllocationHandle(&m_osInterface))
{
uint32_t selIndex = (j + 1) % VP_NUM_FC_INTERMEDIA_SURFACES;
intermediaSurface = m_fcIntermediateSurface[selIndex];
break;
}
}
if (j < VP_NUM_FC_INTERMEDIA_SURFACES)
{
break;
}
}
// If intermediate surface not in use in current pipe, use first one by default.
if (nullptr == intermediaSurface)
{
intermediaSurface = m_fcIntermediateSurface[0];
}
return MOS_STATUS_SUCCESS;
}
MOS_STATUS VpResourceManager::AssignIntermediaSurface(VP_EXECUTE_CAPS& caps, SwFilterPipe &executedFilters)
{
VP_FUNC_CALL();
VP_SURFACE *outputSurface = executedFilters.GetSurface(false, 0);
VP_SURFACE *intermediaSurface = nullptr;
if (outputSurface)
{
// No need intermedia surface.
return MOS_STATUS_SUCCESS;
}
if (caps.bComposite)
{
VP_PUBLIC_CHK_STATUS_RETURN(GetFcIntermediateSurfaceForOutput(intermediaSurface, executedFilters));
}
else
{
while (m_currentPipeIndex >= m_intermediaSurfaces.size())
{
m_intermediaSurfaces.push_back(nullptr);
}
bool allocated = false;
// Get surface parameter.
VP_SURFACE_PARAMS params = {};
GetIntermediaOutputSurfaceParams(caps, params, executedFilters);
VP_PUBLIC_CHK_STATUS_RETURN(m_allocator.ReAllocateSurface(
m_intermediaSurfaces[m_currentPipeIndex],
"IntermediaSurface",
params.format,
MOS_GFXRES_2D,
params.tileType,
params.width,
params.height,
params.surfCompressible,
params.surfCompressionMode,
allocated,
false,
IsDeferredResourceDestroyNeeded(),
MOS_HW_RESOURCE_USAGE_VP_INTERNAL_READ_WRITE_RENDER));
VP_PUBLIC_CHK_NULL_RETURN(m_intermediaSurfaces[m_currentPipeIndex]);
m_intermediaSurfaces[m_currentPipeIndex]->ColorSpace = params.colorSpace;
m_intermediaSurfaces[m_currentPipeIndex]->rcDst = params.rcDst;
m_intermediaSurfaces[m_currentPipeIndex]->rcSrc = params.rcSrc;
m_intermediaSurfaces[m_currentPipeIndex]->rcMaxSrc = params.rcMaxSrc;
m_intermediaSurfaces[m_currentPipeIndex]->SampleType = params.sampleType;
intermediaSurface = m_intermediaSurfaces[m_currentPipeIndex];
}
VP_PUBLIC_CHK_NULL_RETURN(intermediaSurface);
VP_SURFACE *output = m_allocator.AllocateVpSurface(*intermediaSurface);
VP_PUBLIC_CHK_NULL_RETURN(output);
output->SurfType = SURF_OUT_RENDERTARGET;
executedFilters.AddSurface(output, false, 0);
return MOS_STATUS_SUCCESS;
}
VP_SURFACE * VpResourceManager::GetCopyInstOfExtSurface(VP_SURFACE* surf)
{
VP_FUNC_CALL();
if (nullptr == surf || 0 == surf->GetAllocationHandle(&m_osInterface))
{
return nullptr;
}
// Do not use allocation handle as key as some parameters in VP_SURFACE
// may be different for same allocation, e.g. SurfType for intermedia surface.
auto it = m_tempSurface.find((uint64_t)surf);
if (it != m_tempSurface.end())
{
return it->second;
}
VP_SURFACE *surface = m_allocator.AllocateVpSurface(*surf);
if (surface)
{
m_tempSurface.insert(make_pair((uint64_t)surf, surface));
}