2019-02-28 01:12:24 +00:00
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-08-13 21:22:09 +00:00
|
|
|
using System;
|
2018-04-08 19:17:35 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.Shader
|
|
|
|
{
|
|
|
|
class GlslDecl
|
|
|
|
{
|
2018-07-19 05:33:27 +00:00
|
|
|
public const int LayerAttr = 0x064;
|
2018-08-16 05:26:03 +00:00
|
|
|
public const int PointSizeAttr = 0x06c;
|
|
|
|
public const int PointCoordAttrX = 0x2e0;
|
|
|
|
public const int PointCoordAttrY = 0x2e4;
|
2018-05-29 23:37:10 +00:00
|
|
|
public const int TessCoordAttrX = 0x2f0;
|
|
|
|
public const int TessCoordAttrY = 0x2f4;
|
|
|
|
public const int TessCoordAttrZ = 0x2f8;
|
|
|
|
public const int InstanceIdAttr = 0x2f8;
|
2018-04-08 19:17:35 +00:00
|
|
|
public const int VertexIdAttr = 0x2fc;
|
2018-07-03 23:06:13 +00:00
|
|
|
public const int FaceAttr = 0x3fc;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
public const int GlPositionVec4Index = 7;
|
|
|
|
|
2018-06-29 01:01:58 +00:00
|
|
|
public const int PositionOutAttrLocation = 15;
|
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
private const int AttrStartIndex = 8;
|
2018-08-13 21:22:09 +00:00
|
|
|
private const int TexStartIndex = 8;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-04-10 19:50:32 +00:00
|
|
|
public const string PositionOutAttrName = "position";
|
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
private const string TextureName = "tex";
|
2018-04-08 19:17:35 +00:00
|
|
|
private const string UniformName = "c";
|
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
private const string AttrName = "attr";
|
|
|
|
private const string InAttrName = "in_" + AttrName;
|
|
|
|
private const string OutAttrName = "out_" + AttrName;
|
|
|
|
|
|
|
|
private const string GprName = "gpr";
|
|
|
|
private const string PredName = "pred";
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
public const string FragmentOutputName = "FragColor";
|
|
|
|
|
2018-08-10 04:09:40 +00:00
|
|
|
public const string ExtraUniformBlockName = "Extra";
|
2018-06-24 00:39:25 +00:00
|
|
|
public const string FlipUniformName = "flip";
|
2018-08-25 04:16:58 +00:00
|
|
|
public const string InstanceUniformName = "instance";
|
2018-06-24 00:39:25 +00:00
|
|
|
|
2018-08-31 16:14:04 +00:00
|
|
|
public const string BasicBlockName = "bb";
|
|
|
|
public const string BasicBlockAName = BasicBlockName + "_a";
|
|
|
|
public const string BasicBlockBName = BasicBlockName + "_b";
|
|
|
|
|
|
|
|
public const int SsyStackSize = 16;
|
|
|
|
public const string SsyStackName = "ssy_stack";
|
|
|
|
public const string SsyCursorName = "ssy_cursor";
|
2018-06-28 02:55:08 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private string[] _stagePrefixes = new string[] { "vp", "tcp", "tep", "gp", "fp" };
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private string _stagePrefix;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-08-13 21:22:09 +00:00
|
|
|
private Dictionary<ShaderIrOp, ShaderDeclInfo> m_CbTextures;
|
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
private Dictionary<int, ShaderDeclInfo> m_Textures;
|
2018-05-17 18:25:42 +00:00
|
|
|
private Dictionary<int, ShaderDeclInfo> m_Uniforms;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
private Dictionary<int, ShaderDeclInfo> m_Attributes;
|
2018-04-08 19:17:35 +00:00
|
|
|
private Dictionary<int, ShaderDeclInfo> m_InAttributes;
|
|
|
|
private Dictionary<int, ShaderDeclInfo> m_OutAttributes;
|
|
|
|
|
|
|
|
private Dictionary<int, ShaderDeclInfo> m_Gprs;
|
2019-01-31 12:43:24 +00:00
|
|
|
private Dictionary<int, ShaderDeclInfo> m_GprsHalf;
|
2018-04-08 19:17:35 +00:00
|
|
|
private Dictionary<int, ShaderDeclInfo> m_Preds;
|
|
|
|
|
2018-08-13 21:22:09 +00:00
|
|
|
public IReadOnlyDictionary<ShaderIrOp, ShaderDeclInfo> CbTextures => m_CbTextures;
|
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> Textures => m_Textures;
|
2018-05-17 18:25:42 +00:00
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> Uniforms => m_Uniforms;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> Attributes => m_Attributes;
|
2018-04-08 19:17:35 +00:00
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> InAttributes => m_InAttributes;
|
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> OutAttributes => m_OutAttributes;
|
|
|
|
|
2019-01-31 12:43:24 +00:00
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> Gprs => m_Gprs;
|
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> GprsHalf => m_GprsHalf;
|
|
|
|
public IReadOnlyDictionary<int, ShaderDeclInfo> Preds => m_Preds;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
public GalShaderType ShaderType { get; private set; }
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private GlslDecl(GalShaderType shaderType)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderType = shaderType;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-08-13 21:22:09 +00:00
|
|
|
m_CbTextures = new Dictionary<ShaderIrOp, ShaderDeclInfo>();
|
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
m_Textures = new Dictionary<int, ShaderDeclInfo>();
|
2018-08-13 21:22:09 +00:00
|
|
|
m_Uniforms = new Dictionary<int, ShaderDeclInfo>();
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
m_Attributes = new Dictionary<int, ShaderDeclInfo>();
|
2018-04-08 19:17:35 +00:00
|
|
|
m_InAttributes = new Dictionary<int, ShaderDeclInfo>();
|
|
|
|
m_OutAttributes = new Dictionary<int, ShaderDeclInfo>();
|
|
|
|
|
2019-01-31 12:43:24 +00:00
|
|
|
m_Gprs = new Dictionary<int, ShaderDeclInfo>();
|
|
|
|
m_GprsHalf = new Dictionary<int, ShaderDeclInfo>();
|
|
|
|
m_Preds = new Dictionary<int, ShaderDeclInfo>();
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public GlslDecl(ShaderIrBlock[] blocks, GalShaderType shaderType, ShaderHeader header) : this(shaderType)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_stagePrefix = _stagePrefixes[(int)shaderType] + "_";
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (shaderType == GalShaderType.Fragment)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int index = 0;
|
2018-08-23 05:07:23 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int attachment = 0; attachment < 8; attachment++)
|
2018-08-20 01:25:26 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
for (int component = 0; component < 4; component++)
|
2018-08-23 05:07:23 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (header.OmapTargets[attachment].ComponentEnabled(component))
|
2018-08-23 05:07:23 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Gprs.TryAdd(index, new ShaderDeclInfo(GetGprName(index), index));
|
2018-08-23 05:07:23 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
index++;
|
2018-08-23 05:07:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (header.OmapDepth)
|
2018-08-23 05:07:23 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
index = header.DepthRegister;
|
2018-08-23 05:07:23 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Gprs.TryAdd(index, new ShaderDeclInfo(GetGprName(index), index));
|
2018-08-20 01:25:26 +00:00
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (ShaderIrBlock block in blocks)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode[] nodes = block.GetNodes();
|
2018-08-13 21:22:09 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (ShaderIrNode node in nodes)
|
2018-05-29 23:37:10 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Traverse(nodes, null, node);
|
2018-05-29 23:37:10 +00:00
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static GlslDecl Merge(GlslDecl vpA, GlslDecl vpB)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
GlslDecl combined = new GlslDecl(GalShaderType.Vertex);
|
2018-06-28 02:55:08 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
Merge(combined.m_Textures, vpA.m_Textures, vpB.m_Textures);
|
|
|
|
Merge(combined.m_Uniforms, vpA.m_Uniforms, vpB.m_Uniforms);
|
2018-06-28 02:55:08 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
Merge(combined.m_Attributes, vpA.m_Attributes, vpB.m_Attributes);
|
|
|
|
Merge(combined.m_OutAttributes, vpA.m_OutAttributes, vpB.m_OutAttributes);
|
2018-06-28 02:55:08 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
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);
|
2018-06-28 02:55:08 +00:00
|
|
|
|
|
|
|
//Merge input attributes.
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (KeyValuePair<int, ShaderDeclInfo> kv in vpA.m_InAttributes)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
combined.m_InAttributes.TryAdd(kv.Key, kv.Value);
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (KeyValuePair<int, ShaderDeclInfo> kv in vpB.m_InAttributes)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
|
|
|
//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.
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!vpA.m_OutAttributes.ContainsKey(kv.Key))
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
combined.m_InAttributes.TryAdd(kv.Key, kv.Value);
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
return combined;
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public static string GetGprName(int index)
|
2018-08-23 05:07:23 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
return GprName + index;
|
2018-08-23 05:07:23 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 02:55:08 +00:00
|
|
|
private static void Merge(
|
2019-03-04 01:45:25 +00:00
|
|
|
Dictionary<int, ShaderDeclInfo> c,
|
|
|
|
Dictionary<int, ShaderDeclInfo> a,
|
|
|
|
Dictionary<int, ShaderDeclInfo> b)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (KeyValuePair<int, ShaderDeclInfo> kv in a)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
c.TryAdd(kv.Key, kv.Value);
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
foreach (KeyValuePair<int, ShaderDeclInfo> kv in b)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
c.TryAdd(kv.Key, kv.Value);
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private void Traverse(ShaderIrNode[] nodes, ShaderIrNode parent, ShaderIrNode node)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (node)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrAsg asg:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Traverse(nodes, asg, asg.Dst);
|
|
|
|
Traverse(nodes, asg, asg.Src);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrCond cond:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Traverse(nodes, cond, cond.Pred);
|
|
|
|
Traverse(nodes, cond, cond.Child);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrOp op:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
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)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int handle = ((ShaderIrOperImm)op.OperandC).Value;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int index = handle - TexStartIndex;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
string name = _stagePrefix + TextureName + index;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
GalTextureTarget textureTarget;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
TextureInstructionSuffix textureInstructionSuffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
|
|
|
|
// TODO: Non 2D texture type for TEXQ?
|
2019-03-04 01:45:25 +00:00
|
|
|
if (op.Inst == ShaderIrInst.Texq)
|
2019-02-28 01:12:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
textureTarget = GalTextureTarget.TwoD;
|
|
|
|
textureInstructionSuffix = TextureInstructionSuffix.None;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrMetaTex meta = ((ShaderIrMetaTex)op.MetaData);
|
2019-02-28 01:12:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
textureTarget = meta.TextureTarget;
|
|
|
|
textureInstructionSuffix = meta.TextureInstructionSuffix;
|
2019-02-28 01:12:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Textures.TryAdd(handle, new ShaderDeclInfo(name, handle, false, 0, 1, textureTarget, textureInstructionSuffix));
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
2019-03-04 01:45:25 +00:00
|
|
|
else if (op.Inst == ShaderIrInst.Texb)
|
2018-08-13 21:22:09 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode handleSrc = null;
|
2018-08-13 21:22:09 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int index = Array.IndexOf(nodes, parent) - 1;
|
2018-08-13 21:22:09 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
for (; index >= 0; index--)
|
2018-08-13 21:22:09 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrNode curr = nodes[index];
|
2018-08-13 21:22:09 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (curr is ShaderIrAsg asg && asg.Dst is ShaderIrOperGpr gpr)
|
2018-08-13 21:22:09 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (gpr.Index == ((ShaderIrOperGpr)op.OperandC).Index)
|
2018-08-13 21:22:09 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
handleSrc = asg.Src;
|
2018-08-13 21:22:09 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (handleSrc != null && handleSrc is ShaderIrOperCbuf cbuf)
|
2018-08-13 21:22:09 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderIrMetaTex meta = ((ShaderIrMetaTex)op.MetaData);
|
|
|
|
string name = _stagePrefix + TextureName + "_cb" + cbuf.Index + "_" + cbuf.Pos;
|
2018-08-13 21:22:09 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_CbTextures.Add(op, new ShaderDeclInfo(name, cbuf.Pos, true, cbuf.Index, 1, meta.TextureTarget, meta.TextureInstructionSuffix));
|
2018-08-13 21:22:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotImplementedException("Shader TEX.B instruction is not fully supported!");
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrOperCbuf cbuf:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!m_Uniforms.ContainsKey(cbuf.Index))
|
2018-05-17 18:25:42 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
string name = _stagePrefix + UniformName + cbuf.Index;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderDeclInfo declInfo = new ShaderDeclInfo(name, cbuf.Pos, true, cbuf.Index);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Uniforms.Add(cbuf.Index, declInfo);
|
2018-05-17 18:25:42 +00:00
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrOperAbuf abuf:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2018-08-16 05:26:03 +00:00
|
|
|
//This is a built-in variable.
|
2019-03-04 01:45:25 +00:00
|
|
|
if (abuf.Offs == LayerAttr ||
|
|
|
|
abuf.Offs == PointSizeAttr ||
|
|
|
|
abuf.Offs == PointCoordAttrX ||
|
|
|
|
abuf.Offs == PointCoordAttrY ||
|
|
|
|
abuf.Offs == VertexIdAttr ||
|
|
|
|
abuf.Offs == InstanceIdAttr ||
|
|
|
|
abuf.Offs == FaceAttr)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int index = abuf.Offs >> 4;
|
|
|
|
int elem = (abuf.Offs >> 2) & 3;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
int glslIndex = index - AttrStartIndex;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (glslIndex < 0)
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
ShaderDeclInfo declInfo;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (parent is ShaderIrAsg asg && asg.Dst == node)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!m_OutAttributes.TryGetValue(index, out declInfo))
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
declInfo = new ShaderDeclInfo(OutAttrName + glslIndex, glslIndex);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_OutAttributes.Add(index, declInfo);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!m_InAttributes.TryGetValue(index, out declInfo))
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
declInfo = new ShaderDeclInfo(InAttrName + glslIndex, glslIndex);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_InAttributes.Add(index, declInfo);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
declInfo.Enlarge(elem + 1);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!m_Attributes.ContainsKey(index))
|
2018-06-28 02:55:08 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
declInfo = new ShaderDeclInfo(AttrName + glslIndex, glslIndex, false, 0, 4);
|
2018-06-28 02:55:08 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Attributes.Add(index, declInfo);
|
2018-06-28 02:55:08 +00:00
|
|
|
}
|
2018-07-19 05:33:27 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
Traverse(nodes, abuf, abuf.Vertex);
|
2018-08-13 21:22:09 +00:00
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrOperGpr gpr:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!gpr.IsConst)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
string name = GetGprName(gpr.Index);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (gpr.RegisterSize == ShaderRegisterSize.Single)
|
2019-01-31 12:43:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Gprs.TryAdd(gpr.Index, new ShaderDeclInfo(name, gpr.Index));
|
2019-01-31 12:43:24 +00:00
|
|
|
}
|
2019-03-04 01:45:25 +00:00
|
|
|
else if (gpr.RegisterSize == ShaderRegisterSize.Half)
|
2019-01-31 12:43:24 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
name += "_h" + gpr.HalfPart;
|
2019-01-31 12:43:24 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_GprsHalf.TryAdd((gpr.Index << 1) | gpr.HalfPart, new ShaderDeclInfo(name, gpr.Index));
|
2019-01-31 12:43:24 +00:00
|
|
|
}
|
|
|
|
else /* if (Gpr.RegisterSize == ShaderRegisterSize.Double) */
|
|
|
|
{
|
|
|
|
throw new NotImplementedException("Double types are not supported.");
|
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
case ShaderIrOperPred pred:
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (!pred.IsConst && !HasName(m_Preds, pred.Index))
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
string name = PredName + pred.Index;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
m_Preds.TryAdd(pred.Index, new ShaderDeclInfo(name, pred.Index));
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private bool HasName(Dictionary<int, ShaderDeclInfo> decls, int index)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2018-06-28 02:55:08 +00:00
|
|
|
//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.
|
2019-03-04 01:45:25 +00:00
|
|
|
int vecIndex = index & ~3;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (decls.TryGetValue(vecIndex, out ShaderDeclInfo declInfo))
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (declInfo.Size > 1 && index < vecIndex + declInfo.Size)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
return decls.ContainsKey(index);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-16 05:26:03 +00:00
|
|
|
}
|