1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
|
/*==============================================================================
Copyright(c) 2017 Intel Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files(the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and / or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
============================================================================*/
#include "Internal/Common/GmmLibInc.h"
/////////////////////////////////////////////////////////////////////////////////////
/// Checks that clients only set Presentable flag during a resource allocation, ONLY
/// when a platform supported render target is selected in ::GMM_RESOURCE_FORMAT enum.
///
/// @return true if displayable, false otherwise.
/////////////////////////////////////////////////////////////////////////////////////
bool GmmLib::GmmResourceInfoCommon::IsPresentableformat()
{
const GMM_PLATFORM_INFO *pPlatform;
const GMM_FORMAT_ENTRY * FormatTable = NULL;
GMM_DPF_ENTER;
__GMM_ASSERTPTR(pGmmGlobalContext, false);
pPlatform = GMM_OVERRIDE_PLATFORM_INFO(&Surf);
FormatTable = &(pPlatform->FormatTable[0]);
if(Surf.Flags.Gpu.Presentable == false)
{
// When Presentable flag is not set, no reason to check for valid RT
// platform supported format. Safe to return true.
return true;
}
if((Surf.Format > GMM_FORMAT_INVALID) &&
(Surf.Format < GMM_RESOURCE_FORMATS))
{
if((FormatTable[Surf.Format].RenderTarget) &&
(FormatTable[Surf.Format].Supported))
{
return true;
}
else
{
GMM_ASSERTDPF(0, "Present flag can only be set w/ a format!");
return false;
}
}
return false;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns the restrictions that a particular resource must follow on a particular
/// OS or hardware.
///
/// @param[out] Restrictions: restrictions that this resource must adhere to
/////////////////////////////////////////////////////////////////////////////////////
void GmmLib::GmmResourceInfoCommon::GetRestrictions(__GMM_BUFFER_TYPE &Restrictions)
{
GMM_DPF_ENTER;
GMM_TEXTURE_CALC *pTextureCalc = NULL;
pTextureCalc = GMM_OVERRIDE_TEXTURE_CALC(&Surf);
pTextureCalc->GetResRestrictions(&Surf, Restrictions);
GMM_DPF_EXIT;
}
//=============================================================================
//
// Function: GmmResGetRestrictions
//
// Desc: This routine returns resource restrictions
//
// Parameters:
// pPlatform: ptr to HW_DEVICE_EXTENSION
// pResourceInfo: ptr to GMM_RESOURCE_INFO
// pRestrictions: ptr to restrictions
//
// Returns:
// void
//
//-----------------------------------------------------------------------------
void GMM_STDCALL GmmResGetRestrictions(GMM_RESOURCE_INFO *pResourceInfo,
__GMM_BUFFER_TYPE *pRestrictions)
{
pResourceInfo->GetRestrictions(*pRestrictions);
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns the best restrictions by comparing two buffer types. Each buffer type
/// carries alignment and size restrictions.
///
/// @param[in] pFirstBuffer: Contains surface alignment and size restrictions
/// @param[in] pSecondBuffer: Contains surface alignment and size restrictions
///
/// @return Best Restrictions based on the two parameters passed
/////////////////////////////////////////////////////////////////////////////////////
__GMM_BUFFER_TYPE *GmmLib::GmmTextureCalc::GetBestRestrictions(__GMM_BUFFER_TYPE * pFirstBuffer,
const __GMM_BUFFER_TYPE *pSecondBuffer)
{
GMM_DPF_ENTER;
if(IsRestrictionInvalid(pFirstBuffer)) //default
{
*pFirstBuffer = *pSecondBuffer;
return pFirstBuffer;
}
pFirstBuffer->Alignment = GFX_MAX(pFirstBuffer->Alignment,
pSecondBuffer->Alignment);
pFirstBuffer->PitchAlignment = GFX_MAX(pFirstBuffer->PitchAlignment,
pSecondBuffer->PitchAlignment);
pFirstBuffer->RenderPitchAlignment = GFX_MAX(pFirstBuffer->RenderPitchAlignment,
pSecondBuffer->RenderPitchAlignment);
pFirstBuffer->LockPitchAlignment = GFX_MAX(pFirstBuffer->LockPitchAlignment,
pSecondBuffer->LockPitchAlignment);
pFirstBuffer->MinPitch = GFX_MAX(pFirstBuffer->MinPitch,
pSecondBuffer->MinPitch);
pFirstBuffer->MinAllocationSize = GFX_MAX(pFirstBuffer->MinAllocationSize,
pSecondBuffer->MinAllocationSize);
pFirstBuffer->MinDepth = GFX_MAX(pFirstBuffer->MinDepth,
pSecondBuffer->MinDepth);
pFirstBuffer->MinHeight = GFX_MAX(pFirstBuffer->MinHeight,
pSecondBuffer->MinHeight);
pFirstBuffer->MinWidth = GFX_MAX(pFirstBuffer->MinWidth,
pSecondBuffer->MinWidth);
pFirstBuffer->MaxDepth = GFX_MIN(pFirstBuffer->MaxDepth,
pSecondBuffer->MaxDepth);
pFirstBuffer->MaxHeight = GFX_MIN(pFirstBuffer->MaxHeight,
pSecondBuffer->MaxHeight);
pFirstBuffer->MaxWidth = GFX_MIN(pFirstBuffer->MaxWidth,
pSecondBuffer->MaxWidth);
pFirstBuffer->NeedPow2LockAlignment = pFirstBuffer->NeedPow2LockAlignment |
pSecondBuffer->NeedPow2LockAlignment;
GMM_DPF_EXIT;
return pFirstBuffer;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns restrictions for 1D, 2D, 3D textures depending on how the surface
/// may possibliy be used.
///
/// @param[out] pBuff: Restrictions filled in this struct
/////////////////////////////////////////////////////////////////////////////////////
void GmmLib::GmmTextureCalc::GetGenericRestrictions(GMM_TEXTURE_INFO *pTexInfo, __GMM_BUFFER_TYPE *pBuff)
{
GMM_DPF_ENTER;
const GMM_PLATFORM_INFO *pPlatformResource = GMM_OVERRIDE_PLATFORM_INFO(pTexInfo);
if(pTexInfo->Flags.Gpu.NoRestriction)
{
// Impose zero restrictions. Ignore any other GPU usage flags
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->NoRestriction);
return;
}
if(pTexInfo->Flags.Gpu.Texture)
{
if(pTexInfo->Type == RESOURCE_BUFFER)
{
*pBuff = pPlatformResource->BufferType;
}
else if(pTexInfo->Type == RESOURCE_CUBE)
{
*pBuff = pPlatformResource->CubeSurface;
}
else if(pTexInfo->Type == RESOURCE_3D)
{
*pBuff = pPlatformResource->Texture3DSurface;
}
else
{
*pBuff = pPlatformResource->Texture2DSurface;
if(pTexInfo->Flags.Info.Linear)
{
*pBuff = pPlatformResource->Texture2DLinearSurface;
}
if(GmmIsReconstructableSurface(pTexInfo->Format))
{
pBuff->MaxHeight = pPlatformResource->ReconMaxHeight;
pBuff->MaxWidth = pPlatformResource->ReconMaxWidth;
}
}
}
if(pTexInfo->Flags.Gpu.RenderTarget ||
pTexInfo->Flags.Gpu.CCS ||
pTexInfo->Flags.Gpu.MCS)
{
// Gen7 onwards, bound by SURFACE_STATE constraints.
if(pTexInfo->Type == RESOURCE_BUFFER)
{
*pBuff = pPlatformResource->BufferType;
}
else if(pTexInfo->Type == RESOURCE_CUBE)
{
*pBuff = pPlatformResource->CubeSurface;
}
else if(pTexInfo->Type == RESOURCE_3D)
{
*pBuff = pPlatformResource->Texture3DSurface;
}
else
{
*pBuff = pPlatformResource->Texture2DSurface;
if(pTexInfo->Flags.Info.Linear)
{
*pBuff = pPlatformResource->Texture2DLinearSurface;
}
if(GmmIsReconstructableSurface(pTexInfo->Format))
{
pBuff->MaxHeight = pPlatformResource->ReconMaxHeight;
pBuff->MaxWidth = pPlatformResource->ReconMaxWidth;
}
}
}
if(pTexInfo->Flags.Gpu.Depth)
{
// Z
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Depth);
}
if(pTexInfo->Flags.Gpu.Vertex)
{
// VertexData
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Vertex);
}
if(pTexInfo->Flags.Gpu.Index)
{
// Index buffer
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Index);
}
if(pTexInfo->Flags.Gpu.FlipChain)
{
// Async Flip
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->ASyncFlipSurface);
}
if(pTexInfo->Flags.Gpu.MotionComp)
{
// Media buffer
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->MotionComp);
}
if(pTexInfo->Flags.Gpu.State ||
pTexInfo->Flags.Gpu.InstructionFlat ||
pTexInfo->Flags.Gpu.ScratchFlat)
{
// indirect state
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Vertex);
}
if(pTexInfo->Flags.Gpu.Query ||
pTexInfo->Flags.Gpu.HistoryBuffer)
{
// Query
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->NoRestriction);
}
if(pTexInfo->Flags.Gpu.Constant)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Constant);
}
if(pTexInfo->Flags.Gpu.Stream)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Stream);
}
if(pTexInfo->Flags.Gpu.InterlacedScan)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->InterlacedScan);
}
if(pTexInfo->Flags.Gpu.TextApi)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->TextApi);
}
if(pTexInfo->Flags.Gpu.SeparateStencil)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Stencil);
}
if(pTexInfo->Flags.Gpu.HiZ)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->HiZ);
}
if(pTexInfo->Flags.Gpu.Video)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Video);
if(GmmIsReconstructableSurface(pTexInfo->Format))
{
pBuff->MaxHeight = pPlatformResource->ReconMaxHeight;
pBuff->MaxWidth = pPlatformResource->ReconMaxWidth;
}
}
if(pTexInfo->Flags.Gpu.StateDx9ConstantBuffer)
{
//
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->StateDx9ConstantBuffer);
}
if(pTexInfo->Flags.Gpu.Overlay)
{
// Overlay buffer use Async Flip values
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->Overlay);
if((pTexInfo->Format == GMM_FORMAT_YUY2) && (pTexInfo->BaseWidth == 640))
{
// override the pitch alignment
pBuff->PitchAlignment = 64;
}
}
if(pTexInfo->Flags.Info.XAdapter)
{
//Add Cross Adapter resource restriction for hybrid graphics.
pBuff = GetBestRestrictions(pBuff, &pPlatformResource->XAdapter);
if(pTexInfo->Type == RESOURCE_BUFFER)
{
pBuff->MaxWidth = pPlatformResource->SurfaceMaxSize;
pBuff->MaxPitch = pPlatformResource->BufferType.MaxPitch;
pBuff->MaxHeight = 1;
}
}
//Non Aligned ExistingSysMem Special cases.
if((pTexInfo->Flags.Info.ExistingSysMem &&
(!pTexInfo->ExistingSysMem.IsGmmAllocated) &&
(!pTexInfo->ExistingSysMem.IsPageAligned)))
{
if(pTexInfo->Flags.Info.Linear ||
pTexInfo->Flags.Info.SVM)
{
if(pTexInfo->Type == RESOURCE_BUFFER)
{
//Use combination of BufferType, NoRestriction to support large buffer with minimal pitch alignment
*pBuff = pPlatformResource->BufferType;
pBuff->PitchAlignment = pPlatformResource->NoRestriction.PitchAlignment;
pBuff->LockPitchAlignment = pPlatformResource->NoRestriction.LockPitchAlignment;
pBuff->RenderPitchAlignment = pPlatformResource->NoRestriction.LockPitchAlignment;
pBuff->MinPitch = pPlatformResource->NoRestriction.MinPitch;
}
//[To DO] Handle other types when needed!
}
/*
else if(Surf.Flags.Gpu.Texture)
{
//Override as and when required
}
else if(Surf.Flags.Gpu.RenderTarget)
{
//Overide as and when Required
}*/
}
GMM_DPF_EXIT;
}
//=============================================================================
//
// Function: __GmmPlatformResetRestrictions
//
// Desc: This routine initializes a __GMM_BUFFER_TYPE. Once this function is
// called, the caller has a invalid restrictions.
//
// Parameters:
// pRestriction ==> Restrictions
// Returns:
// void
//
//-----------------------------------------------------------------------------
void __GmmPlatformResetRestrictions(__GMM_BUFFER_TYPE *pRestriction)
{
pRestriction->MinDepth = 0xffffffff;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Internal function returns the best restrictions depending on how the surface may
/// possibly be used.
///
/// @param[in] pTexInfo: ptr to ::GMM_TEXTURE_INFO,
/// @param[in] pRestrictions: Reference to surface alignment and size restrictions
///
/////////////////////////////////////////////////////////////////////////////////////
void GmmLib::GmmTextureCalc::GetTexRestrictions(GMM_TEXTURE_INFO * pTexInfo,
__GMM_BUFFER_TYPE *pRestrictions)
{
GMM_DPF_ENTER;
GetResRestrictions(pTexInfo, *pRestrictions);
GMM_DPF_EXIT;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Returns the restrictions that a particular resource must follow on a particular
/// OS or hardware.
///
/// @param[out] Restrictions: restrictions that this resource must adhere to
/////////////////////////////////////////////////////////////////////////////////////
void GmmLib::GmmTextureCalc::GetResRestrictions(GMM_TEXTURE_INFO * pTexinfo,
__GMM_BUFFER_TYPE &Restrictions)
{
GMM_DPF_ENTER;
const GMM_PLATFORM_INFO *pPlatform = NULL;
GMM_RESOURCE_FLAG ZeroGpuFlags;
__GMM_ASSERTPTR(pGmmGlobalContext, VOIDRETURN);
pPlatform = GMM_OVERRIDE_PLATFORM_INFO(pTexinfo);
// Check that at least one usage flag is set for allocations other than
// Primary/Shadow/Staging.
memset(&ZeroGpuFlags.Gpu, 0, sizeof(ZeroGpuFlags.Gpu));
if((pTexinfo->Type <= RESOURCE_KMD_CHECK_START ||
pTexinfo->Type >= RESOURCE_KMD_CHECK_END) &&
!memcmp(&pTexinfo->Flags.Gpu, &ZeroGpuFlags.Gpu, sizeof(ZeroGpuFlags.Gpu)))
{
GMM_ASSERTDPF(0, "No GPU Usage specified!");
return;
}
__GmmPlatformResetRestrictions(&Restrictions); //Set to Default
// Get worst case restrictions that match GPU flags set in resource
switch(pTexinfo->Type)
{
case RESOURCE_1D:
case RESOURCE_2D:
case RESOURCE_3D:
case RESOURCE_CUBE:
case RESOURCE_BUFFER:
case RESOURCE_SCRATCH:
case RESOURCE_GDI:
GetGenericRestrictions(pTexinfo, &Restrictions);
break;
case RESOURCE_HW_CONTEXT:
case RESOURCE_TAG_PAGE:
if(pTexinfo->Flags.Info.TiledW ||
pTexinfo->Flags.Info.TiledX ||
GMM_IS_4KB_TILE(pTexinfo->Flags))
{
GMM_ASSERTDPF(0, "Tiled Pref specified for RESOURCE_LINEAR!");
return;
}
GetLinearRestrictions(pTexinfo, &Restrictions);
break;
case RESOURCE_PRIMARY:
case RESOURCE_SHADOW:
case RESOURCE_STAGING:
GetPrimaryRestrictions(pTexinfo, &Restrictions);
break;
case RESOURCE_NNDI:
Restrictions = pPlatform->Nndi;
break;
case RESOURCE_HARDWARE_MBM:
case RESOURCE_IFFS_MAPTOGTT:
//Hardware MBM resource request can come for overlay allocation or normal
//displayable allocation. So get the restrictions accordingly
if(pTexinfo->Flags.Gpu.Overlay)
{
Restrictions = pPlatform->Overlay;
}
else
{
Restrictions = pPlatform->HardwareMBM;
}
break;
case RESOURCE_CURSOR:
case RESOURCE_PWR_CONTEXT:
case RESOURCE_KMD_BUFFER:
case RESOURCE_NULL_CONTEXT_INDIRECT_STATE:
case RESOURCE_PERF_DATA_QUEUE:
case RESOURCE_GLOBAL_BUFFER:
case RESOURCE_FBC:
case RESOURCE_GFX_CLIENT_BUFFER:
Restrictions = pPlatform->Cursor;
break;
case RESOURCE_OVERLAY_DMA:
Restrictions = pPlatform->NoRestriction;
break;
case RESOURCE_GTT_TRANSFER_REGION:
GetGenericRestrictions(pTexinfo, &Restrictions);
break;
case RESOURCE_OVERLAY_INTERMEDIATE_SURFACE:
Restrictions = pPlatform->Overlay;
break;
default:
GetGenericRestrictions(pTexinfo, &Restrictions);
GMM_ASSERTDPF(0, "Unkown Resource type");
}
// Apply any specific WA
if(((pTexinfo->Flags.Wa.ILKNeedAvcMprRowStore32KAlign)) ||
((pTexinfo->Flags.Wa.ILKNeedAvcDmvBuffer32KAlign)))
{
Restrictions.Alignment = GFX_ALIGN(Restrictions.Alignment, GMM_KBYTE(32));
}
if(pGmmGlobalContext->GetWaTable().WaAlignContextImage && (pTexinfo->Type == RESOURCE_HW_CONTEXT))
{
Restrictions.Alignment = GFX_ALIGN(Restrictions.Alignment, GMM_KBYTE(64));
}
if(pTexinfo->Flags.Gpu.S3d &&
pTexinfo->Flags.Info.Linear &&
!pGmmGlobalContext->GetSkuTable().FtrDisplayEngineS3d)
{
Restrictions.Alignment = PAGE_SIZE;
Restrictions.PitchAlignment = PAGE_SIZE;
}
if(pTexinfo->Flags.Gpu.TiledResource)
{
// Need at least 64KB alignment to track tile mappings (h/w or s/w tracking).
Restrictions.Alignment = GFX_ALIGN(Restrictions.Alignment, GMM_KBYTE(64));
// Buffer tiled resources are trivially divided into 64KB tiles => Pitch must divide into 64KB tiles
if(pTexinfo->Type == RESOURCE_BUFFER)
{
Restrictions.PitchAlignment = GFX_ALIGN(Restrictions.PitchAlignment, GMM_KBYTE(64));
}
if(GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) >= IGFX_GEN9_CORE)
{
pGmmGlobalContext->GetPlatformInfo().SurfaceMaxSize = GMM_TBYTE(1);
}
}
// SKL TileY Display needs 1MB alignment.
if(((pTexinfo->Type == RESOURCE_PRIMARY) ||
pTexinfo->Flags.Gpu.FlipChain) &&
(GMM_IS_4KB_TILE(pTexinfo->Flags) ||
pTexinfo->Flags.Info.TiledYf))
{
Restrictions.Alignment = GMM_MBYTE(1);
}
if(pTexinfo->Flags.Info.RenderCompressed ||
pTexinfo->Flags.Info.MediaCompressed)
{
Restrictions.Alignment = GFX_ALIGN(Restrictions.Alignment, (!WA16K ? GMM_KBYTE(64) : GMM_KBYTE(16)));
}
GMM_DPF_EXIT;
}
/////////////////////////////////////////////////////////////////////////////////////
/// Calculates surface size based on Non Aligned ExistingSysMem restrictions.
///
/// @return ::GMM_STATUS
/////////////////////////////////////////////////////////////////////////////////////
GMM_STATUS GmmLib::GmmResourceInfoCommon::ApplyExistingSysMemRestrictions()
{
const GMM_PLATFORM_INFO *pPlatform;
// Handle Minimal Restriction ExistingSysMem Requirements...
GMM_GFX_SIZE_T AdditionalPaddingBytes = 0;
GMM_GFX_SIZE_T AdditionalPaddingRows = 0;
GMM_GFX_SIZE_T BaseAlignment = 1; // 1 = Byte Alignment
GMM_GFX_SIZE_T EndAlignment = 1; // 1 = Byte Alignment
GMM_GFX_SIZE_T SizePadding = 1; // 1 = Byte Padding
uint32_t CompressHeight, CompressWidth, CompressDepth;
GMM_GFX_SIZE_T Width, Height;
GMM_TEXTURE_INFO *pTexInfo = &Surf;
GMM_TEXTURE_CALC *pTextureCalc;
GMM_DPF_ENTER;
pPlatform = GMM_OVERRIDE_PLATFORM_INFO(pTexInfo);
pTextureCalc = GMM_OVERRIDE_TEXTURE_CALC(pTexInfo);
Height = pTexInfo->BaseHeight;
Width = pTexInfo->BaseWidth;
#define UPDATE_BASE_ALIGNMENT(a) \
{ \
__GMM_ASSERT((GFX_MAX(BaseAlignment, a) % GFX_MIN(BaseAlignment, a)) == 0); /* Revisit if ever have to support complex alignments. */ \
BaseAlignment = GFX_MAX(BaseAlignment, a); \
}
#define UPDATE_PADDING(p) \
{ \
SizePadding = GFX_MAX(SizePadding, p); \
}
#define UPDATE_ADDITIONAL_ROWS(r) \
{ \
AdditionalPaddingRows = GFX_MAX(AdditionalPaddingRows, r); \
}
#define UPDATE_ADDITIONAL_BYTES(b) \
{ \
AdditionalPaddingBytes = GFX_MAX(AdditionalPaddingBytes, b); \
}
#define UPDATE_END_ALIGNMENT(a) \
{ \
__GMM_ASSERT((GFX_MAX(EndAlignment, a) % GFX_MIN(EndAlignment, a)) == 0); /* Revisit if ever have to support complex alignments. */ \
EndAlignment = GFX_MAX(EndAlignment, a); \
}
if(!pTexInfo->Pitch)
{
__GMM_ASSERT(pTexInfo->Type == RESOURCE_1D); // Clients can leave pitch zero for 1D, and we'll fill-in...
pTexInfo->Pitch = Width * (pTexInfo->BitsPerPixel >> 3);
}
__GMM_ASSERT( // Currently limiting our support...
pTexInfo->Flags.Gpu.NoRestriction ||
pTexInfo->Flags.Gpu.Index ||
pTexInfo->Flags.Gpu.RenderTarget ||
pTexInfo->Flags.Gpu.Texture ||
pTexInfo->Flags.Gpu.Vertex);
__GMM_ASSERT( // Trivial, Linear Surface...
((pTexInfo->Type == RESOURCE_BUFFER) || (pTexInfo->Type == RESOURCE_1D) || (pTexInfo->Type == RESOURCE_2D)) &&
(pTexInfo->MaxLod == 0) &&
!GMM_IS_TILED(pPlatform->TileInfo[pTexInfo->TileMode]) &&
!GmmIsPlanar(pTexInfo->Format) &&
((pTexInfo->ArraySize <= 1) || (pTexInfo->Type == RESOURCE_BUFFER)));
__GMM_ASSERT( // Valid Surface...
(Width > 0) &&
!((pTexInfo->Type == RESOURCE_BUFFER) && GmmIsYUVPacked(pTexInfo->Format)));
// Convert to compression blocks, if applicable...
if(GmmIsCompressed(pTexInfo->Format))
{
pTextureCalc->GetCompressionBlockDimensions(pTexInfo->Format, &CompressWidth, &CompressHeight, &CompressDepth);
Width = GFX_CEIL_DIV(Width, CompressWidth);
Height = GFX_CEIL_DIV(Height, CompressHeight);
}
__GMM_ASSERT( // Valid Surface Follow-Up...
(pTexInfo->Pitch >= (Width * (pTexInfo->BitsPerPixel >> 3))));
if(!pTexInfo->Flags.Gpu.NoRestriction && !pTexInfo->Flags.Info.SVM && !pTexInfo->Flags.Info.Linear)
{
if(pTexInfo->Flags.Gpu.Index) /////////////////////////////////////////////////////////
{
__GMM_ASSERT(!(
pTexInfo->Flags.Gpu.RenderTarget ||
pTexInfo->Flags.Gpu.Texture ||
pTexInfo->Flags.Gpu.Vertex)); // Can explore if needed what combo's make sense--and how req's should combine.
// 3DSTATE_INDEX_BUFFER...
UPDATE_BASE_ALIGNMENT(4); // 32-bit worst-case, since GMM doesn't receive element-size from clients.
if(pGmmGlobalContext->GetWaTable().WaAlignIndexBuffer)
{
UPDATE_END_ALIGNMENT(64);
}
else
{
UPDATE_END_ALIGNMENT(1);
}
}
if(pTexInfo->Flags.Gpu.Vertex) ////////////////////////////////////////////////////////
{
__GMM_ASSERT(!(
pTexInfo->Flags.Gpu.Index ||
pTexInfo->Flags.Gpu.RenderTarget ||
pTexInfo->Flags.Gpu.Texture)); // Can explore if needed what combo's make sense--and how req's should combine.
// VERTEX_BUFFER_STATE...
UPDATE_BASE_ALIGNMENT(1); // VB's have member alignment requirements--but it's up to UMD to enforce.
UPDATE_PADDING(1);
}
if(pTexInfo->Flags.Gpu.RenderTarget) //////////////////////////////////////////////////
{
uint32_t ElementSize;
// SURFACE_STATE...
ElementSize = (pTexInfo->BitsPerPixel >> 3) * (GmmIsYUVPacked(pTexInfo->Format) ? 2 : 1);
__GMM_ASSERT((pTexInfo->Pitch % ElementSize) == 0);
UPDATE_BASE_ALIGNMENT(ElementSize);
UPDATE_PADDING(pTexInfo->Pitch * 2); // "Surface Padding Requirements --> Render Target and Media Surfaces"
}
if(pTexInfo->Flags.Gpu.Texture) // (i.e. Sampler Surfaces) ///////////////////////////
{
UPDATE_BASE_ALIGNMENT(1); // Sampler supports byte alignment (with performance hit if misaligned).
if(pGmmGlobalContext->GetWaTable().WaNoMinimizedTrivialSurfacePadding)
{
if(pTexInfo->Type == RESOURCE_BUFFER)
{
if(pGmmGlobalContext->GetWaTable().WaNoBufferSamplerPadding)
{
// Client agreeing to take responsibility for flushing L3 after sampling/etc.
}
else
{
// GMM currently receives GENERIC_8BIT for
// RESOURCE_BUFFER creations, so we have to assume the
// worst-case sample size of 128-bit (unless we alter
// our interface meaning):
uint32_t ElementSize = 16;
// "Surface Padding Requirements --> Sampling Engine Surfaces"
UPDATE_PADDING(ElementSize * ((GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) == IGFX_GEN8_CORE) ? 512 : 256));
UPDATE_ADDITIONAL_BYTES(16);
}
}
else // RESOURCE_1D/2D...
{
/* Sampler needs Alignment Unit padding--
but sampler arch confirms that's overly conservative
padding--and for trivial (linear, single-subresource)
2D's, even-row (quad-row on BDW.A0) plus additional
64B padding is sufficient. (E.g. pitch overfetch will
be caught by subsequent rows or the additional 64B. */
__GMM_ASSERT((GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) <= IGFX_GEN8_CORE));
if(GmmIsCompressed(pTexInfo->Format))
{
// "For compressed textures...padding at the bottom of the surface is to an even compressed row."
UPDATE_PADDING(pTexInfo->Pitch * 2); // (Sampler arch confirmed that even-row is sufficient on BDW despite BDW's 4x4 sampling, since this req is from L2 instead of L1.)
}
else
{
UPDATE_PADDING(pTexInfo->Pitch * ((GFX_GET_CURRENT_RENDERCORE(pPlatform->Platform) == IGFX_GEN8_CORE) ? 4 : 2)); // Sampler Fetch Rows: BDW ? 4 : 2
}
// "For packed YUV, 96 bpt, 48 bpt, and 24 bpt surface formats, additional padding is required."
if(GmmIsYUVPacked(pTexInfo->Format) || (pTexInfo->BitsPerPixel == 96) || (pTexInfo->BitsPerPixel == 48) || (pTexInfo->BitsPerPixel == 24))
{
UPDATE_ADDITIONAL_BYTES(16);
UPDATE_ADDITIONAL_ROWS(1);
}
/* "For linear surfaces, additional padding of 64
bytes is required at the bottom of the surface."
(Sampler arch confirmed the 64 bytes can overlap with
the other "additional 16 bytes" mentions in that section.) */
UPDATE_ADDITIONAL_BYTES(64);
}
}
else
{
/* For SURFTYPE_BUFFER, SURFTYPE_1D, and
SURFTYPE_2D non-array, non-MSAA, non-mip-mapped surfaces in
linear memory, the only padding requirement is to the next
aligned 64-byte boundary beyond the end of the surface. */
UPDATE_END_ALIGNMENT(64);
}
}
}
else // Gpu.NoRestriction...
{
// Clients specify NoRestriction at their own risk--e.g. it can be
// appropriate when using IA-Coherent L3 combined with L3 being in
// unified/"Rest" mode (where there won't be write-->read-only
// collisions on unintentionally shared cachelines).
}
{ //Finally calculate surf size
GMM_GFX_SIZE_T OriginalEnd, RequiredSize;
ExistingSysMem.pVirtAddress =
(ExistingSysMem.pExistingSysMem & (PAGE_SIZE - 1)) ?
((uint64_t)GFX_ALIGN(ExistingSysMem.pExistingSysMem,
BaseAlignment)) :
ExistingSysMem.pExistingSysMem;
ExistingSysMem.pGfxAlignedVirtAddress =
(uint64_t)GFX_ALIGN(
(uint64_t)ExistingSysMem.pVirtAddress, PAGE_SIZE);
__GMM_ASSERT((ExistingSysMem.pVirtAddress % BaseAlignment) == 0);
RequiredSize = pTexInfo->Pitch * Height;
RequiredSize =
GFX_ALIGN(RequiredSize, SizePadding) +
(AdditionalPaddingRows * pTexInfo->Pitch) +
AdditionalPaddingBytes;
OriginalEnd = ExistingSysMem.pVirtAddress + RequiredSize;
RequiredSize += GFX_ALIGN(OriginalEnd, EndAlignment) - OriginalEnd;
//Ensure sufficient ExistingSysMem available.
if(ExistingSysMem.Size < RequiredSize)
{
return GMM_ERROR;
}
Surf.Size = RequiredSize;
}
GMM_DPF_EXIT;
return GMM_SUCCESS;
}
|