public static ImageIntrinsicAttributeData Parse(AttributeData attribute, int defaultOperandsLocation = -1) { if (attribute.ConstructorArguments.Length == 0) { return(null); } ImageIntrinsicAttributeData result = new ImageIntrinsicAttributeData(); result.OperandsLocation = defaultOperandsLocation; // Load the attribute params if they exist. Note: This isn't really safe, but works for now. foreach (var attributeParam in attribute.ConstructorArguments) { var argName = TypeAliases.GetTypeName(attributeParam.Type); if (argName == TypeAliases.GetTypeName <string>()) { result.OpType = (OpInstructionType)Enum.Parse(typeof(OpInstructionType), attributeParam.Value as string, true); } else if (argName == TypeAliases.GetTypeName <Shader.ImageOperands>()) { result.Operands = (Shader.ImageOperands)attributeParam.Value; } else if (argName == TypeAliases.GetTypeName <UInt32>()) { result.OperandsLocation = (int)(UInt32)attributeParam.Value; } } // Also try to resolve any named parameter arguments foreach (var pair in attribute.NamedArguments) { if (pair.Key == "OpName") { result.OpType = (OpInstructionType)Enum.Parse(typeof(OpInstructionType), pair.Value.Value as string, true); } else if (pair.Key == "Operands") { result.Operands = (Shader.ImageOperands)pair.Value.Value; } else if (pair.Key == "OperandsLocation") { result.OperandsLocation = (int)pair.Value.Value; } } return(result); }
public ShaderAttribute FindFirstAttribute(Type attributeType) { return(FindFirstAttribute(TypeAliases.GetTypeName(attributeType))); }
public void ForeachAttribute(Type attributeType, AttributeCallback callback) { ForeachAttribute(TypeAliases.GetTypeName(attributeType), callback); }
public ShaderAttribute Add(Type attributeType) { return(Add(new ShaderAttribute { Name = TypeAliases.GetTypeName(attributeType) })); }
public static ShaderType ProcessImageType(FrontEndTranslator translator, INamedTypeSymbol typeSymbol, AttributeData attribute) { ShaderType sampledType = null; Shader.ImageDimension dimension = Shader.ImageDimension.Dim2D; Shader.ImageDepthMode depthMode = Shader.ImageDepthMode.None; Shader.ImageArrayedMode arrayedMode = Shader.ImageArrayedMode.None; Shader.ImageMultiSampledMode multiSampledMode = Shader.ImageMultiSampledMode.SingleSampled; Shader.ImageSampledMode sampledMode = Shader.ImageSampledMode.Sampling; Shader.ImageFormat imageFormat = Shader.ImageFormat.Unknown; // Load all constructor args by type. foreach (var argument in attribute.ConstructorArguments) { var argName = TypeAliases.GetTypeName(argument.Type); if (argName == TypeAliases.GetTypeName <Type>()) { sampledType = translator.FindType(new TypeKey(argument.Value as ITypeSymbol)); } else if (argName == TypeAliases.GetTypeName <Shader.ImageDimension>()) { dimension = (Shader.ImageDimension)argument.Value; } else if (argName == TypeAliases.GetTypeName <Shader.ImageDepthMode>()) { depthMode = (Shader.ImageDepthMode)argument.Value; } else if (argName == TypeAliases.GetTypeName <Shader.ImageArrayedMode>()) { arrayedMode = (Shader.ImageArrayedMode)argument.Value; } else if (argName == TypeAliases.GetTypeName <Shader.ImageMultiSampledMode>()) { multiSampledMode = (Shader.ImageMultiSampledMode)argument.Value; } else if (argName == TypeAliases.GetTypeName <Shader.ImageSampledMode>()) { sampledMode = (Shader.ImageSampledMode)argument.Value; } else if (argName == TypeAliases.GetTypeName <Shader.ImageFormat>()) { imageFormat = (Shader.ImageFormat)argument.Value; } } // Handle named arguments foreach (var pair in attribute.NamedArguments) { if (pair.Key == "SampledType") { sampledType = translator.FindType(new TypeKey(pair.Value.Value as ITypeSymbol)); } else if (pair.Key == "Dimension") { dimension = (Shader.ImageDimension)pair.Value.Value; } else if (pair.Key == "DepthMode") { depthMode = (Shader.ImageDepthMode)pair.Value.Value; } else if (pair.Key == "ArrayedMode") { arrayedMode = (Shader.ImageArrayedMode)pair.Value.Value; } else if (pair.Key == "MultiSampledMode") { multiSampledMode = (Shader.ImageMultiSampledMode)pair.Value.Value; } else if (pair.Key == "SampledMode") { sampledMode = (Shader.ImageSampledMode)pair.Value.Value; } else if (pair.Key == "ImageFormat") { imageFormat = (Shader.ImageFormat)pair.Value.Value; } } // Validate input type. SpirV spec says: "Sampled Type is the type of the components that result // from sampling or reading from this image type. Must be ascalar numerical type or OpTypeVoid" if (sampledType == null || (sampledType.mBaseType != OpType.Bool && sampledType.mBaseType != OpType.Int && sampledType.mBaseType != OpType.Float && sampledType.mBaseType != OpType.Void)) { throw new Exception(); } var shaderType = translator.CreateType(typeSymbol, OpType.Image); shaderType.mParameters.Add(sampledType); shaderType.mParameters.Add(translator.CreateConstantLiteral((UInt32)dimension)); shaderType.mParameters.Add(translator.CreateConstantLiteral((UInt32)depthMode)); shaderType.mParameters.Add(translator.CreateConstantLiteral((UInt32)arrayedMode)); shaderType.mParameters.Add(translator.CreateConstantLiteral((UInt32)multiSampledMode)); shaderType.mParameters.Add(translator.CreateConstantLiteral((UInt32)sampledMode)); shaderType.mParameters.Add(translator.CreateConstantLiteral((UInt32)imageFormat)); shaderType.mStorageClass = StorageClass.UniformConstant; return(shaderType); }
public bool IsValidClassDeclaration(ClassDeclarationSyntax node) { var symbol = GetDeclaredSymbol(node) as ITypeSymbol; return(TypeAliases.GetTypeName(symbol.BaseType) == TypeAliases.GetTypeName <Attribute>()); }
public ShaderAttributes ParseAttributes(ISymbol symbol) { var shaderAttributes = new ShaderAttributes(); foreach (var attribute in symbol.GetAttributes()) { var shaderAttribute = new ShaderAttribute(); shaderAttributes.Add(shaderAttribute); shaderAttribute.Name = TypeAliases.GetTypeName(attribute.AttributeClass); shaderAttribute.Attribute = attribute; foreach (var argument in attribute.ConstructorArguments) { var shaderAttributeParam = new ShaderAttributeParameter(); shaderAttribute.Parameters.Add(shaderAttributeParam); if (argument.Kind != TypedConstantKind.Array) { shaderAttributeParam.Value = argument.Value; } } foreach (var argument in attribute.NamedArguments) { var shaderAttributeParam = new ShaderAttributeParameter(); shaderAttribute.Parameters.Add(shaderAttributeParam); shaderAttributeParam.Name = argument.Key; shaderAttributeParam.Value = argument.Value.Value; } if (TypeAliases.GetFullTypeName(attribute.AttributeClass) == TypeAliases.GetFullTypeName <Shader.Input>()) { var inputAttributes = new List <TypeName> { TypeAliases.GetTypeName <Shader.FragmentInput>(), TypeAliases.GetTypeName <Shader.StageInput>(), TypeAliases.GetTypeName <Shader.AppBuiltInInput>(), TypeAliases.GetTypeName <Shader.HardwareBuiltInInput>(), TypeAliases.GetTypeName <Shader.PropertyInput>(), }; foreach (var inputAttribute in inputAttributes) { var clone = shaderAttribute.Clone(); clone.Name = inputAttribute; shaderAttributes.Add(clone); } } if (TypeAliases.GetFullTypeName(attribute.AttributeClass) == TypeAliases.GetFullTypeName <Shader.Output>()) { var outputAttributes = new List <TypeName> { TypeAliases.GetTypeName <Shader.FragmentOutput>(), TypeAliases.GetTypeName <Shader.StageOutput>(), TypeAliases.GetTypeName <Shader.HardwareBuiltInOutput>(), }; foreach (var outputAttribute in outputAttributes) { var clone = shaderAttribute.Clone(); clone.Name = outputAttribute; shaderAttributes.Add(clone); } } } return(shaderAttributes); }
public ShaderType CreateType(ISymbol symbol, OpType opType) { return(CreateType(new TypeKey(symbol), TypeAliases.GetTypeName(symbol), opType, symbol)); }
public ShaderType CreatePrimitive(Type type, OpType opType) { return(CreatePrimitive(type, opType, TypeAliases.GetTypeName(type))); }