| 1 |
/* |
| 2 |
* Copyright (c) 2020-2022, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
//! |
| 23 |
//! \file media_debug_interface.cpp |
| 24 |
//! \brief Defines the debug interface shared by all of Media. |
| 25 |
//! \details The debug interface dumps output from Media based on input config file. |
| 26 |
//! |
| 27 |
#include "media_debug_interface.h" |
| 28 |
#if USE_MEDIA_DEBUG_TOOL |
| 29 |
#include "media_debug_config_manager.h" |
| 30 |
#include "media_debug_fast_dump.h" |
| 31 |
#include "codec_hw_next.h" |
| 32 |
#include <fstream> |
| 33 |
#include <sstream> |
| 34 |
#include <iomanip> |
| 35 |
|
| 36 |
#if !defined(LINUX) && !defined(ANDROID) |
| 37 |
#include "UmdStateSeparation.h" |
| 38 |
#endif |
| 39 |
|
| 40 |
MediaDebugInterface::MediaDebugInterface() |
| 41 |
{ |
| 42 |
memset(m_fileName, 0, sizeof(m_fileName)); |
| 43 |
memset(m_path, 0, sizeof(m_path)); |
| 44 |
InitCRCTable(m_crcTable); |
| 45 |
} |
| 46 |
|
| 47 |
MediaDebugInterface::~MediaDebugInterface() |
| 48 |
{ |
| 49 |
if (nullptr != m_configMgr) |
| 50 |
{ |
| 51 |
MOS_Delete(m_configMgr); |
| 52 |
} |
| 53 |
|
| 54 |
if (!Mos_ResourceIsNull(&m_temp2DSurfForCopy.OsResource)) |
| 55 |
{ |
| 56 |
m_osInterface->pfnFreeResource(m_osInterface, &m_temp2DSurfForCopy.OsResource); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
MOS_STATUS MediaDebugInterface::InitDumpLocation() |
| 61 |
{ |
| 62 |
m_crcGoldenRefFileName = m_outputFilePath + std::string("GoldenReference.txt"); |
| 63 |
if (m_configMgr->AttrIsEnabled(MediaDbgAttr::attrDumpToThreadFolder)) |
| 64 |
{ |
| 65 |
std::string ThreadSubFolder = "T" + std::to_string(MosUtilities::MosGetCurrentThreadId()) + MOS_DIRECTORY_DELIMITER; |
| 66 |
m_outputFilePath = m_outputFilePath + ThreadSubFolder; |
| 67 |
MosUtilities::MosCreateDirectory(const_cast<char *>(m_outputFilePath.c_str())); |
| 68 |
} |
| 69 |
|
| 70 |
m_ddiFileName = m_outputFilePath + "ddi.par"; |
| 71 |
std::ofstream ofs(m_ddiFileName, std::ios::out); |
| 72 |
ofs << "ParamFilePath" |
| 73 |
<< " = \"" << m_fileName << "\"" << std::endl; |
| 74 |
ofs.close(); |
| 75 |
|
| 76 |
return MOS_STATUS_SUCCESS; |
| 77 |
} |
| 78 |
|
| 79 |
MOS_STATUS MediaDebugInterface::SetOutputFilePath() |
| 80 |
{ |
| 81 |
std::string outputPathKey; |
| 82 |
std::string dumpFilePath; |
| 83 |
|
| 84 |
MEDIA_DEBUG_FUNCTION_ENTER; |
| 85 |
|
| 86 |
#ifdef LINUX |
| 87 |
char *customizedOutputPath = getenv("MOS_DEBUG_OUTPUT_LOCATION"); |
| 88 |
if (customizedOutputPath != nullptr && strlen(customizedOutputPath) != 0) |
| 89 |
{ |
| 90 |
m_outputFilePath = customizedOutputPath; |
| 91 |
m_outputFilePath.erase(m_outputFilePath.find_last_not_of(" \n\r\t") + 1); |
| 92 |
if (m_outputFilePath[m_outputFilePath.length() - 1] != MOS_DIRECTORY_DELIMITER) |
| 93 |
m_outputFilePath += MOS_DIRECTORY_DELIMITER; |
| 94 |
} |
| 95 |
else |
| 96 |
#endif |
| 97 |
{ |
| 98 |
outputPathKey = SetOutputPathKey(); |
| 99 |
ReadUserSettingForDebug( |
| 100 |
m_userSettingPtr, |
| 101 |
m_outputFilePath, |
| 102 |
outputPathKey, |
| 103 |
MediaUserSetting::Group::Device); |
| 104 |
|
| 105 |
if (!m_outputFilePath.empty()) |
| 106 |
{ |
| 107 |
if (m_outputFilePath.back() != MOS_DIRECTORY_DELIMITER) |
| 108 |
{ |
| 109 |
m_outputFilePath += MOS_DIRECTORY_DELIMITER; |
| 110 |
} |
| 111 |
} |
| 112 |
else |
| 113 |
{ |
| 114 |
#if defined(LINUX) || defined(ANDROID) |
| 115 |
m_outputFilePath = MOS_DEBUG_DEFAULT_OUTPUT_LOCATION; |
| 116 |
#else |
| 117 |
// Use state separation APIs to obtain appropriate storage location |
| 118 |
if (SUCCEEDED(GetDriverPersistentStorageLocation(dumpFilePath))) |
| 119 |
{ |
| 120 |
m_outputFilePath = dumpFilePath.c_str(); |
| 121 |
outputPathKey = InitDefaultOutput(); |
| 122 |
ReportUserSettingForDebug( |
| 123 |
m_userSettingPtr, |
| 124 |
outputPathKey, |
| 125 |
m_outputFilePath, |
| 126 |
MediaUserSetting::Group::Device); |
| 127 |
} |
| 128 |
else |
| 129 |
{ |
| 130 |
return MOS_STATUS_UNKNOWN; |
| 131 |
} |
| 132 |
#endif |
| 133 |
} |
| 134 |
} |
| 135 |
return MOS_STATUS_SUCCESS; |
| 136 |
} |
| 137 |
|
| 138 |
void MediaDebugInterface::PackGoldenReferences(std::initializer_list<std::vector<uint32_t>> goldenReference) |
| 139 |
{ |
| 140 |
for (auto beg = goldenReference.begin(); beg != goldenReference.end(); beg++) |
| 141 |
{ |
| 142 |
m_goldenReferences.push_back(*beg); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
MOS_STATUS MediaDebugInterface::CaptureGoldenReference(uint8_t *buf, uint32_t size, uint32_t hwCrcValue) |
| 147 |
{ |
| 148 |
MOS_STATUS eStatus = MOS_STATUS_SUCCESS; |
| 149 |
if (m_enableHwDebugHooks && |
| 150 |
!m_goldenReferenceExist) |
| 151 |
{ |
| 152 |
if (m_swCRC) |
| 153 |
{ |
| 154 |
if (buf == nullptr) |
| 155 |
{ |
| 156 |
return MOS_STATUS_NULL_POINTER; |
| 157 |
} |
| 158 |
auto crcVal = CalculateCRC(buf, size, 0); |
| 159 |
m_crcGoldenReference.push_back(crcVal); |
| 160 |
} |
| 161 |
else |
| 162 |
{ |
| 163 |
m_crcGoldenReference.push_back(hwCrcValue); |
| 164 |
} |
| 165 |
} |
| 166 |
return eStatus; |
| 167 |
} |
| 168 |
|
| 169 |
MOS_STATUS MediaDebugInterface::FillSemaResource(std::vector<uint32_t*> &vSemaData, std::vector<uint32_t> &data) |
| 170 |
{ |
| 171 |
if (vSemaData.size() != data.size()) |
| 172 |
{ |
| 173 |
return MOS_STATUS_INVALID_PARAMETER; |
| 174 |
} |
| 175 |
for (uint32_t i = 0; i < vSemaData.size(); i++) |
| 176 |
{ |
| 177 |
MEDIA_DEBUG_CHK_NULL(vSemaData[i]); |
| 178 |
*vSemaData[i] = data[i]; |
| 179 |
} |
| 180 |
return MOS_STATUS_SUCCESS; |
| 181 |
} |
| 182 |
|
| 183 |
MOS_STATUS MediaDebugInterface::LockResource(uint32_t *semaData, PMOS_RESOURCE reSemaphore) |
| 184 |
{ |
| 185 |
CodechalResLock semaLock(m_osInterface, reSemaphore); |
| 186 |
semaData = (uint32_t *)semaLock.Lock(CodechalResLock::writeOnly); |
| 187 |
return MOS_STATUS_SUCCESS; |
| 188 |
} |
| 189 |
|
| 190 |
MOS_STATUS MediaDebugInterface::LockSemaResource(std::vector<uint32_t *> &vSemaData, std::vector<MOS_RESOURCE> &vResource) |
| 191 |
{ |
| 192 |
for (uint32_t i = 0; i < vResource.size(); i++) |
| 193 |
{ |
| 194 |
CodechalResLock semaLock(m_osInterface, &vResource[i]); |
| 195 |
uint32_t * smData = (uint32_t *)semaLock.Lock(CodechalResLock::writeOnly); |
| 196 |
LockResource(smData, &vResource[i]); |
| 197 |
vSemaData.push_back(smData); |
| 198 |
} |
| 199 |
return MOS_STATUS_SUCCESS; |
| 200 |
} |
| 201 |
|
| 202 |
MOS_STATUS MediaDebugInterface::DumpToFile(const GoldenReferences &goldenReferences) |
| 203 |
{ |
| 204 |
std::ofstream ofs(m_crcGoldenRefFileName, std::ios_base::out); |
| 205 |
if (goldenReferences.size() <= 0) |
| 206 |
{ |
| 207 |
return MOS_STATUS_INVALID_PARAMETER; |
| 208 |
} |
| 209 |
for (uint32_t i = 0; i < goldenReferences[0].size(); i++) |
| 210 |
{ |
| 211 |
for (auto golden : goldenReferences) |
| 212 |
{ |
| 213 |
ofs << golden[i] << '\t'; |
| 214 |
} |
| 215 |
ofs << '\n'; |
| 216 |
} |
| 217 |
ofs.close(); |
| 218 |
return MOS_STATUS_SUCCESS; |
| 219 |
} |
| 220 |
|
| 221 |
MOS_STATUS MediaDebugInterface::DumpGoldenReference() |
| 222 |
{ |
| 223 |
if (m_enableHwDebugHooks && !m_goldenReferenceExist && m_goldenReferences.size() > 0) |
| 224 |
{ |
| 225 |
return DumpToFile(m_goldenReferences); |
| 226 |
} |
| 227 |
else |
| 228 |
{ |
| 229 |
return MOS_STATUS_UNKNOWN; |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
MOS_STATUS MediaDebugInterface::LoadGoldenReference() |
| 234 |
{ |
| 235 |
std::ifstream ifs(m_crcGoldenRefFileName, std::ios_base::in); |
| 236 |
std::vector<uint32_t> lines; |
| 237 |
std::string str; |
| 238 |
uint32_t num; |
| 239 |
if (!ifs) |
| 240 |
{ |
| 241 |
return MOS_STATUS_FILE_OPEN_FAILED; |
| 242 |
} |
| 243 |
uint32_t crc; |
| 244 |
while (!ifs.eof()) |
| 245 |
{ |
| 246 |
std::getline(ifs, str); |
| 247 |
std::stringstream stringin(str); |
| 248 |
lines.clear(); |
| 249 |
while (stringin >> num) |
| 250 |
{ |
| 251 |
lines.push_back(num); |
| 252 |
} |
| 253 |
m_goldenReferences.push_back(lines); |
| 254 |
} |
| 255 |
ifs.close(); |
| 256 |
m_goldenReferences.pop_back(); |
| 257 |
return MOS_STATUS_SUCCESS; |
| 258 |
} |
| 259 |
|
| 260 |
MOS_STATUS MediaDebugInterface::DumpUncompressedYUVSurface(PMOS_SURFACE surface) |
| 261 |
{ |
| 262 |
if (surface == nullptr) |
| 263 |
{ |
| 264 |
MEDIA_DEBUG_ASSERTMESSAGE("Surface for Dump is nullptr"); |
| 265 |
return MOS_STATUS_NULL_POINTER; |
| 266 |
} |
| 267 |
|
| 268 |
MEDIA_DEBUG_CHK_STATUS(ReAllocateSurface( |
| 269 |
&m_temp2DSurfForCopy, |
| 270 |
surface, |
| 271 |
"Temp2DSurfForSurfDumper", |
| 272 |
MOS_GFXRES_2D, |
| 273 |
true)); |
| 274 |
|
| 275 |
MEDIA_DEBUG_VERBOSEMESSAGE("Temp2DSurfaceForCopy width %d, height %d, pitch %d, TileType %d, bIsCompressed %d, CompressionMode %d", |
| 276 |
m_temp2DSurfForCopy.dwWidth, |
| 277 |
m_temp2DSurfForCopy.dwHeight, |
| 278 |
m_temp2DSurfForCopy.dwPitch, |
| 279 |
m_temp2DSurfForCopy.TileType, |
| 280 |
m_temp2DSurfForCopy.bIsCompressed, |
| 281 |
m_temp2DSurfForCopy.CompressionMode); |
| 282 |
|
| 283 |
// Copy Original Surface to a Linear/Uncompressed surface, later lock can use m_temp2DSurfForCopy for uncompresed surfaces |
| 284 |
// if the return is not supported, then the lock should only happen on origianl resource |
| 285 |
MEDIA_DEBUG_CHK_STATUS(m_osInterface->pfnDoubleBufferCopyResource( |
| 286 |
m_osInterface, |
| 287 |
&surface->OsResource, |
| 288 |
&m_temp2DSurfForCopy.OsResource, |
| 289 |
false)); |
| 290 |
|
| 291 |
return MOS_STATUS_SUCCESS; |
| 292 |
} |
| 293 |
|
| 294 |
#define FIELD_TO_OFS(name, shift) ofs << shift #name << ": " << (int64_t)ptr->name << std::endl; |
| 295 |
#define EMPTY_TO_OFS() |
| 296 |
#define UNION_STRUCT_START_TO_OFS() ofs << "union" << std::endl \ |
| 297 |
<< "{" << std::endl \ |
| 298 |
<< " struct" << std::endl \ |
| 299 |
<< " {" << std::endl; |
| 300 |
|
| 301 |
#define UNION_STRUCT_FIELD_TO_OFS(name) ofs << " "#name << ": " << ptr->name << std::endl; |
| 302 |
#define UNION_END_TO_OFS(name) ofs << " }" << std::endl \ |
| 303 |
<< " "#name << ": " << ptr->name << std::endl \ |
| 304 |
<< "}" << std::endl; |
| 305 |
#define OFFSET_FIELD_TO_OFS(class_name, f_name, shift) << shift " "#f_name": " << ptr->class_name.f_name << std::endl |
| 306 |
#define PLANE_OFFSET_TO_OFS(name) ofs << "MOS_PLANE_OFFSET "#name << std::endl \ |
| 307 |
OFFSET_FIELD_TO_OFS(name, iSurfaceOffset,) \ |
| 308 |
OFFSET_FIELD_TO_OFS(name, iXOffset,) \ |
| 309 |
OFFSET_FIELD_TO_OFS(name, iYOffset,) \ |
| 310 |
OFFSET_FIELD_TO_OFS(name, iLockSurfaceOffset,); |
| 311 |
#define RESOURCE_OFFSET_TO_OFS(name, shift) ofs << shift "MOS_RESOURCE_OFFSETS "#name << std::endl \ |
| 312 |
OFFSET_FIELD_TO_OFS(name, BaseOffset, shift) \ |
| 313 |
OFFSET_FIELD_TO_OFS(name, XOffset, shift) \ |
| 314 |
OFFSET_FIELD_TO_OFS(name, YOffset, shift); |
| 315 |
|
| 316 |
#define FIELD_TO_OFS_8SHIFT(name) FIELD_TO_OFS(name, " ") |
| 317 |
MOS_STATUS MediaDebugInterface::DumpMosSpecificResourceInfoToOfs( |
| 318 |
PMOS_RESOURCE pOsResource, |
| 319 |
std::ofstream& ofs) |
| 320 |
{ |
| 321 |
MEDIA_DEBUG_FUNCTION_ENTER; |
| 322 |
if (Mos_ResourceIsNull(pOsResource)) |
| 323 |
{ |
| 324 |
MEDIA_DEBUG_ASSERTMESSAGE("pOsResource is null"); |
| 325 |
return MOS_STATUS_INVALID_PARAMETER; |
| 326 |
} |
| 327 |
|
| 328 |
PMOS_RESOURCE ptr = pOsResource; |
| 329 |
ofs << "MOS_RESOURCE:" << std::endl; |
| 330 |
#if !defined(LINUX) || defined(WDDM_LINUX) |
| 331 |
FIELD_TO_OFS(RunTimeHandle, ); |
| 332 |
#else |
| 333 |
FIELD_TO_OFS(iWidth, ); |
| 334 |
FIELD_TO_OFS(iHeight, ); |
| 335 |
FIELD_TO_OFS(iSize, ); |
| 336 |
FIELD_TO_OFS(iPitch, ); |
| 337 |
FIELD_TO_OFS(iDepth, ); |
| 338 |
FIELD_TO_OFS(Format, ); |
| 339 |
FIELD_TO_OFS(iCount, ); |
| 340 |
FIELD_TO_OFS(dwGfxAddress, ); |
| 341 |
FIELD_TO_OFS(isTiled, ); |
| 342 |
FIELD_TO_OFS(TileType, ); |
| 343 |
FIELD_TO_OFS(bMapped, ); |
| 344 |
|
| 345 |
EMPTY_TO_OFS(); |
| 346 |
FIELD_TO_OFS(bo->size, ); |
| 347 |
FIELD_TO_OFS(bo->align, ); |
| 348 |
FIELD_TO_OFS(bo->offset, ); |
| 349 |
FIELD_TO_OFS(bo->handle, ); |
| 350 |
FIELD_TO_OFS(bo->offset64, ); |
| 351 |
FIELD_TO_OFS(bo->aux_mapped, ); |
| 352 |
#endif |
| 353 |
ofs << "iAllocationIndex[MOS_GPU_CONTEXT_MAX == " << (uint32_t)MOS_GPU_CONTEXT_MAX << "]: {"; |
| 354 |
for (int i = 0; i < MOS_GPU_CONTEXT_MAX; ++i) |
| 355 |
ofs << ptr->iAllocationIndex[i] << ", "; |
| 356 |
ofs << "}" << std::endl; |
| 357 |
|
| 358 |
{ |
| 359 |
PGMM_RESOURCE_INFO ptr = pOsResource->pGmmResInfo; |
| 360 |
EMPTY_TO_OFS(); |
| 361 |
ofs << "GMM_RESOURCE_INFO:" << std::endl; |
| 362 |
FIELD_TO_OFS(GetResourceType(), ); |
| 363 |
FIELD_TO_OFS(GetResourceFormat(), ); |
| 364 |
FIELD_TO_OFS(GetBitsPerPixel(), ); |
| 365 |
|
| 366 |
{ |
| 367 |
GMM_RESOURCE_FLAG flags = pOsResource->pGmmResInfo->GetResFlags(); |
| 368 |
GMM_RESOURCE_FLAG* ptr = &flags; |
| 369 |
|
| 370 |
EMPTY_TO_OFS(); |
| 371 |
ofs << " GMM_RESOURCE_FLAG:" << std::endl; |
| 372 |
FIELD_TO_OFS_8SHIFT(Gpu.CameraCapture); |
| 373 |
FIELD_TO_OFS_8SHIFT(Gpu.CCS); |
| 374 |
FIELD_TO_OFS_8SHIFT(Gpu.ColorDiscard); |
| 375 |
FIELD_TO_OFS_8SHIFT(Gpu.ColorSeparation); |
| 376 |
FIELD_TO_OFS_8SHIFT(Gpu.ColorSeparationRGBX); |
| 377 |
FIELD_TO_OFS_8SHIFT(Gpu.Constant); |
| 378 |
FIELD_TO_OFS_8SHIFT(Gpu.Depth); |
| 379 |
FIELD_TO_OFS_8SHIFT(Gpu.FlipChain); |
| 380 |
FIELD_TO_OFS_8SHIFT(Gpu.FlipChainPreferred); |
| 381 |
FIELD_TO_OFS_8SHIFT(Gpu.HistoryBuffer); |
| 382 |
FIELD_TO_OFS_8SHIFT(Gpu.HiZ); |
| 383 |
FIELD_TO_OFS_8SHIFT(Gpu.Index); |
| 384 |
FIELD_TO_OFS_8SHIFT(Gpu.IndirectClearColor); |
| 385 |
FIELD_TO_OFS_8SHIFT(Gpu.InstructionFlat); |
| 386 |
FIELD_TO_OFS_8SHIFT(Gpu.InterlacedScan); |
| 387 |
FIELD_TO_OFS_8SHIFT(Gpu.MCS); |
| 388 |
FIELD_TO_OFS_8SHIFT(Gpu.MMC); |
| 389 |
FIELD_TO_OFS_8SHIFT(Gpu.MotionComp); |
| 390 |
FIELD_TO_OFS_8SHIFT(Gpu.NoRestriction); |
| 391 |
FIELD_TO_OFS_8SHIFT(Gpu.Overlay); |
| 392 |
FIELD_TO_OFS_8SHIFT(Gpu.Presentable); |
| 393 |
FIELD_TO_OFS_8SHIFT(Gpu.ProceduralTexture); |
| 394 |
FIELD_TO_OFS_8SHIFT(Gpu.Query); |
| 395 |
FIELD_TO_OFS_8SHIFT(Gpu.RenderTarget); |
| 396 |
FIELD_TO_OFS_8SHIFT(Gpu.S3d); |
| 397 |
FIELD_TO_OFS_8SHIFT(Gpu.S3dDx); |
| 398 |
FIELD_TO_OFS_8SHIFT(Gpu.__S3dNonPacked); |
| 399 |
FIELD_TO_OFS_8SHIFT(Gpu.ScratchFlat); |
| 400 |
FIELD_TO_OFS_8SHIFT(Gpu.SeparateStencil); |
| 401 |
FIELD_TO_OFS_8SHIFT(Gpu.State); |
| 402 |
FIELD_TO_OFS_8SHIFT(Gpu.Stream); |
| 403 |
FIELD_TO_OFS_8SHIFT(Gpu.TextApi); |
| 404 |
FIELD_TO_OFS_8SHIFT(Gpu.Texture); |
| 405 |
FIELD_TO_OFS_8SHIFT(Gpu.TiledResource); |
| 406 |
FIELD_TO_OFS_8SHIFT(Gpu.TilePool); |
| 407 |
FIELD_TO_OFS_8SHIFT(Gpu.UnifiedAuxSurface); |
| 408 |
FIELD_TO_OFS_8SHIFT(Gpu.Vertex); |
| 409 |
FIELD_TO_OFS_8SHIFT(Gpu.Video); |
| 410 |
FIELD_TO_OFS_8SHIFT(Gpu.__NonMsaaTileXCcs); |
| 411 |
FIELD_TO_OFS_8SHIFT(Gpu.__NonMsaaTileYCcs); |
| 412 |
FIELD_TO_OFS_8SHIFT(Gpu.__MsaaTileMcs); |
| 413 |
FIELD_TO_OFS_8SHIFT(Gpu.__NonMsaaLinearCCS); |
| 414 |
FIELD_TO_OFS_8SHIFT(Gpu.__Remaining); |
| 415 |
|
| 416 |
EMPTY_TO_OFS(); |
| 417 |
FIELD_TO_OFS_8SHIFT(Info.AllowVirtualPadding); |
| 418 |
FIELD_TO_OFS_8SHIFT(Info.BigPage); |
| 419 |
FIELD_TO_OFS_8SHIFT(Info.Cacheable); |
| 420 |
FIELD_TO_OFS_8SHIFT(Info.ContigPhysMemoryForiDART); |
| 421 |
FIELD_TO_OFS_8SHIFT(Info.CornerTexelMode); |
| 422 |
FIELD_TO_OFS_8SHIFT(Info.ExistingSysMem); |
| 423 |
FIELD_TO_OFS_8SHIFT(Info.ForceResidency); |
| 424 |
FIELD_TO_OFS_8SHIFT(Info.Gfdt); |
| 425 |
FIELD_TO_OFS_8SHIFT(Info.GttMapType); |
| 426 |
FIELD_TO_OFS_8SHIFT(Info.HardwareProtected); |
| 427 |
FIELD_TO_OFS_8SHIFT(Info.KernelModeMapped); |
| 428 |
FIELD_TO_OFS_8SHIFT(Info.LayoutBelow); |
| 429 |
FIELD_TO_OFS_8SHIFT(Info.LayoutMono); |
| 430 |
FIELD_TO_OFS_8SHIFT(Info.LocalOnly); |
| 431 |
FIELD_TO_OFS_8SHIFT(Info.Linear); |
| 432 |
FIELD_TO_OFS_8SHIFT(Info.MediaCompressed); |
| 433 |
FIELD_TO_OFS_8SHIFT(Info.NoOptimizationPadding); |
| 434 |
FIELD_TO_OFS_8SHIFT(Info.NoPhysMemory); |
| 435 |
FIELD_TO_OFS_8SHIFT(Info.NotLockable); |
| 436 |
FIELD_TO_OFS_8SHIFT(Info.NonLocalOnly); |
| 437 |
FIELD_TO_OFS_8SHIFT(Info.StdSwizzle); |
| 438 |
FIELD_TO_OFS_8SHIFT(Info.PseudoStdSwizzle); |
| 439 |
FIELD_TO_OFS_8SHIFT(Info.Undefined64KBSwizzle); |
| 440 |
FIELD_TO_OFS_8SHIFT(Info.RedecribedPlanes); |
| 441 |
FIELD_TO_OFS_8SHIFT(Info.RenderCompressed); |
| 442 |
FIELD_TO_OFS_8SHIFT(Info.Rotated); |
| 443 |
FIELD_TO_OFS_8SHIFT(Info.Shared); |
| 444 |
FIELD_TO_OFS_8SHIFT(Info.SoftwareProtected); |
| 445 |
FIELD_TO_OFS_8SHIFT(Info.SVM); |
| 446 |
#if !defined(LINUX) |
| 447 |
FIELD_TO_OFS_8SHIFT(Info.Tile4); |
| 448 |
FIELD_TO_OFS_8SHIFT(Info.Tile64); |
| 449 |
#endif |
| 450 |
FIELD_TO_OFS_8SHIFT(Info.TiledW); |
| 451 |
FIELD_TO_OFS_8SHIFT(Info.TiledX); |
| 452 |
FIELD_TO_OFS_8SHIFT(Info.TiledY); |
| 453 |
FIELD_TO_OFS_8SHIFT(Info.TiledYf); |
| 454 |
FIELD_TO_OFS_8SHIFT(Info.TiledYs); |
| 455 |
FIELD_TO_OFS_8SHIFT(Info.XAdapter); |
| 456 |
FIELD_TO_OFS_8SHIFT(Info.__PreallocatedResInfo); |
| 457 |
#if !defined(LINUX) |
| 458 |
FIELD_TO_OFS_8SHIFT(Info.LMemBarPreferred); |
| 459 |
FIELD_TO_OFS_8SHIFT(Info.LMemBarOrNonlocalOnly); |
| 460 |
FIELD_TO_OFS_8SHIFT(Info.LMemBarIndifferent); |
| 461 |
FIELD_TO_OFS_8SHIFT(Info.CpuVisibleOnDemand); |
| 462 |
FIELD_TO_OFS_8SHIFT(Info.DwmFbrResource); |
| 463 |
#endif |
| 464 |
|
| 465 |
EMPTY_TO_OFS(); |
| 466 |
FIELD_TO_OFS_8SHIFT(Wa.GTMfx2ndLevelBatchRingSizeAlign); |
| 467 |
FIELD_TO_OFS_8SHIFT(Wa.ILKNeedAvcMprRowStore32KAlign); |
| 468 |
FIELD_TO_OFS_8SHIFT(Wa.ILKNeedAvcDmvBuffer32KAlign); |
| 469 |
FIELD_TO_OFS_8SHIFT(Wa.NoBufferSamplerPadding); |
| 470 |
FIELD_TO_OFS_8SHIFT(Wa.NoLegacyPlanarLinearVideoRestrictions); |
| 471 |
FIELD_TO_OFS_8SHIFT(Wa.CHVAstcSkipVirtualMips); |
| 472 |
FIELD_TO_OFS_8SHIFT(Wa.DisablePackedMipTail); |
| 473 |
FIELD_TO_OFS_8SHIFT(Wa.__ForceOtherHVALIGN4); |
| 474 |
FIELD_TO_OFS_8SHIFT(Wa.DisableDisplayCcsClearColor); |
| 475 |
FIELD_TO_OFS_8SHIFT(Wa.DisableDisplayCcsCompression); |
| 476 |
FIELD_TO_OFS_8SHIFT(Wa.PreGen12FastClearOnly); |
| 477 |
#if !defined(LINUX) |
| 478 |
FIELD_TO_OFS_8SHIFT(Wa.ForceStdAllocAlign); |
| 479 |
#endif |
| 480 |
} |
| 481 |
|
| 482 |
FIELD_TO_OFS(GetBaseWidth(), ); |
| 483 |
FIELD_TO_OFS(GetBaseHeight(), ); |
| 484 |
FIELD_TO_OFS(GetBaseDepth(), ); |
| 485 |
FIELD_TO_OFS(GetMaxLod(), ); |
| 486 |
FIELD_TO_OFS(GetArraySize(), ); |
| 487 |
FIELD_TO_OFS(GetSetCpSurfTag(0, 0), ); |
| 488 |
FIELD_TO_OFS(GetCachePolicyUsage(), ); |
| 489 |
FIELD_TO_OFS(GetNumSamples(), ); |
| 490 |
FIELD_TO_OFS(GetSamplePattern(), ); |
| 491 |
|
| 492 |
EMPTY_TO_OFS(); |
| 493 |
FIELD_TO_OFS(IsArraySpacingSingleLod(), ); |
| 494 |
FIELD_TO_OFS(GetBaseAlignment(), ); |
| 495 |
FIELD_TO_OFS(GetHAlign(), ); |
| 496 |
FIELD_TO_OFS(GetVAlign(), ); |
| 497 |
FIELD_TO_OFS(GetMipTailStartLodSurfaceState(), ); |
| 498 |
FIELD_TO_OFS(GetQPitch(), ); |
| 499 |
|
| 500 |
EMPTY_TO_OFS(); |
| 501 |
ofs << "MmcMode[GMM_MAX_MMC_INDEX == " << GMM_MAX_MMC_INDEX << "]: {"; |
| 502 |
for (uint32_t i = 0; i < GMM_MAX_MMC_INDEX; ++i) |
| 503 |
ofs << (uint32_t)ptr->GetMmcMode(i) << ", "; |
| 504 |
ofs << "}" << std::endl; |
| 505 |
|
| 506 |
ofs << "MmcHint[GMM_MAX_MMC_INDEX == " << GMM_MAX_MMC_INDEX << "]: {"; |
| 507 |
for (uint32_t i = 0; i < GMM_MAX_MMC_INDEX; ++i) |
| 508 |
ofs << (uint32_t)ptr->GetMmcHint(i) << ", "; |
| 509 |
ofs << "}" << std::endl; |
| 510 |
|
| 511 |
FIELD_TO_OFS(GetRenderPitch(), ); |
| 512 |
FIELD_TO_OFS(GetSizeMainSurface(), ); |
| 513 |
FIELD_TO_OFS(GmmGetTileMode(), ); |
| 514 |
|
| 515 |
#if !defined(LINUX) |
| 516 |
EMPTY_TO_OFS(); |
| 517 |
FIELD_TO_OFS(GetMultiTileArch().Enable, ); |
| 518 |
#endif |
| 519 |
} |
| 520 |
|
| 521 |
return MOS_STATUS_SUCCESS; |
| 522 |
} |
| 523 |
#undef FIELD_TO_OFS_8SHIFT |
| 524 |
#undef RESOURCE_OFFSET_TO_OFS |
| 525 |
#undef PLANE_OFFSET_TO_OFS |
| 526 |
#undef OFFSET_FIELD_TO_OFS |
| 527 |
#undef UNION_END_TO_OFS |
| 528 |
#undef UNION_STRUCT_FIELD_TO_OFS |
| 529 |
#undef UNION_STRUCT_START_TO_OFS |
| 530 |
#undef EMPTY_TO_OFS |
| 531 |
#undef FIELD_TO_OFS |
| 532 |
|
| 533 |
MOS_STATUS MediaDebugInterface::DumpBltOutput( |
| 534 |
PMOS_SURFACE surface, |
| 535 |
const char * attrName) |
| 536 |
{ |
| 537 |
return MOS_STATUS_SUCCESS; |
| 538 |
} |
| 539 |
|
| 540 |
MOS_STATUS MediaDebugInterface::DeleteCfgLinkNode(uint32_t frameIdx) |
| 541 |
{ |
| 542 |
return m_configMgr->DeleteCfgNode(frameIdx); |
| 543 |
} |
| 544 |
|
| 545 |
MOS_STATUS MediaDebugInterface::ReAllocateSurface( |
| 546 |
PMOS_SURFACE pSurface, |
| 547 |
PMOS_SURFACE pSrcSurf, |
| 548 |
PCCHAR pSurfaceName, |
| 549 |
MOS_GFXRES_TYPE defaultResType, |
| 550 |
bool useLinearResource) |
| 551 |
{ |
| 552 |
MOS_ALLOC_GFXRES_PARAMS allocParams; |
| 553 |
|
| 554 |
MEDIA_DEBUG_ASSERT(m_osInterface); |
| 555 |
MEDIA_DEBUG_ASSERT(&pSurface->OsResource); |
| 556 |
|
| 557 |
// bCompressible should be compared with bCompressible since it is inited by bCompressible in previous call |
| 558 |
// TileType of surface should be compared since we need to reallocate surface if TileType changes |
| 559 |
if (!Mos_ResourceIsNull(&pSurface->OsResource) && |
| 560 |
(pSurface->dwWidth == pSrcSurf->dwWidth) && |
| 561 |
(pSurface->dwHeight == pSrcSurf->dwHeight) && |
| 562 |
(pSurface->Format == pSrcSurf->Format) && |
| 563 |
((pSurface->bCompressible == pSrcSurf->bCompressible) || useLinearResource) && // omit this check as linear surface is uncompressible |
| 564 |
(pSurface->CompressionMode == pSrcSurf->CompressionMode) && |
| 565 |
((pSurface->TileType == pSrcSurf->TileType) || |
| 566 |
(pSurface->TileType == MOS_TILE_LINEAR && useLinearResource))) // when useLinearResource no reallocation needed |
| 567 |
{ |
| 568 |
MEDIA_DEBUG_VERBOSEMESSAGE("Skip to reallocate temp surface."); |
| 569 |
return MOS_STATUS_SUCCESS; |
| 570 |
} |
| 571 |
MOS_ZeroMemory(&allocParams, sizeof(MOS_ALLOC_GFXRES_PARAMS)); |
| 572 |
|
| 573 |
#if !EMUL |
| 574 |
// Need to reallocate surface according to expected tiletype instead of tiletype of the surface what we have |
| 575 |
if ((pSurface->OsResource.pGmmResInfo != nullptr) && |
| 576 |
(pSurface->TileType == pSrcSurf->TileType)) |
| 577 |
{ |
| 578 |
// Reallocate but use same tile type and resource type as current |
| 579 |
allocParams.TileType = pSurface->OsResource.TileType; |
| 580 |
allocParams.Type = defaultResType; |
| 581 |
} |
| 582 |
else |
| 583 |
#endif |
| 584 |
{ |
| 585 |
// First time allocation. Caller must specify default params |
| 586 |
allocParams.TileType = pSrcSurf->TileType; |
| 587 |
allocParams.Type = defaultResType; |
| 588 |
} |
| 589 |
|
| 590 |
// Force to use tile linear for reallocated resource |
| 591 |
if (useLinearResource) |
| 592 |
{ |
| 593 |
allocParams.TileType = MOS_TILE_LINEAR; |
| 594 |
allocParams.Type = MOS_GFXRES_2D; |
| 595 |
} |
| 596 |
|
| 597 |
allocParams.dwWidth = pSrcSurf->dwWidth; |
| 598 |
allocParams.dwHeight = pSrcSurf->dwHeight; |
| 599 |
allocParams.Format = pSrcSurf->Format; |
| 600 |
allocParams.bIsCompressible = pSrcSurf->bCompressible; |
| 601 |
allocParams.CompressionMode = pSrcSurf->CompressionMode; |
| 602 |
allocParams.pBufName = pSurfaceName; |
| 603 |
allocParams.dwArraySize = 1; |
| 604 |
|
| 605 |
// Delete resource if already allocated |
| 606 |
m_osInterface->pfnFreeResource(m_osInterface, &(pSurface->OsResource)); |
| 607 |
|
| 608 |
// Allocate surface |
| 609 |
CODECHAL_PUBLIC_CHK_STATUS_RETURN(m_osInterface->pfnAllocateResource( |
| 610 |
m_osInterface, |
| 611 |
&allocParams, |
| 612 |
&pSurface->OsResource)); |
| 613 |
|
| 614 |
if (!m_osInterface->apoMosEnabled) |
| 615 |
{ |
| 616 |
MOS_SURFACE details; |
| 617 |
MOS_ZeroMemory(&details, sizeof(details)); |
| 618 |
details.Format = Format_Invalid; |
| 619 |
|
| 620 |
MEDIA_DEBUG_CHK_STATUS(m_osInterface->pfnGetResourceInfo(m_osInterface, &pSurface->OsResource, &details)); |
| 621 |
|
| 622 |
pSurface->dwWidth = details.dwWidth; |
| 623 |
pSurface->dwHeight = details.dwHeight; |
| 624 |
pSurface->dwPitch = details.dwPitch; |
| 625 |
pSurface->dwDepth = details.dwDepth; |
| 626 |
pSurface->dwQPitch = details.dwQPitch; |
| 627 |
pSurface->bArraySpacing = details.bArraySpacing; |
| 628 |
pSurface->bCompressible = details.bCompressible; |
| 629 |
pSurface->CompressionMode = details.CompressionMode; |
| 630 |
pSurface->bIsCompressed = details.bIsCompressed; |
| 631 |
pSurface->Format = details.Format; |
| 632 |
pSurface->TileType = details.TileType; |
| 633 |
pSurface->dwOffset = details.RenderOffset.YUV.Y.BaseOffset; |
| 634 |
pSurface->YPlaneOffset.iSurfaceOffset = details.RenderOffset.YUV.Y.BaseOffset; |
| 635 |
pSurface->YPlaneOffset.iXOffset = details.RenderOffset.YUV.Y.XOffset; |
| 636 |
pSurface->YPlaneOffset.iYOffset = |
| 637 |
(pSurface->YPlaneOffset.iSurfaceOffset - pSurface->dwOffset) / pSurface->dwPitch + |
| 638 |
details.RenderOffset.YUV.Y.YOffset; |
| 639 |
pSurface->UPlaneOffset.iSurfaceOffset = details.RenderOffset.YUV.U.BaseOffset; |
| 640 |
pSurface->UPlaneOffset.iXOffset = details.RenderOffset.YUV.U.XOffset; |
| 641 |
pSurface->UPlaneOffset.iYOffset = |
| 642 |
(pSurface->UPlaneOffset.iSurfaceOffset - pSurface->dwOffset) / pSurface->dwPitch + |
| 643 |
details.RenderOffset.YUV.U.YOffset; |
| 644 |
pSurface->UPlaneOffset.iLockSurfaceOffset = details.LockOffset.YUV.U; |
| 645 |
pSurface->VPlaneOffset.iSurfaceOffset = details.RenderOffset.YUV.V.BaseOffset; |
| 646 |
pSurface->VPlaneOffset.iXOffset = details.RenderOffset.YUV.V.XOffset; |
| 647 |
pSurface->VPlaneOffset.iYOffset = |
| 648 |
(pSurface->VPlaneOffset.iSurfaceOffset - pSurface->dwOffset) / pSurface->dwPitch + |
| 649 |
details.RenderOffset.YUV.V.YOffset; |
| 650 |
pSurface->VPlaneOffset.iLockSurfaceOffset = details.LockOffset.YUV.V; |
| 651 |
} |
| 652 |
else |
| 653 |
{ |
| 654 |
pSurface->Format = Format_Invalid; |
| 655 |
MEDIA_DEBUG_CHK_STATUS(m_osInterface->pfnGetResourceInfo(m_osInterface, &pSurface->OsResource, pSurface)); |
| 656 |
} |
| 657 |
|
| 658 |
return MOS_STATUS_SUCCESS; |
| 659 |
} |
| 660 |
|
| 661 |
MOS_STATUS MediaDebugInterface::Dump2DBufferInBinary( |
| 662 |
uint8_t *data, |
| 663 |
uint32_t width, |
| 664 |
uint32_t height, |
| 665 |
uint32_t pitch) |
| 666 |
{ |
| 667 |
MEDIA_DEBUG_CHK_NULL(data); |
| 668 |
|
| 669 |
const char *filePath = m_outputFileName.c_str(); |
| 670 |
|
| 671 |
if (width == 0 || height == 0 || pitch == 0) |
| 672 |
{ |
| 673 |
return MOS_STATUS_UNKNOWN; |
| 674 |
} |
| 675 |
|
| 676 |
std::ofstream ofs(filePath, std::ios_base::out | std::ios_base::binary); |
| 677 |
if (ofs.fail()) |
| 678 |
{ |
| 679 |
return MOS_STATUS_UNKNOWN; |
| 680 |
} |
| 681 |
|
| 682 |
for (uint32_t h = 0; h < height; h++) |
| 683 |
{ |
| 684 |
ofs.write((char *)data, width); |
| 685 |
data += pitch; |
| 686 |
} |
| 687 |
|
| 688 |
ofs.close(); |
| 689 |
return MOS_STATUS_SUCCESS; |
| 690 |
} |
| 691 |
|
| 692 |
MOS_STATUS MediaDebugInterface::DumpBufferInBinary(uint8_t *data, uint32_t size) |
| 693 |
{ |
| 694 |
MEDIA_DEBUG_CHK_NULL(data); |
| 695 |
|
| 696 |
const char *filePath = m_outputFileName.c_str(); |
| 697 |
|
| 698 |
if (size == 0) |
| 699 |
{ |
| 700 |
return MOS_STATUS_UNKNOWN; |
| 701 |
} |
| 702 |
|
| 703 |
std::ofstream ofs(filePath, std::ios_base::out | std::ios_base::binary); |
| 704 |
if (ofs.fail()) |
| 705 |
{ |
| 706 |
return MOS_STATUS_UNKNOWN; |
| 707 |
} |
| 708 |
|
| 709 |
ofs.write((char *)data, size); |
| 710 |
ofs.close(); |
| 711 |
return MOS_STATUS_SUCCESS; |
| 712 |
} |
| 713 |
|
| 714 |
MOS_STATUS MediaDebugInterface::LoadBufferInBinary(uint8_t *data, uint32_t size) |
| 715 |
{ |
| 716 |
MEDIA_DEBUG_CHK_NULL(data); |
| 717 |
|
| 718 |
const char *filePath = m_outputFileName.c_str(); |
| 719 |
|
| 720 |
if (size == 0) |
| 721 |
{ |
| 722 |
return MOS_STATUS_UNKNOWN; |
| 723 |
} |
| 724 |
|
| 725 |
std::ifstream ifs(filePath, std::ios_base::in | std::ios_base::binary); |
| 726 |
if (ifs.fail()) |
| 727 |
{ |
| 728 |
return MOS_STATUS_UNKNOWN; |
| 729 |
} |
| 730 |
ifs.read((char *)data, size); |
| 731 |
ifs.close(); |
| 732 |
return MOS_STATUS_SUCCESS; |
| 733 |
} |
| 734 |
|
| 735 |
MOS_STATUS MediaDebugInterface::DumpBufferInHexDwords(uint8_t *data, uint32_t size) |
| 736 |
{ |
| 737 |
MEDIA_DEBUG_CHK_NULL(data); |
| 738 |
|
| 739 |
const char *filePath = m_outputFileName.c_str(); |
| 740 |
|
| 741 |
if (size == 0) |
| 742 |
{ |
| 743 |
return MOS_STATUS_UNKNOWN; |
| 744 |
} |
| 745 |
|
| 746 |
std::ofstream ofs(filePath); |
| 747 |
|
| 748 |
if (ofs.fail()) |
| 749 |
{ |
| 750 |
return MOS_STATUS_UNKNOWN; |
| 751 |
} |
| 752 |
|
| 753 |
uint32_t dwordSize = size / sizeof(uint32_t); |
| 754 |
uint32_t remainSize = size % sizeof(uint32_t); |
| 755 |
|
| 756 |
uint32_t *dwordData = (uint32_t *)data; |
| 757 |
uint32_t i; |
| 758 |
for (i = 0; i < dwordSize; i++) |
| 759 |
{ |
| 760 |
ofs << std::hex << std::setw(8) << std::setfill('0') << +dwordData[i] |
| 761 |
<< ((i + 1) % 4 == 0 ? "\n" : " "); |
| 762 |
} |
| 763 |
|
| 764 |
if (remainSize > 0) |
| 765 |
{ |
| 766 |
uint32_t lastWord = dwordData[i] & (0xFFFFFFFF << ((8 - remainSize * 2) * 4)); |
| 767 |
ofs << std::hex << std::setw(8) << std::setfill('0') << +lastWord << std::endl; |
| 768 |
} |
| 769 |
|
| 770 |
ofs.close(); |
| 771 |
|
| 772 |
return MOS_STATUS_SUCCESS; |
| 773 |
} |
| 774 |
|
| 775 |
MOS_STATUS MediaDebugInterface::InitCRCTable(uint32_t crcTable[256]) |
| 776 |
{ |
| 777 |
uint32_t polynomial = 0xEDB88320; |
| 778 |
for (uint32_t i = 0; i < 256; i++) |
| 779 |
{ |
| 780 |
uint32_t c = i; |
| 781 |
for (size_t j = 0; j < 8; j++) |
| 782 |
{ |
| 783 |
if (c & 1) |
| 784 |
{ |
| 785 |
c = polynomial ^ (c >> 1); |
| 786 |
} |
| 787 |
else |
| 788 |
{ |
| 789 |
c >>= 1; |
| 790 |
} |
| 791 |
} |
| 792 |
crcTable[i] = c; |
| 793 |
} |
| 794 |
return MOS_STATUS_SUCCESS; |
| 795 |
} |
| 796 |
|
| 797 |
uint32_t MediaDebugInterface::CalculateCRC(const void *buf, size_t len, uint32_t initial) |
| 798 |
{ |
| 799 |
uint32_t c = initial ^ 0xFFFFFFFF; |
| 800 |
const uint8_t *u = static_cast<const uint8_t *>(buf); |
| 801 |
for (size_t i = 0; i < len; ++i) |
| 802 |
{ |
| 803 |
c = m_crcTable[(c ^ u[i]) & 0xFF] ^ (c >> 8); |
| 804 |
} |
| 805 |
return c ^ 0xFFFFFFFF; |
| 806 |
} |
| 807 |
|
| 808 |
#endif // USE_MEDIA_DEBUG_TOOL |