| 1 | /* |
| 2 | * Copyright (c) 2020-2023, 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_blt_copy_next.h |
| 24 | //! \brief Common interface and structure used in Blitter Engine |
| 25 | //! \details Common interface and structure used in Blitter Engine which are platform independent |
| 26 | //! |
| 27 | #ifndef __MEDIA_BLT_COPY_NEXT_H__ |
| 28 | #define __MEDIA_BLT_COPY_NEXT_H__ |
| 29 | |
| 30 | #include "media_interfaces_mhw_next.h" |
| 31 | #include "mhw_blt.h" |
| 32 | #include "mhw_mi.h" |
| 33 | #include "mhw_cp_interface.h" |
| 34 | #include "mos_os.h" |
| 35 | #include "media_copy.h" |
| 36 | #include "media_copy_common.h" |
| 37 | |
| 38 | class BltStateNext |
| 39 | { |
| 40 | public: |
| 41 | //! |
| 42 | //! \brief BltStateNext constructor |
| 43 | //! \details Initialize the BltStateNext members. |
| 44 | //! \param osInterface |
| 45 | //! [in] Pointer to MOS_INTERFACE. |
| 46 | //! |
| 47 | BltStateNext(PMOS_INTERFACE osInterface); |
| 48 | BltStateNext(PMOS_INTERFACE osInterface, MhwInterfacesNext* mhwInterfaces); |
| 49 | |
| 50 | virtual ~BltStateNext(); |
| 51 | |
| 52 | //! |
| 53 | //! \brief BltStateNext initialize |
| 54 | //! \details Initialize the BltStateNext, create BLT context. |
| 55 | //! \return MOS_STATUS |
| 56 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 57 | //! |
| 58 | virtual MOS_STATUS Initialize(); |
| 59 | |
| 60 | //! |
| 61 | //! \brief Copy main surface |
| 62 | //! \details BLT engine will copy source surface to destination surface |
| 63 | //! \param src |
| 64 | //! [in] Pointer to source surface |
| 65 | //! \param dst |
| 66 | //! [in] Pointer to destination surface |
| 67 | //! \return MOS_STATUS |
| 68 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 69 | //! |
| 70 | virtual MOS_STATUS CopyMainSurface( |
| 71 | PMOS_SURFACE src, |
| 72 | PMOS_SURFACE dst); |
| 73 | |
| 74 | //! |
| 75 | //! \brief Copy main surface |
| 76 | //! \details BLT engine will copy source surface to destination surface |
| 77 | //! \param src |
| 78 | //! [in] Pointer to source resource |
| 79 | //! \param dst |
| 80 | //! [in] Pointer to destination resource |
| 81 | //! \return MOS_STATUS |
| 82 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 83 | //! |
| 84 | virtual MOS_STATUS CopyMainSurface( |
| 85 | PMOS_RESOURCE src, |
| 86 | PMOS_RESOURCE dst); |
| 87 | |
| 88 | //! |
| 89 | //! \brief Setup blt copy parameters |
| 90 | //! \details Setup blt copy parameters for BLT Engine |
| 91 | //! \param mhwParams |
| 92 | //! [in/out] Pointer to MHW_FAST_COPY_BLT_PARAM |
| 93 | //! \param inputSurface |
| 94 | //! [in] Pointer to input surface |
| 95 | //! \param outputSurface |
| 96 | //! [in] Pointer to output surface |
| 97 | //! \param planeIndex |
| 98 | //! [in] Pointer to YUV(RGB) plane index |
| 99 | //! \return MOS_STATUS |
| 100 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 101 | //! |
| 102 | virtual MOS_STATUS SetupBltCopyParam( |
| 103 | PMHW_FAST_COPY_BLT_PARAM mhwParams, |
| 104 | PMOS_RESOURCE inputSurface, |
| 105 | PMOS_RESOURCE outputSurface, |
| 106 | int planeIndex); |
| 107 | |
| 108 | //! |
| 109 | //! \brief Submit command |
| 110 | //! \details Submit BLT command |
| 111 | //! \param pBltStateParam |
| 112 | //! [in] Pointer to BLT_STATE_PARAM |
| 113 | //! \return MOS_STATUS |
| 114 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 115 | //! |
| 116 | virtual MOS_STATUS SubmitCMD( |
| 117 | PBLT_STATE_PARAM pBltStateParam); |
| 118 | |
| 119 | //! |
| 120 | //! \brief Get Block copy color depth. |
| 121 | //! \details get different format's color depth. |
| 122 | //! \param Gmm format and bits per Pixel |
| 123 | //! [in] Gmm format, Bits per Pixel; |
| 124 | //! \return color depth |
| 125 | //! Return color depth |
| 126 | //! |
| 127 | uint32_t GetBlkCopyColorDepth( |
| 128 | GMM_RESOURCE_FORMAT dstFormat, |
| 129 | uint32_t Pixel); |
| 130 | |
| 131 | //! |
| 132 | //! \brief Get plane's byte per texel |
| 133 | //! \details Get plane's byte per texel |
| 134 | //! \param MOS_FORMAT format |
| 135 | //! [in] GMM resource format |
| 136 | //! \return int |
| 137 | //! return the scaling ratio; |
| 138 | //! |
| 139 | int GetBytesPerTexelScaling(MOS_FORMAT format); |
| 140 | |
| 141 | //! |
| 142 | //! \brief Get plane number |
| 143 | //! \details Get plane number |
| 144 | //! \param MOS_FORMAT format |
| 145 | //! [in] GMM resource format |
| 146 | //! \return int |
| 147 | //! return the plane number |
| 148 | //! |
| 149 | int GetPlaneNum(MOS_FORMAT format); |
| 150 | |
| 151 | |
| 152 | //! |
| 153 | //! \brief Get control surface |
| 154 | //! \details BLT engine will copy aux data of source surface to destination |
| 155 | //! \param src |
| 156 | //! [in] Pointer to source surface |
| 157 | //! \param dst |
| 158 | //! [in] Pointer to destination buffer which is created for aux data |
| 159 | //! \return MOS_STATUS |
| 160 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 161 | //! |
| 162 | virtual MOS_STATUS GetCCS( |
| 163 | PMOS_SURFACE src, |
| 164 | PMOS_SURFACE dst); |
| 165 | |
| 166 | //! |
| 167 | //! \brief Put control surface |
| 168 | //! \details BLT engine will copy aux data in source buffer to CCS of destination surface |
| 169 | //! \param src |
| 170 | //! [in] Pointer to source buffer which store aux data |
| 171 | //! \param dst |
| 172 | //! [in] Pointer to destination surface |
| 173 | //! \return MOS_STATUS |
| 174 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 175 | //! |
| 176 | virtual MOS_STATUS PutCCS( |
| 177 | PMOS_SURFACE src, |
| 178 | PMOS_SURFACE dst); |
| 179 | |
| 180 | //! |
| 181 | //! \brief dump surface |
| 182 | //! \details dump surface to get main surface and aux data |
| 183 | //! \param pSrcSurface |
| 184 | //! [in] Pointer to source surface |
| 185 | //! \return MOS_STATUS |
| 186 | //! MOS_STATUS_SUCCESS if success, otherwise error code |
| 187 | //! |
| 188 | virtual MOS_STATUS LockSurface( |
| 189 | PMOS_SURFACE pSurface); |
| 190 | |
| 191 | //! |
| 192 | //! \brief free surface |
| 193 | //! \details Free resource created by lockSurface, must be called once call LockSurface |
| 194 | //! \return MOS_STATUS |
| 195 | //! MOS_STATUS_SUCCESS if success, otherwise error code |
| 196 | //! |
| 197 | virtual MOS_STATUS UnLockSurface(); |
| 198 | |
| 199 | //! |
| 200 | //! \brief Write compressed surface |
| 201 | //! \details Write compressed surface data from system memory to GPU memory |
| 202 | //! \param pSysMemory |
| 203 | //! [in] Pointer to system memory |
| 204 | //! \param dataSize |
| 205 | //! [in] data size, including main surface data and aux data |
| 206 | //! \param pSurface |
| 207 | //! [in] Pointer to the destination surface |
| 208 | //! \return MOS_STATUS |
| 209 | //! MOS_STATUS_SUCCESS if success, otherwise error code |
| 210 | //! |
| 211 | virtual MOS_STATUS WriteCompressedSurface( |
| 212 | void* pSysMemory, |
| 213 | uint32_t dataSize, |
| 214 | PMOS_SURFACE pSurface); |
| 215 | |
| 216 | //! |
| 217 | //! \brief Get main surface size |
| 218 | //! \details Get the size of main surface |
| 219 | //! \return uint32_t |
| 220 | //! Retrun data size |
| 221 | //! |
| 222 | uint32_t GetMainSurfaceSize() |
| 223 | { |
| 224 | return surfaceSize; |
| 225 | } |
| 226 | |
| 227 | //! |
| 228 | //! \brief Get aux data size |
| 229 | //! \details Get the size of aux |
| 230 | //! \return uint32_t |
| 231 | //! Retrun data size |
| 232 | //! |
| 233 | uint32_t GetAuxSize() |
| 234 | { |
| 235 | return auxSize; |
| 236 | } |
| 237 | |
| 238 | //! |
| 239 | //! \brief Get main surface data |
| 240 | //! \details Get the data of main surface |
| 241 | //! \return void* |
| 242 | //! Retrun the pointer to main surface data |
| 243 | //! |
| 244 | void* GetMainSurfaceData() |
| 245 | { |
| 246 | return pMainSurface; |
| 247 | } |
| 248 | |
| 249 | //! |
| 250 | //! \brief Get aux data |
| 251 | //! \details Get the data of aux |
| 252 | //! \return void* |
| 253 | //! Retrun the pointer to aux data |
| 254 | //! |
| 255 | void* GetAuxData() |
| 256 | { |
| 257 | return pAuxSurface; |
| 258 | } |
| 259 | |
| 260 | protected: |
| 261 | //! |
| 262 | //! \brief Allocate resource |
| 263 | //! \details Allocate internel resource |
| 264 | //! \param pSrcSurface |
| 265 | //! [in] Pointer to source surface |
| 266 | //! \return MOS_STATUS |
| 267 | //! MOS_STATUS_SUCCESS if success, otherwise error code |
| 268 | //! |
| 269 | virtual MOS_STATUS AllocateResource( |
| 270 | PMOS_SURFACE pSurface); |
| 271 | |
| 272 | //! |
| 273 | //! \brief Free resource |
| 274 | //! \details Free internel resource, must be called once call AllocateResource |
| 275 | //! \return MOS_STATUS |
| 276 | //! MOS_STATUS_SUCCESS if success, otherwise error code |
| 277 | //! |
| 278 | virtual MOS_STATUS FreeResource(); |
| 279 | |
| 280 | //! |
| 281 | //! \brief Setup control surface copy parameters |
| 282 | //! \details Setup control surface copy parameters for BLT Engine |
| 283 | //! \param mhwParams |
| 284 | //! [in/out] Pointer to MHW_CTRL_SURF_COPY_BLT_PARAM |
| 285 | //! \param inputSurface |
| 286 | //! [in] Pointer to input surface |
| 287 | //! \param outputSurface |
| 288 | //! [in] Pointer to output surface |
| 289 | //! \param flag |
| 290 | //! [in] Flag for read/write CCS |
| 291 | //! \return MOS_STATUS |
| 292 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 293 | //! |
| 294 | MOS_STATUS SetupCtrlSurfCopyBltParam( |
| 295 | PMHW_CTRL_SURF_COPY_BLT_PARAM pMhwBltParams, |
| 296 | PMOS_SURFACE inputSurface, |
| 297 | PMOS_SURFACE outputSurface, |
| 298 | uint32_t flag); |
| 299 | |
| 300 | //! |
| 301 | //! \brief Block copy buffer |
| 302 | //! \details BLT engine will copy source buffer to destination buffer |
| 303 | //! \param pBltStateParam |
| 304 | //! [in] Pointer to BLT_STATE_PARAM |
| 305 | //! \return MOS_STATUS |
| 306 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 307 | //! |
| 308 | MOS_STATUS BlockCopyBuffer( |
| 309 | PBLT_STATE_PARAM pBltStateParam); |
| 310 | |
| 311 | //! |
| 312 | //! \brief SetPrologParamsforCmdbuffer |
| 313 | //! \details Set PrologParams for Cmdbuffer |
| 314 | //! \param PMOS_COMMAND_BUFFER |
| 315 | //! [in] Pointer to PMOS_COMMAND_BUFFER |
| 316 | //! \return MOS_STATUS |
| 317 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 318 | //! |
| 319 | MOS_STATUS SetPrologParamsforCmdbuffer(PMOS_COMMAND_BUFFER cmdBuffer); |
| 320 | |
| 321 | //! |
| 322 | //! \brief Set BCS_SWCTR cmd |
| 323 | //! \details Set BCS_SWCTR for Cmdbuffer |
| 324 | //! \param PMOS_COMMAND_BUFFER |
| 325 | //! [in] Pointer to PMOS_COMMAND_BUFFER |
| 326 | //! \return MOS_STATUS |
| 327 | //! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 328 | //! |
| 329 | virtual MOS_STATUS SetBCSSWCTR(MOS_COMMAND_BUFFER *cmdBuffer); |
| 330 | |
| 331 | public: |
| 332 | PMOS_INTERFACE m_osInterface = nullptr; |
| 333 | MhwInterfacesNext *m_mhwInterfaces = nullptr; |
| 334 | MhwCpInterface *m_cpInterface = nullptr; |
| 335 | |
| 336 | std::shared_ptr<mhw::mi::Itf> m_miItf = nullptr; |
| 337 | std::shared_ptr<mhw::blt::Itf> m_bltItf = nullptr; |
| 338 | |
| 339 | protected: |
| 340 | bool initialized = false; |
| 341 | bool allocated = false; |
| 342 | PMOS_SURFACE tempSurface = nullptr; |
| 343 | PMOS_SURFACE tempAuxSurface = nullptr; |
| 344 | uint32_t surfaceSize = 0; |
| 345 | uint32_t auxSize = 0; |
| 346 | void* pMainSurface = nullptr; |
| 347 | void* pAuxSurface = nullptr; |
| 348 | |
| 349 | MEDIA_CLASS_DEFINE_END(BltStateNext) |
| 350 | }; |
| 351 | |
| 352 | #endif // __MEDIA_BLT_COPY_H__ |