1 /*
2 * Copyright (c) 2019 - 2021, 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 //!
24 //! \file     vp_feature_manager.h
25 //! \brief    Defines the common interface for vp features manager
26 //! \details  The vp manager is further sub-divided by vp type
27 //!           this file is for the base interface which is shared by all components.
28 //!
29 #ifndef __SW_FILTER_PIPE_H__
30 #define __SW_FILTER_PIPE_H__
31 
32 #include "media_feature_manager.h"
33 #include "vp_utils.h"
34 #include "vp_pipeline_common.h"
35 #include "vp_allocator.h"
36 
37 #include <vector>
38 #include "sw_filter.h"
39 
40 namespace vp
41 {
42 // Filters without order.
43 
44 #define MAX_LAYER_COUNT VPHAL_MAX_SOURCES
45 
46 class VpInterface;
47 class VpPipelineParamFactory;
48 
49 struct FeatureSet
50 {
51     std::vector<FeatureType> m_Features;
52 };
53 
54 struct FeatureSubRule
55 {
56     std::vector<FeatureSet> m_Rule;
57 };
58 
59 struct FeatureRule
60 {
61     std::vector<FeatureSubRule> m_InputPipes;
62     std::vector<FeatureSubRule> m_OutputPipes;
63 };
64 
65 class SwFilterSubPipe
66 {
67 public:
68     SwFilterSubPipe();
69     virtual ~SwFilterSubPipe();
70     MOS_STATUS Clean();
71     MOS_STATUS Update(VP_SURFACE *inputSurf, VP_SURFACE *outputSurf);
72     SwFilter *GetSwFilter(FeatureType type);
73     MOS_STATUS AddSwFilterOrdered(SwFilter *swFilter, bool useNewSwFilterSet);
74     MOS_STATUS AddSwFilterUnordered(SwFilter *swFilter);
75     MOS_STATUS AddFeatureGraphRTLog();
IsEmpty()76     bool IsEmpty()
77     {
78         bool ret = false;
79 
80         if (m_OrderedFilters.size() == 0 &&
81             m_UnorderedFilters.IsEmpty())
82         {
83             return true;
84         }
85         else
86         {
87             return false;
88         }
89     }
GetRenderTargetType()90     RenderTargetType GetRenderTargetType()
91     {
92         if (m_UnorderedFilters.IsEmpty())
93         {
94             // For VEBOX copy case w/o any feature enabled
95             return RenderTargetTypeSurface;
96         }
97         else
98         {
99             return m_UnorderedFilters.GetRenderTargetType();
100         }
101     }
102 
IsSurfaceFeatureEmpty()103     bool IsSurfaceFeatureEmpty()
104     {
105         return IsEmpty() || RenderTargetTypeParameter == GetRenderTargetType();
106     }
107 
108 private:
109     std::vector<SwFilterSet *> m_OrderedFilters;    // For features in featureRule
110     SwFilterSet m_UnorderedFilters;                 // For features not in featureRule
111 
112 MEDIA_CLASS_DEFINE_END(vp__SwFilterSubPipe)
113 };
114 
115 enum SwFilterPipeType
116 {
117     SwFilterPipeTypeInvalid = 0,
118     SwFilterPipeType1To1,
119     SwFilterPipeTypeNTo1,
120     SwFilterPipeType1ToN,
121     SwFilterPipeType0To1,
122     NumOfSwFilterPipeType
123 };
124 
125 class SwFilterPipe
126 {
127 public:
128     SwFilterPipe(VpInterface &vpInterface);
129     virtual ~SwFilterPipe();
130     MOS_STATUS Initialize(VP_PIPELINE_PARAMS &params, FeatureRule &featureRule);
131     MOS_STATUS Initialize(VEBOX_SFC_PARAMS &params);
132     void UpdateSwFilterPipeType();
133     MOS_STATUS Clean();
134 
135     bool IsEmpty();
136     bool IsPrimaryEmpty();
137 
138     MOS_STATUS ConfigFeaturesToPipe(VP_PIPELINE_PARAMS &params, FeatureRule &featureRule, bool isInputPipe);
139     MOS_STATUS ConfigFeatures(VP_PIPELINE_PARAMS &params, FeatureRule &featureRule);
140     MOS_STATUS ConfigFeatures(VEBOX_SFC_PARAMS &params);
141     MOS_STATUS UpdateFeatures(bool isInputPipe, uint32_t pipeIndex, VP_EXECUTE_CAPS *caps = nullptr);
142 
GetSwFilterPipeType()143     SwFilterPipeType GetSwFilterPipeType()
144     {
145         return m_swFilterPipeType;
146     }
147 
148     SwFilter *GetSwFilter(bool isInputPipe, int index, FeatureType type);
149     SwFilterSubPipe *GetSwFilterSubPipe(bool isInputPipe, int index);
150     SwFilterSubPipe *GetSwFilterPrimaryPipe(uint32_t& index);
151 
152     // useNewSwFilterSet: true if insert new swFilterSet in pipe, otherwise, reuse the last one in pipe.
153     MOS_STATUS AddSwFilterOrdered(SwFilter *swFilter, bool isInputPipe, int index, bool useNewSwFilterSet);
154     MOS_STATUS AddSwFilterUnordered(SwFilter *swFilter, bool isInputPipe, int index);
155     MOS_STATUS RemoveSwFilter(SwFilter *swFilter);
156     VP_SURFACE *ReplaceSurface(VP_SURFACE *surf, bool isInputSurface, uint32_t index);
157     VP_SURFACE *GetSurface(bool isInputSurface, uint32_t index);
158     VP_SURFACE *GetPastSurface(uint32_t index);
159     VP_SURFACE *GetFutureSurface(uint32_t index);
160     MOS_STATUS SetPastSurface(uint32_t index, VP_SURFACE *surf);
161     MOS_STATUS SetFutureSurface(uint32_t index, VP_SURFACE *surf);
162     // Destroy the surface but not remove the related layer. Just keep the surface
163     // pointer being nullptr. Update() need be called later to remove the unused layers.
164     MOS_STATUS DestroySurface(bool isInputSurface, uint32_t index);
165     // Remove the surface but not remove the related layer. Just keep the surface
166     // pointer being nullptr. Update() need be called later to remove the unused layers.
167     VP_SURFACE *RemoveSurface(bool isInputSurface, uint32_t index);
168     VP_SURFACE *RemovePastSurface(uint32_t index);
169     VP_SURFACE *RemoveFutureSurface(uint32_t index);
170     MOS_STATUS AddSurface(VP_SURFACE *&surf, bool isInputSurface, uint32_t index);
171     MOS_STATUS Update(VP_EXECUTE_CAPS *caps = nullptr);
172     uint32_t GetSurfaceCount(bool isInputSurface);
173     MOS_STATUS  AddRTLog();
174     MOS_STATUS  AddFeatureGraphRTLog(bool isInputPipe, uint32_t pipeIndex);
175     bool IsAllInputPipeEmpty();
176     bool IsAllInputPipeSurfaceFeatureEmpty();
177     bool IsAllInputPipeSurfaceFeatureEmpty(std::vector<int> &layerIndexes);
178 
GetSurfacesSetting()179     VP_SURFACE_SETTING &GetSurfacesSetting()
180     {
181         return m_surfacesSetting;
182     }
183 
GetVpInterface()184     VpInterface &GetVpInterface()
185     {
186         return m_vpInterface;
187     }
188 
SetSecureProcessFlag(bool secureProcessed)189     MOS_STATUS SetSecureProcessFlag(bool secureProcessed)
190     {
191         m_processedSecurePrepared = secureProcessed;
192         return MOS_STATUS_SUCCESS;
193     }
194 
IsSecurePreProcessComplete()195     bool IsSecurePreProcessComplete()
196     {
197         return m_processedSecurePrepared;
198     }
199 
ResetSecureFlag()200     MOS_STATUS ResetSecureFlag()
201     {
202         m_processedSecurePrepared = false;
203         return MOS_STATUS_SUCCESS;
204     }
205 
GetRenderTargetType()206     RenderTargetType GetRenderTargetType()
207     {
208         std::vector<SwFilterSubPipe *> &pipes = (m_InputPipes.size() == 0) ? m_OutputPipes : m_InputPipes;
209         for (auto subpipe : pipes)
210         {
211             if (subpipe)
212             {
213                 RenderTargetType targetType = subpipe->GetRenderTargetType();
214                 if (targetType == RenderTargetTypeSurface)
215                 {
216                     return RenderTargetTypeSurface;
217                 }
218             }
219         }
220         return RenderTargetTypeParameter;
221     }
222 
GetLinkedLayerIndex(uint32_t index)223     uint32_t GetLinkedLayerIndex(uint32_t index)
224     {
225         if (index >= m_linkedLayerIndex.size())
226         {
227             VP_PUBLIC_ASSERTMESSAGE("Invalid layer index!");
228             return 0;
229         }
230         return m_linkedLayerIndex[index];
231     }
SetLinkedLayerIndex(uint32_t index,uint32_t linkedIndex)232     void SetLinkedLayerIndex(uint32_t index, uint32_t linkedIndex)
233     {
234         if (index >= m_linkedLayerIndex.size())
235         {
236             VP_PUBLIC_ASSERTMESSAGE("Invalid layer index!");
237             return;
238         }
239         m_linkedLayerIndex[index] = linkedIndex;
240     }
241 
SetExePipeFlag(bool isExePipe)242     void SetExePipeFlag(bool isExePipe)
243     {
244         m_isExePipe = isExePipe;
245     }
246 
247 protected:
248     MOS_STATUS CleanFeaturesFromPipe(bool isInputPipe, uint32_t index);
249     MOS_STATUS CleanFeaturesFromPipe(bool isInputPipe);
250     MOS_STATUS CleanFeatures();
251     MOS_STATUS RemoveUnusedLayers(bool bUpdateInput);
252 
253     std::vector<SwFilterSubPipe *>      m_InputPipes;       // For features on input surfaces.
254     std::vector<SwFilterSubPipe *>      m_OutputPipes;      // For features on output surfaces.
255 
256     std::vector<VP_SURFACE *>           m_InputSurfaces;
257     std::vector<VP_SURFACE *>           m_OutputSurfaces;
258     std::vector<VP_SURFACE *>           m_pastSurface;
259     std::vector<VP_SURFACE *>           m_futureSurface;
260     std::vector<int>                    m_linkedLayerIndex; // Only valid for execute pipe. layer index in original pipe.
261     // Only be used for executedFilters in HW_FILTER_PARAMS. It contains the internal surfaces, including the
262     // statistic buffer and histogram, for one submission, which are managed by resource manager.
263     VP_SURFACE_SETTING                  m_surfacesSetting;
264 
265     VpInterface                         &m_vpInterface;
266 
267     bool                                m_isFeatureRegistered = false;
268     SwFilterPipeType                    m_swFilterPipeType = SwFilterPipeTypeInvalid;
269     bool                                m_processedSecurePrepared = false;
270     bool                                m_isExePipe = false;
271 
272 MEDIA_CLASS_DEFINE_END(vp__SwFilterPipe)
273 };
274 
275 
276 }
277 #endif // !__SW_FILTER_PIPE_H__
278