2019-12-28 23:45:33 +00:00
|
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.Graphics.GAL;
|
New shader cache implementation (#3194)
* New shader cache implementation
* Remove some debug code
* Take transform feedback varying count into account
* Create shader cache directory if it does not exist + fragment output map related fixes
* Remove debug code
* Only check texture descriptors if the constant buffer is bound
* Also check CPU VA on GetSpanMapped
* Remove more unused code and move cache related code
* XML docs + remove more unused methods
* Better codegen for TransformFeedbackDescriptor.AsSpan
* Support migration from old cache format, remove more unused code
Shader cache rebuild now also rewrites the shared toc and data files
* Fix migration error with BRX shaders
* Add a limit to the async translation queue
Avoid async translation threads not being able to keep up and the queue growing very large
* Re-create specialization state on recompile
This might be required if a new version of the shader translator requires more or less state, or if there is a bug related to the GPU state access
* Make shader cache more error resilient
* Add some missing XML docs and move GpuAccessor docs to the interface/use inheritdoc
* Address early PR feedback
* Fix rebase
* Remove IRenderer.CompileShader and IShader interface, replace with new ShaderSource struct passed to CreateProgram directly
* Handle some missing exceptions
* Make shader cache purge delete both old and new shader caches
* Register textures on new specialization state
* Translate and compile shaders in forward order (eliminates diffs due to different binding numbers)
* Limit in-flight shader compilation to the maximum number of compilation threads
* Replace ParallelDiskCacheLoader state changed event with a callback function
* Better handling for invalid constant buffer 1 data length
* Do not create the old cache directory structure if the old cache does not exist
* Constant buffer use should be per-stage. This change will invalidate existing new caches (file format version was incremented)
* Replace rectangle texture with just coordinate normalization
* Skip incompatible shaders that are missing texture information, instead of crashing
This is required if we, for example, support new texture instruction to the shader translator, and then they allow access to textures that were not accessed before. In this scenario, the old cache entry is no longer usable
* Fix coordinates normalization on cubemap textures
* Check if title ID is null before combining shader cache path
* More robust constant buffer address validation on spec state
* More robust constant buffer address validation on spec state (2)
* Regenerate shader cache with one stream, rather than one per shader.
* Only create shader cache directory during initialization
* Logging improvements
* Proper shader program disposal
* PR feedback, and add a comment on serialized structs
* XML docs for RegisterTexture
Co-authored-by: riperiperi <rhy3756547@hotmail.com>
2022-04-10 13:49:44 +00:00
|
|
|
|
using Ryujinx.Graphics.Shader;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.OpenGL
|
|
|
|
|
{
|
|
|
|
|
static class EnumConversion
|
|
|
|
|
{
|
|
|
|
|
public static TextureWrapMode Convert(this AddressMode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case AddressMode.Clamp:
|
|
|
|
|
return TextureWrapMode.Clamp;
|
|
|
|
|
case AddressMode.Repeat:
|
|
|
|
|
return TextureWrapMode.Repeat;
|
|
|
|
|
case AddressMode.MirrorClamp:
|
|
|
|
|
return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampExt;
|
|
|
|
|
case AddressMode.MirrorClampToEdge:
|
|
|
|
|
return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampToEdgeExt;
|
|
|
|
|
case AddressMode.MirrorClampToBorder:
|
|
|
|
|
return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampToBorderExt;
|
|
|
|
|
case AddressMode.ClampToBorder:
|
|
|
|
|
return TextureWrapMode.ClampToBorder;
|
|
|
|
|
case AddressMode.MirroredRepeat:
|
|
|
|
|
return TextureWrapMode.MirroredRepeat;
|
|
|
|
|
case AddressMode.ClampToEdge:
|
|
|
|
|
return TextureWrapMode.ClampToEdge;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AddressMode)} enum value: {mode}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return TextureWrapMode.Clamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static All Convert(this BlendFactor factor)
|
|
|
|
|
{
|
|
|
|
|
switch (factor)
|
|
|
|
|
{
|
|
|
|
|
case BlendFactor.Zero:
|
|
|
|
|
case BlendFactor.ZeroGl:
|
|
|
|
|
return All.Zero;
|
|
|
|
|
case BlendFactor.One:
|
|
|
|
|
case BlendFactor.OneGl:
|
|
|
|
|
return All.One;
|
|
|
|
|
case BlendFactor.SrcColor:
|
|
|
|
|
case BlendFactor.SrcColorGl:
|
|
|
|
|
return All.SrcColor;
|
|
|
|
|
case BlendFactor.OneMinusSrcColor:
|
|
|
|
|
case BlendFactor.OneMinusSrcColorGl:
|
|
|
|
|
return All.OneMinusSrcColor;
|
|
|
|
|
case BlendFactor.SrcAlpha:
|
|
|
|
|
case BlendFactor.SrcAlphaGl:
|
|
|
|
|
return All.SrcAlpha;
|
|
|
|
|
case BlendFactor.OneMinusSrcAlpha:
|
|
|
|
|
case BlendFactor.OneMinusSrcAlphaGl:
|
|
|
|
|
return All.OneMinusSrcAlpha;
|
|
|
|
|
case BlendFactor.DstAlpha:
|
|
|
|
|
case BlendFactor.DstAlphaGl:
|
|
|
|
|
return All.DstAlpha;
|
|
|
|
|
case BlendFactor.OneMinusDstAlpha:
|
|
|
|
|
case BlendFactor.OneMinusDstAlphaGl:
|
|
|
|
|
return All.OneMinusDstAlpha;
|
|
|
|
|
case BlendFactor.DstColor:
|
|
|
|
|
case BlendFactor.DstColorGl:
|
|
|
|
|
return All.DstColor;
|
|
|
|
|
case BlendFactor.OneMinusDstColor:
|
|
|
|
|
case BlendFactor.OneMinusDstColorGl:
|
|
|
|
|
return All.OneMinusDstColor;
|
|
|
|
|
case BlendFactor.SrcAlphaSaturate:
|
|
|
|
|
case BlendFactor.SrcAlphaSaturateGl:
|
|
|
|
|
return All.SrcAlphaSaturate;
|
|
|
|
|
case BlendFactor.Src1Color:
|
|
|
|
|
case BlendFactor.Src1ColorGl:
|
|
|
|
|
return All.Src1Color;
|
|
|
|
|
case BlendFactor.OneMinusSrc1Color:
|
|
|
|
|
case BlendFactor.OneMinusSrc1ColorGl:
|
|
|
|
|
return All.OneMinusSrc1Color;
|
|
|
|
|
case BlendFactor.Src1Alpha:
|
|
|
|
|
case BlendFactor.Src1AlphaGl:
|
|
|
|
|
return All.Src1Alpha;
|
|
|
|
|
case BlendFactor.OneMinusSrc1Alpha:
|
|
|
|
|
case BlendFactor.OneMinusSrc1AlphaGl:
|
|
|
|
|
return All.OneMinusSrc1Alpha;
|
|
|
|
|
case BlendFactor.ConstantColor:
|
|
|
|
|
return All.ConstantColor;
|
|
|
|
|
case BlendFactor.OneMinusConstantColor:
|
|
|
|
|
return All.OneMinusConstantColor;
|
|
|
|
|
case BlendFactor.ConstantAlpha:
|
|
|
|
|
return All.ConstantAlpha;
|
|
|
|
|
case BlendFactor.OneMinusConstantAlpha:
|
|
|
|
|
return All.OneMinusConstantAlpha;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(BlendFactor)} enum value: {factor}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return All.Zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static BlendEquationMode Convert(this BlendOp op)
|
|
|
|
|
{
|
|
|
|
|
switch (op)
|
|
|
|
|
{
|
|
|
|
|
case BlendOp.Add:
|
|
|
|
|
case BlendOp.AddGl:
|
|
|
|
|
return BlendEquationMode.FuncAdd;
|
|
|
|
|
case BlendOp.Minimum:
|
|
|
|
|
case BlendOp.MinimumGl:
|
|
|
|
|
return BlendEquationMode.Min;
|
|
|
|
|
case BlendOp.Maximum:
|
|
|
|
|
case BlendOp.MaximumGl:
|
|
|
|
|
return BlendEquationMode.Max;
|
2020-10-13 03:45:41 +00:00
|
|
|
|
case BlendOp.Subtract:
|
|
|
|
|
case BlendOp.SubtractGl:
|
|
|
|
|
return BlendEquationMode.FuncSubtract;
|
|
|
|
|
case BlendOp.ReverseSubtract:
|
|
|
|
|
case BlendOp.ReverseSubtractGl:
|
|
|
|
|
return BlendEquationMode.FuncReverseSubtract;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(BlendOp)} enum value: {op}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return BlendEquationMode.FuncAdd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TextureCompareMode Convert(this CompareMode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case CompareMode.None:
|
|
|
|
|
return TextureCompareMode.None;
|
|
|
|
|
case CompareMode.CompareRToTexture:
|
|
|
|
|
return TextureCompareMode.CompareRToTexture;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(CompareMode)} enum value: {mode}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return TextureCompareMode.None;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static All Convert(this CompareOp op)
|
|
|
|
|
{
|
|
|
|
|
switch (op)
|
|
|
|
|
{
|
|
|
|
|
case CompareOp.Never:
|
|
|
|
|
case CompareOp.NeverGl:
|
|
|
|
|
return All.Never;
|
|
|
|
|
case CompareOp.Less:
|
|
|
|
|
case CompareOp.LessGl:
|
|
|
|
|
return All.Less;
|
|
|
|
|
case CompareOp.Equal:
|
|
|
|
|
case CompareOp.EqualGl:
|
|
|
|
|
return All.Equal;
|
|
|
|
|
case CompareOp.LessOrEqual:
|
|
|
|
|
case CompareOp.LessOrEqualGl:
|
|
|
|
|
return All.Lequal;
|
|
|
|
|
case CompareOp.Greater:
|
|
|
|
|
case CompareOp.GreaterGl:
|
|
|
|
|
return All.Greater;
|
|
|
|
|
case CompareOp.NotEqual:
|
|
|
|
|
case CompareOp.NotEqualGl:
|
|
|
|
|
return All.Notequal;
|
|
|
|
|
case CompareOp.GreaterOrEqual:
|
|
|
|
|
case CompareOp.GreaterOrEqualGl:
|
|
|
|
|
return All.Gequal;
|
|
|
|
|
case CompareOp.Always:
|
|
|
|
|
case CompareOp.AlwaysGl:
|
|
|
|
|
return All.Always;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(CompareOp)} enum value: {op}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return All.Never;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ClipDepthMode Convert(this DepthMode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case DepthMode.MinusOneToOne:
|
|
|
|
|
return ClipDepthMode.NegativeOneToOne;
|
|
|
|
|
case DepthMode.ZeroToOne:
|
|
|
|
|
return ClipDepthMode.ZeroToOne;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(DepthMode)} enum value: {mode}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return ClipDepthMode.NegativeOneToOne;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static All Convert(this DepthStencilMode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case DepthStencilMode.Depth:
|
2020-01-31 03:42:03 +00:00
|
|
|
|
return All.DepthComponent;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
case DepthStencilMode.Stencil:
|
2020-01-31 03:42:03 +00:00
|
|
|
|
return All.StencilIndex;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(DepthStencilMode)} enum value: {mode}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return All.Depth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static CullFaceMode Convert(this Face face)
|
|
|
|
|
{
|
|
|
|
|
switch (face)
|
|
|
|
|
{
|
|
|
|
|
case Face.Back:
|
|
|
|
|
return CullFaceMode.Back;
|
|
|
|
|
case Face.Front:
|
|
|
|
|
return CullFaceMode.Front;
|
|
|
|
|
case Face.FrontAndBack:
|
|
|
|
|
return CullFaceMode.FrontAndBack;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(Face)} enum value: {face}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return CullFaceMode.Back;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FrontFaceDirection Convert(this FrontFace frontFace)
|
|
|
|
|
{
|
|
|
|
|
switch (frontFace)
|
|
|
|
|
{
|
|
|
|
|
case FrontFace.Clockwise:
|
|
|
|
|
return FrontFaceDirection.Cw;
|
|
|
|
|
case FrontFace.CounterClockwise:
|
|
|
|
|
return FrontFaceDirection.Ccw;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(FrontFace)} enum value: {frontFace}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return FrontFaceDirection.Cw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DrawElementsType Convert(this IndexType type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case IndexType.UByte:
|
|
|
|
|
return DrawElementsType.UnsignedByte;
|
|
|
|
|
case IndexType.UShort:
|
|
|
|
|
return DrawElementsType.UnsignedShort;
|
|
|
|
|
case IndexType.UInt:
|
|
|
|
|
return DrawElementsType.UnsignedInt;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(IndexType)} enum value: {type}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return DrawElementsType.UnsignedByte;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TextureMagFilter Convert(this MagFilter filter)
|
|
|
|
|
{
|
|
|
|
|
switch (filter)
|
|
|
|
|
{
|
|
|
|
|
case MagFilter.Nearest:
|
|
|
|
|
return TextureMagFilter.Nearest;
|
|
|
|
|
case MagFilter.Linear:
|
|
|
|
|
return TextureMagFilter.Linear;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(MagFilter)} enum value: {filter}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return TextureMagFilter.Nearest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TextureMinFilter Convert(this MinFilter filter)
|
|
|
|
|
{
|
|
|
|
|
switch (filter)
|
|
|
|
|
{
|
|
|
|
|
case MinFilter.Nearest:
|
|
|
|
|
return TextureMinFilter.Nearest;
|
|
|
|
|
case MinFilter.Linear:
|
|
|
|
|
return TextureMinFilter.Linear;
|
|
|
|
|
case MinFilter.NearestMipmapNearest:
|
|
|
|
|
return TextureMinFilter.NearestMipmapNearest;
|
|
|
|
|
case MinFilter.LinearMipmapNearest:
|
|
|
|
|
return TextureMinFilter.LinearMipmapNearest;
|
|
|
|
|
case MinFilter.NearestMipmapLinear:
|
|
|
|
|
return TextureMinFilter.NearestMipmapLinear;
|
|
|
|
|
case MinFilter.LinearMipmapLinear:
|
|
|
|
|
return TextureMinFilter.LinearMipmapLinear;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(MinFilter)} enum value: {filter}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return TextureMinFilter.Nearest;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 21:38:04 +00:00
|
|
|
|
public static OpenTK.Graphics.OpenGL.PolygonMode Convert(this GAL.PolygonMode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode)
|
|
|
|
|
{
|
|
|
|
|
case GAL.PolygonMode.Point:
|
|
|
|
|
return OpenTK.Graphics.OpenGL.PolygonMode.Point;
|
|
|
|
|
case GAL.PolygonMode.Line:
|
|
|
|
|
return OpenTK.Graphics.OpenGL.PolygonMode.Line;
|
|
|
|
|
case GAL.PolygonMode.Fill:
|
|
|
|
|
return OpenTK.Graphics.OpenGL.PolygonMode.Fill;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(GAL.PolygonMode)} enum value: {mode}.");
|
|
|
|
|
|
|
|
|
|
return OpenTK.Graphics.OpenGL.PolygonMode.Fill;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-28 23:45:33 +00:00
|
|
|
|
public static PrimitiveType Convert(this PrimitiveTopology topology)
|
|
|
|
|
{
|
|
|
|
|
switch (topology)
|
|
|
|
|
{
|
|
|
|
|
case PrimitiveTopology.Points:
|
|
|
|
|
return PrimitiveType.Points;
|
|
|
|
|
case PrimitiveTopology.Lines:
|
|
|
|
|
return PrimitiveType.Lines;
|
|
|
|
|
case PrimitiveTopology.LineLoop:
|
|
|
|
|
return PrimitiveType.LineLoop;
|
|
|
|
|
case PrimitiveTopology.LineStrip:
|
|
|
|
|
return PrimitiveType.LineStrip;
|
|
|
|
|
case PrimitiveTopology.Triangles:
|
|
|
|
|
return PrimitiveType.Triangles;
|
|
|
|
|
case PrimitiveTopology.TriangleStrip:
|
|
|
|
|
return PrimitiveType.TriangleStrip;
|
|
|
|
|
case PrimitiveTopology.TriangleFan:
|
|
|
|
|
return PrimitiveType.TriangleFan;
|
|
|
|
|
case PrimitiveTopology.Quads:
|
|
|
|
|
return PrimitiveType.Quads;
|
|
|
|
|
case PrimitiveTopology.QuadStrip:
|
|
|
|
|
return PrimitiveType.QuadStrip;
|
|
|
|
|
case PrimitiveTopology.Polygon:
|
2022-11-28 22:18:22 +00:00
|
|
|
|
return PrimitiveType.TriangleFan;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
case PrimitiveTopology.LinesAdjacency:
|
|
|
|
|
return PrimitiveType.LinesAdjacency;
|
|
|
|
|
case PrimitiveTopology.LineStripAdjacency:
|
|
|
|
|
return PrimitiveType.LineStripAdjacency;
|
|
|
|
|
case PrimitiveTopology.TrianglesAdjacency:
|
|
|
|
|
return PrimitiveType.TrianglesAdjacency;
|
|
|
|
|
case PrimitiveTopology.TriangleStripAdjacency:
|
|
|
|
|
return PrimitiveType.TriangleStripAdjacency;
|
|
|
|
|
case PrimitiveTopology.Patches:
|
|
|
|
|
return PrimitiveType.Patches;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(PrimitiveTopology)} enum value: {topology}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return PrimitiveType.Points;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-15 03:01:10 +00:00
|
|
|
|
public static TransformFeedbackPrimitiveType ConvertToTfType(this PrimitiveTopology topology)
|
|
|
|
|
{
|
|
|
|
|
switch (topology)
|
|
|
|
|
{
|
|
|
|
|
case PrimitiveTopology.Points:
|
|
|
|
|
return TransformFeedbackPrimitiveType.Points;
|
|
|
|
|
case PrimitiveTopology.Lines:
|
|
|
|
|
case PrimitiveTopology.LineLoop:
|
|
|
|
|
case PrimitiveTopology.LineStrip:
|
|
|
|
|
case PrimitiveTopology.LinesAdjacency:
|
|
|
|
|
case PrimitiveTopology.LineStripAdjacency:
|
|
|
|
|
return TransformFeedbackPrimitiveType.Lines;
|
|
|
|
|
case PrimitiveTopology.Triangles:
|
|
|
|
|
case PrimitiveTopology.TriangleStrip:
|
|
|
|
|
case PrimitiveTopology.TriangleFan:
|
|
|
|
|
case PrimitiveTopology.TrianglesAdjacency:
|
|
|
|
|
case PrimitiveTopology.TriangleStripAdjacency:
|
|
|
|
|
return TransformFeedbackPrimitiveType.Triangles;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(PrimitiveTopology)} enum value: {topology}.");
|
2020-07-15 03:01:10 +00:00
|
|
|
|
|
|
|
|
|
return TransformFeedbackPrimitiveType.Points;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-29 17:41:50 +00:00
|
|
|
|
public static OpenTK.Graphics.OpenGL.StencilOp Convert(this GAL.StencilOp op)
|
2019-12-28 23:45:33 +00:00
|
|
|
|
{
|
|
|
|
|
switch (op)
|
|
|
|
|
{
|
2019-12-29 17:41:50 +00:00
|
|
|
|
case GAL.StencilOp.Keep:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.KeepGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Keep;
|
|
|
|
|
case GAL.StencilOp.Zero:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.ZeroGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Zero;
|
|
|
|
|
case GAL.StencilOp.Replace:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.ReplaceGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Replace;
|
|
|
|
|
case GAL.StencilOp.IncrementAndClamp:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.IncrementAndClampGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Incr;
|
|
|
|
|
case GAL.StencilOp.DecrementAndClamp:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.DecrementAndClampGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Decr;
|
|
|
|
|
case GAL.StencilOp.Invert:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.InvertGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Invert;
|
|
|
|
|
case GAL.StencilOp.IncrementAndWrap:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.IncrementAndWrapGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.IncrWrap;
|
|
|
|
|
case GAL.StencilOp.DecrementAndWrap:
|
2022-05-05 19:16:58 +00:00
|
|
|
|
case GAL.StencilOp.DecrementAndWrapGl:
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.DecrWrap;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(GAL.StencilOp)} enum value: {op}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
2019-12-29 17:41:50 +00:00
|
|
|
|
return OpenTK.Graphics.OpenGL.StencilOp.Keep;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static All Convert(this SwizzleComponent swizzleComponent)
|
|
|
|
|
{
|
|
|
|
|
switch (swizzleComponent)
|
|
|
|
|
{
|
|
|
|
|
case SwizzleComponent.Zero:
|
|
|
|
|
return All.Zero;
|
|
|
|
|
case SwizzleComponent.One:
|
|
|
|
|
return All.One;
|
|
|
|
|
case SwizzleComponent.Red:
|
|
|
|
|
return All.Red;
|
|
|
|
|
case SwizzleComponent.Green:
|
|
|
|
|
return All.Green;
|
|
|
|
|
case SwizzleComponent.Blue:
|
|
|
|
|
return All.Blue;
|
|
|
|
|
case SwizzleComponent.Alpha:
|
|
|
|
|
return All.Alpha;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(SwizzleComponent)} enum value: {swizzleComponent}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return All.Zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ImageTarget ConvertToImageTarget(this Target target)
|
|
|
|
|
{
|
|
|
|
|
return (ImageTarget)target.Convert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TextureTarget Convert(this Target target)
|
|
|
|
|
{
|
|
|
|
|
switch (target)
|
|
|
|
|
{
|
|
|
|
|
case Target.Texture1D:
|
|
|
|
|
return TextureTarget.Texture1D;
|
|
|
|
|
case Target.Texture2D:
|
|
|
|
|
return TextureTarget.Texture2D;
|
|
|
|
|
case Target.Texture3D:
|
|
|
|
|
return TextureTarget.Texture3D;
|
|
|
|
|
case Target.Texture1DArray:
|
|
|
|
|
return TextureTarget.Texture1DArray;
|
|
|
|
|
case Target.Texture2DArray:
|
|
|
|
|
return TextureTarget.Texture2DArray;
|
|
|
|
|
case Target.Texture2DMultisample:
|
|
|
|
|
return TextureTarget.Texture2DMultisample;
|
2022-04-04 21:21:06 +00:00
|
|
|
|
case Target.Texture2DMultisampleArray:
|
|
|
|
|
return TextureTarget.Texture2DMultisampleArray;
|
2019-12-28 23:45:33 +00:00
|
|
|
|
case Target.Cubemap:
|
|
|
|
|
return TextureTarget.TextureCubeMap;
|
|
|
|
|
case Target.CubemapArray:
|
|
|
|
|
return TextureTarget.TextureCubeMapArray;
|
|
|
|
|
case Target.TextureBuffer:
|
|
|
|
|
return TextureTarget.TextureBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(Target)} enum value: {target}.");
|
2019-12-28 23:45:33 +00:00
|
|
|
|
|
|
|
|
|
return TextureTarget.Texture2D;
|
|
|
|
|
}
|
2020-05-27 23:03:07 +00:00
|
|
|
|
|
|
|
|
|
public static NvViewportSwizzle Convert(this ViewportSwizzle swizzle)
|
|
|
|
|
{
|
|
|
|
|
switch (swizzle)
|
|
|
|
|
{
|
|
|
|
|
case ViewportSwizzle.PositiveX:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzlePositiveXNv;
|
|
|
|
|
case ViewportSwizzle.PositiveY:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzlePositiveYNv;
|
|
|
|
|
case ViewportSwizzle.PositiveZ:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzlePositiveZNv;
|
|
|
|
|
case ViewportSwizzle.PositiveW:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzlePositiveWNv;
|
|
|
|
|
case ViewportSwizzle.NegativeX:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzleNegativeXNv;
|
|
|
|
|
case ViewportSwizzle.NegativeY:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzleNegativeYNv;
|
|
|
|
|
case ViewportSwizzle.NegativeZ:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzleNegativeZNv;
|
|
|
|
|
case ViewportSwizzle.NegativeW:
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzleNegativeWNv;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(ViewportSwizzle)} enum value: {swizzle}.");
|
2020-05-27 23:03:07 +00:00
|
|
|
|
|
|
|
|
|
return NvViewportSwizzle.ViewportSwizzlePositiveXNv;
|
|
|
|
|
}
|
2020-07-10 17:23:15 +00:00
|
|
|
|
|
|
|
|
|
public static All Convert(this LogicalOp op)
|
|
|
|
|
{
|
|
|
|
|
switch (op)
|
|
|
|
|
{
|
|
|
|
|
case LogicalOp.Clear:
|
|
|
|
|
return All.Clear;
|
|
|
|
|
case LogicalOp.And:
|
|
|
|
|
return All.And;
|
|
|
|
|
case LogicalOp.AndReverse:
|
|
|
|
|
return All.AndReverse;
|
|
|
|
|
case LogicalOp.Copy:
|
|
|
|
|
return All.Copy;
|
|
|
|
|
case LogicalOp.AndInverted:
|
|
|
|
|
return All.AndInverted;
|
|
|
|
|
case LogicalOp.Noop:
|
|
|
|
|
return All.Noop;
|
|
|
|
|
case LogicalOp.Xor:
|
|
|
|
|
return All.Xor;
|
|
|
|
|
case LogicalOp.Or:
|
|
|
|
|
return All.Or;
|
|
|
|
|
case LogicalOp.Nor:
|
|
|
|
|
return All.Nor;
|
|
|
|
|
case LogicalOp.Equiv:
|
|
|
|
|
return All.Equiv;
|
|
|
|
|
case LogicalOp.Invert:
|
|
|
|
|
return All.Invert;
|
|
|
|
|
case LogicalOp.OrReverse:
|
|
|
|
|
return All.OrReverse;
|
|
|
|
|
case LogicalOp.CopyInverted:
|
|
|
|
|
return All.CopyInverted;
|
|
|
|
|
case LogicalOp.OrInverted:
|
|
|
|
|
return All.OrInverted;
|
|
|
|
|
case LogicalOp.Nand:
|
|
|
|
|
return All.Nand;
|
|
|
|
|
case LogicalOp.Set:
|
|
|
|
|
return All.Set;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 23:32:53 +00:00
|
|
|
|
Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(LogicalOp)} enum value: {op}.");
|
2020-07-10 17:23:15 +00:00
|
|
|
|
|
|
|
|
|
return All.Never;
|
|
|
|
|
}
|
New shader cache implementation (#3194)
* New shader cache implementation
* Remove some debug code
* Take transform feedback varying count into account
* Create shader cache directory if it does not exist + fragment output map related fixes
* Remove debug code
* Only check texture descriptors if the constant buffer is bound
* Also check CPU VA on GetSpanMapped
* Remove more unused code and move cache related code
* XML docs + remove more unused methods
* Better codegen for TransformFeedbackDescriptor.AsSpan
* Support migration from old cache format, remove more unused code
Shader cache rebuild now also rewrites the shared toc and data files
* Fix migration error with BRX shaders
* Add a limit to the async translation queue
Avoid async translation threads not being able to keep up and the queue growing very large
* Re-create specialization state on recompile
This might be required if a new version of the shader translator requires more or less state, or if there is a bug related to the GPU state access
* Make shader cache more error resilient
* Add some missing XML docs and move GpuAccessor docs to the interface/use inheritdoc
* Address early PR feedback
* Fix rebase
* Remove IRenderer.CompileShader and IShader interface, replace with new ShaderSource struct passed to CreateProgram directly
* Handle some missing exceptions
* Make shader cache purge delete both old and new shader caches
* Register textures on new specialization state
* Translate and compile shaders in forward order (eliminates diffs due to different binding numbers)
* Limit in-flight shader compilation to the maximum number of compilation threads
* Replace ParallelDiskCacheLoader state changed event with a callback function
* Better handling for invalid constant buffer 1 data length
* Do not create the old cache directory structure if the old cache does not exist
* Constant buffer use should be per-stage. This change will invalidate existing new caches (file format version was incremented)
* Replace rectangle texture with just coordinate normalization
* Skip incompatible shaders that are missing texture information, instead of crashing
This is required if we, for example, support new texture instruction to the shader translator, and then they allow access to textures that were not accessed before. In this scenario, the old cache entry is no longer usable
* Fix coordinates normalization on cubemap textures
* Check if title ID is null before combining shader cache path
* More robust constant buffer address validation on spec state
* More robust constant buffer address validation on spec state (2)
* Regenerate shader cache with one stream, rather than one per shader.
* Only create shader cache directory during initialization
* Logging improvements
* Proper shader program disposal
* PR feedback, and add a comment on serialized structs
* XML docs for RegisterTexture
Co-authored-by: riperiperi <rhy3756547@hotmail.com>
2022-04-10 13:49:44 +00:00
|
|
|
|
|
|
|
|
|
public static ShaderType Convert(this ShaderStage stage)
|
|
|
|
|
{
|
|
|
|
|
return stage switch
|
|
|
|
|
{
|
|
|
|
|
ShaderStage.Compute => ShaderType.ComputeShader,
|
|
|
|
|
ShaderStage.Vertex => ShaderType.VertexShader,
|
|
|
|
|
ShaderStage.TessellationControl => ShaderType.TessControlShader,
|
|
|
|
|
ShaderStage.TessellationEvaluation => ShaderType.TessEvaluationShader,
|
|
|
|
|
ShaderStage.Geometry => ShaderType.GeometryShader,
|
|
|
|
|
ShaderStage.Fragment => ShaderType.FragmentShader,
|
|
|
|
|
_ => ShaderType.VertexShader
|
|
|
|
|
};
|
|
|
|
|
}
|
2019-12-28 23:45:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|