aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.OpenGL
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Graphics.OpenGL')
-rw-r--r--Ryujinx.Graphics.OpenGL/EnumConversion.cs41
-rw-r--r--Ryujinx.Graphics.OpenGL/Pipeline.cs356
-rw-r--r--Ryujinx.Graphics.OpenGL/Renderer.cs6
-rw-r--r--Ryujinx.Graphics.OpenGL/Sampler.cs3
-rw-r--r--Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs4
-rw-r--r--Ryujinx.Graphics.OpenGL/TextureStorage.cs5
-rw-r--r--Ryujinx.Graphics.OpenGL/TextureView.cs7
-rw-r--r--Ryujinx.Graphics.OpenGL/VertexArray.cs2
8 files changed, 177 insertions, 247 deletions
diff --git a/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/Ryujinx.Graphics.OpenGL/EnumConversion.cs
index 99ed0404..fdd1f972 100644
--- a/Ryujinx.Graphics.OpenGL/EnumConversion.cs
+++ b/Ryujinx.Graphics.OpenGL/EnumConversion.cs
@@ -1,9 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
-using Ryujinx.Graphics.GAL.Blend;
-using Ryujinx.Graphics.GAL.Sampler;
-using Ryujinx.Graphics.GAL.Texture;
namespace Ryujinx.Graphics.OpenGL
{
@@ -334,31 +331,31 @@ namespace Ryujinx.Graphics.OpenGL
return PrimitiveType.Points;
}
- public static StencilOp Convert(this GAL.DepthStencil.StencilOp op)
+ public static OpenTK.Graphics.OpenGL.StencilOp Convert(this GAL.StencilOp op)
{
switch (op)
{
- case GAL.DepthStencil.StencilOp.Keep:
- return StencilOp.Keep;
- case GAL.DepthStencil.StencilOp.Zero:
- return StencilOp.Zero;
- case GAL.DepthStencil.StencilOp.Replace:
- return StencilOp.Replace;
- case GAL.DepthStencil.StencilOp.IncrementAndClamp:
- return StencilOp.Incr;
- case GAL.DepthStencil.StencilOp.DecrementAndClamp:
- return StencilOp.Decr;
- case GAL.DepthStencil.StencilOp.Invert:
- return StencilOp.Invert;
- case GAL.DepthStencil.StencilOp.IncrementAndWrap:
- return StencilOp.IncrWrap;
- case GAL.DepthStencil.StencilOp.DecrementAndWrap:
- return StencilOp.DecrWrap;
+ case GAL.StencilOp.Keep:
+ return OpenTK.Graphics.OpenGL.StencilOp.Keep;
+ case GAL.StencilOp.Zero:
+ return OpenTK.Graphics.OpenGL.StencilOp.Zero;
+ case GAL.StencilOp.Replace:
+ return OpenTK.Graphics.OpenGL.StencilOp.Replace;
+ case GAL.StencilOp.IncrementAndClamp:
+ return OpenTK.Graphics.OpenGL.StencilOp.Incr;
+ case GAL.StencilOp.DecrementAndClamp:
+ return OpenTK.Graphics.OpenGL.StencilOp.Decr;
+ case GAL.StencilOp.Invert:
+ return OpenTK.Graphics.OpenGL.StencilOp.Invert;
+ case GAL.StencilOp.IncrementAndWrap:
+ return OpenTK.Graphics.OpenGL.StencilOp.IncrWrap;
+ case GAL.StencilOp.DecrementAndWrap:
+ return OpenTK.Graphics.OpenGL.StencilOp.DecrWrap;
}
- Logger.PrintError(LogClass.Gpu, $"Invalid {nameof(GAL.DepthStencil.StencilOp)} enum value: {op}.");
+ Logger.PrintError(LogClass.Gpu, $"Invalid {nameof(GAL.StencilOp)} enum value: {op}.");
- return StencilOp.Keep;
+ return OpenTK.Graphics.OpenGL.StencilOp.Keep;
}
public static All Convert(this SwizzleComponent swizzleComponent)
diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs
index 64705862..c7d96edd 100644
--- a/Ryujinx.Graphics.OpenGL/Pipeline.cs
+++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs
@@ -1,10 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
-using Ryujinx.Graphics.GAL.Blend;
-using Ryujinx.Graphics.GAL.Color;
-using Ryujinx.Graphics.GAL.DepthStencil;
-using Ryujinx.Graphics.GAL.InputAssembler;
using Ryujinx.Graphics.Shader;
using System;
@@ -41,166 +37,6 @@ namespace Ryujinx.Graphics.OpenGL
_clipDepthMode = ClipDepthMode.NegativeOneToOne;
}
- public void BindBlendState(int index, BlendDescriptor blend)
- {
- if (!blend.Enable)
- {
- GL.Disable(IndexedEnableCap.Blend, index);
-
- return;
- }
-
- GL.BlendEquationSeparate(
- index,
- blend.ColorOp.Convert(),
- blend.AlphaOp.Convert());
-
- GL.BlendFuncSeparate(
- index,
- (BlendingFactorSrc) blend.ColorSrcFactor.Convert(),
- (BlendingFactorDest)blend.ColorDstFactor.Convert(),
- (BlendingFactorSrc) blend.AlphaSrcFactor.Convert(),
- (BlendingFactorDest)blend.AlphaDstFactor.Convert());
-
- GL.Enable(IndexedEnableCap.Blend, index);
- }
-
- public void BindImage(int index, ShaderStage stage, ITexture texture)
- {
- int unit = _program.GetImageUnit(stage, index);
-
- if (unit != -1 && texture != null)
- {
- TextureView view = (TextureView)texture;
-
- FormatInfo formatInfo = FormatTable.GetFormatInfo(view.Format);
-
- SizedInternalFormat format = (SizedInternalFormat)formatInfo.PixelInternalFormat;
-
- GL.BindImageTexture(
- unit,
- view.Handle,
- 0,
- true,
- 0,
- TextureAccess.ReadWrite,
- format);
- }
- }
-
- public void BindIndexBuffer(BufferRange buffer, IndexType type)
- {
- _elementsType = type.Convert();
-
- _indexBaseOffset = (IntPtr)buffer.Offset;
-
- EnsureVertexArray();
-
- _vertexArray.SetIndexBuffer((Buffer)buffer.Buffer);
- }
-
- public void BindProgram(IProgram program)
- {
- _program = (Program)program;
-
- _program.Bind();
- }
-
- public void BindSampler(int index, ShaderStage stage, ISampler sampler)
- {
- int unit = _program.GetTextureUnit(stage, index);
-
- if (unit != -1 && sampler != null)
- {
- ((Sampler)sampler).Bind(unit);
- }
- else if (unit == -1)
- {
- Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}.");
- }
- }
-
- public void BindTexture(int index, ShaderStage stage, ITexture texture)
- {
- int unit = _program.GetTextureUnit(stage, index);
-
- if (unit != -1 && texture != null)
- {
- if (unit == 0)
- {
- _unit0Texture = ((TextureView)texture);
- }
- else
- {
- ((TextureView)texture).Bind(unit);
- }
- }
- else if (unit == -1)
- {
- Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}.");
- }
- }
-
- public void BindStorageBuffer(int index, ShaderStage stage, BufferRange buffer)
- {
- BindBuffer(index, stage, buffer, isStorage: true);
- }
-
- public void BindUniformBuffer(int index, ShaderStage stage, BufferRange buffer)
- {
- BindBuffer(index, stage, buffer, isStorage: false);
- }
-
- private void BindBuffer(int index, ShaderStage stage, BufferRange buffer, bool isStorage)
- {
- int bindingPoint = isStorage
- ? _program.GetStorageBufferBindingPoint(stage, index)
- : _program.GetUniformBufferBindingPoint(stage, index);
-
- if (bindingPoint == -1)
- {
- Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}.");
-
- return;
- }
-
- BufferRangeTarget target = isStorage
- ? BufferRangeTarget.ShaderStorageBuffer
- : BufferRangeTarget.UniformBuffer;
-
- if (buffer.Buffer == null)
- {
- GL.BindBufferRange(target, bindingPoint, 0, IntPtr.Zero, 0);
-
- return;
- }
-
- int bufferHandle = ((Buffer)buffer.Buffer).Handle;
-
- IntPtr bufferOffset = (IntPtr)buffer.Offset;
-
- GL.BindBufferRange(
- target,
- bindingPoint,
- bufferHandle,
- bufferOffset,
- buffer.Size);
- }
-
- public void BindVertexAttribs(VertexAttribDescriptor[] vertexAttribs)
- {
- EnsureVertexArray();
-
- _vertexArray.SetVertexAttributes(vertexAttribs);
- }
-
- public void BindVertexBuffers(VertexBufferDescriptor[] vertexBuffers)
- {
- EnsureVertexArray();
-
- _vertexArray.SetVertexBuffers(vertexBuffers);
- }
-
public void ClearRenderTargetColor(int index, uint componentMask, ColorF color)
{
GL.ColorMask(
@@ -217,43 +53,7 @@ namespace Ryujinx.Graphics.OpenGL
RestoreComponentMask(index);
}
- public void ClearRenderTargetColor(int index, uint componentMask, ColorSI color)
- {
- GL.ColorMask(
- index,
- (componentMask & 1u) != 0,
- (componentMask & 2u) != 0,
- (componentMask & 4u) != 0,
- (componentMask & 8u) != 0);
-
- int[] colors = new int[] { color.Red, color.Green, color.Blue, color.Alpha };
-
- GL.ClearBuffer(ClearBuffer.Color, index, colors);
-
- RestoreComponentMask(index);
- }
-
- public void ClearRenderTargetColor(int index, uint componentMask, ColorUI color)
- {
- GL.ColorMask(
- index,
- (componentMask & 1u) != 0,
- (componentMask & 2u) != 0,
- (componentMask & 4u) != 0,
- (componentMask & 8u) != 0);
-
- uint[] colors = new uint[] { color.Red, color.Green, color.Blue, color.Alpha };
-
- GL.ClearBuffer(ClearBuffer.Color, index, colors);
-
- RestoreComponentMask(index);
- }
-
- public void ClearRenderTargetDepthStencil(
- float depthValue,
- bool depthMask,
- int stencilValue,
- int stencilMask)
+ public void ClearRenderTargetDepthStencil(float depthValue, bool depthMask, int stencilValue, int stencilMask)
{
bool stencilMaskChanged =
stencilMask != 0 &&
@@ -295,7 +95,7 @@ namespace Ryujinx.Graphics.OpenGL
}
}
- public void Dispatch(int groupsX, int groupsY, int groupsZ)
+ public void DispatchCompute(int groupsX, int groupsY, int groupsZ)
{
if (!_program.IsLinked)
{
@@ -607,19 +407,33 @@ namespace Ryujinx.Graphics.OpenGL
}
}
- public void DrawIndirect(BufferRange buffer, ulong offset, int drawCount, int stride)
+ public void SetBlendColor(ColorF color)
{
-
+ GL.BlendColor(color.Red, color.Green, color.Blue, color.Alpha);
}
- public void DrawIndexedIndirect(BufferRange buffer, ulong offset, int drawCount, int stride)
+ public void SetBlendState(int index, BlendDescriptor blend)
{
+ if (!blend.Enable)
+ {
+ GL.Disable(IndexedEnableCap.Blend, index);
- }
+ return;
+ }
- public void SetBlendColor(ColorF color)
- {
- GL.BlendColor(color.Red, color.Green, color.Blue, color.Alpha);
+ GL.BlendEquationSeparate(
+ index,
+ blend.ColorOp.Convert(),
+ blend.AlphaOp.Convert());
+
+ GL.BlendFuncSeparate(
+ index,
+ (BlendingFactorSrc)blend.ColorSrcFactor.Convert(),
+ (BlendingFactorDest)blend.ColorDstFactor.Convert(),
+ (BlendingFactorSrc)blend.AlphaSrcFactor.Convert(),
+ (BlendingFactorDest)blend.AlphaDstFactor.Convert());
+
+ GL.Enable(IndexedEnableCap.Blend, index);
}
public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp)
@@ -701,6 +515,33 @@ namespace Ryujinx.Graphics.OpenGL
GL.FrontFace(frontFace.Convert());
}
+ public void SetImage(int index, ShaderStage stage, ITexture texture)
+ {
+ int unit = _program.GetImageUnit(stage, index);
+
+ if (unit != -1 && texture != null)
+ {
+ TextureView view = (TextureView)texture;
+
+ FormatInfo formatInfo = FormatTable.GetFormatInfo(view.Format);
+
+ SizedInternalFormat format = (SizedInternalFormat)formatInfo.PixelInternalFormat;
+
+ GL.BindImageTexture(unit, view.Handle, 0, true, 0, TextureAccess.ReadWrite, format);
+ }
+ }
+
+ public void SetIndexBuffer(BufferRange buffer, IndexType type)
+ {
+ _elementsType = type.Convert();
+
+ _indexBaseOffset = (IntPtr)buffer.Offset;
+
+ EnsureVertexArray();
+
+ _vertexArray.SetIndexBuffer((Buffer)buffer.Buffer);
+ }
+
public void SetPrimitiveRestart(bool enable, int index)
{
if (!enable)
@@ -720,6 +561,13 @@ namespace Ryujinx.Graphics.OpenGL
_primitiveType = topology.Convert();
}
+ public void SetProgram(IProgram program)
+ {
+ _program = (Program)program;
+
+ _program.Bind();
+ }
+
public void SetRenderTargetColorMasks(uint[] componentMasks)
{
_componentMasks = (uint[])componentMasks.Clone();
@@ -752,6 +600,20 @@ namespace Ryujinx.Graphics.OpenGL
UpdateDepthTest();
}
+ public void SetSampler(int index, ShaderStage stage, ISampler sampler)
+ {
+ int unit = _program.GetTextureUnit(stage, index);
+
+ if (unit != -1 && sampler != null)
+ {
+ ((Sampler)sampler).Bind(unit);
+ }
+ else if (unit == -1)
+ {
+ Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}.");
+ }
+ }
+
public void SetStencilTest(StencilTestDescriptor stencilTest)
{
if (!stencilTest.TestEnable)
@@ -794,6 +656,51 @@ namespace Ryujinx.Graphics.OpenGL
_stencilFrontMask = stencilTest.FrontMask;
}
+ public void SetStorageBuffer(int index, ShaderStage stage, BufferRange buffer)
+ {
+ SetBuffer(index, stage, buffer, isStorage: true);
+ }
+
+ public void SetTexture(int index, ShaderStage stage, ITexture texture)
+ {
+ int unit = _program.GetTextureUnit(stage, index);
+
+ if (unit != -1 && texture != null)
+ {
+ if (unit == 0)
+ {
+ _unit0Texture = ((TextureView)texture);
+ }
+ else
+ {
+ ((TextureView)texture).Bind(unit);
+ }
+ }
+ else if (unit == -1)
+ {
+ Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}.");
+ }
+ }
+
+ public void SetUniformBuffer(int index, ShaderStage stage, BufferRange buffer)
+ {
+ SetBuffer(index, stage, buffer, isStorage: false);
+ }
+
+ public void SetVertexAttribs(VertexAttribDescriptor[] vertexAttribs)
+ {
+ EnsureVertexArray();
+
+ _vertexArray.SetVertexAttributes(vertexAttribs);
+ }
+
+ public void SetVertexBuffers(VertexBufferDescriptor[] vertexBuffers)
+ {
+ EnsureVertexArray();
+
+ _vertexArray.SetVertexBuffers(vertexBuffers);
+ }
+
public void SetViewports(int first, Viewport[] viewports)
{
bool flipY = false;
@@ -848,6 +755,37 @@ namespace Ryujinx.Graphics.OpenGL
GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit);
}
+ private void SetBuffer(int index, ShaderStage stage, BufferRange buffer, bool isStorage)
+ {
+ int bindingPoint = isStorage
+ ? _program.GetStorageBufferBindingPoint(stage, index)
+ : _program.GetUniformBufferBindingPoint(stage, index);
+
+ if (bindingPoint == -1)
+ {
+ Logger.PrintError(LogClass.Gpu, $"Invalid binding point: {stage} {index}.");
+
+ return;
+ }
+
+ BufferRangeTarget target = isStorage
+ ? BufferRangeTarget.ShaderStorageBuffer
+ : BufferRangeTarget.UniformBuffer;
+
+ if (buffer.Buffer == null)
+ {
+ GL.BindBufferRange(target, bindingPoint, 0, IntPtr.Zero, 0);
+
+ return;
+ }
+
+ int bufferHandle = ((Buffer)buffer.Buffer).Handle;
+
+ IntPtr bufferOffset = (IntPtr)buffer.Offset;
+
+ GL.BindBufferRange(target, bindingPoint, bufferHandle, bufferOffset, buffer.Size);
+ }
+
private void SetOrigin(ClipOrigin origin)
{
if (_clipOrigin != origin)
diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs
index ac16a37f..7cb69a78 100644
--- a/Ryujinx.Graphics.OpenGL/Renderer.cs
+++ b/Ryujinx.Graphics.OpenGL/Renderer.cs
@@ -1,7 +1,5 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
-using Ryujinx.Graphics.GAL.Sampler;
-using Ryujinx.Graphics.GAL.Texture;
using Ryujinx.Graphics.Shader;
namespace Ryujinx.Graphics.OpenGL
@@ -10,9 +8,9 @@ namespace Ryujinx.Graphics.OpenGL
{
public IPipeline Pipeline { get; }
- private Counters _counters;
+ private readonly Counters _counters;
- private Window _window;
+ private readonly Window _window;
public IWindow Window => _window;
diff --git a/Ryujinx.Graphics.OpenGL/Sampler.cs b/Ryujinx.Graphics.OpenGL/Sampler.cs
index 9b9f09a1..674fc797 100644
--- a/Ryujinx.Graphics.OpenGL/Sampler.cs
+++ b/Ryujinx.Graphics.OpenGL/Sampler.cs
@@ -1,6 +1,5 @@
-using Ryujinx.Graphics.GAL;
-using Ryujinx.Graphics.GAL.Sampler;
using OpenTK.Graphics.OpenGL;
+using Ryujinx.Graphics.GAL;
namespace Ryujinx.Graphics.OpenGL
{
diff --git a/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs b/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs
index dae492d9..2597214a 100644
--- a/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs
+++ b/Ryujinx.Graphics.OpenGL/TextureCopyUnscaled.cs
@@ -1,6 +1,6 @@
-using Ryujinx.Common;
-using Ryujinx.Graphics.GAL.Texture;
using OpenTK.Graphics.OpenGL;
+using Ryujinx.Common;
+using Ryujinx.Graphics.GAL;
using System;
namespace Ryujinx.Graphics.OpenGL
diff --git a/Ryujinx.Graphics.OpenGL/TextureStorage.cs b/Ryujinx.Graphics.OpenGL/TextureStorage.cs
index 482189ca..ec40a487 100644
--- a/Ryujinx.Graphics.OpenGL/TextureStorage.cs
+++ b/Ryujinx.Graphics.OpenGL/TextureStorage.cs
@@ -1,7 +1,6 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
-using Ryujinx.Graphics.GAL.Texture;
namespace Ryujinx.Graphics.OpenGL
{
@@ -9,9 +8,9 @@ namespace Ryujinx.Graphics.OpenGL
{
public int Handle { get; private set; }
- private Renderer _renderer;
+ private readonly Renderer _renderer;
- private TextureCreateInfo _info;
+ private readonly TextureCreateInfo _info;
public Target Target => _info.Target;
diff --git a/Ryujinx.Graphics.OpenGL/TextureView.cs b/Ryujinx.Graphics.OpenGL/TextureView.cs
index 2fd23d4c..f533404b 100644
--- a/Ryujinx.Graphics.OpenGL/TextureView.cs
+++ b/Ryujinx.Graphics.OpenGL/TextureView.cs
@@ -1,6 +1,5 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
-using Ryujinx.Graphics.GAL.Texture;
using System;
namespace Ryujinx.Graphics.OpenGL
@@ -9,13 +8,13 @@ namespace Ryujinx.Graphics.OpenGL
{
public int Handle { get; private set; }
- private Renderer _renderer;
+ private readonly Renderer _renderer;
- private TextureStorage _parent;
+ private readonly TextureStorage _parent;
private TextureView _emulatedViewParent;
- private TextureCreateInfo _info;
+ private readonly TextureCreateInfo _info;
private int _firstLayer;
private int _firstLevel;
diff --git a/Ryujinx.Graphics.OpenGL/VertexArray.cs b/Ryujinx.Graphics.OpenGL/VertexArray.cs
index c3c37813..26e63364 100644
--- a/Ryujinx.Graphics.OpenGL/VertexArray.cs
+++ b/Ryujinx.Graphics.OpenGL/VertexArray.cs
@@ -1,5 +1,5 @@
using OpenTK.Graphics.OpenGL;
-using Ryujinx.Graphics.GAL.InputAssembler;
+using Ryujinx.Graphics.GAL;
using System;
namespace Ryujinx.Graphics.OpenGL