Debian Codegraph @

media_softlet/agnostic/common/vp/hal/pipeline/vp_packet_reuse_manager.cpp

raw
1 /*
2 * Copyright (c) 2022, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file vp_packet_reuse_manager.cpp
24 //! \brief Defines the common classes for vp packet reuse
25 //! this file is for the base interface which is shared by all features.
26 //!
27
28 #include "vp_packet_reuse_manager.h"
29 #include "vp_vebox_cmd_packet_base.h"
30 #include "vp_user_feature_control.h"
31 #include "policy.h"
32
33 using namespace vp;
34
35 /*******************************************************************/
36 /***********************VpFeatureReuseBase**************************/
37 /*******************************************************************/
38
39 VpFeatureReuseBase::~VpFeatureReuseBase()
40 {
41 }
42
43 MOS_STATUS VpFeatureReuseBase::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
44 {
45 reused = false;
46 return MOS_STATUS_SUCCESS;
47 }
48
49 MOS_STATUS VpFeatureReuseBase::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
50 {
51 VP_PUBLIC_ASSERTMESSAGE("UpdatePacket must be overridden in subclass");
52 return MOS_STATUS_INVALID_PARAMETER;
53 }
54
55 /*******************************************************************/
56 /***********************VpScalingReuse******************************/
57 /*******************************************************************/
58
59 VpScalingReuse::VpScalingReuse()
60 {
61 }
62
63 VpScalingReuse::~VpScalingReuse()
64 {
65 }
66
67 MOS_STATUS VpScalingReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
68 {
69 VP_FUNC_CALL();
70 SwFilterScaling *scaling = dynamic_cast<SwFilterScaling *>(filter);
71 VP_PUBLIC_CHK_NULL_RETURN(scaling);
72 FeatureParamScaling &params = scaling->GetSwFilterParams();
73 if (reusable && params == m_params)
74 {
75 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
76 // is enough. UpdatePacket should use params in swfilter instead of m_params.
77 reused = true;
78 }
79 else
80 {
81 reused = false;
82 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
83 }
84 return MOS_STATUS_SUCCESS;
85 }
86
87 MOS_STATUS VpScalingReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
88 {
89 // Parameters should be no change in UpdateFeatureParams.
90 // No need update.
91 return MOS_STATUS_SUCCESS;
92 }
93
94 MOS_STATUS VpScalingReuse::UpdateFeatureParams(FeatureParamScaling &params)
95 {
96 m_params = params;
97 if (params.pColorFillParams)
98 {
99 m_colorFillParams = *params.pColorFillParams;
100 m_params.pColorFillParams = &m_colorFillParams;
101 }
102 if (params.pCompAlpha)
103 {
104 m_compAlpha = *params.pCompAlpha;
105 m_params.pCompAlpha = &m_compAlpha;
106 }
107 return MOS_STATUS_SUCCESS;
108 }
109
110 /*******************************************************************/
111 /***********************VpCscReuse**********************************/
112 /*******************************************************************/
113 VpCscReuse::VpCscReuse()
114 {
115 }
116
117 VpCscReuse::~VpCscReuse()
118 {
119 }
120
121 MOS_STATUS VpCscReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
122 {
123 VP_FUNC_CALL();
124 auto IsIefEnabled = [&](PVPHAL_IEF_PARAMS iefParams)
125 {
126 return (iefParams && iefParams->bEnabled && iefParams->fIEFFactor > 0.0F);
127 };
128
129 SwFilterCsc *csc = dynamic_cast<SwFilterCsc *>(filter);
130 VP_PUBLIC_CHK_NULL_RETURN(csc);
131 FeatureParamCsc &params = csc->GetSwFilterParams();
132 // pIEFParams to be updated.
133 if (reusable &&
134 params.formatInput == m_params.formatInput &&
135 params.formatOutput == m_params.formatOutput &&
136 params.input == m_params.input &&
137 params.output == m_params.output &&
138 (nullptr == params.pAlphaParams && nullptr == m_params.pAlphaParams ||
139 nullptr != params.pAlphaParams && nullptr != m_params.pAlphaParams &&
140 0 == memcmp(params.pAlphaParams, m_params.pAlphaParams, sizeof(VPHAL_ALPHA_PARAMS))) &&
141 IsIefEnabled(params.pIEFParams) == IsIefEnabled(m_params.pIEFParams))
142 {
143 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
144 // is enough. UpdatePacket should use params in swfilter instead of m_params.
145 reused = true;
146 }
147 else
148 {
149 reused = false;
150 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
151 }
152 return MOS_STATUS_SUCCESS;
153 }
154
155 MOS_STATUS VpCscReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
156 {
157 VP_FUNC_CALL();
158 VpVeboxCmdPacketBase *veboxPacket = dynamic_cast<VpVeboxCmdPacketBase *>(packet);
159 VP_PUBLIC_CHK_NULL_RETURN(veboxPacket);
160
161 SwFilterCsc *scaling = dynamic_cast<SwFilterCsc *>(filter);
162 VP_PUBLIC_CHK_NULL_RETURN(scaling);
163 FeatureParamCsc &params = scaling->GetSwFilterParams();
164
165 VP_PUBLIC_CHK_STATUS_RETURN(veboxPacket->UpdateCscParams(params));
166 return MOS_STATUS_SUCCESS;
167 }
168
169 MOS_STATUS VpCscReuse::UpdateFeatureParams(FeatureParamCsc &params)
170 {
171 VP_FUNC_CALL();
172 m_params = params;
173
174 if (params.pAlphaParams)
175 {
176 m_alphaParams = *params.pAlphaParams;
177 m_params.pAlphaParams = &m_alphaParams;
178 }
179 else
180 {
181 m_params.pAlphaParams = nullptr;
182 }
183
184 if (params.pIEFParams)
185 {
186 m_iefParams = *params.pIEFParams;
187 m_params.pIEFParams = &m_iefParams;
188 }
189 else
190 {
191 m_params.pIEFParams = nullptr;
192 }
193
194 return MOS_STATUS_SUCCESS;
195 }
196
197 /*******************************************************************/
198 /***********************VpRotMirReuse*******************************/
199 /*******************************************************************/
200
201 VpRotMirReuse::VpRotMirReuse()
202 {
203 }
204
205 VpRotMirReuse::~VpRotMirReuse()
206 {
207 }
208
209 MOS_STATUS VpRotMirReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
210 {
211 VP_FUNC_CALL();
212 SwFilterRotMir *rot = dynamic_cast<SwFilterRotMir *>(filter);
213 VP_PUBLIC_CHK_NULL_RETURN(rot);
214 FeatureParamRotMir &params = rot->GetSwFilterParams();
215 if (reusable && params == m_params)
216 {
217 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
218 // is enough. UpdatePacket should use params in swfilter instead of m_params.
219 reused = true;
220 }
221 else
222 {
223 reused = false;
224 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
225 }
226 return MOS_STATUS_SUCCESS;
227 }
228
229 MOS_STATUS VpRotMirReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
230 {
231 // Parameters should be no change in UpdateFeatureParams.
232 // No need update.
233 return MOS_STATUS_SUCCESS;
234 }
235
236 MOS_STATUS VpRotMirReuse::UpdateFeatureParams(FeatureParamRotMir &params)
237 {
238 m_params = params;
239
240 return MOS_STATUS_SUCCESS;
241 }
242
243 /*******************************************************************/
244 /***********************VpColorFillReuse****************************/
245 /*******************************************************************/
246
247 VpColorFillReuse::VpColorFillReuse()
248 {
249 }
250
251 VpColorFillReuse::~VpColorFillReuse()
252 {
253 }
254
255 MOS_STATUS VpColorFillReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
256 {
257 VP_FUNC_CALL();
258 SwFilterColorFill *colorfill = dynamic_cast<SwFilterColorFill *>(filter);
259 VP_PUBLIC_CHK_NULL_RETURN(colorfill);
260 FeatureParamColorFill &params = colorfill->GetSwFilterParams();
261 if (reusable && params == m_params)
262 {
263 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
264 // is enough. UpdatePacket should use params in swfilter instead of m_params.
265 reused = true;
266 }
267 else
268 {
269 reused = false;
270 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
271 }
272 return MOS_STATUS_SUCCESS;
273 }
274
275 MOS_STATUS VpColorFillReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
276 {
277 // Parameters should be no change in UpdateFeatureParams.
278 // No need update.
279 return MOS_STATUS_SUCCESS;
280 }
281
282 MOS_STATUS VpColorFillReuse::UpdateFeatureParams(FeatureParamColorFill &params)
283 {
284 m_params = params;
285
286 if (params.colorFillParams)
287 {
288 m_colorFillParams = *params.colorFillParams;
289 m_params.colorFillParams = &m_colorFillParams;
290 }
291
292 return MOS_STATUS_SUCCESS;
293 }
294
295 /*******************************************************************/
296 /***********************VpAlphaReuse********************************/
297 /*******************************************************************/
298
299 VpAlphaReuse::VpAlphaReuse()
300 {
301 }
302
303 VpAlphaReuse::~VpAlphaReuse()
304 {
305 }
306
307 MOS_STATUS VpAlphaReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
308 {
309 VP_FUNC_CALL();
310 SwFilterAlpha *alpha = dynamic_cast<SwFilterAlpha *>(filter);
311 VP_PUBLIC_CHK_NULL_RETURN(alpha);
312 FeatureParamAlpha &params = alpha->GetSwFilterParams();
313 if (reusable && params == m_params)
314 {
315 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
316 // is enough. UpdatePacket should use params in swfilter instead of m_params.
317 reused = true;
318 }
319 else
320 {
321 reused = false;
322 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
323 }
324 return MOS_STATUS_SUCCESS;
325 }
326
327 MOS_STATUS VpAlphaReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
328 {
329 // Parameters should be no change in UpdateFeatureParams.
330 // No need update.
331 return MOS_STATUS_SUCCESS;
332 }
333
334 MOS_STATUS VpAlphaReuse::UpdateFeatureParams(FeatureParamAlpha &params)
335 {
336 m_params = params;
337
338 if (params.compAlpha)
339 {
340 m_compAlpha = *params.compAlpha;
341 m_params.compAlpha = &m_compAlpha;
342 }
343
344 return MOS_STATUS_SUCCESS;
345 }
346
347 /*******************************************************************/
348 /***********************VpDenoiseReuse********************************/
349 /*******************************************************************/
350
351 VpDenoiseReuse::VpDenoiseReuse()
352 {
353 }
354
355 VpDenoiseReuse::~VpDenoiseReuse()
356 {
357 }
358
359 MOS_STATUS VpDenoiseReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
360 {
361 VP_FUNC_CALL();
362 SwFilterDenoise *dn = dynamic_cast<SwFilterDenoise *>(filter);
363 VP_PUBLIC_CHK_NULL_RETURN(dn);
364 FeatureParamDenoise &params = dn->GetSwFilterParams();
365 if (reusable && params == m_params)
366 {
367 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
368 // is enough. UpdatePacket should use params in swfilter instead of m_params.
369 reused = true;
370 }
371 else
372 {
373 reused = false;
374 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
375 }
376 return MOS_STATUS_SUCCESS;
377 }
378
379 MOS_STATUS VpDenoiseReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
380 {
381 VP_FUNC_CALL();
382 VpVeboxCmdPacketBase *veboxPacket = dynamic_cast<VpVeboxCmdPacketBase *>(packet);
383 VP_PUBLIC_CHK_NULL_RETURN(veboxPacket);
384
385 SwFilterDenoise *denoise = dynamic_cast<SwFilterDenoise *>(filter);
386 VP_PUBLIC_CHK_NULL_RETURN(denoise);
387 FeatureParamDenoise &params = denoise->GetSwFilterParams();
388
389 VP_PUBLIC_CHK_STATUS_RETURN(veboxPacket->UpdateDenoiseParams(params));
390 return MOS_STATUS_SUCCESS;
391 }
392
393 MOS_STATUS VpDenoiseReuse::UpdateFeatureParams(FeatureParamDenoise &params)
394 {
395 m_params = params;
396 return MOS_STATUS_SUCCESS;
397 }
398
399 /*******************************************************************/
400 /***********************VpTccReuse**********************************/
401 /*******************************************************************/
402
403 VpTccReuse::VpTccReuse()
404 {
405 }
406
407 VpTccReuse::~VpTccReuse()
408 {
409 }
410
411 MOS_STATUS VpTccReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
412 {
413 VP_FUNC_CALL();
414 SwFilterTcc *tcc = dynamic_cast<SwFilterTcc *>(filter);
415 VP_PUBLIC_CHK_NULL_RETURN(tcc);
416 FeatureParamTcc &params = tcc->GetSwFilterParams();
417 if (reusable && params.bEnableTCC == m_params.bEnableTCC)
418 {
419 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
420 // is enough. UpdatePacket should use params in swfilter instead of m_params.
421 reused = true;
422 }
423 else
424 {
425 reused = false;
426 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
427 }
428 return MOS_STATUS_SUCCESS;
429 }
430
431 MOS_STATUS VpTccReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
432 {
433 VP_FUNC_CALL();
434 VpVeboxCmdPacketBase *veboxPacket = dynamic_cast<VpVeboxCmdPacketBase *>(packet);
435 VP_PUBLIC_CHK_NULL_RETURN(veboxPacket);
436
437 SwFilterTcc *tcc = dynamic_cast<SwFilterTcc *>(filter);
438 VP_PUBLIC_CHK_NULL_RETURN(tcc);
439 FeatureParamTcc &params = tcc->GetSwFilterParams();
440
441 VP_PUBLIC_CHK_STATUS_RETURN(veboxPacket->UpdateTccParams(params));
442 return MOS_STATUS_SUCCESS;
443 }
444
445 MOS_STATUS VpTccReuse::UpdateFeatureParams(FeatureParamTcc &params)
446 {
447 m_params = params;
448 return MOS_STATUS_SUCCESS;
449 }
450
451 /*******************************************************************/
452 /***********************VpSteReuse**********************************/
453 /*******************************************************************/
454
455 VpSteReuse::VpSteReuse()
456 {
457 }
458
459 VpSteReuse::~VpSteReuse()
460 {
461 }
462
463 MOS_STATUS VpSteReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
464 {
465 VP_FUNC_CALL();
466 SwFilterSte *ste = dynamic_cast<SwFilterSte *>(filter);
467 VP_PUBLIC_CHK_NULL_RETURN(ste);
468 FeatureParamSte &params = ste->GetSwFilterParams();
469 if (reusable && params.bEnableSTE == m_params.bEnableSTE)
470 {
471 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
472 // is enough. UpdatePacket should use params in swfilter instead of m_params.
473 reused = true;
474 }
475 else
476 {
477 reused = false;
478 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
479 }
480 return MOS_STATUS_SUCCESS;
481 }
482
483 MOS_STATUS VpSteReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
484 {
485 VP_FUNC_CALL();
486 VpVeboxCmdPacketBase *veboxPacket = dynamic_cast<VpVeboxCmdPacketBase *>(packet);
487 VP_PUBLIC_CHK_NULL_RETURN(veboxPacket);
488
489 SwFilterSte *ste = dynamic_cast<SwFilterSte *>(filter);
490 VP_PUBLIC_CHK_NULL_RETURN(ste);
491 FeatureParamSte &params = ste->GetSwFilterParams();
492
493 VP_PUBLIC_CHK_STATUS_RETURN(veboxPacket->UpdateSteParams(params));
494 return MOS_STATUS_SUCCESS;
495 }
496
497 MOS_STATUS VpSteReuse::UpdateFeatureParams(FeatureParamSte &params)
498 {
499 m_params = params;
500 return MOS_STATUS_SUCCESS;
501 }
502
503 /*******************************************************************/
504 /***********************VpProcampReuse**********************************/
505 /*******************************************************************/
506
507 VpProcampReuse::VpProcampReuse()
508 {
509 }
510
511 VpProcampReuse::~VpProcampReuse()
512 {
513 }
514
515 MOS_STATUS VpProcampReuse::UpdateFeatureParams(bool reusable, bool &reused, SwFilter *filter)
516 {
517 VP_FUNC_CALL();
518 SwFilterProcamp *procamp = dynamic_cast<SwFilterProcamp *>(filter);
519 VP_PUBLIC_CHK_NULL_RETURN(procamp);
520 FeatureParamProcamp &params = procamp->GetSwFilterParams();
521 if (reusable && ((params.procampParams && m_params.procampParams && params.procampParams->bEnabled == m_params.procampParams->bEnabled) ||
522 (!params.procampParams && !m_params.procampParams)))
523 {
524 // No need call UpdateFeatureParams. Just keep compared items updated in m_params
525 // is enough. UpdatePacket should use params in swfilter instead of m_params.
526 reused = true;
527 }
528 else
529 {
530 reused = false;
531 VP_PUBLIC_CHK_STATUS_RETURN(UpdateFeatureParams(params));
532 }
533 return MOS_STATUS_SUCCESS;
534 }
535
536 MOS_STATUS VpProcampReuse::UpdatePacket(SwFilter *filter, VpCmdPacket *packet)
537 {
538 VP_FUNC_CALL();
539 VpVeboxCmdPacketBase *veboxPacket = dynamic_cast<VpVeboxCmdPacketBase *>(packet);
540 VP_PUBLIC_CHK_NULL_RETURN(veboxPacket);
541
542 SwFilterProcamp *procamp = dynamic_cast<SwFilterProcamp *>(filter);
543 VP_PUBLIC_CHK_NULL_RETURN(procamp);
544 FeatureParamProcamp &params = procamp->GetSwFilterParams();
545
546 VP_PUBLIC_CHK_STATUS_RETURN(veboxPacket->UpdateProcampParams(params));
547 return MOS_STATUS_SUCCESS;
548 }
549
550 MOS_STATUS VpProcampReuse::UpdateFeatureParams(FeatureParamProcamp &params)
551 {
552 m_params = params;
553 if (params.procampParams)
554 {
555 m_procampParams = *params.procampParams;
556 m_params.procampParams = &m_procampParams;
557 }
558 return MOS_STATUS_SUCCESS;
559 }
560
561 /*******************************************************************/
562 /***********************VpPacketReuseManager************************/
563 /*******************************************************************/
564
565 VpPacketReuseManager::VpPacketReuseManager(PacketPipeFactory &packetPipeFactory, VpUserFeatureControl &userFeatureControl) :
566 m_packetPipeFactory(packetPipeFactory), m_disablePacketReuse(userFeatureControl.IsPacketReuseDisabled())
567 {
568 }
569
570 VpPacketReuseManager::~VpPacketReuseManager()
571 {
572 if (m_pipeReused)
573 {
574 m_packetPipeFactory.ReturnPacketPipe(m_pipeReused);
575 }
576 for (auto &it : m_features)
577 {
578 if (it.second)
579 {
580 MOS_Delete(it.second);
581 }
582 }
583 m_features.clear();
584 }
585
586 MOS_STATUS VpPacketReuseManager::RegisterFeatures()
587 {
588 VP_FUNC_CALL()
589 if (m_disablePacketReuse)
590 {
591 return MOS_STATUS_SUCCESS;
592 }
593 VpFeatureReuseBase *p = MOS_New(VpScalingReuse);
594 VP_PUBLIC_CHK_NULL_RETURN(p);
595 m_features.emplace(FeatureTypeScaling, p);
596
597 p = MOS_New(VpCscReuse);
598 VP_PUBLIC_CHK_NULL_RETURN(p);
599 m_features.emplace(FeatureTypeCsc, p);
600
601 p = MOS_New(VpRotMirReuse);
602 VP_PUBLIC_CHK_NULL_RETURN(p);
603 m_features.emplace(FeatureTypeRotMir, p);
604
605 p = MOS_New(VpColorFillReuse);
606 VP_PUBLIC_CHK_NULL_RETURN(p);
607 m_features.emplace(FeatureTypeColorFill, p);
608
609 p = MOS_New(VpDenoiseReuse);
610 VP_PUBLIC_CHK_NULL_RETURN(p);
611 m_features.emplace(FeatureTypeDn, p);
612
613 p = MOS_New(VpAlphaReuse);
614 VP_PUBLIC_CHK_NULL_RETURN(p);
615 m_features.emplace(FeatureTypeAlpha, p);
616
617 p = MOS_New(VpTccReuse);
618 VP_PUBLIC_CHK_NULL_RETURN(p);
619 m_features.emplace(FeatureTypeTcc, p);
620
621 p = MOS_New(VpSteReuse);
622 VP_PUBLIC_CHK_NULL_RETURN(p);
623 m_features.emplace(FeatureTypeSte, p);
624
625 p = MOS_New(VpProcampReuse);
626 VP_PUBLIC_CHK_NULL_RETURN(p);
627 m_features.emplace(FeatureTypeProcamp, p);
628
629
630 return MOS_STATUS_SUCCESS;
631 }
632
633 MOS_STATUS VpPacketReuseManager::PreparePacketPipeReuse(SwFilterPipe *&swFilterPipe, Policy &policy, VpResourceManager &resMgr, bool &isPacketPipeReused, bool &isTeamsWL)
634 {
635 VP_FUNC_CALL();
636 bool reusableOfLastPipe = m_reusable;
637 bool foundPipe = false;
638 uint32_t index = 0;
639
640 m_reusable = true;
641
642 if (m_disablePacketReuse)
643 {
644 m_reusable = false;
645 VP_PUBLIC_NORMALMESSAGE("Not reusable since Packet reuse disabled.");
646 return MOS_STATUS_SUCCESS;
647 }
648
649 if (nullptr == swFilterPipe || swFilterPipe->GetSurfaceCount(true) != 1)
650 {
651 m_reusable = false;
652 VP_PUBLIC_NORMALMESSAGE("Not reusable for multi-layer cases.");
653
654 if (m_pipeReused)
655 {
656 ReturnPacketPipeReused();
657 }
658
659 return MOS_STATUS_SUCCESS;
660 }
661
662 auto &pipe = *swFilterPipe;
663 auto featureRegistered = policy.GetFeatureRegistered();
664
665 isPacketPipeReused = true;
666
667 bool hasAiSwFilter = false;
668 VP_PUBLIC_CHK_STATUS_RETURN(pipe.QuerySwAiFilter(hasAiSwFilter));
669 if (hasAiSwFilter)
670 {
671 m_reusable = false;
672 isPacketPipeReused = false;
673 VP_PUBLIC_NORMALMESSAGE("Packet not reused for containing AI feature");
674 }
675
676 for (auto feature : featureRegistered)
677 {
678 SwFilter *swfilter = pipe.GetSwFilter(true, 0, feature);
679 auto it = m_features.find(feature);
680 bool ignoreUpdateFeatureParams = false;
681
682 if (m_features.end() == it)
683 {
684 if (nullptr != swfilter)
685 {
686 // unreused feature && nullptr != swfilter
687 m_reusable = false;
688 isPacketPipeReused = false;
689 if (m_pipeReused)
690 {
691 ReturnPacketPipeReused();
692 }
693 return MOS_STATUS_SUCCESS;
694 }
695 else
696 {
697 // unreused feature && nullptr == swfilter
698 continue;
699 }
700 }
701 else
702 {
703 // handle reused feature
704 VP_PUBLIC_CHK_STATUS_RETURN(it->second->HandleNullSwFilter(reusableOfLastPipe, isPacketPipeReused, swfilter, ignoreUpdateFeatureParams));
705 if (ignoreUpdateFeatureParams)
706 {
707 continue;
708 }
709 }
710
711 bool reused = false;
712 VP_PUBLIC_CHK_STATUS_RETURN(it->second->UpdateFeatureParams(reusableOfLastPipe, reused, swfilter));
713 if (!reused)
714 {
715 VP_PUBLIC_NORMALMESSAGE("Packet not reused for feature %d", feature);
716 }
717 else
718 {
719 VP_PUBLIC_NORMALMESSAGE("Packet reused for feature %d", feature);
720 }
721 isPacketPipeReused &= reused;
722 }
723
724 if (!isPacketPipeReused)
725 {
726 // m_pipeReused will be udpated in UpdatePacketPipeConfig.
727 VP_PUBLIC_NORMALMESSAGE("Packet cannot be reused.");
728
729 ReturnPacketPipeReused();
730
731 return MOS_STATUS_SUCCESS;
732 }
733
734 VP_PUBLIC_CHK_NULL_RETURN(m_pipeReused);
735
736 if (0 == m_pipeReused->PacketNum())
737 {
738 VP_PUBLIC_ASSERTMESSAGE("Invalid pipe for reuse!");
739 VP_PUBLIC_CHK_STATUS_RETURN(MOS_STATUS_INVALID_PARAMETER);
740 }
741
742 VpCmdPacket *packet = m_pipeReused->GetPacket(0);
743 VP_PUBLIC_CHK_NULL_RETURN(packet);
744
745 VP_SURFACE_SETTING surfSetting = {};
746 VP_EXECUTE_CAPS caps = packet->GetExecuteCaps();
747 resMgr.GetUpdatedExecuteResource(featureRegistered, caps, pipe, surfSetting);
748
749 VP_PUBLIC_CHK_STATUS_RETURN(packet->PacketInitForReuse(pipe.GetSurface(true, 0), pipe.GetSurface(false, 0), pipe.GetPastSurface(0), surfSetting, caps));
750
751 // Update Packet
752 for (auto it : m_features)
753 {
754 SwFilter *swfilter = pipe.GetSwFilter(true, 0, it.first);
755 if (nullptr == swfilter)
756 {
757 continue;
758 }
759
760 VP_PUBLIC_NORMALMESSAGE("Update Packet for feature %d", it.first);
761 VP_PUBLIC_CHK_STATUS_RETURN(it.second->UpdatePacket(swfilter, packet));
762 }
763
764 return MOS_STATUS_SUCCESS;
765 }
766
767 // Be called for not reused case before packet pipe execution.
768 MOS_STATUS VpPacketReuseManager::UpdatePacketPipeConfig(PacketPipe *&pipe)
769 {
770 VP_FUNC_CALL();
771 if (!m_reusable)
772 {
773 VP_PUBLIC_NORMALMESSAGE("Bypass UpdatePacketPipeConfig since not reusable.");
774 return MOS_STATUS_SUCCESS;
775 }
776 if (nullptr == pipe || pipe->PacketNum() > 1)
777 {
778 VP_PUBLIC_NORMALMESSAGE("Not reusable for multi-pass case.");
779 m_reusable = false;
780 return MOS_STATUS_SUCCESS;
781 }
782
783 auto *packet = pipe->GetPacket(0);
784 if (nullptr == packet)
785 {
786 VP_PUBLIC_ASSERTMESSAGE("Invalid packet!");
787 m_reusable = false;
788 VP_PUBLIC_CHK_NULL_RETURN(packet);
789 }
790
791 VP_EXECUTE_CAPS caps = packet->GetExecuteCaps();
792 if (caps.bRender)
793 {
794 VP_PUBLIC_NORMALMESSAGE("Not reusable for render case.");
795 m_reusable = false;
796 return MOS_STATUS_SUCCESS;
797 }
798
799 if (caps.enableSFCLinearOutputByTileConvert)
800 {
801 VP_PUBLIC_NORMALMESSAGE("Not reusable for enableSFCLinearOutputByTileConvert case.");
802 m_reusable = false;
803 return MOS_STATUS_SUCCESS;
804 }
805
806 ReturnPacketPipeReused();
807
808 m_pipeReused = pipe;
809
810 pipe = nullptr;
811
812 return MOS_STATUS_SUCCESS;
813 }
814
815 void VpPacketReuseManager::ReturnPacketPipeReused()
816 {
817 VP_FUNC_CALL();
818 if (nullptr == m_pipeReused)
819 {
820 return;
821 }
822 m_packetPipeFactory.ReturnPacketPipe(m_pipeReused);
823 return;
824 }