diff options
Diffstat (limited to 'Ryujinx.Graphics.Shader/CodeGen')
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) { |
