Only enable clip distance if written to on shader (#2217)

* Only enable clip distance if written to on shader

* Signal InstanceId use through FeatureFlags

* Shader cache version bump
This commit is contained in:
gdkchan 2021-04-20 07:33:54 -03:00 committed by GitHub
parent 89791ba68d
commit 4770cfa920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 79 additions and 23 deletions

View file

@ -39,6 +39,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
private bool _isAnyVbInstanced;
private bool _vsUsesInstanceId;
private byte _vsClipDistancesWritten;
private bool _forceShaderUpdate;
@ -993,7 +994,15 @@ namespace Ryujinx.Graphics.Gpu.Engine
ShaderBundle gs = ShaderCache.GetGraphicsShader(state, addresses);
_vsUsesInstanceId = gs.Shaders[0]?.Info.UsesInstanceId ?? false;
byte oldVsClipDistancesWritten = _vsClipDistancesWritten;
_vsUsesInstanceId = gs.Shaders[0]?.Info.UsesInstanceId ?? false;
_vsClipDistancesWritten = gs.Shaders[0]?.Info.ClipDistancesWritten ?? 0;
if (oldVsClipDistancesWritten != _vsClipDistancesWritten)
{
UpdateUserClipState(state);
}
int storageBufferBindingsCount = 0;
int uniformBufferBindingsCount = 0;
@ -1098,7 +1107,7 @@ namespace Ryujinx.Graphics.Gpu.Engine
/// <param name="state">Current GPU state</param>
private void UpdateUserClipState(GpuState state)
{
int clipMask = state.Get<int>(MethodOffset.ClipDistanceEnable);
int clipMask = state.Get<int>(MethodOffset.ClipDistanceEnable) & _vsClipDistancesWritten;
for (int i = 0; i < Constants.TotalClipDistances; ++i)
{

View file

@ -75,7 +75,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
programInfo.SBuffers.Count,
programInfo.Textures.Count,
programInfo.Images.Count,
programInfo.UsesInstanceId);
programInfo.UsesInstanceId,
programInfo.ClipDistancesWritten);
CBuffers = programInfo.CBuffers.ToArray();
SBuffers = programInfo.SBuffers.ToArray();
Textures = programInfo.Textures.ToArray();
@ -88,7 +89,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
/// <returns>A new <see cref="ShaderProgramInfo"/> from this instance</returns>
internal ShaderProgramInfo ToShaderProgramInfo()
{
return new ShaderProgramInfo(CBuffers, SBuffers, Textures, Images, Header.UsesInstanceId);
return new ShaderProgramInfo(CBuffers, SBuffers, Textures, Images, Header.UsesInstanceId, Header.ClipDistancesWritten);
}
/// <summary>

View file

@ -41,10 +41,15 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
[MarshalAs(UnmanagedType.I1)]
public bool InUse;
/// <summary>
/// Mask of clip distances that are written to on the shader.
/// </summary>
public byte ClipDistancesWritten;
/// <summary>
/// Reserved / unused.
/// </summary>
public short Reserved;
public byte Reserved;
/// <summary>
/// Create a new host shader cache entry header.
@ -54,14 +59,21 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache.Definition
/// <param name="texturesCount">Count of texture descriptors</param>
/// <param name="imagesCount">Count of image descriptors</param>
/// <param name="usesInstanceId">Set to true if the shader uses instance id</param>
public HostShaderCacheEntryHeader(int cBuffersCount, int sBuffersCount, int texturesCount, int imagesCount, bool usesInstanceId) : this()
public HostShaderCacheEntryHeader(
int cBuffersCount,
int sBuffersCount,
int texturesCount,
int imagesCount,
bool usesInstanceId,
byte clipDistancesWritten) : this()
{
CBuffersCount = cBuffersCount;
SBuffersCount = sBuffersCount;
TexturesCount = texturesCount;
ImagesCount = imagesCount;
UsesInstanceId = usesInstanceId;
InUse = true;
CBuffersCount = cBuffersCount;
SBuffersCount = sBuffersCount;
TexturesCount = texturesCount;
ImagesCount = imagesCount;
UsesInstanceId = usesInstanceId;
ClipDistancesWritten = clipDistancesWritten;
InUse = true;
}
}
}

View file

@ -35,7 +35,7 @@ namespace Ryujinx.Graphics.Gpu.Shader
/// <summary>
/// Version of the codegen (to be changed when codegen or guest format change).
/// </summary>
private const ulong ShaderCodeGenVersion = 2200;
private const ulong ShaderCodeGenVersion = 2217;
// Progress reporting helpers
private volatile int _shaderCount;