1 /* 2 * Copyright (c) 2018-2022, 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_status_report_defs.h 24 //! \brief Defines the common struture for encode status report 25 //! \details 26 //! 27 #ifndef __ENCODE_STATUS_REPORT_DEFS_H__ 28 #define __ENCODE_STATUS_REPORT_DEFS_H__ 29 30 #include "mos_defs.h" 31 #include "codec_def_common.h" 32 #include "media_status_report.h" 33 34 namespace encode 35 { 36 enum EncodeStatusReportType 37 { 38 statusReportGlobalCount = STATUS_REPORT_GLOBAL_COUNT, 39 //RCS 40 statusReportRCSStart, 41 statusReportEncNormal = statusReportRCSStart, 42 statusReportEncPerformance, 43 statusReportEncQuality, 44 statusReportEncIFrameDist, 45 statusReport32xScaling, 46 statusReport16xScaling, 47 statusReport4xScaling, 48 statusReport32xME, 49 statusReport16xME, 50 statusReport4xME, 51 statusReportBRCInitReset, 52 statusReportBRCUpdate, 53 statusReportBRCBlockCopy, 54 statusReportHybridPakP1, 55 statusReportHybridPakP2, 56 statusReportEncIFrameChroma, 57 statusReportEncIFrameLuma, 58 statusReportMPUFHB, 59 statusReportTPUFHB, 60 statusReportPACopy, 61 statusReportPl2Copy, 62 statusReportEvcAdv, 63 statusReport2xScaling, 64 statusReport32x32PUModeDecision, 65 statusReport16x16PUSAD, 66 statusReport16x16PUModeDecision, 67 statusReport8x8PU, 68 statusReport8x8PUFmode, 69 statusReport32x32BIntraCheck, 70 statusReportHevcBMbEnc, 71 statusReportResetVLineStride, 72 statusReportHevcBPak, 73 statusReportHevcBRCLCUUpdate, 74 statusReportMeVDEncStreamIn, 75 statusReportVP9EncI32x32, 76 statusReportVP9EncI16x16, 77 statusReportVP9EncP, 78 statusReportVP9EncTX, 79 statusReportVP9DYS, 80 statusReportVP9PakLumaRecon, 81 statusReportVP9PakChromaRecon, 82 statusReportVP9PakDeblockMask, 83 statusReportVP9PakLumaDeblock, 84 statusReportVP9PakChromaDeblock, 85 statusReportVP9PakMcPred, 86 statusReportVP9PakPFrameLumaRecon, 87 statusReportVP9PakPFrameLumaRecon32x32, 88 statusReportVP9PakPFrameChromaRecon, 89 statusReportVP9PakPFrameIntraLumaRecon, 90 statusReportVP9PakPFrameIntraChromaRecon, 91 statusReportPreProc, 92 statusReportEncWP, 93 statusReportHevcIMbEnc, 94 statusReportCSCDSCopy, 95 statusReport2x4xScaling, 96 statusReportHevcLCU64BMbEnc, 97 statusReportMbBRCUpdate, 98 statusReportStaticFrameDetection, 99 statusReportHevcROI, 100 statusReportSwScoreBoardInit, 101 statusReportFrameStatus, 102 statusReportRcsMaxNum, 103 104 //MFX 105 statusReportMfx, 106 statusReportMfxBitstreamByteCountPerFrame, 107 statusReportMfxBitstreamSyntaxElementOnlyBitCount, 108 statusReportImageStatusMask, 109 statusReportImageStatusCtrl, 110 statusReportHucStatusRegMask, 111 statusReportHucStatusReg, 112 statusReportNumSlices, 113 statusReportErrorFlags, 114 statusReportBRCQPReport, 115 statusReportNumberPasses, 116 statusReportHeaderBytesInserted, 117 statusReportQPStatusCount, 118 statusReportPictureCodingType, 119 statusReportLoopFilterLevel, 120 statusReportImageStatusCtrlOfLastBRCPass, 121 statusReportSceneChangedFlag, 122 statusReportSumSquareError, 123 statusReportSadLuma, 124 statusReportNumIntra4x4Block, 125 statusReportNumInterSkip4x4Block, 126 statusReportNumSkip8x8Block, 127 statusReportSliceReport, 128 statusReportLpla, 129 statusReportHucStatus2Reg, 130 statusReportMfxMaxNum, 131 132 statusReportMaxNum 133 }; 134 135 struct EncoderStatusParameters 136 { 137 uint32_t statusReportFeedbackNumber; 138 uint32_t numberTilesInFrame; 139 uint16_t pictureCodingType; 140 CODEC_PICTURE currOriginalPic; 141 CODECHAL_FUNCTION codecFunction; 142 uint8_t numUsedVdbox; 143 const void *currRefList; 144 bool hwWalker; 145 uint16_t picWidthInMb; 146 uint16_t frameFieldHeightInMb; 147 uint32_t maxNumSlicesAllowed; 148 uint32_t av1EnableFrameObu; 149 uint32_t av1FrameHdrOBUSizeByteOffset; 150 uint32_t frameWidth; 151 uint32_t frameHeight; 152 }; 153 154 struct ImageStatusControl 155 { 156 union 157 { 158 struct 159 { 160 uint32_t maxMbConformanceFlag : 1; 161 uint32_t frameBitcountFlag : 1; 162 uint32_t panic : 1; 163 uint32_t missingHuffmanCode : 1; // new addition for JPEG encode 164 uint32_t : 4; 165 uint32_t totalNumPass : 4; 166 uint32_t vdencSliceOverflowErrorOccurred : 1; 167 uint32_t numPassPolarityChange : 2; 168 uint32_t cumulativeSliceQPPolarityChange : 1; 169 uint32_t suggestedSliceQPDelta : 8; 170 uint32_t cumulativeSliceDeltaQP: 8; 171 }; 172 173 struct 174 { 175 uint32_t hcpLCUMaxSizeViolate : 1; 176 uint32_t hcpFrameBitCountViolateOverRun : 1; 177 uint32_t hcpFrameBitCountViolateUnderRun : 1; 178 uint32_t : 5; 179 uint32_t hcpTotalPass : 4; 180 uint32_t : 4; 181 uint32_t hcpCumulativeFrameDeltaLF: 7; 182 uint32_t : 1; 183 uint32_t hcpCumulativeFrameDeltaQP : 8; 184 }; 185 186 struct 187 { 188 uint32_t : 1; 189 uint32_t avpFrameBitCountViolateOverrun : 1; 190 uint32_t avpFrameBitCountViolateUnderrun : 1; 191 uint32_t : 5; 192 uint32_t avpTotalNumPass : 4; 193 uint32_t : 4; 194 uint32_t avpCumulativeFrameDeltaLf : 7; 195 uint32_t : 1; 196 uint32_t avpCumulativeFrameDeltaQIndex : 8; 197 }; 198 199 struct 200 { 201 uint32_t value; 202 }; 203 }; 204 }; 205 206 struct PakNumberOfSlices 207 { 208 // Num Slices 209 union 210 { 211 struct 212 { 213 uint32_t numberOfSlices : 16; 214 uint32_t reserved : 16; 215 }; 216 217 struct 218 { 219 uint32_t value; 220 }; 221 }; 222 }; 223 224 struct BrcQpReport 225 { 226 // uint32_t 0 227 union 228 { 229 struct 230 { 231 uint32_t qpPrimeY : 8; 232 uint32_t qpPrimeCb : 8; 233 uint32_t qpPrimeCr : 8; 234 uint32_t reserved : 8; 235 }; 236 struct 237 { 238 uint32_t value; 239 }; 240 } DW0; 241 242 // uint32_t 1 ~ 15 243 struct 244 { 245 uint32_t value[15]; 246 }; 247 }; 248 249 struct QpStatusCount 250 { 251 union{ 252 struct{ 253 uint32_t cumulativeQP : 24; 254 uint32_t cumulativeQPAdjust : 8; 255 }; 256 257 struct 258 { 259 // DW0 260 uint32_t hcpCumulativeQP : 32; 261 262 // DW1 263 uint32_t hcpFrameMinCUQp : 6; 264 uint32_t hcpFrameMaxCUQp : 6; 265 uint32_t : 20; 266 }; 267 268 struct 269 { 270 uint32_t avpCumulativeQP : 24; 271 uint32_t : 8; 272 }; 273 274 struct 275 { 276 uint32_t value[2]; 277 }; 278 }; 279 }; 280 281 struct EncodeStatusSliceReport 282 { 283 uint32_t sliceSizeOverflow; 284 uint8_t numberSlices; 285 uint32_t sizeOfSliceSizesBuffer; 286 PMOS_RESOURCE sliceSize; 287 uint32_t reserved; 288 }; 289 290 struct LookaheadReport 291 { 292 uint32_t StatusReportNumber = 0; 293 union 294 { 295 struct 296 { 297 uint32_t cqmHint : 8; 298 uint32_t intraHint : 1; 299 uint32_t reserved2 : 22; 300 uint32_t isValid : 1; 301 }; 302 uint32_t encodeHints = 0; 303 }; 304 uint32_t targetFrameSize = 0; 305 uint32_t targetBufferFulness = 0; 306 uint32_t pyramidDeltaQP = 0; 307 uint8_t adaptive_rounding = 0; 308 uint8_t miniGopSize = 0; 309 uint8_t reserved1[2]; 310 uint32_t reserved3[10]; 311 }; 312 313 // the tile size record is streamed out serving 2 purposes 314 // in vp9 for back annotation of tile size into the bitstream 315 struct PakHwTileSizeRecord 316 { 317 //DW0 318 uint32_t 319 Address_31_0; 320 321 //DW1 322 uint32_t 323 Address_63_32; 324 325 //DW2 326 uint32_t 327 Length; // Bitstream length per tile; includes header len in first tile, and tail len in last tile 328 329 //DW3 330 uint32_t 331 TileSize; // In Vp9, it is used for back annotation, In Hevc, it is the mmio register bytecountNoHeader 332 333 //DW4 334 uint32_t 335 AddressOffset; // Cacheline offset 336 337 //DW5 338 uint32_t 339 ByteOffset : 6, //[5:0] // Byte offset within cacheline 340 Res_95_70 : 26; //[31:6] 341 342 //DW6 343 uint32_t 344 Hcp_Bs_SE_Bitcount_Tile; // bitstream size for syntax element per tile 345 346 //DW7 347 uint32_t 348 Hcp_Cabac_BinCnt_Tile; // bitstream size for syntax element per tile 349 350 //DW8 351 uint32_t 352 Res_DW8_31_0; 353 354 //DW9 355 uint32_t 356 Hcp_Image_Status_Ctrl; // image status control per tile 357 358 //DW10 359 uint32_t 360 Hcp_Qp_Status_Count; // Qp status count per tile 361 362 //DW11 363 uint32_t 364 Hcp_Slice_Count_Tile; // number of slices per tile 365 366 //DW12-15 367 uint32_t 368 Res_DW12_DW15[4]; // reserved bits added so that QwordDisables are set correctly 369 }; 370 371 struct EncodeStatusMfx 372 { 373 uint32_t status; //!< HW requires a QW aligned offset for data storage 374 uint32_t pad; //!< Pad 375 376 uint32_t mfcBitstreamByteCountPerFrame; //!< Media fixed function bitstream byte count per frame 377 uint32_t mfcBitstreamSyntaxElementOnlyBitCount; //!< Media fixed function bitstream bit count for syntax element only 378 uint32_t imageStatusMask; //!< MUST ENSURE THAT THIS IS QWORD ALIGNED as it's used for the conditional BB end 379 ImageStatusControl imageStatusCtrl; //!< Used for storing the control flags for the image status 380 uint32_t hucStatusRegMask; //!< MUST ENSURE THAT THIS IS QWORD ALIGNED as it's used for the conditional BB end 381 uint32_t hucStatusReg; //!< Register value saving HuC Status 382 PakNumberOfSlices numSlices; //!< Num of slices for encode 383 uint32_t errorFlags; //!< The definition is different on SNB/IVB, hence DWORD 384 union 385 { 386 BrcQpReport brcQPReport; //!< Query bit rate control and QP Status 387 LookaheadReport lookaheadStatus; //!< Lookahead status. valid in lookahead pass only 388 }; 389 uint32_t numberPasses; //!< Number of passes 390 uint32_t headerBytesInserted; //!< The size including header, prevention bytes and dummy "0xff" inserted by SW driver 391 QpStatusCount qpStatusCount; //!< This is used to obtain the cumulative QP 392 uint16_t pictureCodingType; //!< Type of picture coding 393 uint32_t loopFilterLevel; //!< The level of loop filter 394 ImageStatusControl imageStatusCtrlOfLastBRCPass; //!< The level of loop filter 395 uint32_t sceneChangedFlag; //!< The flag indicate if the scene is changed 396 uint64_t sumSquareError[3]; //!< The list of sum square error, luma, Cb, Cr respectively 397 uint32_t sadLuma; //!< Luma SAD 398 uint32_t numIntra4x4Block; //!< Number of intra 4x4 blocks 399 uint32_t numInterSkip4x4Block; //!< Number of inter and skipped 4x4 blocks 400 uint32_t numSkip8x8Block; //!< Number of skipped 8x8 blocks 401 EncodeStatusSliceReport sliceReport; 402 uint32_t hucStatus2Reg; //!< Register value saving HuC Status2 403 }; 404 405 struct EncodeStatusRcs 406 { 407 struct 408 { 409 uint32_t status; 410 uint32_t pad; //!< Pad 411 } executingStatus[statusReportRcsMaxNum]; //!< Media states of stored encode data 412 }; 413 414 struct VDEncStatusReportParam 415 { 416 bool vdEncBRCEnabled; 417 bool waReadVDEncOverflowStatus; 418 uint32_t mode ; 419 uint32_t vDEncBRCNumOfSliceOffset; 420 PMOS_RESOURCE *resVDEncBRCUpdateDmemBufferPtr; 421 }; 422 }; 423 424 #endif // !__ENCODE_STATUS_REPORT_DEFS_H__