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 encode_hevc_tile.h 24 //! \brief Defines the common interface for hevc tile 25 //! 26 #ifndef __ENCODE_HEVC_TILE_H__ 27 #define __ENCODE_HEVC_TILE_H__ 28 29 #include "encode_tile.h" 30 #include "mhw_vdbox_vdenc_itf.h" 31 #include "mhw_vdbox_hcp_itf.h" 32 33 namespace encode 34 { 35 36 struct HevcTileStatusInfo 37 { 38 uint32_t tileSizeRecord = 0; 39 uint32_t hevcPakStatistics = 0; 40 uint32_t vdencStatistics = 0; 41 uint32_t hevcSliceStreamout = 0; 42 }; 43 44 struct HevcTileInfo 45 { 46 uint16_t tileId = 0; 47 uint16_t tileNum = 0; 48 uint16_t tileGroupId = 0; 49 50 uint16_t tileColPositionInSb = 0; 51 uint16_t tileRowPositionInSb = 0; 52 53 uint16_t tileWidthInSbMinus1 = 0; 54 uint16_t tileHeightInSbMinus1 = 0; 55 56 uint32_t tileStartXInLCU = 0; 57 uint32_t tileStartYInLCU = 0; 58 uint32_t tileEndXInLCU = 0; 59 uint32_t tileEndYInLCU = 0; 60 }; 61 62 class EncodePipeline; 63 64 class HevcEncodeTile : public EncodeTile, public mhw::vdbox::vdenc::Itf::ParSetting, public mhw::vdbox::hcp::Itf::ParSetting 65 { 66 public: 67 HevcEncodeTile(MediaFeatureManager *featureManager, 68 EncodeAllocator *allocator, 69 CodechalHwInterfaceNext *hwInterface, 70 void *constSettings); 71 ~HevcEncodeTile()72 virtual ~HevcEncodeTile() {} 73 74 virtual MOS_STATUS Init(void* settings) override; 75 76 //! 77 //! \brief Update encode parameter 78 //! \param [in] params 79 //! Pointer to parameters 80 //! \return MOS_STATUS 81 //! MOS_STATUS_SUCCESS if success, else fail reason 82 //! 83 virtual MOS_STATUS Update(void *params) override; 84 85 //! 86 //! \brief Set pipe number 87 //! \param [in] numPipes 88 //! Active pipe number 89 //! \return MOS_STATUS 90 //! MOS_STATUS_SUCCESS if success, else fail reason 91 //! 92 MOS_STATUS SetPipeNumber(uint32_t numPipes); 93 94 //! 95 //! \brief Set current tile from slice index 96 //! \param [in] slcCount 97 //! Index of slice 98 //! \param [in] pipeline 99 //! Pipeline used 100 //! \return MOS_STATUS 101 //! MOS_STATUS_SUCCESS if success, else fail reason 102 //! 103 MOS_STATUS SetCurrentTileFromSliceIndex( 104 uint32_t slcCount, 105 EncodePipeline *pipeline); 106 107 //! 108 //! \brief Judge if slice is in current tile 109 //! \param [in] sliceNumber 110 //! Index of slice 111 //! \param [in] currentTile 112 //! Tile data for currentTile 113 //! \param [out] sliceInTile 114 //! Pointer to the flag to indicate if slice is in current tile 115 //! \param [out] lastSliceInTile 116 //! Pointer to the flag to indicate if this slice is last slice in tile 117 //! \return MOS_STATUS 118 //! MOS_STATUS_SUCCESS if success, else fail reason 119 //! 120 MOS_STATUS IsSliceInTile( 121 uint32_t sliceNumber, 122 EncodeTileData *currentTile, 123 bool * sliceInTile, 124 bool * lastSliceInTile); 125 126 //! 127 //! \brief Get tile Level Batch Buffer from Encode Tile features 128 //! \param [out] hevcTileStatsOffset 129 //! Tile Stats offset 130 //! \param [out] hevcFrameStatsOffset 131 //! Frame Stats offset 132 //! \param [out] hevcStatsSize 133 //! Stats size. 134 //! \return MOS_STATUS 135 //! MOS_STATUS_SUCCESS if success, else fail reason 136 //! 137 MOS_STATUS GetTileStatusInfo( 138 HevcTileStatusInfo &hevcTileStatsOffset, 139 HevcTileStatusInfo &hevcFrameStatsOffset, 140 HevcTileStatusInfo &hevcStatsSize); 141 142 //! \brief Get tile information 143 //! 144 //! \param [in] xPosition 145 //! Position of X 146 //! \param [in] xPosition 147 //! Position of Y 148 //! \param [out] tileId 149 //! Tile ID 150 //! \param [out] tileStartLcuX 151 //! Position of X of Tile Start 152 //! \param [out] tileEndLcuX 153 //! Position of X of Tile End 154 //! \param [out] tileStartLcuY 155 //! Position of Y of Tile Start 156 //! \param [out] tileEndLcuY 157 //! Position of Y of Tile End 158 //! 159 //! \return MOS_STATUS 160 //! MOS_STATUS_SUCCESS if success, else fail reason 161 //! 162 MOS_STATUS GetTileInfo( 163 uint32_t xPosition, 164 uint32_t yPosition, 165 uint32_t &tileStartLcuX, 166 uint32_t &tileEndLcuX, 167 uint32_t &tileStartLcuY, 168 uint32_t &tileEndLcuY, 169 uint32_t &tileStreaminOffset); 170 171 MOS_STATUS GetTileInfo(HevcTileInfo *hevcTileInfo) const; 172 173 MHW_SETPAR_DECL_HDR(VDENC_PIPE_MODE_SELECT); 174 175 MHW_SETPAR_DECL_HDR(VDENC_PIPE_BUF_ADDR_STATE); 176 177 MHW_SETPAR_DECL_HDR(VDENC_WALKER_STATE); 178 179 MHW_SETPAR_DECL_HDR(HCP_PIPE_MODE_SELECT); 180 181 MHW_SETPAR_DECL_HDR(HCP_TILE_CODING); 182 183 MHW_SETPAR_DECL_HDR(HCP_PIPE_BUF_ADDR_STATE); 184 185 MHW_SETPAR_DECL_HDR(HCP_SLICE_STATE); 186 187 MHW_SETPAR_DECL_HDR(HCP_IND_OBJ_BASE_ADDR_STATE); 188 189 MHW_SETPAR_DECL_HDR(VDENC_HEVC_VP9_TILE_SLICE_STATE); 190 191 protected: 192 MOS_STATUS SetTileData(void *params) override; 193 194 //! 195 //! \brief Allocate Tile Statistics 196 //! 197 //! \param [in] params 198 //! Pointer to parameters 199 //! 200 //! \return MOS_STATUS 201 //! MOS_STATUS_SUCCESS if success, else fail reason 202 //! 203 MOS_STATUS AllocateTileStatistics(void *params) override; 204 205 //! 206 //! \brief Judge if lcu is in current tile 207 //! \param [in] lcuX 208 //! X coordinate of lcu 209 //! \param [in] lcuY 210 //! Y coordinate of lcu 211 //! \param [in] currentTile 212 //! Tile data for currentTile 213 //! \return bool 214 //! True if lcu is inside current tile, else false. 215 //! 216 bool IsLcuInTile( 217 uint32_t lcuX, 218 uint32_t lcuY, 219 EncodeTileData *currentTile); 220 221 //! 222 //! \brief Calculate Lcu number by tile layout 223 //! 224 //! \param [in] hevcPicParams 225 //! Picture params used for cal 226 //! 227 //! \return MOS_STATUS 228 //! MOS_STATUS_SUCCESS if success, else fail reason 229 //! 230 MOS_STATUS CalculateNumLcuByTiles(PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams); 231 232 //! 233 //! \brief Calculate one tile's width and height 234 //! 235 //! \param [in] hevcPicParams 236 //! Picture params used for cal 237 //! \param [out] rowBd 238 //! Tile row boundary 239 //! \param [out] colBd 240 //! Tile column boundary 241 //! 242 //! \return MOS_STATUS 243 //! MOS_STATUS_SUCCESS if success, else fail reason 244 //! 245 MOS_STATUS CalculateTilesBoundary( 246 PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams, 247 uint32_t *rowBd, 248 uint32_t *colBd); 249 250 //! 251 //! \brief Calculate one tile's width and height 252 //! 253 //! \param [in] hevcPicParams 254 //! Picture params used for cal 255 //! \param [in] hevcSeqParams 256 //! Sequence params used for cal 257 //! \param [in] rowIndex 258 //! Tile row index 259 //! \param [in] colIndex 260 //! Tile column index 261 //! \param [in] rowBd 262 //! Tile row boundary 263 //! \param [in] colBd 264 //! Tile column boundary 265 //! 266 //! \return MOS_STATUS 267 //! MOS_STATUS_SUCCESS if success, else fail reason 268 //! 269 MOS_STATUS CalculateTileWidthAndHeight( 270 PCODEC_HEVC_ENCODE_PICTURE_PARAMS hevcPicParams, 271 PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS hevcSeqParams, 272 uint32_t rowIndex, 273 uint32_t colIndex, 274 uint32_t *rowBd, 275 uint32_t *colBd); 276 277 MOS_CONTEXT_HANDLE m_mosCtx = nullptr; 278 279 uint32_t m_numLcuInPic = 0; //!< Total number of LCU in pic cal by each tile 280 281 HevcTileStatusInfo m_hevcTileStatsOffset = {}; //!< Page aligned offsets used to program HCP / VDEnc pipe and HuC PAK Integration kernel input 282 HevcTileStatusInfo m_hevcFrameStatsOffset = {}; //!< Page aligned offsets used to program HuC PAK Integration kernel output, HuC BRC kernel input 283 HevcTileStatusInfo m_hevcStatsSize = {}; //!< HEVC Statistics size 284 285 std::shared_ptr<mhw::vdbox::hcp::Itf> m_hcpItf = nullptr; 286 287 MEDIA_CLASS_DEFINE_END(encode__HevcEncodeTile) 288 }; 289 290 } // namespace encode 291 292 #endif // !__ENCODE_HEVC_TILE_H__ 293