| 1 | /* |
| 2 | * Copyright (c) 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 media_copy.h |
| 24 | //! \brief Common interface and structure used in media copy |
| 25 | //! \details Common interface and structure used in media copy which are platform independent |
| 26 | //! |
| 27 | |
| 28 | #ifndef __MEDIA_COPY_H__ |
| 29 | #define __MEDIA_COPY_H__ |
| 30 | |
| 31 | #include <stdint.h> |
| 32 | #include "mos_defs.h" |
| 33 | #include "mos_defs_specific.h" |
| 34 | #include "mos_os_specific.h" |
| 35 | #include "mos_resource_defs.h" |
| 36 | #include "mos_util_debug.h" |
| 37 | #include "mos_os.h" |
| 38 | #include "mos_interface.h" |
| 39 | |
| 40 | class CommonSurfaceDumper; |
| 41 | |
| 42 | typedef struct _MCPY_ENGINE_CAPS |
| 43 | { |
| 44 | uint32_t engineVebox :1; |
| 45 | uint32_t engineBlt :1; |
| 46 | uint32_t engineRender :1; |
| 47 | uint32_t reversed :29; |
| 48 | }MCPY_ENGINE_CAPS; |
| 49 | |
| 50 | enum MCPY_ENGINE |
| 51 | { |
| 52 | MCPY_ENGINE_VEBOX = 0, |
| 53 | MCPY_ENGINE_BLT, |
| 54 | MCPY_ENGINE_RENDER, |
| 55 | }; |
| 56 | |
| 57 | enum MCPY_CPMODE |
| 58 | { |
| 59 | MCPY_CPMODE_CP = 0, |
| 60 | MCPY_CPMODE_CLEAR, |
| 61 | }; |
| 62 | |
| 63 | enum MCPY_METHOD |
| 64 | { |
| 65 | MCPY_METHOD_DEFAULT = 0, |
| 66 | MCPY_METHOD_POWERSAVING, // use BCS engine |
| 67 | MCPY_METHOD_PERFORMANCE, // use EU to get the best perf. |
| 68 | MCPY_METHOD_BALANCE, // use vebox engine. |
| 69 | }; |
| 70 | |
| 71 | typedef struct _MCPY_STATE_PARAMS |
| 72 | { |
| 73 | MOS_RESOURCE *OsRes; // mos resource |
| 74 | MOS_RESOURCE_MMC_MODE CompressionMode; // MC, RC, uncompressed |
| 75 | MOS_TILE_TYPE TileMode; // linear, TILEY, TILE4 |
| 76 | MCPY_CPMODE CpMode; // CP content. |
| 77 | bool bAuxSuface; |
| 78 | }MCPY_STATE_PARAMS; |
| 79 | |
| 80 | class MediaCopyBaseState |
| 81 | { |
| 82 | public: |
| 83 | //! |
| 84 | //! \brief MediaCopy constructor |
| 85 | //! \details Initialize the MediaCopy members. |
| 86 | //! \param osInterface |
| 87 | //! [in] Pointer to MOS_INTERFACE. |
| 88 | //! |
| 89 | MediaCopyBaseState(); |
| 90 | virtual ~MediaCopyBaseState(); |
| 91 | |
| 92 | //! |
| 93 | //! \brief init Media copy |
| 94 | //! \details init func. |
| 95 | //! \param none |
| 96 | //! \return MOS_STATUS |
| 97 | //! Return MOS_STATUS_SUCCESS if success, otherwise return failed. |
| 98 | //! |
| 99 | virtual MOS_STATUS Initialize(PMOS_INTERFACE osInterface); |
| 100 | |
| 101 | //! |
| 102 | //! \brief check copy capability. |
| 103 | //! \details to determine surface copy is supported or not. |
| 104 | //! \param format |
| 105 | //! [in] surface format |
| 106 | //! \param mcpySrc |
| 107 | //! [in] Pointer to source paramters |
| 108 | //! \param mcpyDst |
| 109 | //! [in] Pointer to destination paramters |
| 110 | //! \param caps |
| 111 | //! [in] reference of featue supported engine's caps |
| 112 | //! \return MOS_STATUS |
| 113 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 114 | //! |
| 115 | virtual MOS_STATUS CapabilityCheck( |
| 116 | MOS_FORMAT format, |
| 117 | MCPY_STATE_PARAMS &mcpySrc, |
| 118 | MCPY_STATE_PARAMS &mcpyDst, |
| 119 | MCPY_ENGINE_CAPS &caps, |
| 120 | MCPY_METHOD preferMethod); |
| 121 | |
| 122 | //! |
| 123 | //! \brief surface copy pre process. |
| 124 | //! \details pre process before doing surface copy. |
| 125 | //! \param src |
| 126 | //! [in]Media copy state's input parmaters |
| 127 | //! \param dest |
| 128 | //! [in]Media copy state's output parmaters |
| 129 | //! \param preferMethod |
| 130 | //! [in]Media copy Method |
| 131 | //! \return MOS_STATUS |
| 132 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 133 | //! |
| 134 | virtual MOS_STATUS PreCheckCpCopy( |
| 135 | MCPY_STATE_PARAMS src, MCPY_STATE_PARAMS dest, MCPY_METHOD preferMethod); |
| 136 | |
| 137 | //! |
| 138 | //! \brief surface copy func. |
| 139 | //! \details copy surface. |
| 140 | //! \param src |
| 141 | //! [in] Pointer to source surface |
| 142 | //! \param dst |
| 143 | //! [in] Pointer to destination surface |
| 144 | //! \return MOS_STATUS |
| 145 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 146 | //! |
| 147 | virtual MOS_STATUS SurfaceCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst, MCPY_METHOD preferMethod = MCPY_METHOD_PERFORMANCE); |
| 148 | |
| 149 | //! |
| 150 | //! \brief aux surface copy. |
| 151 | //! \details copy surface. |
| 152 | //! \param src |
| 153 | //! [in] Pointer to source surface |
| 154 | //! \param dst |
| 155 | //! [in] Pointer to destination surface |
| 156 | //! \return MOS_STATUS |
| 157 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 158 | //! |
| 159 | virtual MOS_STATUS AuxCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst); |
| 160 | |
| 161 | //! |
| 162 | //! \brief Is AIL force opition. |
| 163 | //! \details Is AIL force opition. |
| 164 | //! \return bool |
| 165 | //! Return true if support, otherwise return false. |
| 166 | virtual bool IsAILForceOption() |
| 167 | { |
| 168 | return false; |
| 169 | } |
| 170 | |
| 171 | virtual PMOS_INTERFACE GetMosInterface(); |
| 172 | |
| 173 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 174 | virtual void SetRegkeyReport(bool flag) |
| 175 | { |
| 176 | m_bRegReport = flag; |
| 177 | } |
| 178 | #endif |
| 179 | |
| 180 | protected: |
| 181 | |
| 182 | //! |
| 183 | //! \brief dispatch copy task if support. |
| 184 | //! \details dispatch copy task to HW engine (vebox, EU, Blt) based on customer and default. |
| 185 | //! \param mcpySrc |
| 186 | //! [in] Pointer to source surface |
| 187 | //! \param mcpyDst |
| 188 | //! [in] Pointer to destination surface |
| 189 | //! \param mcpyEngine |
| 190 | //! [in] reference of featue supported engine |
| 191 | //! \return MOS_STATUS |
| 192 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 193 | //! |
| 194 | virtual MOS_STATUS TaskDispatch(MCPY_STATE_PARAMS mcpySrc, MCPY_STATE_PARAMS mcpyDst, MCPY_ENGINE mcpyEngine); |
| 195 | |
| 196 | //! |
| 197 | //! \brief vebox format support. |
| 198 | //! \details surface format support. |
| 199 | //! \param src |
| 200 | //! [in] Pointer to source surface |
| 201 | //! \param dst |
| 202 | //! [in] Pointer to destination surface |
| 203 | //! \return bool |
| 204 | //! Return true if support, otherwise return false. |
| 205 | //! |
| 206 | virtual bool IsVeboxCopySupported(PMOS_RESOURCE src, PMOS_RESOURCE dst) |
| 207 | { |
| 208 | return false; |
| 209 | } |
| 210 | |
| 211 | //! |
| 212 | //! \brief render format support. |
| 213 | //! \details surface format support. |
| 214 | //! \param src |
| 215 | //! [in] Pointer to source surface |
| 216 | //! \param dst |
| 217 | //! [in] Pointer to destination surface |
| 218 | //! \return bool |
| 219 | //! Return true if support, otherwise return false. |
| 220 | //! |
| 221 | virtual bool RenderFormatSupportCheck(PMOS_RESOURCE src, PMOS_RESOURCE dst) |
| 222 | {return false;} |
| 223 | |
| 224 | //! |
| 225 | //! \brief feature support check on specific check. |
| 226 | //! \details media copy feature support. |
| 227 | //! \param src |
| 228 | //! [in] Pointer to source surface |
| 229 | //! \param dst |
| 230 | //! [in] Pointer to destination surface |
| 231 | //! \param caps |
| 232 | //! [in] reference of featue supported engine |
| 233 | //! \return MOS_STATUS |
| 234 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 235 | //! |
| 236 | virtual MOS_STATUS FeatureSupport(PMOS_RESOURCE src, PMOS_RESOURCE dst, |
| 237 | MCPY_STATE_PARAMS& mcpy_src, MCPY_STATE_PARAMS& mcpy_dst, MCPY_ENGINE_CAPS& caps) |
| 238 | {return MOS_STATUS_SUCCESS;} |
| 239 | |
| 240 | //! |
| 241 | //! \brief select copy enigne |
| 242 | //! \details media copy select copy enigne. |
| 243 | //! \param preferMethod |
| 244 | //! [in] copy method |
| 245 | //! \param mcpyEngine |
| 246 | //! [in] copy engine |
| 247 | //! \param caps |
| 248 | //! [in] reference of featue supported engine |
| 249 | //! \return MOS_STATUS |
| 250 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 251 | //! |
| 252 | virtual MOS_STATUS CopyEnigneSelect(MCPY_METHOD& preferMethod, MCPY_ENGINE &mcpyEngine, MCPY_ENGINE_CAPS &caps); |
| 253 | |
| 254 | //! |
| 255 | //! \brief use blt engie to do surface copy. |
| 256 | //! \details implementation media blt copy. |
| 257 | //! \param src |
| 258 | //! [in] Pointer to source surface |
| 259 | //! \param dst |
| 260 | //! [in] Pointer to destination surface |
| 261 | //! \return MOS_STATUS |
| 262 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 263 | //! |
| 264 | virtual MOS_STATUS MediaBltCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst) |
| 265 | {return MOS_STATUS_SUCCESS;} |
| 266 | |
| 267 | //! |
| 268 | //! \brief use Render engie to do surface copy. |
| 269 | //! \details implementation media Render copy. |
| 270 | //! \param src |
| 271 | //! [in] Pointer to source surface |
| 272 | //! \param dst |
| 273 | //! [in] Pointer to destination surface |
| 274 | //! \return MOS_STATUS |
| 275 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 276 | //! |
| 277 | virtual MOS_STATUS MediaRenderCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst) |
| 278 | {return MOS_STATUS_SUCCESS;} |
| 279 | |
| 280 | //! |
| 281 | //! \brief use vebox engie to do surface copy. |
| 282 | //! \details implementation media vebox copy. |
| 283 | //! \param src |
| 284 | //! [in] Pointer to source surface |
| 285 | //! \param dst |
| 286 | //! [in] Pointer to destination surface |
| 287 | //! \return MOS_STATUS |
| 288 | //! Return MOS_STATUS_SUCCESS if support, otherwise return unspoort. |
| 289 | //! |
| 290 | virtual MOS_STATUS MediaVeboxCopy(PMOS_RESOURCE src, PMOS_RESOURCE dst) |
| 291 | {return MOS_STATUS_SUCCESS;} |
| 292 | |
| 293 | MOS_STATUS CheckResourceSizeValidForCopy(const MOS_SURFACE &res, const MCPY_ENGINE method); |
| 294 | MOS_STATUS ValidateResource(const MOS_SURFACE &src, const MOS_SURFACE &dst, MCPY_ENGINE method); |
| 295 | |
| 296 | public: |
| 297 | PMOS_INTERFACE m_osInterface = nullptr; |
| 298 | |
| 299 | protected: |
| 300 | PMOS_MUTEX m_inUseGPUMutex = nullptr; // Mutex for in-use GPU context |
| 301 | #if (_DEBUG || _RELEASE_INTERNAL) |
| 302 | CommonSurfaceDumper *m_surfaceDumper = nullptr; |
| 303 | int m_MCPYForceMode = 0; |
| 304 | bool m_enableVeCopySmallRes = false; |
| 305 | bool m_bRegReport = true; |
| 306 | char m_dumpLocation_in[MAX_PATH] = {}; |
| 307 | char m_dumpLocation_out[MAX_PATH] = {}; |
| 308 | #endif |
| 309 | bool m_bRenderFallbackToBlt = false; |
| 310 | MEDIA_CLASS_DEFINE_END(MediaCopyBaseState) |
| 311 | }; |
| 312 | #endif |