1
0
mirror of synced 2024-12-11 23:36:01 +01:00

Merge pull request #46 from aboood40091/master

Fix GTX version and some fixes in GX2 swizzling
This commit is contained in:
KillzXGaming 2019-04-09 16:59:02 -04:00 committed by GitHub
commit a11e7dedc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 131 deletions

View File

@ -104,13 +104,13 @@ namespace FirstPlugin
uint dataBlockType; uint dataBlockType;
uint mipBlockType; uint mipBlockType;
if (header.MajorVersion == 6) if (header.MajorVersion == 6 && header.MinorVersion == 0)
{ {
surfBlockType = 0x0A; surfBlockType = 0x0A;
dataBlockType = 0x0B; dataBlockType = 0x0B;
mipBlockType = 0x0C; mipBlockType = 0x0C;
} }
else if (header.MajorVersion == 7) else if (header.MajorVersion == 6 || header.MajorVersion == 7)
{ {
surfBlockType = 0x0B; surfBlockType = 0x0B;
dataBlockType = 0x0C; dataBlockType = 0x0C;
@ -152,13 +152,13 @@ namespace FirstPlugin
uint dataBlockType; uint dataBlockType;
uint mipBlockType; uint mipBlockType;
if (header.MajorVersion == 6) if (header.MajorVersion == 6 && header.MinorVersion == 0)
{ {
surfBlockType = 0x0A; surfBlockType = 0x0A;
dataBlockType = 0x0B; dataBlockType = 0x0B;
mipBlockType = 0x0C; mipBlockType = 0x0C;
} }
else if (header.MajorVersion == 7) else if (header.MajorVersion == 6 || header.MajorVersion == 7)
{ {
surfBlockType = 0x0B; surfBlockType = 0x0B;
dataBlockType = 0x0C; dataBlockType = 0x0C;
@ -193,6 +193,9 @@ namespace FirstPlugin
var surface = new SurfaceInfoParse(); var surface = new SurfaceInfoParse();
surface.Read(new FileReader(block.data)); surface.Read(new FileReader(block.data));
if (surface.tileMode == 0 || surface.tileMode > 16)
throw new Exception($"Invalid tileMode {surface.tileMode}!");
if (surface.numMips > 14) if (surface.numMips > 14)
throw new Exception($"Invalid number of mip maps {surface.numMips}!"); throw new Exception($"Invalid number of mip maps {surface.numMips}!");
@ -262,7 +265,7 @@ namespace FirstPlugin
HeaderSize = reader.ReadUInt32(); HeaderSize = reader.ReadUInt32();
MajorVersion = reader.ReadUInt32(); MajorVersion = reader.ReadUInt32();
MinorVersion = reader.ReadUInt32(); MinorVersion = reader.ReadUInt32();
GpuVersion = reader.ReadUInt32(); GpuVersion = reader.ReadUInt32(); //Ignored in 6.0
AlignMode = reader.ReadUInt32(); AlignMode = reader.ReadUInt32();
} }
public void Write(FileWriter writer) public void Write(FileWriter writer)
@ -296,8 +299,8 @@ namespace FirstPlugin
throw new Exception($"Invalid signature {Signature}! Expected BLK."); throw new Exception($"Invalid signature {Signature}! Expected BLK.");
HeaderSize = reader.ReadUInt32(); HeaderSize = reader.ReadUInt32();
MajorVersion = reader.ReadUInt32(); //Must be 0x01 for 6.x.x MajorVersion = reader.ReadUInt32(); //Must be 0x01 for 6.x
MinorVersion = reader.ReadUInt32(); //Must be 0x00 for 6.x.x MinorVersion = reader.ReadUInt32(); //Must be 0x00 for 6.x
BlockType = reader.ReadEnum<BlockType>(false); BlockType = reader.ReadEnum<BlockType>(false);
DataSize = reader.ReadUInt32(); DataSize = reader.ReadUInt32();
Identifier = reader.ReadUInt32(); Identifier = reader.ReadUInt32();

View File

@ -47,8 +47,6 @@ namespace Switch_Toolbox.Library
public uint[] texRegs; public uint[] texRegs;
}; };
public static int m_configFlags = 4;
public static uint expPitch = 0; public static uint expPitch = 0;
public static uint expHeight = 0; public static uint expHeight = 0;
public static uint expNumSlices = 0; public static uint expNumSlices = 0;
@ -717,11 +715,6 @@ namespace Switch_Toolbox.Library
return (n + d - 1) / d; return (n + d - 1) / d;
} }
private static uint powTwoAlign_0(uint x, uint align)
{
return (x + align - 1) & ~(align - 1);
}
/*--------------------------------------- /*---------------------------------------
* *
@ -753,15 +746,15 @@ namespace Switch_Toolbox.Library
public static byte[] deswizzle(uint width, uint height, uint depth, uint height_, uint format_, uint tileMode, uint swizzle_, public static byte[] deswizzle(uint width, uint height, uint depth, uint height_, uint format_, uint tileMode, uint swizzle_,
uint pitch, uint bpp, byte[] data, int depthLevel) uint pitch, uint bpp, byte[] data, int depthLevel)
{ {
return swizzleSurf(width, height, depth, height_, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 0); return swizzleSurf(width, height, depth, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 0);
} }
public static byte[] swizzle(uint width, uint height, uint depth, uint height_, uint format_, uint tileMode, uint swizzle_, public static byte[] swizzle(uint width, uint height, uint depth, uint height_, uint format_, uint tileMode, uint swizzle_,
uint pitch, uint bpp, byte[] data, int depthLevel) uint pitch, uint bpp, byte[] data, int depthLevel)
{ {
return swizzleSurf(width, height, depth, height_, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 1); return swizzleSurf(width, height, depth, format_, tileMode, swizzle_, pitch, bpp, data, depthLevel, 1);
} }
private static byte[] swizzleSurf(uint width, uint height,uint depth, uint height_, uint format, uint tileMode, uint swizzle_, private static byte[] swizzleSurf(uint width, uint height,uint depth, uint format, uint tileMode, uint swizzle_,
uint pitch, uint bitsPerPixel, byte[] data, int depthLevel, int swizzle) uint pitch, uint bitsPerPixel, byte[] data, int depthLevel, int swizzle)
{ {
uint bytesPerPixel = bitsPerPixel / 8; uint bytesPerPixel = bitsPerPixel / 8;
@ -798,7 +791,7 @@ namespace Switch_Toolbox.Library
} }
else else
{ {
pos = computeSurfaceAddrFromCoordMacroTiled((uint)x, (uint)y, bitsPerPixel, pitch, height_, (AddrTileMode)tileMode, pipeSwizzle, bankSwizzle); pos = computeSurfaceAddrFromCoordMacroTiled((uint)x, (uint)y, bitsPerPixel, pitch, height, (AddrTileMode)tileMode, pipeSwizzle, bankSwizzle);
} }
@ -1026,7 +1019,7 @@ namespace Switch_Toolbox.Library
} }
} }
private static uint computeSurfaceBankSwappedWidth(AddrTileMode tileMode, uint bpp, uint pitch, uint numSamples) private static uint computeSurfaceBankSwappedWidth(AddrTileMode tileMode, uint bpp, uint numSamples, uint pitch)
{ {
if (isBankSwappedTileMode(tileMode) == 0) if (isBankSwappedTileMode(tileMode) == 0)
return 0; return 0;
@ -1161,24 +1154,15 @@ namespace Switch_Toolbox.Library
uint macroTileIndexY = y / macroTileHeight; uint macroTileIndexY = y / macroTileHeight;
ulong macroTileOffset = (macroTileIndexX + macroTilesPerRow * macroTileIndexY) * macroTileBytes; ulong macroTileOffset = (macroTileIndexX + macroTilesPerRow * macroTileIndexY) * macroTileBytes;
switch (tileMode) if (isBankSwappedTileMode(tileMode))
{ {
case AddrTileMode.ADDR_TM_2B_TILED_THIN1: bankSwapWidth = computeSurfaceBankSwappedWidth(tileMode, bpp, 1, pitch);
case AddrTileMode.ADDR_TM_2B_TILED_THIN2:
case AddrTileMode.ADDR_TM_2B_TILED_THIN4:
case AddrTileMode.ADDR_TM_2B_TILED_THICK:
case AddrTileMode.ADDR_TM_3B_TILED_THIN1:
case AddrTileMode.ADDR_TM_3B_TILED_THICK:
{
bankSwapWidth = computeSurfaceBankSwappedWidth(tileMode, bpp, pitch, 1);
swapIndex = macroTilePitch * macroTileIndexX / bankSwapWidth; swapIndex = macroTilePitch * macroTileIndexX / bankSwapWidth;
bank ^= bankSwapOrder[swapIndex & 3]; bank ^= bankSwapOrder[swapIndex & 3];
break;
}
} }
ulong totalOffset = elemOffset + ((macroTileOffset + sliceOffset) >> 3); ulong totalOffset = elemOffset + ((macroTileOffset + sliceOffset) >> 3);
return bank << 9 | pipe << 8 | 255 & totalOffset | (ulong)((int)totalOffset & -256) << 3; return bank << 9 | pipe << 8 | totalOffset & 255 | (ulong)((int)totalOffset & -256) << 3;
} }
public static uint computeSurfaceMipLevelTileMode(uint baseTileMode, uint bpp, uint level, uint width, uint height, public static uint computeSurfaceMipLevelTileMode(uint baseTileMode, uint bpp, uint level, uint width, uint height,
@ -1226,8 +1210,9 @@ namespace Switch_Toolbox.Library
if (DebugSurface) if (DebugSurface)
Console.WriteLine("computeSurfaceMipLevelTileMode expTileMode " + expTileMode); Console.WriteLine("computeSurfaceMipLevelTileMode expTileMode " + expTileMode);
if (noRecursive == 0) if (noRecursive || level == 0)
{ return expTileMode;
switch (bpp) switch (bpp)
{ {
case 24: case 24:
@ -1241,8 +1226,6 @@ namespace Switch_Toolbox.Library
heighta = nextPow2(height); heighta = nextPow2(height);
numSlicesa = nextPow2(numSlices); numSlicesa = nextPow2(numSlices);
if (level != 0)
{
expTileMode = convertToNonBankSwappedMode((AddrTileMode)expTileMode); expTileMode = convertToNonBankSwappedMode((AddrTileMode)expTileMode);
thickness = computeSurfaceThickness((AddrTileMode)expTileMode); thickness = computeSurfaceThickness((AddrTileMode)expTileMode);
microTileBytes = (numSamples * bpp * (thickness << 6) + 7) >> 3; microTileBytes = (numSamples * bpp * (thickness << 6) + 7) >> 3;
@ -1299,10 +1282,7 @@ namespace Switch_Toolbox.Library
isDepth, isDepth,
1); 1);
} }
}
return expTileMode;
}
private static uint computeSurfaceTileSlices(uint tileMode, uint bpp, uint numSamples) private static uint computeSurfaceTileSlices(uint tileMode, uint bpp, uint numSamples)
{ {
uint bytePerSample = ((bpp << 6) + 7) >> 3; uint bytePerSample = ((bpp << 6) + 7) >> 3;
@ -1322,11 +1302,6 @@ namespace Switch_Toolbox.Library
return tileSlices; return tileSlices;
} }
private static int getFillSizeFieldsFlags()
{
return (m_configFlags >> 6) & 1;
}
private static uint ComputeSurfaceInfoEx() private static uint ComputeSurfaceInfoEx()
{ {
uint tileMode = pIn.tileMode; uint tileMode = pIn.tileMode;
@ -1576,7 +1551,6 @@ namespace Switch_Toolbox.Library
tileMode, tileMode,
padDims, padDims,
(flags.value >> 4) & 1, (flags.value >> 4) & 1,
(flags.value >> 7) & 1,
pitchAlign, pitchAlign,
heightAlign, heightAlign,
microTileThickness); microTileThickness);
@ -1815,7 +1789,6 @@ namespace Switch_Toolbox.Library
expTileMode, expTileMode,
padDims, padDims,
(flags.value >> 4) & 1, (flags.value >> 4) & 1,
(flags.value >> 7) & 1,
pitchAlign, pitchAlign,
heightAlign, heightAlign,
microTileThickness); microTileThickness);
@ -1843,14 +1816,7 @@ namespace Switch_Toolbox.Library
return new uint[] { valid, pPitchOut, pHeightOut, pNumSlicesOut, pSurfSize, pTileModeOut, pBaseAlign, pPitchAlign, pHeightAlign, pDepthAlign }; return new uint[] { valid, pPitchOut, pHeightOut, pNumSlicesOut, pSurfSize, pTileModeOut, pBaseAlign, pPitchAlign, pHeightAlign, pDepthAlign };
} }
private static uint IsPow2(uint dim) private static Tuple<uint, uint, uint> padDimensions(uint tileMode, uint padDims, uint isCube, uint pitchAlign, uint heightAlign, uint sliceAlign)
{
if ((dim & (dim - 1)) == 0)
return 1;
else
return 0;
}
private static Tuple<uint, uint, uint> padDimensions(uint tileMode, uint padDims, uint isCube, uint cubeAsArray, uint pitchAlign, uint heightAlign, uint sliceAlign)
{ {
uint thickness = computeSurfaceThickness((AddrTileMode)tileMode); uint thickness = computeSurfaceThickness((AddrTileMode)tileMode);
if (padDims == 0) if (padDims == 0)
@ -1860,7 +1826,7 @@ namespace Switch_Toolbox.Library
expPitch = powTwoAlign(expPitch, pitchAlign); expPitch = powTwoAlign(expPitch, pitchAlign);
else else
{ {
expPitch = pitchAlign + expPitch - 1; expPitch += pitchAlign - 1;
expPitch /= pitchAlign; expPitch /= pitchAlign;
expPitch *= pitchAlign; expPitch *= pitchAlign;
} }
@ -1870,7 +1836,7 @@ namespace Switch_Toolbox.Library
if (padDims > 2 || thickness > 1) if (padDims > 2 || thickness > 1)
{ {
if (isCube != 0 || cubeAsArray != 0) if (isCube != 0)
expNumSlices = nextPow2(expNumSlices); expNumSlices = nextPow2(expNumSlices);
if (thickness > 1) if (thickness > 1)
@ -1935,7 +1901,7 @@ namespace Switch_Toolbox.Library
macroWidth = tup.Item4; macroWidth = tup.Item4;
macroHeight = tup.Item5; macroHeight = tup.Item5;
bankSwappedWidth = computeSurfaceBankSwappedWidth((AddrTileMode)tileMode, bpp, pitch, numSamples); bankSwappedWidth = computeSurfaceBankSwappedWidth((AddrTileMode)tileMode, bpp, numSamples, pitch);
if (bankSwappedWidth > pitchAlign) if (bankSwappedWidth > pitchAlign)
pitchAlign = bankSwappedWidth; pitchAlign = bankSwappedWidth;
@ -2022,7 +1988,7 @@ namespace Switch_Toolbox.Library
macroWidth = tup.Item4; macroWidth = tup.Item4;
macroHeight = tup.Item5; macroHeight = tup.Item5;
bankSwappedWidth = computeSurfaceBankSwappedWidth((AddrTileMode)tileMode, bpp, pitch, numSamples); bankSwappedWidth = computeSurfaceBankSwappedWidth((AddrTileMode)tileMode, bpp, numSamples, pitch);
if (bankSwappedWidth > pitchAlign) if (bankSwappedWidth > pitchAlign)
pitchAlign = bankSwappedWidth; pitchAlign = bankSwappedWidth;
@ -2118,7 +2084,7 @@ namespace Switch_Toolbox.Library
private static uint adjustPitchAlignment(Flags flags, uint pitchAlign) private static uint adjustPitchAlignment(Flags flags, uint pitchAlign)
{ {
if (((flags.value >> 13) & 1) != 0) if (((flags.value >> 13) & 1) != 0)
pitchAlign = powTwoAlign_0(pitchAlign, 0x20); pitchAlign = powTwoAlign(pitchAlign, 0x20);
return pitchAlign; return pitchAlign;
} }
@ -2199,10 +2165,6 @@ namespace Switch_Toolbox.Library
return 0; return 0;
} }
private static uint useTileIndex(int index)
{
return 0;
}
private static void computeMipLevel() private static void computeMipLevel()
{ {
uint slices = 0; uint slices = 0;
@ -2519,6 +2481,9 @@ namespace Switch_Toolbox.Library
pSurfOut = pOut; pSurfOut = pOut;
} }
if (pSurfOut.tileMode == 0)
pSurfOut.tileMode = 16;
return pSurfOut; return pSurfOut;
} }
} }