aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Core/Gpu/TextureFactory.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-05-07 15:53:23 -0300
committerGitHub <noreply@github.com>2018-05-07 15:53:23 -0300
commit34037701c708cb70bbf44dea71ee0912f7b4102b (patch)
treeca4cf2bde85dea48af12033b8d0446f17b611f4f /Ryujinx.Core/Gpu/TextureFactory.cs
parent4419e8d6b43432eae94a3a9304f7df22b34738a8 (diff)
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
Diffstat (limited to 'Ryujinx.Core/Gpu/TextureFactory.cs')
-rw-r--r--Ryujinx.Core/Gpu/TextureFactory.cs83
1 files changed, 83 insertions, 0 deletions
diff --git a/Ryujinx.Core/Gpu/TextureFactory.cs b/Ryujinx.Core/Gpu/TextureFactory.cs
new file mode 100644
index 00000000..68b48a1f
--- /dev/null
+++ b/Ryujinx.Core/Gpu/TextureFactory.cs
@@ -0,0 +1,83 @@
+using Ryujinx.Graphics.Gal;
+using System;
+
+namespace Ryujinx.Core.Gpu
+{
+ static class TextureFactory
+ {
+ public static GalTexture MakeTexture(NvGpu Gpu, NvGpuVmm Vmm, long TicPosition)
+ {
+ int[] Tic = ReadWords(Vmm, TicPosition, 8);
+
+ GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f);
+
+ long TextureAddress = (uint)Tic[1];
+
+ TextureAddress |= (long)((ushort)Tic[2]) << 32;
+
+ TextureSwizzle Swizzle = (TextureSwizzle)((Tic[2] >> 21) & 7);
+
+ int Pitch = (Tic[3] & 0xffff) << 5;
+
+ 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,
+ Pitch,
+ BlockHeight,
+ Swizzle,
+ Format);
+
+ byte[] Data = TextureReader.Read(Vmm, Texture);
+
+ return new GalTexture(Data, Width, Height, Format);
+ }
+
+ public static GalTextureSampler MakeSampler(NvGpu Gpu, NvGpuVmm Vmm, long TscPosition)
+ {
+ int[] Tsc = ReadWords(Vmm, TscPosition, 8);
+
+ 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);
+ }
+
+ private static int[] ReadWords(NvGpuVmm Vmm, long Position, int Count)
+ {
+ int[] Words = new int[Count];
+
+ for (int Index = 0; Index < Count; Index++, Position += 4)
+ {
+ Words[Index] = Vmm.ReadInt32(Position);
+ }
+
+ return Words;
+ }
+ }
+} \ No newline at end of file