| 1 |
/* |
| 2 |
* Copyright (c) 2020-2023, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file media_blt_copy_next.cpp |
| 24 |
//! \brief Common interface used in Blitter Engine |
| 25 |
//! \details Common interface used in Blitter Engine which are platform independent |
| 26 |
//! |
| 27 |
|
| 28 |
#define NOMINMAX |
| 29 |
#include <algorithm> |
| 30 |
#include "media_perf_profiler.h" |
| 31 |
#include "media_blt_copy_next.h" |
| 32 |
#include "mhw_utilities_next.h" |
| 33 |
#include "mos_os_cp_interface_specific.h" |
| 34 |
#include "renderhal.h" |
| 35 |
#define BIT( n ) ( 1 << (n) ) |
| 36 |
|
| 37 |
#ifdef min |
| 38 |
#undef min |
| 39 |
#endif |
| 40 |
//! |
| 41 |
//! \brief BltStateNext constructor |
| 42 |
//! \details Initialize the BltStateNext members. |
| 43 |
//! \param osInterface |
| 44 |
//! [in] Pointer to MOS_INTERFACE. |
| 45 |
//! |
| 46 |
BltStateNext::BltStateNext(PMOS_INTERFACE osInterface) : |
| 47 |
m_osInterface(osInterface), |
| 48 |
m_mhwInterfaces(nullptr), |
| 49 |
m_cpInterface(nullptr) |
| 50 |
{ |
| 51 |
MhwInterfacesNext::CreateParams params; |
| 52 |
MOS_ZeroMemory(¶ms, sizeof(params)); |
| 53 |
params.Flags.m_blt = 1; |
| 54 |
m_mhwInterfaces = MhwInterfacesNext::CreateFactory(params, osInterface); |
| 55 |
if (m_mhwInterfaces != nullptr) |
| 56 |
{ |
| 57 |
m_miItf = m_mhwInterfaces->m_miItf; |
| 58 |
m_bltItf = m_mhwInterfaces->m_bltItf; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
//! |
| 63 |
//! \brief BltStateNext constructor |
| 64 |
//! \details Initialize the BltStateNext members. |
| 65 |
//! \param osInterface |
| 66 |
//! [in] Pointer to MOS_INTERFACE. |
| 67 |
//! |
| 68 |
BltStateNext::BltStateNext(PMOS_INTERFACE osInterface, MhwInterfacesNext* mhwInterfaces) : |
| 69 |
m_osInterface(osInterface), |
| 70 |
m_mhwInterfaces(nullptr), |
| 71 |
m_cpInterface(nullptr) |
| 72 |
{ |
| 73 |
m_miItf = mhwInterfaces->m_miItf; |
| 74 |
m_bltItf = mhwInterfaces->m_bltItf; |
| 75 |
m_cpInterface = mhwInterfaces->m_cpInterface; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
BltStateNext::~BltStateNext() |
| 80 |
{ |
| 81 |
FreeResource(); |
| 82 |
if (pMainSurface) |
| 83 |
{ |
| 84 |
MOS_FreeMemAndSetNull(pMainSurface); |
| 85 |
} |
| 86 |
if (pAuxSurface) |
| 87 |
{ |
| 88 |
MOS_FreeMemAndSetNull(pAuxSurface); |
| 89 |
} |
| 90 |
//component interface will be relesed in media copy. |
| 91 |
if (m_mhwInterfaces != nullptr) |
| 92 |
{ |
| 93 |
m_mhwInterfaces->Destroy(); |
| 94 |
MOS_Delete(m_mhwInterfaces); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
//! |
| 99 |
//! \brief BltStateNext initialize |
| 100 |
//! \details Initialize the BltStateNext, create BLT context. |
| 101 |
//! \return MOS_STATUS |
| 102 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 103 |
//! |
| 104 |
MOS_STATUS BltStateNext::Initialize() |
| 105 |
{ |
| 106 |
return MOS_STATUS_SUCCESS; |
| 107 |
} |
| 108 |
|
| 109 |
//! |
| 110 |
//! \brief Get control surface |
| 111 |
//! \details BLT engine will copy aux data of source surface to destination |
| 112 |
//! \param src |
| 113 |
//! [in] Pointer to source surface |
| 114 |
//! \param dst |
| 115 |
//! [in] Pointer to destination buffer is created for aux data |
| 116 |
//! \return MOS_STATUS |
| 117 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 118 |
//! |
| 119 |
MOS_STATUS BltStateNext::GetCCS( |
| 120 |
PMOS_SURFACE src, |
| 121 |
PMOS_SURFACE dst) |
| 122 |
{ |
| 123 |
BLT_STATE_PARAM bltStateParam; |
| 124 |
|
| 125 |
BLT_CHK_NULL_RETURN(src); |
| 126 |
BLT_CHK_NULL_RETURN(dst); |
| 127 |
BLT_CHK_NULL_RETURN(&src->OsResource); |
| 128 |
BLT_CHK_NULL_RETURN(&dst->OsResource); |
| 129 |
|
| 130 |
MOS_ZeroMemory(&bltStateParam, sizeof(BLT_STATE_PARAM)); |
| 131 |
bltStateParam.bCopyCCS = true; |
| 132 |
bltStateParam.ccsFlag = CCS_READ; |
| 133 |
bltStateParam.pSrcCCS = src; |
| 134 |
bltStateParam.pDstCCS = dst; |
| 135 |
|
| 136 |
BLT_CHK_STATUS_RETURN(SubmitCMD(&bltStateParam)); |
| 137 |
|
| 138 |
// sync |
| 139 |
MOS_LOCK_PARAMS flag; |
| 140 |
flag.Value = 0; |
| 141 |
flag.WriteOnly = 1; |
| 142 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnLockSyncRequest(m_osInterface, &dst->OsResource, &flag)); |
| 143 |
|
| 144 |
return MOS_STATUS_SUCCESS; |
| 145 |
} |
| 146 |
|
| 147 |
//! |
| 148 |
//! \brief Put control surface |
| 149 |
//! \details BLT engine will copy aux data of source surface to destination |
| 150 |
//! \param src |
| 151 |
//! [in] Pointer to source surface |
| 152 |
//! \param dst |
| 153 |
//! [in] Pointer to destination buffer is created for aux data |
| 154 |
//! \return MOS_STATUS |
| 155 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 156 |
//! |
| 157 |
MOS_STATUS BltStateNext::PutCCS( |
| 158 |
PMOS_SURFACE src, |
| 159 |
PMOS_SURFACE dst) |
| 160 |
{ |
| 161 |
BLT_STATE_PARAM bltStateParam; |
| 162 |
|
| 163 |
BLT_CHK_NULL_RETURN(src); |
| 164 |
BLT_CHK_NULL_RETURN(dst); |
| 165 |
BLT_CHK_NULL_RETURN(&src->OsResource); |
| 166 |
BLT_CHK_NULL_RETURN(&dst->OsResource); |
| 167 |
|
| 168 |
MOS_ZeroMemory(&bltStateParam, sizeof(BLT_STATE_PARAM)); |
| 169 |
bltStateParam.bCopyCCS = true; |
| 170 |
bltStateParam.ccsFlag = CCS_WRITE; |
| 171 |
bltStateParam.pSrcCCS = src; |
| 172 |
bltStateParam.pDstCCS = dst; |
| 173 |
|
| 174 |
BLT_CHK_STATUS_RETURN(SubmitCMD(&bltStateParam)); |
| 175 |
|
| 176 |
// sync |
| 177 |
MOS_LOCK_PARAMS flag; |
| 178 |
flag.Value = 0; |
| 179 |
flag.WriteOnly = 1; |
| 180 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnLockSyncRequest(m_osInterface, &dst->OsResource, &flag)); |
| 181 |
|
| 182 |
return MOS_STATUS_SUCCESS; |
| 183 |
} |
| 184 |
|
| 185 |
//! |
| 186 |
//! \brief Lock surface |
| 187 |
//! \details Lock surface to get main surface and aux data |
| 188 |
//! \param pSrcSurface |
| 189 |
//! [in] Pointer to source surface |
| 190 |
//! \return MOS_STATUS |
| 191 |
//! MOS_STATUS_SUCCESS if success, otherwise error code |
| 192 |
//! |
| 193 |
MOS_STATUS BltStateNext::LockSurface( |
| 194 |
PMOS_SURFACE pSurface) |
| 195 |
{ |
| 196 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 197 |
void* pTemp = nullptr; |
| 198 |
do |
| 199 |
{ |
| 200 |
if (pSurface==nullptr) |
| 201 |
{ |
| 202 |
BLT_ASSERTMESSAGE("BLT: pSurface check nullptr fail in LockSurface.") |
| 203 |
break; |
| 204 |
} |
| 205 |
|
| 206 |
// Initialize for the first time |
| 207 |
if (!initialized) |
| 208 |
{ |
| 209 |
if (Initialize() != MOS_STATUS_SUCCESS) |
| 210 |
{ |
| 211 |
break; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
// Allocate internel resource |
| 216 |
if (AllocateResource (pSurface) != MOS_STATUS_SUCCESS) |
| 217 |
{ |
| 218 |
break; |
| 219 |
} |
| 220 |
|
| 221 |
// Get main surface and CCS |
| 222 |
// Currentlt main surface copy will cause page fault, which cause crash. |
| 223 |
// BLT_CHK_STATUS(CopyMainSurface(pSurface, tempSurface)); |
| 224 |
if (GetCCS(pSurface, tempAuxSurface) != MOS_STATUS_SUCCESS) |
| 225 |
{ |
| 226 |
break; |
| 227 |
} |
| 228 |
|
| 229 |
MOS_LOCK_PARAMS LockFlags; |
| 230 |
LockFlags.Value = 0; |
| 231 |
LockFlags.ReadOnly = 1; |
| 232 |
LockFlags.TiledAsTiled = 1; |
| 233 |
LockFlags.NoDecompress = 1; |
| 234 |
|
| 235 |
// Lock main surface data |
| 236 |
pTemp = (uint8_t *)m_osInterface->pfnLockResource( |
| 237 |
m_osInterface, |
| 238 |
&pSurface->OsResource, |
| 239 |
&LockFlags); |
| 240 |
if (pTemp == nullptr) |
| 241 |
{ |
| 242 |
break; |
| 243 |
} |
| 244 |
|
| 245 |
MOS_SecureMemcpy( |
| 246 |
pMainSurface, |
| 247 |
surfaceSize, |
| 248 |
pTemp, |
| 249 |
surfaceSize); |
| 250 |
if (m_osInterface->pfnUnlockResource(m_osInterface, &pSurface->OsResource) != MOS_STATUS_SUCCESS) |
| 251 |
{ |
| 252 |
break; |
| 253 |
} |
| 254 |
|
| 255 |
// Lock CCS data |
| 256 |
pTemp = (uint8_t *)m_osInterface->pfnLockResource( |
| 257 |
m_osInterface, |
| 258 |
&tempAuxSurface->OsResource, |
| 259 |
&LockFlags); |
| 260 |
if (pTemp == nullptr) |
| 261 |
{ |
| 262 |
break; |
| 263 |
} |
| 264 |
|
| 265 |
MOS_SecureMemcpy( |
| 266 |
pAuxSurface, |
| 267 |
auxSize, |
| 268 |
pTemp, |
| 269 |
auxSize); |
| 270 |
if (m_osInterface->pfnUnlockResource(m_osInterface, &tempAuxSurface->OsResource)) |
| 271 |
{ |
| 272 |
break; |
| 273 |
} |
| 274 |
|
| 275 |
return eStatus; |
| 276 |
} while (false); |
| 277 |
|
| 278 |
BLT_ASSERTMESSAGE("BLT: Lock surface failed."); |
| 279 |
FreeResource(); |
| 280 |
return eStatus; |
| 281 |
} |
| 282 |
|
| 283 |
//! |
| 284 |
//! \brief Unlock surface |
| 285 |
//! \details Free resource created by lockSurface, must be called once call LockSurface |
| 286 |
//! \return MOS_STATUS |
| 287 |
//! MOS_STATUS_SUCCESS if success, otherwise error code |
| 288 |
//! |
| 289 |
MOS_STATUS BltStateNext::UnLockSurface() |
| 290 |
{ |
| 291 |
FreeResource(); |
| 292 |
return MOS_STATUS_SUCCESS; |
| 293 |
} |
| 294 |
|
| 295 |
//! |
| 296 |
//! \brief Write compressed surface |
| 297 |
//! \details Write compressed surface data from system memory to GPU memory |
| 298 |
//! \param pSysMemory |
| 299 |
//! [in] Pointer to system memory |
| 300 |
//! \param dataSize |
| 301 |
//! [in] data size, including main surface data and aux data |
| 302 |
//! \param pSurface |
| 303 |
//! [in] Pointer to the destination surface |
| 304 |
//! \return MOS_STATUS |
| 305 |
//! MOS_STATUS_SUCCESS if success, otherwise error code |
| 306 |
//! |
| 307 |
MOS_STATUS BltStateNext::WriteCompressedSurface( |
| 308 |
void* pSysMemory, |
| 309 |
uint32_t dataSize, |
| 310 |
PMOS_SURFACE pSurface) |
| 311 |
{ |
| 312 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 313 |
void* pTemp = nullptr; |
| 314 |
uint32_t sizeAux = 0; |
| 315 |
do |
| 316 |
{ |
| 317 |
if (pSurface == nullptr) |
| 318 |
{ |
| 319 |
BLT_ASSERTMESSAGE("BLT: pSurface check nullptr fail in WriteCompressedSurface.") |
| 320 |
break; |
| 321 |
} |
| 322 |
|
| 323 |
// Initialize for the first time |
| 324 |
if (!initialized) |
| 325 |
{ |
| 326 |
if (Initialize() != MOS_STATUS_SUCCESS) |
| 327 |
{ |
| 328 |
break; |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
// Allocate internel resource |
| 333 |
if (AllocateResource(pSurface) != MOS_STATUS_SUCCESS) |
| 334 |
{ |
| 335 |
break; |
| 336 |
} |
| 337 |
|
| 338 |
sizeAux = dataSize / 257; |
| 339 |
|
| 340 |
MOS_LOCK_PARAMS LockFlags; |
| 341 |
LockFlags.Value = 0; |
| 342 |
LockFlags.WriteOnly = 1; |
| 343 |
LockFlags.TiledAsTiled = 1; |
| 344 |
LockFlags.NoDecompress = 1; |
| 345 |
|
| 346 |
// Lock temp main surface |
| 347 |
pTemp = (uint32_t *)m_osInterface->pfnLockResource( |
| 348 |
m_osInterface, |
| 349 |
&pSurface->OsResource, |
| 350 |
&LockFlags); |
| 351 |
// copy surface data to temp surface |
| 352 |
MOS_SecureMemcpy( |
| 353 |
pTemp, |
| 354 |
sizeAux * 256, |
| 355 |
pSysMemory, |
| 356 |
sizeAux * 256); |
| 357 |
if (m_osInterface->pfnUnlockResource(m_osInterface, &pSurface->OsResource) != MOS_STATUS_SUCCESS) |
| 358 |
{ |
| 359 |
break; |
| 360 |
} |
| 361 |
|
| 362 |
// Lock temp aux surface |
| 363 |
pTemp = (uint8_t *)m_osInterface->pfnLockResource( |
| 364 |
m_osInterface, |
| 365 |
&tempAuxSurface->OsResource, |
| 366 |
&LockFlags); |
| 367 |
// copy aux data to temp aux surface |
| 368 |
MOS_SecureMemcpy( |
| 369 |
pTemp, |
| 370 |
sizeAux, |
| 371 |
(uint8_t *)pSysMemory + sizeAux * 256, |
| 372 |
sizeAux); |
| 373 |
if (m_osInterface->pfnUnlockResource(m_osInterface, &tempAuxSurface->OsResource) != MOS_STATUS_SUCCESS) |
| 374 |
{ |
| 375 |
break; |
| 376 |
} |
| 377 |
BLT_CHK_STATUS_RETURN(PutCCS(tempAuxSurface, pSurface)); |
| 378 |
|
| 379 |
FreeResource(); |
| 380 |
return eStatus; |
| 381 |
} while (false); |
| 382 |
|
| 383 |
BLT_ASSERTMESSAGE("BLT: Write compressed surface failed."); |
| 384 |
FreeResource(); |
| 385 |
return eStatus; |
| 386 |
} |
| 387 |
|
| 388 |
//! |
| 389 |
//! \brief Allocate resource |
| 390 |
//! \details Allocate internel resource |
| 391 |
//! \param pSrcSurface |
| 392 |
//! [in] Pointer to source surface |
| 393 |
//! \return MOS_STATUS |
| 394 |
//! MOS_STATUS_SUCCESS if success, otherwise error code |
| 395 |
//! |
| 396 |
MOS_STATUS BltStateNext::AllocateResource( |
| 397 |
PMOS_SURFACE pSurface) |
| 398 |
{ |
| 399 |
MOS_ALLOC_GFXRES_PARAMS AllocParams; |
| 400 |
|
| 401 |
tempSurface = (PMOS_SURFACE)MOS_AllocAndZeroMemory(sizeof(MOS_SURFACE)); |
| 402 |
tempAuxSurface = (PMOS_SURFACE)MOS_AllocAndZeroMemory(sizeof(MOS_SURFACE)); |
| 403 |
BLT_CHK_NULL_RETURN(tempSurface); |
| 404 |
BLT_CHK_NULL_RETURN(tempAuxSurface); |
| 405 |
|
| 406 |
// Always allocate the temp surface as compressible surface to make sure the size is correct. |
| 407 |
MOS_ZeroMemory(&AllocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 408 |
AllocParams.TileType = pSurface->TileType; |
| 409 |
AllocParams.Type = MOS_GFXRES_2D; |
| 410 |
AllocParams.dwWidth = pSurface->dwWidth; |
| 411 |
AllocParams.dwHeight = pSurface->dwHeight; |
| 412 |
AllocParams.Format = pSurface->Format; |
| 413 |
AllocParams.bIsCompressible = true; |
| 414 |
AllocParams.CompressionMode = pSurface->CompressionMode; |
| 415 |
AllocParams.pBufName = "TempOutSurface"; |
| 416 |
AllocParams.dwArraySize = 1; |
| 417 |
|
| 418 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnAllocateResource( |
| 419 |
m_osInterface, |
| 420 |
&AllocParams, |
| 421 |
&tempSurface->OsResource)); |
| 422 |
|
| 423 |
tempSurface->dwPitch = pSurface->dwPitch; |
| 424 |
tempSurface->dwWidth = pSurface->dwWidth; |
| 425 |
tempSurface->dwHeight = pSurface->dwHeight; |
| 426 |
tempSurface->Format = pSurface->Format; |
| 427 |
tempSurface->TileType = pSurface->TileType; |
| 428 |
|
| 429 |
MOS_ZeroMemory(&AllocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 430 |
AllocParams.TileType = MOS_TILE_LINEAR; |
| 431 |
AllocParams.Type = MOS_GFXRES_BUFFER; |
| 432 |
AllocParams.dwWidth = (uint32_t)tempSurface->OsResource.pGmmResInfo->GetSizeMainSurface() / 256; |
| 433 |
AllocParams.dwHeight = 1; |
| 434 |
AllocParams.Format = Format_Buffer; |
| 435 |
AllocParams.bIsCompressible = false; |
| 436 |
AllocParams.CompressionMode = MOS_MMC_DISABLED; |
| 437 |
AllocParams.pBufName = "TempCCS"; |
| 438 |
AllocParams.dwArraySize = 1; |
| 439 |
|
| 440 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnAllocateResource( |
| 441 |
m_osInterface, |
| 442 |
&AllocParams, |
| 443 |
&tempAuxSurface->OsResource)); |
| 444 |
|
| 445 |
surfaceSize = (uint32_t)tempSurface->OsResource.pGmmResInfo->GetSizeMainSurface(); |
| 446 |
auxSize = surfaceSize / 256; |
| 447 |
pMainSurface = MOS_AllocAndZeroMemory(surfaceSize); |
| 448 |
pAuxSurface = MOS_AllocAndZeroMemory(auxSize); |
| 449 |
BLT_CHK_NULL_RETURN(pMainSurface); |
| 450 |
BLT_CHK_NULL_RETURN(pAuxSurface); |
| 451 |
|
| 452 |
allocated = true; |
| 453 |
|
| 454 |
return MOS_STATUS_SUCCESS; |
| 455 |
} |
| 456 |
//! |
| 457 |
//! \brief Free resource |
| 458 |
//! \details Free internel resource, must be called once call AllocateResource |
| 459 |
//! \return MOS_STATUS |
| 460 |
//! MOS_STATUS_SUCCESS if success, otherwise error code |
| 461 |
//! |
| 462 |
MOS_STATUS BltStateNext::FreeResource() |
| 463 |
{ |
| 464 |
if (allocated) |
| 465 |
{ |
| 466 |
m_osInterface->pfnFreeResource(m_osInterface, &tempSurface->OsResource); |
| 467 |
m_osInterface->pfnFreeResource(m_osInterface, &tempAuxSurface->OsResource); |
| 468 |
allocated = false; |
| 469 |
} |
| 470 |
if (tempSurface) |
| 471 |
{ |
| 472 |
MOS_FreeMemAndSetNull(tempSurface); |
| 473 |
} |
| 474 |
if (tempAuxSurface) |
| 475 |
{ |
| 476 |
MOS_FreeMemAndSetNull(tempAuxSurface); |
| 477 |
} |
| 478 |
|
| 479 |
return MOS_STATUS_SUCCESS; |
| 480 |
} |
| 481 |
//! |
| 482 |
//! \brief Setup control surface copy parameters |
| 483 |
//! \details Setup control surface copy parameters for BLT Engine |
| 484 |
//! \param mhwParams |
| 485 |
//! [in/out] Pointer to MHW_CTRL_SURF_COPY_BLT_PARAM |
| 486 |
//! \param inputSurface |
| 487 |
//! [in] Pointer to input surface |
| 488 |
//! \param outputSurface |
| 489 |
//! [in] Pointer to output surface |
| 490 |
//! \param flag |
| 491 |
//! [in] Flag for read/write CCS |
| 492 |
//! \return MOS_STATUS |
| 493 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 494 |
//! |
| 495 |
MOS_STATUS BltStateNext::SetupCtrlSurfCopyBltParam( |
| 496 |
PMHW_CTRL_SURF_COPY_BLT_PARAM pMhwBltParams, |
| 497 |
PMOS_SURFACE inputSurface, |
| 498 |
PMOS_SURFACE outputSurface, |
| 499 |
uint32_t flag) |
| 500 |
{ |
| 501 |
BLT_CHK_NULL_RETURN(pMhwBltParams); |
| 502 |
BLT_CHK_NULL_RETURN(inputSurface); |
| 503 |
BLT_CHK_NULL_RETURN(outputSurface); |
| 504 |
|
| 505 |
if (flag == CCS_READ) |
| 506 |
{ |
| 507 |
pMhwBltParams->dwSrcMemoryType = 0; |
| 508 |
pMhwBltParams->dwDstMemoryType = 1; |
| 509 |
pMhwBltParams->dwSizeofControlSurface = (uint32_t)inputSurface->OsResource.pGmmResInfo->GetSizeMainSurface() / 65536; |
| 510 |
} |
| 511 |
else |
| 512 |
{ |
| 513 |
pMhwBltParams->dwSrcMemoryType = 1; |
| 514 |
pMhwBltParams->dwDstMemoryType = 0; |
| 515 |
pMhwBltParams->dwSizeofControlSurface = (uint32_t)outputSurface->OsResource.pGmmResInfo->GetSizeMainSurface() / 65536; |
| 516 |
} |
| 517 |
|
| 518 |
pMhwBltParams->pSrcOsResource = &inputSurface->OsResource; |
| 519 |
pMhwBltParams->pDstOsResource = &outputSurface->OsResource; |
| 520 |
|
| 521 |
return MOS_STATUS_SUCCESS; |
| 522 |
} |
| 523 |
|
| 524 |
//! |
| 525 |
//! \brief Block copy buffer |
| 526 |
//! \details BLT engine will copy source buffer to destination buffer |
| 527 |
//! \param pBltStateParam |
| 528 |
//! [in] Pointer to BLT_STATE_PARAM |
| 529 |
//! \return MOS_STATUS |
| 530 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 531 |
//! |
| 532 |
MOS_STATUS BltStateNext::BlockCopyBuffer(PBLT_STATE_PARAM pBltStateParam) |
| 533 |
{ |
| 534 |
PMOS_RESOURCE src = nullptr; |
| 535 |
PMOS_RESOURCE dst = nullptr; |
| 536 |
BLT_CHK_NULL_RETURN(pBltStateParam); |
| 537 |
BLT_CHK_NULL_RETURN(pBltStateParam->pSrcSurface); |
| 538 |
BLT_CHK_NULL_RETURN(pBltStateParam->pDstSurface); |
| 539 |
BLT_CHK_NULL_RETURN(pBltStateParam->pSrcSurface->pGmmResInfo); |
| 540 |
BLT_CHK_NULL_RETURN(pBltStateParam->pDstSurface->pGmmResInfo); |
| 541 |
|
| 542 |
src = pBltStateParam->pSrcSurface; |
| 543 |
dst = pBltStateParam->pDstSurface; |
| 544 |
|
| 545 |
if ((src->pGmmResInfo->GetSizeMainSurface() > MAX_BLT_BLOCK_COPY_WIDTH * MAX_BLT_BLOCK_COPY_WIDTH) && |
| 546 |
(dst->pGmmResInfo->GetSizeMainSurface() > MAX_BLT_BLOCK_COPY_WIDTH * MAX_BLT_BLOCK_COPY_WIDTH)) |
| 547 |
{ |
| 548 |
BLT_ASSERTMESSAGE("Buffer size too large"); |
| 549 |
return MOS_STATUS_INVALID_PARAMETER; |
| 550 |
} |
| 551 |
|
| 552 |
if ((src->pGmmResInfo->GetSizeMainSurface() % 4096 != 0) && |
| 553 |
(src->pGmmResInfo->GetSizeMainSurface() % 4096 != 16)) |
| 554 |
{ |
| 555 |
BLT_ASSERTMESSAGE("Src buffer is not aligned to 4K"); |
| 556 |
return MOS_STATUS_INVALID_PARAMETER; |
| 557 |
} |
| 558 |
|
| 559 |
if ((dst->pGmmResInfo->GetSizeMainSurface() % 4096 != 0) && |
| 560 |
(dst->pGmmResInfo->GetSizeMainSurface() % 4096 != 16)) |
| 561 |
{ |
| 562 |
BLT_ASSERTMESSAGE("Dst buffer is not aligned to 4K"); |
| 563 |
return MOS_STATUS_INVALID_PARAMETER; |
| 564 |
} |
| 565 |
|
| 566 |
GMM_RESOURCE_FORMAT backupSrcFormat = src->pGmmResInfo->GetResourceFormat(); |
| 567 |
GMM_GFX_SIZE_T backupSrcWidth = src->pGmmResInfo->GetBaseWidth(); |
| 568 |
uint32_t backupSrcHeight = src->pGmmResInfo->GetBaseHeight(); |
| 569 |
GMM_RESOURCE_FORMAT backupDstFormat = dst->pGmmResInfo->GetResourceFormat(); |
| 570 |
GMM_GFX_SIZE_T backupDstWidth = dst->pGmmResInfo->GetBaseWidth(); |
| 571 |
uint32_t backupDstHeight = dst->pGmmResInfo->GetBaseHeight(); |
| 572 |
|
| 573 |
uint32_t pitch = 4096; |
| 574 |
uint32_t size = static_cast<uint32_t>((std::min)(src->pGmmResInfo->GetSizeMainSurface(), dst->pGmmResInfo->GetSizeMainSurface())); |
| 575 |
uint32_t height = static_cast<uint32_t>(size / pitch); |
| 576 |
while (height > MAX_BLT_BLOCK_COPY_WIDTH) |
| 577 |
{ |
| 578 |
pitch += 4096; |
| 579 |
height = static_cast<uint32_t>(size / pitch); |
| 580 |
} |
| 581 |
|
| 582 |
src->pGmmResInfo->OverrideSurfaceFormat(GMM_FORMAT_R8_UINT); |
| 583 |
src->pGmmResInfo->OverrideSurfaceType(RESOURCE_2D); |
| 584 |
src->pGmmResInfo->OverrideBaseWidth(pitch); |
| 585 |
src->pGmmResInfo->OverrideBaseHeight(height); |
| 586 |
src->pGmmResInfo->OverridePitch(pitch); |
| 587 |
|
| 588 |
dst->pGmmResInfo->OverrideSurfaceFormat(GMM_FORMAT_R8_UINT); |
| 589 |
dst->pGmmResInfo->OverrideSurfaceType(RESOURCE_2D); |
| 590 |
dst->pGmmResInfo->OverrideBaseWidth(pitch); |
| 591 |
dst->pGmmResInfo->OverrideBaseHeight(height); |
| 592 |
dst->pGmmResInfo->OverridePitch(pitch); |
| 593 |
|
| 594 |
MOS_STATUS status = SubmitCMD(pBltStateParam); |
| 595 |
|
| 596 |
src->pGmmResInfo->OverrideSurfaceFormat(backupSrcFormat); |
| 597 |
src->pGmmResInfo->OverrideSurfaceType(RESOURCE_BUFFER); |
| 598 |
src->pGmmResInfo->OverrideBaseWidth(backupSrcWidth); |
| 599 |
src->pGmmResInfo->OverrideBaseHeight(backupSrcHeight); |
| 600 |
src->pGmmResInfo->OverridePitch(backupSrcWidth); |
| 601 |
|
| 602 |
dst->pGmmResInfo->OverrideSurfaceFormat(backupDstFormat); |
| 603 |
dst->pGmmResInfo->OverrideSurfaceType(RESOURCE_BUFFER); |
| 604 |
dst->pGmmResInfo->OverrideBaseWidth(backupDstWidth); |
| 605 |
dst->pGmmResInfo->OverrideBaseHeight(backupDstHeight); |
| 606 |
dst->pGmmResInfo->OverridePitch(backupDstWidth); |
| 607 |
|
| 608 |
BLT_CHK_STATUS_RETURN(status); |
| 609 |
return MOS_STATUS_SUCCESS; |
| 610 |
} |
| 611 |
|
| 612 |
//! |
| 613 |
//! \brief Copy main surface |
| 614 |
//! \details BLT engine will copy source surface to destination surface |
| 615 |
//! \param src |
| 616 |
//! [in] Pointer to source surface |
| 617 |
//! \param dst |
| 618 |
//! [in] Pointer to destination surface |
| 619 |
//! \return MOS_STATUS |
| 620 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 621 |
//! |
| 622 |
MOS_STATUS BltStateNext::CopyMainSurface( |
| 623 |
PMOS_SURFACE src, |
| 624 |
PMOS_SURFACE dst) |
| 625 |
{ |
| 626 |
BLT_CHK_STATUS_RETURN(CopyMainSurface(&src->OsResource, &dst->OsResource)); |
| 627 |
return MOS_STATUS_SUCCESS; |
| 628 |
} |
| 629 |
|
| 630 |
//! |
| 631 |
//! \brief Copy main surface |
| 632 |
//! \details BLT engine will copy source surface to destination surface |
| 633 |
//! \param src |
| 634 |
//! [in] Pointer to source resource |
| 635 |
//! \param dst |
| 636 |
//! [in] Pointer to destination resource |
| 637 |
//! \return MOS_STATUS |
| 638 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 639 |
//! |
| 640 |
MOS_STATUS BltStateNext::CopyMainSurface( |
| 641 |
PMOS_RESOURCE src, |
| 642 |
PMOS_RESOURCE dst) |
| 643 |
{ |
| 644 |
BLT_STATE_PARAM BltStateNextParam; |
| 645 |
|
| 646 |
BLT_CHK_NULL_RETURN(src); |
| 647 |
BLT_CHK_NULL_RETURN(dst); |
| 648 |
BLT_CHK_NULL_RETURN(src->pGmmResInfo); |
| 649 |
BLT_CHK_NULL_RETURN(dst->pGmmResInfo); |
| 650 |
|
| 651 |
MOS_ZeroMemory(&BltStateNextParam, sizeof(BLT_STATE_PARAM)); |
| 652 |
BltStateNextParam.bCopyMainSurface = true; |
| 653 |
BltStateNextParam.pSrcSurface = src; |
| 654 |
BltStateNextParam.pDstSurface = dst; |
| 655 |
|
| 656 |
// A workaround for oversized buffers. |
| 657 |
// BLOCK_COPY_BLT can only receive (width-1) of up to 14 bits. |
| 658 |
// The width of the internal buffer of a staging texture may exceed that limit. |
| 659 |
if ((src->pGmmResInfo->GetResourceType() == RESOURCE_BUFFER) && |
| 660 |
(dst->pGmmResInfo->GetResourceType() == RESOURCE_BUFFER) && |
| 661 |
((src->pGmmResInfo->GetBaseWidth() > MAX_BLT_BLOCK_COPY_WIDTH) || (dst->pGmmResInfo->GetBaseWidth() > MAX_BLT_BLOCK_COPY_WIDTH))) |
| 662 |
{ |
| 663 |
BLT_CHK_STATUS_RETURN(BlockCopyBuffer(&BltStateNextParam)); |
| 664 |
} |
| 665 |
else |
| 666 |
{ |
| 667 |
BLT_CHK_STATUS_RETURN(SubmitCMD(&BltStateNextParam)); |
| 668 |
} |
| 669 |
|
| 670 |
return MOS_STATUS_SUCCESS; |
| 671 |
|
| 672 |
} |
| 673 |
|
| 674 |
//! |
| 675 |
//! \brief Setup fast copy parameters |
| 676 |
//! \details Setup fast copy parameters for BLT Engine |
| 677 |
//! \param mhwParams |
| 678 |
//! [in/out] Pointer to MHW_FAST_COPY_BLT_PARAM |
| 679 |
//! \param inputSurface |
| 680 |
//! [in] Pointer to input surface |
| 681 |
//! \param outputSurface |
| 682 |
//! [in] Pointer to output surface |
| 683 |
//! \param planeIndex |
| 684 |
//! [in] Pointer to YUV(RGB) plane index |
| 685 |
//! \return MOS_STATUS |
| 686 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 687 |
//! |
| 688 |
MOS_STATUS BltStateNext::SetupBltCopyParam( |
| 689 |
PMHW_FAST_COPY_BLT_PARAM pMhwBltParams, |
| 690 |
PMOS_RESOURCE inputSurface, |
| 691 |
PMOS_RESOURCE outputSurface, |
| 692 |
int planeIndex) |
| 693 |
{ |
| 694 |
BLT_CHK_NULL_RETURN(pMhwBltParams); |
| 695 |
BLT_CHK_NULL_RETURN(inputSurface); |
| 696 |
BLT_CHK_NULL_RETURN(outputSurface); |
| 697 |
|
| 698 |
MOS_SURFACE ResDetails; |
| 699 |
MOS_ZeroMemory(&ResDetails, sizeof(MOS_SURFACE)); |
| 700 |
MOS_ZeroMemory(pMhwBltParams, sizeof(MHW_FAST_COPY_BLT_PARAM)); |
| 701 |
ResDetails.Format = Format_Invalid; |
| 702 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnGetResourceInfo(m_osInterface, inputSurface, &ResDetails)); |
| 703 |
|
| 704 |
uint32_t inputHeight = ResDetails.dwHeight; |
| 705 |
uint32_t inputWidth = ResDetails.dwWidth; |
| 706 |
uint32_t inputPitch = ResDetails.dwPitch; |
| 707 |
|
| 708 |
if (inputSurface->TileType != MOS_TILE_LINEAR) |
| 709 |
{ //for tiled surfaces, pitch is expressed in DWORDs |
| 710 |
pMhwBltParams->dwSrcPitch = ResDetails.dwPitch / 4; |
| 711 |
} |
| 712 |
else |
| 713 |
{ |
| 714 |
pMhwBltParams->dwSrcPitch = ResDetails.dwPitch; |
| 715 |
} |
| 716 |
|
| 717 |
pMhwBltParams->dwSrcTop = ResDetails.RenderOffset.YUV.Y.YOffset; |
| 718 |
pMhwBltParams->dwSrcLeft = ResDetails.RenderOffset.YUV.Y.XOffset; |
| 719 |
|
| 720 |
MOS_ZeroMemory(&ResDetails, sizeof(MOS_SURFACE)); |
| 721 |
ResDetails.Format = Format_Invalid; |
| 722 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnGetResourceInfo(m_osInterface, outputSurface, &ResDetails)); |
| 723 |
|
| 724 |
uint32_t outputHeight = ResDetails.dwHeight; |
| 725 |
uint32_t outputWidth = ResDetails.dwWidth; |
| 726 |
uint32_t outputPitch = ResDetails.dwPitch; |
| 727 |
|
| 728 |
if (outputSurface->TileType != MOS_TILE_LINEAR) |
| 729 |
{// for tiled surfaces, pitch is expressed in DWORDs |
| 730 |
pMhwBltParams->dwDstPitch = ResDetails.dwPitch/4; |
| 731 |
} |
| 732 |
else |
| 733 |
{ |
| 734 |
pMhwBltParams->dwDstPitch = ResDetails.dwPitch; |
| 735 |
} |
| 736 |
pMhwBltParams->dwDstTop = ResDetails.RenderOffset.YUV.Y.YOffset; |
| 737 |
pMhwBltParams->dwDstLeft = ResDetails.RenderOffset.YUV.Y.XOffset; |
| 738 |
|
| 739 |
int planeNum = GetPlaneNum(ResDetails.Format); |
| 740 |
pMhwBltParams->dwPlaneIndex = planeIndex; |
| 741 |
pMhwBltParams->dwPlaneNum = planeNum; |
| 742 |
|
| 743 |
// some upper layer has overwrite the format, so need get orignal BitsPerBlock |
| 744 |
BLT_CHK_NULL_RETURN(inputSurface->pGmmResInfo); |
| 745 |
BLT_CHK_NULL_RETURN(outputSurface->pGmmResInfo); |
| 746 |
uint32_t inputBitsPerPixel = inputSurface->pGmmResInfo->GetBitsPerPixel(); |
| 747 |
uint32_t outputBitsPerPixel = outputSurface->pGmmResInfo->GetBitsPerPixel(); |
| 748 |
uint32_t BitsPerPixel = 8; |
| 749 |
uint32_t blockWidth = 1; |
| 750 |
if (inputSurface->TileType != MOS_TILE_LINEAR) |
| 751 |
{ |
| 752 |
BitsPerPixel = inputBitsPerPixel; |
| 753 |
blockWidth = inputSurface->pGmmResInfo->GetCompressionBlockWidth(); |
| 754 |
} |
| 755 |
else if (outputSurface->TileType != MOS_TILE_LINEAR) |
| 756 |
{ |
| 757 |
BitsPerPixel = outputBitsPerPixel; |
| 758 |
blockWidth = outputSurface->pGmmResInfo->GetCompressionBlockWidth(); |
| 759 |
} |
| 760 |
else |
| 761 |
{ |
| 762 |
// both input and output are linear surfaces. |
| 763 |
// upper layer overwrite the format from buffer to 2D surfaces. Then the BitsPerPixel may different. |
| 764 |
BitsPerPixel = inputBitsPerPixel >= outputBitsPerPixel ? inputBitsPerPixel : outputBitsPerPixel; |
| 765 |
blockWidth = inputSurface->pGmmResInfo->GetCompressionBlockWidth(); |
| 766 |
} |
| 767 |
MCPY_NORMALMESSAGE("input BitsPerBlock %d, output BitsPerBlock %d, the vid mem BitsPerBlock %d", |
| 768 |
inputBitsPerPixel, |
| 769 |
outputBitsPerPixel, |
| 770 |
BitsPerPixel); |
| 771 |
pMhwBltParams->dwColorDepth = GetBlkCopyColorDepth(outputSurface->pGmmResInfo->GetResourceFormat(), BitsPerPixel); |
| 772 |
pMhwBltParams->dwDstRight = std::min(inputWidth, outputWidth); |
| 773 |
pMhwBltParams->dwDstBottom = std::min(inputHeight, outputHeight); |
| 774 |
if (ResDetails.Format == Format_YUY2 || ResDetails.Format == Format_Y210 || ResDetails.Format == Format_Y216) |
| 775 |
{ |
| 776 |
// packed YUV, dst right should be devided by blockwidth |
| 777 |
// YUY2_2x1, 32 bit per element, 2 element width |
| 778 |
// YUY2, 16 bit per element, 1 element width |
| 779 |
pMhwBltParams->dwDstRight /= blockWidth; |
| 780 |
} |
| 781 |
// The 2nd and 3nd layer. |
| 782 |
if (planeNum == TWO_PLANES || planeNum == THREE_PLANES) |
| 783 |
{ |
| 784 |
int bytePerTexelScaling = GetBytesPerTexelScaling(ResDetails.Format); |
| 785 |
if (MCPY_PLANE_U == planeIndex || MCPY_PLANE_V == planeIndex) |
| 786 |
{ |
| 787 |
// bpp of interleved chroma plane is double of luma plane bpp |
| 788 |
pMhwBltParams->dwColorDepth = GetBlkCopyColorDepth(outputSurface->pGmmResInfo->GetResourceFormat(), BitsPerPixel * bytePerTexelScaling); |
| 789 |
pMhwBltParams->dwDstRight = pMhwBltParams->dwDstRight / bytePerTexelScaling; |
| 790 |
pMhwBltParams->dwDstBottom = pMhwBltParams->dwDstBottom / bytePerTexelScaling; |
| 791 |
if (ResDetails.Format == Format_I420 || ResDetails.Format == Format_YV12) |
| 792 |
{ |
| 793 |
pMhwBltParams->dwDstPitch = pMhwBltParams->dwDstPitch / 2; |
| 794 |
pMhwBltParams->dwSrcPitch = pMhwBltParams->dwSrcPitch / 2; |
| 795 |
pMhwBltParams->dwDstRight = pMhwBltParams->dwDstRight / 2; |
| 796 |
pMhwBltParams->dwDstBottom = pMhwBltParams->dwDstBottom / 2; |
| 797 |
} |
| 798 |
} |
| 799 |
} |
| 800 |
pMhwBltParams->pSrcOsResource = inputSurface; |
| 801 |
pMhwBltParams->pDstOsResource = outputSurface; |
| 802 |
MCPY_NORMALMESSAGE("BLT params:format %d, planeNum %d, planeIndex %d, dwColorDepth %d, dwSrcTop %d, dwSrcLeft %d, dwSrcPitch %d," |
| 803 |
"dwDstTop %d, dwDstLeft %d, dwDstRight %d, dwDstBottom %d, dwDstPitch %d", |
| 804 |
ResDetails.Format, planeNum, planeIndex, pMhwBltParams->dwColorDepth, pMhwBltParams->dwSrcTop, pMhwBltParams->dwSrcLeft, |
| 805 |
pMhwBltParams->dwSrcPitch, pMhwBltParams->dwDstTop, pMhwBltParams->dwDstLeft, pMhwBltParams->dwDstRight, |
| 806 |
pMhwBltParams->dwDstBottom, pMhwBltParams->dwDstPitch); |
| 807 |
|
| 808 |
return MOS_STATUS_SUCCESS; |
| 809 |
} |
| 810 |
|
| 811 |
//! |
| 812 |
//! \brief Submit command2 |
| 813 |
//! \details Submit BLT command2 |
| 814 |
//! \param pBltStateParam |
| 815 |
//! [in] Pointer to BLT_STATE_PARAM |
| 816 |
//! \return MOS_STATUS |
| 817 |
//! Return MOS_STATUS_SUCCESS if successful, otherwise failed |
| 818 |
//! |
| 819 |
MOS_STATUS BltStateNext::SubmitCMD( |
| 820 |
PBLT_STATE_PARAM pBltStateParam) |
| 821 |
{ |
| 822 |
MOS_STATUS eStatus; |
| 823 |
MOS_COMMAND_BUFFER cmdBuffer; |
| 824 |
MHW_FAST_COPY_BLT_PARAM fastCopyBltParam; |
| 825 |
MHW_CTRL_SURF_COPY_BLT_PARAM ctrlSurfCopyBltParam; |
| 826 |
MOS_GPUCTX_CREATOPTIONS_ENHANCED createOption = {}; |
| 827 |
int planeNum = 1; |
| 828 |
|
| 829 |
BLT_CHK_NULL_RETURN(m_miItf); |
| 830 |
BLT_CHK_NULL_RETURN(m_bltItf); |
| 831 |
BLT_CHK_NULL_RETURN(pBltStateParam); |
| 832 |
BLT_CHK_NULL_RETURN(m_osInterface); |
| 833 |
// need consolidate both input/output surface information to decide cp context. |
| 834 |
PMOS_RESOURCE surfaceArray[2]; |
| 835 |
surfaceArray[0] = pBltStateParam->pSrcSurface; |
| 836 |
surfaceArray[1] = pBltStateParam->pDstSurface; |
| 837 |
if (m_osInterface->osCpInterface) |
| 838 |
{ |
| 839 |
m_osInterface->osCpInterface->PrepareResources((void **)&surfaceArray, sizeof(surfaceArray) / sizeof(PMOS_RESOURCE), nullptr, 0); |
| 840 |
} |
| 841 |
// no gpucontext will be created if the gpu context has been created before. |
| 842 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnCreateGpuContext( |
| 843 |
m_osInterface, |
| 844 |
MOS_GPU_CONTEXT_BLT, |
| 845 |
MOS_GPU_NODE_BLT, |
| 846 |
&createOption)); |
| 847 |
// Set GPU context |
| 848 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnSetGpuContext(m_osInterface, MOS_GPU_CONTEXT_BLT)); |
| 849 |
// Register context with the Batch Buffer completion event |
| 850 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnRegisterBBCompleteNotifyEvent( |
| 851 |
m_osInterface, |
| 852 |
MOS_GPU_CONTEXT_BLT)); |
| 853 |
|
| 854 |
// Initialize the command buffer struct |
| 855 |
MOS_ZeroMemory(&cmdBuffer, sizeof(MOS_COMMAND_BUFFER)); |
| 856 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnGetCommandBuffer(m_osInterface, &cmdBuffer, 0)); |
| 857 |
BLT_CHK_STATUS_RETURN(SetPrologParamsforCmdbuffer(&cmdBuffer)); |
| 858 |
|
| 859 |
MOS_SURFACE srcResDetails; |
| 860 |
MOS_SURFACE dstResDetails; |
| 861 |
MOS_ZeroMemory(&srcResDetails, sizeof(MOS_SURFACE)); |
| 862 |
MOS_ZeroMemory(&dstResDetails, sizeof(MOS_SURFACE)); |
| 863 |
srcResDetails.Format = Format_Invalid; |
| 864 |
dstResDetails.Format = Format_Invalid; |
| 865 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnGetResourceInfo(m_osInterface, pBltStateParam->pSrcSurface, &srcResDetails)); |
| 866 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnGetResourceInfo(m_osInterface, pBltStateParam->pDstSurface, &dstResDetails)); |
| 867 |
|
| 868 |
if (srcResDetails.Format != dstResDetails.Format) |
| 869 |
{ |
| 870 |
MCPY_ASSERTMESSAGE("BLT copy can't support CSC copy. input format = %d, output format = %d", srcResDetails.Format, dstResDetails.Format); |
| 871 |
return MOS_STATUS_INVALID_PARAMETER; |
| 872 |
} |
| 873 |
planeNum = GetPlaneNum(dstResDetails.Format); |
| 874 |
m_osInterface->pfnSetPerfTag(m_osInterface, BLT_COPY); |
| 875 |
MediaPerfProfiler* perfProfiler = MediaPerfProfiler::Instance(); |
| 876 |
BLT_CHK_NULL_RETURN(perfProfiler); |
| 877 |
BLT_CHK_STATUS_RETURN(perfProfiler->AddPerfCollectStartCmd((void*)this, m_osInterface, m_miItf, &cmdBuffer)); |
| 878 |
|
| 879 |
if (pBltStateParam->bCopyMainSurface) |
| 880 |
{ |
| 881 |
BLT_CHK_STATUS_RETURN(SetupBltCopyParam( |
| 882 |
&fastCopyBltParam, |
| 883 |
pBltStateParam->pSrcSurface, |
| 884 |
pBltStateParam->pDstSurface, |
| 885 |
MCPY_PLANE_Y)); |
| 886 |
|
| 887 |
BLT_CHK_STATUS_RETURN(SetBCSSWCTR(&cmdBuffer)); |
| 888 |
BLT_CHK_STATUS_RETURN(m_miItf->AddBLTMMIOPrologCmd(&cmdBuffer)); |
| 889 |
BLT_CHK_STATUS_RETURN(m_bltItf->AddBlockCopyBlt( |
| 890 |
&cmdBuffer, |
| 891 |
&fastCopyBltParam, |
| 892 |
srcResDetails.YPlaneOffset.iSurfaceOffset, |
| 893 |
dstResDetails.YPlaneOffset.iSurfaceOffset)); |
| 894 |
|
| 895 |
if (planeNum == TWO_PLANES || planeNum == THREE_PLANES) |
| 896 |
{ |
| 897 |
BLT_CHK_STATUS_RETURN(SetupBltCopyParam( |
| 898 |
&fastCopyBltParam, |
| 899 |
pBltStateParam->pSrcSurface, |
| 900 |
pBltStateParam->pDstSurface, |
| 901 |
MCPY_PLANE_U)); |
| 902 |
BLT_CHK_STATUS_RETURN(m_bltItf->AddBlockCopyBlt( |
| 903 |
&cmdBuffer, |
| 904 |
&fastCopyBltParam, |
| 905 |
srcResDetails.UPlaneOffset.iSurfaceOffset, |
| 906 |
dstResDetails.UPlaneOffset.iSurfaceOffset)); |
| 907 |
|
| 908 |
if (planeNum == THREE_PLANES) |
| 909 |
{ |
| 910 |
BLT_CHK_STATUS_RETURN(SetupBltCopyParam( |
| 911 |
&fastCopyBltParam, |
| 912 |
pBltStateParam->pSrcSurface, |
| 913 |
pBltStateParam->pDstSurface, |
| 914 |
MCPY_PLANE_V)); |
| 915 |
BLT_CHK_STATUS_RETURN(m_bltItf->AddBlockCopyBlt( |
| 916 |
&cmdBuffer, |
| 917 |
&fastCopyBltParam, |
| 918 |
srcResDetails.VPlaneOffset.iSurfaceOffset, |
| 919 |
dstResDetails.VPlaneOffset.iSurfaceOffset)); |
| 920 |
} |
| 921 |
|
| 922 |
} |
| 923 |
} |
| 924 |
BLT_CHK_STATUS_RETURN(perfProfiler->AddPerfCollectEndCmd((void*)this, m_osInterface, m_miItf, &cmdBuffer)); |
| 925 |
|
| 926 |
// Add flush DW |
| 927 |
auto& flushDwParams = m_miItf->MHW_GETPAR_F(MI_FLUSH_DW)(); |
| 928 |
flushDwParams = {}; |
| 929 |
auto skuTable = m_osInterface->pfnGetSkuTable(m_osInterface); |
| 930 |
if (skuTable && MEDIA_IS_SKU(skuTable, FtrEnablePPCFlush)) |
| 931 |
{ |
| 932 |
flushDwParams.bEnablePPCFlush = true; |
| 933 |
} |
| 934 |
BLT_CHK_STATUS_RETURN(m_miItf->MHW_ADDCMD_F(MI_FLUSH_DW)(&cmdBuffer)); |
| 935 |
// Add Batch Buffer end |
| 936 |
BLT_CHK_STATUS_RETURN(m_miItf->AddMiBatchBufferEnd(&cmdBuffer, nullptr)); |
| 937 |
|
| 938 |
// Return unused command buffer space to OS |
| 939 |
m_osInterface->pfnReturnCommandBuffer(m_osInterface, &cmdBuffer, 0); |
| 940 |
|
| 941 |
// Flush the command buffer |
| 942 |
BLT_CHK_STATUS_RETURN(m_osInterface->pfnSubmitCommandBuffer(m_osInterface, &cmdBuffer, false)); |
| 943 |
|
| 944 |
return MOS_STATUS_SUCCESS; |
| 945 |
} |
| 946 |
|
| 947 |
uint32_t BltStateNext::GetBlkCopyColorDepth( |
| 948 |
GMM_RESOURCE_FORMAT dstFormat, |
| 949 |
uint32_t BitsPerPixel) |
| 950 |
{ |
| 951 |
switch (BitsPerPixel) |
| 952 |
{ |
| 953 |
case 16: |
| 954 |
switch (dstFormat) |
| 955 |
{ |
| 956 |
case GMM_FORMAT_B5G5R5A1_UNORM: |
| 957 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_32BITCOLOR; |
| 958 |
default: |
| 959 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_16BITCOLOR; |
| 960 |
} |
| 961 |
case 32: |
| 962 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_32BITCOLOR; |
| 963 |
case 64: |
| 964 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_64BITCOLOR; |
| 965 |
case 96: |
| 966 |
MCPY_ASSERTMESSAGE("96 BitPerPixel support limimated as Linear format %d", dstFormat); |
| 967 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_96BITCOLOR_ONLYLINEARCASEISSUPPORTED; |
| 968 |
case 128: |
| 969 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_128BITCOLOR; |
| 970 |
case 8: |
| 971 |
default: |
| 972 |
return mhw_blt_state::XY_BLOCK_COPY_BLT_CMD::COLOR_DEPTH_8BITCOLOR; |
| 973 |
} |
| 974 |
} |
| 975 |
|
| 976 |
int BltStateNext::GetBytesPerTexelScaling(MOS_FORMAT format) |
| 977 |
{ |
| 978 |
int dstBytesPerTexel = 1; |
| 979 |
switch (format) |
| 980 |
{ |
| 981 |
case Format_NV12: |
| 982 |
case Format_P010: |
| 983 |
case Format_P016: |
| 984 |
dstBytesPerTexel = 2; |
| 985 |
break; |
| 986 |
default: |
| 987 |
dstBytesPerTexel = 1; |
| 988 |
} |
| 989 |
return dstBytesPerTexel; |
| 990 |
} |
| 991 |
|
| 992 |
int BltStateNext::GetPlaneNum(MOS_FORMAT format) |
| 993 |
{ |
| 994 |
|
| 995 |
int planeNum = SINGLE_PLANE; |
| 996 |
|
| 997 |
switch (format) |
| 998 |
{ |
| 999 |
case Format_NV12: |
| 1000 |
case Format_P010: |
| 1001 |
case Format_P016: |
| 1002 |
planeNum = TWO_PLANES; |
| 1003 |
break; |
| 1004 |
case Format_YV12: |
| 1005 |
case Format_I420: |
| 1006 |
case Format_444P: |
| 1007 |
case Format_RGBP: |
| 1008 |
case Format_BGRP: |
| 1009 |
case Format_IMC3: |
| 1010 |
case Format_411P: |
| 1011 |
case Format_422V: |
| 1012 |
case Format_422H: |
| 1013 |
planeNum = THREE_PLANES; |
| 1014 |
break; |
| 1015 |
default: |
| 1016 |
planeNum = SINGLE_PLANE; |
| 1017 |
break; |
| 1018 |
} |
| 1019 |
return planeNum; |
| 1020 |
} |
| 1021 |
|
| 1022 |
MOS_STATUS BltStateNext::SetPrologParamsforCmdbuffer(PMOS_COMMAND_BUFFER cmdBuffer) |
| 1023 |
{ |
| 1024 |
PMOS_INTERFACE pOsInterface; |
| 1025 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 1026 |
uint32_t iRemaining; |
| 1027 |
RENDERHAL_GENERIC_PROLOG_PARAMS GenericPrologParams = {}; |
| 1028 |
PMOS_RESOURCE gpuStatusBuffer = nullptr; |
| 1029 |
|
| 1030 |
//--------------------------------------------- |
| 1031 |
BLT_CHK_NULL_RETURN(cmdBuffer); |
| 1032 |
BLT_CHK_NULL_RETURN(m_osInterface); |
| 1033 |
//--------------------------------------------- |
| 1034 |
|
| 1035 |
eStatus = MOS_STATUS_SUCCESS; |
| 1036 |
pOsInterface = m_osInterface; |
| 1037 |
|
| 1038 |
|
| 1039 |
MOS_GPU_CONTEXT gpuContext = m_osInterface->pfnGetGpuContext(m_osInterface); |
| 1040 |
|
| 1041 |
#ifndef EMUL |
| 1042 |
if (pOsInterface->bEnableKmdMediaFrameTracking) |
| 1043 |
{ |
| 1044 |
// Get GPU Status buffer |
| 1045 |
BLT_CHK_STATUS_RETURN(pOsInterface->pfnGetGpuStatusBufferResource(pOsInterface, gpuStatusBuffer)); |
| 1046 |
BLT_CHK_NULL_RETURN(gpuStatusBuffer); |
| 1047 |
// Register the buffer |
| 1048 |
BLT_CHK_STATUS_RETURN(pOsInterface->pfnRegisterResource(pOsInterface, gpuStatusBuffer, true, true)); |
| 1049 |
|
| 1050 |
GenericPrologParams.bEnableMediaFrameTracking = true; |
| 1051 |
GenericPrologParams.presMediaFrameTrackingSurface = gpuStatusBuffer; |
| 1052 |
GenericPrologParams.dwMediaFrameTrackingTag = pOsInterface->pfnGetGpuStatusTag(pOsInterface, pOsInterface->CurrentGpuContextOrdinal); |
| 1053 |
GenericPrologParams.dwMediaFrameTrackingAddrOffset = pOsInterface->pfnGetGpuStatusTagOffset(pOsInterface, pOsInterface->CurrentGpuContextOrdinal); |
| 1054 |
|
| 1055 |
// Increment GPU Status Tag |
| 1056 |
pOsInterface->pfnIncrementGpuStatusTag(pOsInterface, pOsInterface->CurrentGpuContextOrdinal); |
| 1057 |
} |
| 1058 |
#endif |
| 1059 |
|
| 1060 |
if (GenericPrologParams.bEnableMediaFrameTracking) |
| 1061 |
{ |
| 1062 |
BLT_CHK_NULL_RETURN(GenericPrologParams.presMediaFrameTrackingSurface); |
| 1063 |
cmdBuffer->Attributes.bEnableMediaFrameTracking = GenericPrologParams.bEnableMediaFrameTracking; |
| 1064 |
cmdBuffer->Attributes.dwMediaFrameTrackingTag = GenericPrologParams.dwMediaFrameTrackingTag; |
| 1065 |
cmdBuffer->Attributes.dwMediaFrameTrackingAddrOffset = GenericPrologParams.dwMediaFrameTrackingAddrOffset; |
| 1066 |
cmdBuffer->Attributes.resMediaFrameTrackingSurface = GenericPrologParams.presMediaFrameTrackingSurface; |
| 1067 |
} |
| 1068 |
MHW_CHK_STATUS_RETURN(Mhw_SendNativeFenceSyncBBStartCmd(cmdBuffer, pOsInterface, m_miItf)); |
| 1069 |
|
| 1070 |
return eStatus; |
| 1071 |
} |
| 1072 |
|
| 1073 |
MOS_STATUS BltStateNext::SetBCSSWCTR(MOS_COMMAND_BUFFER *cmdBuffer) |
| 1074 |
{ |
| 1075 |
MOS_UNUSED(cmdBuffer); |
| 1076 |
return MOS_STATUS_SUCCESS; |
| 1077 |
} |