2018-04-08 19:17:35 +00:00
|
|
|
using Ryujinx.Graphics.Gal;
|
|
|
|
using System;
|
|
|
|
|
2018-06-11 00:46:42 +00:00
|
|
|
namespace Ryujinx.HLE.Gpu
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
|
|
|
static class TextureFactory
|
|
|
|
{
|
2018-06-09 00:15:56 +00:00
|
|
|
public static GalTexture MakeTexture(NvGpuVmm Vmm, long TicPosition)
|
2018-04-08 19:17:35 +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
|
|
|
int[] Tic = ReadWords(Vmm, TicPosition, 8);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f);
|
|
|
|
|
2018-05-17 18:25:42 +00: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 00:15:56 +00:00
|
|
|
int Width = (Tic[4] & 0xffff) + 1;
|
|
|
|
int Height = (Tic[5] & 0xffff) + 1;
|
|
|
|
|
|
|
|
return new GalTexture(
|
|
|
|
Width,
|
|
|
|
Height,
|
|
|
|
Format,
|
|
|
|
XSource,
|
|
|
|
YSource,
|
|
|
|
ZSource,
|
|
|
|
WSource);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static byte[] GetTextureData(NvGpuVmm Vmm, long TicPosition)
|
|
|
|
{
|
|
|
|
int[] Tic = ReadWords(Vmm, TicPosition, 8);
|
|
|
|
|
|
|
|
GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f);
|
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
long TextureAddress = (uint)Tic[1];
|
|
|
|
|
|
|
|
TextureAddress |= (long)((ushort)Tic[2]) << 32;
|
|
|
|
|
|
|
|
TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7);
|
|
|
|
|
2018-04-08 20:09:41 +00:00
|
|
|
int Pitch = (Tic[3] & 0xffff) << 5;
|
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
int BlockHeightLog2 = (Tic[3] >> 3) & 7;
|
|
|
|
|
|
|
|
int BlockHeight = 1 << BlockHeightLog2;
|
|
|
|
|
|
|
|
int Width = (Tic[4] & 0xffff) + 1;
|
|
|
|
int Height = (Tic[5] & 0xffff) + 1;
|
|
|
|
|
|
|
|
Texture Texture = new Texture(
|
|
|
|
TextureAddress,
|
|
|
|
Width,
|
|
|
|
Height,
|
2018-04-08 20:09:41 +00:00
|
|
|
Pitch,
|
2018-04-08 19:17:35 +00:00
|
|
|
BlockHeight,
|
|
|
|
Swizzle,
|
|
|
|
Format);
|
|
|
|
|
2018-06-09 00:15:56 +00:00
|
|
|
return TextureReader.Read(Vmm, Texture);
|
2018-04-08 19:17:35 +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 GalTextureSampler MakeSampler(NvGpu Gpu, NvGpuVmm Vmm, long TscPosition)
|
2018-04-08 19:17:35 +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
|
|
|
int[] Tsc = ReadWords(Vmm, TscPosition, 8);
|
2018-04-08 19:17:35 +00: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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
private static int[] ReadWords(NvGpuVmm Vmm, long Position, int Count)
|
2018-04-08 19:17:35 +00: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 18:53:23 +00:00
|
|
|
Words[Index] = Vmm.ReadInt32(Position);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Words;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|