| 1 |
/* |
| 2 |
* Copyright (c) 2018, 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 codechal_encode_mpeg2_g11.cpp |
| 24 |
//! \brief MPEG2 dual-pipe encoder for GEN11. |
| 25 |
//! |
| 26 |
|
| 27 |
#include "codechal_encode_mpeg2_g11.h" |
| 28 |
#include "codechal_kernel_hme_g11.h" |
| 29 |
#include "codechal_kernel_header_g11.h" |
| 30 |
#ifndef _FULL_OPEN_SOURCE |
| 31 |
#include "igcodeckrn_g11.h" |
| 32 |
#include "igcodeckrn_g11_icllp.h" |
| 33 |
#endif |
| 34 |
#include "mos_util_user_interface.h" |
| 35 |
#include "codeckrnheader.h" |
| 36 |
|
| 37 |
struct KernelHeaderMpegG11 |
| 38 |
{ |
| 39 |
uint32_t m_kernelCount; |
| 40 |
|
| 41 |
// MBEnc Norm/Perf/Quality moes for frame |
| 42 |
CODECHAL_KERNEL_HEADER m_mpeg2MbEncI; |
| 43 |
CODECHAL_KERNEL_HEADER m_mpeg2MbEncP; |
| 44 |
CODECHAL_KERNEL_HEADER m_mpeg2MbEncB; |
| 45 |
|
| 46 |
CODECHAL_KERNEL_HEADER m_mpeg2InitFrameBrc; |
| 47 |
CODECHAL_KERNEL_HEADER m_mpeg2FrameEncUpdate; |
| 48 |
CODECHAL_KERNEL_HEADER m_mpeg2BrcResetFrame; |
| 49 |
}; |
| 50 |
|
| 51 |
enum BindingTableOffsetMbEncG11 |
| 52 |
{ |
| 53 |
mbEncPakObj = 0, |
| 54 |
mbEncPakObjPrev = 1, |
| 55 |
mbEncCurrentY = 3, |
| 56 |
mbEncBrcDistortionSurface = 8, |
| 57 |
mbEncCurrentPic = 9, |
| 58 |
mbEncForwardPic = 10, |
| 59 |
mbEncBackwardPic = 11, |
| 60 |
mbEncInterlaceFrameCurrentPic = 14, |
| 61 |
mbEncInterlaceFrameBackwardPic = 15, |
| 62 |
mbEncMbControl = 18, |
| 63 |
mbEncSwScoreboard = 19, |
| 64 |
mbEncNumBindingTableEntries = 20 |
| 65 |
}; |
| 66 |
|
| 67 |
//! |
| 68 |
//! \enum StartCode |
| 69 |
//! \brief Start code |
| 70 |
//! |
| 71 |
enum StartCode |
| 72 |
{ |
| 73 |
startCodePrefix = 0x000001, // bit string 0000 0000 0000 0000 0000 0001 |
| 74 |
startCodePicture = 0x00, |
| 75 |
// slice_start_code = 0x01..0xAF, it is the slice_vertical_position for the slice |
| 76 |
// 0xB0, 0xB1, 0xB6 - Reserved |
| 77 |
startCodeUserData = 0xB2, |
| 78 |
startCodeSequenceHeader = 0xB3, |
| 79 |
startCodeSequenceError = 0xB4, |
| 80 |
startCodeExtension = 0xB5, |
| 81 |
startCodeSequenceEnd = 0xB7, |
| 82 |
startCodeGroupStart = 0xB8 |
| 83 |
// system start codes = 0xB9..0xFF |
| 84 |
}; |
| 85 |
|
| 86 |
class MbEncCurbeG11 |
| 87 |
{ |
| 88 |
public: |
| 89 |
struct CurbeData |
| 90 |
{ |
| 91 |
union |
| 92 |
{ |
| 93 |
struct |
| 94 |
{ |
| 95 |
uint32_t m_skipModeEn : MOS_BITFIELD_BIT(0); |
| 96 |
uint32_t m_adaptiveEn : MOS_BITFIELD_BIT(1); |
| 97 |
uint32_t m_biMixDis : MOS_BITFIELD_BIT(2); |
| 98 |
uint32_t m_isInterlacedFrameFlag : MOS_BITFIELD_BIT(3); |
| 99 |
uint32_t m_isTopFieldFirst : MOS_BITFIELD_BIT(4); |
| 100 |
uint32_t m_earlyImeSuccessEn : MOS_BITFIELD_BIT(5); |
| 101 |
uint32_t m_forceToSkip : MOS_BITFIELD_BIT(6); |
| 102 |
uint32_t m_t8x8FlagForInterEn : MOS_BITFIELD_BIT(7); |
| 103 |
uint32_t m_refPixOff : MOS_BITFIELD_RANGE(8,15); |
| 104 |
uint32_t m_reserved1 : MOS_BITFIELD_RANGE(16,23); |
| 105 |
uint32_t m_earlyImeStop : MOS_BITFIELD_RANGE(24,31); |
| 106 |
}; |
| 107 |
struct |
| 108 |
{ |
| 109 |
uint32_t m_value; |
| 110 |
}; |
| 111 |
} DW0; |
| 112 |
|
| 113 |
union |
| 114 |
{ |
| 115 |
struct |
| 116 |
{ |
| 117 |
uint32_t m_maxNumMVs : MOS_BITFIELD_RANGE(0,5); |
| 118 |
uint32_t m_reserved0 : MOS_BITFIELD_RANGE(6,7); |
| 119 |
uint32_t m_refIDPolBits : MOS_BITFIELD_RANGE(8,15); |
| 120 |
uint32_t m_biWeight : MOS_BITFIELD_RANGE(16,21); |
| 121 |
uint32_t m_gxMask : MOS_BITFIELD_BIT(22); |
| 122 |
uint32_t m_gyMask : MOS_BITFIELD_BIT(23); |
| 123 |
uint32_t m_refPixShift : MOS_BITFIELD_RANGE(24,27); |
| 124 |
uint32_t m_uniMixDisable : MOS_BITFIELD_BIT(28); |
| 125 |
uint32_t m_refPixBiasEn : MOS_BITFIELD_BIT(29); // m_refPixBiasEn (MBZ) |
| 126 |
uint32_t m_idmShapeModeExt7x7 : MOS_BITFIELD_BIT(30); |
| 127 |
uint32_t m_idmShapeModeExt5x5 : MOS_BITFIELD_BIT(31); |
| 128 |
}; |
| 129 |
struct |
| 130 |
{ |
| 131 |
uint32_t m_value; |
| 132 |
}; |
| 133 |
} DW1; |
| 134 |
|
| 135 |
union |
| 136 |
{ |
| 137 |
struct |
| 138 |
{ |
| 139 |
uint32_t m_maxLenSP : MOS_BITFIELD_RANGE(0,7); |
| 140 |
uint32_t m_maxNumSU : MOS_BITFIELD_RANGE(8,15); |
| 141 |
uint32_t m_start0X : MOS_BITFIELD_RANGE(16,19); |
| 142 |
uint32_t m_start0Y : MOS_BITFIELD_RANGE(20,23); |
| 143 |
uint32_t m_start1X : MOS_BITFIELD_RANGE(24,27); |
| 144 |
uint32_t m_start1Y : MOS_BITFIELD_RANGE(28,31); |
| 145 |
}; |
| 146 |
struct |
| 147 |
{ |
| 148 |
uint32_t m_value; |
| 149 |
}; |
| 150 |
} DW2; |
| 151 |
|
| 152 |
union |
| 153 |
{ |
| 154 |
struct |
| 155 |
{ |
| 156 |
uint32_t m_fieldBias : MOS_BITFIELD_RANGE(0,7); |
| 157 |
uint32_t m_oppFieldBias : MOS_BITFIELD_RANGE(8,15); |
| 158 |
uint32_t m_fieldSkipThr : MOS_BITFIELD_RANGE(16,31); |
| 159 |
}; |
| 160 |
struct |
| 161 |
{ |
| 162 |
uint32_t m_value; |
| 163 |
}; |
| 164 |
} DW3; |
| 165 |
|
| 166 |
union |
| 167 |
{ |
| 168 |
struct |
| 169 |
{ |
| 170 |
uint32_t m_reserved0 : MOS_BITFIELD_RANGE(0,7); |
| 171 |
uint32_t m_picHeightMinus1 : MOS_BITFIELD_RANGE(8,15); |
| 172 |
uint32_t m_picWidth : MOS_BITFIELD_RANGE(16,23); |
| 173 |
uint32_t m_reserved24 : MOS_BITFIELD_BIT(24); // WalkerType |
| 174 |
uint32_t m_motionSeeding : MOS_BITFIELD_BIT(25); |
| 175 |
uint32_t m_kernelMBModeDecision : MOS_BITFIELD_BIT(26); |
| 176 |
uint32_t m_iFrameMBDistortionDumpEnable : MOS_BITFIELD_BIT(27); |
| 177 |
uint32_t m_fieldFlag : MOS_BITFIELD_BIT(28); |
| 178 |
uint32_t m_pictureType : MOS_BITFIELD_RANGE(29,30); |
| 179 |
uint32_t m_reserved1 : MOS_BITFIELD_BIT(31); |
| 180 |
}; |
| 181 |
struct |
| 182 |
{ |
| 183 |
uint32_t m_value; |
| 184 |
}; |
| 185 |
} DW4; |
| 186 |
|
| 187 |
struct |
| 188 |
{ |
| 189 |
union |
| 190 |
{ |
| 191 |
struct |
| 192 |
{ |
| 193 |
uint32_t m_mv0Cost : MOS_BITFIELD_RANGE(0,7); |
| 194 |
uint32_t m_mv1Cost : MOS_BITFIELD_RANGE(8,15); |
| 195 |
uint32_t m_mv2Cost : MOS_BITFIELD_RANGE(16,23); |
| 196 |
uint32_t m_mv3Cost : MOS_BITFIELD_RANGE(24,31); |
| 197 |
}; |
| 198 |
struct |
| 199 |
{ |
| 200 |
uint32_t m_value; |
| 201 |
}; |
| 202 |
} DW5; |
| 203 |
|
| 204 |
union |
| 205 |
{ |
| 206 |
struct |
| 207 |
{ |
| 208 |
uint32_t m_mv4Cost : MOS_BITFIELD_RANGE(0,7); |
| 209 |
uint32_t m_mv5Cost : MOS_BITFIELD_RANGE(8,15); |
| 210 |
uint32_t m_mv6Cost : MOS_BITFIELD_RANGE(16,23); |
| 211 |
uint32_t m_mv7Cost : MOS_BITFIELD_RANGE(24,31); |
| 212 |
}; |
| 213 |
struct |
| 214 |
{ |
| 215 |
uint32_t m_value; |
| 216 |
}; |
| 217 |
} DW6; |
| 218 |
} MvCost; |
| 219 |
|
| 220 |
union |
| 221 |
{ |
| 222 |
struct |
| 223 |
{ |
| 224 |
uint32_t m_intraPartMask : MOS_BITFIELD_RANGE(0,4); |
| 225 |
uint32_t m_nonSkipZMvAdded : MOS_BITFIELD_BIT(5); |
| 226 |
uint32_t m_nonSkipModeAdded : MOS_BITFIELD_BIT(6); |
| 227 |
uint32_t m_reserved7 : MOS_BITFIELD_BIT(7); |
| 228 |
uint32_t m_reserved8 : MOS_BITFIELD_RANGE(8,15); |
| 229 |
uint32_t m_mvCostScaleFactor : MOS_BITFIELD_RANGE(16,17); |
| 230 |
uint32_t m_bilinearEnable : MOS_BITFIELD_BIT(18); |
| 231 |
uint32_t m_srcFieldPolarity : MOS_BITFIELD_BIT(19); |
| 232 |
uint32_t m_weightedSADHAAR : MOS_BITFIELD_BIT(20); |
| 233 |
uint32_t m_acOnlyHAAR : MOS_BITFIELD_BIT(21); |
| 234 |
uint32_t m_refIDCostMode : MOS_BITFIELD_BIT(22); |
| 235 |
uint32_t m_idmShapeMode : MOS_BITFIELD_BIT(23); |
| 236 |
uint32_t m_skipCenterMask : MOS_BITFIELD_RANGE(24,31); |
| 237 |
}; |
| 238 |
struct |
| 239 |
{ |
| 240 |
uint32_t m_value; |
| 241 |
}; |
| 242 |
} DW7; |
| 243 |
|
| 244 |
union |
| 245 |
{ |
| 246 |
struct |
| 247 |
{ |
| 248 |
uint32_t m_mode8Cost : MOS_BITFIELD_RANGE(0,7); |
| 249 |
uint32_t m_mode9Cost : MOS_BITFIELD_RANGE(8,15); |
| 250 |
uint32_t m_refIDCost : MOS_BITFIELD_RANGE(16,23); |
| 251 |
uint32_t m_chromaIntraModeCost : MOS_BITFIELD_RANGE(24,31); |
| 252 |
}; |
| 253 |
struct |
| 254 |
{ |
| 255 |
uint32_t m_value; |
| 256 |
}; |
| 257 |
} DW8; |
| 258 |
|
| 259 |
union |
| 260 |
{ |
| 261 |
struct |
| 262 |
{ |
| 263 |
uint32_t m_srcSize : MOS_BITFIELD_RANGE(0,1); |
| 264 |
uint32_t m_mbQPEnable : MOS_BITFIELD_BIT(2); |
| 265 |
uint32_t m_mbSkipEnable : MOS_BITFIELD_BIT(3); |
| 266 |
uint32_t m_mbNonSkipEnable : MOS_BITFIELD_BIT(4); |
| 267 |
uint32_t m_reserved5 : MOS_BITFIELD_BIT(5); |
| 268 |
uint32_t m_srcAccess : MOS_BITFIELD_BIT(6); |
| 269 |
uint32_t m_refAccess : MOS_BITFIELD_BIT(7); |
| 270 |
uint32_t m_searchCtrl : MOS_BITFIELD_RANGE(8,10); |
| 271 |
uint32_t m_dualSearchOpt : MOS_BITFIELD_BIT(11); |
| 272 |
uint32_t m_subPelMode : MOS_BITFIELD_RANGE(12,13); |
| 273 |
uint32_t m_skipType : MOS_BITFIELD_BIT(14); |
| 274 |
uint32_t m_fieldCacheAllocationDis : MOS_BITFIELD_BIT(15); |
| 275 |
uint32_t m_interChromaMode : MOS_BITFIELD_BIT(16); |
| 276 |
uint32_t m_ftEnable : MOS_BITFIELD_BIT(17); |
| 277 |
uint32_t m_bmeDisableFBR : MOS_BITFIELD_BIT(18); |
| 278 |
uint32_t m_reserved19 : MOS_BITFIELD_BIT(19); |
| 279 |
uint32_t m_interSAD : MOS_BITFIELD_RANGE(20,21); |
| 280 |
uint32_t m_intraSAD : MOS_BITFIELD_RANGE(22,23); |
| 281 |
uint32_t m_subMbPartMask : MOS_BITFIELD_RANGE(24,30); |
| 282 |
uint32_t m_reserved31 : MOS_BITFIELD_BIT(31); |
| 283 |
}; |
| 284 |
struct |
| 285 |
{ |
| 286 |
uint32_t m_value; |
| 287 |
}; |
| 288 |
} DW9; |
| 289 |
|
| 290 |
union |
| 291 |
{ |
| 292 |
struct |
| 293 |
{ |
| 294 |
uint32_t m_dispatchID : MOS_BITFIELD_RANGE(0,7); |
| 295 |
uint32_t m_largeMbSizeInWord : MOS_BITFIELD_RANGE(8,15); |
| 296 |
uint32_t m_refWidth : MOS_BITFIELD_RANGE(16,23); |
| 297 |
uint32_t m_refHeight : MOS_BITFIELD_RANGE(24,31); |
| 298 |
}; |
| 299 |
struct |
| 300 |
{ |
| 301 |
uint32_t m_value; |
| 302 |
}; |
| 303 |
} DW10; |
| 304 |
|
| 305 |
union |
| 306 |
{ |
| 307 |
struct |
| 308 |
{ |
| 309 |
uint32_t m_qpScaleCode : MOS_BITFIELD_RANGE(0,7); |
| 310 |
uint32_t m_intraFactor : MOS_BITFIELD_RANGE(8,11); |
| 311 |
uint32_t m_intraMulFact : MOS_BITFIELD_RANGE(12,15); |
| 312 |
uint32_t m_intraBiasFF : MOS_BITFIELD_RANGE(16,23); |
| 313 |
uint32_t m_intraBiasFrame : MOS_BITFIELD_RANGE(24,31); |
| 314 |
}; |
| 315 |
struct |
| 316 |
{ |
| 317 |
uint32_t m_value; |
| 318 |
}; |
| 319 |
} DW11; |
| 320 |
|
| 321 |
union |
| 322 |
{ |
| 323 |
struct |
| 324 |
{ |
| 325 |
uint32_t m_isFastMode : MOS_BITFIELD_RANGE(0,7); |
| 326 |
uint32_t m_smallMbSizeInWord : MOS_BITFIELD_RANGE(8,15); |
| 327 |
uint32_t m_distScaleFactor : MOS_BITFIELD_RANGE(16,31); |
| 328 |
}; |
| 329 |
struct |
| 330 |
{ |
| 331 |
uint32_t m_value; |
| 332 |
}; |
| 333 |
} DW12; |
| 334 |
|
| 335 |
union |
| 336 |
{ |
| 337 |
struct |
| 338 |
{ |
| 339 |
uint32_t m_panicModeMBThreshold : MOS_BITFIELD_RANGE(0,15); |
| 340 |
uint32_t m_targetSizeInWord : MOS_BITFIELD_RANGE(16,23); |
| 341 |
uint32_t m_reserved14 : MOS_BITFIELD_RANGE(24,31); |
| 342 |
}; |
| 343 |
struct |
| 344 |
{ |
| 345 |
uint32_t m_value; |
| 346 |
}; |
| 347 |
} DW13; |
| 348 |
|
| 349 |
union |
| 350 |
{ |
| 351 |
struct |
| 352 |
{ |
| 353 |
uint32_t m_forwardHorizontalSearchRange : MOS_BITFIELD_RANGE(0,15); |
| 354 |
uint32_t m_forwardVerticalSearchRange : MOS_BITFIELD_RANGE(16,31); |
| 355 |
}; |
| 356 |
struct |
| 357 |
{ |
| 358 |
uint32_t m_value; |
| 359 |
}; |
| 360 |
} DW14; |
| 361 |
|
| 362 |
union |
| 363 |
{ |
| 364 |
struct |
| 365 |
{ |
| 366 |
uint32_t m_backwardHorizontalSearchRange : MOS_BITFIELD_RANGE(0,15); |
| 367 |
uint32_t m_backwardVerticalSearchRange : MOS_BITFIELD_RANGE(16,31); |
| 368 |
}; |
| 369 |
struct |
| 370 |
{ |
| 371 |
uint32_t m_value; |
| 372 |
}; |
| 373 |
} DW15; |
| 374 |
|
| 375 |
struct |
| 376 |
{ |
| 377 |
union |
| 378 |
{ |
| 379 |
struct |
| 380 |
{ |
| 381 |
uint32_t m_meDelta0to3; |
| 382 |
}; |
| 383 |
struct |
| 384 |
{ |
| 385 |
uint32_t m_value; |
| 386 |
}; |
| 387 |
} DW16; |
| 388 |
|
| 389 |
union |
| 390 |
{ |
| 391 |
struct |
| 392 |
{ |
| 393 |
uint32_t m_meDelta4to7; |
| 394 |
}; |
| 395 |
struct |
| 396 |
{ |
| 397 |
uint32_t m_value; |
| 398 |
}; |
| 399 |
} DW17; |
| 400 |
|
| 401 |
union |
| 402 |
{ |
| 403 |
struct |
| 404 |
{ |
| 405 |
uint32_t m_meDelta8to11; |
| 406 |
}; |
| 407 |
struct |
| 408 |
{ |
| 409 |
uint32_t m_value; |
| 410 |
}; |
| 411 |
} DW18; |
| 412 |
|
| 413 |
union |
| 414 |
{ |
| 415 |
struct |
| 416 |
{ |
| 417 |
uint32_t m_meDelta12to15; |
| 418 |
}; |
| 419 |
struct |
| 420 |
{ |
| 421 |
uint32_t m_value; |
| 422 |
}; |
| 423 |
} DW19; |
| 424 |
|
| 425 |
union |
| 426 |
{ |
| 427 |
struct |
| 428 |
{ |
| 429 |
uint32_t m_meDelta16to19; |
| 430 |
}; |
| 431 |
struct |
| 432 |
{ |
| 433 |
uint32_t m_value; |
| 434 |
}; |
| 435 |
} DW20; |
| 436 |
|
| 437 |
union |
| 438 |
{ |
| 439 |
struct |
| 440 |
{ |
| 441 |
uint32_t m_meDelta20to23; |
| 442 |
}; |
| 443 |
struct |
| 444 |
{ |
| 445 |
uint32_t m_value; |
| 446 |
}; |
| 447 |
} DW21; |
| 448 |
|
| 449 |
union |
| 450 |
{ |
| 451 |
struct |
| 452 |
{ |
| 453 |
uint32_t m_meDelta24to27; |
| 454 |
}; |
| 455 |
struct |
| 456 |
{ |
| 457 |
uint32_t m_value; |
| 458 |
}; |
| 459 |
} DW22; |
| 460 |
|
| 461 |
union |
| 462 |
{ |
| 463 |
struct |
| 464 |
{ |
| 465 |
uint32_t m_meDelta28to31; |
| 466 |
}; |
| 467 |
struct |
| 468 |
{ |
| 469 |
uint32_t m_value; |
| 470 |
}; |
| 471 |
} DW23; |
| 472 |
|
| 473 |
union |
| 474 |
{ |
| 475 |
struct |
| 476 |
{ |
| 477 |
uint32_t m_meDelta32to35; |
| 478 |
}; |
| 479 |
struct |
| 480 |
{ |
| 481 |
uint32_t m_value; |
| 482 |
}; |
| 483 |
} DW24; |
| 484 |
|
| 485 |
union |
| 486 |
{ |
| 487 |
struct |
| 488 |
{ |
| 489 |
uint32_t m_meDelta36to39; |
| 490 |
}; |
| 491 |
struct |
| 492 |
{ |
| 493 |
uint32_t m_value; |
| 494 |
}; |
| 495 |
} DW25; |
| 496 |
|
| 497 |
union |
| 498 |
{ |
| 499 |
struct |
| 500 |
{ |
| 501 |
uint32_t m_meDelta40to43; |
| 502 |
}; |
| 503 |
struct |
| 504 |
{ |
| 505 |
uint32_t m_value; |
| 506 |
}; |
| 507 |
} DW26; |
| 508 |
|
| 509 |
union |
| 510 |
{ |
| 511 |
struct |
| 512 |
{ |
| 513 |
uint32_t m_meDelta44to47; |
| 514 |
}; |
| 515 |
struct |
| 516 |
{ |
| 517 |
uint32_t m_value; |
| 518 |
}; |
| 519 |
} DW27; |
| 520 |
|
| 521 |
union |
| 522 |
{ |
| 523 |
struct |
| 524 |
{ |
| 525 |
uint32_t m_meDelta48to51; |
| 526 |
}; |
| 527 |
struct |
| 528 |
{ |
| 529 |
uint32_t m_value; |
| 530 |
}; |
| 531 |
} DW28; |
| 532 |
|
| 533 |
union |
| 534 |
{ |
| 535 |
struct |
| 536 |
{ |
| 537 |
uint32_t m_meDelta52to55; |
| 538 |
}; |
| 539 |
struct |
| 540 |
{ |
| 541 |
uint32_t m_value; |
| 542 |
}; |
| 543 |
} DW29; |
| 544 |
|
| 545 |
union |
| 546 |
{ |
| 547 |
struct |
| 548 |
{ |
| 549 |
uint32_t m_mode0Cost : MOS_BITFIELD_RANGE(0, 7); |
| 550 |
uint32_t m_mode1Cost : MOS_BITFIELD_RANGE(8, 15); |
| 551 |
uint32_t m_mode2Cost : MOS_BITFIELD_RANGE(16, 23); |
| 552 |
uint32_t m_mode3Cost : MOS_BITFIELD_RANGE(24, 31); |
| 553 |
}; |
| 554 |
struct |
| 555 |
{ |
| 556 |
uint32_t m_value; |
| 557 |
}; |
| 558 |
} DW30; |
| 559 |
|
| 560 |
union |
| 561 |
{ |
| 562 |
struct |
| 563 |
{ |
| 564 |
uint32_t m_mode4Cost : MOS_BITFIELD_RANGE(0, 7); |
| 565 |
uint32_t m_mode5Cost : MOS_BITFIELD_RANGE(8, 15); |
| 566 |
uint32_t m_mode6Cost : MOS_BITFIELD_RANGE(16, 23); |
| 567 |
uint32_t m_mode7Cost : MOS_BITFIELD_RANGE(24, 31); |
| 568 |
}; |
| 569 |
struct |
| 570 |
{ |
| 571 |
uint32_t m_value; |
| 572 |
}; |
| 573 |
} DW31; |
| 574 |
} VmeSPath0; |
| 575 |
|
| 576 |
struct |
| 577 |
{ |
| 578 |
union |
| 579 |
{ |
| 580 |
struct |
| 581 |
{ |
| 582 |
uint32_t m_meDelta0to3; |
| 583 |
}; |
| 584 |
struct |
| 585 |
{ |
| 586 |
uint32_t m_value; |
| 587 |
}; |
| 588 |
} DW32; |
| 589 |
|
| 590 |
union |
| 591 |
{ |
| 592 |
struct |
| 593 |
{ |
| 594 |
uint32_t m_meDelta4to7; |
| 595 |
}; |
| 596 |
struct |
| 597 |
{ |
| 598 |
uint32_t m_value; |
| 599 |
}; |
| 600 |
} DW33; |
| 601 |
|
| 602 |
union |
| 603 |
{ |
| 604 |
struct |
| 605 |
{ |
| 606 |
uint32_t m_meDelta8to11; |
| 607 |
}; |
| 608 |
struct |
| 609 |
{ |
| 610 |
uint32_t m_value; |
| 611 |
}; |
| 612 |
} DW34; |
| 613 |
|
| 614 |
union |
| 615 |
{ |
| 616 |
struct |
| 617 |
{ |
| 618 |
uint32_t m_meDelta12to15; |
| 619 |
}; |
| 620 |
struct |
| 621 |
{ |
| 622 |
uint32_t m_value; |
| 623 |
}; |
| 624 |
} DW35; |
| 625 |
|
| 626 |
union |
| 627 |
{ |
| 628 |
struct |
| 629 |
{ |
| 630 |
uint32_t m_meDelta16to19; |
| 631 |
}; |
| 632 |
struct |
| 633 |
{ |
| 634 |
uint32_t m_value; |
| 635 |
}; |
| 636 |
} DW36; |
| 637 |
|
| 638 |
union |
| 639 |
{ |
| 640 |
struct |
| 641 |
{ |
| 642 |
uint32_t m_meDelta20to23; |
| 643 |
}; |
| 644 |
struct |
| 645 |
{ |
| 646 |
uint32_t m_value; |
| 647 |
}; |
| 648 |
} DW37; |
| 649 |
|
| 650 |
union |
| 651 |
{ |
| 652 |
struct |
| 653 |
{ |
| 654 |
uint32_t m_meDelta24to27; |
| 655 |
}; |
| 656 |
struct |
| 657 |
{ |
| 658 |
uint32_t m_value; |
| 659 |
}; |
| 660 |
} DW38; |
| 661 |
|
| 662 |
union |
| 663 |
{ |
| 664 |
struct |
| 665 |
{ |
| 666 |
uint32_t m_meDelta28to31; |
| 667 |
}; |
| 668 |
struct |
| 669 |
{ |
| 670 |
uint32_t m_value; |
| 671 |
}; |
| 672 |
} DW39; |
| 673 |
|
| 674 |
union |
| 675 |
{ |
| 676 |
struct |
| 677 |
{ |
| 678 |
uint32_t m_meDelta32to35; |
| 679 |
}; |
| 680 |
struct |
| 681 |
{ |
| 682 |
uint32_t m_value; |
| 683 |
}; |
| 684 |
} DW40; |
| 685 |
|
| 686 |
union |
| 687 |
{ |
| 688 |
struct |
| 689 |
{ |
| 690 |
uint32_t m_meDelta36to39; |
| 691 |
}; |
| 692 |
struct |
| 693 |
{ |
| 694 |
uint32_t m_value; |
| 695 |
}; |
| 696 |
} DW41; |
| 697 |
|
| 698 |
union |
| 699 |
{ |
| 700 |
struct |
| 701 |
{ |
| 702 |
uint32_t m_meDelta40to43; |
| 703 |
}; |
| 704 |
struct |
| 705 |
{ |
| 706 |
uint32_t m_value; |
| 707 |
}; |
| 708 |
} DW42; |
| 709 |
|
| 710 |
union |
| 711 |
{ |
| 712 |
struct |
| 713 |
{ |
| 714 |
uint32_t m_meDelta44to47; |
| 715 |
}; |
| 716 |
struct |
| 717 |
{ |
| 718 |
uint32_t m_value; |
| 719 |
}; |
| 720 |
} DW43; |
| 721 |
|
| 722 |
union |
| 723 |
{ |
| 724 |
struct |
| 725 |
{ |
| 726 |
uint32_t m_meDelta48to51; |
| 727 |
}; |
| 728 |
struct |
| 729 |
{ |
| 730 |
uint32_t m_value; |
| 731 |
}; |
| 732 |
} DW44; |
| 733 |
|
| 734 |
union |
| 735 |
{ |
| 736 |
struct |
| 737 |
{ |
| 738 |
uint32_t m_meDelta52to55; |
| 739 |
}; |
| 740 |
struct |
| 741 |
{ |
| 742 |
uint32_t m_value; |
| 743 |
}; |
| 744 |
} DW45; |
| 745 |
|
| 746 |
struct |
| 747 |
{ |
| 748 |
union |
| 749 |
{ |
| 750 |
struct |
| 751 |
{ |
| 752 |
uint32_t m_mv0Cost_Interlaced : MOS_BITFIELD_RANGE(0, 7); |
| 753 |
uint32_t m_mv1Cost_Interlaced : MOS_BITFIELD_RANGE(8, 15); |
| 754 |
uint32_t m_mv2Cost_Interlaced : MOS_BITFIELD_RANGE(16, 23); |
| 755 |
uint32_t m_mv3Cost_Interlaced : MOS_BITFIELD_RANGE(24, 31); |
| 756 |
}; |
| 757 |
struct |
| 758 |
{ |
| 759 |
uint32_t m_value; |
| 760 |
}; |
| 761 |
} DW46; |
| 762 |
|
| 763 |
union |
| 764 |
{ |
| 765 |
struct |
| 766 |
{ |
| 767 |
uint32_t m_mv4Cost_Interlaced : MOS_BITFIELD_RANGE(0, 7); |
| 768 |
uint32_t m_mv5Cost_Interlaced : MOS_BITFIELD_RANGE(8, 15); |
| 769 |
uint32_t m_mv6Cost_Interlaced : MOS_BITFIELD_RANGE(16, 23); |
| 770 |
uint32_t m_mv7Cost_Interlaced : MOS_BITFIELD_RANGE(24, 31); |
| 771 |
}; |
| 772 |
struct |
| 773 |
{ |
| 774 |
uint32_t m_value; |
| 775 |
}; |
| 776 |
} DW47; |
| 777 |
} MvCostInterlace; |
| 778 |
} VmeSPath1; |
| 779 |
|
| 780 |
union |
| 781 |
{ |
| 782 |
struct |
| 783 |
{ |
| 784 |
uint32_t m_batchBufferEnd; |
| 785 |
}; |
| 786 |
struct |
| 787 |
{ |
| 788 |
uint32_t m_value; |
| 789 |
}; |
| 790 |
} DW48; |
| 791 |
|
| 792 |
union |
| 793 |
{ |
| 794 |
struct |
| 795 |
{ |
| 796 |
uint32_t m_pakObjCmds; |
| 797 |
}; |
| 798 |
struct |
| 799 |
{ |
| 800 |
uint32_t m_value; |
| 801 |
}; |
| 802 |
} DW49; |
| 803 |
|
| 804 |
union |
| 805 |
{ |
| 806 |
struct |
| 807 |
{ |
| 808 |
uint32_t m_prevmPakObjCmds; |
| 809 |
}; |
| 810 |
struct |
| 811 |
{ |
| 812 |
uint32_t m_value; |
| 813 |
}; |
| 814 |
} DW50; |
| 815 |
|
| 816 |
union |
| 817 |
{ |
| 818 |
struct |
| 819 |
{ |
| 820 |
uint32_t m_currPicY; |
| 821 |
}; |
| 822 |
struct |
| 823 |
{ |
| 824 |
uint32_t m_value; |
| 825 |
}; |
| 826 |
} DW51; |
| 827 |
|
| 828 |
union |
| 829 |
{ |
| 830 |
struct |
| 831 |
{ |
| 832 |
uint32_t m_currFwdBwdRef; |
| 833 |
}; |
| 834 |
struct |
| 835 |
{ |
| 836 |
uint32_t m_value; |
| 837 |
}; |
| 838 |
} DW52; |
| 839 |
|
| 840 |
union |
| 841 |
{ |
| 842 |
struct |
| 843 |
{ |
| 844 |
uint32_t m_currBwdRef; |
| 845 |
}; |
| 846 |
struct |
| 847 |
{ |
| 848 |
uint32_t m_value; |
| 849 |
}; |
| 850 |
} DW53; |
| 851 |
|
| 852 |
union |
| 853 |
{ |
| 854 |
struct |
| 855 |
{ |
| 856 |
uint32_t m_distSurf4x; |
| 857 |
}; |
| 858 |
struct |
| 859 |
{ |
| 860 |
uint32_t m_value; |
| 861 |
}; |
| 862 |
} DW54; |
| 863 |
|
| 864 |
union |
| 865 |
{ |
| 866 |
struct |
| 867 |
{ |
| 868 |
uint32_t m_mbControl; |
| 869 |
}; |
| 870 |
struct |
| 871 |
{ |
| 872 |
uint32_t m_value; |
| 873 |
}; |
| 874 |
} DW55; |
| 875 |
|
| 876 |
union |
| 877 |
{ |
| 878 |
struct |
| 879 |
{ |
| 880 |
uint32_t softwareScoreboard; |
| 881 |
}; |
| 882 |
struct |
| 883 |
{ |
| 884 |
uint32_t m_value; |
| 885 |
}; |
| 886 |
} DW56; |
| 887 |
|
| 888 |
union |
| 889 |
{ |
| 890 |
struct |
| 891 |
{ |
| 892 |
uint32_t m_reserved; |
| 893 |
}; |
| 894 |
struct |
| 895 |
{ |
| 896 |
uint32_t m_value; |
| 897 |
}; |
| 898 |
} DW57; |
| 899 |
|
| 900 |
union |
| 901 |
{ |
| 902 |
struct |
| 903 |
{ |
| 904 |
uint32_t m_reserved; |
| 905 |
}; |
| 906 |
struct |
| 907 |
{ |
| 908 |
uint32_t m_value; |
| 909 |
}; |
| 910 |
} DW58; |
| 911 |
|
| 912 |
union |
| 913 |
{ |
| 914 |
struct |
| 915 |
{ |
| 916 |
uint32_t m_reserved; |
| 917 |
}; |
| 918 |
struct |
| 919 |
{ |
| 920 |
uint32_t m_value; |
| 921 |
}; |
| 922 |
} DW59; |
| 923 |
|
| 924 |
union |
| 925 |
{ |
| 926 |
struct |
| 927 |
{ |
| 928 |
uint32_t m_reserved; |
| 929 |
}; |
| 930 |
struct |
| 931 |
{ |
| 932 |
uint32_t m_value; |
| 933 |
}; |
| 934 |
} DW60; |
| 935 |
|
| 936 |
union |
| 937 |
{ |
| 938 |
struct |
| 939 |
{ |
| 940 |
uint32_t m_reserved; |
| 941 |
}; |
| 942 |
struct |
| 943 |
{ |
| 944 |
uint32_t m_value; |
| 945 |
}; |
| 946 |
} DW61; |
| 947 |
|
| 948 |
union |
| 949 |
{ |
| 950 |
struct |
| 951 |
{ |
| 952 |
uint32_t m_reserved; |
| 953 |
}; |
| 954 |
struct |
| 955 |
{ |
| 956 |
uint32_t m_value; |
| 957 |
}; |
| 958 |
} DW62; |
| 959 |
|
| 960 |
union |
| 961 |
{ |
| 962 |
struct |
| 963 |
{ |
| 964 |
uint32_t m_reserved; |
| 965 |
}; |
| 966 |
struct |
| 967 |
{ |
| 968 |
uint32_t m_value; |
| 969 |
}; |
| 970 |
} DW63; |
| 971 |
}m_curbeData; |
| 972 |
|
| 973 |
//! |
| 974 |
//! \brief Constructor |
| 975 |
//! |
| 976 |
MbEncCurbeG11(uint8_t codingType); |
| 977 |
|
| 978 |
//! |
| 979 |
//! \brief Destructor |
| 980 |
//! |
| 981 |
~MbEncCurbeG11(){}; |
| 982 |
|
| 983 |
static const size_t m_byteSize = sizeof(CurbeData); |
| 984 |
}; |
| 985 |
|
| 986 |
MbEncCurbeG11::MbEncCurbeG11(uint8_t codingType) |
| 987 |
{ |
| 988 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 989 |
|
| 990 |
MOS_ZeroMemory(&m_curbeData, m_byteSize); |
| 991 |
|
| 992 |
m_curbeData.DW0.m_value = 0x00000023; |
| 993 |
switch (codingType) |
| 994 |
{ |
| 995 |
case I_TYPE: |
| 996 |
m_curbeData.DW1.m_value = 0x00200020; |
| 997 |
m_curbeData.DW2.m_value = 0x00000000; |
| 998 |
m_curbeData.DW4.m_value = 0x00000000; |
| 999 |
m_curbeData.DW7.m_value = 0x00050066; |
| 1000 |
m_curbeData.DW8.m_value = 0x00000000; |
| 1001 |
m_curbeData.DW9.m_value = 0x7EA41000; |
| 1002 |
m_curbeData.DW10.m_value = 0x0000FF00; |
| 1003 |
break; |
| 1004 |
case P_TYPE: |
| 1005 |
m_curbeData.DW1.m_value = 0x00200020; |
| 1006 |
m_curbeData.DW2.m_value = 0x00001009; |
| 1007 |
m_curbeData.DW4.m_value = 0x20000000; |
| 1008 |
m_curbeData.DW7.m_value = 0x00050066; |
| 1009 |
m_curbeData.DW8.m_value = 0x00000041; |
| 1010 |
m_curbeData.DW9.m_value = 0x7EA41000; |
| 1011 |
m_curbeData.DW10.m_value = 0x2830FF00; |
| 1012 |
break; |
| 1013 |
case B_TYPE: |
| 1014 |
default: |
| 1015 |
m_curbeData.DW1.m_value = 0x10200010; |
| 1016 |
m_curbeData.DW2.m_value = 0x00001005; |
| 1017 |
m_curbeData.DW4.m_value = 0x40000000; |
| 1018 |
m_curbeData.DW7.m_value = 0xFF050066; |
| 1019 |
m_curbeData.DW8.m_value = 0x00000041; |
| 1020 |
m_curbeData.DW9.m_value = 0x7EA01000; |
| 1021 |
m_curbeData.DW10.m_value = 0x2020FF00; |
| 1022 |
break; |
| 1023 |
|
| 1024 |
} |
| 1025 |
|
| 1026 |
m_curbeData.DW3.m_value = 0xFE0C0000; |
| 1027 |
m_curbeData.MvCost.DW5.m_value = 0x00000000; |
| 1028 |
m_curbeData.MvCost.DW6.m_value = 0x00000000; |
| 1029 |
m_curbeData.DW11.m_value = 0x5A325300; |
| 1030 |
m_curbeData.DW12.m_value = 0x0000FF00; |
| 1031 |
m_curbeData.DW13.m_value = 0x00FF0000; |
| 1032 |
|
| 1033 |
} |
| 1034 |
|
| 1035 |
CodechalEncodeMpeg2G11::CodechalEncodeMpeg2G11( |
| 1036 |
CodechalHwInterface* hwInterface, |
| 1037 |
CodechalDebugInterface* debugInterface, |
| 1038 |
PCODECHAL_STANDARD_INFO standardInfo) |
| 1039 |
:CodechalEncodeMpeg2(hwInterface, debugInterface, standardInfo), |
| 1040 |
m_sinlgePipeVeState(nullptr) |
| 1041 |
{ |
| 1042 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1043 |
|
| 1044 |
CODECHAL_ENCODE_CHK_NULL_NO_STATUS_RETURN(m_osInterface); |
| 1045 |
|
| 1046 |
m_kuidCommon = IDR_CODEC_HME_DS_SCOREBOARD_KERNEL; |
| 1047 |
|
| 1048 |
m_osInterface->pfnVirtualEngineSupported(m_osInterface, false, true); |
| 1049 |
|
| 1050 |
pfnGetKernelHeaderAndSize = GetKernelHeaderAndSize; |
| 1051 |
uint8_t *kernelBase = nullptr; |
| 1052 |
#ifndef _FULL_OPEN_SOURCE |
| 1053 |
// ICL and ICLLP use different kernels |
| 1054 |
if (GFX_IS_PRODUCT(m_hwInterface->GetPlatform(), IGFX_ICELAKE)) |
| 1055 |
{ |
| 1056 |
kernelBase = (uint8_t *)IGCODECKRN_G11; |
| 1057 |
} |
| 1058 |
else |
| 1059 |
{ |
| 1060 |
kernelBase = (uint8_t *)IGCODECKRN_G11_ICLLP; |
| 1061 |
} |
| 1062 |
#endif |
| 1063 |
m_useHwScoreboard = false; |
| 1064 |
m_useCommonKernel = true; |
| 1065 |
|
| 1066 |
MOS_STATUS eStatus = CodecHalGetKernelBinaryAndSize( |
| 1067 |
kernelBase, |
| 1068 |
m_kuid, |
| 1069 |
&m_kernelBinary, |
| 1070 |
&m_combinedKernelSize); |
| 1071 |
|
| 1072 |
// Virtual Engine is enabled in default |
| 1073 |
Mos_SetVirtualEngineSupported(m_osInterface, true); |
| 1074 |
|
| 1075 |
CODECHAL_ENCODE_ASSERT(eStatus == MOS_STATUS_SUCCESS); |
| 1076 |
|
| 1077 |
m_hwInterface->GetStateHeapSettings()->dwIshSize += |
| 1078 |
MOS_ALIGN_CEIL(m_combinedKernelSize, (1 << MHW_KERNEL_OFFSET_SHIFT)); |
| 1079 |
|
| 1080 |
m_vdboxOneDefaultUsed = true; |
| 1081 |
} |
| 1082 |
|
| 1083 |
CodechalEncodeMpeg2G11::~CodechalEncodeMpeg2G11() |
| 1084 |
{ |
| 1085 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1086 |
|
| 1087 |
if (m_swScoreboardState) |
| 1088 |
{ |
| 1089 |
MOS_Delete(m_swScoreboardState); |
| 1090 |
m_swScoreboardState = nullptr; |
| 1091 |
} |
| 1092 |
|
| 1093 |
if (m_sinlgePipeVeState) |
| 1094 |
{ |
| 1095 |
MOS_FreeMemAndSetNull(m_sinlgePipeVeState); |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
MOS_STATUS CodechalEncodeMpeg2G11::Initialize(CodechalSetting * codecHalSettings) |
| 1100 |
{ |
| 1101 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1102 |
|
| 1103 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1104 |
|
| 1105 |
// common initilization |
| 1106 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncodeMpeg2::Initialize(codecHalSettings)); |
| 1107 |
|
| 1108 |
if (MOS_VE_SUPPORTED(m_osInterface)) |
| 1109 |
{ |
| 1110 |
m_sinlgePipeVeState = (PCODECHAL_ENCODE_SINGLEPIPE_VIRTUALENGINE_STATE)MOS_AllocAndZeroMemory(sizeof(CODECHAL_ENCODE_SINGLEPIPE_VIRTUALENGINE_STATE)); |
| 1111 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_sinlgePipeVeState); |
| 1112 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeSinglePipeVE_InitInterface(m_hwInterface, m_sinlgePipeVeState)); |
| 1113 |
} |
| 1114 |
|
| 1115 |
return eStatus; |
| 1116 |
} |
| 1117 |
|
| 1118 |
uint32_t CodechalEncodeMpeg2G11::GetMaxBtCount() |
| 1119 |
{ |
| 1120 |
uint32_t scalingBtCount = MOS_ALIGN_CEIL( |
| 1121 |
m_scaling4xKernelStates[0].KernelParams.iBTCount, |
| 1122 |
m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment()); |
| 1123 |
uint32_t meBtCount = MOS_ALIGN_CEIL( |
| 1124 |
m_hmeKernel ? m_hmeKernel->GetBTCount() : 0 , |
| 1125 |
m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment()); |
| 1126 |
uint32_t mbEncBtCount = MOS_ALIGN_CEIL( |
| 1127 |
m_mbEncKernelStates[0].KernelParams.iBTCount, |
| 1128 |
m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment()); |
| 1129 |
|
| 1130 |
uint32_t brcBtCount = 0; |
| 1131 |
for (uint32_t i = 0; i < CODECHAL_ENCODE_BRC_IDX_NUM; i++) |
| 1132 |
{ |
| 1133 |
brcBtCount += MOS_ALIGN_CEIL( |
| 1134 |
m_brcKernelStates[i].KernelParams.iBTCount, |
| 1135 |
m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment()); |
| 1136 |
} |
| 1137 |
|
| 1138 |
uint32_t swScoreboardBtCount = 0; |
| 1139 |
if (!m_useHwScoreboard) |
| 1140 |
{ |
| 1141 |
swScoreboardBtCount = MOS_ALIGN_CEIL( |
| 1142 |
m_swScoreboardState->GetBTCount(), |
| 1143 |
m_stateHeapInterface->pStateHeapInterface->GetBtIdxAlignment()); |
| 1144 |
} |
| 1145 |
|
| 1146 |
return MOS_MAX(scalingBtCount + meBtCount, mbEncBtCount + brcBtCount + swScoreboardBtCount); |
| 1147 |
} |
| 1148 |
|
| 1149 |
MOS_STATUS CodechalEncodeMpeg2G11::GetKernelHeaderAndSize( |
| 1150 |
void *binary, |
| 1151 |
EncOperation operation, |
| 1152 |
uint32_t krnStateIdx, |
| 1153 |
void *krnHeader, |
| 1154 |
uint32_t *krnSize) |
| 1155 |
{ |
| 1156 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1157 |
|
| 1158 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1159 |
|
| 1160 |
CODECHAL_ENCODE_CHK_NULL_RETURN(binary); |
| 1161 |
CODECHAL_ENCODE_CHK_NULL_RETURN(krnHeader); |
| 1162 |
CODECHAL_ENCODE_CHK_NULL_RETURN(krnSize); |
| 1163 |
|
| 1164 |
auto kernelHeaderTable = (KernelHeaderMpegG11 *)binary; |
| 1165 |
PCODECHAL_KERNEL_HEADER currKrnHeader; |
| 1166 |
|
| 1167 |
if (operation == ENC_BRC) |
| 1168 |
{ |
| 1169 |
currKrnHeader = &kernelHeaderTable->m_mpeg2InitFrameBrc; |
| 1170 |
} |
| 1171 |
else if (operation == ENC_MBENC) |
| 1172 |
{ |
| 1173 |
currKrnHeader = &kernelHeaderTable->m_mpeg2MbEncI; |
| 1174 |
} |
| 1175 |
else |
| 1176 |
{ |
| 1177 |
CODECHAL_ENCODE_ASSERTMESSAGE("Unsupported ENC mode requested"); |
| 1178 |
eStatus = MOS_STATUS_INVALID_PARAMETER; |
| 1179 |
return eStatus; |
| 1180 |
} |
| 1181 |
|
| 1182 |
currKrnHeader += krnStateIdx; |
| 1183 |
*((PCODECHAL_KERNEL_HEADER)krnHeader) = *currKrnHeader; |
| 1184 |
|
| 1185 |
PCODECHAL_KERNEL_HEADER invalidEntry = &(kernelHeaderTable->m_mpeg2BrcResetFrame) + 1; |
| 1186 |
PCODECHAL_KERNEL_HEADER nextKrnHeader = (currKrnHeader + 1); |
| 1187 |
uint32_t nextKrnOffset = *krnSize; |
| 1188 |
|
| 1189 |
if (nextKrnHeader < invalidEntry) |
| 1190 |
{ |
| 1191 |
nextKrnOffset = nextKrnHeader->KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT; |
| 1192 |
} |
| 1193 |
*krnSize = nextKrnOffset - (currKrnHeader->KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT); |
| 1194 |
|
| 1195 |
return eStatus; |
| 1196 |
} |
| 1197 |
|
| 1198 |
MOS_STATUS CodechalEncodeMpeg2G11::InitKernelState() |
| 1199 |
{ |
| 1200 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1201 |
|
| 1202 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1203 |
|
| 1204 |
// Init kernel state |
| 1205 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitKernelStateMbEnc()); |
| 1206 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(InitKernelStateBrc()); |
| 1207 |
|
| 1208 |
// Create SW scoreboard init kernel state |
| 1209 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_swScoreboardState = MOS_New(CodechalEncodeSwScoreboardG11, this)); |
| 1210 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_swScoreboardState->InitKernelState()); |
| 1211 |
|
| 1212 |
// Create hme kernel |
| 1213 |
m_hmeKernel = MOS_New(CodechalKernelHmeG11, this, true); |
| 1214 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_hmeKernel); |
| 1215 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hmeKernel->Initialize( |
| 1216 |
GetCommonKernelHeaderAndSizeG11, |
| 1217 |
m_kernelBase, |
| 1218 |
m_kuidCommon)); |
| 1219 |
return eStatus; |
| 1220 |
} |
| 1221 |
|
| 1222 |
MOS_STATUS CodechalEncodeMpeg2G11::InitKernelStateMbEnc() |
| 1223 |
{ |
| 1224 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1225 |
|
| 1226 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1227 |
|
| 1228 |
for (uint8_t krnStateIdx = 0; krnStateIdx < mbEncKernelIdxNum; krnStateIdx++) |
| 1229 |
{ |
| 1230 |
auto kernelStatePtr = &m_mbEncKernelStates[krnStateIdx]; |
| 1231 |
auto kernelSize = m_combinedKernelSize; |
| 1232 |
|
| 1233 |
CODECHAL_KERNEL_HEADER currKrnHeader; |
| 1234 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(pfnGetKernelHeaderAndSize( |
| 1235 |
m_kernelBinary, |
| 1236 |
ENC_MBENC, |
| 1237 |
krnStateIdx, |
| 1238 |
&currKrnHeader, |
| 1239 |
&kernelSize)); |
| 1240 |
|
| 1241 |
kernelStatePtr->KernelParams.iBTCount = mbEncNumBindingTableEntries; |
| 1242 |
kernelStatePtr->KernelParams.iThreadCount = m_hwInterface->GetRenderInterface()->GetHwCaps()->dwMaxThreads; |
| 1243 |
kernelStatePtr->KernelParams.iCurbeLength = MbEncCurbeG11::m_byteSize; |
| 1244 |
kernelStatePtr->KernelParams.iBlockWidth = CODECHAL_MACROBLOCK_WIDTH; |
| 1245 |
kernelStatePtr->KernelParams.iBlockHeight = CODECHAL_MACROBLOCK_HEIGHT; |
| 1246 |
kernelStatePtr->KernelParams.iIdCount = 1; |
| 1247 |
|
| 1248 |
kernelStatePtr->dwCurbeOffset = m_stateHeapInterface->pStateHeapInterface->GetSizeofCmdInterfaceDescriptorData(); |
| 1249 |
kernelStatePtr->KernelParams.pBinary = m_kernelBinary + (currKrnHeader.KernelStartPointer << MHW_KERNEL_OFFSET_SHIFT); |
| 1250 |
kernelStatePtr->KernelParams.iSize = kernelSize; |
| 1251 |
|
| 1252 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_stateHeapInterface->pfnCalculateSshAndBtSizesRequested( |
| 1253 |
m_stateHeapInterface, |
| 1254 |
kernelStatePtr->KernelParams.iBTCount, |
| 1255 |
&kernelStatePtr->dwSshSize, |
| 1256 |
&kernelStatePtr->dwBindingTableSize)); |
| 1257 |
|
| 1258 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hwInterface->MhwInitISH(m_stateHeapInterface, kernelStatePtr)); |
| 1259 |
} |
| 1260 |
|
| 1261 |
m_mbEncBindingTable.m_mbEncPakObj = mbEncPakObj; |
| 1262 |
m_mbEncBindingTable.m_mbEncPakObjPrev = mbEncPakObjPrev; |
| 1263 |
m_mbEncBindingTable.m_mbEncCurrentY = mbEncCurrentY; |
| 1264 |
m_mbEncBindingTable.m_mbEncBrcDistortionSurface = mbEncBrcDistortionSurface; |
| 1265 |
m_mbEncBindingTable.m_mbEncCurrentPic = mbEncCurrentPic; |
| 1266 |
m_mbEncBindingTable.m_mbEncForwardPic = mbEncForwardPic; |
| 1267 |
m_mbEncBindingTable.m_mbEncBackwardPic = mbEncBackwardPic; |
| 1268 |
m_mbEncBindingTable.m_mbEncInterlaceFrameCurrentPic = mbEncInterlaceFrameCurrentPic; |
| 1269 |
m_mbEncBindingTable.m_mbEncInterlaceFrameBackwardPic = mbEncInterlaceFrameBackwardPic; |
| 1270 |
m_mbEncBindingTable.m_mbEncMbControl = mbEncMbControl; |
| 1271 |
m_mbEncBindingTable.m_mbEncScoreboard = mbEncSwScoreboard; |
| 1272 |
|
| 1273 |
return eStatus; |
| 1274 |
} |
| 1275 |
|
| 1276 |
MOS_STATUS CodechalEncodeMpeg2G11::SetAndPopulateVEHintParams( |
| 1277 |
PMOS_COMMAND_BUFFER cmdBuffer) |
| 1278 |
{ |
| 1279 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1280 |
|
| 1281 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1282 |
|
| 1283 |
if (!MOS_VE_SUPPORTED(m_osInterface)) |
| 1284 |
{ |
| 1285 |
return eStatus; |
| 1286 |
} |
| 1287 |
|
| 1288 |
if (!MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface)) |
| 1289 |
{ |
| 1290 |
MOS_VIRTUALENGINE_SET_PARAMS vesetParams; |
| 1291 |
MOS_ZeroMemory(&vesetParams, sizeof(vesetParams)); |
| 1292 |
vesetParams.bNeedSyncWithPrevious = true; |
| 1293 |
vesetParams.bSFCInUse = false; |
| 1294 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeSinglePipeVE_SetHintParams(m_sinlgePipeVeState, &vesetParams)); |
| 1295 |
} |
| 1296 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeSinglePipeVE_PopulateHintParams(m_sinlgePipeVeState, cmdBuffer, true)); |
| 1297 |
|
| 1298 |
return eStatus; |
| 1299 |
} |
| 1300 |
|
| 1301 |
MOS_STATUS CodechalEncodeMpeg2G11::ExecuteSliceLevel() |
| 1302 |
{ |
| 1303 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1304 |
|
| 1305 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1306 |
|
| 1307 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_osInterface->osCpInterface); |
| 1308 |
|
| 1309 |
auto cpInterface = m_hwInterface->GetCpInterface(); |
| 1310 |
|
| 1311 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 1312 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, &cmdBuffer, 0)); |
| 1313 |
|
| 1314 |
if (m_osInterface->osCpInterface->IsCpEnabled()) |
| 1315 |
{ |
| 1316 |
MHW_CP_SLICE_INFO_PARAMS sliceInfoParam; |
| 1317 |
sliceInfoParam.bLastPass = (m_currPass == m_numPasses) ? true : false; |
| 1318 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(cpInterface->SetMfxProtectionState(m_mfxInterface->IsDecodeInUse(), &cmdBuffer, nullptr, &sliceInfoParam)); |
| 1319 |
|
| 1320 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(cpInterface->UpdateParams(false)); |
| 1321 |
} |
| 1322 |
|
| 1323 |
MHW_VDBOX_MPEG2_SLICE_STATE sliceState; |
| 1324 |
MOS_ZeroMemory(&sliceState, sizeof(sliceState)); |
| 1325 |
sliceState.presDataBuffer = &m_resMbCodeSurface; |
| 1326 |
sliceState.pMpeg2PicIdx = &(m_picIdx[0]); |
| 1327 |
sliceState.ppMpeg2RefList = &(m_refList[0]); |
| 1328 |
sliceState.pEncodeMpeg2SeqParams = m_seqParams; |
| 1329 |
sliceState.pEncodeMpeg2PicParams = m_picParams; |
| 1330 |
sliceState.pEncodeMpeg2SliceParams = m_sliceParams; |
| 1331 |
sliceState.pBsBuffer = &m_bsBuffer; |
| 1332 |
sliceState.bBrcEnabled = m_brcEnabled; |
| 1333 |
if (m_seqParams->m_forcePanicModeControl == 1) { |
| 1334 |
sliceState.bRCPanicEnable = !m_seqParams->m_panicModeDisable; |
| 1335 |
} |
| 1336 |
else { |
| 1337 |
sliceState.bRCPanicEnable = m_panicEnable; |
| 1338 |
} |
| 1339 |
sliceState.presPicHeaderBBSurf = &m_brcBuffers.resBrcPicHeaderOutputBuffer; |
| 1340 |
|
| 1341 |
for (uint16_t slcCount = 0; slcCount < m_numSlices; slcCount++) |
| 1342 |
{ |
| 1343 |
//we should not need to call pfnPackSliceHeader this it's done by hw |
| 1344 |
PCODEC_ENCODER_SLCDATA slcData = m_slcData; |
| 1345 |
CODECHAL_ENCODE_CHK_NULL_RETURN(slcData); |
| 1346 |
sliceState.dwDataBufferOffset = |
| 1347 |
m_slcData[slcCount].CmdOffset + m_mbcodeBottomFieldOffset; |
| 1348 |
sliceState.dwOffset = slcData[slcCount].SliceOffset; |
| 1349 |
sliceState.dwLength = slcData[slcCount].BitSize; |
| 1350 |
sliceState.dwSliceIndex = slcCount; |
| 1351 |
sliceState.bFirstPass = true; |
| 1352 |
sliceState.bLastPass = false; |
| 1353 |
sliceState.pSlcData = &slcData[slcCount]; |
| 1354 |
sliceState.bFirstPass = (m_currPass == 0); |
| 1355 |
sliceState.bLastPass = (m_currPass == m_numPasses); |
| 1356 |
|
| 1357 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SendSliceParams(&cmdBuffer, &sliceState)); |
| 1358 |
} |
| 1359 |
|
| 1360 |
// Insert end of stream if set |
| 1361 |
if (m_lastPicInStream) |
| 1362 |
{ |
| 1363 |
MHW_VDBOX_PAK_INSERT_PARAMS pakInsertObjectParams; |
| 1364 |
MOS_ZeroMemory(&pakInsertObjectParams, sizeof(pakInsertObjectParams)); |
| 1365 |
pakInsertObjectParams.bLastPicInStream = true; |
| 1366 |
if (m_codecFunction == CODECHAL_FUNCTION_ENC_PAK) |
| 1367 |
{ |
| 1368 |
pakInsertObjectParams.bSetLastPicInStreamData = true; |
| 1369 |
pakInsertObjectParams.dwBitSize = 32; // use dwBitSize for SrcDataEndingBitInclusion |
| 1370 |
pakInsertObjectParams.dwLastPicInStreamData = (uint32_t)((1 << 16) | startCodeSequenceEnd << 24); |
| 1371 |
} |
| 1372 |
else |
| 1373 |
{ |
| 1374 |
pakInsertObjectParams.bSetLastPicInStreamData = false; |
| 1375 |
pakInsertObjectParams.dwBitSize = 8; // use dwBitSize for SrcDataEndingBitInclusion |
| 1376 |
pakInsertObjectParams.dwLastPicInStreamData = 0; |
| 1377 |
} |
| 1378 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_mfxInterface->AddMfxPakInsertObject(&cmdBuffer, nullptr, &pakInsertObjectParams)); |
| 1379 |
} |
| 1380 |
|
| 1381 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReadMfcStatus(&cmdBuffer)); |
| 1382 |
|
| 1383 |
// BRC PAK statistics different for each pass |
| 1384 |
if (m_brcEnabled) |
| 1385 |
{ |
| 1386 |
uint32_t frameOffset = |
| 1387 |
(m_encodeStatusBuf.wCurrIndex * m_encodeStatusBuf.dwReportSize) + |
| 1388 |
m_encodeStatusBuf.dwNumPassesOffset + // Num passes offset |
| 1389 |
sizeof(uint32_t) * 2; // pEncodeStatus is offset by 2 DWs in the resource |
| 1390 |
|
| 1391 |
EncodeReadBrcPakStatsParams readBrcPakStatsParams; |
| 1392 |
readBrcPakStatsParams.pHwInterface = m_hwInterface; |
| 1393 |
readBrcPakStatsParams.presBrcPakStatisticBuffer = &m_brcBuffers.resBrcPakStatisticBuffer[0]; |
| 1394 |
readBrcPakStatsParams.presStatusBuffer = &m_encodeStatusBuf.resStatusBuffer; |
| 1395 |
readBrcPakStatsParams.dwStatusBufNumPassesOffset = frameOffset; |
| 1396 |
readBrcPakStatsParams.ucPass = m_currPass; |
| 1397 |
readBrcPakStatsParams.VideoContext = m_videoContext; |
| 1398 |
|
| 1399 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(ReadBrcPakStatistics( |
| 1400 |
&cmdBuffer, |
| 1401 |
&readBrcPakStatsParams)); |
| 1402 |
} |
| 1403 |
|
| 1404 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EndStatusReport( |
| 1405 |
&cmdBuffer, |
| 1406 |
CODECHAL_NUM_MEDIA_STATES)); |
| 1407 |
|
| 1408 |
if (!m_singleTaskPhaseSupported || m_lastTaskInPhase) |
| 1409 |
{ |
| 1410 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_miInterface->AddMiBatchBufferEnd( |
| 1411 |
&cmdBuffer, |
| 1412 |
nullptr)); |
| 1413 |
} |
| 1414 |
|
| 1415 |
std::string Pak_pass = "PAK_PASS[" + std::to_string(static_cast<uint32_t>(m_currPass)) + "]"; |
| 1416 |
CODECHAL_DEBUG_TOOL( |
| 1417 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCmdBuffer( |
| 1418 |
&cmdBuffer, |
| 1419 |
CODECHAL_NUM_MEDIA_STATES, |
| 1420 |
Pak_pass.c_str())); |
| 1421 |
|
| 1422 |
//CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHal_DbgReplaceAllCommands( |
| 1423 |
// m_debugInterface, |
| 1424 |
// &cmdBuffer)); |
| 1425 |
) |
| 1426 |
|
| 1427 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0); |
| 1428 |
|
| 1429 |
MOS_SYNC_PARAMS syncParams; |
| 1430 |
if ((m_currPass == 0) && |
| 1431 |
!Mos_ResourceIsNull(&m_resSyncObjectRenderContextInUse)) |
| 1432 |
{ |
| 1433 |
syncParams = g_cInitSyncParams; |
| 1434 |
syncParams.GpuContext = m_videoContext; |
| 1435 |
syncParams.presSyncResource = &m_resSyncObjectRenderContextInUse; |
| 1436 |
|
| 1437 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineWait(m_osInterface, &syncParams)); |
| 1438 |
} |
| 1439 |
|
| 1440 |
if (!m_singleTaskPhaseSupported || |
| 1441 |
m_lastTaskInPhase) |
| 1442 |
{ |
| 1443 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(SetAndPopulateVEHintParams(&cmdBuffer)); |
| 1444 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnSubmitCommandBuffer( |
| 1445 |
m_osInterface, |
| 1446 |
&cmdBuffer, |
| 1447 |
m_videoContextUsesNullHw)); |
| 1448 |
|
| 1449 |
CODECHAL_DEBUG_TOOL( |
| 1450 |
if (m_mmcState) |
| 1451 |
{ |
| 1452 |
m_mmcState->UpdateUserFeatureKey(&m_reconSurface); |
| 1453 |
} |
| 1454 |
) |
| 1455 |
|
| 1456 |
if ((m_currPass == m_numPasses) && |
| 1457 |
m_signalEnc && |
| 1458 |
!Mos_ResourceIsNull(&m_resSyncObjectVideoContextInUse)) |
| 1459 |
{ |
| 1460 |
// Check if the signal obj count exceeds max m_value |
| 1461 |
if (m_semaphoreObjCount == MOS_MIN(m_semaphoreMaxCount, MOS_MAX_OBJECT_SIGNALED)) |
| 1462 |
{ |
| 1463 |
syncParams = g_cInitSyncParams; |
| 1464 |
syncParams.GpuContext = m_renderContext; |
| 1465 |
syncParams.presSyncResource = &m_resSyncObjectVideoContextInUse; |
| 1466 |
|
| 1467 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineWait(m_osInterface, &syncParams)); |
| 1468 |
m_semaphoreObjCount--; |
| 1469 |
} |
| 1470 |
|
| 1471 |
// signal semaphore |
| 1472 |
syncParams = g_cInitSyncParams; |
| 1473 |
syncParams.GpuContext = m_videoContext; |
| 1474 |
syncParams.presSyncResource = &m_resSyncObjectVideoContextInUse; |
| 1475 |
|
| 1476 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineSignal(m_osInterface, &syncParams)); |
| 1477 |
m_semaphoreObjCount++; |
| 1478 |
} |
| 1479 |
} |
| 1480 |
|
| 1481 |
// Reset parameters for next PAK execution |
| 1482 |
if (m_currPass == m_numPasses) |
| 1483 |
{ |
| 1484 |
m_newPpsHeader = 0; |
| 1485 |
m_newSeqHeader = 0; |
| 1486 |
} |
| 1487 |
|
| 1488 |
return eStatus; |
| 1489 |
} |
| 1490 |
|
| 1491 |
MOS_STATUS CodechalEncodeMpeg2G11::EncodeMeKernel() |
| 1492 |
{ |
| 1493 |
CodechalKernelHme::CurbeParam curbeParam = {}; |
| 1494 |
curbeParam.subPelMode = 3; |
| 1495 |
curbeParam.currOriginalPic = m_picParams->m_currOriginalPic; |
| 1496 |
curbeParam.qpPrimeY = m_mvCostTableOffset; |
| 1497 |
// This parameter is used to select correct mode mv cost |
| 1498 |
// and search path from the predefined tables specifically |
| 1499 |
// for Mpeg2 BRC encoding path |
| 1500 |
curbeParam.targetUsage = 8; |
| 1501 |
curbeParam.maxMvLen = 128; |
| 1502 |
curbeParam.numRefIdxL0Minus1 = 0; |
| 1503 |
curbeParam.numRefIdxL1Minus1 = 0; |
| 1504 |
|
| 1505 |
CODEC_PICTURE l0RefFrameList = m_picParams->m_refFrameList[0]; |
| 1506 |
// no need to modify index if picture is invalid |
| 1507 |
if (l0RefFrameList.PicFlags != PICTURE_INVALID) |
| 1508 |
{ |
| 1509 |
l0RefFrameList.FrameIdx = 0; |
| 1510 |
} |
| 1511 |
|
| 1512 |
CODEC_PICTURE l1RefFrameList = m_picParams->m_refFrameList[1]; |
| 1513 |
// no need to modify index if picture is invalid |
| 1514 |
if (l1RefFrameList.PicFlags != PICTURE_INVALID) |
| 1515 |
{ |
| 1516 |
l1RefFrameList.FrameIdx = 1; |
| 1517 |
} |
| 1518 |
|
| 1519 |
CodechalKernelHme::SurfaceParams surfaceParam = {}; |
| 1520 |
surfaceParam.numRefIdxL0ActiveMinus1 = 0; |
| 1521 |
surfaceParam.numRefIdxL1ActiveMinus1 = 0; |
| 1522 |
surfaceParam.refList = &m_refList[0]; |
| 1523 |
surfaceParam.picIdx = &m_picIdx[0]; |
| 1524 |
surfaceParam.currOriginalPic = &m_currOriginalPic; |
| 1525 |
surfaceParam.refL0List = &l0RefFrameList; |
| 1526 |
surfaceParam.refL1List = &l1RefFrameList; |
| 1527 |
surfaceParam.meBrcDistortionBuffer = &m_brcBuffers.sMeBrcDistortionBuffer; |
| 1528 |
surfaceParam.meBrcDistortionBottomFieldOffset = m_brcBuffers.dwMeBrcDistortionBottomFieldOffset; |
| 1529 |
surfaceParam.downScaledWidthInMb = m_downscaledWidthInMb4x; |
| 1530 |
surfaceParam.downScaledHeightInMb = m_downscaledHeightInMb4x; |
| 1531 |
surfaceParam.downScaledBottomFieldOffset = m_scaledBottomFieldOffset; |
| 1532 |
surfaceParam.verticalLineStride = m_verticalLineStride; |
| 1533 |
surfaceParam.verticalLineStrideOffset = m_verticalLineStrideOffset; |
| 1534 |
|
| 1535 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_hmeKernel->Execute(curbeParam, surfaceParam, CodechalKernelHme::HmeLevel::hmeLevel4x)); |
| 1536 |
return MOS_STATUS_SUCCESS; |
| 1537 |
} |
| 1538 |
|
| 1539 |
MOS_STATUS CodechalEncodeMpeg2G11::SetCurbeMbEnc( |
| 1540 |
bool mbEncIFrameDistEnabled, |
| 1541 |
bool mbQpDataEnabled) |
| 1542 |
{ |
| 1543 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1544 |
|
| 1545 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1546 |
|
| 1547 |
uint16_t picWidthInMb = mbEncIFrameDistEnabled ? |
| 1548 |
(uint16_t)m_downscaledWidthInMb4x : m_picWidthInMb; |
| 1549 |
uint16_t fieldFrameHeightInMb = mbEncIFrameDistEnabled ? |
| 1550 |
(uint16_t)m_downscaledFrameFieldHeightInMb4x : m_frameFieldHeightInMb; |
| 1551 |
|
| 1552 |
MbEncCurbeG11 cmd(m_picParams->m_pictureCodingType); |
| 1553 |
|
| 1554 |
// Set CURBE data |
| 1555 |
cmd.m_curbeData.DW0.m_isInterlacedFrameFlag = |
| 1556 |
(CodecHal_PictureIsFrame(m_picParams->m_currOriginalPic)) ? (m_picParams->m_fieldCodingFlag || m_picParams->m_fieldFrameCodingFlag) : 0; |
| 1557 |
cmd.m_curbeData.DW0.m_isTopFieldFirst = cmd.m_curbeData.DW0.m_isInterlacedFrameFlag ? !m_picParams->m_interleavedFieldBFF : 0; |
| 1558 |
cmd.m_curbeData.DW0.m_forceToSkip = 0; |
| 1559 |
cmd.m_curbeData.DW4.m_pictureType = m_picParams->m_pictureCodingType; |
| 1560 |
cmd.m_curbeData.DW4.m_fieldFlag = (CodecHal_PictureIsFrame(m_picParams->m_currOriginalPic)) ? 0 : 1; |
| 1561 |
cmd.m_curbeData.DW4.m_picWidth = picWidthInMb; |
| 1562 |
cmd.m_curbeData.DW4.m_picHeightMinus1 = fieldFrameHeightInMb - 1; |
| 1563 |
|
| 1564 |
cmd.m_curbeData.DW7.m_bilinearEnable = 1; |
| 1565 |
cmd.m_curbeData.DW7.m_mvCostScaleFactor = 1; // half-pel |
| 1566 |
cmd.m_curbeData.DW7.m_idmShapeMode = 0; |
| 1567 |
|
| 1568 |
cmd.m_curbeData.DW9.m_srcAccess = cmd.m_curbeData.DW9.m_refAccess = 0; |
| 1569 |
cmd.m_curbeData.DW9.m_fieldCacheAllocationDis = 0; |
| 1570 |
|
| 1571 |
// This is approximation using first slice |
| 1572 |
// MPEG2 quantiser_scale_code legal range is [1, 31] inclusive |
| 1573 |
if (m_sliceParams->m_quantiserScaleCode < 1) |
| 1574 |
{ |
| 1575 |
m_sliceParams->m_quantiserScaleCode = 1; |
| 1576 |
} |
| 1577 |
else if (m_sliceParams->m_quantiserScaleCode > 31) |
| 1578 |
{ |
| 1579 |
m_sliceParams->m_quantiserScaleCode = 31; |
| 1580 |
} |
| 1581 |
|
| 1582 |
cmd.m_curbeData.DW9.m_mbQPEnable = mbQpDataEnabled; |
| 1583 |
cmd.m_curbeData.DW11.m_qpScaleCode = m_sliceParams->m_quantiserScaleCode; |
| 1584 |
cmd.m_curbeData.DW2.m_maxNumSU = 0x10; |
| 1585 |
cmd.m_curbeData.DW12.m_isFastMode = 0; |
| 1586 |
|
| 1587 |
if (m_seqParams ->m_rateControlMethod == RATECONTROL_CQP) |
| 1588 |
{ |
| 1589 |
cmd.m_curbeData.DW13.m_panicModeMBThreshold = 0xFFFF; |
| 1590 |
} |
| 1591 |
|
| 1592 |
cmd.m_curbeData.DW14.m_forwardHorizontalSearchRange = 4 << m_picParams->m_fcode00; |
| 1593 |
cmd.m_curbeData.DW14.m_forwardVerticalSearchRange = 4 << m_picParams->m_fcode01; |
| 1594 |
cmd.m_curbeData.DW15.m_backwardHorizontalSearchRange = 4 << m_picParams->m_fcode10; |
| 1595 |
cmd.m_curbeData.DW15.m_backwardVerticalSearchRange = 4 << m_picParams->m_fcode11; |
| 1596 |
|
| 1597 |
if (m_picParams->m_pictureCodingType == I_TYPE) |
| 1598 |
{ |
| 1599 |
cmd.m_curbeData.DW2.m_value = 0; |
| 1600 |
cmd.m_curbeData.DW4.m_pictureType = 0; |
| 1601 |
cmd.m_curbeData.DW9.m_intraSAD = 0x2; |
| 1602 |
|
| 1603 |
// Modify CURBE for distortion calculation. |
| 1604 |
if (mbEncIFrameDistEnabled) |
| 1605 |
{ |
| 1606 |
cmd.m_curbeData.DW4.m_iFrameMBDistortionDumpEnable = true; |
| 1607 |
} |
| 1608 |
else |
| 1609 |
{ |
| 1610 |
// Make sure the distortion dump flag is disabled for the normal MBEnc case. |
| 1611 |
// No need to reset the height and width since they are set |
| 1612 |
// correctly above this if-else and not modified after. |
| 1613 |
cmd.m_curbeData.DW4.m_iFrameMBDistortionDumpEnable = false; |
| 1614 |
} |
| 1615 |
} |
| 1616 |
else if (m_picParams->m_pictureCodingType == P_TYPE) |
| 1617 |
{ |
| 1618 |
cmd.m_curbeData.DW1.m_uniMixDisable = 0; |
| 1619 |
cmd.m_curbeData.DW1.m_biWeight = 32; |
| 1620 |
cmd.m_curbeData.DW2.m_maxLenSP = 0x09; |
| 1621 |
cmd.m_curbeData.DW4.m_pictureType = 1; |
| 1622 |
cmd.m_curbeData.DW9.m_interSAD = 2; |
| 1623 |
cmd.m_curbeData.DW9.m_intraSAD = 2; |
| 1624 |
cmd.m_curbeData.DW9.m_searchCtrl = 0; |
| 1625 |
cmd.m_curbeData.DW9.m_subPelMode = 1; |
| 1626 |
cmd.m_curbeData.DW9.m_skipType = 0; |
| 1627 |
cmd.m_curbeData.DW9.m_subMbPartMask = 0x7E; |
| 1628 |
cmd.m_curbeData.DW10.m_refWidth = 48; |
| 1629 |
cmd.m_curbeData.DW10.m_refHeight = 40; |
| 1630 |
cmd.m_curbeData.DW12.m_distScaleFactor = 0; |
| 1631 |
cmd.m_curbeData.DW7.m_skipCenterMask = 0x55; |
| 1632 |
|
| 1633 |
//Motion vector cost is taken from VME_LUTXY |
| 1634 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1635 |
&(cmd.m_curbeData.MvCost), |
| 1636 |
sizeof(uint32_t)* 2, |
| 1637 |
m_vmeLutXyP, |
| 1638 |
sizeof(uint32_t)* 2)); |
| 1639 |
|
| 1640 |
//VME_SEARCH_PATH |
| 1641 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1642 |
&(cmd.m_curbeData.VmeSPath0), |
| 1643 |
sizeof(uint32_t)* 16, |
| 1644 |
m_vmeSPathP0, |
| 1645 |
sizeof(uint32_t)* 16)); |
| 1646 |
|
| 1647 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1648 |
&(cmd.m_curbeData.VmeSPath1), |
| 1649 |
sizeof(uint32_t)* 16, |
| 1650 |
m_vmeSPathP1, |
| 1651 |
sizeof(uint32_t)* 16)); |
| 1652 |
|
| 1653 |
//Interlaced motion vector cost is the same as progressive P frame |
| 1654 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1655 |
&(cmd.m_curbeData.VmeSPath1.MvCostInterlace), |
| 1656 |
sizeof(uint32_t)* 2, |
| 1657 |
m_vmeLutXyP, |
| 1658 |
sizeof(uint32_t)* 2)); |
| 1659 |
|
| 1660 |
} |
| 1661 |
else// B_TYPE |
| 1662 |
{ |
| 1663 |
cmd.m_curbeData.DW1.m_biWeight = 32; |
| 1664 |
cmd.m_curbeData.DW1.m_refPixShift = 0; |
| 1665 |
cmd.m_curbeData.DW2.m_maxLenSP = 0x05; |
| 1666 |
cmd.m_curbeData.DW4.m_pictureType = 2; |
| 1667 |
cmd.m_curbeData.DW9.m_subMbPartMask = 0x7E; |
| 1668 |
cmd.m_curbeData.DW9.m_subPelMode = 1; |
| 1669 |
cmd.m_curbeData.DW9.m_skipType = 0; |
| 1670 |
cmd.m_curbeData.DW9.m_searchCtrl = 7; |
| 1671 |
cmd.m_curbeData.DW9.m_interSAD = 2; |
| 1672 |
cmd.m_curbeData.DW9.m_intraSAD = 2; |
| 1673 |
cmd.m_curbeData.DW10.m_refWidth = 32; |
| 1674 |
cmd.m_curbeData.DW10.m_refHeight = 32; |
| 1675 |
cmd.m_curbeData.DW7.m_skipCenterMask = 0xFF; |
| 1676 |
|
| 1677 |
// This calculation of m_distScaleFactor was taken directly from the algorithm. |
| 1678 |
switch (m_picParams->m_gopRefDist) |
| 1679 |
{ |
| 1680 |
case 3: |
| 1681 |
cmd.m_curbeData.DW12.m_distScaleFactor = (m_frameNumB > 1) ? 43 : 21; |
| 1682 |
break; |
| 1683 |
case 4: |
| 1684 |
cmd.m_curbeData.DW12.m_distScaleFactor = (m_frameNumB << 4); |
| 1685 |
break; |
| 1686 |
default: |
| 1687 |
cmd.m_curbeData.DW12.m_distScaleFactor = 32; |
| 1688 |
break; |
| 1689 |
} |
| 1690 |
|
| 1691 |
//Motion vector cost is taken from VME_LUTXY |
| 1692 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1693 |
&(cmd.m_curbeData.MvCost), sizeof(uint32_t)* 2, |
| 1694 |
m_vmeLutXyB, |
| 1695 |
sizeof(uint32_t)* 2)); |
| 1696 |
|
| 1697 |
//VME_SEARCH_PATH |
| 1698 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1699 |
&(cmd.m_curbeData.VmeSPath0), |
| 1700 |
sizeof(uint32_t)* 16, |
| 1701 |
m_vmeSPathB0, |
| 1702 |
sizeof(uint32_t)* 16)); |
| 1703 |
|
| 1704 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1705 |
&(cmd.m_curbeData.VmeSPath1), |
| 1706 |
sizeof(uint32_t)* 16, |
| 1707 |
m_vmeSPathB1, |
| 1708 |
sizeof(uint32_t)* 16)); |
| 1709 |
|
| 1710 |
//Interlaced motion vector cost is the same as progressive P frame |
| 1711 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(MOS_SecureMemcpy( |
| 1712 |
&(cmd.m_curbeData.VmeSPath1.MvCostInterlace), |
| 1713 |
sizeof(uint32_t)* 2, |
| 1714 |
m_vmeLutXyP, |
| 1715 |
sizeof(uint32_t)* 2)); |
| 1716 |
|
| 1717 |
} |
| 1718 |
|
| 1719 |
//ModeCost for P/B pictures |
| 1720 |
if (m_picParams->m_pictureCodingType != I_TYPE) |
| 1721 |
{ |
| 1722 |
cmd.m_curbeData.VmeSPath0.DW30.m_value = 0x83; // Setting mode 0 cost to 0x83 (131) |
| 1723 |
cmd.m_curbeData.VmeSPath0.DW31.m_value = 0x41414141; // Set mode 4, 5, 6, 7 costs to 0x41 (67) |
| 1724 |
cmd.m_curbeData.DW8.m_mode8Cost = 0x41; |
| 1725 |
} |
| 1726 |
|
| 1727 |
cmd.m_curbeData.DW48.m_value = 0x05000000; // BB-End Command |
| 1728 |
cmd.m_curbeData.DW49.m_value = m_mbEncBindingTable.m_mbEncPakObj; |
| 1729 |
cmd.m_curbeData.DW50.m_value = m_mbEncBindingTable.m_mbEncPakObjPrev; |
| 1730 |
cmd.m_curbeData.DW51.m_value = m_mbEncBindingTable.m_mbEncCurrentY; |
| 1731 |
cmd.m_curbeData.DW52.m_value = m_mbEncBindingTable.m_mbEncCurrentPic; // Also FWD REF & BWD REF too, +1, +2 respectively |
| 1732 |
cmd.m_curbeData.DW53.m_value = m_mbEncBindingTable.m_mbEncInterlaceFrameCurrentPic; // Also Int BWD Ref (+1) |
| 1733 |
cmd.m_curbeData.DW54.m_value = m_mbEncBindingTable.m_mbEncBrcDistortionSurface; |
| 1734 |
cmd.m_curbeData.DW55.m_value = m_mbEncBindingTable.m_mbEncMbControl; |
| 1735 |
// P/B frames need software score board |
| 1736 |
if (m_picParams->m_pictureCodingType != I_TYPE) |
| 1737 |
{ |
| 1738 |
cmd.m_curbeData.DW56.m_value = m_mbEncBindingTable.m_mbEncScoreboard; |
| 1739 |
} |
| 1740 |
|
| 1741 |
PMHW_KERNEL_STATE kernelState; |
| 1742 |
// Initialize DSH kernel region |
| 1743 |
if (mbEncIFrameDistEnabled) |
| 1744 |
{ |
| 1745 |
kernelState = &m_brcKernelStates[CODECHAL_ENCODE_BRC_IDX_IFRAMEDIST]; |
| 1746 |
} |
| 1747 |
else |
| 1748 |
{ |
| 1749 |
// wPictureCodingType: I_TYPE = 1, P_TYPE = 2, B_TYPE = 3 |
| 1750 |
// KernelStates are I: 0, P: 1, B: 2 |
| 1751 |
// m_mbEncKernelStates: I: m_mbEncKernelStates[0], P: m_mbEncKernelStates[1], B: m_mbEncKernelStates[2] |
| 1752 |
uint32_t krnStateIdx = m_pictureCodingType - 1; |
| 1753 |
kernelState = &m_mbEncKernelStates[krnStateIdx]; |
| 1754 |
} |
| 1755 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(kernelState->m_dshRegion.AddData( |
| 1756 |
&cmd, |
| 1757 |
kernelState->dwCurbeOffset, |
| 1758 |
cmd.m_byteSize)); |
| 1759 |
|
| 1760 |
return eStatus; |
| 1761 |
|
| 1762 |
} |
| 1763 |
|
| 1764 |
MOS_STATUS CodechalEncodeMpeg2G11::SetGpuCtxCreatOption() |
| 1765 |
{ |
| 1766 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1767 |
|
| 1768 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1769 |
|
| 1770 |
if (!MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface)) |
| 1771 |
{ |
| 1772 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncoderState::SetGpuCtxCreatOption()); |
| 1773 |
} |
| 1774 |
else |
| 1775 |
{ |
| 1776 |
m_gpuCtxCreatOpt = MOS_New(MOS_GPUCTX_CREATOPTIONS_ENHANCED); |
| 1777 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_gpuCtxCreatOpt); |
| 1778 |
|
| 1779 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalEncodeSinglePipeVE_ConstructParmsForGpuCtxCreation( |
| 1780 |
m_sinlgePipeVeState, |
| 1781 |
(PMOS_GPUCTX_CREATOPTIONS_ENHANCED)m_gpuCtxCreatOpt)); |
| 1782 |
} |
| 1783 |
|
| 1784 |
return eStatus; |
| 1785 |
} |
| 1786 |
|
| 1787 |
MOS_STATUS CodechalEncodeMpeg2G11::UserFeatureKeyReport() |
| 1788 |
{ |
| 1789 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1790 |
|
| 1791 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1792 |
|
| 1793 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncoderState::UserFeatureKeyReport()); |
| 1794 |
|
| 1795 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 1796 |
|
| 1797 |
// VE2.0 Reporting |
| 1798 |
CodecHalEncode_WriteKey(__MEDIA_USER_FEATURE_VALUE_ENABLE_ENCODE_VE_CTXSCHEDULING_ID, MOS_VE_CTXBASEDSCHEDULING_SUPPORTED(m_osInterface), m_osInterface->pOsContext); |
| 1799 |
|
| 1800 |
#endif // _DEBUG || _RELEASE_INTERNAL |
| 1801 |
|
| 1802 |
return eStatus; |
| 1803 |
} |
| 1804 |
|
| 1805 |
MOS_STATUS CodechalEncodeMpeg2G11::SendMbEncSurfaces( |
| 1806 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 1807 |
bool mbEncIFrameDistEnabled) |
| 1808 |
{ |
| 1809 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1810 |
|
| 1811 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1812 |
|
| 1813 |
CODECHAL_ENCODE_CHK_NULL_RETURN(cmdBuffer); |
| 1814 |
|
| 1815 |
auto currPicSurface = mbEncIFrameDistEnabled ? m_trackedBuf->Get4xDsSurface(CODEC_CURR_TRACKED_BUFFER) : m_rawSurfaceToEnc; |
| 1816 |
|
| 1817 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_mmcState); |
| 1818 |
m_mmcState->GetSurfaceMmcState(currPicSurface); |
| 1819 |
|
| 1820 |
// forward reference |
| 1821 |
if (m_picIdx[0].bValid) |
| 1822 |
{ |
| 1823 |
uint8_t picIdx0 = m_picIdx[0].ucPicIdx; |
| 1824 |
|
| 1825 |
if (picIdx0 < CODECHAL_NUM_UNCOMPRESSED_SURFACE_MPEG2) |
| 1826 |
{ |
| 1827 |
CodecHalGetResourceInfo(m_osInterface, &m_refList[picIdx0]->sRefBuffer); |
| 1828 |
m_mmcState->GetSurfaceMmcState(&m_refList[picIdx0]->sRefBuffer); |
| 1829 |
} |
| 1830 |
} |
| 1831 |
|
| 1832 |
// backward reference |
| 1833 |
if (m_picIdx[1].bValid) |
| 1834 |
{ |
| 1835 |
uint8_t picIdx1 = m_picIdx[1].ucPicIdx; |
| 1836 |
if (picIdx1 < CODECHAL_NUM_UNCOMPRESSED_SURFACE_MPEG2) |
| 1837 |
{ |
| 1838 |
CodecHalGetResourceInfo(m_osInterface, &m_refList[picIdx1]->sRefBuffer); |
| 1839 |
m_mmcState->GetSurfaceMmcState(&m_refList[picIdx1]->sRefBuffer); |
| 1840 |
} |
| 1841 |
} |
| 1842 |
|
| 1843 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodechalEncodeMpeg2::SendMbEncSurfaces( |
| 1844 |
cmdBuffer, |
| 1845 |
mbEncIFrameDistEnabled)); |
| 1846 |
|
| 1847 |
if (!m_useHwScoreboard && |
| 1848 |
m_pictureCodingType != I_TYPE) |
| 1849 |
{ |
| 1850 |
PMHW_KERNEL_STATE kernelState; |
| 1851 |
if (mbEncIFrameDistEnabled) |
| 1852 |
{ |
| 1853 |
kernelState = &m_brcKernelStates[CODECHAL_ENCODE_BRC_IDX_IFRAMEDIST]; |
| 1854 |
} |
| 1855 |
else |
| 1856 |
{ |
| 1857 |
// wPictureCodingType: I_TYPE = 1, P_TYPE = 2, B_TYPE = 3 |
| 1858 |
// KernelStates are I: 0, P: 1, B: 2 |
| 1859 |
// m_mbEncKernelStates: I: m_mbEncKernelStates[0], P: m_mbEncKernelStates[1], B: m_mbEncKernelStates[2] |
| 1860 |
uint32_t krnStateIdx = m_pictureCodingType - 1; |
| 1861 |
|
| 1862 |
kernelState = &m_mbEncKernelStates[krnStateIdx]; |
| 1863 |
} |
| 1864 |
|
| 1865 |
CODECHAL_SURFACE_CODEC_PARAMS surfaceCodecParams; |
| 1866 |
MOS_ZeroMemory(&surfaceCodecParams, sizeof(CODECHAL_SURFACE_CODEC_PARAMS)); |
| 1867 |
surfaceCodecParams.bIs2DSurface = true; |
| 1868 |
surfaceCodecParams.bMediaBlockRW = true; |
| 1869 |
surfaceCodecParams.psSurface = m_swScoreboardState->GetCurSwScoreboardSurface(); |
| 1870 |
surfaceCodecParams.dwCacheabilityControl = m_hwInterface->GetCacheabilitySettings()[MOS_CODEC_RESOURCE_USAGE_SURFACE_MB_QP_CODEC].Value; |
| 1871 |
surfaceCodecParams.dwBindingTableOffset = m_mbEncBindingTable.m_mbEncScoreboard; |
| 1872 |
surfaceCodecParams.bUse32UINTSurfaceFormat = true; |
| 1873 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(CodecHalSetRcsSurfaceState( |
| 1874 |
m_hwInterface, |
| 1875 |
cmdBuffer, |
| 1876 |
&surfaceCodecParams, |
| 1877 |
kernelState)); |
| 1878 |
} |
| 1879 |
return eStatus; |
| 1880 |
} |
| 1881 |
|
| 1882 |
MOS_STATUS CodechalEncodeMpeg2G11::SendPrologWithFrameTracking( |
| 1883 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 1884 |
bool frameTracking, |
| 1885 |
MHW_MI_MMIOREGISTERS *mmioRegister) |
| 1886 |
{ |
| 1887 |
if (MOS_VE_SUPPORTED(m_osInterface)) |
| 1888 |
{ |
| 1889 |
PMOS_CMD_BUF_ATTRI_VE attriExt = |
| 1890 |
(PMOS_CMD_BUF_ATTRI_VE)(cmdBuffer->Attributes.pAttriVe); |
| 1891 |
if (attriExt) |
| 1892 |
{ |
| 1893 |
attriExt->bUseVirtualEngineHint = true; |
| 1894 |
attriExt->VEngineHintParams.NeedSyncWithPrevious = 1; |
| 1895 |
} |
| 1896 |
} |
| 1897 |
|
| 1898 |
return CodechalEncoderState::SendPrologWithFrameTracking(cmdBuffer, frameTracking, mmioRegister); |
| 1899 |
} |
| 1900 |
|
| 1901 |
MOS_STATUS CodechalEncodeMpeg2G11::ExecuteKernelFunctions() |
| 1902 |
{ |
| 1903 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1904 |
|
| 1905 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 1906 |
|
| 1907 |
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN( m_debugInterface->DumpYUVSurface( |
| 1908 |
m_rawSurfaceToEnc, |
| 1909 |
CodechalDbgAttr::attrEncodeRawInputSurface, |
| 1910 |
"SrcSurf"))); |
| 1911 |
|
| 1912 |
m_firstTaskInPhase = true; |
| 1913 |
m_lastTaskInPhase = !m_singleTaskPhaseSupported; |
| 1914 |
m_lastEncPhase = false; |
| 1915 |
|
| 1916 |
m_setRequestedEUSlices = (m_brcEnabled && |
| 1917 |
m_sliceStateEnable && |
| 1918 |
(m_frameHeight * m_frameWidth) >= m_hwInterface->m_mpeg2SSDResolutionThreshold) ? true : false; |
| 1919 |
|
| 1920 |
m_hwInterface->m_numRequestedEuSlices = (m_setRequestedEUSlices) ? |
| 1921 |
m_sliceShutdownRequestState : m_sliceShutdownDefaultState; |
| 1922 |
|
| 1923 |
// Csc, Downscaling, and/or 10-bit to 8-bit conversion |
| 1924 |
// Scaling is only used to calculate distortions in case of Mpeg2 |
| 1925 |
CODECHAL_ENCODE_CHK_NULL_RETURN(m_cscDsState); |
| 1926 |
|
| 1927 |
CodechalEncodeCscDs::KernelParams cscScalingKernelParams; |
| 1928 |
MOS_ZeroMemory(&cscScalingKernelParams, sizeof(cscScalingKernelParams)); |
| 1929 |
cscScalingKernelParams.bLastTaskInPhaseCSC = |
| 1930 |
cscScalingKernelParams.bLastTaskInPhase4xDS = m_pictureCodingType == I_TYPE; |
| 1931 |
|
| 1932 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_cscDsState->KernelFunctions(&cscScalingKernelParams)); |
| 1933 |
|
| 1934 |
// P and B frames distortion calculations |
| 1935 |
if (m_hmeSupported && (m_pictureCodingType != I_TYPE)) |
| 1936 |
{ |
| 1937 |
m_firstTaskInPhase = !m_singleTaskPhaseSupported; |
| 1938 |
m_lastTaskInPhase = true; |
| 1939 |
|
| 1940 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EncodeMeKernel()); |
| 1941 |
} |
| 1942 |
|
| 1943 |
MOS_SYNC_PARAMS syncParams; |
| 1944 |
|
| 1945 |
// Scaling and HME are not dependent on the output from PAK |
| 1946 |
if (m_waitForPak && |
| 1947 |
m_semaphoreObjCount && |
| 1948 |
!Mos_ResourceIsNull(&m_resSyncObjectVideoContextInUse)) |
| 1949 |
{ |
| 1950 |
// Wait on PAK |
| 1951 |
syncParams = g_cInitSyncParams; |
| 1952 |
syncParams.GpuContext = m_renderContext; |
| 1953 |
syncParams.presSyncResource = &m_resSyncObjectVideoContextInUse; |
| 1954 |
syncParams.uiSemaphoreCount = m_semaphoreObjCount; |
| 1955 |
|
| 1956 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineWait(m_osInterface, &syncParams)); |
| 1957 |
m_semaphoreObjCount = 0; //reset |
| 1958 |
} |
| 1959 |
|
| 1960 |
m_firstTaskInPhase = true; |
| 1961 |
if (m_brcEnabled) |
| 1962 |
{ |
| 1963 |
if (m_pictureCodingType == I_TYPE) |
| 1964 |
{ |
| 1965 |
// The reset/init is only valid for I frames |
| 1966 |
if (m_brcInit || m_brcReset) |
| 1967 |
{ |
| 1968 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EncodeBrcInitResetKernel()); |
| 1969 |
m_firstTaskInPhase = !m_singleTaskPhaseSupported; |
| 1970 |
} |
| 1971 |
|
| 1972 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EncodeMbEncKernel(true)); |
| 1973 |
m_firstTaskInPhase = !m_singleTaskPhaseSupported; |
| 1974 |
} |
| 1975 |
|
| 1976 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EncodeBrcUpdateKernel()); |
| 1977 |
m_firstTaskInPhase = !m_singleTaskPhaseSupported; |
| 1978 |
} |
| 1979 |
|
| 1980 |
if (!m_useHwScoreboard && m_pictureCodingType != I_TYPE) |
| 1981 |
{ |
| 1982 |
CodechalEncodeSwScoreboard::KernelParams swScoreboardKernelParames; |
| 1983 |
MOS_ZeroMemory(&swScoreboardKernelParames, sizeof(swScoreboardKernelParames)); |
| 1984 |
|
| 1985 |
m_swScoreboardState->SetDependencyPattern(m_pictureCodingType == P_TYPE ? |
| 1986 |
dependencyWavefront45Degree : dependencyWavefrontHorizontal); |
| 1987 |
swScoreboardKernelParames.surfaceIndex = m_swScoreboardState->GetDependencyPattern(); |
| 1988 |
|
| 1989 |
m_swScoreboardState->SetCurSwScoreboardSurfaceIndex(swScoreboardKernelParames.surfaceIndex); |
| 1990 |
|
| 1991 |
if (Mos_ResourceIsNull(&m_swScoreboardState->GetCurSwScoreboardSurface()->OsResource)) |
| 1992 |
{ |
| 1993 |
swScoreboardKernelParames.scoreboardWidth = m_picWidthInMb; |
| 1994 |
swScoreboardKernelParames.scoreboardHeight = m_frameFieldHeightInMb; |
| 1995 |
swScoreboardKernelParames.swScoreboardSurfaceWidth = swScoreboardKernelParames.scoreboardWidth * 4; |
| 1996 |
swScoreboardKernelParames.swScoreboardSurfaceHeight = swScoreboardKernelParames.scoreboardHeight; |
| 1997 |
|
| 1998 |
m_swScoreboardState->Execute(&swScoreboardKernelParames); |
| 1999 |
} |
| 2000 |
|
| 2001 |
CODECHAL_DEBUG_TOOL(CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2002 |
&(m_swScoreboardState->GetCurSwScoreboardSurface())->OsResource, |
| 2003 |
CodechalDbgAttr::attrOutput, |
| 2004 |
"Out", |
| 2005 |
(m_swScoreboardState->GetCurSwScoreboardSurface())->dwHeight * (m_swScoreboardState->GetCurSwScoreboardSurface())->dwPitch, |
| 2006 |
0, |
| 2007 |
CODECHAL_MEDIA_STATE_SW_SCOREBOARD_INIT)); |
| 2008 |
) |
| 2009 |
} |
| 2010 |
|
| 2011 |
m_lastTaskInPhase = true; |
| 2012 |
m_lastEncPhase = true; |
| 2013 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(EncodeMbEncKernel(false)); |
| 2014 |
|
| 2015 |
if (!Mos_ResourceIsNull(&m_resSyncObjectRenderContextInUse)) |
| 2016 |
{ |
| 2017 |
syncParams = g_cInitSyncParams; |
| 2018 |
syncParams.GpuContext = m_renderContext; |
| 2019 |
syncParams.presSyncResource = &m_resSyncObjectRenderContextInUse; |
| 2020 |
|
| 2021 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_osInterface->pfnEngineSignal(m_osInterface, &syncParams)); |
| 2022 |
} |
| 2023 |
|
| 2024 |
CODECHAL_DEBUG_TOOL( |
| 2025 |
if (m_hmeEnabled && m_brcEnabled) |
| 2026 |
{ |
| 2027 |
CODECHAL_ME_OUTPUT_PARAMS meOutputParams; |
| 2028 |
MOS_ZeroMemory(&meOutputParams, sizeof(CODECHAL_ME_OUTPUT_PARAMS)); |
| 2029 |
meOutputParams.psMeMvBuffer = m_hmeKernel->GetSurface(CodechalKernelHme::SurfaceId::me4xMvDataBuffer); |
| 2030 |
meOutputParams.psMeBrcDistortionBuffer = |
| 2031 |
m_brcDistortionBufferSupported ? &m_brcBuffers.sMeBrcDistortionBuffer : nullptr; |
| 2032 |
meOutputParams.psMeDistortionBuffer = m_hmeKernel->GetSurface(CodechalKernelHme::SurfaceId::me4xDistortionBuffer); |
| 2033 |
meOutputParams.b16xMeInUse = false; |
| 2034 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2035 |
&meOutputParams.psMeMvBuffer->OsResource, |
| 2036 |
CodechalDbgAttr::attrOutput, |
| 2037 |
"MvData", |
| 2038 |
meOutputParams.psMeMvBuffer->dwHeight *meOutputParams.psMeMvBuffer->dwPitch, |
| 2039 |
CodecHal_PictureIsBottomField(m_currOriginalPic) ? MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 32), 64) * (m_downscaledFrameFieldHeightInMb4x * 4) : 0, |
| 2040 |
CODECHAL_MEDIA_STATE_4X_ME)); |
| 2041 |
if (!m_vdencStreamInEnabled && meOutputParams.psMeBrcDistortionBuffer) |
| 2042 |
{ |
| 2043 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2044 |
&meOutputParams.psMeBrcDistortionBuffer->OsResource, |
| 2045 |
CodechalDbgAttr::attrOutput, |
| 2046 |
"BrcDist", |
| 2047 |
meOutputParams.psMeBrcDistortionBuffer->dwHeight *meOutputParams.psMeBrcDistortionBuffer->dwPitch, |
| 2048 |
CodecHal_PictureIsBottomField(m_currOriginalPic) ? MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 8), 64) * MOS_ALIGN_CEIL((m_downscaledFrameFieldHeightInMb4x * 4), 8) : 0, |
| 2049 |
CODECHAL_MEDIA_STATE_4X_ME)); |
| 2050 |
if (meOutputParams.psMeDistortionBuffer) |
| 2051 |
{ |
| 2052 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2053 |
&meOutputParams.psMeDistortionBuffer->OsResource, |
| 2054 |
CodechalDbgAttr::attrOutput, |
| 2055 |
"MeDist", |
| 2056 |
meOutputParams.psMeDistortionBuffer->dwHeight *meOutputParams.psMeDistortionBuffer->dwPitch, |
| 2057 |
CodecHal_PictureIsBottomField(m_currOriginalPic) ? MOS_ALIGN_CEIL((m_downscaledWidthInMb4x * 8), 64) * MOS_ALIGN_CEIL((m_downscaledFrameFieldHeightInMb4x * 4 * 10), 8) : 0, |
| 2058 |
CODECHAL_MEDIA_STATE_4X_ME)); |
| 2059 |
} |
| 2060 |
} |
| 2061 |
// dump VDEncStreamin |
| 2062 |
if (m_vdencStreamInEnabled) |
| 2063 |
{ |
| 2064 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2065 |
&m_resVdencStreamInBuffer[m_currRecycledBufIdx], |
| 2066 |
CodechalDbgAttr::attrOutput, |
| 2067 |
"MvData", |
| 2068 |
m_picWidthInMb * m_picHeightInMb* CODECHAL_CACHELINE_SIZE, |
| 2069 |
0, |
| 2070 |
CODECHAL_MEDIA_STATE_ME_VDENC_STREAMIN)); |
| 2071 |
} |
| 2072 |
} |
| 2073 |
if (m_mbQpDataEnabled) |
| 2074 |
{ |
| 2075 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2076 |
&m_mbQpDataSurface.OsResource, |
| 2077 |
CodechalDbgAttr::attrInput, |
| 2078 |
"MbQp", |
| 2079 |
m_mbQpDataSurface.dwHeight*m_mbQpDataSurface.dwPitch, |
| 2080 |
0, |
| 2081 |
CODECHAL_MEDIA_STATE_ENC_QUALITY)); |
| 2082 |
} |
| 2083 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2084 |
&m_brcBuffers.resBrcImageStatesWriteBuffer, |
| 2085 |
CodechalDbgAttr::attrOutput, |
| 2086 |
"ImgStateWrite", |
| 2087 |
BRC_IMG_STATE_SIZE_PER_PASS * m_hwInterface->GetMfxInterface()->GetBrcNumPakPasses(), |
| 2088 |
0, |
| 2089 |
CODECHAL_MEDIA_STATE_BRC_UPDATE)); |
| 2090 |
|
| 2091 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2092 |
&m_brcBuffers.resBrcHistoryBuffer, |
| 2093 |
CodechalDbgAttr::attrOutput, |
| 2094 |
"HistoryWrite", |
| 2095 |
m_brcHistoryBufferSize, |
| 2096 |
0, |
| 2097 |
CODECHAL_MEDIA_STATE_BRC_UPDATE)); |
| 2098 |
if (m_brcBuffers.pMbEncKernelStateInUse) |
| 2099 |
{ |
| 2100 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpCurbe( |
| 2101 |
CODECHAL_MEDIA_STATE_ENC_NORMAL, |
| 2102 |
m_brcBuffers.pMbEncKernelStateInUse)); |
| 2103 |
} |
| 2104 |
if (m_mbencBrcBufferSize>0) |
| 2105 |
{ |
| 2106 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2107 |
&m_brcBuffers.resMbEncBrcBuffer, |
| 2108 |
CodechalDbgAttr::attrOutput, |
| 2109 |
"MbEncBRCWrite", |
| 2110 |
m_mbencBrcBufferSize, |
| 2111 |
0, |
| 2112 |
CODECHAL_MEDIA_STATE_BRC_UPDATE)); |
| 2113 |
} |
| 2114 |
CODECHAL_ENCODE_CHK_STATUS_RETURN(m_debugInterface->DumpBuffer( |
| 2115 |
&m_brcBuffers.resBrcPicHeaderOutputBuffer, |
| 2116 |
CodechalDbgAttr::attrOutput, |
| 2117 |
"PicHeaderWrite", |
| 2118 |
CODEC_ENCODE_MPEG2_BRC_PIC_HEADER_SURFACE_SIZE, |
| 2119 |
0, |
| 2120 |
CODECHAL_MEDIA_STATE_BRC_UPDATE)); |
| 2121 |
) |
| 2122 |
|
| 2123 |
// Reset after BRC Init has been processed |
| 2124 |
m_brcInit = false; |
| 2125 |
|
| 2126 |
m_setRequestedEUSlices = false; |
| 2127 |
|
| 2128 |
// Reset indices for next frame |
| 2129 |
if (m_brcEnabled) |
| 2130 |
{ |
| 2131 |
m_mbEncCurbeSetInBrcUpdate = false; |
| 2132 |
} |
| 2133 |
|
| 2134 |
return eStatus; |
| 2135 |
} |
| 2136 |
|
| 2137 |
void CodechalEncodeMpeg2G11::ResizeOnResChange() |
| 2138 |
{ |
| 2139 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2140 |
|
| 2141 |
CodechalEncoderState::ResizeOnResChange(); |
| 2142 |
|
| 2143 |
// need to re-allocate surfaces according to resolution |
| 2144 |
m_swScoreboardState->ReleaseResources(); |
| 2145 |
} |
| 2146 |
|
| 2147 |
MOS_STATUS CodechalEncodeMpeg2G11::UpdateCmdBufAttribute( |
| 2148 |
PMOS_COMMAND_BUFFER cmdBuffer, |
| 2149 |
bool renderEngineInUse) |
| 2150 |
{ |
| 2151 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 2152 |
|
| 2153 |
// should not be there. Will remove it in the next change |
| 2154 |
CODECHAL_ENCODE_FUNCTION_ENTER; |
| 2155 |
if (MOS_VE_SUPPORTED(m_osInterface) && cmdBuffer->Attributes.pAttriVe) |
| 2156 |
{ |
| 2157 |
PMOS_CMD_BUF_ATTRI_VE attriExt = |
| 2158 |
(PMOS_CMD_BUF_ATTRI_VE)(cmdBuffer->Attributes.pAttriVe); |
| 2159 |
|
| 2160 |
if (attriExt) |
| 2161 |
{ |
| 2162 |
memset(attriExt, 0, sizeof(MOS_CMD_BUF_ATTRI_VE)); |
| 2163 |
attriExt->bUseVirtualEngineHint = |
| 2164 |
attriExt->VEngineHintParams.NeedSyncWithPrevious = !renderEngineInUse; |
| 2165 |
} |
| 2166 |
} |
| 2167 |
|
| 2168 |
return eStatus; |
| 2169 |
} |