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 decode_filmgrain_applynoise_packet_g12.h 24 //! \brief Defines the implementation of av1 decode film grain apply noise kernel packet 25 //! 26 27 #ifndef __DECODE_FILMGRAIN_APPLYNOISE_PACKET_G12_H__ 28 #define __DECODE_FILMGRAIN_APPLYNOISE_PACKET_G12_H__ 29 30 #include "media_render_cmd_packet.h" 31 #include "decode_av1_pipeline_g12_base.h" 32 #include "decode_av1_filmgrain_feature_g12.h" 33 34 namespace decode 35 { 36 37 //Curbe definitions 38 struct FilmGrainApplyNoiseCurbe 39 { 40 // uint32_t 0 41 union 42 { 43 struct 44 { 45 uint32_t InputYuvSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 46 }; 47 struct 48 { 49 uint32_t Value; 50 }; 51 } DW0; 52 53 // uint32_t 1 54 union 55 { 56 struct 57 { 58 uint32_t OutputYSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 59 }; 60 struct 61 { 62 uint32_t Value; 63 }; 64 } DW1; 65 66 // uint32_t 2 67 union 68 { 69 struct 70 { 71 uint32_t OutputUvSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 72 }; 73 struct 74 { 75 uint32_t Value; 76 }; 77 } DW2; 78 79 // uint32_t 3 80 union 81 { 82 struct 83 { 84 uint32_t YDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 85 }; 86 struct 87 { 88 uint32_t Value; 89 }; 90 } DW3; 91 92 // uint32_t 4 93 union 94 { 95 struct 96 { 97 uint32_t UDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 98 }; 99 struct 100 { 101 uint32_t Value; 102 }; 103 } DW4; 104 105 // uint32_t 5 106 union 107 { 108 struct 109 { 110 uint32_t VDitheringSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 111 }; 112 struct 113 { 114 uint32_t Value; 115 }; 116 } DW5; 117 118 // uint32_t 6 119 union 120 { 121 struct 122 { 123 uint32_t RandomValuesForCoordinatesSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 124 }; 125 struct 126 { 127 uint32_t Value; 128 }; 129 } DW6; 130 131 // uint32_t 7 132 union 133 { 134 struct 135 { 136 uint32_t YGammaCorrectionLutSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 137 }; 138 struct 139 { 140 uint32_t Value; 141 }; 142 } DW7; 143 144 // uint32_t 8 145 union 146 { 147 struct 148 { 149 uint32_t UGammaCorrectionLutSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 150 }; 151 struct 152 { 153 uint32_t Value; 154 }; 155 } DW8; 156 157 // uint32_t 9 158 union 159 { 160 struct 161 { 162 uint32_t VGammaCorrectionLutSurfaceIndex : MOS_BITFIELD_RANGE(0, 31); 163 }; 164 struct 165 { 166 uint32_t Value; 167 }; 168 } DW9; 169 170 // uint32_t 10 171 union 172 { 173 struct 174 { 175 uint32_t EnableYFilmGrain : MOS_BITFIELD_RANGE(0, 15); 176 uint32_t EnableUFilmGrain : MOS_BITFIELD_RANGE(16, 31); 177 }; 178 struct 179 { 180 uint32_t Value; 181 }; 182 } DW10; 183 184 // uint32_t 11 185 union 186 { 187 struct 188 { 189 uint32_t EnableVFilmGrain : MOS_BITFIELD_RANGE(0, 15); 190 uint32_t RandomValuesForCoordinatesTableWidth : MOS_BITFIELD_RANGE(16, 31); 191 }; 192 struct 193 { 194 uint32_t Value; 195 }; 196 } DW11; 197 198 // uint32_t 12 199 union 200 { 201 struct 202 { 203 uint32_t ImageHeight : MOS_BITFIELD_RANGE(0, 15); 204 uint32_t ScalingShiftValue : MOS_BITFIELD_RANGE(16, 31); 205 }; 206 struct 207 { 208 uint32_t Value; 209 }; 210 } DW12; 211 212 // uint32_t 13 213 union 214 { 215 struct 216 { 217 uint32_t MinimumYClippingValue : MOS_BITFIELD_RANGE(0, 15); 218 uint32_t MaximumYClippingValue : MOS_BITFIELD_RANGE(16, 31); 219 }; 220 struct 221 { 222 uint32_t Value; 223 }; 224 } DW13; 225 226 // uint32_t 14 227 union 228 { 229 struct 230 { 231 uint32_t MinimumUvClippingValue : MOS_BITFIELD_RANGE(0, 15); 232 uint32_t MaximumUvClippingValue : MOS_BITFIELD_RANGE(16, 31); 233 }; 234 struct 235 { 236 uint32_t Value; 237 }; 238 } DW14; 239 240 // uint32_t 15 241 union 242 { 243 struct 244 { 245 uint32_t CbLumaMultiplier : MOS_BITFIELD_RANGE(0, 15); 246 uint32_t CbMultiplier : MOS_BITFIELD_RANGE(16, 31); 247 }; 248 struct 249 { 250 uint32_t Value; 251 }; 252 } DW15; 253 254 // uint32_t 16 255 union 256 { 257 struct 258 { 259 uint32_t CbOffset : MOS_BITFIELD_RANGE(0, 15); 260 uint32_t CrLumaMultiplier : MOS_BITFIELD_RANGE(16, 31); 261 }; 262 struct 263 { 264 uint32_t Value; 265 }; 266 } DW16; 267 268 // uint32_t 17 269 union 270 { 271 struct 272 { 273 uint32_t CrMultiplier : MOS_BITFIELD_RANGE(0, 15); 274 uint32_t CrOffset : MOS_BITFIELD_RANGE(16, 31); 275 }; 276 struct 277 { 278 uint32_t Value; 279 }; 280 } DW17; 281 282 static const size_t m_size = 18; 283 static const size_t m_byteSize = 72; 284 }; 285 C_ASSERT(sizeof(FilmGrainApplyNoiseCurbe) == 72); 286 287 // Binding Table Definitions 288 //! 289 //! \enum FilmGrainApplyNoiseBindingTableOffset 290 //! \brief Binding table offset for ApplyNoise kernel 291 //! 292 enum FilmGrainApplyNoiseBindingTableOffset 293 { 294 anInputYOrYuv = 0, 295 anInputUv, 296 anOutputY, 297 anOutputUv, 298 anInputYDithering, 299 anInputUDithering, 300 anInputVDithering, 301 anInputRandomValuesCoordinates, 302 anInputYGammaLut, 303 anInputUGammaLut, 304 anInputVGammaLut, 305 anNumSurfaces 306 }; 307 308 enum FilmGrainKernelStateIdx; 309 310 class FilmGrainAppNoisePkt : public RenderCmdPacket 311 { 312 public: 313 FilmGrainAppNoisePkt(MediaPipeline *pipeline, MediaTask *task, CodechalHwInterface *hwInterface); 314 ~FilmGrainAppNoisePkt()315 virtual ~FilmGrainAppNoisePkt() {}; 316 317 //! 318 //! \brief Prepare interal parameters, should be invoked for each frame 319 //! \return MOS_STATUS 320 //! MOS_STATUS_SUCCESS if success, else fail reason 321 //! 322 MOS_STATUS Prepare() override; 323 324 MOS_STATUS Submit(MOS_COMMAND_BUFFER *commandBuffer, uint8_t packetPhase) override; 325 MOS_STATUS Initilize(); 326 virtual MOS_STATUS Init() override; GetPacketName()327 virtual std::string GetPacketName() override 328 { 329 return "AV1_DECODE_FilmGrainAppNoise"; 330 } 331 332 //! 333 //! \brief Calculate Command Size 334 //! 335 //! \param [in, out] commandBufferSize 336 //! requested size 337 //! \param [in, out] requestedPatchListSize 338 //! requested size 339 //! \return MOS_STATUS 340 //! status 341 //! 342 MOS_STATUS CalculateCommandSize(uint32_t &commandBufferSize, uint32_t &requestedPatchListSize) override; 343 344 MOS_STATUS SetCurbeApplyNoise( 345 FilmGrainProcParams *procParams); 346 347 //! 348 //! \brief Destroy the media packet and release the resources specific to it 349 //! \return MOS_STATUS 350 //! MOS_STATUS_SUCCESS if success, else fail reason 351 //! Destroy()352 MOS_STATUS Destroy() override 353 { 354 return RenderCmdPacket::Destroy(); 355 } 356 357 protected: 358 static const int32_t m_minLumaLegalRange = 16; 359 static const int32_t m_maxLumaLegalRange = 235; 360 static const int32_t m_minChromaLegalRange = 16; 361 static const int32_t m_maxChromaLegalRange = 240; 362 363 MOS_STATUS KernelStateSetup(); 364 MOS_STATUS SetUpSurfaceState(); 365 366 virtual MOS_STATUS SetupMediaWalker() override; 367 368 protected: 369 int32_t m_kernelIndex = applyNoise; 370 Kdll_FilterEntry* m_filter = nullptr; //!< Kernel Filter (points to base of filter array) 371 372 MediaFeatureManager *m_featureManager = nullptr; 373 Av1PipelineG12_Base *m_av1Pipeline = nullptr; 374 DecodeAllocator *m_allocator = nullptr; 375 PMOS_INTERFACE m_osInterface = nullptr; 376 Av1BasicFeatureG12 *m_av1BasicFeature = nullptr; 377 Av1DecodeFilmGrainG12 *m_filmGrainFeature = nullptr; 378 379 MhwVdboxVdencInterface *m_vdencInterface = nullptr; 380 CodechalHwInterface *m_hwInterface = nullptr; 381 DecodeMemComp *m_mmcState = nullptr; 382 const CodecAv1PicParams *m_picParams = nullptr; //!< Pointer to picture parameter 383 384 // Surfaces for ApplyNoise 385 FilmGrainProcParams *m_filmGrainProcParams = nullptr; 386 387 uint32_t m_bindingTableIndex[anNumSurfaces] = 388 { 389 anInputYOrYuv, 390 anInputUv, 391 anOutputY, 392 anOutputUv, 393 anInputYDithering, 394 anInputUDithering, 395 anInputVDithering, 396 anInputRandomValuesCoordinates, 397 anInputYGammaLut, 398 anInputUGammaLut, 399 anInputVGammaLut, 400 }; 401 MEDIA_CLASS_DEFINE_END(decode__FilmGrainAppNoisePkt) 402 }; 403 } 404 405 #endif 406