aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader/CodeGen
diff options
context:
space:
mode:
authorriperiperi <rhy3756547@hotmail.com>2022-01-08 17:48:48 +0000
committerGitHub <noreply@github.com>2022-01-08 14:48:48 -0300
commit79adba44022abb5c1c547fb41d98a4d7a6b5029a (patch)
tree46acbb76860961fca9ef70d12a6e12d5839f55af /Ryujinx.Graphics.Shader/CodeGen
parente5f7ff1eee81ebc852b8bc703d5f4847eb430560 (diff)
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
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs31
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs1
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_fp.glsl2
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_vp.glsl20
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs6
5 files changed, 41 insertions, 19 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index 7dcd1671..d8956567 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -208,7 +208,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
bool isFragment = context.Config.Stage == ShaderStage.Fragment;
- if (isFragment || context.Config.Stage == ShaderStage.Compute)
+ if (isFragment || context.Config.Stage == ShaderStage.Compute || context.Config.Stage == ShaderStage.Vertex)
{
if (isFragment && context.Config.GpuAccessor.QueryEarlyZForce())
{
@@ -227,7 +227,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
scaleElements++; // Also includes render target scale, for gl_FragCoord.
}
- DeclareSupportUniformBlock(context, isFragment, scaleElements);
+ DeclareSupportUniformBlock(context, context.Config.Stage, scaleElements);
if (context.Config.UsedFeatures.HasFlag(FeatureFlags.IntegerSampling))
{
@@ -237,7 +237,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
else if (isFragment)
{
- DeclareSupportUniformBlock(context, true, 0);
+ DeclareSupportUniformBlock(context, context.Config.Stage, 0);
}
}
@@ -591,8 +591,9 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine($"patch out vec4 {name};");
}
- private static void DeclareSupportUniformBlock(CodeGenContext context, bool isFragment, int scaleElements)
+ private static void DeclareSupportUniformBlock(CodeGenContext context, ShaderStage stage, int scaleElements)
{
+ bool isFragment = stage == ShaderStage.Fragment;
if (!isFragment && scaleElements == 0)
{
return;
@@ -601,20 +602,20 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
context.AppendLine($"layout (binding = 0, std140) uniform {DefaultNames.SupportBlockName}");
context.EnterScope();
- if (isFragment)
+ switch (stage)
{
- context.AppendLine($"uint {DefaultNames.SupportBlockAlphaTestName};");
- context.AppendLine($"bool {DefaultNames.SupportBlockIsBgraName}[{SupportBuffer.FragmentIsBgraCount}];");
- }
- else
- {
- context.AppendLine($"uint s_reserved[{SupportBuffer.ComputeRenderScaleOffset / SupportBuffer.FieldSize}];");
+ case ShaderStage.Fragment:
+ case ShaderStage.Vertex:
+ context.AppendLine($"uint {DefaultNames.SupportBlockAlphaTestName};");
+ context.AppendLine($"bool {DefaultNames.SupportBlockIsBgraName}[{SupportBuffer.FragmentIsBgraCount}];");
+ context.AppendLine($"int {DefaultNames.SupportBlockFragmentScaleCount};");
+ break;
+ case ShaderStage.Compute:
+ context.AppendLine($"uint s_reserved[{SupportBuffer.ComputeRenderScaleOffset / SupportBuffer.FieldSize}];");
+ break;
}
- if (scaleElements != 0)
- {
- context.AppendLine($"float {DefaultNames.SupportBlockRenderScaleName}[{scaleElements}];");
- }
+ context.AppendLine($"float {DefaultNames.SupportBlockRenderScaleName}[{SupportBuffer.RenderScaleMaxCount}];");
context.LeaveScope(";");
context.AppendLine();
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs
index 47350408..76203522 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs
@@ -18,6 +18,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
public const string SupportBlockName = "support_block";
public const string SupportBlockAlphaTestName = "s_alpha_test";
public const string SupportBlockIsBgraName = "s_is_bgra";
+ public const string SupportBlockFragmentScaleCount = "s_frag_scale_count";
public const string SupportBlockRenderScaleName = "s_render_scale";
public const string BlockSuffix = "block";
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_fp.glsl b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_fp.glsl
index 5def1390..6c670f91 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_fp.glsl
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_fp.glsl
@@ -7,7 +7,7 @@
}
if (scale < 0.0) // If less than 0, try interpolate between texels by using the screen position.
{
- return ivec2(vec2(inputVec) * (-scale) + mod(gl_FragCoord.xy, -scale));
+ return ivec2(vec2(inputVec) * (-scale) + mod(gl_FragCoord.xy, 0.0 - scale));
}
else
{
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_vp.glsl b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_vp.glsl
new file mode 100644
index 00000000..19eb119d
--- /dev/null
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/TexelFetchScale_vp.glsl
@@ -0,0 +1,20 @@
+ivec2 Helper_TexelFetchScale(ivec2 inputVec, int samplerIndex)
+{
+ float scale = abs(s_render_scale[1 + samplerIndex + s_frag_scale_count]);
+ if (scale == 1.0)
+ {
+ return inputVec;
+ }
+
+ return ivec2(vec2(inputVec) * scale);
+}
+
+int Helper_TextureSizeUnscale(int size, int samplerIndex)
+{
+ float scale = abs(s_render_scale[1 + samplerIndex + s_frag_scale_count]);
+ if (scale == 1.0)
+ {
+ return size;
+ }
+ return int(float(size) / scale);
+} \ No newline at end of file
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
index abca03aa..164de7bb 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Instructions/InstGenMemory.cs
@@ -85,7 +85,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
string ApplyScaling(string vector)
{
- if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
+ if ((context.Config.Stage.SupportsRenderScale()) &&
texOp.Inst == Instruction.ImageLoad &&
!isBindless &&
!isIndexed)
@@ -621,7 +621,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
{
if (intCoords)
{
- if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
+ if ((context.Config.Stage.SupportsRenderScale()) &&
!isBindless &&
!isIndexed)
{
@@ -770,7 +770,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl.Instructions
{
string texCall = $"textureSize({samplerName}, {lodExpr}){GetMask(texOp.Index)}";
- if ((context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute) &&
+ if (context.Config.Stage.SupportsRenderScale() &&
!isBindless &&
!isIndexed)
{