Organized the Gpu folder a bit more, renamed a few things, address PR feedback

This commit is contained in:
gdkchan 2018-06-23 18:22:24 -03:00
commit e7320471b9
48 changed files with 191 additions and 179 deletions

View file

@ -1,7 +0,0 @@
namespace Ryujinx.Graphics.Gal
{
public static class GalConsts
{
public const string FlipUniformName = "flip";
}
}

View file

@ -4,13 +4,13 @@ namespace Ryujinx.Graphics.Gal
{ {
public interface IGalFrameBuffer public interface IGalFrameBuffer
{ {
void Create(long Tag, int Width, int Height); void Create(long Key, int Width, int Height);
void Bind(long Tag); void Bind(long Key);
void BindTexture(long Tag, int Index); void BindTexture(long Key, int Index);
void Set(long Tag); void Set(long Key);
void Set(byte[] Data, int Width, int Height); void Set(byte[] Data, int Width, int Height);
@ -22,6 +22,6 @@ namespace Ryujinx.Graphics.Gal
void Render(); void Render();
void GetBufferData(long Tag, Action<byte[]> Callback); void GetBufferData(long Key, Action<byte[]> Callback);
} }
} }

View file

@ -4,20 +4,20 @@ namespace Ryujinx.Graphics.Gal
{ {
void ClearBuffers(int RtIndex, GalClearBufferFlags Flags); void ClearBuffers(int RtIndex, GalClearBufferFlags Flags);
bool IsVboCached(long Tag, long DataSize); bool IsVboCached(long Key, long DataSize);
bool IsIboCached(long Tag, long DataSize); bool IsIboCached(long Key, long DataSize);
void CreateVbo(long Tag, byte[] Buffer); void CreateVbo(long Key, byte[] Buffer);
void CreateIbo(long Tag, byte[] Buffer); void CreateIbo(long Key, byte[] Buffer);
void SetVertexArray(int VbIndex, int Stride, long VboTag, GalVertexAttrib[] Attribs); void SetVertexArray(int VbIndex, int Stride, long VboKey, GalVertexAttrib[] Attribs);
void SetIndexArray(long Tag, int Size, GalIndexFormat Format); void SetIndexArray(long Key, int Size, GalIndexFormat Format);
void DrawArrays(int First, int PrimCount, GalPrimitiveType PrimType); void DrawArrays(int First, int PrimCount, GalPrimitiveType PrimType);
void DrawElements(long IboTag, int First, GalPrimitiveType PrimType); void DrawElements(long IboKey, int First, GalPrimitiveType PrimType);
} }
} }

View file

