aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-07-28 18:30:08 -0300
committerGitHub <noreply@github.com>2020-07-28 18:30:08 -0300
commit43c13057da7726c324f2b5d674e5e1308eb1f6a7 (patch)
tree222d8bace4d35166aa9a0ca8d6ed121bec20b287
parent938c06c652ca15e4a5f776e434fa8304b4b43f0b (diff)
Implement alpha test using legacy functions (#1426)
-rw-r--r--Ryujinx.Graphics.GAL/IPipeline.cs4
-rw-r--r--Ryujinx.Graphics.Gpu/Engine/Methods.cs25
-rw-r--r--Ryujinx.Graphics.Gpu/State/MethodOffset.cs3
-rw-r--r--Ryujinx.Graphics.OpenGL/Pipeline.cs20
4 files changed, 39 insertions, 13 deletions
diff --git a/Ryujinx.Graphics.GAL/IPipeline.cs b/Ryujinx.Graphics.GAL/IPipeline.cs
index 83ccfc3d..8e8cd965 100644
--- a/Ryujinx.Graphics.GAL/IPipeline.cs
+++ b/Ryujinx.Graphics.GAL/IPipeline.cs
@@ -31,6 +31,8 @@ namespace Ryujinx.Graphics.GAL
void EndTransformFeedback();
+ void SetAlphaTest(bool enable, float reference, CompareOp op);
+
void SetBlendState(int index, BlendDescriptor blend);
void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp);
@@ -61,9 +63,7 @@ namespace Ryujinx.Graphics.GAL
void SetRasterizerDiscard(bool discard);
void SetRenderTargetScale(float scale);
-
void SetRenderTargetColorMasks(ReadOnlySpan<uint> componentMask);
-
void SetRenderTargets(ITexture[] colors, ITexture depthStencil);
void SetSampler(int index, ShaderStage stage, ISampler sampler);
diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs
index fbde0f0a..f8b6e43f 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs
@@ -164,6 +164,13 @@ namespace Ryujinx.Graphics.Gpu.Engine
UpdateDepthClampState(state);
}
+ if (state.QueryModified(MethodOffset.AlphaTestEnable,
+ MethodOffset.AlphaTestRef,
+ MethodOffset.AlphaTestFunc))
+ {
+ UpdateAlphaTestState(state);
+ }
+
if (state.QueryModified(MethodOffset.DepthTestEnable,
MethodOffset.DepthWriteEnable,
MethodOffset.DepthTestFunc))
@@ -372,7 +379,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
if (dsEnable)
{
var dsState = state.Get<RtDepthStencilState>(MethodOffset.RtDepthStencilState);
- var dsSize = state.Get<Size3D> (MethodOffset.RtDepthStencilSize);
+ var dsSize = state.Get<Size3D>(MethodOffset.RtDepthStencilSize);
depthStencil = TextureManager.FindOrCreateTexture(dsState, dsSize, samplesInX, samplesInY);
}
@@ -451,6 +458,18 @@ namespace Ryujinx.Graphics.Gpu.Engine
}
/// <summary>
+ /// Updates host alpha test state based on current GPU state.
+ /// </summary>
+ /// <param name="state">Current GPU state</param>
+ private void UpdateAlphaTestState(GpuState state)
+ {
+ _context.Renderer.Pipeline.SetAlphaTest(
+ state.Get<Boolean32>(MethodOffset.AlphaTestEnable),
+ state.Get<float>(MethodOffset.AlphaTestRef),
+ state.Get<CompareOp>(MethodOffset.AlphaTestFunc));
+ }
+
+ /// <summary>
/// Updates host depth test state based on current GPU state.
/// </summary>
/// <param name="state">Current GPU state</param>
@@ -577,8 +596,8 @@ namespace Ryujinx.Graphics.Gpu.Engine
/// <param name="state">Current GPU state</param>
private void UpdateStencilTestState(GpuState state)
{
- var backMasks = state.Get<StencilBackMasks> (MethodOffset.StencilBackMasks);
- var test = state.Get<StencilTestState> (MethodOffset.StencilTestState);
+ var backMasks = state.Get<StencilBackMasks>(MethodOffset.StencilBackMasks);
+ var test = state.Get<StencilTestState>(MethodOffset.StencilTestState);
var backTest = state.Get<StencilBackTestState>(MethodOffset.StencilBackTestState);
CompareOp backFunc;
diff --git a/Ryujinx.Graphics.Gpu/State/MethodOffset.cs b/Ryujinx.Graphics.Gpu/State/MethodOffset.cs
index 505e3d89..13b699f3 100644
--- a/Ryujinx.Graphics.Gpu/State/MethodOffset.cs
+++ b/Ryujinx.Graphics.Gpu/State/MethodOffset.cs
@@ -52,8 +52,11 @@ namespace Ryujinx.Graphics.Gpu.State
DepthTestEnable = 0x4b3,
BlendIndependent = 0x4b9,
DepthWriteEnable = 0x4ba,
+ AlphaTestEnable = 0x4bb,
VbElementU8 = 0x4c1,
DepthTestFunc = 0x4c3,
+ AlphaTestRef = 0x4c4,
+ AlphaTestFunc = 0x4c5,
BlendConstant = 0x4c7,
BlendStateCommon = 0x4cf,
BlendEnableCommon = 0x4d7,
diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs
index 4f3c2a29..69bd7844 100644
--- a/Ryujinx.Graphics.OpenGL/Pipeline.cs
+++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs
@@ -157,7 +157,6 @@ namespace Ryujinx.Graphics.OpenGL
if (!_program.IsLinked)
{
Logger.PrintDebug(LogClass.Gpu, "Dispatch error, shader not linked.");
-
return;
}
@@ -171,7 +170,6 @@ namespace Ryujinx.Graphics.OpenGL
if (!_program.IsLinked)
{
Logger.PrintDebug(LogClass.Gpu, "Draw error, shader not linked.");
-
return;
}
@@ -290,7 +288,6 @@ namespace Ryujinx.Graphics.OpenGL
if (!_program.IsLinked)
{
Logger.PrintDebug(LogClass.Gpu, "Draw error, shader not linked.");
-
return;
}
@@ -527,12 +524,23 @@ namespace Ryujinx.Graphics.OpenGL
_tfEnabled = false;
}
+ public void SetAlphaTest(bool enable, float reference, CompareOp op)
+ {
+ if (!enable)
+ {
+ GL.Disable(EnableCap.AlphaTest);
+ return;
+ }
+
+ GL.AlphaFunc((AlphaFunction)op.Convert(), reference);
+ GL.Enable(EnableCap.AlphaTest);
+ }
+
public void SetBlendState(int index, BlendDescriptor blend)
{
if (!blend.Enable)
{
GL.Disable(IndexedEnableCap.Blend, index);
-
return;
}
@@ -658,7 +666,6 @@ namespace Ryujinx.Graphics.OpenGL
if (!enable)
{
GL.Disable(EnableCap.CullFace);
-
return;
}
@@ -742,7 +749,6 @@ namespace Ryujinx.Graphics.OpenGL
if (!enable)
{
GL.Disable(EnableCap.PrimitiveRestart);
-
return;
}
@@ -874,7 +880,6 @@ namespace Ryujinx.Graphics.OpenGL
if (!stencilTest.TestEnable)
{
GL.Disable(EnableCap.StencilTest);
-
return;
}
@@ -1077,7 +1082,6 @@ namespace Ryujinx.Graphics.OpenGL
if (buffer.Handle == null)
{
GL.BindBufferRange(target, bindingPoint, 0, IntPtr.Zero, 0);
-
return;
}