1 /* 2 * Copyright (c) 2019-2020, 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 vphal_render_vebox_memdecomp.h 24 //! \brief Defines data structures and interfaces for media memory decompression. 25 //! \details 26 //! 27 28 #ifndef __VPHAL_RENDER_VEBOX_MEMDECOMP_H__ 29 #define __VPHAL_RENDER_VEBOX_MEMDECOMP_H__ 30 31 #include "mhw_render_legacy.h" 32 #include "mos_os.h" 33 #include "vphal_debug.h" 34 #include "mediamemdecomp.h" 35 #include "vphal_common.h" 36 #include "mhw_vebox.h" 37 #include "renderhal_legacy.h" 38 39 //------------------------------------------------------------------------------ 40 // Macros specific to MOS_VP_SUBCOMP_RENDER sub-comp 41 //------------------------------------------------------------------------------ 42 #define VPHAL_MEMORY_DECOMP_ASSERT(_expr) \ 43 MOS_ASSERT(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _expr) 44 45 #define VPHAL_MEMORY_DECOMP_ASSERTMESSAGE(_message, ...) \ 46 MOS_ASSERTMESSAGE(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _message, ##__VA_ARGS__) 47 48 #define VPHAL_MEMORY_DECOMP_NORMALMESSAGE(_message, ...) \ 49 MOS_NORMALMESSAGE(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _message, ##__VA_ARGS__) 50 51 #define VPHAL_MEMORY_DECOMP_VERBOSEMESSAGE(_message, ...) \ 52 MOS_VERBOSEMESSAGE(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _message, ##__VA_ARGS__) 53 54 #define VPHAL_MEMORY_DECOMP_FUNCTION_ENTER \ 55 MOS_FUNCTION_ENTER(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER) 56 57 #define VPHAL_MEMORY_DECOMP_EXITMESSAGE(_message, ...) \ 58 MOS_DEBUGMESSAGE(MOS_MESSAGE_LVL_FUNCTION_EXIT, MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _message, ##__VA_ARGS__) 59 60 #define VPHAL_MEMORY_DECOMP_CHK_STATUS(_stmt) \ 61 MOS_CHK_STATUS(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _stmt) 62 63 #define VPHAL_MEMORY_DECOMP_CHK_STATUS_RETURN(_stmt) \ 64 MOS_CHK_STATUS_RETURN(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _stmt) 65 66 #define VPHAL_MEMORY_DECOMP_CHK_STATUS_MESSAGE(_stmt, _message, ...) \ 67 MOS_CHK_STATUS_MESSAGE(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _stmt, _message, ##__VA_ARGS__) 68 69 #define VPHAL_MEMORY_DECOMP_CHK_NULL(_ptr) \ 70 MOS_CHK_NULL(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _ptr) 71 72 #define VPHAL_MEMORY_DECOMP_CHK_NULL_RETURN(_ptr) \ 73 MOS_CHK_NULL_RETURN(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _ptr) 74 75 #define VPHAL_MEMORY_DECOMP_CHK_NULL_NO_STATUS(_ptr) \ 76 MOS_CHK_NULL_NO_STATUS(MOS_COMPONENT_VP, MOS_VP_SUBCOMP_RENDER, _ptr) 77 78 //! 79 //! \class MediaVeboxDecompState 80 //! \brief Media vebox inplace memory decompression state. This class defines the member fields 81 //! functions etc used by memory decompression. 82 //! 83 class MediaVeboxDecompState : public MediaMemDecompBaseState 84 { 85 public: 86 87 //! 88 //! \brief Constructor, initiallize 89 //! 90 MediaVeboxDecompState(); 91 92 //! 93 //! \brief Copy constructor 94 //! 95 MediaVeboxDecompState(const MediaVeboxDecompState&) = delete; 96 97 //! 98 //! \brief Copy assignment operator 99 //! 100 MediaVeboxDecompState& operator=(const MediaVeboxDecompState&) = delete; 101 102 //! 103 //! \brief Destructor 104 //! 105 virtual ~MediaVeboxDecompState(); 106 107 //! 108 //! \brief Media memory decompression render 109 //! \details Entry point to decompress media memory 110 //! \param [in] surface 111 //! Input surface will be decompressed 112 //! 113 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 114 //! 115 virtual MOS_STATUS RenderDecompCMD( 116 PMOS_SURFACE surface) = 0; 117 118 //! 119 //! \brief Media memory double buffer decompression render 120 //! \details Entry point to decompress media memory 121 //! \param [in] surface 122 //! Input surface to be copied and decompressed 123 //! \param [out] surface 124 //! Output surface for clear data 125 //! 126 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 127 //! 128 virtual MOS_STATUS RenderDoubleBufferDecompCMD( 129 PMOS_SURFACE inputSurface, 130 PMOS_SURFACE outputSurface) = 0; 131 132 //! 133 //! \brief Media memory decompression 134 //! \details Entry point to decompress media memory 135 //! \param [in] targetResource 136 //! The surface will be decompressed 137 //! 138 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 139 //! 140 virtual MOS_STATUS MemoryDecompress( 141 PMOS_RESOURCE targetResource); 142 143 //! 144 //! \brief Media memory decompression Enabled or not 145 //! \details Media memory decompression Enabled or not 146 //! 147 //! \return true if MMC decompression enabled, else false. 148 //! 149 virtual MOS_STATUS IsVeboxDecompressionEnabled() = 0; 150 151 //! 152 //! \brief Media memory copy 153 //! \details Entry point to copy media memory, input can support both compressed/uncompressed 154 //! \param [in] inputSurface 155 //! The surface resource will be decompressed 156 //! \param [out] outputSurface 157 //! The target uncompressed surface resource will be copied to 158 //! \param [in] outputCompressed 159 //! The surface resource will compressed if true for compressilbe surface 160 //! 161 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 162 //! 163 virtual MOS_STATUS MediaMemoryCopy( 164 PMOS_RESOURCE inputResource, 165 PMOS_RESOURCE outputResource, 166 bool outputCompressed); 167 168 //! 169 //! \brief Media memory copy 2D 170 //! \details Entry point to decompress media memory and copy with byte in unit 171 //! \param [in] inputSurface 172 //! The source surface resource 173 //! \param [out] outputSurface 174 //! The target surface resource will be copied to 175 //! \param [in] copyWidth 176 //! The 2D surface Width 177 //! \param [in] copyHeight 178 //! The 2D surface height 179 //! \param [in] copyInputOffset 180 //! The offset of copied surface from 181 //! \param [in] copyOutputOffset 182 //! The offset of copied to 183 //! \param [in] bpp 184 //! bit per pixel for copied surfaces 185 //! \param [in] bOutputCompressed 186 //! true means apply compression on output surface, else output uncompressed surface 187 //! 188 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 189 //! 190 virtual MOS_STATUS MediaMemoryCopy2D( 191 PMOS_RESOURCE inputResource, 192 PMOS_RESOURCE outputResource, 193 uint32_t copyWidth, 194 uint32_t copyHeight, 195 uint32_t copyInputOffset, 196 uint32_t copyOutputOffset, 197 uint32_t bpp, 198 bool bOutputCompressed); 199 200 //! 201 //! \brief Media memory tile convert 202 //! \details Convert media between Tile/Linear with decompression 203 //! \param [in] inputSurface 204 //! The source surface resource 205 //! \param [out] outputSurface 206 //! The target surface resource will be copied to 207 //! \param [in] copyWidth 208 //! The 2D surface Width 209 //! \param [in] copyHeight 210 //! The 2D surface height 211 //! \param [in] copyInputOffset 212 //! The offset of copied surface from 213 //! \param [in] copyOutputOffset 214 //! The offset of copied to 215 //! \param [in] isTileToLinear 216 //! Convertion direction, true: tile->linear, false: linear->tile 217 //! \param [in] outputCompressed 218 //! true means apply compression on output surface, else output uncompressed surface 219 //! 220 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 221 //! 222 virtual MOS_STATUS MediaMemoryTileConvert( 223 PMOS_RESOURCE inputResource, 224 PMOS_RESOURCE outputResource, 225 uint32_t copyWidth, 226 uint32_t copyHeight, 227 uint32_t copyInputOffset, 228 uint32_t copyOutputOffset, 229 bool isTileToLinear, 230 bool outputCompressed); 231 232 //! 233 //! \brief Initialize memory decompress state 234 //! \param [in] osInterface 235 //! Os interface 236 //! \param [in] cpInterface 237 //! CP interface 238 //! \param [in] mhwMiInterface 239 //! Hw MI interface 240 //! \param [in] veboxInterface 241 //! Vebox interface 242 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 243 //! 244 MOS_STATUS Initialize( 245 PMOS_INTERFACE osInterface, 246 MhwCpInterface *cpInterface, 247 PMHW_MI_INTERFACE mhwMiInterface, 248 PMHW_VEBOX_INTERFACE veboxInterface); 249 250 //! 251 //! \brief GetDecompState's mosinterface 252 //! \details get the mosinterface 253 //! \return mosinterface 254 //! GetDecompStateMosInterface()255 virtual PMOS_INTERFACE GetDecompStateMosInterface() 256 { 257 return m_osInterface; 258 } 259 260 protected: 261 262 //! 263 //! \brief Get resource information 264 //! \details Get resource information for the specifc surface 265 //! \param [in] pSurface 266 //! Surface pointer 267 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 268 //! 269 MOS_STATUS GetResourceInfo( 270 PMOS_SURFACE surface); 271 272 //! 273 //! \brief Setup Vebox_Surface_State Command parameter 274 //! \param [in/out] mhwVeboxSurfaceStateCmdParams 275 //! Pointer to VEBOX_SURFACE_STATE command parameters 276 //! \param [in] surface 277 //! Input surface pointer 278 //! \param [in] surface 279 //! output surface pointer 280 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 281 //! 282 MOS_STATUS SetupVeboxSurfaceState( 283 PMHW_VEBOX_SURFACE_STATE_CMD_PARAMS mhwVeboxSurfaceStateCmdParams, 284 PMOS_SURFACE inputSurface, 285 PMOS_SURFACE outputSurface); 286 287 //! 288 //! \brief Get resource information 289 //! \details Get resource information for the specifc surface 290 //! \param [in] cmdBuffer 291 //! CmdBuffer pointer 292 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 293 //! 294 MOS_STATUS InitCommandBuffer( 295 PMOS_COMMAND_BUFFER cmdBuffer); 296 297 //! 298 //! Vebox Send Vebox_Tile_Convert command 299 //! \param [in/out] cmdBuffer 300 //! Pointer to PMOS_COMMAND_BUFFER command parameters 301 //! \param [in] surface 302 //! Pointer to Input Surface parameters 303 //! \param [in] surface 304 //! Pointer to Output Surface parameters 305 //! \param [in] streamID 306 //! Stream ID for current surface 307 //! \return MOS_STATUS_SUCCESS if succeeded, else error code. 308 //! 309 virtual MOS_STATUS VeboxSendVeboxTileConvertCMD( 310 PMOS_COMMAND_BUFFER cmdBuffer, 311 PMOS_SURFACE inputSurface, 312 PMOS_SURFACE outputSurface, 313 uint32_t streamID) = 0; 314 315 //! 316 //! Is Vebox Tile Convert/Decompression Format supported 317 //! \param [in/out] surface 318 //! Pointer to Output Surface parameters 319 //! \return true if supported, else false. 320 //! 321 bool IsFormatSupported(PMOS_SURFACE surface); 322 323 enum MEDIA_TILE_TYPE 324 { 325 MEMORY_MEDIACOMPRESSION_ENABLE = 0, 326 MEMORY_RENDERCOMPRESSION_ENABLE, 327 }; 328 329 enum MEDIA_SURFACE_TILE_RESOURCE_MODE 330 { 331 TRMODE_NONE = 0, 332 TRMODE_TILEYF, 333 TRMODE_TILEYS, 334 TRMODE_UNKNOWN, 335 }; 336 337 #if (_DEBUG || _RELEASE_INTERNAL) 338 virtual void CreateSurfaceDumper(); 339 #endif 340 341 public: 342 // Add Public Numbers 343 344 // Interface 345 PMOS_INTERFACE m_osInterface; 346 347 protected: 348 349 // Interface 350 PMHW_VEBOX_INTERFACE m_veboxInterface; 351 PMHW_MI_INTERFACE m_mhwMiInterface; 352 MhwCpInterface *m_cpInterface; 353 bool m_veboxMMCResolveEnabled; 354 355 MediaUserSettingSharedPtr m_userSettingPtr = nullptr; //!< UserSettingInstance 356 357 #if (_DEBUG || _RELEASE_INTERNAL) 358 VphalSurfaceDumper *m_surfaceDumper = nullptr; 359 uint32_t m_surfaceDumpCounter = 0; 360 #endif 361 }; 362 363 #endif // __VPHAL_RENDER_VEBOX_MEMDECOMP_EXT_H__ 364