NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 18:53:23 +00:00
|
|
|
using ChocolArm64.Memory;
|
2018-06-09 00:15:56 +00:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-06-24 00:39:25 +00:00
|
|
|
using Ryujinx.HLE.Gpu.Memory;
|
2018-04-26 02:11:26 +00:00
|
|
|
using System;
|
|
|
|
|
2018-06-24 00:39:25 +00:00
|
|
|
namespace Ryujinx.HLE.Gpu.Texture
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
|
|
|
static class TextureHelper
|
|
|
|
{
|
2018-07-19 05:30:21 +00:00
|
|
|
public static ISwizzle GetSwizzle(TextureInfo Texture, int BlockWidth, int Bpp)
|
2018-04-26 02:11:26 +00:00
|
|
|
{
|
2018-07-19 05:30:21 +00:00
|
|
|
int Width = (Texture.Width + (BlockWidth - 1)) / BlockWidth;
|
|
|
|
|
|
|
|
int AlignMask = Texture.TileWidth * (64 / Bpp) - 1;
|
|
|
|
|
|
|
|
Width = (Width + AlignMask) & ~AlignMask;
|
|
|
|
|
2018-04-26 02:11:26 +00:00
|
|
|
switch (Texture.Swizzle)
|
|
|
|
{
|
2018-06-23 05:00:44 +00:00
|
|
|
case TextureSwizzle._1dBuffer:
|
2018-04-26 02:11:26 +00:00
|
|
|
case TextureSwizzle.Pitch:
|
|
|
|
case TextureSwizzle.PitchColorKey:
|
|
|
|
return new LinearSwizzle(Texture.Pitch, Bpp);
|
|
|
|
|
|
|
|
case TextureSwizzle.BlockLinear:
|
|
|
|
case TextureSwizzle.BlockLinearColorKey:
|
|
|
|
return new BlockLinearSwizzle(Width, Bpp, Texture.BlockHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new NotImplementedException(Texture.Swizzle.ToString());
|
|
|
|
}
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 18:53:23 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
public static int GetTextureSize(GalImage Image)
|
2018-06-09 00:15:56 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
switch (Image.Format)
|
2018-06-09 00:15:56 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.R32G32B32A32_SFLOAT:
|
|
|
|
case GalImageFormat.R32G32B32A32_SINT:
|
|
|
|
case GalImageFormat.R32G32B32A32_UINT:
|
|
|
|
return Image.Width * Image.Height * 16;
|
|
|
|
|
|
|
|
case GalImageFormat.R16G16B16A16_SFLOAT:
|
|
|
|
case GalImageFormat.R16G16B16A16_SINT:
|
|
|
|
case GalImageFormat.R16G16B16A16_SNORM:
|
|
|
|
case GalImageFormat.R16G16B16A16_UINT:
|
|
|
|
case GalImageFormat.R16G16B16A16_UNORM:
|
2018-09-01 21:25:49 +00:00
|
|
|
case GalImageFormat.D32_SFLOAT_S8_UINT:
|
2018-08-27 14:18:21 +00:00
|
|
|
case GalImageFormat.R32G32_SFLOAT:
|
|
|
|
case GalImageFormat.R32G32_SINT:
|
|
|
|
case GalImageFormat.R32G32_UINT:
|
2018-08-20 01:25:26 +00:00
|
|
|
return Image.Width * Image.Height * 8;
|
|
|
|
|
|
|
|
case GalImageFormat.A8B8G8R8_SINT_PACK32:
|
|
|
|
case GalImageFormat.A8B8G8R8_SNORM_PACK32:
|
|
|
|
case GalImageFormat.A8B8G8R8_UINT_PACK32:
|
|
|
|
case GalImageFormat.A8B8G8R8_UNORM_PACK32:
|
|
|
|
case GalImageFormat.A8B8G8R8_SRGB_PACK32:
|
|
|
|
case GalImageFormat.A2B10G10R10_SINT_PACK32:
|
|
|
|
case GalImageFormat.A2B10G10R10_SNORM_PACK32:
|
|
|
|
case GalImageFormat.A2B10G10R10_UINT_PACK32:
|
|
|
|
case GalImageFormat.A2B10G10R10_UNORM_PACK32:
|
|
|
|
case GalImageFormat.R16G16_SFLOAT:
|
|
|
|
case GalImageFormat.R16G16_SINT:
|
|
|
|
case GalImageFormat.R16G16_SNORM:
|
|
|
|
case GalImageFormat.R16G16_UINT:
|
|
|
|
case GalImageFormat.R16G16_UNORM:
|
|
|
|
case GalImageFormat.R32_SFLOAT:
|
|
|
|
case GalImageFormat.R32_SINT:
|
|
|
|
case GalImageFormat.R32_UINT:
|
|
|
|
case GalImageFormat.D32_SFLOAT:
|
|
|
|
case GalImageFormat.B10G11R11_UFLOAT_PACK32:
|
|
|
|
case GalImageFormat.D24_UNORM_S8_UINT:
|
|
|
|
return Image.Width * Image.Height * 4;
|
|
|
|
|
|
|
|
case GalImageFormat.B4G4R4A4_UNORM_PACK16:
|
|
|
|
case GalImageFormat.A1R5G5B5_UNORM_PACK16:
|
|
|
|
case GalImageFormat.B5G6R5_UNORM_PACK16:
|
|
|
|
case GalImageFormat.R8G8_SINT:
|
|
|
|
case GalImageFormat.R8G8_SNORM:
|
|
|
|
case GalImageFormat.R8G8_UINT:
|
|
|
|
case GalImageFormat.R8G8_UNORM:
|
|
|
|
case GalImageFormat.R16_SFLOAT:
|
|
|
|
case GalImageFormat.R16_SINT:
|
|
|
|
case GalImageFormat.R16_SNORM:
|
|
|
|
case GalImageFormat.R16_UINT:
|
|
|
|
case GalImageFormat.R16_UNORM:
|
|
|
|
case GalImageFormat.D16_UNORM:
|
|
|
|
return Image.Width * Image.Height * 2;
|
|
|
|
|
|
|
|
case GalImageFormat.R8_SINT:
|
|
|
|
case GalImageFormat.R8_SNORM:
|
|
|
|
case GalImageFormat.R8_UINT:
|
|
|
|
case GalImageFormat.R8_UNORM:
|
|
|
|
return Image.Width * Image.Height;
|
|
|
|
|
|
|
|
case GalImageFormat.BC1_RGBA_UNORM_BLOCK:
|
|
|
|
case GalImageFormat.BC4_SNORM_BLOCK:
|
|
|
|
case GalImageFormat.BC4_UNORM_BLOCK:
|
2018-06-09 00:15:56 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 4, 4, 8);
|
2018-06-09 00:15:56 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.BC6H_SFLOAT_BLOCK:
|
|
|
|
case GalImageFormat.BC6H_UFLOAT_BLOCK:
|
|
|
|
case GalImageFormat.BC7_UNORM_BLOCK:
|
|
|
|
case GalImageFormat.BC2_UNORM_BLOCK:
|
|
|
|
case GalImageFormat.BC3_UNORM_BLOCK:
|
|
|
|
case GalImageFormat.BC5_SNORM_BLOCK:
|
|
|
|
case GalImageFormat.BC5_UNORM_BLOCK:
|
|
|
|
case GalImageFormat.ASTC_4x4_UNORM_BLOCK:
|
2018-06-09 00:15:56 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 4, 4, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_5x5_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 5, 5, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_6x6_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 6, 6, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_8x8_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 8, 8, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_10x10_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 10, 10, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_12x12_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 12, 12, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_5x4_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 5, 4, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_6x5_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 6, 5, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_8x6_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 8, 6, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_10x8_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 10, 8, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_12x10_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 12, 10, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_8x5_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 8, 5, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_10x5_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 10, 5, 16);
|
2018-07-13 00:27:59 +00:00
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
2018-08-20 01:25:26 +00:00
|
|
|
case GalImageFormat.ASTC_10x6_UNORM_BLOCK:
|
2018-07-13 00:27:59 +00:00
|
|
|
{
|
2018-08-20 01:25:26 +00:00
|
|
|
return CompressedTextureSize(Image.Width, Image.Height, 10, 6, 16);
|
2018-06-09 00:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-01 21:51:51 +00:00
|
|
|
throw new NotImplementedException(Image.Format.ToString());
|
2018-06-09 00:15:56 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 00:27:59 +00:00
|
|
|
public static int CompressedTextureSize(int TextureWidth, int TextureHeight, int BlockWidth, int BlockHeight, int Bpb)
|
|
|
|
{
|
|
|
|
int W = (TextureWidth + (BlockWidth - 1)) / BlockWidth;
|
|
|
|
int H = (TextureHeight + (BlockHeight - 1)) / BlockHeight;
|
|
|
|
|
|
|
|
return W * H * Bpb;
|
|
|
|
}
|
2018-07-14 16:08:39 +00:00
|
|
|
|
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl
* More work on NvHostCtrl
* Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind
* Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb)
* Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks
* Remove now unused code, add comment about probably wrong result codes
2018-05-07 18:53:23 +00:00
|
|
|
public static (AMemory Memory, long Position) GetMemoryAndPosition(
|
|
|
|
IAMemory Memory,
|
|
|
|
long Position)
|
|
|
|
{
|
|
|
|
if (Memory is NvGpuVmm Vmm)
|
|
|
|
{
|
|
|
|
return (Vmm.Memory, Vmm.GetPhysicalAddress(Position));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((AMemory)Memory, Position);
|
|
|
|
}
|
2018-04-26 02:11:26 +00:00
|
|
|
}
|
|
|
|
}
|