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 SwFilterPipe *m_executedPipe = nullptr; 75 PRENDER_FC_PARAMS m_renderFcParams = nullptr; 76 77 MEDIA_CLASS_DEFINE_END(VpFcFilter) 78 }; 79 80 struct HW_FILTER_FC_PARAM : public HW_FILTER_PARAM 81 { 82 SwFilterPipe *executedPipe; 83 }; 84 85 class HwFilterFcParameter : public HwFilterParameter 86 { 87 public: 88 static HwFilterParameter *Create(HW_FILTER_FC_PARAM ¶m, FeatureType featureType); 89 HwFilterFcParameter(FeatureType featureType); 90 virtual ~HwFilterFcParameter(); 91 virtual MOS_STATUS ConfigParams(HwFilter &hwFilter); 92 93 MOS_STATUS Initialize(HW_FILTER_FC_PARAM¶m); 94 95 private: 96 HW_FILTER_FC_PARAM m_Params = {}; 97 98 MEDIA_CLASS_DEFINE_END(HwFilterFcParameter) 99 }; 100 101 class VpRenderFcParameter : public VpPacketParameter 102 { 103 public: 104 static VpPacketParameter *Create(HW_FILTER_FC_PARAM ¶m); 105 VpRenderFcParameter(PVP_MHWINTERFACE pHwInterface, PacketParamFactoryBase *packetParamFactory); 106 virtual ~VpRenderFcParameter(); 107 108 virtual bool SetPacketParam(VpCmdPacket *pPacket); 109 110 private: 111 MOS_STATUS Initialize(HW_FILTER_FC_PARAM¶ms); 112 113 VpFcFilter m_fcFilter; 114 115 MEDIA_CLASS_DEFINE_END(VpRenderFcParameter) 116 }; 117 118 #define VP_COMP_MAX_LAYERS 8 119 #define VP_COMP_MAX_PALETTES 2 120 #define VP_COMP_MAX_PROCAMP 1 121 #define VP_COMP_MAX_LUMA_KEY 1 122 #define VP_COMP_MAX_AVS 1 123 #define VP_COMP_SAMPLER_NEAREST 1 124 #define VP_COMP_SAMPLER_BILINEAR 2 125 #define VP_COMP_SAMPLER_LUMAKEY 4 126 #define VP_COMP_MAX_SAMPLER (VP_COMP_SAMPLER_NEAREST | VP_COMP_SAMPLER_BILINEAR | VP_COMP_SAMPLER_LUMAKEY) 127 128 class PolicyFcFeatureHandler : public PolicyFeatureHandler 129 { 130 public: PolicyFcFeatureHandler(VP_HW_CAPS & hwCaps)131 PolicyFcFeatureHandler(VP_HW_CAPS &hwCaps) : PolicyFeatureHandler(hwCaps) 132 { 133 m_Type = FeatureTypeFc; 134 } ~PolicyFcFeatureHandler()135 virtual ~PolicyFcFeatureHandler() 136 { 137 } IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps)138 virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps) 139 { 140 // Not create hwFilters for single FC features. 141 return false; 142 } CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps,SwFilterPipe & swFilterPipe,PVP_MHWINTERFACE pHwInterface)143 virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface) 144 { 145 return nullptr; 146 } 147 virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index); CreatePacketParam(HW_FILTER_PARAM & param)148 static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param) 149 { 150 return nullptr; 151 } 152 153 MEDIA_CLASS_DEFINE_END(PolicyFcFeatureHandler) 154 }; 155 156 class PolicyFcHandler : public PolicyFeatureHandler 157 { 158 public: 159 PolicyFcHandler(VP_HW_CAPS &hwCaps); 160 virtual ~PolicyFcHandler(); 161 virtual bool IsFeatureEnabled(VP_EXECUTE_CAPS vpExecuteCaps); 162 virtual HwFilterParameter *CreateHwFilterParam(VP_EXECUTE_CAPS vpExecuteCaps, SwFilterPipe &swFilterPipe, PVP_MHWINTERFACE pHwInterface); 163 virtual MOS_STATUS UpdateFeaturePipe(VP_EXECUTE_CAPS caps, SwFilter &feature, SwFilterPipe &featurePipe, SwFilterPipe &executePipe, bool isInputPipe, int index); CreatePacketParam(HW_FILTER_PARAM & param)164 static VpPacketParameter* CreatePacketParam(HW_FILTER_PARAM& param) 165 { 166 if (param.type != FeatureTypeFcOnRender) 167 { 168 VP_PUBLIC_ASSERTMESSAGE("Invalid parameter for FC!"); 169 return nullptr; 170 } 171 172 HW_FILTER_FC_PARAM* fcParam = (HW_FILTER_FC_PARAM*)(¶m); 173 return VpRenderFcParameter::Create(*fcParam); 174 } 175 176 virtual MOS_STATUS LayerSelectForProcess(std::vector<int> &layerIndexes, SwFilterPipe& featurePipe, bool isSingleSubPipe, uint32_t pipeIndex, VP_EXECUTE_CAPS& caps); 177 178 // true to force all layer to use bilinear if bilinear is needed by any layer. 179 // false to use nearest or bilinear based on the requirement of each layer. 180 static bool s_forceNearestToBilinearIfBilinearExists; 181 182 private: 183 MOS_STATUS RemoveTransparentLayers(SwFilterPipe& featurePipe); 184 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); 185 186 PacketParamFactory<VpRenderFcParameter> m_PacketParamFactory; 187 188 // Resource counters 189 struct 190 { 191 int32_t layers; 192 int32_t palettes; 193 int32_t avs; 194 int32_t procamp; 195 int32_t lumaKeys; 196 int32_t sampler; 197 Reset__anonfc0a03bb0108198 void Reset(bool isAvsSamplerSupported) 199 { 200 // Next step to init it from hw caps object. 201 layers = VP_COMP_MAX_LAYERS; 202 palettes = VP_COMP_MAX_PALETTES; 203 procamp = VP_COMP_MAX_PROCAMP; 204 lumaKeys = VP_COMP_MAX_LUMA_KEY; 205 avs = isAvsSamplerSupported ? VP_COMP_MAX_AVS : 0; 206 sampler = VP_COMP_MAX_SAMPLER; 207 } 208 } m_resCounter = {}; 209 210 MEDIA_CLASS_DEFINE_END(PolicyFcHandler) 211 }; 212 } 213 #endif 214