Skip to content

Commit 73fbd50

Browse files
authored
Planar Surface Redescription and pitch adjustment. (#31)
1 parent 58c09f1 commit 73fbd50

File tree

8 files changed

+286
-71
lines changed

8 files changed

+286
-71
lines changed

Source/GmmLib/Resource/GmmResourceInfoCommon.cpp

+29-10
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,12 @@ uint32_t GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetQPitch()
12311231
/////////////////////////////////////////////////////////////////////////////////////
12321232
GMM_STATUS GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetOffset(GMM_REQ_OFFSET_INFO &ReqInfo)
12331233
{
1234+
GMM_TEXTURE_CALC *pTextureCalc;
1235+
1236+
pTextureCalc = GMM_OVERRIDE_TEXTURE_CALC(&Surf);
1237+
1238+
__GMM_ASSERT((pTextureCalc != NULL))
1239+
12341240
if(Surf.Flags.Info.RedecribedPlanes)
12351241
{
12361242
uint8_t RestoreReqStdLayout = ReqInfo.ReqStdLayout ? 1 : 0;
@@ -1246,6 +1252,7 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetOffset(GMM_REQ_OFFSET_I
12461252
if(ReqInfo.ReqStdLayout)
12471253
{
12481254
GMM_REQ_OFFSET_INFO TempReqInfo[GMM_MAX_PLANE] = {0};
1255+
GMM_TEXTURE_INFO TexInfo[GMM_MAX_PLANE];
12491256
uint32_t Plane, TotalPlanes = GmmLib::Utility::GmmGetNumPlanes(Surf.Format);
12501257

12511258
// Caller must specify which plane they need the offset into if not
@@ -1262,11 +1269,15 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetOffset(GMM_REQ_OFFSET_I
12621269
TempReqInfo[GMM_PLANE_Y].ReqLock = TempReqInfo[GMM_PLANE_Y].ReqRender = 0;
12631270

12641271
TempReqInfo[GMM_PLANE_V] = TempReqInfo[GMM_PLANE_U] = TempReqInfo[GMM_PLANE_Y];
1265-
1266-
if(GMM_SUCCESS != GmmTexGetMipMapOffset(&PlaneSurf[GMM_PLANE_Y], &TempReqInfo[GMM_PLANE_Y]) ||
1267-
GMM_SUCCESS != GmmTexGetMipMapOffset(&PlaneSurf[GMM_PLANE_U], &TempReqInfo[GMM_PLANE_U]) ||
1268-
GMM_SUCCESS != GmmTexGetMipMapOffset(&PlaneSurf[GMM_PLANE_V], &TempReqInfo[GMM_PLANE_V]))
1269-
{
1272+
1273+
pTextureCalc->GetRedescribedPlaneParams(&Surf, GMM_PLANE_Y, &TexInfo[GMM_PLANE_Y]);
1274+
pTextureCalc->GetRedescribedPlaneParams(&Surf, GMM_PLANE_U, &TexInfo[GMM_PLANE_U]);
1275+
pTextureCalc->GetRedescribedPlaneParams(&Surf, GMM_PLANE_V, &TexInfo[GMM_PLANE_V]);
1276+
1277+
if(GMM_SUCCESS != GmmTexGetMipMapOffset(&TexInfo[GMM_PLANE_Y], &TempReqInfo[GMM_PLANE_Y]) ||
1278+
GMM_SUCCESS != GmmTexGetMipMapOffset(&TexInfo[GMM_PLANE_U], &TempReqInfo[GMM_PLANE_U]) ||
1279+
GMM_SUCCESS != GmmTexGetMipMapOffset(&TexInfo[GMM_PLANE_V], &TempReqInfo[GMM_PLANE_V]))
1280+
{
12701281
__GMM_ASSERT(0);
12711282
return GMM_ERROR;
12721283
}
@@ -1295,9 +1306,10 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetOffset(GMM_REQ_OFFSET_I
12951306
{
12961307
// Find the size of the previous planes and add it to the offset
12971308
TempReqInfo[Plane].StdLayout.Offset = -1;
1298-
1299-
if(GMM_SUCCESS != GmmTexGetMipMapOffset(&PlaneSurf[Plane], &TempReqInfo[Plane]))
1309+
1310+
if(GMM_SUCCESS != GmmTexGetMipMapOffset(&TexInfo[Plane], &TempReqInfo[Plane]))
13001311
{
1312+
13011313
__GMM_ASSERT(0);
13021314
return GMM_ERROR;
13031315
}
@@ -1336,6 +1348,7 @@ uint8_t GMM_STDCALL GmmLib::GmmResourceInfoCommon::CpuBlt(GMM_RES_COPY_BLT *pBlt
13361348
uint8_t Success = 1;
13371349
GMM_TEXTURE_INFO * pTexInfo;
13381350
GMM_TEXTURE_CALC * pTextureCalc;
1351+
GMM_TEXTURE_INFO RedescribedPlaneInfo;
13391352

13401353
__GMM_ASSERTPTR(pBlt, 0);
13411354

@@ -1468,13 +1481,15 @@ uint8_t GMM_STDCALL GmmLib::GmmResourceInfoCommon::CpuBlt(GMM_RES_COPY_BLT *pBlt
14681481

14691482
if(pBlt->Gpu.OffsetY < pTexInfo->OffsetInfo.Plane.Y[GMM_PLANE_U])
14701483
{
1484+
pTextureCalc->GetRedescribedPlaneParams(pTexInfo, GMM_PLANE_Y, &RedescribedPlaneInfo);
14711485
// Y Plane
1472-
pTexInfo = &(PlaneSurf[GMM_PLANE_Y]);
1486+
pTexInfo = &RedescribedPlaneInfo;
14731487
}
14741488
else
14751489
{
14761490
// UV Plane
1477-
pTexInfo = &(PlaneSurf[GMM_PLANE_U]);
1491+
pTextureCalc->GetRedescribedPlaneParams(pTexInfo, GMM_PLANE_U, &RedescribedPlaneInfo);
1492+
pTexInfo = &RedescribedPlaneInfo;
14781493
}
14791494
}
14801495

@@ -1869,12 +1884,14 @@ uint8_t GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetMappingSpanDesc(GMM_GET_MA
18691884
uint8_t WasFinalSpan = 0;
18701885
GMM_TEXTURE_INFO * pTexInfo;
18711886
GMM_TEXTURE_CALC * pTextureCalc;
1887+
GMM_TEXTURE_INFO RedescribedPlaneInfo;
18721888

18731889
__GMM_ASSERT(Surf.Flags.Info.StdSwizzle);
18741890

18751891
pPlatform = GMM_OVERRIDE_PLATFORM_INFO(&Surf);
18761892
pTextureCalc = GMM_OVERRIDE_TEXTURE_CALC(&Surf);
18771893

1894+
__GMM_ASSERT(pTextureCalc != NULL);
18781895
pTexInfo = &Surf;
18791896

18801897
if(pMapping->Type == GMM_MAPPING_GEN9_YS_TO_STDSWIZZLE)
@@ -1933,7 +1950,9 @@ uint8_t GMM_STDCALL GmmLib::GmmResourceInfoCommon::GetMappingSpanDesc(GMM_GET_MA
19331950
pMapping->__NextSpan.VirtualOffset = ReqInfo.Render.Offset64;
19341951
}
19351952

1936-
pTexInfo = &PlaneSurf[pMapping->Scratch.Plane];
1953+
pTextureCalc->GetRedescribedPlaneParams(pTexInfo, GMM_PLANE_Y, &RedescribedPlaneInfo);
1954+
pTexInfo = &RedescribedPlaneInfo;
1955+
19371956
}
19381957

19391958
// Initialization of Mapping Params...

Source/GmmLib/Texture/GmmGen10Texture.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,14 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmGen10TextureCalc::FillTexPlanar(GMM_TEXTURE_IN
898898
pTexInfo->Flags.Gpu.MMC = 0;
899899
}
900900
}
901+
902+
if(pTexInfo->Flags.Info.RedecribedPlanes)
903+
{
904+
if(false == RedescribeTexturePlanes(pTexInfo, &WidthBytesPhysical))
905+
{
906+
__GMM_ASSERT(FALSE);
907+
}
908+
}
901909

902910
if((Status = // <-- Note assignment.
903911
FillTexPitchAndSize(

Source/GmmLib/Texture/GmmGen11Texture.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,14 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmGen11TextureCalc::FillTexPlanar(GMM_TEXTURE_IN
10861086
}
10871087
}
10881088

1089+
if(pTexInfo->Flags.Info.RedecribedPlanes)
1090+
{
1091+
if(false == RedescribeTexturePlanes(pTexInfo, &WidthBytesPhysical))
1092+
{
1093+
__GMM_ASSERT(FALSE);
1094+
}
1095+
}
1096+
10891097
if((Status = // <-- Note assignment.
10901098
FillTexPitchAndSize(
10911099
pTexInfo, WidthBytesPhysical, Height, pRestrictions)) == GMM_SUCCESS)

Source/GmmLib/Texture/GmmGen12Texture.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,15 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmGen12TextureCalc::FillTexPlanar(GMM_TEXTURE_IN
923923

924924
Height = YHeight + VHeight;
925925
}
926-
926+
927+
if(pTexInfo->Flags.Info.RedecribedPlanes)
928+
{
929+
if(false == RedescribeTexturePlanes(pTexInfo, &WidthBytesPhysical))
930+
{
931+
__GMM_ASSERT(FALSE);
932+
}
933+
}
934+
927935
if((Status = // <-- Note assignment.
928936
FillTexPitchAndSize(
929937
pTexInfo, WidthBytesPhysical, Height, pRestrictions)) == GMM_SUCCESS)

Source/GmmLib/Texture/GmmTexture.cpp

+197
Original file line numberDiff line numberDiff line change
@@ -629,3 +629,200 @@ bool GmmLib::GmmTextureCalc::GmmGetD3DToHwTileConversion(GMM_TEXTURE_INFO *pTexI
629629
*pRowFactor = 0;
630630
return false;
631631
}
632+
633+
/////////////////////////////////////////////////////////////////////////////////////
634+
/// This function redescribes WidthBytesPhysical of main surface as per UV plane bpp and tilemode
635+
///
636+
/// @return ::bool
637+
/////////////////////////////////////////////////////////////////////////////////////
638+
bool GmmLib::GmmTextureCalc::RedescribeTexturePlanes(GMM_TEXTURE_INFO *pTexInfo, uint32_t *pWidthBytesPhysical)
639+
{
640+
GMM_STATUS Status = GMM_SUCCESS;
641+
GMM_TEXTURE_INFO TexInfoUVPlane;
642+
const GMM_PLATFORM_INFO *pPlatform = GMM_OVERRIDE_PLATFORM_INFO(pTexInfo);
643+
644+
__GMM_ASSERT(pTexInfo);
645+
__GMM_ASSERT(pTexInfo->Flags.Info.RedecribedPlanes);
646+
__GMM_ASSERT(pWidthBytesPhysical);
647+
648+
TexInfoUVPlane = *pTexInfo;
649+
#ifdef _WIN32
650+
memcpy_s(&TexInfoUVPlane, sizeof(GMM_TEXTURE_INFO), pTexInfo, sizeof(GMM_TEXTURE_INFO));
651+
#else
652+
memcpy(&TexInfoUVPlane, pTexInfo, sizeof(GMM_TEXTURE_INFO));
653+
#endif // _WIN32
654+
655+
656+
if(GmmIsUVPacked(pTexInfo->Format))
657+
{
658+
// UV packed resources must have two seperate
659+
// tiling modes per plane, due to the packed
660+
// UV plane having twice the bits per pixel
661+
// as the Y plane.
662+
switch(pTexInfo->Format)
663+
{
664+
case GMM_FORMAT_NV12:
665+
case GMM_FORMAT_NV21:
666+
case GMM_FORMAT_P208:
667+
TexInfoUVPlane.BitsPerPixel = 16; // Redescribe bpp to 16 from 8
668+
break;
669+
case GMM_FORMAT_P010:
670+
case GMM_FORMAT_P012:
671+
case GMM_FORMAT_P016:
672+
case GMM_FORMAT_P216:
673+
TexInfoUVPlane.BitsPerPixel = 32;
674+
break;
675+
default:
676+
GMM_ASSERTDPF(0, "Unsupported format/pixel size combo!");
677+
Status = GMM_INVALIDPARAM;
678+
goto ERROR_CASE;
679+
break;
680+
}
681+
}
682+
else
683+
{
684+
// Non-UV packed surfaces, TileMode and bpp of each plane is same as that of pTexInfo
685+
}
686+
687+
SetTileMode(&TexInfoUVPlane);
688+
*pWidthBytesPhysical = GFX_ALIGN(*pWidthBytesPhysical, pPlatform->TileInfo[TexInfoUVPlane.TileMode].LogicalTileWidth);
689+
690+
ERROR_CASE:
691+
return (Status == GMM_SUCCESS) ? true : false;
692+
}
693+
694+
/////////////////////////////////////////////////////////////////////////////////////
695+
/// This function returns per plane redescribed parameters (pRedescribedTexInfo: fmt, tilemode,bpp, width, height, size) when main surface pTexInfo is passed
696+
///
697+
/// @return ::bool
698+
/////////////////////////////////////////////////////////////////////////////////////
699+
bool GmmLib::GmmTextureCalc::GetRedescribedPlaneParams(GMM_TEXTURE_INFO *pTexInfo, GMM_YUV_PLANE PlaneType, GMM_TEXTURE_INFO *pRedescribedTexInfo)
700+
{
701+
GMM_STATUS Status = GMM_SUCCESS;
702+
GMM_TEXTURE_INFO TexInfoUVPlane;
703+
const GMM_PLATFORM_INFO *pPlatform = GMM_OVERRIDE_PLATFORM_INFO(pTexInfo);
704+
705+
__GMM_ASSERT(pTexInfo);
706+
__GMM_ASSERT(pTexInfo->Flags.Info.RedecribedPlanes);
707+
__GMM_ASSERT(pRedescribedTexInfo);
708+
709+
*pRedescribedTexInfo = *pTexInfo;
710+
pRedescribedTexInfo->Flags.Info.RedecribedPlanes = 0;
711+
#ifdef _WIN32
712+
memcpy_s(&TexInfoUVPlane, sizeof(GMM_TEXTURE_INFO), pTexInfo, sizeof(GMM_TEXTURE_INFO));
713+
#else
714+
memcpy(&TexInfoUVPlane, pTexInfo, sizeof(GMM_TEXTURE_INFO));
715+
#endif // _WIN32
716+
717+
if(GmmIsUVPacked(pTexInfo->Format))
718+
{
719+
// UV packed resources must have two seperate
720+
// tiling modes per plane, due to the packed
721+
// UV plane having twice the bits per pixel
722+
// as the Y plane.
723+
if((PlaneType == GMM_PLANE_U) || (PlaneType == GMM_PLANE_V))
724+
{
725+
switch(pTexInfo->Format)
726+
{
727+
// GMM_FORMAT_NV11 : linear format, no tiling supported, hence no redescription supported
728+
case GMM_FORMAT_NV12:
729+
case GMM_FORMAT_NV21:
730+
pRedescribedTexInfo->BitsPerPixel = 16;
731+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 2);
732+
pRedescribedTexInfo->BaseHeight = GFX_CEIL_DIV(pTexInfo->BaseHeight, 2);
733+
break;
734+
case GMM_FORMAT_P208:
735+
pRedescribedTexInfo->BitsPerPixel = 16;
736+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 2);
737+
// same base height as main surface
738+
break;
739+
case GMM_FORMAT_P010:
740+
case GMM_FORMAT_P012:
741+
case GMM_FORMAT_P016:
742+
pRedescribedTexInfo->BitsPerPixel = 32;
743+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 2);
744+
pRedescribedTexInfo->BaseHeight = GFX_CEIL_DIV(pTexInfo->BaseHeight, 2);
745+
break;
746+
case GMM_FORMAT_P216:
747+
pRedescribedTexInfo->BitsPerPixel = 32;
748+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 2);
749+
// same base height as main surface
750+
break;
751+
default:
752+
GMM_ASSERTDPF(0, "Unsupported format/pixel size combo!");
753+
Status = GMM_INVALIDPARAM;
754+
goto ERROR_CASE;
755+
break;
756+
}
757+
}
758+
}
759+
else
760+
{
761+
// Non-UV packed surfaces TileMode of each plane is same as that of pTexInfo
762+
if((PlaneType == GMM_PLANE_U) || (PlaneType == GMM_PLANE_V))
763+
{ // Non-UV packed surfaces only require the plane descriptors have proper height and width for each plane
764+
switch(pTexInfo->Format)
765+
{
766+
case GMM_FORMAT_IMC1:
767+
case GMM_FORMAT_IMC2:
768+
case GMM_FORMAT_IMC3:
769+
case GMM_FORMAT_IMC4:
770+
case GMM_FORMAT_MFX_JPEG_YUV420:
771+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 2);
772+
pRedescribedTexInfo->BaseHeight = GFX_CEIL_DIV(pTexInfo->BaseHeight, 2);
773+
break;
774+
case GMM_FORMAT_MFX_JPEG_YUV422V:
775+
pRedescribedTexInfo->BaseHeight = GFX_CEIL_DIV(pTexInfo->BaseHeight, 2);
776+
break;
777+
case GMM_FORMAT_MFX_JPEG_YUV411R_TYPE:
778+
pRedescribedTexInfo->BaseHeight = GFX_CEIL_DIV(pTexInfo->BaseHeight, 4);
779+
break;
780+
case GMM_FORMAT_MFX_JPEG_YUV411:
781+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 4);
782+
break;
783+
case GMM_FORMAT_MFX_JPEG_YUV422H:
784+
pRedescribedTexInfo->BaseWidth = GFX_CEIL_DIV(pTexInfo->BaseWidth, 2);
785+
break;
786+
default:
787+
GMM_ASSERTDPF(0, "Unsupported format/pixel size combo!");
788+
Status = GMM_INVALIDPARAM;
789+
goto ERROR_CASE;
790+
break;
791+
}
792+
}
793+
}
794+
795+
SetTileMode(pRedescribedTexInfo);
796+
switch(pRedescribedTexInfo->BitsPerPixel)
797+
{
798+
case 8:
799+
pRedescribedTexInfo->Format = GMM_FORMAT_R8_UINT;
800+
break;
801+
case 16:
802+
pRedescribedTexInfo->Format = GMM_FORMAT_R16_UINT;
803+
break;
804+
case 32:
805+
pRedescribedTexInfo->Format = GMM_FORMAT_R32_UINT;
806+
break;
807+
default:
808+
GMM_ASSERTDPF(0, "Unsupported format/pixel size combo!");
809+
Status = GMM_INVALIDPARAM;
810+
goto ERROR_CASE;
811+
break;
812+
}
813+
if(pTexInfo->ArraySize > 1)
814+
{
815+
pRedescribedTexInfo->OffsetInfo.Plane.ArrayQPitch = 0; // no longer a planar format on redescription
816+
pRedescribedTexInfo->Alignment.QPitch = GFX_ALIGN(pRedescribedTexInfo->BaseHeight, pTexInfo->Alignment.VAlign);
817+
pRedescribedTexInfo->OffsetInfo.Texture2DOffsetInfo.ArrayQPitchRender =
818+
pRedescribedTexInfo->OffsetInfo.Texture2DOffsetInfo.ArrayQPitchLock = pRedescribedTexInfo->Alignment.QPitch * pTexInfo->Pitch;
819+
pRedescribedTexInfo->Size = pRedescribedTexInfo->Alignment.QPitch * pTexInfo->Pitch * pTexInfo->ArraySize;
820+
}
821+
else
822+
{
823+
pRedescribedTexInfo->Size = (GFX_ALIGN(pRedescribedTexInfo->BaseHeight, pTexInfo->Alignment.VAlign)) * pTexInfo->Pitch;
824+
}
825+
826+
ERROR_CASE:
827+
return (Status == GMM_SUCCESS) ? true : false;
828+
}

Source/GmmLib/Texture/GmmTextureAlloc.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,14 @@ GMM_STATUS GMM_STDCALL GmmLib::GmmTextureCalc::FillTexPlanar(GMM_TEXTURE_INFO *
13661366
}
13671367
}
13681368

1369+
if(pTexInfo->Flags.Info.RedecribedPlanes)
1370+
{
1371+
if(false == RedescribeTexturePlanes(pTexInfo, &WidthBytesPhysical))
1372+
{
1373+
__GMM_ASSERT(FALSE);
1374+
}
1375+
}
1376+
13691377
if((Status = // <-- Note assignment.
13701378
FillTexPitchAndSize(
13711379
pTexInfo, WidthBytesPhysical, Height, pRestrictions)) == GMM_SUCCESS)

0 commit comments

Comments
 (0)