xref: /aosp_15_r20/external/intel-media-driver/media_softlet/agnostic/common/vp/hal/features/vp_fc_filter.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2020-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 //! \file     vp_fc_filter.h
24 //! \brief    Defines the common interface for denoise
25 //!           this file is for the base interface which is shared by all fc in driver.
26 //!
27 #ifndef __VP_FC_FILTER_H__
28 #define __VP_FC_FILTER_H__
29 #include "vp_filter.h"
30 #include "sw_filter.h"
31 
32 namespace vp {
33 class VpFcFilter : public VpFilter
34 {
35 public:
36 
37     VpFcFilter(
38         PVP_MHWINTERFACE vpMhwInterface);
39 
~VpFcFilter()40     ~VpFcFilter()
41     {
42         Destroy();
43     };
44 
45     virtual MOS_STATUS Init() override;
46 
47     virtual MOS_STATUS Prepare() override;
48 
49     virtual MOS_STATUS Destroy() override;
50 
51     virtual MOS_STATUS SetExecuteEngineCaps(
52         SwFilterPipe            *executedPipe,
53         VP_EXECUTE_CAPS         vpExecuteCaps);
54 
55     MOS_STATUS CalculateEngineParams();
GetFcParams()56     PRENDER_FC_PARAMS GetFcParams()
57     {
58         return m_renderFcParams;
59     }
60 
61 protected:
62     MOS_STATUS GetDefaultScalingMode(VPHAL_SCALING_MODE& defaultScalingMode,SwFilterPipe &executedPipe);
63     MOS_STATUS InitLayer(VP_FC_LAYER &layer, bool isInputPipe, int index, SwFilterPipe &executedPipe, VPHAL_SCALING_MODE defaultScalingMode);
64     MOS_STATUS InitCompParams(VP_COMPOSITE_PARAMS &compParams, SwFilterPipe &executedPipe);
65 
66     MOS_STATUS CalculateCompParams(VP_COMPOSITE_PARAMS &compParams);
67     MOS_STATUS CalculateConstantAlpha(uint16_t &alpha, VP_FC_LAYER &layer);
68     MOS_STATUS CalculateScalingParams(VP_FC_LAYER *layer, VP_FC_LAYER *target,float &fScaleX, float &fScaleY,
69         float &fOffsetX, float &fOffsetY, float &fShiftX , float &fShiftY, RECT &clipedDstRect,
70         bool &isChromaUpSamplingNeeded, bool &isChromaDownSamplingNeeded, MHW_SAMPLER_FILTER_MODE &samplerFilterMode,
71         float &fStepX, float &fStepY);
72     MHW_SAMPLER_FILTER_MODE Get3DSamperFilterMode(VPHAL_SCALING_MODE scalingMode);
73 
74     MOS_STATUS AdjustParamsBasedOnFcLimit(VP_COMPOSITE_PARAMS &compParams);
75 
76     SwFilterPipe            *m_executedPipe = nullptr;
77     PRENDER_FC_PARAMS       m_renderFcParams = nullptr;
78 
79 MEDIA_CLASS_DEFINE_END(vp__VpFcFilter)
80 };
81 
82 struct HW_FILTER_FC_PARAM : public HW_FILTER_PARAM
83 {
84     SwFilterPipe *executedPipe;
85 };
86 
87 class HwFilterFcParameter : public HwFilterParameter
88 {
89 public:
90     static HwFilterParameter *Create(HW_FILTER_FC_PARAM &param, FeatureType featureType);
91     HwFilterFcParameter(FeatureType featureType);
92     virtual ~HwFilterFcParameter();
93     virtual MOS_STATUS ConfigParams(HwFilter &hwFilter);
94 
95     MOS_STATUS Initialize(HW_FILTER_FC_PARAM&param);
96 
97 private:
98     HW_FILTER_FC_PARAM m_Params = {};
99 
100 MEDIA_CLASS_DEFINE_END(vp__HwFilterFcParameter)
101 };
102 
103 class VpRenderFcParameter : public VpPacketParameter
104 {
105 public:
106     static VpPacketParameter *Create(HW_FILTER_FC_PARAM &param);
107     VpRenderFcParameter(PVP_MHWINTERFACE pHwInterface, PacketParamFactoryBase *packetParamFactory);
108     virtual ~VpRenderFcParameter();
109 
110     virtual bool SetPacketParam(VpCmdPacket *pPacket);
111 
112 private:
113     MOS_STATUS Initialize(HW_FILTER_FC_PARAM&params);
114 
115     VpFcFilter m_fcFilter;
116 
117 MEDIA_CLASS_DEFINE_END(vp__VpRenderFcParameter)
118 };
119 
120 #define VP_COMP_MAX_LAYERS          8
121 #define VP_COMP_MAX_PALETTES        2
122 #define VP_COMP_MAX_PROCAMP         1
123 #define VP_COMP_MAX_LUMA_KEY        1
124 #define VP_COMP_MAX_AVS             1
125 #define VP_COMP_SAMPLER_NEAREST     1
126 #define VP_COMP_SAMPLER_BILINEAR    2
127 #define VP_COMP_SAMPLER_LUMAKEY     4
128 #define VP_COMP_MAX_SAMPLER         (VP_COMP_SAMPLER_NEAREST | VP_COMP_SAMPLER_BILINEAR | VP_COMP_SAMPLER_LUMAKEY)
129 
130 class PolicyFcFeatureHandler : public PolicyFeatureHandler
131 {
132 public:
PolicyFcFeatureHandler(VP_HW_CAPS & hwCaps)133     PolicyFcFeatureHandler(VP_HW_CAPS &hwCaps) : PolicyFeatureHandler(hwCaps)
134     {
135         m_Type = FeatureTypeFc;
136     }
~PolicyFcFeatureHandler()137     virtual ~PolicyFcFeatureHandler()
138     {
139     }
IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)140     virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)
141     {
142         // Not create hwFilters for single FC features.
143         return false;
144     }
CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)145     virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface)
146     {
147         return nullptr;
148     }
149     virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
CreatePacketParam(HW_FILTER_PARAM & param)150     static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param)
151     {
152         return nullptr;
153     }
154     virtual MOS_STATUS UpdateUnusedFeature(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
155 
156 MEDIA_CLASS_DEFINE_END(vp__PolicyFcFeatureHandler)
157 };
158 
159 class PolicyFcHandler : public PolicyFeatureHandler
160 {
161 public:
162     PolicyFcHandler(VP_HW_CAPS &hwCaps);
163     virtual ~PolicyFcHandler();
164     virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps);
165     virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface);
166     virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index);
CreatePacketParam(HW_FILTER_PARAM & param)167     static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param)
168     {
169         if (param.type != FeatureTypeFcOnRender)
170         {
171             VP_PUBLIC_ASSERTMESSAGE("Invalid parameter for FC!");
172             return nullptr;
173         }
174 
175         HW_FILTER_FC_PARAM* fcParam = (HW_FILTER_FC_PARAM*)(&param);
176         return VpRenderFcParameter::Create(*fcParam);
177     }
178 
179     virtual MOS_STATUS LayerSelectForProcess(std::vector<int> &layerIndexes, SwFilterPipe& featurePipe, VP_EXECUTE_CAPS& caps);
180 
181     // true to force all layer to use bilinear if bilinear is needed by any layer.
182     // false to use nearest or bilinear based on the requirement of each layer.
183     static bool s_forceNearestToBilinearIfBilinearExists;
184 
185 private:
186     MOS_STATUS RemoveTransparentLayers(SwFilterPipe& featurePipe);
187     virtual MOS_STATUS AddInputLayerForProcess(bool &bSkip, std::vector<int> &layerIndexes, VPHAL_SCALING_MODE &scalingMode, int index, VP_SURFACE &input, SwFilterSubPipe& pipe, VP_SURFACE &output, VP_EXECUTE_CAPS& caps);
188 
189     PacketParamFactory<VpRenderFcParameter> m_PacketParamFactory;
190 
191     // Resource counters
192     struct
193     {
194         int32_t                 layers;
195         int32_t                 palettes;
196         int32_t                 avs;
197         int32_t                 procamp;
198         int32_t                 lumaKeys;
199         int32_t                 sampler;
200 
Reset__anon3a0142760108201         void Reset(bool isAvsSamplerSupported)
202         {
203             // Next step to init it from hw caps object.
204             layers   = VP_COMP_MAX_LAYERS;
205             palettes = VP_COMP_MAX_PALETTES;
206             procamp  = VP_COMP_MAX_PROCAMP;
207             lumaKeys = VP_COMP_MAX_LUMA_KEY;
208             avs      = isAvsSamplerSupported ? VP_COMP_MAX_AVS : 0;
209             sampler  = VP_COMP_MAX_SAMPLER;
210         }
211     } m_resCounter = {};
212 
213 MEDIA_CLASS_DEFINE_END(vp__PolicyFcHandler)
214 };
215 }
216 #endif
217