1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-05 01:02:01 +00:00
Ryujinx/Ryujinx.Graphics.Shader/SupportBuffer.cs
riperiperi 79adba4402
Add support for render scale to vertex stage. (#2763)
* Add support for render scale to vertex stage.

Occasionally games read off textureSize on the vertex stage to inform the fragment shader what size a texture is without querying in there. Scales were not present in the vertex shader to correct the sizes, so games were providing the raw upscaled texture size to the fragment shader, which was incorrect.

One downside is that the fragment and vertex support buffer description must be identical, so the full size scales array must be defined when used. I don't think this will have an impact though. Another is that the fragment texture count must be updated when vertex shader textures are used. I'd like to correct this so that the update is folded into the update for the scales.

Also cleans up a bunch of things, like it making no sense to call CommitRenderScale for each stage.

Fixes render scale causing a weird offset bloom in Super Mario Party and Clubhouse Games. Clubhouse Games still has a pixelated look in a number of its games due to something else it does in the shader.

* Split out support buffer update, lazy updates.

* Commit support buffer before compute dispatch

* Remove unnecessary qualifier.

* Address Feedback
2022-01-08 14:48:48 -03:00

55 lines
No EOL
2 KiB
C#

using Ryujinx.Common.Memory;
using System.Runtime.CompilerServices;
namespace Ryujinx.Graphics.Shader
{
public struct Vector4<T>
{
public T X;
public T Y;
public T Z;
public T W;
}
public struct SupportBuffer
{
public static int FieldSize;
public static int RequiredSize;
public static int FragmentAlphaTestOffset;
public static int FragmentIsBgraOffset;
public static int FragmentRenderScaleCountOffset;
public static int GraphicsRenderScaleOffset;
public static int ComputeRenderScaleOffset;
public const int FragmentIsBgraCount = 8;
// One for the render target, 32 for the textures, and 8 for the images.
public const int RenderScaleMaxCount = 1 + 32 + 8;
private static int OffsetOf<T>(ref SupportBuffer storage, ref T target)
{
return (int)Unsafe.ByteOffset(ref Unsafe.As<SupportBuffer, T>(ref storage), ref target);
}
static SupportBuffer()
{
FieldSize = Unsafe.SizeOf<Vector4<float>>();
RequiredSize = Unsafe.SizeOf<SupportBuffer>();
SupportBuffer instance = new SupportBuffer();
FragmentAlphaTestOffset = OffsetOf(ref instance, ref instance.FragmentAlphaTest);
FragmentIsBgraOffset = OffsetOf(ref instance, ref instance.FragmentIsBgra);
FragmentRenderScaleCountOffset = OffsetOf(ref instance, ref instance.FragmentRenderScaleCount);
GraphicsRenderScaleOffset = OffsetOf(ref instance, ref instance.RenderScale);
ComputeRenderScaleOffset = GraphicsRenderScaleOffset + FieldSize;
}
public Vector4<int> FragmentAlphaTest;
public Array8<Vector4<int>> FragmentIsBgra;
public Vector4<int> FragmentRenderScaleCount;
// Render scale max count: 1 + 32 + 8. First scale is fragment output scale, others are textures/image inputs.
public Array41<Vector4<float>> RenderScale;
}
}