public override void VisitPropertyDeclaration(PropertyDeclarationSyntax node)
        {
            var propertySymbol = GetDeclaredSymbol(node) as IPropertySymbol;
            var attributes     = mFrontEnd.ParseAttributes(propertySymbol);

            foreach (var fieldAttribute in propertySymbol.GetAttributes())
            {
                var attributeName = TypeAliases.GetFullTypeName(fieldAttribute.AttributeClass);
                var processor     = SpecialResolvers.FieldProcessors.GetValueOrDefault(attributeName);
                processor?.Invoke(mFrontEnd, propertySymbol.ContainingType, propertySymbol, fieldAttribute);
            }
        }
Exemplo n.º 2
0
 public bool TryProcessIntrinsicMethod(FrontEndTranslator translator, IMethodSymbol methodSymbol)
 {
     foreach (var fieldAttribute in methodSymbol.GetAttributes())
     {
         var attributeName = TypeAliases.GetFullTypeName(fieldAttribute.AttributeClass);
         var processor     = MethodProcessors.GetValueOrDefault(attributeName);
         if (processor != null)
         {
             processor?.Invoke(translator, methodSymbol.ContainingType, methodSymbol, fieldAttribute);
             return(true);
         }
     }
     return(false);
 }
 public override void VisitFieldDeclaration(FieldDeclarationSyntax node)
 {
     foreach (var variable in node.Declaration.Variables)
     {
         var fieldSymbol = GetDeclaredSymbol(variable) as IFieldSymbol;
         var attributes  = mFrontEnd.ParseAttributes(fieldSymbol);
         foreach (var fieldAttribute in fieldSymbol.GetAttributes())
         {
             var attributeName = TypeAliases.GetFullTypeName(fieldAttribute.AttributeClass);
             var processor     = SpecialResolvers.FieldProcessors.GetValueOrDefault(attributeName);
             processor?.Invoke(mFrontEnd, fieldSymbol.ContainingType, fieldSymbol, fieldAttribute);
         }
     }
 }
        public ShaderType CreatePrimitiveShaderType(INamedTypeSymbol typeSymbol, ShaderAttributes attributes)
        {
            ShaderType shaderType = null;

            // If there's a special resolver for this type then use that to get the shader type
            foreach (var attribute in typeSymbol.GetAttributes())
            {
                var attributeName = TypeAliases.GetFullTypeName(attribute.AttributeClass);
                var processor     = SpecialResolvers.SpecialTypeCreationAttributeProcessors.GetValueOrDefault(attributeName);
                shaderType = processor?.Invoke(mFrontEnd, typeSymbol, attribute);
                if (shaderType != null)
                {
                    return(shaderType);
                }
            }
            throw new Exception("Failed to create primitive");
        }
Exemplo n.º 5
0
        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 override void VisitStructDeclaration(StructDeclarationSyntax node)
        {
            var structSymbol = GetDeclaredSymbol(node) as INamedTypeSymbol;
            var attributes   = mFrontEnd.ParseAttributes(structSymbol);

            // If the type has a special primitive attribute then queue it up for processing
            foreach (var attribute in structSymbol.GetAttributes())
            {
                int priority      = 0;
                var attributeName = TypeAliases.GetFullTypeName(attribute.AttributeClass);
                if (PrimitiveAttributePriorities.TryGetValue(attributeName, out priority))
                {
                    var data = new PrimitiveData();
                    data.Priority     = priority;
                    data.Node         = node;
                    data.StructSymbol = structSymbol;
                    PrimitivesToProcess.Add(data);
                }
            }
        }
Exemplo n.º 7
0
 public SpecialResolvers()
 {
     // Setup a few special processing functors here
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.IntegerPrimitive>(), IntegerResolvers.ProcessIntegerType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.FloatPrimitive>(), FloatResolvers.ProcessFloatType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.VectorPrimitive>(), VectorResolvers.ProcessVectorType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.MatrixPrimitive>(), MatrixResolvers.ProcessMatrixType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Math.FixedArrayPrimitive>(), FixedArrayResolver.ProcessFixedArrayType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Shader.SamplerPrimitive>(), SamplerResolvers.ProcessSamplerType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Shader.ImagePrimitive>(), ImageResolvers.ProcessImageType);
     SpecialTypeCreationAttributeProcessors.Add(TypeAliases.GetFullTypeName <Shader.SampledImagePrimitive>(), SampledSamplerResolvers.ProcessSampledImageType);
     FieldProcessors.Add(TypeAliases.GetFullTypeName <Math.Swizzle>(), VectorResolvers.ProcessVectorSwizzle);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.SimpleIntrinsicFunction>(), CreateSimpleIntrinsicType);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.ArrayGetIntrinsic>(), CreateArrayGetType);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.ArraySetIntrinsic>(), CreateArraySetType);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Math.CompositeConstruct>(), CreateCompositeConstructIntrinsic);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.SampledImageIntrinsicFunction>(), SampledImageIntrinsicResolvers.CreateSampledImageIntrinsicFunction);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.ImageIntrinsicFunction>(), ImageIntrinsicResolvers.CreateImageIntrinsicFunction);
     MethodProcessors.Add(TypeAliases.GetFullTypeName <Shader.SimpleExtensionIntrinsic>(), ExtensionIntrinsicResolvers.ProcessSimpleExtensionIntrinsic);
 }
Exemplo n.º 8
0
 public ShaderType CreatePrimitive(Type type, OpType opType)
 {
     return(CreatePrimitive(type, opType, TypeAliases.GetTypeName(type)));
 }
Exemplo n.º 9
0
 public ShaderAttribute FindFirstAttribute(Type attributeType)
 {
     return(FindFirstAttribute(TypeAliases.GetTypeName(attributeType)));
 }
Exemplo n.º 10
0
 public ShaderAttribute Add(Type attributeType)
 {
     return(Add(new ShaderAttribute {
         Name = TypeAliases.GetTypeName(attributeType)
     }));
 }
Exemplo n.º 11
0
 public void ForeachAttribute(Type attributeType, AttributeCallback callback)
 {
     ForeachAttribute(TypeAliases.GetTypeName(attributeType), callback);
 }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        public bool IsValidClassDeclaration(ClassDeclarationSyntax node)
        {
            var symbol = GetDeclaredSymbol(node) as ITypeSymbol;

            return(TypeAliases.GetTypeName(symbol.BaseType) == TypeAliases.GetTypeName <Attribute>());
        }
Exemplo n.º 14
0
 public ShaderType CreateType(ISymbol symbol, OpType opType)
 {
     return(CreateType(new TypeKey(symbol), TypeAliases.GetTypeName(symbol), opType, symbol));
 }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 public TypeKey(Type type)
 {
     mKey = TypeAliases.GetFullTypeName(type);
 }
Exemplo n.º 17
0
 public TypeKey(ISymbol symbol)
 {
     mKey = TypeAliases.GetFullTypeName(symbol);
 }