1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-15 09:46:41 +00:00
Ryujinx/Ryujinx.Graphics.Shader/IGpuAccessor.cs
riperiperi 8fa248ceb4
Vulkan: Add workarounds for MoltenVK (#4202)
* Add MVK basics.

* Use appropriate output attribute types

* 4kb vertex alignment, bunch of fixes

* Add reduced shader precision mode for mvk.

* Disable ASTC on MVK for now

* Only request robustnes2 when it is available.

* It's just the one feature actually

* Add triangle fan conversion

* Allow NullDescriptor on MVK for some reason.

* Force safe blit on MoltenVK

* Use ASTC only when formats are all available.

* Disable multilevel 3d texture views

* Filter duplicate render targets (on backend)

* Add Automatic MoltenVK Configuration

* Do not create color attachment views with formats that are not RT compatible

* Make sure that the host format matches the vertex shader input types for invalid/unknown guest formats

* FIx rebase for Vertex Attrib State

* Fix 4b alignment for vertex

* Use asynchronous queue submits for MVK

* Ensure color clear shader has correct output type

* Update MoltenVK config

* Always use MoltenVK workarounds on MacOS

* Make MVK supersede all vendors

* Fix rebase

* Various fixes on rebase

* Get portability flags from extension

* Fix some minor rebasing issues

* Style change

* Use LibraryImport for MVKConfiguration

* Rename MoltenVK vendor to Apple

Intel and AMD GPUs on moltenvk report with the those vendors - only apple silicon reports with vendor 0x106B.

* Fix features2 rebase conflict

* Rename fragment output type

* Add missing check for fragment output types

Might have caused the crash in MK8

* Only do fragment output specialization on MoltenVK

* Avoid copy when passing capabilities

* Self feedback

* Address feedback

Co-authored-by: gdk <gab.dark.100@gmail.com>
Co-authored-by: nastys <nastys@users.noreply.github.com>
2023-01-13 01:31:21 +01:00

492 lines
17 KiB
C#

using System;
namespace Ryujinx.Graphics.Shader
{
/// <summary>
/// GPU state access interface.
/// </summary>
public interface IGpuAccessor
{
/// <summary>
/// Prints a log message.
/// </summary>
/// <param name="message">Message to print</param>
void Log(string message)
{
// No default log output.
}
/// <summary>
/// Reads data from the constant buffer 1.
/// </summary>
/// <param name="offset">Offset in bytes to read from</param>
/// <returns>Value at the given offset</returns>
uint ConstantBuffer1Read(int offset)
{
return 0;
}
/// <summary>
/// Gets a span of the specified memory location, containing shader code.
/// </summary>
/// <param name="address">GPU virtual address of the data</param>
/// <param name="minimumSize">Minimum size that the returned span may have</param>
/// <returns>Span of the memory location</returns>
ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize);
/// <summary>
/// Queries the alpha test comparison operator that is being used currently.
/// If alpha test is disabled, it should be set to <see cref="AlphaTestOp.Always"/>.
/// </summary>
/// <returns>Current alpha test comparison</returns>
AlphaTestOp QueryAlphaTestCompare()
{
return AlphaTestOp.Always;
}
/// <summary>
/// Queries the current alpha test reference value used by the comparison.
/// </summary>
/// <returns>Current alpha test reference value</returns>
float QueryAlphaTestReference()
{
return 0f;
}
/// <summary>
/// Queries the type of the vertex shader input attribute at the specified <paramref name="location"/>.
/// </summary>
/// <param name="location">Location of the input attribute</param>
/// <returns>Input type</returns>
AttributeType QueryAttributeType(int location)
{
return AttributeType.Float;
}
/// <summary>
/// Queries whenever the alpha-to-coverage dithering feature is enabled.
/// </summary>
/// <returns>True if the feature is enabled, false otherwise</returns>
bool QueryAlphaToCoverageDitherEnable()
{
return false;
}
/// <summary>
/// Queries the binding number of a constant buffer.
/// </summary>
/// <param name="index">Constant buffer index</param>
/// <returns>Binding number</returns>
int QueryBindingConstantBuffer(int index)
{
return index;
}
/// <summary>
/// Queries the binding number of a storage buffer.
/// </summary>
/// <param name="index">Storage buffer index</param>
/// <returns>Binding number</returns>
int QueryBindingStorageBuffer(int index)
{
return index;
}
/// <summary>
/// Queries the binding number of a texture.
/// </summary>
/// <param name="index">Texture index</param>
/// <param name="isBuffer">Indicates if the texture is a buffer texture</param>
/// <returns>Binding number</returns>
int QueryBindingTexture(int index, bool isBuffer)
{
return index;
}
/// <summary>
/// Queries the binding number of an image.
/// </summary>
/// <param name="index">Image index</param>
/// <param name="isBuffer">Indicates if the image is a buffer image</param>
/// <returns>Binding number</returns>
int QueryBindingImage(int index, bool isBuffer)
{
return index;
}
/// <summary>
/// Queries output type for fragment shaders.
/// </summary>
/// <param name="location">Location of the framgent output</param>
/// <returns>Output location</returns>
AttributeType QueryFragmentOutputType(int location)
{
return AttributeType.Float;
}
/// <summary>
/// Queries Local Size X for compute shaders.
/// </summary>
/// <returns>Local Size X</returns>
int QueryComputeLocalSizeX()
{
return 1;
}
/// <summary>
/// Queries Local Size Y for compute shaders.
/// </summary>
/// <returns>Local Size Y</returns>
int QueryComputeLocalSizeY()
{
return 1;
}
/// <summary>
/// Queries Local Size Z for compute shaders.
/// </summary>
/// <returns>Local Size Z</returns>
int QueryComputeLocalSizeZ()
{
return 1;
}
/// <summary>
/// Queries Local Memory size in bytes for compute shaders.
/// </summary>
/// <returns>Local Memory size in bytes</returns>
int QueryComputeLocalMemorySize()
{
return 0x1000;
}
/// <summary>
/// Queries Shared Memory size in bytes for compute shaders.
/// </summary>
/// <returns>Shared Memory size in bytes</returns>
int QueryComputeSharedMemorySize()
{
return 0xc000;
}
/// <summary>
/// Queries Constant Buffer usage information.
/// </summary>
/// <returns>A mask where each bit set indicates a bound constant buffer</returns>
uint QueryConstantBufferUse()
{
return 0;
}
/// <summary>
/// Queries whenever the current draw has written the base vertex and base instance into Constant Buffer 0.
/// </summary>
/// <returns>True if the shader translator can assume that the constant buffer contains the base IDs, false otherwise</returns>
bool QueryHasConstantBufferDrawParameters()
{
return false;
}
/// <summary>
/// Queries whenever the current draw uses unaligned storage buffer addresses.
/// </summary>
/// <returns>True if any storage buffer address is not aligned to 16 bytes, false otherwise</returns>
bool QueryHasUnalignedStorageBuffer()
{
return false;
}
/// <summary>
/// Queries host about whether to reduce precision to improve performance.
/// </summary>
/// <returns>True if precision is limited to vertex position, false otherwise</returns>
bool QueryHostReducedPrecision()
{
return false;
}
/// <summary>
/// Queries host about the presence of the FrontFacing built-in variable bug.
/// </summary>
/// <returns>True if the bug is present on the host device used, false otherwise</returns>
bool QueryHostHasFrontFacingBug()
{
return false;
}
/// <summary>
/// Queries host about the presence of the vector indexing bug.
/// </summary>
/// <returns>True if the bug is present on the host device used, false otherwise</returns>
bool QueryHostHasVectorIndexingBug()
{
return false;
}
/// <summary>
/// Queries host storage buffer alignment required.
/// </summary>
/// <returns>Host storage buffer alignment in bytes</returns>
int QueryHostStorageBufferOffsetAlignment()
{
return 16;
}
/// <summary>
/// Queries host support for texture formats with BGRA component order (such as BGRA8).
/// </summary>
/// <returns>True if BGRA formats are supported, false otherwise</returns>
bool QueryHostSupportsBgraFormat()
{
return true;
}
/// <summary>
/// Queries host support for fragment shader ordering critical sections on the shader code.
/// </summary>
/// <returns>True if fragment shader interlock is supported, false otherwise</returns>
bool QueryHostSupportsFragmentShaderInterlock()
{
return true;
}
/// <summary>
/// Queries host support for fragment shader ordering scoped critical sections on the shader code.
/// </summary>
/// <returns>True if fragment shader ordering is supported, false otherwise</returns>
bool QueryHostSupportsFragmentShaderOrderingIntel()
{
return false;
}
/// <summary>
/// Queries host GPU geometry shader passthrough support.
/// </summary>
/// <returns>True if the GPU and driver supports geometry shader passthrough, false otherwise</returns>
bool QueryHostSupportsGeometryShaderPassthrough()
{
return true;
}
/// <summary>
/// Queries host support for readable images without a explicit format declaration on the shader.
/// </summary>
/// <returns>True if formatted image load is supported, false otherwise</returns>
bool QueryHostSupportsImageLoadFormatted()
{
return true;
}
/// <summary>
/// Queries host support for writes to Layer from vertex or tessellation shader stages.
/// </summary>
/// <returns>True if writes to layer from vertex or tessellation are supported, false otherwise</returns>
bool QueryHostSupportsLayerVertexTessellation()
{
return true;
}
/// <summary>
/// Queries host GPU non-constant texture offset support.
/// </summary>
/// <returns>True if the GPU and driver supports non-constant texture offsets, false otherwise</returns>
bool QueryHostSupportsNonConstantTextureOffset()
{
return true;
}
/// <summary>
/// Queries host GPU shader ballot support.
/// </summary>
/// <returns>True if the GPU and driver supports shader ballot, false otherwise</returns>
bool QueryHostSupportsShaderBallot()
{
return true;
}
/// <summary>
/// Queries host GPU support for signed normalized buffer texture formats.
/// </summary>
/// <returns>True if the GPU and driver supports the formats, false otherwise</returns>
bool QueryHostSupportsSnormBufferTextureFormat()
{
return true;
}
/// <summary>
/// Queries host GPU texture shadow LOD support.
/// </summary>
/// <returns>True if the GPU and driver supports texture shadow LOD, false otherwise</returns>
bool QueryHostSupportsTextureShadowLod()
{
return true;
}
/// <summary>
/// Queries host GPU shader viewport index output support.
/// </summary>
/// <returns>True if the GPU and driver supports shader viewport index output, false otherwise</returns>
bool QueryHostSupportsViewportIndex()
{
return true;
}
/// <summary>
/// Queries the point size from the GPU state, used when it is not explicitly set on the shader.
/// </summary>
/// <returns>Current point size</returns>
float QueryPointSize()
{
return 1f;
}
/// <summary>
/// Queries the state that indicates if the program point size should be explicitly set on the shader
/// or read from the GPU state.
/// </summary>
/// <returns>True if the shader is expected to set the point size explicitly, false otherwise</returns>
bool QueryProgramPointSize()
{
return true;
}
/// <summary>
/// Queries sampler type information.
/// </summary>
/// <param name="handle">Texture handle</param>
/// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
/// <returns>The sampler type value for the given handle</returns>
SamplerType QuerySamplerType(int handle, int cbufSlot = -1)
{
return SamplerType.Texture2D;
}
/// <summary>
/// Queries texture coordinate normalization information.
/// </summary>
/// <param name="handle">Texture handle</param>
/// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
/// <returns>True if the coordinates are normalized, false otherwise</returns>
bool QueryTextureCoordNormalized(int handle, int cbufSlot = -1)
{
return true;
}
/// <summary>
/// Queries current primitive topology for geometry shaders.
/// </summary>
/// <returns>Current primitive topology</returns>
InputTopology QueryPrimitiveTopology()
{
return InputTopology.Points;
}
/// <summary>
/// Queries the tessellation evaluation shader primitive winding order.
/// </summary>
/// <returns>True if the primitive winding order is clockwise, false if counter-clockwise</returns>
bool QueryTessCw()
{
return false;
}
/// <summary>
/// Queries the tessellation evaluation shader abstract patch type.
/// </summary>
/// <returns>Abstract patch type</returns>
TessPatchType QueryTessPatchType()
{
return TessPatchType.Triangles;
}
/// <summary>
/// Queries the tessellation evaluation shader spacing between tessellated vertices of the patch.
/// </summary>
/// <returns>Spacing between tessellated vertices of the patch</returns>
TessSpacing QueryTessSpacing()
{
return TessSpacing.EqualSpacing;
}
/// <summary>
/// Queries texture format information, for shaders using image load or store.
/// </summary>
/// <remarks>
/// This only returns non-compressed color formats.
/// If the format of the texture is a compressed, depth or unsupported format, then a default value is returned.
/// </remarks>
/// <param name="handle">Texture handle</param>
/// <param name="cbufSlot">Constant buffer slot for the texture handle</param>
/// <returns>Color format of the non-compressed texture</returns>
TextureFormat QueryTextureFormat(int handle, int cbufSlot = -1)
{
return TextureFormat.R8G8B8A8Unorm;
}
/// <summary>
/// Queries depth mode information from the GPU state.
/// </summary>
/// <returns>True if current depth mode is -1 to 1, false if 0 to 1</returns>
bool QueryTransformDepthMinusOneToOne()
{
return false;
}
/// <summary>
/// Queries transform feedback enable state.
/// </summary>
/// <returns>True if the shader uses transform feedback, false otherwise</returns>
bool QueryTransformFeedbackEnabled()
{
return false;
}
/// <summary>
/// Queries the varying locations that should be written to the transform feedback buffer.
/// </summary>
/// <param name="bufferIndex">Index of the transform feedback buffer</param>
/// <returns>Varying locations for the specified buffer</returns>
ReadOnlySpan<byte> QueryTransformFeedbackVaryingLocations(int bufferIndex)
{
return ReadOnlySpan<byte>.Empty;
}
/// <summary>
/// Queries the stride (in bytes) of the per vertex data written into the transform feedback buffer.
/// </summary>
/// <param name="bufferIndex">Index of the transform feedback buffer</param>
/// <returns>Stride for the specified buffer</returns>
int QueryTransformFeedbackStride(int bufferIndex)
{
return 0;
}
/// <summary>
/// Queries if host state forces early depth testing.
/// </summary>
/// <returns>True if early depth testing is forced</returns>
bool QueryEarlyZForce()
{
return false;
}
/// <summary>
/// Queries if host state disables the viewport transform.
/// </summary>
/// <returns>True if the viewport transform is disabled</returns>
bool QueryViewportTransformDisable()
{
return false;
}
/// <summary>
/// Registers a texture used by the shader.
/// </summary>
/// <param name="handle">Texture handle word offset</param>
/// <param name="cbufSlot">Constant buffer slot where the texture handle is located</param>
void RegisterTexture(int handle, int cbufSlot)
{
// Only useful when recording information for a disk shader cache.
}
}
}