@ -4,17 +4,17 @@ namespace Ryujinx.Graphics.Gal
{ {
public interface IGalShader public interface IGalShader
{ {
void Create(IGalMemory Memory, long Tag, GalShaderType Type); void Create(IGalMemory Memory, long Key, GalShaderType Type);
IEnumerable<ShaderDeclInfo> GetTextureUsage(long Tag); IEnumerable<ShaderDeclInfo> GetTextureUsage(long Key);
void SetConstBuffer(long Tag, int Cbuf, byte[] Data); void SetConstBuffer(long Key, int Cbuf, byte[] Data);
void SetUniform1(string UniformName, int Value); void EnsureTextureBinding(string UniformName, int Value);
void SetUniform2F(string UniformName, float X, float Y); void SetFlip(float X, float Y);
void Bind(long Tag); void Bind(long Key);
void BindProgram(); void BindProgram();
} }

View file

@ -2,11 +2,11 @@ namespace Ryujinx.Graphics.Gal
{ {
public interface IGalTexture public interface IGalTexture
{ {
void Create(long Tag, byte[] Data, GalTexture Texture); void Create(long Key, byte[] Data, GalTexture Texture);
bool TryGetCachedTexture(long Tag, long DataSize, out GalTexture Texture); bool TryGetCachedTexture(long Key, long DataSize, out GalTexture Texture);
void Bind(long Tag, int Index); void Bind(long Key, int Index);
void SetSampler(GalTextureSampler Sampler); void SetSampler(GalTextureSampler Sampler);
} }

View file

@ -76,14 +76,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Shader = new ShaderProgram(); Shader = new ShaderProgram();
} }
public void Create(long Tag, int Width, int Height) public void Create(long Key, int Width, int Height)
{ {
//TODO: We should either use the original frame buffer size, //TODO: We should either use the original frame buffer size,
//or just remove the Width/Height arguments. //or just remove the Width/Height arguments.
Width = Window.Width; Width = Window.Width;
Height = Window.Height; Height = Window.Height;
if (Fbs.TryGetValue(Tag, out FrameBuffer Fb)) if (Fbs.TryGetValue(Key, out FrameBuffer Fb))
{ {
if (Fb.Width != Width || if (Fb.Width != Width ||
Fb.Height != Height) Fb.Height != Height)
@ -127,12 +127,12 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.Viewport(0, 0, Width, Height); GL.Viewport(0, 0, Width, Height);
Fbs.Add(Tag, Fb); Fbs.Add(Key, Fb);
} }
public void Bind(long Tag) public void Bind(long Key)
{ {
if (Fbs.TryGetValue(Tag, out FrameBuffer Fb)) if (Fbs.TryGetValue(Key, out FrameBuffer Fb))
{ {
GL.BindFramebuffer(FramebufferTarget.Framebuffer, Fb.Handle); GL.BindFramebuffer(FramebufferTarget.Framebuffer, Fb.Handle);
@ -140,9 +140,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
} }
} }
public void BindTexture(long Tag, int Index) public void BindTexture(long Key, int Index)
{ {
if (Fbs.TryGetValue(Tag, out FrameBuffer Fb)) if (Fbs.TryGetValue(Key, out FrameBuffer Fb))
{ {
GL.ActiveTexture(TextureUnit.Texture0 + Index); GL.ActiveTexture(TextureUnit.Texture0 + Index);
@ -150,9 +150,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
} }
} }
public void Set(long Tag) public void Set(long Key)
{ {
if (Fbs.TryGetValue(Tag, out FrameBuffer Fb)) if (Fbs.TryGetValue(Key, out FrameBuffer Fb))
{ {
CurrTexHandle = Fb.TexHandle; CurrTexHandle = Fb.TexHandle;
} }
@ -277,9 +277,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
} }
} }
public void GetBufferData(long Tag, Action<byte[]> Callback) public void GetBufferData(long Key, Action<byte[]> Callback)
{ {
if (Fbs.TryGetValue(Tag, out FrameBuffer Fb)) if (Fbs.TryGetValue(Key, out FrameBuffer Fb))
{ {
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, Fb.Handle); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, Fb.Handle);

View file

@ -74,8 +74,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{ {
ClearBufferMask Mask = 0; ClearBufferMask Mask = 0;
//OpenGL doesn't support clearing just a single color channel, //TODO: Use glColorMask to clear just the specified channels.
//so we can't just clear all channels...
if (Flags.HasFlag(GalClearBufferFlags.ColorRed) && if (Flags.HasFlag(GalClearBufferFlags.ColorRed) &&
Flags.HasFlag(GalClearBufferFlags.ColorGreen) && Flags.HasFlag(GalClearBufferFlags.ColorGreen) &&
Flags.HasFlag(GalClearBufferFlags.ColorBlue) && Flags.HasFlag(GalClearBufferFlags.ColorBlue) &&
@ -97,45 +96,43 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.Clear(Mask); GL.Clear(Mask);
} }
public bool IsVboCached(long Tag, long DataSize) public bool IsVboCached(long Key, long DataSize)
{ {
return VboCache.TryGetSize(Tag, out long Size) && Size == DataSize; return VboCache.TryGetSize(Key, out long Size) && Size == DataSize;
} }
public bool IsIboCached(long Tag, long DataSize) public bool IsIboCached(long Key, long DataSize)
{ {
return IboCache.TryGetSize(Tag, out long Size) && Size == DataSize; return IboCache.TryGetSize(Key, out long Size) && Size == DataSize;
} }
public void CreateVbo(long Tag, byte[] Buffer) public void CreateVbo(long Key, byte[] Buffer)
{ {
int Handle = GL.GenBuffer(); int Handle = GL.GenBuffer();
VboCache.AddOrUpdate(Tag, Handle, (uint)Buffer.Length); VboCache.AddOrUpdate(Key, Handle, (uint)Buffer.Length);
IntPtr Length = new IntPtr(Buffer.Length); IntPtr Length = new IntPtr(Buffer.Length);
GL.BindBuffer(BufferTarget.ArrayBuffer, Handle); GL.BindBuffer(BufferTarget.ArrayBuffer, Handle);
GL.BufferData(BufferTarget.ArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw); GL.BufferData(BufferTarget.ArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
} }
public void CreateIbo(long Tag, byte[] Buffer) public void CreateIbo(long Key, byte[] Buffer)
{ {
int Handle = GL.GenBuffer(); int Handle = GL.GenBuffer();
IboCache.AddOrUpdate(Tag, Handle, (uint)Buffer.Length); IboCache.AddOrUpdate(Key, Handle, (uint)Buffer.Length);
IntPtr Length = new IntPtr(Buffer.Length); IntPtr Length = new IntPtr(Buffer.Length);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, Handle); GL.BindBuffer(BufferTarget.ElementArrayBuffer, Handle);
GL.BufferData(BufferTarget.ElementArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw); GL.BufferData(BufferTarget.ElementArrayBuffer, Length, Buffer, BufferUsageHint.StreamDraw);
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
} }
public void SetVertexArray(int VbIndex, int Stride, long VboTag, GalVertexAttrib[] Attribs) public void SetVertexArray(int VbIndex, int Stride, long VboKey, GalVertexAttrib[] Attribs)
{ {
if (!VboCache.TryGetValue(VboTag, out int VboHandle)) if (!VboCache.TryGetValue(VboKey, out int VboHandle))
{ {
return; return;
} }
@ -178,11 +175,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Stride, Offset); GL.VertexAttribPointer(Attrib.Index, Size, Type, Normalize, Stride, Offset);
} }
GL.BindVertexArray(0);
} }
public void SetIndexArray(long Tag, int Size, GalIndexFormat Format) public void SetIndexArray(long Key, int Size, GalIndexFormat Format)
{ {
IndexBuffer.Type = OGLEnumConverter.GetDrawElementsType(Format); IndexBuffer.Type = OGLEnumConverter.GetDrawElementsType(Format);
@ -201,9 +196,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.DrawArrays(OGLEnumConverter.GetPrimitiveType(PrimType), First, PrimCount); GL.DrawArrays(OGLEnumConverter.GetPrimitiveType(PrimType), First, PrimCount);
} }
public void DrawElements(long IboTag, int First, GalPrimitiveType PrimType) public void DrawElements(long IboKey, int First, GalPrimitiveType PrimType)
{ {
if (!IboCache.TryGetValue(IboTag, out int IboHandle)) if (!IboCache.TryGetValue(IboKey, out int IboHandle))
{ {
return; return;
} }

View file

@ -3,7 +3,7 @@ using System.Collections.Concurrent;
namespace Ryujinx.Graphics.Gal.OpenGL namespace Ryujinx.Graphics.Gal.OpenGL
{ {
public class OpenGLRenderer : IGalRenderer public class OGLRenderer : IGalRenderer
{ {
public IGalBlend Blend { get; private set; } public IGalBlend Blend { get; private set; }
@ -17,7 +17,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
private ConcurrentQueue<Action> ActionsQueue; private ConcurrentQueue<Action> ActionsQueue;
public OpenGLRenderer() public OGLRenderer()
{ {
Blend = new OGLBlend(); Blend = new OGLBlend();

View file

@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Programs = new Dictionary<ShaderProgram, int>(); Programs = new Dictionary<ShaderProgram, int>();
} }
public void Create(IGalMemory Memory, long Tag, GalShaderType Type) public void Create(IGalMemory Memory, long Key, GalShaderType Type)
{ {
Stages.GetOrAdd(Tag, (Key) => ShaderStageFactory(Memory, Tag, Type)); Stages.GetOrAdd(Key, (Stage) => ShaderStageFactory(Memory, Key, Type));
} }
private ShaderStage ShaderStageFactory(IGalMemory Memory, long Position, GalShaderType Type) private ShaderStage ShaderStageFactory(IGalMemory Memory, long Position, GalShaderType Type)
@ -107,9 +107,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
return Decompiler.Decompile(Memory, Position + 0x50, Type); return Decompiler.Decompile(Memory, Position + 0x50, Type);
} }
public IEnumerable<ShaderDeclInfo> GetTextureUsage(long Tag) public IEnumerable<ShaderDeclInfo> GetTextureUsage(long Key)
{ {
if (Stages.TryGetValue(Tag, out ShaderStage Stage)) if (Stages.TryGetValue(Key, out ShaderStage Stage))
{ {
return Stage.TextureUsage; return Stage.TextureUsage;
} }
@ -117,11 +117,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
return Enumerable.Empty<ShaderDeclInfo>(); return Enumerable.Empty<ShaderDeclInfo>();
} }
public void SetConstBuffer(long Tag, int Cbuf, byte[] Data) public void SetConstBuffer(long Key, int Cbuf, byte[] Data)
{ {
BindProgram(); BindProgram();
if (Stages.TryGetValue(Tag, out ShaderStage Stage)) if (Stages.TryGetValue(Key, out ShaderStage Stage))
{ {
foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage.Where(x => x.Cbuf == Cbuf)) foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage.Where(x => x.Cbuf == Cbuf))
{ {
@ -144,7 +144,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
} }
} }
public void SetUniform1(string UniformName, int Value) public void EnsureTextureBinding(string UniformName, int Value)
{ {
BindProgram(); BindProgram();
@ -153,18 +153,18 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.Uniform1(Location, Value); GL.Uniform1(Location, Value);
} }
public void SetUniform2F(string UniformName, float X, float Y) public void SetFlip(float X, float Y)
{ {
BindProgram(); BindProgram();
int Location = GL.GetUniformLocation(CurrentProgramHandle, UniformName); int Location = GL.GetUniformLocation(CurrentProgramHandle, GlslDecl.FlipUniformName);
GL.Uniform2(Location, X, Y); GL.Uniform2(Location, X, Y);
} }
public void Bind(long Tag) public void Bind(long Key)
{ {
if (Stages.TryGetValue(Tag, out ShaderStage Stage)) if (Stages.TryGetValue(Key, out ShaderStage Stage))
{ {
Bind(Stage); Bind(Stage);
} }

View file

@ -31,11 +31,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.DeleteTexture(CachedTexture.Handle); GL.DeleteTexture(CachedTexture.Handle);
} }
public void Create(long Tag, byte[] Data, GalTexture Texture) public void Create(long Key, byte[] Data, GalTexture Texture)
{ {
int Handle = GL.GenTexture(); int Handle = GL.GenTexture();
TextureCache.AddOrUpdate(Tag, new TCE(Handle, Texture), (uint)Data.Length); TextureCache.AddOrUpdate(Key, new TCE(Handle, Texture), (uint)Data.Length);
GL.BindTexture(TextureTarget.Texture2D, Handle); GL.BindTexture(TextureTarget.Texture2D, Handle);
@ -146,11 +146,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
throw new ArgumentException(nameof(Format)); throw new ArgumentException(nameof(Format));
} }
public bool TryGetCachedTexture(long Tag, long DataSize, out GalTexture Texture) public bool TryGetCachedTexture(long Key, long DataSize, out GalTexture Texture)
{ {
if (TextureCache.TryGetSize(Tag, out long Size) && Size == DataSize) if (TextureCache.TryGetSize(Key, out long Size) && Size == DataSize)
{ {
if (TextureCache.TryGetValue(Tag, out TCE CachedTexture)) if (TextureCache.TryGetValue(Key, out TCE CachedTexture))
{ {
Texture = CachedTexture.Texture; Texture = CachedTexture.Texture;
@ -163,9 +163,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL
return false; return false;
} }
public void Bind(long Tag, int Index) public void Bind(long Key, int Index)
{ {
if (TextureCache.TryGetValue(Tag, out TCE CachedTexture)) if (TextureCache.TryGetValue(Key, out TCE CachedTexture))
{ {
GL.ActiveTexture(TextureUnit.Texture0 + Index); GL.ActiveTexture(TextureUnit.Texture0 + Index);

View file

@ -26,6 +26,8 @@ namespace Ryujinx.Graphics.Gal.Shader
public const string FragmentOutputName = "FragColor"; public const string FragmentOutputName = "FragColor";
public const string FlipUniformName = "flip";
private string[] StagePrefixes = new string[] { "vp", "tcp", "tep", "gp", "fp" }; private string[] StagePrefixes = new string[] { "vp", "tcp", "tep", "gp", "fp" };
private string StagePrefix; private string StagePrefix;

View file

@ -140,7 +140,7 @@ namespace Ryujinx.Graphics.Gal.Shader
{ {
if (Decl.ShaderType == GalShaderType.Vertex) if (Decl.ShaderType == GalShaderType.Vertex)
{ {
SB.AppendLine("uniform vec2 " + GalConsts.FlipUniformName + ";"); SB.AppendLine("uniform vec2 " + GlslDecl.FlipUniformName + ";");
} }
foreach (ShaderDeclInfo DeclInfo in Decl.Uniforms.Values.OrderBy(DeclKeySelector)) foreach (ShaderDeclInfo DeclInfo in Decl.Uniforms.Values.OrderBy(DeclKeySelector))

View file

@ -1,4 +1,6 @@
namespace Ryujinx.HLE.Gpu using Ryujinx.HLE.Gpu.Memory;
namespace Ryujinx.HLE.Gpu.Engines
{ {
interface INvGpuEngine interface INvGpuEngine
{ {

View file

@ -1,7 +1,9 @@
using Ryujinx.HLE.Gpu.Exceptions;
using Ryujinx.HLE.Gpu.Memory;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
class MacroInterpreter class MacroInterpreter
{ {
@ -419,7 +421,7 @@ namespace Ryujinx.HLE.Gpu
//draw calls, this prevents the system from freezing (and throws instead). //draw calls, this prevents the system from freezing (and throws instead).
if (MethAddr == 0x585 && ++CallCount > MaxCallCountPerRun) if (MethAddr == 0x585 && ++CallCount > MaxCallCountPerRun)
{ {
throw new GpuMacroException(GpuMacroExceptionMsgs.CallCountExceeded); GpuExceptionHelper.ThrowCallCoundExceeded();
} }
NvGpuPBEntry PBEntry = new NvGpuPBEntry(MethAddr, 0, Value); NvGpuPBEntry PBEntry = new NvGpuPBEntry(MethAddr, 0, Value);

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
enum NvGpuEngine enum NvGpuEngine
{ {

View file

@ -1,7 +1,9 @@
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using Ryujinx.HLE.Gpu.Memory;
using Ryujinx.HLE.Gpu.Texture;
using System.Collections.Generic; using System.Collections.Generic;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
class NvGpuEngine2d : INvGpuEngine class NvGpuEngine2d : INvGpuEngine
{ {
@ -75,19 +77,19 @@ namespace Ryujinx.HLE.Gpu
int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf); int DstBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf);
long Tag = Vmm.GetPhysicalAddress(MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress)); long Key = Vmm.GetPhysicalAddress(MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress));
long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress); long SrcAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.SrcAddress);
long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress); long DstAddress = MakeInt64From2xInt32(NvGpuEngine2dReg.DstAddress);
bool IsFbTexture = Gpu.Engine3d.IsFrameBufferPosition(Tag); bool IsFbTexture = Gpu.Engine3d.IsFrameBufferPosition(Key);
if (IsFbTexture && DstLinear) if (IsFbTexture && DstLinear)
{ {
DstSwizzle = TextureSwizzle.BlockLinear; DstSwizzle = TextureSwizzle.BlockLinear;
} }
Texture DstTexture = new Texture( TextureInfo DstTexture = new TextureInfo(
DstAddress, DstAddress,
DstWidth, DstWidth,
DstHeight, DstHeight,
@ -103,7 +105,7 @@ namespace Ryujinx.HLE.Gpu
SrcWidth = 1280; SrcWidth = 1280;
SrcHeight = 720; SrcHeight = 720;
Gpu.Renderer.FrameBuffer.GetBufferData(Tag, (byte[] Buffer) => Gpu.Renderer.FrameBuffer.GetBufferData(Key, (byte[] Buffer) =>
{ {
CopyTexture( CopyTexture(
Vmm, Vmm,
@ -130,7 +132,7 @@ namespace Ryujinx.HLE.Gpu
private void CopyTexture( private void CopyTexture(
NvGpuVmm Vmm, NvGpuVmm Vmm,
Texture Texture, TextureInfo Texture,
byte[] Buffer, byte[] Buffer,
int Width, int Width,
int Height) int Height)

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
enum NvGpuEngine2dReg enum NvGpuEngine2dReg
{ {

View file

@ -1,8 +1,10 @@
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using Ryujinx.HLE.Gpu.Memory;
using Ryujinx.HLE.Gpu.Texture;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
class NvGpuEngine3d : INvGpuEngine class NvGpuEngine3d : INvGpuEngine
{ {
@ -73,13 +75,13 @@ namespace Ryujinx.HLE.Gpu
{ {
SetFrameBuffer(Vmm, 0); SetFrameBuffer(Vmm, 0);
long[] Tags = UploadShaders(Vmm); long[] Keys = UploadShaders(Vmm);
Gpu.Renderer.Shader.BindProgram(); Gpu.Renderer.Shader.BindProgram();
SetAlphaBlending(); SetAlphaBlending();
UploadTextures(Vmm, Tags); UploadTextures(Vmm, Keys);
UploadUniforms(Vmm); UploadUniforms(Vmm);
UploadVertexArrays(Vmm); UploadVertexArrays(Vmm);
} }
@ -119,7 +121,7 @@ namespace Ryujinx.HLE.Gpu
private long[] UploadShaders(NvGpuVmm Vmm) private long[] UploadShaders(NvGpuVmm Vmm)
{ {
long[] Tags = new long[5]; long[] Keys = new long[5];
long BasePosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress); long BasePosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress);
@ -136,14 +138,14 @@ namespace Ryujinx.HLE.Gpu
continue; continue;
} }
long Tag = BasePosition + (uint)Offset; long Key = BasePosition + (uint)Offset;
GalShaderType ShaderType = GetTypeFromProgram(Index); GalShaderType ShaderType = GetTypeFromProgram(Index);
Tags[(int)ShaderType] = Tag; Keys[(int)ShaderType] = Key;
Gpu.Renderer.Shader.Create(Vmm, Tag, ShaderType); Gpu.Renderer.Shader.Create(Vmm, Key, ShaderType);
Gpu.Renderer.Shader.Bind(Tag); Gpu.Renderer.Shader.Bind(Key);
} }
int RawSX = ReadRegister(NvGpuEngine3dReg.ViewportScaleX); int RawSX = ReadRegister(NvGpuEngine3dReg.ViewportScaleX);
@ -155,9 +157,9 @@ namespace Ryujinx.HLE.Gpu
float SignX = MathF.Sign(SX); float SignX = MathF.Sign(SX);
float SignY = MathF.Sign(SY); float SignY = MathF.Sign(SY);
Gpu.Renderer.Shader.SetUniform2F(GalConsts.FlipUniformName, SignX, SignY); Gpu.Renderer.Shader.SetFlip(SignX, SignY);
return Tags; return Keys;
} }
private static GalShaderType GetTypeFromProgram(int Program) private static GalShaderType GetTypeFromProgram(int Program)
@ -224,7 +226,7 @@ namespace Ryujinx.HLE.Gpu
} }
} }
private void UploadTextures(NvGpuVmm Vmm, long[] Tags) private void UploadTextures(NvGpuVmm Vmm, long[] Keys)
{ {
long BaseShPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress); long BaseShPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress);
@ -234,15 +236,15 @@ namespace Ryujinx.HLE.Gpu
//reserved for drawing the frame buffer. //reserved for drawing the frame buffer.
int TexIndex = 1; int TexIndex = 1;
for (int Index = 0; Index < Tags.Length; Index++) for (int Index = 0; Index < Keys.Length; Index++)
{ {
foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetTextureUsage(Tags[Index])) foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetTextureUsage(Keys[Index]))
{ {
long Position = ConstBuffers[Index][TextureCbIndex].Position; long Position = ConstBuffers[Index][TextureCbIndex].Position;
UploadTexture(Vmm, Position, TexIndex, DeclInfo.Index); UploadTexture(Vmm, Position, TexIndex, DeclInfo.Index);
Gpu.Renderer.Shader.SetUniform1(DeclInfo.Name, TexIndex); Gpu.Renderer.Shader.EnsureTextureBinding(DeclInfo.Name, TexIndex);
TexIndex++; TexIndex++;
} }
@ -277,7 +279,7 @@ namespace Ryujinx.HLE.Gpu
long TextureAddress = Vmm.ReadInt64(TicPosition + 4) & 0xffffffffffff; long TextureAddress = Vmm.ReadInt64(TicPosition + 4) & 0xffffffffffff;
long Tag = TextureAddress; long Key = TextureAddress;
TextureAddress = Vmm.GetPhysicalAddress(TextureAddress); TextureAddress = Vmm.GetPhysicalAddress(TextureAddress);
@ -297,11 +299,11 @@ namespace Ryujinx.HLE.Gpu
bool HasCachedTexture = false; bool HasCachedTexture = false;
if (Gpu.Renderer.Texture.TryGetCachedTexture(Tag, Size, out GalTexture Texture)) if (Gpu.Renderer.Texture.TryGetCachedTexture(Key, Size, out GalTexture Texture))
{ {
if (NewTexture.Equals(Texture) && !Vmm.IsRegionModified(Tag, Size, NvGpuBufferType.Texture)) if (NewTexture.Equals(Texture) && !Vmm.IsRegionModified(Key, Size, NvGpuBufferType.Texture))
{ {
Gpu.Renderer.Texture.Bind(Tag, TexIndex); Gpu.Renderer.Texture.Bind(Key, TexIndex);
HasCachedTexture = true; HasCachedTexture = true;
} }
@ -311,10 +313,10 @@ namespace Ryujinx.HLE.Gpu
{ {
byte[] Data = TextureFactory.GetTextureData(Vmm, TicPosition); byte[] Data = TextureFactory.GetTextureData(Vmm, TicPosition);
Gpu.Renderer.Texture.Create(Tag, Data, NewTexture); Gpu.Renderer.Texture.Create(Key, Data, NewTexture);
} }
Gpu.Renderer.Texture.Bind(Tag, TexIndex); Gpu.Renderer.Texture.Bind(Key, TexIndex);
} }
Gpu.Renderer.Texture.SetSampler(Sampler); Gpu.Renderer.Texture.SetSampler(Sampler);

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
enum NvGpuEngine3dReg enum NvGpuEngine3dReg
{ {

View file

@ -1,6 +1,8 @@
using Ryujinx.HLE.Gpu.Memory;
using Ryujinx.HLE.Gpu.Texture;
using System.Collections.Generic; using System.Collections.Generic;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
class NvGpuEngineDma : INvGpuEngine class NvGpuEngineDma : INvGpuEngine
{ {

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
enum NvGpuEngineDmaReg enum NvGpuEngineDmaReg
{ {

View file

@ -1,6 +1,7 @@
using Ryujinx.HLE.Gpu.Memory;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
class NvGpuFifo class NvGpuFifo
{ {

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Engines
{ {
enum NvGpuFifoMeth enum NvGpuFifoMeth
{ {

View file

@ -1,4 +1,6 @@
namespace Ryujinx.HLE.Gpu using Ryujinx.HLE.Gpu.Memory;
namespace Ryujinx.HLE.Gpu.Engines
{ {
delegate void NvGpuMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry); delegate void NvGpuMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry);
} }

View file

@ -0,0 +1,11 @@
using System;
namespace Ryujinx.HLE.Gpu.Exceptions
{
class GpuException : Exception
{
public GpuException() : base() { }
public GpuException(string ExMsg) : base(ExMsg) { }
}
}

View file

@ -0,0 +1,12 @@
namespace Ryujinx.HLE.Gpu.Exceptions
{
static class GpuExceptionHelper
{
private const string CallCountExceeded = "Method call count exceeded the limit allowed per run!";
public static void ThrowCallCoundExceeded()
{
throw new GpuException(CallCountExceeded);
}
}
}

View file

@ -1,11 +0,0 @@
using System;
namespace Ryujinx.HLE.Gpu
{
class GpuMacroException : Exception
{
public GpuMacroException() : base() { }
public GpuMacroException(string ExMsg) : base(ExMsg) { }
}
}

View file

@ -1,7 +0,0 @@
namespace Ryujinx.HLE.Gpu
{
static class GpuMacroExceptionMsgs
{
public const string CallCountExceeded = "Method call count exceeded the limit allowed per run!";
}
}

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Memory
{ {
enum NvGpuBufferType enum NvGpuBufferType
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Memory
{ {
struct NvGpuPBEntry struct NvGpuPBEntry
{ {

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Memory
{ {
static class NvGpuPushBuffer static class NvGpuPushBuffer
{ {

View file

@ -2,7 +2,7 @@ using ChocolArm64.Memory;
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using System.Collections.Concurrent; using System.Collections.Concurrent;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Memory
{ {
class NvGpuVmm : IAMemory, IGalMemory class NvGpuVmm : IAMemory, IGalMemory
{ {

View file

@ -2,7 +2,7 @@ using ChocolArm64.Memory;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Memory
{ {
class NvGpuVmmCache class NvGpuVmmCache
{ {

View file

@ -1,4 +1,5 @@
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using Ryujinx.HLE.Gpu.Engines;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu
{ {

View file

@ -1,6 +1,6 @@
using System; using System;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
class BlockLinearSwizzle : ISwizzle class BlockLinearSwizzle : ISwizzle
{ {

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
interface ISwizzle interface ISwizzle
{ {

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
class LinearSwizzle : ISwizzle class LinearSwizzle : ISwizzle
{ {

View file

@ -1,7 +1,8 @@
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using Ryujinx.HLE.Gpu.Memory;
using System; using System;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
static class TextureFactory static class TextureFactory
{ {
@ -61,7 +62,7 @@ namespace Ryujinx.HLE.Gpu
int Width = (Tic[4] & 0xffff) + 1; int Width = (Tic[4] & 0xffff) + 1;
int Height = (Tic[5] & 0xffff) + 1; int Height = (Tic[5] & 0xffff) + 1;
Texture Texture = new Texture( TextureInfo Texture = new TextureInfo(
TextureAddress, TextureAddress,
Width, Width,
Height, Height,

View file

@ -1,12 +1,13 @@
using ChocolArm64.Memory; using ChocolArm64.Memory;
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using Ryujinx.HLE.Gpu.Memory;
using System; using System;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
static class TextureHelper static class TextureHelper
{ {
public static ISwizzle GetSwizzle(Texture Texture, int Width, int Bpp) public static ISwizzle GetSwizzle(TextureInfo Texture, int Width, int Bpp)
{ {
switch (Texture.Swizzle) switch (Texture.Swizzle)
{ {

View file

@ -1,8 +1,8 @@
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
struct Texture struct TextureInfo
{ {
public long Position { get; private set; } public long Position { get; private set; }
@ -16,7 +16,7 @@ namespace Ryujinx.HLE.Gpu
public GalTextureFormat Format { get; private set; } public GalTextureFormat Format { get; private set; }
public Texture( public TextureInfo(
long Position, long Position,
int Width, int Width,
int Height) int Height)
@ -34,7 +34,7 @@ namespace Ryujinx.HLE.Gpu
Format = GalTextureFormat.A8B8G8R8; Format = GalTextureFormat.A8B8G8R8;
} }
public Texture( public TextureInfo(
long Position, long Position,
int Width, int Width,
int Height, int Height,

View file

@ -2,11 +2,11 @@ using ChocolArm64.Memory;
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using System; using System;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
static class TextureReader static class TextureReader
{ {
public static byte[] Read(IAMemory Memory, Texture Texture) public static byte[] Read(IAMemory Memory, TextureInfo Texture)
{ {
switch (Texture.Format) switch (Texture.Format)
{ {
@ -31,7 +31,7 @@ namespace Ryujinx.HLE.Gpu
throw new NotImplementedException(Texture.Format.ToString()); throw new NotImplementedException(Texture.Format.ToString());
} }
private unsafe static byte[] Read1Bpp(IAMemory Memory, Texture Texture) private unsafe static byte[] Read1Bpp(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -64,7 +64,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read5551(IAMemory Memory, Texture Texture) private unsafe static byte[] Read5551(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -102,7 +102,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read565(IAMemory Memory, Texture Texture) private unsafe static byte[] Read565(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -139,7 +139,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read2Bpp(IAMemory Memory, Texture Texture) private unsafe static byte[] Read2Bpp(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -172,7 +172,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read4Bpp(IAMemory Memory, Texture Texture) private unsafe static byte[] Read4Bpp(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -205,7 +205,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read8Bpp(IAMemory Memory, Texture Texture) private unsafe static byte[] Read8Bpp(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -238,7 +238,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read16Bpp(IAMemory Memory, Texture Texture) private unsafe static byte[] Read16Bpp(IAMemory Memory, TextureInfo Texture)
{ {
int Width = Texture.Width; int Width = Texture.Width;
int Height = Texture.Height; int Height = Texture.Height;
@ -273,7 +273,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read8Bpt4x4(IAMemory Memory, Texture Texture) private unsafe static byte[] Read8Bpt4x4(IAMemory Memory, TextureInfo Texture)
{ {
int Width = (Texture.Width + 3) / 4; int Width = (Texture.Width + 3) / 4;
int Height = (Texture.Height + 3) / 4; int Height = (Texture.Height + 3) / 4;
@ -306,7 +306,7 @@ namespace Ryujinx.HLE.Gpu
return Output; return Output;
} }
private unsafe static byte[] Read16Bpt4x4(IAMemory Memory, Texture Texture) private unsafe static byte[] Read16Bpt4x4(IAMemory Memory, TextureInfo Texture)
{ {
int Width = (Texture.Width + 3) / 4; int Width = (Texture.Width + 3) / 4;
int Height = (Texture.Height + 3) / 4; int Height = (Texture.Height + 3) / 4;

View file

@ -1,4 +1,4 @@
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
enum TextureSwizzle enum TextureSwizzle
{ {

View file

@ -2,16 +2,16 @@ using ChocolArm64.Memory;
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using System; using System;
namespace Ryujinx.HLE.Gpu namespace Ryujinx.HLE.Gpu.Texture
{ {
static class TextureWriter static class TextureWriter
{ {
public static void Write( public static void Write(
IAMemory Memory, IAMemory Memory,
Texture Texture, TextureInfo Texture,
byte[] Data, byte[] Data,
int Width, int Width,
int Height) int Height)
{ {
switch (Texture.Format) switch (Texture.Format)
{ {
@ -22,11 +22,11 @@ namespace Ryujinx.HLE.Gpu
} }
private unsafe static void Write4Bpp( private unsafe static void Write4Bpp(
IAMemory Memory, IAMemory Memory,
Texture Texture, TextureInfo Texture,
byte[] Data, byte[] Data,
int Width, int Width,
int Height) int Height)
{ {
ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4); ISwizzle Swizzle = TextureHelper.GetSwizzle(Texture, Width, 4);

View file

@ -1,5 +1,5 @@
using ChocolArm64.Memory; using ChocolArm64.Memory;
using Ryujinx.HLE.Gpu; using Ryujinx.HLE.Gpu.Memory;
using Ryujinx.HLE.Logging; using Ryujinx.HLE.Logging;
using Ryujinx.HLE.OsHle.Services.Nv.NvMap; using Ryujinx.HLE.OsHle.Services.Nv.NvMap;
using System; using System;

View file

@ -1,5 +1,5 @@
using ChocolArm64.Memory; using ChocolArm64.Memory;
using Ryujinx.HLE.Gpu; using Ryujinx.HLE.Gpu.Memory;
using Ryujinx.HLE.Logging; using Ryujinx.HLE.Logging;
using Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS; using Ryujinx.HLE.OsHle.Services.Nv.NvGpuAS;
using System; using System;

View file

@ -1,5 +1,5 @@
using ChocolArm64.Memory; using ChocolArm64.Memory;
using Ryujinx.HLE.Gpu; using Ryujinx.HLE.Gpu.Memory;
using Ryujinx.HLE.Logging; using Ryujinx.HLE.Logging;
using Ryujinx.HLE.OsHle.Utilities; using Ryujinx.HLE.OsHle.Utilities;
using System.Collections.Concurrent; using System.Collections.Concurrent;

View file

@ -1,5 +1,5 @@
using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Gal;
using Ryujinx.HLE.Gpu; using Ryujinx.HLE.Gpu.Texture;
using Ryujinx.HLE.Logging; using Ryujinx.HLE.Logging;
using Ryujinx.HLE.OsHle.Handles; using Ryujinx.HLE.OsHle.Handles;
using Ryujinx.HLE.OsHle.Services.Nv.NvMap; using Ryujinx.HLE.OsHle.Services.Nv.NvMap;
@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using static Ryujinx.HLE.OsHle.Services.Android.Parcel; using static Ryujinx.HLE.OsHle.Services.Android.Parcel;
namespace Ryujinx.HLE.OsHle.Services.Android namespace Ryujinx.HLE.OsHle.Services.Android
@ -353,7 +354,7 @@ namespace Ryujinx.HLE.OsHle.Services.Android
{ {
//Frame buffer is not set on the GPU registers, in this case //Frame buffer is not set on the GPU registers, in this case
//assume that the app is manually writing to it. //assume that the app is manually writing to it.
Texture Texture = new Texture(FbAddr, FbWidth, FbHeight); TextureInfo Texture = new TextureInfo(FbAddr, FbWidth, FbHeight);
byte[] Data = TextureReader.Read(Context.Memory, Texture); byte[] Data = TextureReader.Read(Context.Memory, Texture);

View file

@ -14,7 +14,7 @@ namespace Ryujinx
{ {
Console.Title = "Ryujinx Console"; Console.Title = "Ryujinx Console";
IGalRenderer Renderer = new OpenGLRenderer(); IGalRenderer Renderer = new OGLRenderer();
IAalOutput AudioOut = new OpenALAudioOut(); IAalOutput AudioOut = new OpenALAudioOut();