2020-11-13 00:15:34 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2019-12-29 18:41:50 +01:00
|
|
|
namespace Ryujinx.Graphics.Shader.Translation
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
2020-07-30 07:53:23 +02:00
|
|
|
class ShaderConfig
|
2019-10-13 08:02:07 +02:00
|
|
|
{
|
|
|
|
public ShaderStage Stage { get; }
|
|
|
|
|
2021-01-29 04:38:51 +01:00
|
|
|
public bool GpPassthrough { get; }
|
|
|
|
|
2019-12-16 05:59:46 +01:00
|
|
|
public OutputTopology OutputTopology { get; }
|
|
|
|
|
|
|
|
public int MaxOutputVertices { get; }
|
|
|
|
|
2020-02-02 04:25:52 +01:00
|
|
|
public int LocalMemorySize { get; }
|
|
|
|
|
2020-04-03 02:20:47 +02:00
|
|
|
public ImapPixelType[] ImapTypes { get; }
|
|
|
|
|
|
|
|
public OmapTarget[] OmapTargets { get; }
|
|
|
|
public bool OmapSampleMask { get; }
|
|
|
|
public bool OmapDepth { get; }
|
2019-12-01 03:53:09 +01:00
|
|
|
|
2020-05-06 03:02:28 +02:00
|
|
|
public IGpuAccessor GpuAccessor { get; }
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2020-05-06 03:02:28 +02:00
|
|
|
public TranslationFlags Flags { get; }
|
2019-10-13 08:02:07 +02:00
|
|
|
|
2020-11-08 12:10:00 +01:00
|
|
|
public TranslationCounts Counts { get; }
|
|
|
|
|
2020-07-30 07:53:23 +02:00
|
|
|
public int Size { get; private set; }
|
|
|
|
|
2021-04-20 12:33:54 +02:00
|
|
|
public byte ClipDistancesWritten { get; private set; }
|
|
|
|
|
2020-07-30 07:53:23 +02:00
|
|
|
public FeatureFlags UsedFeatures { get; private set; }
|
2020-07-07 04:41:07 +02:00
|
|
|
|
2020-11-13 00:15:34 +01:00
|
|
|
public HashSet<int> TextureHandlesForCache { get; }
|
|
|
|
|
2020-11-08 12:10:00 +01:00
|
|
|
public ShaderConfig(IGpuAccessor gpuAccessor, TranslationFlags flags, TranslationCounts counts)
|
2019-12-16 05:59:46 +01:00
|
|
|
{
|
2020-11-13 00:15:34 +01:00
|
|
|
Stage = ShaderStage.Compute;
|
2021-01-29 04:38:51 +01:00
|
|
|
GpPassthrough = false;
|
2020-11-13 00:15:34 +01:00
|
|
|
OutputTopology = OutputTopology.PointList;
|
|
|
|
MaxOutputVertices = 0;
|
|
|
|
LocalMemorySize = 0;
|
|
|
|
ImapTypes = null;
|
|
|
|
OmapTargets = null;
|
|
|
|
OmapSampleMask = false;
|
|
|
|
OmapDepth = false;
|
|
|
|
GpuAccessor = gpuAccessor;
|
|
|
|
Flags = flags;
|
|
|
|
Size = 0;
|
|
|
|
UsedFeatures = FeatureFlags.None;
|
|
|
|
Counts = counts;
|
|
|
|
TextureHandlesForCache = new HashSet<int>();
|
2019-12-16 05:59:46 +01:00
|
|
|
}
|
|
|
|
|
2020-11-08 12:10:00 +01:00
|
|
|
public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationFlags flags, TranslationCounts counts)
|
2019-12-16 05:59:46 +01:00
|
|
|
{
|
2020-11-13 00:15:34 +01:00
|
|
|
Stage = header.Stage;
|
2021-01-29 04:38:51 +01:00
|
|
|
GpPassthrough = header.Stage == ShaderStage.Geometry && header.GpPassthrough;
|
2020-11-13 00:15:34 +01:00
|
|
|
OutputTopology = header.OutputTopology;
|
|
|
|
MaxOutputVertices = header.MaxOutputVertexCount;
|
|
|
|
LocalMemorySize = header.ShaderLocalMemoryLowSize + header.ShaderLocalMemoryHighSize;
|
|
|
|
ImapTypes = header.ImapTypes;
|
|
|
|
OmapTargets = header.OmapTargets;
|
|
|
|
OmapSampleMask = header.OmapSampleMask;
|
|
|
|
OmapDepth = header.OmapDepth;
|
|
|
|
GpuAccessor = gpuAccessor;
|
|
|
|
Flags = flags;
|
|
|
|
Size = 0;
|
|
|
|
UsedFeatures = FeatureFlags.None;
|
|
|
|
Counts = counts;
|
|
|
|
TextureHandlesForCache = new HashSet<int>();
|
2019-12-16 05:59:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int GetDepthRegister()
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (int index = 0; index < OmapTargets.Length; index++)
|
|
|
|
{
|
|
|
|
for (int component = 0; component < 4; component++)
|
|
|
|
{
|
|
|
|
if (OmapTargets[index].ComponentEnabled(component))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The depth register is always two registers after the last color output.
|
|
|
|
return count + 1;
|
|
|
|
}
|
2020-07-04 01:48:44 +02:00
|
|
|
|
|
|
|
public TextureFormat GetTextureFormat(int handle)
|
|
|
|
{
|
|
|
|
// When the formatted load extension is supported, we don't need to
|
|
|
|
// specify a format, we can just declare it without a format and the GPU will handle it.
|
|
|
|
if (GpuAccessor.QuerySupportsImageLoadFormatted())
|
|
|
|
{
|
|
|
|
return TextureFormat.Unknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
var format = GpuAccessor.QueryTextureFormat(handle);
|
|
|
|
|
|
|
|
if (format == TextureFormat.Unknown)
|
|
|
|
{
|
|
|
|
GpuAccessor.Log($"Unknown format for texture {handle}.");
|
|
|
|
|
|
|
|
format = TextureFormat.R8G8B8A8Unorm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
2020-07-30 07:53:23 +02:00
|
|
|
|
|
|
|
public void SizeAdd(int size)
|
|
|
|
{
|
|
|
|
Size += size;
|
|
|
|
}
|
|
|
|
|
2021-04-20 12:33:54 +02:00
|
|
|
public void SetClipDistanceWritten(int index)
|
|
|
|
{
|
|
|
|
ClipDistancesWritten |= (byte)(1 << index);
|
|
|
|
}
|
|
|
|
|
2020-07-30 07:53:23 +02:00
|
|
|
public void SetUsedFeature(FeatureFlags flags)
|
|
|
|
{
|
|
|
|
UsedFeatures |= flags;
|
|
|
|
}
|
2019-10-13 08:02:07 +02:00
|
|
|
}
|
|
|
|
}
|