aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Shader
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-07-26 00:03:40 -0300
committerGitHub <noreply@github.com>2020-07-26 00:03:40 -0300
commit8dbcae1ff88927dc0734d5f0e24fbf8781d68590 (patch)
treed884544af874f385a7a374c8889683db2e4c1ccc /Ryujinx.Graphics.Shader
parent2678bf0010166e683364102221b52caebea8747e (diff)
Implement BGRA texture support (#1418)
* Implement BGRA texture support * Missing AppendLine * Remove empty lines * Address PR feedback
Diffstat (limited to 'Ryujinx.Graphics.Shader')
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs6
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs2
-rw-r--r--Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs16
-rw-r--r--Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs3
-rw-r--r--Ryujinx.Graphics.Shader/Translation/EmitterContext.cs38
5 files changed, 54 insertions, 11 deletions
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
index efd30143..40e277e0 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/Declarations.cs
@@ -139,6 +139,12 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
if (context.Config.Stage == ShaderStage.Fragment || context.Config.Stage == ShaderStage.Compute)
{
+ if (context.Config.Stage == ShaderStage.Fragment)
+ {
+ context.AppendLine($"uniform bool {DefaultNames.IsBgraName}[8];");
+ context.AppendLine();
+ }
+
if (DeclareRenderScale(context))
{
context.AppendLine();
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs
index 4da38b2d..d1cf4636 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/DefaultNames.cs
@@ -23,5 +23,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
public const string SharedMemoryName = "shared_mem";
public const string UndefinedName = "undef";
+
+ public const string IsBgraName = "is_bgra";
}
} \ No newline at end of file
diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
index 8801fc11..4ae9a00a 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
@@ -64,6 +64,16 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
{ AttributeConsts.GtMask, new BuiltInAttribute("unpackUint2x32(gl_SubGroupGtMaskARB).x", VariableType.U32) },
{ AttributeConsts.LeMask, new BuiltInAttribute("unpackUint2x32(gl_SubGroupLeMaskARB).x", VariableType.U32) },
{ AttributeConsts.LtMask, new BuiltInAttribute("unpackUint2x32(gl_SubGroupLtMaskARB).x", VariableType.U32) },
+
+ // Support uniforms.
+ { AttributeConsts.FragmentOutputIsBgraBase + 0, new BuiltInAttribute($"{DefaultNames.IsBgraName}[0]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 4, new BuiltInAttribute($"{DefaultNames.IsBgraName}[1]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 8, new BuiltInAttribute($"{DefaultNames.IsBgraName}[2]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 12, new BuiltInAttribute($"{DefaultNames.IsBgraName}[3]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 16, new BuiltInAttribute($"{DefaultNames.IsBgraName}[4]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 20, new BuiltInAttribute($"{DefaultNames.IsBgraName}[5]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 24, new BuiltInAttribute($"{DefaultNames.IsBgraName}[6]", VariableType.Bool) },
+ { AttributeConsts.FragmentOutputIsBgraBase + 28, new BuiltInAttribute($"{DefaultNames.IsBgraName}[7]", VariableType.Bool) }
};
private Dictionary<AstOperand, string> _locals;
@@ -149,8 +159,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
char swzMask = GetSwizzleMask((value >> 2) & 3);
- if (value >= AttributeConsts.UserAttributeBase &&
- value < AttributeConsts.UserAttributeEnd)
+ if (value >= AttributeConsts.UserAttributeBase && value < AttributeConsts.UserAttributeEnd)
{
value -= AttributeConsts.UserAttributeBase;
@@ -169,8 +178,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
}
else
{
- if (value >= AttributeConsts.FragmentOutputColorBase &&
- value < AttributeConsts.FragmentOutputColorEnd)
+ if (value >= AttributeConsts.FragmentOutputColorBase && value < AttributeConsts.FragmentOutputColorEnd)
{
value -= AttributeConsts.FragmentOutputColorBase;
diff --git a/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs b/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
index 8ff37429..c194b5c2 100644
--- a/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
+++ b/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
@@ -35,6 +35,9 @@ namespace Ryujinx.Graphics.Shader.Translation
public const int FragmentOutputColorBase = 0x1000010;
public const int FragmentOutputColorEnd = FragmentOutputColorBase + 8 * 16;
+ public const int FragmentOutputIsBgraBase = 0x1000100;
+ public const int FragmentOutputIsBgraEnd = FragmentOutputIsBgraBase + 8 * 4;
+
public const int ThreadIdX = 0x2000000;
public const int ThreadIdY = 0x2000004;
public const int ThreadIdZ = 0x2000008;
diff --git a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
index 39532a64..9b26fa4a 100644
--- a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
+++ b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs
@@ -115,22 +115,46 @@ namespace Ryujinx.Graphics.Shader.Translation
int regIndex = 0;
- for (int attachment = 0; attachment < 8; attachment++)
+ for (int rtIndex = 0; rtIndex < 8; rtIndex++)
{
- OmapTarget target = Config.OmapTargets[attachment];
+ OmapTarget target = Config.OmapTargets[rtIndex];
for (int component = 0; component < 4; component++)
{
- if (target.ComponentEnabled(component))
+ if (!target.ComponentEnabled(component))
{
- Operand dest = Attribute(AttributeConsts.FragmentOutputColorBase + attachment * 16 + component * 4);
+ continue;
+ }
+
+ int fragmentOutputColorAttr = AttributeConsts.FragmentOutputColorBase + rtIndex * 16;
+
+ Operand src = Register(regIndex, RegisterType.Gpr);
+
+ // Perform B <-> R swap if needed, for BGRA formats (not supported on OpenGL).
+ if (component == 0 || component == 2)
+ {
+ Operand isBgra = Attribute(AttributeConsts.FragmentOutputIsBgraBase + rtIndex * 4);
+
+ Operand lblIsBgra = Label();
+ Operand lblEnd = Label();
- Operand src = Register(regIndex, RegisterType.Gpr);
+ this.BranchIfTrue(lblIsBgra, isBgra);
- this.Copy(dest, src);
+ this.Copy(Attribute(fragmentOutputColorAttr + component * 4), src);
+ this.Branch(lblEnd);
- regIndex++;
+ MarkLabel(lblIsBgra);
+
+ this.Copy(Attribute(fragmentOutputColorAttr + (2 - component) * 4), src);
+
+ MarkLabel(lblEnd);
}
+ else
+ {
+ this.Copy(Attribute(fragmentOutputColorAttr + component * 4), src);
+ }
+
+ regIndex++;
}
}
}