2018-04-08 21:17:35 +02:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-09-08 19:51:50 +02:00
|
|
|
using Ryujinx.Graphics.Memory;
|
2018-04-08 21:17:35 +02:00
|
|
|
using System;
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
namespace Ryujinx.Graphics.Texture
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
static class TextureFactory
|
|
|
|
{
|
2018-08-20 03:25:26 +02:00
|
|
|
public static GalImage MakeTexture(NvGpuVmm Vmm, long TicPosition)
|
2018-04-08 21:17:35 +02: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 20:53:23 +02:00
|
|
|
int[] Tic = ReadWords(Vmm, TicPosition, 8);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
GalImageFormat Format = GetImageFormat(Tic);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
2018-05-17 20:25:42 +02:00
|
|
|
GalTextureSource XSource = (GalTextureSource)((Tic[0] >> 19) & 7);
|
|
|
|
GalTextureSource YSource = (GalTextureSource)((Tic[0] >> 22) & 7);
|
|
|
|
GalTextureSource ZSource = (GalTextureSource)((Tic[0] >> 25) & 7);
|
|
|
|
GalTextureSource WSource = (GalTextureSource)((Tic[0] >> 28) & 7);
|
|
|
|
|
2018-06-09 02:15:56 +02:00
|
|
|
int Width = (Tic[4] & 0xffff) + 1;
|
|
|
|
int Height = (Tic[5] & 0xffff) + 1;
|
|
|
|
|
2018-08-20 03:25:26 +02:00
|
|
|
return new GalImage(
|
2018-06-09 02:15:56 +02:00
|
|
|
Width,
|
|
|
|
Height,
|
|
|
|
Format,
|
|
|
|
XSource,
|
|
|
|
YSource,
|
|
|
|
ZSource,
|
|
|
|
WSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte[] GetTextureData(NvGpuVmm Vmm, long TicPosition)
|
|
|
|
{
|
|
|
|
int[] Tic = ReadWords(Vmm, TicPosition, 8);
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
GalImageFormat Format = GetImageFormat(Tic);
|
2018-06-09 02:15:56 +02:00
|
|
|
|
2018-04-08 21:17:35 +02:00
|
|
|
long TextureAddress = (uint)Tic[1];
|
|
|
|
|
|
|
|
TextureAddress |= (long)((ushort)Tic[2]) << 32;
|
|
|
|
|
|
|
|
TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7);
|
|
|
|
|
2018-06-23 07:00:44 +02:00
|
|
|
if (Swizzle == TextureSwizzle.BlockLinear ||
|
|
|
|
Swizzle == TextureSwizzle.BlockLinearColorKey)
|
|
|
|
{
|
|
|
|
TextureAddress &= ~0x1ffL;
|
|
|
|
}
|
|
|
|
else if (Swizzle == TextureSwizzle.Pitch ||
|
|
|
|
Swizzle == TextureSwizzle.PitchColorKey)
|
|
|
|
{
|
|
|
|
TextureAddress &= ~0x1fL;
|
|
|
|
}
|
|
|
|
|
2018-04-08 22:09:41 +02:00
|
|
|
int Pitch = (Tic[3] & 0xffff) << 5;
|
|
|
|
|
2018-07-19 07:30:21 +02:00
|
|
|
int BlockHeightLog2 = (Tic[3] >> 3) & 7;
|
|
|
|
int TileWidthLog2 = (Tic[3] >> 10) & 7;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
int BlockHeight = 1 << BlockHeightLog2;
|
2018-07-19 07:30:21 +02:00
|
|
|
int TileWidth = 1 << TileWidthLog2;
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
int Width = (Tic[4] & 0xffff) + 1;
|
|
|
|
int Height = (Tic[5] & 0xffff) + 1;
|
|
|
|
|
2018-06-24 02:39:25 +02:00
|
|
|
TextureInfo Texture = new TextureInfo(
|
2018-04-08 21:17:35 +02:00
|
|
|
TextureAddress,
|
|
|
|
Width,
|
|
|
|
Height,
|
2018-04-08 22:09:41 +02:00
|
|
|
Pitch,
|
2018-04-08 21:17:35 +02:00
|
|
|
BlockHeight,
|
2018-07-19 07:30:21 +02:00
|
|
|
TileWidth,
|
2018-04-08 21:17:35 +02:00
|
|
|
Swizzle,
|
|
|
|
Format);
|
|
|
|
|
2018-06-09 02:15:56 +02:00
|
|
|
return TextureReader.Read(Vmm, Texture);
|
2018-04-08 21:17:35 +02: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 20:53:23 +02:00
|
|
|
public static GalTextureSampler MakeSampler(NvGpu Gpu, NvGpuVmm Vmm, long TscPosition)
|
2018-04-08 21:17:35 +02: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 20:53:23 +02:00
|
|
|
int[] Tsc = ReadWords(Vmm, TscPosition, 8);
|
2018-04-08 21:17:35 +02:00
|
|
|
|
|
|
|
GalTextureWrap AddressU = (GalTextureWrap)((Tsc[0] >> 0) & 7);
|
|
|
|
GalTextureWrap AddressV = (GalTextureWrap)((Tsc[0] >> 3) & 7);
|
|
|
|
GalTextureWrap AddressP = (GalTextureWrap)((Tsc[0] >> 6) & 7);
|
|
|
|
|
|
|
|
GalTextureFilter MagFilter = (GalTextureFilter) ((Tsc[1] >> 0) & 3);
|
|
|
|
GalTextureFilter MinFilter = (GalTextureFilter) ((Tsc[1] >> 4) & 3);
|
|
|
|
GalTextureMipFilter MipFilter = (GalTextureMipFilter)((Tsc[1] >> 6) & 3);
|
|
|
|
|
|
|
|
GalColorF BorderColor = new GalColorF(
|
|
|
|
BitConverter.Int32BitsToSingle(Tsc[4]),
|
|
|
|
BitConverter.Int32BitsToSingle(Tsc[5]),
|
|
|
|
BitConverter.Int32BitsToSingle(Tsc[6]),
|
|
|
|
BitConverter.Int32BitsToSingle(Tsc[7]));
|
|
|
|
|
|
|
|
return new GalTextureSampler(
|
|
|
|
AddressU,
|
|
|
|
AddressV,
|
|
|
|
AddressP,
|
|
|
|
MinFilter,
|
|
|
|
MagFilter,
|
|
|
|
MipFilter,
|
|
|
|
BorderColor);
|
|
|
|
}
|
|
|
|
|
2018-09-08 19:51:50 +02:00
|
|
|
private static GalImageFormat GetImageFormat(int[] Tic)
|
|
|
|
{
|
|
|
|
GalTextureType RType = (GalTextureType)((Tic[0] >> 7) & 7);
|
|
|
|
GalTextureType GType = (GalTextureType)((Tic[0] >> 10) & 7);
|
|
|
|
GalTextureType BType = (GalTextureType)((Tic[0] >> 13) & 7);
|
|
|
|
GalTextureType AType = (GalTextureType)((Tic[0] >> 16) & 7);
|
|
|
|
|
|
|
|
GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f);
|
|
|
|
|
|
|
|
return ImageUtils.ConvertTexture(Format, RType, GType, BType, AType);
|
|
|
|
}
|
|
|
|
|
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 20:53:23 +02:00
|
|
|
private static int[] ReadWords(NvGpuVmm Vmm, long Position, int Count)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
int[] Words = new int[Count];
|
|
|
|
|
|
|
|
for (int Index = 0; Index < Count; Index++, Position += 4)
|
|
|
|
{
|
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 20:53:23 +02:00
|
|
|
Words[Index] = Vmm.ReadInt32(Position);
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Words;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|