Renaming part 2
This commit is contained in:
parent
a268285d9e
commit
e697dbffc9
29 changed files with 2266 additions and 2266 deletions
|
@ -51,9 +51,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
public const string SsyStackName = "ssy_stack";
|
||||
public const string SsyCursorName = "ssy_cursor";
|
||||
|
||||
private string[] StagePrefixes = new string[] { "vp", "tcp", "tep", "gp", "fp" };
|
||||
private string[] _stagePrefixes = new string[] { "vp", "tcp", "tep", "gp", "fp" };
|
||||
|
||||
private string StagePrefix;
|
||||
private string _stagePrefix;
|
||||
|
||||
private Dictionary<ShaderIrOp, ShaderDeclInfo> m_CbTextures;
|
||||
|
||||
|
@ -83,9 +83,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public GalShaderType ShaderType { get; private set; }
|
||||
|
||||
private GlslDecl(GalShaderType ShaderType)
|
||||
private GlslDecl(GalShaderType shaderType)
|
||||
{
|
||||
this.ShaderType = ShaderType;
|
||||
this.ShaderType = shaderType;
|
||||
|
||||
m_CbTextures = new Dictionary<ShaderIrOp, ShaderDeclInfo>();
|
||||
|
||||
|
@ -101,187 +101,187 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
m_Preds = new Dictionary<int, ShaderDeclInfo>();
|
||||
}
|
||||
|
||||
public GlslDecl(ShaderIrBlock[] Blocks, GalShaderType ShaderType, ShaderHeader Header) : this(ShaderType)
|
||||
public GlslDecl(ShaderIrBlock[] blocks, GalShaderType shaderType, ShaderHeader header) : this(shaderType)
|
||||
{
|
||||
StagePrefix = StagePrefixes[(int)ShaderType] + "_";
|
||||
_stagePrefix = _stagePrefixes[(int)shaderType] + "_";
|
||||
|
||||
if (ShaderType == GalShaderType.Fragment)
|
||||
if (shaderType == GalShaderType.Fragment)
|
||||
{
|
||||
int Index = 0;
|
||||
int index = 0;
|
||||
|
||||
for (int Attachment = 0; Attachment < 8; Attachment++)
|
||||
for (int attachment = 0; attachment < 8; attachment++)
|
||||
{
|
||||
for (int Component = 0; Component < 4; Component++)
|
||||
for (int component = 0; component < 4; component++)
|
||||
{
|
||||
if (Header.OmapTargets[Attachment].ComponentEnabled(Component))
|
||||
if (header.OmapTargets[attachment].ComponentEnabled(component))
|
||||
{
|
||||
m_Gprs.TryAdd(Index, new ShaderDeclInfo(GetGprName(Index), Index));
|
||||
m_Gprs.TryAdd(index, new ShaderDeclInfo(GetGprName(index), index));
|
||||
|
||||
Index++;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Header.OmapDepth)
|
||||
if (header.OmapDepth)
|
||||
{
|
||||
Index = Header.DepthRegister;
|
||||
index = header.DepthRegister;
|
||||
|
||||
m_Gprs.TryAdd(Index, new ShaderDeclInfo(GetGprName(Index), Index));
|
||||
m_Gprs.TryAdd(index, new ShaderDeclInfo(GetGprName(index), index));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (ShaderIrBlock Block in Blocks)
|
||||
foreach (ShaderIrBlock block in blocks)
|
||||
{
|
||||
ShaderIrNode[] Nodes = Block.GetNodes();
|
||||
ShaderIrNode[] nodes = block.GetNodes();
|
||||
|
||||
foreach (ShaderIrNode Node in Nodes)
|
||||
foreach (ShaderIrNode node in nodes)
|
||||
{
|
||||
Traverse(Nodes, null, Node);
|
||||
Traverse(nodes, null, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GlslDecl Merge(GlslDecl VpA, GlslDecl VpB)
|
||||
public static GlslDecl Merge(GlslDecl vpA, GlslDecl vpB)
|
||||
{
|
||||
GlslDecl Combined = new GlslDecl(GalShaderType.Vertex);
|
||||
GlslDecl combined = new GlslDecl(GalShaderType.Vertex);
|
||||
|
||||
Merge(Combined.m_Textures, VpA.m_Textures, VpB.m_Textures);
|
||||
Merge(Combined.m_Uniforms, VpA.m_Uniforms, VpB.m_Uniforms);
|
||||
Merge(combined.m_Textures, vpA.m_Textures, vpB.m_Textures);
|
||||
Merge(combined.m_Uniforms, vpA.m_Uniforms, vpB.m_Uniforms);
|
||||
|
||||
Merge(Combined.m_Attributes, VpA.m_Attributes, VpB.m_Attributes);
|
||||
Merge(Combined.m_OutAttributes, VpA.m_OutAttributes, VpB.m_OutAttributes);
|
||||
Merge(combined.m_Attributes, vpA.m_Attributes, vpB.m_Attributes);
|
||||
Merge(combined.m_OutAttributes, vpA.m_OutAttributes, vpB.m_OutAttributes);
|
||||
|
||||
Merge(Combined.m_Gprs, VpA.m_Gprs, VpB.m_Gprs);
|
||||
Merge(Combined.m_GprsHalf, VpA.m_GprsHalf, VpB.m_GprsHalf);
|
||||
Merge(Combined.m_Preds, VpA.m_Preds, VpB.m_Preds);
|
||||
Merge(combined.m_Gprs, vpA.m_Gprs, vpB.m_Gprs);
|
||||
Merge(combined.m_GprsHalf, vpA.m_GprsHalf, vpB.m_GprsHalf);
|
||||
Merge(combined.m_Preds, vpA.m_Preds, vpB.m_Preds);
|
||||
|
||||
//Merge input attributes.
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> KV in VpA.m_InAttributes)
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> kv in vpA.m_InAttributes)
|
||||
{
|
||||
Combined.m_InAttributes.TryAdd(KV.Key, KV.Value);
|
||||
combined.m_InAttributes.TryAdd(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> KV in VpB.m_InAttributes)
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> kv in vpB.m_InAttributes)
|
||||
{
|
||||
//If Vertex Program A already writes to this attribute,
|
||||
//then we don't need to add it as an input attribute since
|
||||
//Vertex Program A will already have written to it anyway,
|
||||
//and there's no guarantee that there is an input attribute
|
||||
//for this slot.
|
||||
if (!VpA.m_OutAttributes.ContainsKey(KV.Key))
|
||||
if (!vpA.m_OutAttributes.ContainsKey(kv.Key))
|
||||
{
|
||||
Combined.m_InAttributes.TryAdd(KV.Key, KV.Value);
|
||||
combined.m_InAttributes.TryAdd(kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
|
||||
return Combined;
|
||||
return combined;
|
||||
}
|
||||
|
||||
public static string GetGprName(int Index)
|
||||
public static string GetGprName(int index)
|
||||
{
|
||||
return GprName + Index;
|
||||
return GprName + index;
|
||||
}
|
||||
|
||||
private static void Merge(
|
||||
Dictionary<int, ShaderDeclInfo> C,
|
||||
Dictionary<int, ShaderDeclInfo> A,
|
||||
Dictionary<int, ShaderDeclInfo> B)
|
||||
Dictionary<int, ShaderDeclInfo> c,
|
||||
Dictionary<int, ShaderDeclInfo> a,
|
||||
Dictionary<int, ShaderDeclInfo> b)
|
||||
{
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> KV in A)
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> kv in a)
|
||||
{
|
||||
C.TryAdd(KV.Key, KV.Value);
|
||||
c.TryAdd(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> KV in B)
|
||||
foreach (KeyValuePair<int, ShaderDeclInfo> kv in b)
|
||||
{
|
||||
C.TryAdd(KV.Key, KV.Value);
|
||||
c.TryAdd(kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private void Traverse(ShaderIrNode[] Nodes, ShaderIrNode Parent, ShaderIrNode Node)
|
||||
private void Traverse(ShaderIrNode[] nodes, ShaderIrNode parent, ShaderIrNode node)
|
||||
{
|
||||
switch (Node)
|
||||
switch (node)
|
||||
{
|
||||
case ShaderIrAsg Asg:
|
||||
case ShaderIrAsg asg:
|
||||
{
|
||||
Traverse(Nodes, Asg, Asg.Dst);
|
||||
Traverse(Nodes, Asg, Asg.Src);
|
||||
Traverse(nodes, asg, asg.Dst);
|
||||
Traverse(nodes, asg, asg.Src);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderIrCond Cond:
|
||||
case ShaderIrCond cond:
|
||||
{
|
||||
Traverse(Nodes, Cond, Cond.Pred);
|
||||
Traverse(Nodes, Cond, Cond.Child);
|
||||
Traverse(nodes, cond, cond.Pred);
|
||||
Traverse(nodes, cond, cond.Child);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderIrOp Op:
|
||||
case ShaderIrOp op:
|
||||
{
|
||||
Traverse(Nodes, Op, Op.OperandA);
|
||||
Traverse(Nodes, Op, Op.OperandB);
|
||||
Traverse(Nodes, Op, Op.OperandC);
|
||||
Traverse(nodes, op, op.OperandA);
|
||||
Traverse(nodes, op, op.OperandB);
|
||||
Traverse(nodes, op, op.OperandC);
|
||||
|
||||
if (Op.Inst == ShaderIrInst.Texq ||
|
||||
Op.Inst == ShaderIrInst.Texs ||
|
||||
Op.Inst == ShaderIrInst.Tld4 ||
|
||||
Op.Inst == ShaderIrInst.Txlf)
|
||||
if (op.Inst == ShaderIrInst.Texq ||
|
||||
op.Inst == ShaderIrInst.Texs ||
|
||||
op.Inst == ShaderIrInst.Tld4 ||
|
||||
op.Inst == ShaderIrInst.Txlf)
|
||||
{
|
||||
int Handle = ((ShaderIrOperImm)Op.OperandC).Value;
|
||||
int handle = ((ShaderIrOperImm)op.OperandC).Value;
|
||||
|
||||
int Index = Handle - TexStartIndex;
|
||||
int index = handle - TexStartIndex;
|
||||
|
||||
string Name = StagePrefix + TextureName + Index;
|
||||
string name = _stagePrefix + TextureName + index;
|
||||
|
||||
GalTextureTarget TextureTarget;
|
||||
GalTextureTarget textureTarget;
|
||||
|
||||
TextureInstructionSuffix TextureInstructionSuffix;
|
||||
TextureInstructionSuffix textureInstructionSuffix;
|
||||
|
||||
// TODO: Non 2D texture type for TEXQ?
|
||||
if (Op.Inst == ShaderIrInst.Texq)
|
||||
if (op.Inst == ShaderIrInst.Texq)
|
||||
{
|
||||
TextureTarget = GalTextureTarget.TwoD;
|
||||
TextureInstructionSuffix = TextureInstructionSuffix.None;
|
||||
textureTarget = GalTextureTarget.TwoD;
|
||||
textureInstructionSuffix = TextureInstructionSuffix.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
ShaderIrMetaTex Meta = ((ShaderIrMetaTex)Op.MetaData);
|
||||
ShaderIrMetaTex meta = ((ShaderIrMetaTex)op.MetaData);
|
||||
|
||||
TextureTarget = Meta.TextureTarget;
|
||||
TextureInstructionSuffix = Meta.TextureInstructionSuffix;
|
||||
textureTarget = meta.TextureTarget;
|
||||
textureInstructionSuffix = meta.TextureInstructionSuffix;
|
||||
}
|
||||
|
||||
m_Textures.TryAdd(Handle, new ShaderDeclInfo(Name, Handle, false, 0, 1, TextureTarget, TextureInstructionSuffix));
|
||||
m_Textures.TryAdd(handle, new ShaderDeclInfo(name, handle, false, 0, 1, textureTarget, textureInstructionSuffix));
|
||||
}
|
||||
else if (Op.Inst == ShaderIrInst.Texb)
|
||||
else if (op.Inst == ShaderIrInst.Texb)
|
||||
{
|
||||
ShaderIrNode HandleSrc = null;
|
||||
ShaderIrNode handleSrc = null;
|
||||
|
||||
int Index = Array.IndexOf(Nodes, Parent) - 1;
|
||||
int index = Array.IndexOf(nodes, parent) - 1;
|
||||
|
||||
for (; Index >= 0; Index--)
|
||||
for (; index >= 0; index--)
|
||||
{
|
||||
ShaderIrNode Curr = Nodes[Index];
|
||||
ShaderIrNode curr = nodes[index];
|
||||
|
||||
if (Curr is ShaderIrAsg Asg && Asg.Dst is ShaderIrOperGpr Gpr)
|
||||
if (curr is ShaderIrAsg asg && asg.Dst is ShaderIrOperGpr gpr)
|
||||
{
|
||||
if (Gpr.Index == ((ShaderIrOperGpr)Op.OperandC).Index)
|
||||
if (gpr.Index == ((ShaderIrOperGpr)op.OperandC).Index)
|
||||
{
|
||||
HandleSrc = Asg.Src;
|
||||
handleSrc = asg.Src;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HandleSrc != null && HandleSrc is ShaderIrOperCbuf Cbuf)
|
||||
if (handleSrc != null && handleSrc is ShaderIrOperCbuf cbuf)
|
||||
{
|
||||
ShaderIrMetaTex Meta = ((ShaderIrMetaTex)Op.MetaData);
|
||||
string Name = StagePrefix + TextureName + "_cb" + Cbuf.Index + "_" + Cbuf.Pos;
|
||||
ShaderIrMetaTex meta = ((ShaderIrMetaTex)op.MetaData);
|
||||
string name = _stagePrefix + TextureName + "_cb" + cbuf.Index + "_" + cbuf.Pos;
|
||||
|
||||
m_CbTextures.Add(Op, new ShaderDeclInfo(Name, Cbuf.Pos, true, Cbuf.Index, 1, Meta.TextureTarget, Meta.TextureInstructionSuffix));
|
||||
m_CbTextures.Add(op, new ShaderDeclInfo(name, cbuf.Pos, true, cbuf.Index, 1, meta.TextureTarget, meta.TextureInstructionSuffix));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -291,93 +291,93 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
break;
|
||||
}
|
||||
|
||||
case ShaderIrOperCbuf Cbuf:
|
||||
case ShaderIrOperCbuf cbuf:
|
||||
{
|
||||
if (!m_Uniforms.ContainsKey(Cbuf.Index))
|
||||
if (!m_Uniforms.ContainsKey(cbuf.Index))
|
||||
{
|
||||
string Name = StagePrefix + UniformName + Cbuf.Index;
|
||||
string name = _stagePrefix + UniformName + cbuf.Index;
|
||||
|
||||
ShaderDeclInfo DeclInfo = new ShaderDeclInfo(Name, Cbuf.Pos, true, Cbuf.Index);
|
||||
ShaderDeclInfo declInfo = new ShaderDeclInfo(name, cbuf.Pos, true, cbuf.Index);
|
||||
|
||||
m_Uniforms.Add(Cbuf.Index, DeclInfo);
|
||||
m_Uniforms.Add(cbuf.Index, declInfo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderIrOperAbuf Abuf:
|
||||
case ShaderIrOperAbuf abuf:
|
||||
{
|
||||
//This is a built-in variable.
|
||||
if (Abuf.Offs == LayerAttr ||
|
||||
Abuf.Offs == PointSizeAttr ||
|
||||
Abuf.Offs == PointCoordAttrX ||
|
||||
Abuf.Offs == PointCoordAttrY ||
|
||||
Abuf.Offs == VertexIdAttr ||
|
||||
Abuf.Offs == InstanceIdAttr ||
|
||||
Abuf.Offs == FaceAttr)
|
||||
if (abuf.Offs == LayerAttr ||
|
||||
abuf.Offs == PointSizeAttr ||
|
||||
abuf.Offs == PointCoordAttrX ||
|
||||
abuf.Offs == PointCoordAttrY ||
|
||||
abuf.Offs == VertexIdAttr ||
|
||||
abuf.Offs == InstanceIdAttr ||
|
||||
abuf.Offs == FaceAttr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
int Index = Abuf.Offs >> 4;
|
||||
int Elem = (Abuf.Offs >> 2) & 3;
|
||||
int index = abuf.Offs >> 4;
|
||||
int elem = (abuf.Offs >> 2) & 3;
|
||||
|
||||
int GlslIndex = Index - AttrStartIndex;
|
||||
int glslIndex = index - AttrStartIndex;
|
||||
|
||||
if (GlslIndex < 0)
|
||||
if (glslIndex < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ShaderDeclInfo DeclInfo;
|
||||
ShaderDeclInfo declInfo;
|
||||
|
||||
if (Parent is ShaderIrAsg Asg && Asg.Dst == Node)
|
||||
if (parent is ShaderIrAsg asg && asg.Dst == node)
|
||||
{
|
||||
if (!m_OutAttributes.TryGetValue(Index, out DeclInfo))
|
||||
if (!m_OutAttributes.TryGetValue(index, out declInfo))
|
||||
{
|
||||
DeclInfo = new ShaderDeclInfo(OutAttrName + GlslIndex, GlslIndex);
|
||||
declInfo = new ShaderDeclInfo(OutAttrName + glslIndex, glslIndex);
|
||||
|
||||
m_OutAttributes.Add(Index, DeclInfo);
|
||||
m_OutAttributes.Add(index, declInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_InAttributes.TryGetValue(Index, out DeclInfo))
|
||||
if (!m_InAttributes.TryGetValue(index, out declInfo))
|
||||
{
|
||||
DeclInfo = new ShaderDeclInfo(InAttrName + GlslIndex, GlslIndex);
|
||||
declInfo = new ShaderDeclInfo(InAttrName + glslIndex, glslIndex);
|
||||
|
||||
m_InAttributes.Add(Index, DeclInfo);
|
||||
m_InAttributes.Add(index, declInfo);
|
||||
}
|
||||
}
|
||||
|
||||
DeclInfo.Enlarge(Elem + 1);
|
||||
declInfo.Enlarge(elem + 1);
|
||||
|
||||
if (!m_Attributes.ContainsKey(Index))
|
||||
if (!m_Attributes.ContainsKey(index))
|
||||
{
|
||||
DeclInfo = new ShaderDeclInfo(AttrName + GlslIndex, GlslIndex, false, 0, 4);
|
||||
declInfo = new ShaderDeclInfo(AttrName + glslIndex, glslIndex, false, 0, 4);
|
||||
|
||||
m_Attributes.Add(Index, DeclInfo);
|
||||
m_Attributes.Add(index, declInfo);
|
||||
}
|
||||
|
||||
Traverse(Nodes, Abuf, Abuf.Vertex);
|
||||
Traverse(nodes, abuf, abuf.Vertex);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case ShaderIrOperGpr Gpr:
|
||||
case ShaderIrOperGpr gpr:
|
||||
{
|
||||
if (!Gpr.IsConst)
|
||||
if (!gpr.IsConst)
|
||||
{
|
||||
string Name = GetGprName(Gpr.Index);
|
||||
string name = GetGprName(gpr.Index);
|
||||
|
||||
if (Gpr.RegisterSize == ShaderRegisterSize.Single)
|
||||
if (gpr.RegisterSize == ShaderRegisterSize.Single)
|
||||
{
|
||||
m_Gprs.TryAdd(Gpr.Index, new ShaderDeclInfo(Name, Gpr.Index));
|
||||
m_Gprs.TryAdd(gpr.Index, new ShaderDeclInfo(name, gpr.Index));
|
||||
}
|
||||
else if (Gpr.RegisterSize == ShaderRegisterSize.Half)
|
||||
else if (gpr.RegisterSize == ShaderRegisterSize.Half)
|
||||
{
|
||||
Name += "_h" + Gpr.HalfPart;
|
||||
name += "_h" + gpr.HalfPart;
|
||||
|
||||
m_GprsHalf.TryAdd((Gpr.Index << 1) | Gpr.HalfPart, new ShaderDeclInfo(Name, Gpr.Index));
|
||||
m_GprsHalf.TryAdd((gpr.Index << 1) | gpr.HalfPart, new ShaderDeclInfo(name, gpr.Index));
|
||||
}
|
||||
else /* if (Gpr.RegisterSize == ShaderRegisterSize.Double) */
|
||||
{
|
||||
|
@ -387,35 +387,35 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
break;
|
||||
}
|
||||
|
||||
case ShaderIrOperPred Pred:
|
||||
case ShaderIrOperPred pred:
|
||||
{
|
||||
if (!Pred.IsConst && !HasName(m_Preds, Pred.Index))
|
||||
if (!pred.IsConst && !HasName(m_Preds, pred.Index))
|
||||
{
|
||||
string Name = PredName + Pred.Index;
|
||||
string name = PredName + pred.Index;
|
||||
|
||||
m_Preds.TryAdd(Pred.Index, new ShaderDeclInfo(Name, Pred.Index));
|
||||
m_Preds.TryAdd(pred.Index, new ShaderDeclInfo(name, pred.Index));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasName(Dictionary<int, ShaderDeclInfo> Decls, int Index)
|
||||
private bool HasName(Dictionary<int, ShaderDeclInfo> decls, int index)
|
||||
{
|
||||
//This is used to check if the dictionary already contains
|
||||
//a entry for a vector at a given index position.
|
||||
//Used to enable turning gprs into vectors.
|
||||
int VecIndex = Index & ~3;
|
||||
int vecIndex = index & ~3;
|
||||
|
||||
if (Decls.TryGetValue(VecIndex, out ShaderDeclInfo DeclInfo))
|
||||
if (decls.TryGetValue(vecIndex, out ShaderDeclInfo declInfo))
|
||||
{
|
||||
if (DeclInfo.Size > 1 && Index < VecIndex + DeclInfo.Size)
|
||||
if (declInfo.Size > 1 && index < vecIndex + declInfo.Size)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return Decls.ContainsKey(Index);
|
||||
return decls.ContainsKey(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,13 +10,13 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
public IEnumerable<ShaderDeclInfo> Uniforms { get; private set; }
|
||||
|
||||
public GlslProgram(
|
||||
string Code,
|
||||
IEnumerable<ShaderDeclInfo> Textures,
|
||||
IEnumerable<ShaderDeclInfo> Uniforms)
|
||||
string code,
|
||||
IEnumerable<ShaderDeclInfo> textures,
|
||||
IEnumerable<ShaderDeclInfo> uniforms)
|
||||
{
|
||||
this.Code = Code;
|
||||
this.Textures = Textures;
|
||||
this.Uniforms = Uniforms;
|
||||
this.Code = code;
|
||||
this.Textures = textures;
|
||||
this.Uniforms = uniforms;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -4,54 +4,54 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
static partial class ShaderDecode
|
||||
{
|
||||
public static void Bra(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Bra(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
if ((OpCode & 0x20) != 0)
|
||||
if ((opCode & 0x20) != 0)
|
||||
{
|
||||
//This reads the target offset from the constant buffer.
|
||||
//Almost impossible to support with GLSL.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ShaderIrOperImm Imm = new ShaderIrOperImm(Position + OpCode.Branch());
|
||||
ShaderIrOperImm imm = new ShaderIrOperImm(position + opCode.Branch());
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrOp(ShaderIrInst.Bra, Imm)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrOp(ShaderIrInst.Bra, imm)));
|
||||
}
|
||||
|
||||
public static void Exit(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Exit(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
int CCode = (int)OpCode & 0x1f;
|
||||
int cCode = (int)opCode & 0x1f;
|
||||
|
||||
//TODO: Figure out what the other condition codes mean...
|
||||
if (CCode == 0xf)
|
||||
if (cCode == 0xf)
|
||||
{
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrOp(ShaderIrInst.Exit)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrOp(ShaderIrInst.Exit)));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Kil(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Kil(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrOp(ShaderIrInst.Kil)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrOp(ShaderIrInst.Kil)));
|
||||
}
|
||||
|
||||
public static void Ssy(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Ssy(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
if ((OpCode & 0x20) != 0)
|
||||
if ((opCode & 0x20) != 0)
|
||||
{
|
||||
//This reads the target offset from the constant buffer.
|
||||
//Almost impossible to support with GLSL.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
ShaderIrOperImm Imm = new ShaderIrOperImm(Position + OpCode.Branch());
|
||||
ShaderIrOperImm imm = new ShaderIrOperImm(position + opCode.Branch());
|
||||
|
||||
Block.AddNode(new ShaderIrOp(ShaderIrInst.Ssy, Imm));
|
||||
block.AddNode(new ShaderIrOp(ShaderIrInst.Ssy, imm));
|
||||
}
|
||||
|
||||
public static void Sync(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Sync(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
//TODO: Implement Sync condition codes
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrOp(ShaderIrInst.Sync)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrOp(ShaderIrInst.Sync)));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
namespace Ryujinx.Graphics.Gal.Shader
|
||||
{
|
||||
delegate void ShaderDecodeFunc(ShaderIrBlock Block, long OpCode, int Position);
|
||||
delegate void ShaderDecodeFunc(ShaderIrBlock block, long opCode, int position);
|
||||
}
|
|
@ -5,74 +5,74 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
private static readonly ShaderIrOperImmf ImmfZero = new ShaderIrOperImmf(0);
|
||||
private static readonly ShaderIrOperImmf ImmfOne = new ShaderIrOperImmf(1);
|
||||
|
||||
public static ShaderIrNode GetAluFabsFneg(ShaderIrNode Node, bool Abs, bool Neg)
|
||||
public static ShaderIrNode GetAluFabsFneg(ShaderIrNode node, bool abs, bool neg)
|
||||
{
|
||||
return GetAluFneg(GetAluFabs(Node, Abs), Neg);
|
||||
return GetAluFneg(GetAluFabs(node, abs), neg);
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluFabs(ShaderIrNode Node, bool Abs)
|
||||
public static ShaderIrNode GetAluFabs(ShaderIrNode node, bool abs)
|
||||
{
|
||||
return Abs ? new ShaderIrOp(ShaderIrInst.Fabs, Node) : Node;
|
||||
return abs ? new ShaderIrOp(ShaderIrInst.Fabs, node) : node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluFneg(ShaderIrNode Node, bool Neg)
|
||||
public static ShaderIrNode GetAluFneg(ShaderIrNode node, bool neg)
|
||||
{
|
||||
return Neg ? new ShaderIrOp(ShaderIrInst.Fneg, Node) : Node;
|
||||
return neg ? new ShaderIrOp(ShaderIrInst.Fneg, node) : node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluFsat(ShaderIrNode Node, bool Sat)
|
||||
public static ShaderIrNode GetAluFsat(ShaderIrNode node, bool sat)
|
||||
{
|
||||
return Sat ? new ShaderIrOp(ShaderIrInst.Fclamp, Node, ImmfZero, ImmfOne) : Node;
|
||||
return sat ? new ShaderIrOp(ShaderIrInst.Fclamp, node, ImmfZero, ImmfOne) : node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluIabsIneg(ShaderIrNode Node, bool Abs, bool Neg)
|
||||
public static ShaderIrNode GetAluIabsIneg(ShaderIrNode node, bool abs, bool neg)
|
||||
{
|
||||
return GetAluIneg(GetAluIabs(Node, Abs), Neg);
|
||||
return GetAluIneg(GetAluIabs(node, abs), neg);
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluIabs(ShaderIrNode Node, bool Abs)
|
||||
public static ShaderIrNode GetAluIabs(ShaderIrNode node, bool abs)
|
||||
{
|
||||
return Abs ? new ShaderIrOp(ShaderIrInst.Abs, Node) : Node;
|
||||
return abs ? new ShaderIrOp(ShaderIrInst.Abs, node) : node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluIneg(ShaderIrNode Node, bool Neg)
|
||||
public static ShaderIrNode GetAluIneg(ShaderIrNode node, bool neg)
|
||||
{
|
||||
return Neg ? new ShaderIrOp(ShaderIrInst.Neg, Node) : Node;
|
||||
return neg ? new ShaderIrOp(ShaderIrInst.Neg, node) : node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode GetAluNot(ShaderIrNode Node, bool Not)
|
||||
public static ShaderIrNode GetAluNot(ShaderIrNode node, bool not)
|
||||
{
|
||||
return Not ? new ShaderIrOp(ShaderIrInst.Not, Node) : Node;
|
||||
return not ? new ShaderIrOp(ShaderIrInst.Not, node) : node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode ExtendTo32(ShaderIrNode Node, bool Signed, int Size)
|
||||
public static ShaderIrNode ExtendTo32(ShaderIrNode node, bool signed, int size)
|
||||
{
|
||||
int Shift = 32 - Size;
|
||||
int shift = 32 - size;
|
||||
|
||||
ShaderIrInst RightShift = Signed
|
||||
ShaderIrInst rightShift = signed
|
||||
? ShaderIrInst.Asr
|
||||
: ShaderIrInst.Lsr;
|
||||
|
||||
Node = new ShaderIrOp(ShaderIrInst.Lsl, Node, new ShaderIrOperImm(Shift));
|
||||
Node = new ShaderIrOp(RightShift, Node, new ShaderIrOperImm(Shift));
|
||||
node = new ShaderIrOp(ShaderIrInst.Lsl, node, new ShaderIrOperImm(shift));
|
||||
node = new ShaderIrOp(rightShift, node, new ShaderIrOperImm(shift));
|
||||
|
||||
return Node;
|
||||
return node;
|
||||
}
|
||||
|
||||
public static ShaderIrNode ExtendTo32(ShaderIrNode Node, bool Signed, ShaderIrNode Size)
|
||||
public static ShaderIrNode ExtendTo32(ShaderIrNode node, bool signed, ShaderIrNode size)
|
||||
{
|
||||
ShaderIrOperImm WordSize = new ShaderIrOperImm(32);
|
||||
ShaderIrOperImm wordSize = new ShaderIrOperImm(32);
|
||||
|
||||
ShaderIrOp Shift = new ShaderIrOp(ShaderIrInst.Sub, WordSize, Size);
|
||||
ShaderIrOp shift = new ShaderIrOp(ShaderIrInst.Sub, wordSize, size);
|
||||
|
||||
ShaderIrInst RightShift = Signed
|
||||
ShaderIrInst rightShift = signed
|
||||
? ShaderIrInst.Asr
|
||||
: ShaderIrInst.Lsr;
|
||||
|
||||
Node = new ShaderIrOp(ShaderIrInst.Lsl, Node, Shift);
|
||||
Node = new ShaderIrOp(RightShift, Node, Shift);
|
||||
node = new ShaderIrOp(ShaderIrInst.Lsl, node, shift);
|
||||
node = new ShaderIrOp(rightShift, node, shift);
|
||||
|
||||
return Node;
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -25,400 +25,400 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
F64 = 3
|
||||
}
|
||||
|
||||
public static void F2f_C(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void F2f_C(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitF2f(Block, OpCode, ShaderOper.CR);
|
||||
EmitF2F(block, opCode, ShaderOper.Cr);
|
||||
}
|
||||
|
||||
public static void F2f_I(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void F2f_I(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitF2f(Block, OpCode, ShaderOper.Immf);
|
||||
EmitF2F(block, opCode, ShaderOper.Immf);
|
||||
}
|
||||
|
||||
public static void F2f_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void F2f_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitF2f(Block, OpCode, ShaderOper.RR);
|
||||
EmitF2F(block, opCode, ShaderOper.Rr);
|
||||
}
|
||||
|
||||
public static void F2i_C(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void F2i_C(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitF2i(Block, OpCode, ShaderOper.CR);
|
||||
EmitF2I(block, opCode, ShaderOper.Cr);
|
||||
}
|
||||
|
||||
public static void F2i_I(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void F2i_I(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitF2i(Block, OpCode, ShaderOper.Immf);
|
||||
EmitF2I(block, opCode, ShaderOper.Immf);
|
||||
}
|
||||
|
||||
public static void F2i_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void F2i_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitF2i(Block, OpCode, ShaderOper.RR);
|
||||
EmitF2I(block, opCode, ShaderOper.Rr);
|
||||
}
|
||||
|
||||
public static void I2f_C(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void I2f_C(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitI2f(Block, OpCode, ShaderOper.CR);
|
||||
EmitI2F(block, opCode, ShaderOper.Cr);
|
||||
}
|
||||
|
||||
public static void I2f_I(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void I2f_I(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitI2f(Block, OpCode, ShaderOper.Imm);
|
||||
EmitI2F(block, opCode, ShaderOper.Imm);
|
||||
}
|
||||
|
||||
public static void I2f_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void I2f_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitI2f(Block, OpCode, ShaderOper.RR);
|
||||
EmitI2F(block, opCode, ShaderOper.Rr);
|
||||
}
|
||||
|
||||
public static void I2i_C(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void I2i_C(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitI2i(Block, OpCode, ShaderOper.CR);
|
||||
EmitI2I(block, opCode, ShaderOper.Cr);
|
||||
}
|
||||
|
||||
public static void I2i_I(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void I2i_I(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitI2i(Block, OpCode, ShaderOper.Imm);
|
||||
EmitI2I(block, opCode, ShaderOper.Imm);
|
||||
}
|
||||
|
||||
public static void I2i_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void I2i_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitI2i(Block, OpCode, ShaderOper.RR);
|
||||
EmitI2I(block, opCode, ShaderOper.Rr);
|
||||
}
|
||||
|
||||
public static void Isberd(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Isberd(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
//This instruction seems to be used to translate from an address to a vertex index in a GS
|
||||
//Stub it as such
|
||||
|
||||
Block.AddNode(new ShaderIrCmnt("Stubbed."));
|
||||
block.AddNode(new ShaderIrCmnt("Stubbed."));
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OpCode.Gpr8())));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), opCode.Gpr8())));
|
||||
}
|
||||
|
||||
public static void Mov_C(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Mov_C(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
ShaderIrOperCbuf Cbuf = OpCode.Cbuf34();
|
||||
ShaderIrOperCbuf cbuf = opCode.Cbuf34();
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Cbuf)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), cbuf)));
|
||||
}
|
||||
|
||||
public static void Mov_I(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Mov_I(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
ShaderIrOperImm Imm = OpCode.Imm19_20();
|
||||
ShaderIrOperImm imm = opCode.Imm19_20();
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Imm)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), imm)));
|
||||
}
|
||||
|
||||
public static void Mov_I32(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Mov_I32(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
ShaderIrOperImm Imm = OpCode.Imm32_20();
|
||||
ShaderIrOperImm imm = opCode.Imm32_20();
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Imm)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), imm)));
|
||||
}
|
||||
|
||||
public static void Mov_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Mov_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
ShaderIrOperGpr Gpr = OpCode.Gpr20();
|
||||
ShaderIrOperGpr gpr = opCode.Gpr20();
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Gpr)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), gpr)));
|
||||
}
|
||||
|
||||
public static void Sel_C(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Sel_C(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitSel(Block, OpCode, ShaderOper.CR);
|
||||
EmitSel(block, opCode, ShaderOper.Cr);
|
||||
}
|
||||
|
||||
public static void Sel_I(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Sel_I(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitSel(Block, OpCode, ShaderOper.Imm);
|
||||
EmitSel(block, opCode, ShaderOper.Imm);
|
||||
}
|
||||
|
||||
public static void Sel_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Sel_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
EmitSel(Block, OpCode, ShaderOper.RR);
|
||||
EmitSel(block, opCode, ShaderOper.Rr);
|
||||
}
|
||||
|
||||
public static void Mov_S(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Mov_S(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
Block.AddNode(new ShaderIrCmnt("Stubbed."));
|
||||
block.AddNode(new ShaderIrCmnt("Stubbed."));
|
||||
|
||||
//Zero is used as a special number to get a valid "0 * 0 + VertexIndex" in a GS
|
||||
ShaderIrNode Source = new ShaderIrOperImm(0);
|
||||
ShaderIrNode source = new ShaderIrOperImm(0);
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Source)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), source)));
|
||||
}
|
||||
|
||||
private static void EmitF2f(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
||||
private static void EmitF2F(ShaderIrBlock block, long opCode, ShaderOper oper)
|
||||
{
|
||||
bool NegA = OpCode.Read(45);
|
||||
bool AbsA = OpCode.Read(49);
|
||||
bool negA = opCode.Read(45);
|
||||
bool absA = opCode.Read(49);
|
||||
|
||||
ShaderIrNode OperA;
|
||||
ShaderIrNode operA;
|
||||
|
||||
switch (Oper)
|
||||
switch (oper)
|
||||
{
|
||||
case ShaderOper.CR: OperA = OpCode.Cbuf34(); break;
|
||||
case ShaderOper.Immf: OperA = OpCode.Immf19_20(); break;
|
||||
case ShaderOper.RR: OperA = OpCode.Gpr20(); break;
|
||||
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
||||
case ShaderOper.Immf: operA = opCode.Immf19_20(); break;
|
||||
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
||||
|
||||
default: throw new ArgumentException(nameof(Oper));
|
||||
default: throw new ArgumentException(nameof(oper));
|
||||
}
|
||||
|
||||
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
||||
operA = GetAluFabsFneg(operA, absA, negA);
|
||||
|
||||
ShaderIrInst RoundInst = GetRoundInst(OpCode);
|
||||
ShaderIrInst roundInst = GetRoundInst(opCode);
|
||||
|
||||
if (RoundInst != ShaderIrInst.Invalid)
|
||||
if (roundInst != ShaderIrInst.Invalid)
|
||||
{
|
||||
OperA = new ShaderIrOp(RoundInst, OperA);
|
||||
operA = new ShaderIrOp(roundInst, operA);
|
||||
}
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OperA)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), operA)));
|
||||
}
|
||||
|
||||
private static void EmitF2i(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
||||
private static void EmitF2I(ShaderIrBlock block, long opCode, ShaderOper oper)
|
||||
{
|
||||
IntType Type = GetIntType(OpCode);
|
||||
IntType type = GetIntType(opCode);
|
||||
|
||||
if (Type == IntType.U64 ||
|
||||
Type == IntType.S64)
|
||||
if (type == IntType.U64 ||
|
||||
type == IntType.S64)
|
||||
{
|
||||
//TODO: 64-bits support.
|
||||
//Note: GLSL doesn't support 64-bits integers.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
bool NegA = OpCode.Read(45);
|
||||
bool AbsA = OpCode.Read(49);
|
||||
bool negA = opCode.Read(45);
|
||||
bool absA = opCode.Read(49);
|
||||
|
||||
ShaderIrNode OperA;
|
||||
ShaderIrNode operA;
|
||||
|
||||
switch (Oper)
|
||||
switch (oper)
|
||||
{
|
||||
case ShaderOper.CR: OperA = OpCode.Cbuf34(); break;
|
||||
case ShaderOper.Immf: OperA = OpCode.Immf19_20(); break;
|
||||
case ShaderOper.RR: OperA = OpCode.Gpr20(); break;
|
||||
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
||||
case ShaderOper.Immf: operA = opCode.Immf19_20(); break;
|
||||
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
||||
|
||||
default: throw new ArgumentException(nameof(Oper));
|
||||
default: throw new ArgumentException(nameof(oper));
|
||||
}
|
||||
|
||||
OperA = GetAluFabsFneg(OperA, AbsA, NegA);
|
||||
operA = GetAluFabsFneg(operA, absA, negA);
|
||||
|
||||
ShaderIrInst RoundInst = GetRoundInst(OpCode);
|
||||
ShaderIrInst roundInst = GetRoundInst(opCode);
|
||||
|
||||
if (RoundInst != ShaderIrInst.Invalid)
|
||||
if (roundInst != ShaderIrInst.Invalid)
|
||||
{
|
||||
OperA = new ShaderIrOp(RoundInst, OperA);
|
||||
operA = new ShaderIrOp(roundInst, operA);
|
||||
}
|
||||
|
||||
bool Signed = Type >= IntType.S8;
|
||||
bool signed = type >= IntType.S8;
|
||||
|
||||
int Size = 8 << ((int)Type & 3);
|
||||
int size = 8 << ((int)type & 3);
|
||||
|
||||
if (Size < 32)
|
||||
if (size < 32)
|
||||
{
|
||||
uint Mask = uint.MaxValue >> (32 - Size);
|
||||
uint mask = uint.MaxValue >> (32 - size);
|
||||
|
||||
float CMin = 0;
|
||||
float CMax = Mask;
|
||||
float cMin = 0;
|
||||
float cMax = mask;
|
||||
|
||||
if (Signed)
|
||||
if (signed)
|
||||
{
|
||||
uint HalfMask = Mask >> 1;
|
||||
uint halfMask = mask >> 1;
|
||||
|
||||
CMin -= HalfMask + 1;
|
||||
CMax = HalfMask;
|
||||
cMin -= halfMask + 1;
|
||||
cMax = halfMask;
|
||||
}
|
||||
|
||||
ShaderIrOperImmf IMin = new ShaderIrOperImmf(CMin);
|
||||
ShaderIrOperImmf IMax = new ShaderIrOperImmf(CMax);
|
||||
ShaderIrOperImmf min = new ShaderIrOperImmf(cMin);
|
||||
ShaderIrOperImmf max = new ShaderIrOperImmf(cMax);
|
||||
|
||||
OperA = new ShaderIrOp(ShaderIrInst.Fclamp, OperA, IMin, IMax);
|
||||
operA = new ShaderIrOp(ShaderIrInst.Fclamp, operA, min, max);
|
||||
}
|
||||
|
||||
ShaderIrInst Inst = Signed
|
||||
ShaderIrInst inst = signed
|
||||
? ShaderIrInst.Ftos
|
||||
: ShaderIrInst.Ftou;
|
||||
|
||||
ShaderIrNode Op = new ShaderIrOp(Inst, OperA);
|
||||
ShaderIrNode op = new ShaderIrOp(inst, operA);
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), op)));
|
||||
}
|
||||
|
||||
private static void EmitI2f(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
||||
private static void EmitI2F(ShaderIrBlock block, long opCode, ShaderOper oper)
|
||||
{
|
||||
IntType Type = GetIntType(OpCode);
|
||||
IntType type = GetIntType(opCode);
|
||||
|
||||
if (Type == IntType.U64 ||
|
||||
Type == IntType.S64)
|
||||
if (type == IntType.U64 ||
|
||||
type == IntType.S64)
|
||||
{
|
||||
//TODO: 64-bits support.
|
||||
//Note: GLSL doesn't support 64-bits integers.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int Sel = OpCode.Read(41, 3);
|
||||
int sel = opCode.Read(41, 3);
|
||||
|
||||
bool NegA = OpCode.Read(45);
|
||||
bool AbsA = OpCode.Read(49);
|
||||
bool negA = opCode.Read(45);
|
||||
bool absA = opCode.Read(49);
|
||||
|
||||
ShaderIrNode OperA;
|
||||
ShaderIrNode operA;
|
||||
|
||||
switch (Oper)
|
||||
switch (oper)
|
||||
{
|
||||
case ShaderOper.CR: OperA = OpCode.Cbuf34(); break;
|
||||
case ShaderOper.Imm: OperA = OpCode.Imm19_20(); break;
|
||||
case ShaderOper.RR: OperA = OpCode.Gpr20(); break;
|
||||
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
||||
case ShaderOper.Imm: operA = opCode.Imm19_20(); break;
|
||||
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
||||
|
||||
default: throw new ArgumentException(nameof(Oper));
|
||||
default: throw new ArgumentException(nameof(oper));
|
||||
}
|
||||
|
||||
OperA = GetAluIabsIneg(OperA, AbsA, NegA);
|
||||
operA = GetAluIabsIneg(operA, absA, negA);
|
||||
|
||||
bool Signed = Type >= IntType.S8;
|
||||
bool signed = type >= IntType.S8;
|
||||
|
||||
int Shift = Sel * 8;
|
||||
int shift = sel * 8;
|
||||
|
||||
int Size = 8 << ((int)Type & 3);
|
||||
int size = 8 << ((int)type & 3);
|
||||
|
||||
if (Shift != 0)
|
||||
if (shift != 0)
|
||||
{
|
||||
OperA = new ShaderIrOp(ShaderIrInst.Asr, OperA, new ShaderIrOperImm(Shift));
|
||||
operA = new ShaderIrOp(ShaderIrInst.Asr, operA, new ShaderIrOperImm(shift));
|
||||
}
|
||||
|
||||
if (Size < 32)
|
||||
if (size < 32)
|
||||
{
|
||||
OperA = ExtendTo32(OperA, Signed, Size);
|
||||
operA = ExtendTo32(operA, signed, size);
|
||||
}
|
||||
|
||||
ShaderIrInst Inst = Signed
|
||||
ShaderIrInst inst = signed
|
||||
? ShaderIrInst.Stof
|
||||
: ShaderIrInst.Utof;
|
||||
|
||||
ShaderIrNode Op = new ShaderIrOp(Inst, OperA);
|
||||
ShaderIrNode op = new ShaderIrOp(inst, operA);
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), Op)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), op)));
|
||||
}
|
||||
|
||||
private static void EmitI2i(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
||||
private static void EmitI2I(ShaderIrBlock block, long opCode, ShaderOper oper)
|
||||
{
|
||||
IntType Type = GetIntType(OpCode);
|
||||
IntType type = GetIntType(opCode);
|
||||
|
||||
if (Type == IntType.U64 ||
|
||||
Type == IntType.S64)
|
||||
if (type == IntType.U64 ||
|
||||
type == IntType.S64)
|
||||
{
|
||||
//TODO: 64-bits support.
|
||||
//Note: GLSL doesn't support 64-bits integers.
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
int Sel = OpCode.Read(41, 3);
|
||||
int sel = opCode.Read(41, 3);
|
||||
|
||||
bool NegA = OpCode.Read(45);
|
||||
bool AbsA = OpCode.Read(49);
|
||||
bool SatA = OpCode.Read(50);
|
||||
bool negA = opCode.Read(45);
|
||||
bool absA = opCode.Read(49);
|
||||
bool satA = opCode.Read(50);
|
||||
|
||||
ShaderIrNode OperA;
|
||||
ShaderIrNode operA;
|
||||
|
||||
switch (Oper)
|
||||
switch (oper)
|
||||
{
|
||||
case ShaderOper.CR: OperA = OpCode.Cbuf34(); break;
|
||||
case ShaderOper.Immf: OperA = OpCode.Immf19_20(); break;
|
||||
case ShaderOper.RR: OperA = OpCode.Gpr20(); break;
|
||||
case ShaderOper.Cr: operA = opCode.Cbuf34(); break;
|
||||
case ShaderOper.Immf: operA = opCode.Immf19_20(); break;
|
||||
case ShaderOper.Rr: operA = opCode.Gpr20(); break;
|
||||
|
||||
default: throw new ArgumentException(nameof(Oper));
|
||||
default: throw new ArgumentException(nameof(oper));
|
||||
}
|
||||
|
||||
OperA = GetAluIabsIneg(OperA, AbsA, NegA);
|
||||
operA = GetAluIabsIneg(operA, absA, negA);
|
||||
|
||||
bool Signed = Type >= IntType.S8;
|
||||
bool signed = type >= IntType.S8;
|
||||
|
||||
int Shift = Sel * 8;
|
||||
int shift = sel * 8;
|
||||
|
||||
int Size = 8 << ((int)Type & 3);
|
||||
int size = 8 << ((int)type & 3);
|
||||
|
||||
if (Shift != 0)
|
||||
if (shift != 0)
|
||||
{
|
||||
OperA = new ShaderIrOp(ShaderIrInst.Asr, OperA, new ShaderIrOperImm(Shift));
|
||||
operA = new ShaderIrOp(ShaderIrInst.Asr, operA, new ShaderIrOperImm(shift));
|
||||
}
|
||||
|
||||
if (Size < 32)
|
||||
if (size < 32)
|
||||
{
|
||||
uint Mask = uint.MaxValue >> (32 - Size);
|
||||
uint mask = uint.MaxValue >> (32 - size);
|
||||
|
||||
if (SatA)
|
||||
if (satA)
|
||||
{
|
||||
uint CMin = 0;
|
||||
uint CMax = Mask;
|
||||
uint cMin = 0;
|
||||
uint cMax = mask;
|
||||
|
||||
if (Signed)
|
||||
if (signed)
|
||||
{
|
||||
uint HalfMask = Mask >> 1;
|
||||
uint halfMask = mask >> 1;
|
||||
|
||||
CMin -= HalfMask + 1;
|
||||
CMax = HalfMask;
|
||||
cMin -= halfMask + 1;
|
||||
cMax = halfMask;
|
||||
}
|
||||
|
||||
ShaderIrOperImm IMin = new ShaderIrOperImm((int)CMin);
|
||||
ShaderIrOperImm IMax = new ShaderIrOperImm((int)CMax);
|
||||
ShaderIrOperImm min = new ShaderIrOperImm((int)cMin);
|
||||
ShaderIrOperImm max = new ShaderIrOperImm((int)cMax);
|
||||
|
||||
OperA = new ShaderIrOp(Signed
|
||||
operA = new ShaderIrOp(signed
|
||||
? ShaderIrInst.Clamps
|
||||
: ShaderIrInst.Clampu, OperA, IMin, IMax);
|
||||
: ShaderIrInst.Clampu, operA, min, max);
|
||||
}
|
||||
else
|
||||
{
|
||||
OperA = ExtendTo32(OperA, Signed, Size);
|
||||
operA = ExtendTo32(operA, signed, size);
|
||||
}
|
||||
}
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrAsg(OpCode.Gpr0(), OperA)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrAsg(opCode.Gpr0(), operA)));
|
||||
}
|
||||
|
||||
private static void EmitSel(ShaderIrBlock Block, long OpCode, ShaderOper Oper)
|
||||
private static void EmitSel(ShaderIrBlock block, long opCode, ShaderOper oper)
|
||||
{
|
||||
ShaderIrOperGpr Dst = OpCode.Gpr0();
|
||||
ShaderIrNode Pred = OpCode.Pred39N();
|
||||
ShaderIrOperGpr dst = opCode.Gpr0();
|
||||
ShaderIrNode pred = opCode.Pred39N();
|
||||
|
||||
ShaderIrNode ResultA = OpCode.Gpr8();
|
||||
ShaderIrNode ResultB;
|
||||
ShaderIrNode resultA = opCode.Gpr8();
|
||||
ShaderIrNode resultB;
|
||||
|
||||
switch (Oper)
|
||||
switch (oper)
|
||||
{
|
||||
case ShaderOper.CR: ResultB = OpCode.Cbuf34(); break;
|
||||
case ShaderOper.Imm: ResultB = OpCode.Imm19_20(); break;
|
||||
case ShaderOper.RR: ResultB = OpCode.Gpr20(); break;
|
||||
case ShaderOper.Cr: resultB = opCode.Cbuf34(); break;
|
||||
case ShaderOper.Imm: resultB = opCode.Imm19_20(); break;
|
||||
case ShaderOper.Rr: resultB = opCode.Gpr20(); break;
|
||||
|
||||
default: throw new ArgumentException(nameof(Oper));
|
||||
default: throw new ArgumentException(nameof(oper));
|
||||
}
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrCond(Pred, new ShaderIrAsg(Dst, ResultA), false)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrCond(pred, new ShaderIrAsg(dst, resultA), false)));
|
||||
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrCond(Pred, new ShaderIrAsg(Dst, ResultB), true)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrCond(pred, new ShaderIrAsg(dst, resultB), true)));
|
||||
}
|
||||
|
||||
private static IntType GetIntType(long OpCode)
|
||||
private static IntType GetIntType(long opCode)
|
||||
{
|
||||
bool Signed = OpCode.Read(13);
|
||||
bool signed = opCode.Read(13);
|
||||
|
||||
IntType Type = (IntType)(OpCode.Read(10, 3));
|
||||
IntType type = (IntType)(opCode.Read(10, 3));
|
||||
|
||||
if (Signed)
|
||||
if (signed)
|
||||
{
|
||||
Type += (int)IntType.S8;
|
||||
type += (int)IntType.S8;
|
||||
}
|
||||
|
||||
return Type;
|
||||
return type;
|
||||
}
|
||||
|
||||
private static FloatType GetFloatType(long OpCode)
|
||||
private static FloatType GetFloatType(long opCode)
|
||||
{
|
||||
return (FloatType)(OpCode.Read(8, 3));
|
||||
return (FloatType)(opCode.Read(8, 3));
|
||||
}
|
||||
|
||||
private static ShaderIrInst GetRoundInst(long OpCode)
|
||||
private static ShaderIrInst GetRoundInst(long opCode)
|
||||
{
|
||||
switch (OpCode.Read(39, 3))
|
||||
switch (opCode.Read(39, 3))
|
||||
{
|
||||
case 1: return ShaderIrInst.Floor;
|
||||
case 2: return ShaderIrInst.Ceil;
|
||||
|
|
|
@ -4,227 +4,227 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
static partial class ShaderDecode
|
||||
{
|
||||
private static int Read(this long OpCode, int Position, int Mask)
|
||||
private static int Read(this long opCode, int position, int mask)
|
||||
{
|
||||
return (int)(OpCode >> Position) & Mask;
|
||||
return (int)(opCode >> position) & mask;
|
||||
}
|
||||
|
||||
private static bool Read(this long OpCode, int Position)
|
||||
private static bool Read(this long opCode, int position)
|
||||
{
|
||||
return ((OpCode >> Position) & 1) != 0;
|
||||
return ((opCode >> position) & 1) != 0;
|
||||
}
|
||||
|
||||
private static int Branch(this long OpCode)
|
||||
private static int Branch(this long opCode)
|
||||
{
|
||||
return ((int)(OpCode >> 20) << 8) >> 8;
|
||||
return ((int)(opCode >> 20) << 8) >> 8;
|
||||
}
|
||||
|
||||
private static bool HasArray(this long OpCode)
|
||||
private static bool HasArray(this long opCode)
|
||||
{
|
||||
return OpCode.Read(0x1c);
|
||||
return opCode.Read(0x1c);
|
||||
}
|
||||
|
||||
private static ShaderIrOperAbuf[] Abuf20(this long OpCode)
|
||||
private static ShaderIrOperAbuf[] Abuf20(this long opCode)
|
||||
{
|
||||
int Abuf = OpCode.Read(20, 0x3ff);
|
||||
int Size = OpCode.Read(47, 3);
|
||||
int abuf = opCode.Read(20, 0x3ff);
|
||||
int size = opCode.Read(47, 3);
|
||||
|
||||
ShaderIrOperGpr Vertex = OpCode.Gpr39();
|
||||
ShaderIrOperGpr vertex = opCode.Gpr39();
|
||||
|
||||
ShaderIrOperAbuf[] Opers = new ShaderIrOperAbuf[Size + 1];
|
||||
ShaderIrOperAbuf[] opers = new ShaderIrOperAbuf[size + 1];
|
||||
|
||||
for (int Index = 0; Index <= Size; Index++)
|
||||
for (int index = 0; index <= size; index++)
|
||||
{
|
||||
Opers[Index] = new ShaderIrOperAbuf(Abuf + Index * 4, Vertex);
|
||||
opers[index] = new ShaderIrOperAbuf(abuf + index * 4, vertex);
|
||||
}
|
||||
|
||||
return Opers;
|
||||
return opers;
|
||||
}
|
||||
|
||||
private static ShaderIrOperAbuf Abuf28(this long OpCode)
|
||||
private static ShaderIrOperAbuf Abuf28(this long opCode)
|
||||
{
|
||||
int Abuf = OpCode.Read(28, 0x3ff);
|
||||
int abuf = opCode.Read(28, 0x3ff);
|
||||
|
||||
return new ShaderIrOperAbuf(Abuf, OpCode.Gpr39());
|
||||
return new ShaderIrOperAbuf(abuf, opCode.Gpr39());
|
||||
}
|
||||
|
||||
private static ShaderIrOperCbuf Cbuf34(this long OpCode)
|
||||
private static ShaderIrOperCbuf Cbuf34(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperCbuf(
|
||||
OpCode.Read(34, 0x1f),
|
||||
OpCode.Read(20, 0x3fff));
|
||||
opCode.Read(34, 0x1f),
|
||||
opCode.Read(20, 0x3fff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr Gpr8(this long OpCode)
|
||||
private static ShaderIrOperGpr Gpr8(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(8, 0xff));
|
||||
return new ShaderIrOperGpr(opCode.Read(8, 0xff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr Gpr20(this long OpCode)
|
||||
private static ShaderIrOperGpr Gpr20(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(20, 0xff));
|
||||
return new ShaderIrOperGpr(opCode.Read(20, 0xff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr Gpr39(this long OpCode)
|
||||
private static ShaderIrOperGpr Gpr39(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(39, 0xff));
|
||||
return new ShaderIrOperGpr(opCode.Read(39, 0xff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr Gpr0(this long OpCode)
|
||||
private static ShaderIrOperGpr Gpr0(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(0, 0xff));
|
||||
return new ShaderIrOperGpr(opCode.Read(0, 0xff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr Gpr28(this long OpCode)
|
||||
private static ShaderIrOperGpr Gpr28(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(28, 0xff));
|
||||
return new ShaderIrOperGpr(opCode.Read(28, 0xff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr[] GprHalfVec8(this long OpCode)
|
||||
private static ShaderIrOperGpr[] GprHalfVec8(this long opCode)
|
||||
{
|
||||
return GetGprHalfVec2(OpCode.Read(8, 0xff), OpCode.Read(47, 3));
|
||||
return GetGprHalfVec2(opCode.Read(8, 0xff), opCode.Read(47, 3));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr[] GprHalfVec20(this long OpCode)
|
||||
private static ShaderIrOperGpr[] GprHalfVec20(this long opCode)
|
||||
{
|
||||
return GetGprHalfVec2(OpCode.Read(20, 0xff), OpCode.Read(28, 3));
|
||||
return GetGprHalfVec2(opCode.Read(20, 0xff), opCode.Read(28, 3));
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr[] GetGprHalfVec2(int Gpr, int Mask)
|
||||
private static ShaderIrOperGpr[] GetGprHalfVec2(int gpr, int mask)
|
||||
{
|
||||
if (Mask == 1)
|
||||
if (mask == 1)
|
||||
{
|
||||
//This value is used for FP32, the whole 32-bits register
|
||||
//is used as each element on the vector.
|
||||
return new ShaderIrOperGpr[]
|
||||
{
|
||||
new ShaderIrOperGpr(Gpr),
|
||||
new ShaderIrOperGpr(Gpr)
|
||||
new ShaderIrOperGpr(gpr),
|
||||
new ShaderIrOperGpr(gpr)
|
||||
};
|
||||
}
|
||||
|
||||
ShaderIrOperGpr Low = new ShaderIrOperGpr(Gpr, 0);
|
||||
ShaderIrOperGpr High = new ShaderIrOperGpr(Gpr, 1);
|
||||
ShaderIrOperGpr low = new ShaderIrOperGpr(gpr, 0);
|
||||
ShaderIrOperGpr high = new ShaderIrOperGpr(gpr, 1);
|
||||
|
||||
return new ShaderIrOperGpr[]
|
||||
{
|
||||
(Mask & 1) != 0 ? High : Low,
|
||||
(Mask & 2) != 0 ? High : Low
|
||||
(mask & 1) != 0 ? high : low,
|
||||
(mask & 2) != 0 ? high : low
|
||||
};
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr GprHalf0(this long OpCode, int HalfPart)
|
||||
private static ShaderIrOperGpr GprHalf0(this long opCode, int halfPart)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(0, 0xff), HalfPart);
|
||||
return new ShaderIrOperGpr(opCode.Read(0, 0xff), halfPart);
|
||||
}
|
||||
|
||||
private static ShaderIrOperGpr GprHalf28(this long OpCode, int HalfPart)
|
||||
private static ShaderIrOperGpr GprHalf28(this long opCode, int halfPart)
|
||||
{
|
||||
return new ShaderIrOperGpr(OpCode.Read(28, 0xff), HalfPart);
|
||||
return new ShaderIrOperGpr(opCode.Read(28, 0xff), halfPart);
|
||||
}
|
||||
|
||||
private static ShaderIrOperImm Imm5_39(this long OpCode)
|
||||
private static ShaderIrOperImm Imm5_39(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperImm(OpCode.Read(39, 0x1f));
|
||||
return new ShaderIrOperImm(opCode.Read(39, 0x1f));
|
||||
}
|
||||
|
||||
private static ShaderIrOperImm Imm13_36(this long OpCode)
|
||||
private static ShaderIrOperImm Imm13_36(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperImm(OpCode.Read(36, 0x1fff));
|
||||
return new ShaderIrOperImm(opCode.Read(36, 0x1fff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperImm Imm32_20(this long OpCode)
|
||||
private static ShaderIrOperImm Imm32_20(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperImm((int)(OpCode >> 20));
|
||||
return new ShaderIrOperImm((int)(opCode >> 20));
|
||||
}
|
||||
|
||||
private static ShaderIrOperImmf Immf32_20(this long OpCode)
|
||||
private static ShaderIrOperImmf Immf32_20(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperImmf(BitConverter.Int32BitsToSingle((int)(OpCode >> 20)));
|
||||
return new ShaderIrOperImmf(BitConverter.Int32BitsToSingle((int)(opCode >> 20)));
|
||||
}
|
||||
|
||||
private static ShaderIrOperImm ImmU16_20(this long OpCode)
|
||||
private static ShaderIrOperImm ImmU16_20(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperImm(OpCode.Read(20, 0xffff));
|
||||
return new ShaderIrOperImm(opCode.Read(20, 0xffff));
|
||||
}
|
||||
|
||||
private static ShaderIrOperImm Imm19_20(this long OpCode)
|
||||
private static ShaderIrOperImm Imm19_20(this long opCode)
|
||||
{
|
||||
int Value = OpCode.Read(20, 0x7ffff);
|
||||
int value = opCode.Read(20, 0x7ffff);
|
||||
|
||||
bool Neg = OpCode.Read(56);
|
||||
bool neg = opCode.Read(56);
|
||||
|
||||
if (Neg)
|
||||
if (neg)
|
||||
{
|
||||
Value = -Value;
|
||||
value = -value;
|
||||
}
|
||||
|
||||
return new ShaderIrOperImm(Value);
|
||||
return new ShaderIrOperImm(value);
|
||||
}
|
||||
|
||||
private static ShaderIrOperImmf Immf19_20(this long OpCode)
|
||||
private static ShaderIrOperImmf Immf19_20(this long opCode)
|
||||
{
|
||||
uint Imm = (uint)(OpCode >> 20) & 0x7ffff;
|
||||
uint imm = (uint)(opCode >> 20) & 0x7ffff;
|
||||
|
||||
bool Neg = OpCode.Read(56);
|
||||
bool neg = opCode.Read(56);
|
||||
|
||||
Imm <<= 12;
|
||||
imm <<= 12;
|
||||
|
||||
if (Neg)
|
||||
if (neg)
|
||||
{
|
||||
Imm |= 0x80000000;
|
||||
imm |= 0x80000000;
|
||||
}
|
||||
|
||||
float Value = BitConverter.Int32BitsToSingle((int)Imm);
|
||||
float value = BitConverter.Int32BitsToSingle((int)imm);
|
||||
|
||||
return new ShaderIrOperImmf(Value);
|
||||
return new ShaderIrOperImmf(value);
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred Pred0(this long OpCode)
|
||||
private static ShaderIrOperPred Pred0(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperPred(OpCode.Read(0, 7));
|
||||
return new ShaderIrOperPred(opCode.Read(0, 7));
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred Pred3(this long OpCode)
|
||||
private static ShaderIrOperPred Pred3(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperPred(OpCode.Read(3, 7));
|
||||
return new ShaderIrOperPred(opCode.Read(3, 7));
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred Pred12(this long OpCode)
|
||||
private static ShaderIrOperPred Pred12(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperPred(OpCode.Read(12, 7));
|
||||
return new ShaderIrOperPred(opCode.Read(12, 7));
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred Pred29(this long OpCode)
|
||||
private static ShaderIrOperPred Pred29(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperPred(OpCode.Read(29, 7));
|
||||
return new ShaderIrOperPred(opCode.Read(29, 7));
|
||||
}
|
||||
|
||||
private static ShaderIrNode Pred39N(this long OpCode)
|
||||
private static ShaderIrNode Pred39N(this long opCode)
|
||||
{
|
||||
ShaderIrNode Node = OpCode.Pred39();
|
||||
ShaderIrNode node = opCode.Pred39();
|
||||
|
||||
if (OpCode.Read(42))
|
||||
if (opCode.Read(42))
|
||||
{
|
||||
Node = new ShaderIrOp(ShaderIrInst.Bnot, Node);
|
||||
node = new ShaderIrOp(ShaderIrInst.Bnot, node);
|
||||
}
|
||||
|
||||
return Node;
|
||||
return node;
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred Pred39(this long OpCode)
|
||||
private static ShaderIrOperPred Pred39(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperPred(OpCode.Read(39, 7));
|
||||
return new ShaderIrOperPred(opCode.Read(39, 7));
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred Pred48(this long OpCode)
|
||||
private static ShaderIrOperPred Pred48(this long opCode)
|
||||
{
|
||||
return new ShaderIrOperPred(OpCode.Read(48, 7));
|
||||
return new ShaderIrOperPred(opCode.Read(48, 7));
|
||||
}
|
||||
|
||||
private static ShaderIrInst Cmp(this long OpCode)
|
||||
private static ShaderIrInst Cmp(this long opCode)
|
||||
{
|
||||
switch (OpCode.Read(49, 7))
|
||||
switch (opCode.Read(49, 7))
|
||||
{
|
||||
case 1: return ShaderIrInst.Clt;
|
||||
case 2: return ShaderIrInst.Ceq;
|
||||
|
@ -234,12 +234,12 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
case 6: return ShaderIrInst.Cge;
|
||||
}
|
||||
|
||||
throw new ArgumentException(nameof(OpCode));
|
||||
throw new ArgumentException(nameof(opCode));
|
||||
}
|
||||
|
||||
private static ShaderIrInst CmpF(this long OpCode)
|
||||
private static ShaderIrInst CmpF(this long opCode)
|
||||
{
|
||||
switch (OpCode.Read(48, 0xf))
|
||||
switch (opCode.Read(48, 0xf))
|
||||
{
|
||||
case 0x1: return ShaderIrInst.Fclt;
|
||||
case 0x2: return ShaderIrInst.Fceq;
|
||||
|
@ -257,57 +257,57 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
case 0xe: return ShaderIrInst.Fcgeu;
|
||||
}
|
||||
|
||||
throw new ArgumentException(nameof(OpCode));
|
||||
throw new ArgumentException(nameof(opCode));
|
||||
}
|
||||
|
||||
private static ShaderIrInst BLop45(this long OpCode)
|
||||
private static ShaderIrInst BLop45(this long opCode)
|
||||
{
|
||||
switch (OpCode.Read(45, 3))
|
||||
switch (opCode.Read(45, 3))
|
||||
{
|
||||
case 0: return ShaderIrInst.Band;
|
||||
case 1: return ShaderIrInst.Bor;
|
||||
case 2: return ShaderIrInst.Bxor;
|
||||
}
|
||||
|
||||
throw new ArgumentException(nameof(OpCode));
|
||||
throw new ArgumentException(nameof(opCode));
|
||||
}
|
||||
|
||||
private static ShaderIrInst BLop24(this long OpCode)
|
||||
private static ShaderIrInst BLop24(this long opCode)
|
||||
{
|
||||
switch (OpCode.Read(24, 3))
|
||||
switch (opCode.Read(24, 3))
|
||||
{
|
||||
case 0: return ShaderIrInst.Band;
|
||||
case 1: return ShaderIrInst.Bor;
|
||||
case 2: return ShaderIrInst.Bxor;
|
||||
}
|
||||
|
||||
throw new ArgumentException(nameof(OpCode));
|
||||
throw new ArgumentException(nameof(opCode));
|
||||
}
|
||||
|
||||
private static ShaderIrNode PredNode(this long OpCode, ShaderIrNode Node)
|
||||
private static ShaderIrNode PredNode(this long opCode, ShaderIrNode node)
|
||||
{
|
||||
ShaderIrOperPred Pred = OpCode.PredNode();
|
||||
ShaderIrOperPred pred = opCode.PredNode();
|
||||
|
||||
if (Pred.Index != ShaderIrOperPred.UnusedIndex)
|
||||
if (pred.Index != ShaderIrOperPred.UnusedIndex)
|
||||
{
|
||||
bool Inv = OpCode.Read(19);
|
||||
bool inv = opCode.Read(19);
|
||||
|
||||
Node = new ShaderIrCond(Pred, Node, Inv);
|
||||
node = new ShaderIrCond(pred, node, inv);
|
||||
}
|
||||
|
||||
return Node;
|
||||
return node;
|
||||
}
|
||||
|
||||
private static ShaderIrOperPred PredNode(this long OpCode)
|
||||
private static ShaderIrOperPred PredNode(this long opCode)
|
||||
{
|
||||
int Pred = OpCode.Read(16, 0xf);
|
||||
int pred = opCode.Read(16, 0xf);
|
||||
|
||||
if (Pred != 0xf)
|
||||
if (pred != 0xf)
|
||||
{
|
||||
Pred &= 7;
|
||||
pred &= 7;
|
||||
}
|
||||
|
||||
return new ShaderIrOperPred(Pred);
|
||||
return new ShaderIrOperPred(pred);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,23 +2,23 @@
|
|||
{
|
||||
static partial class ShaderDecode
|
||||
{
|
||||
public static void Out_R(ShaderIrBlock Block, long OpCode, int Position)
|
||||
public static void Out_R(ShaderIrBlock block, long opCode, int position)
|
||||
{
|
||||
//TODO: Those registers have to be used for something
|
||||
ShaderIrOperGpr Gpr0 = OpCode.Gpr0();
|
||||
ShaderIrOperGpr Gpr8 = OpCode.Gpr8();
|
||||
ShaderIrOperGpr Gpr20 = OpCode.Gpr20();
|
||||
ShaderIrOperGpr gpr0 = opCode.Gpr0();
|
||||
ShaderIrOperGpr gpr8 = opCode.Gpr8();
|
||||
ShaderIrOperGpr gpr20 = opCode.Gpr20();
|
||||
|
||||
int Type = OpCode.Read(39, 3);
|
||||
int type = opCode.Read(39, 3);
|
||||
|
||||
if ((Type & 1) != 0)
|
||||
if ((type & 1) != 0)
|
||||
{
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrOp(ShaderIrInst.Emit)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrOp(ShaderIrInst.Emit)));
|
||||
}
|
||||
|
||||
if ((Type & 2) != 0)
|
||||
if ((type & 2) != 0)
|
||||
{
|
||||
Block.AddNode(OpCode.PredNode(new ShaderIrOp(ShaderIrInst.Cut)));
|
||||
block.AddNode(opCode.PredNode(new ShaderIrOp(ShaderIrInst.Cut)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,74 +8,74 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
private const bool AddDbgComments = true;
|
||||
|
||||
public static ShaderIrBlock[] Decode(IGalMemory Memory, long Start)
|
||||
public static ShaderIrBlock[] Decode(IGalMemory memory, long start)
|
||||
{
|
||||
Dictionary<int, ShaderIrBlock> Visited = new Dictionary<int, ShaderIrBlock>();
|
||||
Dictionary<int, ShaderIrBlock> VisitedEnd = new Dictionary<int, ShaderIrBlock>();
|
||||
Dictionary<int, ShaderIrBlock> visited = new Dictionary<int, ShaderIrBlock>();
|
||||
Dictionary<int, ShaderIrBlock> visitedEnd = new Dictionary<int, ShaderIrBlock>();
|
||||
|
||||
Queue<ShaderIrBlock> Blocks = new Queue<ShaderIrBlock>();
|
||||
Queue<ShaderIrBlock> blocks = new Queue<ShaderIrBlock>();
|
||||
|
||||
long Beginning = Start + HeaderSize;
|
||||
long beginning = start + HeaderSize;
|
||||
|
||||
ShaderIrBlock Enqueue(int Position, ShaderIrBlock Source = null)
|
||||
ShaderIrBlock Enqueue(int position, ShaderIrBlock source = null)
|
||||
{
|
||||
if (!Visited.TryGetValue(Position, out ShaderIrBlock Output))
|
||||
if (!visited.TryGetValue(position, out ShaderIrBlock output))
|
||||
{
|
||||
Output = new ShaderIrBlock(Position);
|
||||
output = new ShaderIrBlock(position);
|
||||
|
||||
Blocks.Enqueue(Output);
|
||||
blocks.Enqueue(output);
|
||||
|
||||
Visited.Add(Position, Output);
|
||||
visited.Add(position, output);
|
||||
}
|
||||
|
||||
if (Source != null)
|
||||
if (source != null)
|
||||
{
|
||||
Output.Sources.Add(Source);
|
||||
output.Sources.Add(source);
|
||||
}
|
||||
|
||||
return Output;
|
||||
return output;
|
||||
}
|
||||
|
||||
ShaderIrBlock Entry = Enqueue(0);
|
||||
ShaderIrBlock entry = Enqueue(0);
|
||||
|
||||
while (Blocks.Count > 0)
|
||||
while (blocks.Count > 0)
|
||||
{
|
||||
ShaderIrBlock Current = Blocks.Dequeue();
|
||||
ShaderIrBlock current = blocks.Dequeue();
|
||||
|
||||
FillBlock(Memory, Current, Beginning);
|
||||
FillBlock(memory, current, beginning);
|
||||
|
||||
//Set child blocks. "Branch" is the block the branch instruction
|
||||
//points to (when taken), "Next" is the block at the next address,
|
||||
//executed when the branch is not taken. For Unconditional Branches
|
||||
//or end of shader, Next is null.
|
||||
if (Current.Nodes.Count > 0)
|
||||
if (current.Nodes.Count > 0)
|
||||
{
|
||||
ShaderIrNode LastNode = Current.GetLastNode();
|
||||
ShaderIrNode lastNode = current.GetLastNode();
|
||||
|
||||
ShaderIrOp InnerOp = GetInnermostOp(LastNode);
|
||||
ShaderIrOp innerOp = GetInnermostOp(lastNode);
|
||||
|
||||
if (InnerOp?.Inst == ShaderIrInst.Bra)
|
||||
if (innerOp?.Inst == ShaderIrInst.Bra)
|
||||
{
|
||||
int Target = ((ShaderIrOperImm)InnerOp.OperandA).Value;
|
||||
int target = ((ShaderIrOperImm)innerOp.OperandA).Value;
|
||||
|
||||
Current.Branch = Enqueue(Target, Current);
|
||||
current.Branch = Enqueue(target, current);
|
||||
}
|
||||
|
||||
foreach (ShaderIrNode Node in Current.Nodes)
|
||||
foreach (ShaderIrNode node in current.Nodes)
|
||||
{
|
||||
InnerOp = GetInnermostOp(Node);
|
||||
innerOp = GetInnermostOp(node);
|
||||
|
||||
if (InnerOp is ShaderIrOp CurrOp && CurrOp.Inst == ShaderIrInst.Ssy)
|
||||
if (innerOp is ShaderIrOp currOp && currOp.Inst == ShaderIrInst.Ssy)
|
||||
{
|
||||
int Target = ((ShaderIrOperImm)CurrOp.OperandA).Value;
|
||||
int target = ((ShaderIrOperImm)currOp.OperandA).Value;
|
||||
|
||||
Enqueue(Target, Current);
|
||||
Enqueue(target, current);
|
||||
}
|
||||
}
|
||||
|
||||
if (NodeHasNext(LastNode))
|
||||
if (NodeHasNext(lastNode))
|
||||
{
|
||||
Current.Next = Enqueue(Current.EndPosition);
|
||||
current.Next = Enqueue(current.EndPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,136 +83,136 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
//then we need to split the bigger block and have two small blocks,
|
||||
//the end position of the bigger "Current" block should then be == to
|
||||
//the position of the "Smaller" block.
|
||||
while (VisitedEnd.TryGetValue(Current.EndPosition, out ShaderIrBlock Smaller))
|
||||
while (visitedEnd.TryGetValue(current.EndPosition, out ShaderIrBlock smaller))
|
||||
{
|
||||
if (Current.Position > Smaller.Position)
|
||||
if (current.Position > smaller.Position)
|
||||
{
|
||||
ShaderIrBlock Temp = Smaller;
|
||||
ShaderIrBlock temp = smaller;
|
||||
|
||||
Smaller = Current;
|
||||
Current = Temp;
|
||||
smaller = current;
|
||||
current = temp;
|
||||
}
|
||||
|
||||
Current.EndPosition = Smaller.Position;
|
||||
Current.Next = Smaller;
|
||||
Current.Branch = null;
|
||||
current.EndPosition = smaller.Position;
|
||||
current.Next = smaller;
|
||||
current.Branch = null;
|
||||
|
||||
Current.Nodes.RemoveRange(
|
||||
Current.Nodes.Count - Smaller.Nodes.Count,
|
||||
Smaller.Nodes.Count);
|
||||
current.Nodes.RemoveRange(
|
||||
current.Nodes.Count - smaller.Nodes.Count,
|
||||
smaller.Nodes.Count);
|
||||
|
||||
VisitedEnd[Smaller.EndPosition] = Smaller;
|
||||
visitedEnd[smaller.EndPosition] = smaller;
|
||||
}
|
||||
|
||||
VisitedEnd.Add(Current.EndPosition, Current);
|
||||
visitedEnd.Add(current.EndPosition, current);
|
||||
}
|
||||
|
||||
//Make and sort Graph blocks array by position.
|
||||
ShaderIrBlock[] Graph = new ShaderIrBlock[Visited.Count];
|
||||
ShaderIrBlock[] graph = new ShaderIrBlock[visited.Count];
|
||||
|
||||
while (Visited.Count > 0)
|
||||
while (visited.Count > 0)
|
||||
{
|
||||
uint FirstPos = uint.MaxValue;
|
||||
uint firstPos = uint.MaxValue;
|
||||
|
||||
foreach (ShaderIrBlock Block in Visited.Values)
|
||||
foreach (ShaderIrBlock block in visited.Values)
|
||||
{
|
||||
if (FirstPos > (uint)Block.Position)
|
||||
FirstPos = (uint)Block.Position;
|
||||
if (firstPos > (uint)block.Position)
|
||||
firstPos = (uint)block.Position;
|
||||
}
|
||||
|
||||
ShaderIrBlock Current = Visited[(int)FirstPos];
|
||||
ShaderIrBlock current = visited[(int)firstPos];
|
||||
|
||||
do
|
||||
{
|
||||
Graph[Graph.Length - Visited.Count] = Current;
|
||||
graph[graph.Length - visited.Count] = current;
|
||||
|
||||
Visited.Remove(Current.Position);
|
||||
visited.Remove(current.Position);
|
||||
|
||||
Current = Current.Next;
|
||||
current = current.Next;
|
||||
}
|
||||
while (Current != null);
|
||||
while (current != null);
|
||||
}
|
||||
|
||||
return Graph;
|
||||
return graph;
|
||||
}
|
||||
|
||||
private static void FillBlock(IGalMemory Memory, ShaderIrBlock Block, long Beginning)
|
||||
private static void FillBlock(IGalMemory memory, ShaderIrBlock block, long beginning)
|
||||
{
|
||||
int Position = Block.Position;
|
||||
int position = block.Position;
|
||||
|
||||
do
|
||||
{
|
||||
//Ignore scheduling instructions, which are written every 32 bytes.
|
||||
if ((Position & 0x1f) == 0)
|
||||
if ((position & 0x1f) == 0)
|
||||
{
|
||||
Position += 8;
|
||||
position += 8;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
uint Word0 = (uint)Memory.ReadInt32(Position + Beginning + 0);
|
||||
uint Word1 = (uint)Memory.ReadInt32(Position + Beginning + 4);
|
||||
uint word0 = (uint)memory.ReadInt32(position + beginning + 0);
|
||||
uint word1 = (uint)memory.ReadInt32(position + beginning + 4);
|
||||
|
||||
Position += 8;
|
||||
position += 8;
|
||||
|
||||
long OpCode = Word0 | (long)Word1 << 32;
|
||||
long opCode = word0 | (long)word1 << 32;
|
||||
|
||||
ShaderDecodeFunc Decode = ShaderOpCodeTable.GetDecoder(OpCode);
|
||||
ShaderDecodeFunc decode = ShaderOpCodeTable.GetDecoder(opCode);
|
||||
|
||||
if (AddDbgComments)
|
||||
{
|
||||
string DbgOpCode = $"0x{(Position - 8):x16}: 0x{OpCode:x16} ";
|
||||
string dbgOpCode = $"0x{(position - 8):x16}: 0x{opCode:x16} ";
|
||||
|
||||
DbgOpCode += (Decode?.Method.Name ?? "???");
|
||||
dbgOpCode += (decode?.Method.Name ?? "???");
|
||||
|
||||
if (Decode == ShaderDecode.Bra || Decode == ShaderDecode.Ssy)
|
||||
if (decode == ShaderDecode.Bra || decode == ShaderDecode.Ssy)
|
||||
{
|
||||
int Offset = ((int)(OpCode >> 20) << 8) >> 8;
|
||||
int offset = ((int)(opCode >> 20) << 8) >> 8;
|
||||
|
||||
long Target = Position + Offset;
|
||||
long target = position + offset;
|
||||
|
||||
DbgOpCode += " (0x" + Target.ToString("x16") + ")";
|
||||
dbgOpCode += " (0x" + target.ToString("x16") + ")";
|
||||
}
|
||||
|
||||
Block.AddNode(new ShaderIrCmnt(DbgOpCode));
|
||||
block.AddNode(new ShaderIrCmnt(dbgOpCode));
|
||||
}
|
||||
|
||||
if (Decode == null)
|
||||
if (decode == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Decode(Block, OpCode, Position);
|
||||
decode(block, opCode, position);
|
||||
}
|
||||
while (!IsFlowChange(Block.GetLastNode()));
|
||||
while (!IsFlowChange(block.GetLastNode()));
|
||||
|
||||
Block.EndPosition = Position;
|
||||
block.EndPosition = position;
|
||||
}
|
||||
|
||||
private static bool IsFlowChange(ShaderIrNode Node)
|
||||
private static bool IsFlowChange(ShaderIrNode node)
|
||||
{
|
||||
return !NodeHasNext(GetInnermostOp(Node));
|
||||
return !NodeHasNext(GetInnermostOp(node));
|
||||
}
|
||||
|
||||
private static ShaderIrOp GetInnermostOp(ShaderIrNode Node)
|
||||
private static ShaderIrOp GetInnermostOp(ShaderIrNode node)
|
||||
{
|
||||
if (Node is ShaderIrCond Cond)
|
||||
if (node is ShaderIrCond cond)
|
||||
{
|
||||
Node = Cond.Child;
|
||||
node = cond.Child;
|
||||
}
|
||||
|
||||
return Node is ShaderIrOp Op ? Op : null;
|
||||
return node is ShaderIrOp op ? op : null;
|
||||
}
|
||||
|
||||
private static bool NodeHasNext(ShaderIrNode Node)
|
||||
private static bool NodeHasNext(ShaderIrNode node)
|
||||
{
|
||||
if (!(Node is ShaderIrOp Op))
|
||||
if (!(node is ShaderIrOp op))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return Op.Inst != ShaderIrInst.Exit &&
|
||||
Op.Inst != ShaderIrInst.Bra;
|
||||
return op.Inst != ShaderIrInst.Exit &&
|
||||
op.Inst != ShaderIrInst.Bra;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public bool Enabled => Red || Green || Blue || Alpha;
|
||||
|
||||
public bool ComponentEnabled(int Component)
|
||||
public bool ComponentEnabled(int component)
|
||||
{
|
||||
switch (Component)
|
||||
switch (component)
|
||||
{
|
||||
case 0: return Red;
|
||||
case 1: return Green;
|
||||
|
@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
case 3: return Alpha;
|
||||
}
|
||||
|
||||
throw new ArgumentException(nameof(Component));
|
||||
throw new ArgumentException(nameof(component));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,88 +59,88 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
public bool OmapSampleMask { get; private set; }
|
||||
public bool OmapDepth { get; private set; }
|
||||
|
||||
public ShaderHeader(IGalMemory Memory, long Position)
|
||||
public ShaderHeader(IGalMemory memory, long position)
|
||||
{
|
||||
uint CommonWord0 = (uint)Memory.ReadInt32(Position + 0);
|
||||
uint CommonWord1 = (uint)Memory.ReadInt32(Position + 4);
|
||||
uint CommonWord2 = (uint)Memory.ReadInt32(Position + 8);
|
||||
uint CommonWord3 = (uint)Memory.ReadInt32(Position + 12);
|
||||
uint CommonWord4 = (uint)Memory.ReadInt32(Position + 16);
|
||||
uint commonWord0 = (uint)memory.ReadInt32(position + 0);
|
||||
uint commonWord1 = (uint)memory.ReadInt32(position + 4);
|
||||
uint commonWord2 = (uint)memory.ReadInt32(position + 8);
|
||||
uint commonWord3 = (uint)memory.ReadInt32(position + 12);
|
||||
uint commonWord4 = (uint)memory.ReadInt32(position + 16);
|
||||
|
||||
SphType = ReadBits(CommonWord0, 0, 5);
|
||||
Version = ReadBits(CommonWord0, 5, 5);
|
||||
ShaderType = ReadBits(CommonWord0, 10, 4);
|
||||
MrtEnable = ReadBits(CommonWord0, 14, 1) != 0;
|
||||
KillsPixels = ReadBits(CommonWord0, 15, 1) != 0;
|
||||
DoesGlobalStore = ReadBits(CommonWord0, 16, 1) != 0;
|
||||
SassVersion = ReadBits(CommonWord0, 17, 4);
|
||||
DoesLoadOrStore = ReadBits(CommonWord0, 26, 1) != 0;
|
||||
DoesFp64 = ReadBits(CommonWord0, 27, 1) != 0;
|
||||
StreamOutMask = ReadBits(CommonWord0, 28, 4);
|
||||
SphType = ReadBits(commonWord0, 0, 5);
|
||||
Version = ReadBits(commonWord0, 5, 5);
|
||||
ShaderType = ReadBits(commonWord0, 10, 4);
|
||||
MrtEnable = ReadBits(commonWord0, 14, 1) != 0;
|
||||
KillsPixels = ReadBits(commonWord0, 15, 1) != 0;
|
||||
DoesGlobalStore = ReadBits(commonWord0, 16, 1) != 0;
|
||||
SassVersion = ReadBits(commonWord0, 17, 4);
|
||||
DoesLoadOrStore = ReadBits(commonWord0, 26, 1) != 0;
|
||||
DoesFp64 = ReadBits(commonWord0, 27, 1) != 0;
|
||||
StreamOutMask = ReadBits(commonWord0, 28, 4);
|
||||
|
||||
ShaderLocalMemoryLowSize = ReadBits(CommonWord1, 0, 24);
|
||||
PerPatchAttributeCount = ReadBits(CommonWord1, 24, 8);
|
||||
ShaderLocalMemoryLowSize = ReadBits(commonWord1, 0, 24);
|
||||
PerPatchAttributeCount = ReadBits(commonWord1, 24, 8);
|
||||
|
||||
ShaderLocalMemoryHighSize = ReadBits(CommonWord2, 0, 24);
|
||||
ThreadsPerInputPrimitive = ReadBits(CommonWord2, 24, 8);
|
||||
ShaderLocalMemoryHighSize = ReadBits(commonWord2, 0, 24);
|
||||
ThreadsPerInputPrimitive = ReadBits(commonWord2, 24, 8);
|
||||
|
||||
ShaderLocalMemoryCrsSize = ReadBits(CommonWord3, 0, 24);
|
||||
OutputTopology = ReadBits(CommonWord3, 24, 4);
|
||||
ShaderLocalMemoryCrsSize = ReadBits(commonWord3, 0, 24);
|
||||
OutputTopology = ReadBits(commonWord3, 24, 4);
|
||||
|
||||
MaxOutputVertexCount = ReadBits(CommonWord4, 0, 12);
|
||||
StoreReqStart = ReadBits(CommonWord4, 12, 8);
|
||||
StoreReqEnd = ReadBits(CommonWord4, 24, 8);
|
||||
MaxOutputVertexCount = ReadBits(commonWord4, 0, 12);
|
||||
StoreReqStart = ReadBits(commonWord4, 12, 8);
|
||||
StoreReqEnd = ReadBits(commonWord4, 24, 8);
|
||||
|
||||
//Type 2 (fragment?) reading
|
||||
uint Type2OmapTarget = (uint)Memory.ReadInt32(Position + 72);
|
||||
uint Type2Omap = (uint)Memory.ReadInt32(Position + 76);
|
||||
uint type2OmapTarget = (uint)memory.ReadInt32(position + 72);
|
||||
uint type2Omap = (uint)memory.ReadInt32(position + 76);
|
||||
|
||||
OmapTargets = new OmapTarget[8];
|
||||
|
||||
for (int i = 0; i < OmapTargets.Length; i++)
|
||||
{
|
||||
int Offset = i * 4;
|
||||
int offset = i * 4;
|
||||
|
||||
OmapTargets[i] = new OmapTarget
|
||||
{
|
||||
Red = ReadBits(Type2OmapTarget, Offset + 0, 1) != 0,
|
||||
Green = ReadBits(Type2OmapTarget, Offset + 1, 1) != 0,
|
||||
Blue = ReadBits(Type2OmapTarget, Offset + 2, 1) != 0,
|
||||
Alpha = ReadBits(Type2OmapTarget, Offset + 3, 1) != 0
|
||||
Red = ReadBits(type2OmapTarget, offset + 0, 1) != 0,
|
||||
Green = ReadBits(type2OmapTarget, offset + 1, 1) != 0,
|
||||
Blue = ReadBits(type2OmapTarget, offset + 2, 1) != 0,
|
||||
Alpha = ReadBits(type2OmapTarget, offset + 3, 1) != 0
|
||||
};
|
||||
}
|
||||
|
||||
OmapSampleMask = ReadBits(Type2Omap, 0, 1) != 0;
|
||||
OmapDepth = ReadBits(Type2Omap, 1, 1) != 0;
|
||||
OmapSampleMask = ReadBits(type2Omap, 0, 1) != 0;
|
||||
OmapDepth = ReadBits(type2Omap, 1, 1) != 0;
|
||||
}
|
||||
|
||||
public int DepthRegister
|
||||
{
|
||||
get
|
||||
{
|
||||
int Count = 0;
|
||||
int count = 0;
|
||||
|
||||
for (int Index = 0; Index < OmapTargets.Length; Index++)
|
||||
for (int index = 0; index < OmapTargets.Length; index++)
|
||||
{
|
||||
for (int Component = 0; Component < 4; Component++)
|
||||
for (int component = 0; component < 4; component++)
|
||||
{
|
||||
if (OmapTargets[Index].ComponentEnabled(Component))
|
||||
if (OmapTargets[index].ComponentEnabled(component))
|
||||
{
|
||||
Count++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Depth register is always two registers after the last color output
|
||||
return Count + 1;
|
||||
return count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private static int ReadBits(uint Word, int Offset, int BitWidth)
|
||||
private static int ReadBits(uint word, int offset, int bitWidth)
|
||||
{
|
||||
uint Mask = (1u << BitWidth) - 1u;
|
||||
uint mask = (1u << bitWidth) - 1u;
|
||||
|
||||
return (int)((Word >> Offset) & Mask);
|
||||
return (int)((word >> offset) & mask);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,10 +5,10 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
public ShaderIrNode Dst { get; set; }
|
||||
public ShaderIrNode Src { get; set; }
|
||||
|
||||
public ShaderIrAsg(ShaderIrNode Dst, ShaderIrNode Src)
|
||||
public ShaderIrAsg(ShaderIrNode dst, ShaderIrNode src)
|
||||
{
|
||||
this.Dst = Dst;
|
||||
this.Src = Src;
|
||||
this.Dst = dst;
|
||||
this.Src = src;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,18 +14,18 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public List<ShaderIrNode> Nodes { get; private set; }
|
||||
|
||||
public ShaderIrBlock(int Position)
|
||||
public ShaderIrBlock(int position)
|
||||
{
|
||||
this.Position = Position;
|
||||
this.Position = position;
|
||||
|
||||
Sources = new List<ShaderIrBlock>();
|
||||
|
||||
Nodes = new List<ShaderIrNode>();
|
||||
}
|
||||
|
||||
public void AddNode(ShaderIrNode Node)
|
||||
public void AddNode(ShaderIrNode node)
|
||||
{
|
||||
Nodes.Add(Node);
|
||||
Nodes.Add(node);
|
||||
}
|
||||
|
||||
public ShaderIrNode[] GetNodes()
|
||||
|
|
|
@ -4,9 +4,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
public string Comment { get; private set; }
|
||||
|
||||
public ShaderIrCmnt(string Comment)
|
||||
public ShaderIrCmnt(string comment)
|
||||
{
|
||||
this.Comment = Comment;
|
||||
this.Comment = comment;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,11 +7,11 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public bool Not { get; private set; }
|
||||
|
||||
public ShaderIrCond(ShaderIrNode Pred, ShaderIrNode Child, bool Not)
|
||||
public ShaderIrCond(ShaderIrNode pred, ShaderIrNode child, bool not)
|
||||
{
|
||||
this.Pred = Pred;
|
||||
this.Child = Child;
|
||||
this.Not = Not;
|
||||
this.Pred = pred;
|
||||
this.Child = child;
|
||||
this.Not = not;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
{
|
||||
public ShaderIpaMode Mode { get; private set; }
|
||||
|
||||
public ShaderIrMetaIpa(ShaderIpaMode Mode)
|
||||
public ShaderIrMetaIpa(ShaderIpaMode mode)
|
||||
{
|
||||
this.Mode = Mode;
|
||||
this.Mode = mode;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,12 +13,12 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
public ShaderIrOperGpr DepthCompare;
|
||||
public int Component; // for TLD4(S)
|
||||
|
||||
public ShaderIrMetaTex(int Elem, GalTextureTarget TextureTarget, TextureInstructionSuffix TextureInstructionSuffix, params ShaderIrNode[] Coordinates)
|
||||
public ShaderIrMetaTex(int elem, GalTextureTarget textureTarget, TextureInstructionSuffix textureInstructionSuffix, params ShaderIrNode[] coordinates)
|
||||
{
|
||||
this.Elem = Elem;
|
||||
this.TextureTarget = TextureTarget;
|
||||
this.TextureInstructionSuffix = TextureInstructionSuffix;
|
||||
this.Coordinates = Coordinates;
|
||||
this.Elem = elem;
|
||||
this.TextureTarget = textureTarget;
|
||||
this.TextureInstructionSuffix = textureInstructionSuffix;
|
||||
this.Coordinates = coordinates;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,10 +6,10 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public int Elem { get; private set; }
|
||||
|
||||
public ShaderIrMetaTexq(ShaderTexqInfo Info, int Elem)
|
||||
public ShaderIrMetaTexq(ShaderTexqInfo info, int elem)
|
||||
{
|
||||
this.Info = Info;
|
||||
this.Elem = Elem;
|
||||
this.Info = info;
|
||||
this.Elem = elem;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,17 +9,17 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
public ShaderIrMeta MetaData { get; set; }
|
||||
|
||||
public ShaderIrOp(
|
||||
ShaderIrInst Inst,
|
||||
ShaderIrNode OperandA = null,
|
||||
ShaderIrNode OperandB = null,
|
||||
ShaderIrNode OperandC = null,
|
||||
ShaderIrMeta MetaData = null)
|
||||
ShaderIrInst inst,
|
||||
ShaderIrNode operandA = null,
|
||||
ShaderIrNode operandB = null,
|
||||
ShaderIrNode operandC = null,
|
||||
ShaderIrMeta metaData = null)
|
||||
{
|
||||
this.Inst = Inst;
|
||||
this.OperandA = OperandA;
|
||||
this.OperandB = OperandB;
|
||||
this.OperandC = OperandC;
|
||||
this.MetaData = MetaData;
|
||||
this.Inst = inst;
|
||||
this.OperandA = operandA;
|
||||
this.OperandB = operandB;
|
||||
this.OperandC = operandC;
|
||||
this.MetaData = metaData;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,10 +6,10 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public ShaderIrNode Vertex { get; private set; }
|
||||
|
||||
public ShaderIrOperAbuf(int Offs, ShaderIrNode Vertex)
|
||||
public ShaderIrOperAbuf(int offs, ShaderIrNode vertex)
|
||||
{
|
||||
this.Offs = Offs;
|
||||
this.Vertex = Vertex;
|
||||
this.Offs = offs;
|
||||
this.Vertex = vertex;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,11 +7,11 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public ShaderIrNode Offs { get; private set; }
|
||||
|
||||
public ShaderIrOperCbuf(int Index, int Pos, ShaderIrNode Offs = null)
|
||||
public ShaderIrOperCbuf(int index, int pos, ShaderIrNode offs = null)
|
||||
{
|
||||
this.Index = Index;
|
||||
this.Pos = Pos;
|
||||
this.Offs = Offs;
|
||||
this.Index = index;
|
||||
this.Pos = pos;
|
||||
this.Offs = offs;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,35 +2,35 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
class ShaderIrOperGpr : ShaderIrNode
|
||||
{
|
||||
public const int ZRIndex = 0xff;
|
||||
public const int ZrIndex = 0xff;
|
||||
|
||||
public bool IsConst => Index == ZRIndex;
|
||||
public bool IsConst => Index == ZrIndex;
|
||||
|
||||
public bool IsValidRegister => (uint)Index <= ZRIndex;
|
||||
public bool IsValidRegister => (uint)Index <= ZrIndex;
|
||||
|
||||
public int Index { get; set; }
|
||||
public int HalfPart { get; set; }
|
||||
|
||||
public ShaderRegisterSize RegisterSize { get; private set; }
|
||||
|
||||
public ShaderIrOperGpr(int Index)
|
||||
public ShaderIrOperGpr(int index)
|
||||
{
|
||||
this.Index = Index;
|
||||
this.Index = index;
|
||||
|
||||
RegisterSize = ShaderRegisterSize.Single;
|
||||
}
|
||||
|
||||
public ShaderIrOperGpr(int Index, int HalfPart)
|
||||
public ShaderIrOperGpr(int index, int halfPart)
|
||||
{
|
||||
this.Index = Index;
|
||||
this.HalfPart = HalfPart;
|
||||
this.Index = index;
|
||||
this.HalfPart = halfPart;
|
||||
|
||||
RegisterSize = ShaderRegisterSize.Half;
|
||||
}
|
||||
|
||||
public static ShaderIrOperGpr MakeTemporary(int Index = 0)
|
||||
public static ShaderIrOperGpr MakeTemporary(int index = 0)
|
||||
{
|
||||
return new ShaderIrOperGpr(0x100 + Index);
|
||||
return new ShaderIrOperGpr(0x100 + index);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
public int Value { get; private set; }
|
||||
|
||||
public ShaderIrOperImm(int Value)
|
||||
public ShaderIrOperImm(int value)
|
||||
{
|
||||
this.Value = Value;
|
||||
this.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
public float Value { get; private set; }
|
||||
|
||||
public ShaderIrOperImmf(float Value)
|
||||
public ShaderIrOperImmf(float value)
|
||||
{
|
||||
this.Value = Value;
|
||||
this.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,9 +9,9 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public int Index { get; set; }
|
||||
|
||||
public ShaderIrOperPred(int Index)
|
||||
public ShaderIrOperPred(int index)
|
||||
{
|
||||
this.Index = Index;
|
||||
this.Index = index;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,18 +12,18 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
|
||||
public int XBits;
|
||||
|
||||
public ShaderDecodeEntry(ShaderDecodeFunc Func, int XBits)
|
||||
public ShaderDecodeEntry(ShaderDecodeFunc func, int xBits)
|
||||
{
|
||||
this.Func = Func;
|
||||
this.XBits = XBits;
|
||||
this.Func = func;
|
||||
this.XBits = xBits;
|
||||
}
|
||||
}
|
||||
|
||||
private static ShaderDecodeEntry[] OpCodes;
|
||||
private static ShaderDecodeEntry[] _opCodes;
|
||||
|
||||
static ShaderOpCodeTable()
|
||||
{
|
||||
OpCodes = new ShaderDecodeEntry[1 << EncodingBits];
|
||||
_opCodes = new ShaderDecodeEntry[1 << EncodingBits];
|
||||
|
||||
#region Instructions
|
||||
Set("0100110000000x", ShaderDecode.Bfe_C);
|
||||
|
@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
Set("1101x00xxxxxxx", ShaderDecode.Texs);
|
||||
Set("1101101xxxxxxx", ShaderDecode.Tlds);
|
||||
Set("110010xxxx111x", ShaderDecode.Tld4);
|
||||
Set("1101111100xxxx", ShaderDecode.Tld4s);
|
||||
Set("1101111100xxxx", ShaderDecode.Tld4S);
|
||||
Set("01011111xxxxxx", ShaderDecode.Vmad);
|
||||
Set("0100111xxxxxxx", ShaderDecode.Xmad_CR);
|
||||
Set("0011011x00xxxx", ShaderDecode.Xmad_I);
|
||||
|
@ -132,59 +132,59 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
#endregion
|
||||
}
|
||||
|
||||
private static void Set(string Encoding, ShaderDecodeFunc Func)
|
||||
private static void Set(string encoding, ShaderDecodeFunc func)
|
||||
{
|
||||
if (Encoding.Length != EncodingBits)
|
||||
if (encoding.Length != EncodingBits)
|
||||
{
|
||||
throw new ArgumentException(nameof(Encoding));
|
||||
throw new ArgumentException(nameof(encoding));
|
||||
}
|
||||
|
||||
int Bit = Encoding.Length - 1;
|
||||
int Value = 0;
|
||||
int XMask = 0;
|
||||
int XBits = 0;
|
||||
int bit = encoding.Length - 1;
|
||||
int value = 0;
|
||||
int xMask = 0;
|
||||
int xBits = 0;
|
||||
|
||||
int[] XPos = new int[Encoding.Length];
|
||||
int[] xPos = new int[encoding.Length];
|
||||
|
||||
for (int Index = 0; Index < Encoding.Length; Index++, Bit--)
|
||||
for (int index = 0; index < encoding.Length; index++, bit--)
|
||||
{
|
||||
char Chr = Encoding[Index];
|
||||
char chr = encoding[index];
|
||||
|
||||
if (Chr == '1')
|
||||
if (chr == '1')
|
||||
{
|
||||
Value |= 1 << Bit;
|
||||
value |= 1 << bit;
|
||||
}
|
||||
else if (Chr == 'x')
|
||||
else if (chr == 'x')
|
||||
{
|
||||
XMask |= 1 << Bit;
|
||||
xMask |= 1 << bit;
|
||||
|
||||
XPos[XBits++] = Bit;
|
||||
xPos[xBits++] = bit;
|
||||
}
|
||||
}
|
||||
|
||||
XMask = ~XMask;
|
||||
xMask = ~xMask;
|
||||
|
||||
ShaderDecodeEntry Entry = new ShaderDecodeEntry(Func, XBits);
|
||||
ShaderDecodeEntry entry = new ShaderDecodeEntry(func, xBits);
|
||||
|
||||
for (int Index = 0; Index < (1 << XBits); Index++)
|
||||
for (int index = 0; index < (1 << xBits); index++)
|
||||
{
|
||||
Value &= XMask;
|
||||
value &= xMask;
|
||||
|
||||
for (int X = 0; X < XBits; X++)
|
||||
for (int x = 0; x < xBits; x++)
|
||||
{
|
||||
Value |= ((Index >> X) & 1) << XPos[X];
|
||||
value |= ((index >> x) & 1) << xPos[x];
|
||||
}
|
||||
|
||||
if (OpCodes[Value] == null || OpCodes[Value].XBits > XBits)
|
||||
if (_opCodes[value] == null || _opCodes[value].XBits > xBits)
|
||||
{
|
||||
OpCodes[Value] = Entry;
|
||||
_opCodes[value] = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ShaderDecodeFunc GetDecoder(long OpCode)
|
||||
public static ShaderDecodeFunc GetDecoder(long opCode)
|
||||
{
|
||||
return OpCodes[(ulong)OpCode >> (64 - EncodingBits)]?.Func;
|
||||
return _opCodes[(ulong)opCode >> (64 - EncodingBits)]?.Func;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,10 +2,10 @@ namespace Ryujinx.Graphics.Gal.Shader
|
|||
{
|
||||
enum ShaderOper
|
||||
{
|
||||
CR,
|
||||
Cr,
|
||||
Imm,
|
||||
Immf,
|
||||
RC,
|
||||
RR
|
||||
Rc,
|
||||
Rr
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue