2019-10-31 03:29:22 +00:00
|
|
|
using Ryujinx.Common;
|
2019-10-13 07:02:07 +01:00
|
|
|
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
|
|
|
|
using Ryujinx.Graphics.Shader.StructuredIr;
|
|
|
|
using Ryujinx.Graphics.Shader.Translation;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
|
|
|
|
{
|
|
|
|
static class Declarations
|
|
|
|
{
|
|
|
|
// At least 16 attributes are guaranteed by the spec.
|
|
|
|
public const int MaxAttributes = 16;
|
|
|
|
|
|
|
|
public static void Declare(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
2020-03-22 21:31:31 +00:00
|
|
|
context.AppendLine("#version 430 core");
|
2019-11-08 20:29:41 +00:00
|
|
|
context.AppendLine("#extension GL_ARB_gpu_shader_int64 : enable");
|
2019-10-31 03:29:22 +00:00
|
|
|
context.AppendLine("#extension GL_ARB_shader_ballot : enable");
|
2019-11-08 20:29:41 +00:00
|
|
|
context.AppendLine("#extension GL_ARB_shader_group_vote : enable");
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
if (context.Config.Stage == ShaderStage.Compute)
|
|
|
|
{
|
|
|
|
context.AppendLine("#extension GL_ARB_compute_shader : enable");
|
|
|
|
}
|
|
|
|
|
2019-12-07 04:54:28 +00:00
|
|
|
context.AppendLine("#pragma optionNV(fastmath off)");
|
|
|
|
|
2019-10-13 07:02:07 +01:00
|
|
|
context.AppendLine();
|
|
|
|
|
|
|
|
context.AppendLine($"const int {DefaultNames.UndefinedName} = 0;");
|
|
|
|
context.AppendLine();
|
|
|
|
|
|
|
|
if (context.Config.Stage == ShaderStage.Geometry)
|
|
|
|
{
|
2019-12-16 04:59:46 +00:00
|
|
|
string inPrimitive = ((InputTopology)context.Config.QueryInfo(QueryInfoName.PrimitiveTopology)).ToGlslString();
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
context.AppendLine($"layout ({inPrimitive}) in;");
|
|
|
|
|
2019-12-16 04:59:46 +00:00
|
|
|
string outPrimitive = context.Config.OutputTopology.ToGlslString();
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
int maxOutputVertices = context.Config.MaxOutputVertices;
|
|
|
|
|
|
|
|
context.AppendLine($"layout ({outPrimitive}, max_vertices = {maxOutputVertices}) out;");
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
if (context.Config.Stage == ShaderStage.Compute)
|
|
|
|
{
|
|
|
|
int localMemorySize = BitUtils.DivRoundUp(context.Config.QueryInfo(QueryInfoName.ComputeLocalMemorySize), 4);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
if (localMemorySize != 0)
|
|
|
|
{
|
|
|
|
string localMemorySizeStr = NumberFormatter.FormatInt(localMemorySize);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
context.AppendLine($"uint {DefaultNames.LocalMemoryName}[{localMemorySizeStr}];");
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
int sharedMemorySize = BitUtils.DivRoundUp(context.Config.QueryInfo(QueryInfoName.ComputeSharedMemorySize), 4);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
if (sharedMemorySize != 0)
|
|
|
|
{
|
|
|
|
string sharedMemorySizeStr = NumberFormatter.FormatInt(sharedMemorySize);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
context.AppendLine($"shared uint {DefaultNames.SharedMemoryName}[{sharedMemorySizeStr}];");
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (context.Config.LocalMemorySize != 0)
|
2019-11-08 20:29:41 +00:00
|
|
|
{
|
2020-02-02 03:25:52 +00:00
|
|
|
int localMemorySize = BitUtils.DivRoundUp(context.Config.LocalMemorySize, 4);
|
|
|
|
|
|
|
|
string localMemorySizeStr = NumberFormatter.FormatInt(localMemorySize);
|
2019-12-09 02:55:22 +00:00
|
|
|
|
2020-02-02 03:25:52 +00:00
|
|
|
context.AppendLine($"uint {DefaultNames.LocalMemoryName}[{localMemorySizeStr}];");
|
2019-11-08 20:29:41 +00:00
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
2019-10-13 07:02:07 +01:00
|
|
|
if (info.CBuffers.Count != 0)
|
|
|
|
{
|
|
|
|
DeclareUniforms(context, info);
|
|
|
|
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.SBuffers.Count != 0)
|
|
|
|
{
|
2019-12-01 02:53:09 +00:00
|
|
|
DeclareStorages(context, info);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.Samplers.Count != 0)
|
|
|
|
{
|
|
|
|
DeclareSamplers(context, info);
|
|
|
|
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
if (info.Images.Count != 0)
|
|
|
|
{
|
|
|
|
DeclareImages(context, info);
|
|
|
|
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
2019-10-13 07:02:07 +01:00
|
|
|
if (context.Config.Stage != ShaderStage.Compute)
|
|
|
|
{
|
|
|
|
if (info.IAttributes.Count != 0)
|
|
|
|
{
|
|
|
|
DeclareInputAttributes(context, info);
|
|
|
|
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info.OAttributes.Count != 0 || context.Config.Stage != ShaderStage.Fragment)
|
|
|
|
{
|
|
|
|
DeclareOutputAttributes(context, info);
|
|
|
|
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-16 04:59:46 +00:00
|
|
|
string localSizeX = NumberFormatter.FormatInt(context.Config.QueryInfo(QueryInfoName.ComputeLocalSizeX));
|
|
|
|
string localSizeY = NumberFormatter.FormatInt(context.Config.QueryInfo(QueryInfoName.ComputeLocalSizeY));
|
|
|
|
string localSizeZ = NumberFormatter.FormatInt(context.Config.QueryInfo(QueryInfoName.ComputeLocalSizeZ));
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
context.AppendLine(
|
2019-12-16 04:59:46 +00:00
|
|
|
"layout (" +
|
2019-10-13 07:02:07 +01:00
|
|
|
$"local_size_x = {localSizeX}, " +
|
|
|
|
$"local_size_y = {localSizeY}, " +
|
|
|
|
$"local_size_z = {localSizeZ}) in;");
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
2019-10-31 03:29:22 +00:00
|
|
|
|
2019-12-06 22:37:00 +00:00
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.MultiplyHighS32) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/MultiplyHighS32.glsl");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.MultiplyHighU32) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/MultiplyHighU32.glsl");
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:29:22 +00:00
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.Shuffle) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/Shuffle.glsl");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.ShuffleDown) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/ShuffleDown.glsl");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.ShuffleUp) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/ShuffleUp.glsl");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.ShuffleXor) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/ShuffleXor.glsl");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((info.HelperFunctionsMask & HelperFunctionsMask.SwizzleAdd) != 0)
|
|
|
|
{
|
|
|
|
AppendHelperFunction(context, "Ryujinx.Graphics.Shader/CodeGen/Glsl/HelperFunctions/SwizzleAdd.glsl");
|
|
|
|
}
|
2019-10-13 07:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void DeclareLocals(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
foreach (AstOperand decl in info.Locals)
|
|
|
|
{
|
|
|
|
string name = context.OperandManager.DeclareLocal(decl);
|
|
|
|
|
|
|
|
context.AppendLine(GetVarTypeName(decl.VarType) + " " + name + ";");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static string GetVarTypeName(VariableType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case VariableType.Bool: return "bool";
|
|
|
|
case VariableType.F32: return "precise float";
|
2020-03-03 14:02:08 +00:00
|
|
|
case VariableType.F64: return "double";
|
2019-10-13 07:02:07 +01:00
|
|
|
case VariableType.S32: return "int";
|
|
|
|
case VariableType.U32: return "uint";
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ArgumentException($"Invalid variable type \"{type}\".");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DeclareUniforms(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
foreach (int cbufSlot in info.CBuffers.OrderBy(x => x))
|
|
|
|
{
|
|
|
|
string ubName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
|
|
|
|
|
|
|
|
ubName += "_" + DefaultNames.UniformNamePrefix + cbufSlot;
|
|
|
|
|
|
|
|
context.CBufferDescriptors.Add(new BufferDescriptor(ubName, cbufSlot));
|
|
|
|
|
2019-11-24 22:49:19 +00:00
|
|
|
context.AppendLine("layout (std140) uniform " + ubName);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
context.EnterScope();
|
|
|
|
|
2019-11-24 22:49:19 +00:00
|
|
|
string ubSize = "[" + NumberFormatter.FormatInt(Constants.ConstantBufferSize / 16) + "]";
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-24 22:49:19 +00:00
|
|
|
context.AppendLine("vec4 " + OperandManager.GetUbName(context.Config.Stage, cbufSlot) + ubSize + ";");
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
context.LeaveScope(";");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-01 02:53:09 +00:00
|
|
|
private static void DeclareStorages(CodeGenContext context, StructuredProgramInfo info)
|
2019-11-08 20:29:41 +00:00
|
|
|
{
|
|
|
|
string sbName = OperandManager.GetShaderStagePrefix(context.Config.Stage);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-08 20:29:41 +00:00
|
|
|
sbName += "_" + DefaultNames.StorageNamePrefix;
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-08 20:29:41 +00:00
|
|
|
string blockName = $"{sbName}_{DefaultNames.BlockSuffix}";
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-08 20:29:41 +00:00
|
|
|
int maxSlot = 0;
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-08 20:29:41 +00:00
|
|
|
foreach (int sbufSlot in info.SBuffers)
|
|
|
|
{
|
|
|
|
context.SBufferDescriptors.Add(new BufferDescriptor($"{blockName}[{sbufSlot}]", sbufSlot));
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-08 20:29:41 +00:00
|
|
|
if (maxSlot < sbufSlot)
|
|
|
|
{
|
|
|
|
maxSlot = sbufSlot;
|
|
|
|
}
|
2019-10-13 07:02:07 +01:00
|
|
|
}
|
2019-11-08 20:29:41 +00:00
|
|
|
|
|
|
|
context.AppendLine("layout (std430) buffer " + blockName);
|
|
|
|
|
|
|
|
context.EnterScope();
|
|
|
|
|
|
|
|
context.AppendLine("uint " + DefaultNames.DataName + "[];");
|
|
|
|
|
|
|
|
string arraySize = NumberFormatter.FormatInt(maxSlot + 1);
|
|
|
|
|
|
|
|
context.LeaveScope($" {sbName}[{arraySize}];");
|
2019-10-13 07:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void DeclareSamplers(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
Dictionary<string, AstTextureOperation> samplers = new Dictionary<string, AstTextureOperation>();
|
|
|
|
|
2020-03-15 00:24:45 +00:00
|
|
|
// Texture instructions other than TextureSample (like TextureSize)
|
|
|
|
// may have incomplete sampler type information. In those cases,
|
|
|
|
// we prefer instead the more accurate information from the
|
|
|
|
// TextureSample instruction, if both are available.
|
|
|
|
foreach (AstTextureOperation texOp in info.Samplers.OrderBy(x => x.Handle * 2 + (x.Inst == Instruction.TextureSample ? 0 : 1)))
|
2019-10-13 07:02:07 +01:00
|
|
|
{
|
2019-11-03 02:07:21 +00:00
|
|
|
string indexExpr = NumberFormatter.FormatInt(texOp.ArraySize);
|
|
|
|
|
|
|
|
string samplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
if (!samplers.TryAdd(samplerName, texOp))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
string samplerTypeName = GetSamplerTypeName(texOp.Type);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
context.AppendLine("uniform " + samplerTypeName + " " + samplerName + ";");
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, AstTextureOperation> kv in samplers)
|
|
|
|
{
|
|
|
|
string samplerName = kv.Key;
|
|
|
|
|
|
|
|
AstTextureOperation texOp = kv.Value;
|
|
|
|
|
|
|
|
TextureDescriptor desc;
|
|
|
|
|
|
|
|
if ((texOp.Flags & TextureFlags.Bindless) != 0)
|
|
|
|
{
|
|
|
|
AstOperand operand = texOp.GetSource(0) as AstOperand;
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
desc = new TextureDescriptor(samplerName, texOp.Type, operand.CbufSlot, operand.CbufOffset);
|
2019-12-28 01:16:14 +00:00
|
|
|
|
|
|
|
context.TextureDescriptors.Add(desc);
|
2019-10-13 07:02:07 +01:00
|
|
|
}
|
2019-11-03 02:07:21 +00:00
|
|
|
else if ((texOp.Type & SamplerType.Indexed) != 0)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < texOp.ArraySize; index++)
|
|
|
|
{
|
|
|
|
string indexExpr = NumberFormatter.FormatInt(index);
|
|
|
|
|
|
|
|
string indexedSamplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
|
|
|
|
|
|
|
|
desc = new TextureDescriptor(indexedSamplerName, texOp.Type, texOp.Handle + index * 2);
|
|
|
|
|
|
|
|
context.TextureDescriptors.Add(desc);
|
|
|
|
}
|
|
|
|
}
|
2019-10-13 07:02:07 +01:00
|
|
|
else
|
|
|
|
{
|
2019-10-18 03:41:18 +01:00
|
|
|
desc = new TextureDescriptor(samplerName, texOp.Type, texOp.Handle);
|
2019-10-13 07:02:07 +01:00
|
|
|
|
2019-11-03 02:07:21 +00:00
|
|
|
context.TextureDescriptors.Add(desc);
|
|
|
|
}
|
2019-10-13 07:02:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
private static void DeclareImages(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
Dictionary<string, AstTextureOperation> images = new Dictionary<string, AstTextureOperation>();
|
|
|
|
|
|
|
|
foreach (AstTextureOperation texOp in info.Images.OrderBy(x => x.Handle))
|
|
|
|
{
|
2019-11-03 02:07:21 +00:00
|
|
|
string indexExpr = NumberFormatter.FormatInt(texOp.ArraySize);
|
|
|
|
|
|
|
|
string imageName = OperandManager.GetImageName(context.Config.Stage, texOp, indexExpr);
|
2019-10-18 03:41:18 +01:00
|
|
|
|
|
|
|
if (!images.TryAdd(imageName, texOp))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
string imageTypeName = GetImageTypeName(texOp.Type);
|
|
|
|
|
|
|
|
context.AppendLine("writeonly uniform " + imageTypeName + " " + imageName + ";");
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, AstTextureOperation> kv in images)
|
|
|
|
{
|
|
|
|
string imageName = kv.Key;
|
|
|
|
|
|
|
|
AstTextureOperation texOp = kv.Value;
|
|
|
|
|
2019-11-03 02:07:21 +00:00
|
|
|
if ((texOp.Type & SamplerType.Indexed) != 0)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < texOp.ArraySize; index++)
|
|
|
|
{
|
|
|
|
string indexExpr = NumberFormatter.FormatInt(index);
|
|
|
|
|
|
|
|
string indexedSamplerName = OperandManager.GetSamplerName(context.Config.Stage, texOp, indexExpr);
|
|
|
|
|
|
|
|
var desc = new TextureDescriptor(indexedSamplerName, texOp.Type, texOp.Handle + index * 2);
|
|
|
|
|
|
|
|
context.TextureDescriptors.Add(desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var desc = new TextureDescriptor(imageName, texOp.Type, texOp.Handle);
|
2019-10-18 03:41:18 +01:00
|
|
|
|
2019-11-03 02:07:21 +00:00
|
|
|
context.ImageDescriptors.Add(desc);
|
|
|
|
}
|
2019-10-18 03:41:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-13 07:02:07 +01:00
|
|
|
private static void DeclareInputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
string suffix = context.Config.Stage == ShaderStage.Geometry ? "[]" : string.Empty;
|
|
|
|
|
|
|
|
foreach (int attr in info.IAttributes.OrderBy(x => x))
|
|
|
|
{
|
|
|
|
string iq = info.InterpolationQualifiers[attr].ToGlslQualifier();
|
|
|
|
|
|
|
|
if (iq != string.Empty)
|
|
|
|
{
|
|
|
|
iq += " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
context.AppendLine($"layout (location = {attr}) {iq}in vec4 {DefaultNames.IAttributePrefix}{attr}{suffix};");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DeclareOutputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
if (context.Config.Stage == ShaderStage.Fragment)
|
|
|
|
{
|
|
|
|
DeclareUsedOutputAttributes(context, info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DeclareAllOutputAttributes(context, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DeclareUsedOutputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
foreach (int attr in info.OAttributes.OrderBy(x => x))
|
|
|
|
{
|
|
|
|
context.AppendLine($"layout (location = {attr}) out vec4 {DefaultNames.OAttributePrefix}{attr};");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void DeclareAllOutputAttributes(CodeGenContext context, StructuredProgramInfo info)
|
|
|
|
{
|
|
|
|
for (int attr = 0; attr < MaxAttributes; attr++)
|
|
|
|
{
|
|
|
|
string iq = $"{DefineNames.OutQualifierPrefixName}{attr} ";
|
|
|
|
|
|
|
|
context.AppendLine($"layout (location = {attr}) {iq}out vec4 {DefaultNames.OAttributePrefix}{attr};");
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (int attr in info.OAttributes.OrderBy(x => x).Where(x => x >= MaxAttributes))
|
|
|
|
{
|
|
|
|
context.AppendLine($"layout (location = {attr}) out vec4 {DefaultNames.OAttributePrefix}{attr};");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 03:29:22 +00:00
|
|
|
private static void AppendHelperFunction(CodeGenContext context, string filename)
|
|
|
|
{
|
|
|
|
string code = EmbeddedResources.ReadAllText(filename);
|
|
|
|
|
|
|
|
context.AppendLine(code.Replace("\t", CodeGenContext.Tab));
|
|
|
|
context.AppendLine();
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
private static string GetSamplerTypeName(SamplerType type)
|
2019-10-13 07:02:07 +01:00
|
|
|
{
|
|
|
|
string typeName;
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
switch (type & SamplerType.Mask)
|
2019-10-13 07:02:07 +01:00
|
|
|
{
|
2019-10-18 03:41:18 +01:00
|
|
|
case SamplerType.Texture1D: typeName = "sampler1D"; break;
|
|
|
|
case SamplerType.TextureBuffer: typeName = "samplerBuffer"; break;
|
|
|
|
case SamplerType.Texture2D: typeName = "sampler2D"; break;
|
|
|
|
case SamplerType.Texture3D: typeName = "sampler3D"; break;
|
|
|
|
case SamplerType.TextureCube: typeName = "samplerCube"; break;
|
2019-10-13 07:02:07 +01:00
|
|
|
|
|
|
|
default: throw new ArgumentException($"Invalid sampler type \"{type}\".");
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
if ((type & SamplerType.Multisample) != 0)
|
2019-10-13 07:02:07 +01:00
|
|
|
{
|
|
|
|
typeName += "MS";
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
if ((type & SamplerType.Array) != 0)
|
2019-10-13 07:02:07 +01:00
|
|
|
{
|
|
|
|
typeName += "Array";
|
|
|
|
}
|
|
|
|
|
2019-10-18 03:41:18 +01:00
|
|
|
if ((type & SamplerType.Shadow) != 0)
|
2019-10-13 07:02:07 +01:00
|
|
|
{
|
|
|
|
typeName += "Shadow";
|
|
|
|
}
|
|
|
|
|
|
|
|
return typeName;
|
|
|
|
}
|
2019-10-18 03:41:18 +01:00
|
|
|
|
|
|
|
private static string GetImageTypeName(SamplerType type)
|
|
|
|
{
|
|
|
|
string typeName;
|
|
|
|
|
|
|
|
switch (type & SamplerType.Mask)
|
|
|
|
{
|
|
|
|
case SamplerType.Texture1D: typeName = "image1D"; break;
|
|
|
|
case SamplerType.TextureBuffer: typeName = "imageBuffer"; break;
|
|
|
|
case SamplerType.Texture2D: typeName = "image2D"; break;
|
|
|
|
case SamplerType.Texture3D: typeName = "image3D"; break;
|
|
|
|
case SamplerType.TextureCube: typeName = "imageCube"; break;
|
|
|
|
|
|
|
|
default: throw new ArgumentException($"Invalid sampler type \"{type}\".");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type & SamplerType.Multisample) != 0)
|
|
|
|
{
|
|
|
|
typeName += "MS";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((type & SamplerType.Array) != 0)
|
|
|
|
{
|
|
|
|
typeName += "Array";
|
|
|
|
}
|
|
|
|
|
|
|
|
return typeName;
|
|
|
|
}
|
2019-10-13 07:02:07 +01:00
|
|
|
}
|
|
|
|
}
|