mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-02-21 00:23:36 +00:00
Shader specialization for new Vulkan required state (fixes remaining alpha test issues, vertex stretching on AMD on Crash Bandicoot, etc)
This commit is contained in:
parent
4648e37a31
commit
4f086b0ec9
7 changed files with 52 additions and 27 deletions
|
@ -1,4 +1,5 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Gpu.Engine.Types;
|
||||
using Ryujinx.Graphics.Gpu.Image;
|
||||
|
@ -1267,6 +1268,20 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
|||
/// <returns>Current GPU channel state</returns>
|
||||
private GpuChannelGraphicsState GetGraphicsState()
|
||||
{
|
||||
ref var vertexAttribState = ref _state.State.VertexAttribState;
|
||||
|
||||
Array32<AttributeType> attributeTypes = new Array32<AttributeType>();
|
||||
|
||||
for (int location = 0; location < attributeTypes.Length; location++)
|
||||
{
|
||||
attributeTypes[location] = vertexAttribState[location].UnpackType() switch
|
||||
{
|
||||
3 => AttributeType.Sint,
|
||||
4 => AttributeType.Uint,
|
||||
_ => AttributeType.Float
|
||||
};
|
||||
}
|
||||
|
||||
return new GpuChannelGraphicsState(
|
||||
_state.State.EarlyZForce,
|
||||
_drawState.Topology,
|
||||
|
@ -1277,7 +1292,8 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
|
|||
_state.State.PointSize,
|
||||
_state.State.AlphaTestEnable,
|
||||
_state.State.AlphaTestFunc,
|
||||
_state.State.AlphaTestRef);
|
||||
_state.State.AlphaTestRef,
|
||||
ref attributeTypes);
|
||||
}
|
||||
|
||||
private DepthMode GetDepthMode()
|
||||
|
|
|
@ -163,6 +163,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
|
|||
_ => PrimitiveTopology.Points
|
||||
};
|
||||
|
||||
Array32<AttributeType> attributeTypes = default;
|
||||
|
||||
GpuChannelGraphicsState graphicsState = new GpuChannelGraphicsState(
|
||||
accessorHeader.StateFlags.HasFlag(GuestGpuStateFlags.EarlyZForce),
|
||||
topology,
|
||||
|
@ -173,7 +175,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache
|
|||
1f,
|
||||
false,
|
||||
CompareOp.Always,
|
||||
0f);
|
||||
0f,
|
||||
ref attributeTypes);
|
||||
|
||||
TransformFeedbackDescriptor[] tfdNew = null;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
{
|
||||
private readonly GpuChannel _channel;
|
||||
private readonly GpuAccessorState _state;
|
||||
private readonly AttributeType[] _attributeTypes;
|
||||
private readonly int _stageIndex;
|
||||
private readonly bool _compute;
|
||||
private readonly bool _isVulkan;
|
||||
|
@ -26,19 +25,16 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <param name="context">GPU context</param>
|
||||
/// <param name="channel">GPU channel</param>
|
||||
/// <param name="state">Current GPU state</param>
|
||||
/// <param name="attributeTypes">Type of the vertex attributes consumed by the shader</param>
|
||||
/// <param name="stageIndex">Graphics shader stage index (0 = Vertex, 4 = Fragment)</param>
|
||||
public GpuAccessor(
|
||||
GpuContext context,
|
||||
GpuChannel channel,
|
||||
GpuAccessorState state,
|
||||
AttributeType[] attributeTypes,
|
||||
int stageIndex) : base(context, state.ResourceCounts, stageIndex)
|
||||
{
|
||||
_isVulkan = context.Capabilities.Api == TargetApi.Vulkan;
|
||||
_channel = channel;
|
||||
_state = state;
|
||||
_attributeTypes = attributeTypes;
|
||||
_stageIndex = stageIndex;
|
||||
}
|
||||
|
||||
|
@ -108,12 +104,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <inheritdoc/>
|
||||
public AttributeType QueryAttributeType(int location)
|
||||
{
|
||||
if (_attributeTypes != null)
|
||||
{
|
||||
return _attributeTypes[location];
|
||||
}
|
||||
|
||||
return AttributeType.Float;
|
||||
return _state.GraphicsState.AttributeTypes[location];
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Graphics.GAL;
|
||||
using Ryujinx.Graphics.Gpu.Engine.Threed;
|
||||
using Ryujinx.Graphics.Shader;
|
||||
|
||||
namespace Ryujinx.Graphics.Gpu.Shader
|
||||
{
|
||||
|
@ -60,6 +62,11 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// </summary>
|
||||
public readonly float AlphaTestReference;
|
||||
|
||||
/// <summary>
|
||||
/// Type of the vertex attributes consumed by the shader.
|
||||
/// </summary>
|
||||
public Array32<AttributeType> AttributeTypes;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new GPU graphics state.
|
||||
/// </summary>
|
||||
|
@ -73,6 +80,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
/// <param name="alphaTestEnable">Indicates whenever alpha test is enabled</param>
|
||||
/// <param name="alphaTestCompare">When alpha test is enabled, indicates the comparison that decides if the fragment is discarded</param>
|
||||
/// <param name="alphaTestReference">When alpha test is enabled, indicates the value to compare with the fragment output alpha</param>
|
||||
/// <param name="attributeTypes">Type of the vertex attributes consumed by the shader</param>
|
||||
public GpuChannelGraphicsState(
|
||||
bool earlyZForce,
|
||||
PrimitiveTopology topology,
|
||||
|
@ -83,7 +91,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
float pointSize,
|
||||
bool alphaTestEnable,
|
||||
CompareOp alphaTestCompare,
|
||||
float alphaTestReference)
|
||||
float alphaTestReference,
|
||||
ref Array32<AttributeType> attributeTypes)
|
||||
{
|
||||
EarlyZForce = earlyZForce;
|
||||
Topology = topology;
|
||||
|
@ -95,6 +104,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
AlphaTestEnable = alphaTestEnable;
|
||||
AlphaTestCompare = alphaTestCompare;
|
||||
AlphaTestReference = alphaTestReference;
|
||||
AttributeTypes = attributeTypes;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -305,18 +305,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
return gpShaders;
|
||||
}
|
||||
|
||||
AttributeType[] attributeTypes = new AttributeType[32];
|
||||
|
||||
for (int location = 0; location < attributeTypes.Length; location++)
|
||||
{
|
||||
attributeTypes[location] = state.VertexAttribState[location].UnpackType() switch
|
||||
{
|
||||
3 => AttributeType.Sint,
|
||||
4 => AttributeType.Uint,
|
||||
_ => AttributeType.Float
|
||||
};
|
||||
}
|
||||
|
||||
TransformFeedbackDescriptor[] transformFeedbackDescriptors = GetTransformFeedbackDescriptors(ref state);
|
||||
|
||||
ShaderSpecializationState specState = new ShaderSpecializationState(graphicsState, transformFeedbackDescriptors);
|
||||
|
@ -335,7 +323,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
|
||||
if (gpuVa != 0)
|
||||
{
|
||||
GpuAccessor gpuAccessor = new GpuAccessor(_context, channel, gpuAccessorState, attributeTypes, stageIndex);
|
||||
GpuAccessor gpuAccessor = new GpuAccessor(_context, channel, gpuAccessorState, stageIndex);
|
||||
TranslatorContext currentStage = DecodeGraphicsShader(gpuAccessor, api, DefaultFlags, gpuVa);
|
||||
|
||||
if (nextStage != null)
|
||||
|
|
|
@ -455,6 +455,23 @@ namespace Ryujinx.Graphics.Gpu.Shader
|
|||
return false;
|
||||
}
|
||||
|
||||
if (graphicsState.DepthMode != GraphicsState.DepthMode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (graphicsState.AlphaTestEnable != GraphicsState.AlphaTestEnable ||
|
||||
graphicsState.AlphaTestCompare != GraphicsState.AlphaTestCompare ||
|
||||
graphicsState.AlphaTestReference != GraphicsState.AlphaTestReference)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!graphicsState.AttributeTypes.ToSpan().SequenceEqual(GraphicsState.AttributeTypes.ToSpan()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Matches(channel, poolState, checkTextures, isCompute: false);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ using System;
|
|||
|
||||
namespace Ryujinx.Graphics.Shader
|
||||
{
|
||||
public enum AttributeType
|
||||
public enum AttributeType : byte
|
||||
{
|
||||
Float,
|
||||
Sint,
|
||||
|
|
Loading…
Reference in a new issue