Ejemplo n.º 1
0
        private EntityClass CreateLogger()
        {
            Entity intEntity      = IntrinsicTypes.Create("System.Int32");
            Entity stringEntity   = IntrinsicTypes.Create("System.String");
            Entity dateTimeEntity = IntrinsicTypes.Create("System.DateTime");

            EntityClass logger = new EntityClass();

            logger.Name       = "RequestLogger";
            logger.Visibility = "public";

            EntityField field = new EntityField();

            field.Name         = "id";
            field.IsPrimaryKey = true;
            field.IsPreview    = true;
            field.Type         = intEntity;
            logger.Fields.Add(field);

            field            = new EntityField();
            field.Name       = "url";
            field.IsPreview  = true;
            field.Represents = true;
            field.Type       = stringEntity;
            field.MaxSize    = 1000;
            logger.Fields.Add(field);

            field           = new EntityField();
            field.Name      = "date";
            field.IsPreview = true;
            field.Type      = dateTimeEntity;
            logger.Fields.Add(field);

            field           = new EntityField();
            field.Name      = "requestTime";
            field.IsPreview = true;
            field.Type      = intEntity;
            logger.Fields.Add(field);

            field            = new EntityField();
            field.Name       = "referrer";
            field.Type       = stringEntity;
            field.IsRequired = false;
            field.MaxSize    = 1000;
            logger.Fields.Add(field);

            field         = new EntityField();
            field.Name    = "ip";
            field.Type    = stringEntity;
            field.MaxSize = 15;
            logger.Fields.Add(field);

            field         = new EntityField();
            field.Name    = "userAgent";
            field.Type    = stringEntity;
            field.MaxSize = 1500;
            logger.Fields.Add(field);

            return(logger);
        }
Ejemplo n.º 2
0
        public override void Init(IProject project, IDependencyManager dependencies, IBuildAggregator aggregator)
        {
            base.Init(project, dependencies, aggregator);
            Model model = project.Model;

            EntityClass quotes = new EntityClass();

            quotes.Name       = "QuoteOfTheDay";
            quotes.Visibility = "public";

            EntityField id = new EntityField();

            id.Name         = "id";
            id.IsPreview    = true;
            id.IsPrimaryKey = true;
            id.Type         = IntrinsicTypes.Create("System.Int32");
            quotes.Fields.Add(id);

            EntityField quote = new EntityField();

            quote.Name       = "quote";
            quote.Represents = true;
            quote.IsPreview  = true;
            quote.Type       = IntrinsicTypes.Create("System.String");
            quote.IsRequired = true;
            quote.MaxSize    = 1000;
            quotes.Fields.Add(quote);

            model.Add(quotes);
        }
Ejemplo n.º 3
0
        private static TypeSymbol ResolveIntrinsicGenericVectorType(GenericVectorTypeSyntax type)
        {
            var scalarType    = SyntaxFacts.GetScalarType(type.ScalarType.TypeTokens.Select(x => x.Kind).ToArray());
            var numComponents = (int)type.SizeToken.Value;

            return(IntrinsicTypes.GetVectorType(scalarType, numComponents));
        }
Ejemplo n.º 4
0
        private static TypeSymbol ResolveIntrinsicVectorType(VectorTypeSyntax type)
        {
            var vectorType    = SyntaxFacts.GetVectorType(type.TypeToken.Kind);
            var scalarType    = vectorType.Item1;
            var numComponents = vectorType.Item2;

            return(IntrinsicTypes.GetVectorType(scalarType, numComponents));
        }
Ejemplo n.º 5
0
        private BoundVectorType BindVectorType(VectorTypeSyntax node)
        {
            var vectorType    = TypeFacts.GetVectorType(node.TypeToken.Kind);
            var scalarType    = vectorType.Item1;
            var numComponents = vectorType.Item2;

            return(new BoundVectorType(IntrinsicTypes.GetVectorType(scalarType, numComponents)));
        }
Ejemplo n.º 6
0
        private static TypeSymbol ResolveIntrinsicGenericMatrixType(GenericMatrixTypeSyntax type)
        {
            var scalarType = SyntaxFacts.GetScalarType(type.ScalarType.TypeTokens.Select(x => x.Kind).ToArray());
            var numRows    = (int)type.RowsToken.Value;
            var numCols    = (int)type.ColsToken.Value;

            return(IntrinsicTypes.GetMatrixType(scalarType, numRows, numCols));
        }
Ejemplo n.º 7
0
        private BoundGenericVectorType BindGenericVectorType(GenericVectorTypeSyntax node)
        {
            var scalarType    = TypeFacts.GetScalarType(node.ScalarType);
            var numComponents = (int)node.SizeToken.Value;

            return(new BoundGenericVectorType(
                       IntrinsicTypes.GetVectorType(scalarType, numComponents),
                       Bind(node.ScalarType, BindScalarType)));
        }
Ejemplo n.º 8
0
        private BoundMatrixType BindMatrixType(MatrixTypeSyntax node)
        {
            var matrixType = TypeFacts.GetMatrixType(node.TypeToken.Kind);
            var scalarType = matrixType.Item1;
            var numRows    = matrixType.Item2;
            var numCols    = matrixType.Item3;

            return(new BoundMatrixType(IntrinsicTypes.GetMatrixType(scalarType, numRows, numCols)));
        }
Ejemplo n.º 9
0
        private static TypeSymbol ResolveIntrinsicMatrixType(MatrixTypeSyntax type)
        {
            var matrixType = SyntaxFacts.GetMatrixType(type.TypeToken.Kind);
            var scalarType = matrixType.Item1;
            var numRows    = matrixType.Item2;
            var numCols    = matrixType.Item3;

            return(IntrinsicTypes.GetMatrixType(scalarType, numRows, numCols));
        }
Ejemplo n.º 10
0
        private BoundGenericMatrixType BindGenericMatrixType(GenericMatrixTypeSyntax node)
        {
            var scalarType = TypeFacts.GetScalarType(node.ScalarType);
            var numRows    = (int)node.RowsToken.Value;
            var numCols    = (int)node.ColsToken.Value;

            return(new BoundGenericMatrixType(
                       IntrinsicTypes.GetMatrixType(scalarType, numRows, numCols),
                       Bind(node.ScalarType, BindScalarType)));
        }
Ejemplo n.º 11
0
        private static EntityInterface GetInterface()
        {
            /** IPerson Definition **/
            EntityInterface iPerson = new EntityInterface();

            iPerson.Name       = "IPerson";
            iPerson.Visibility = "public";

            EntityMethod getDescription = new EntityMethod();

            getDescription.Name = "GetPerson";
            EntityParameter paramRet = new EntityParameter();

            paramRet.IsReturn = true;
            paramRet.Type     = IntrinsicTypes.Create("System.String");
            EntityParameter param = new EntityParameter();

            param.IsReturn = false;
            param.Type     = IntrinsicTypes.Create("System.Int32");
            param.Name     = "id";

            getDescription.ReturnEntity = paramRet;
            List <EntityParameter> parames = new List <EntityParameter>();

            parames.Add(param);
            getDescription.Parameters = parames;

            EntityMethod init = new EntityMethod();

            init.Name = "Init";

            EntityMethod set = new EntityMethod();

            set.Name = "SetData";
            EntityParameter param1 = new EntityParameter();

            param1.IsReturn = true;
            param1.Type     = IntrinsicTypes.Create("System.String");
            param1.Name     = "nome";
            EntityParameter param2 = new EntityParameter();

            param2.IsReturn = false;
            param2.Type     = IntrinsicTypes.Create("System.Boolean");
            param2.Name     = "isMale";
            List <EntityParameter> parames2 = new List <EntityParameter>();

            parames2.Add(param1);
            parames2.Add(param2);
            set.Parameters = parames2;

            iPerson.Methods.Add(getDescription);
            iPerson.Methods.Add(init);
            iPerson.Methods.Add(set);
            return(iPerson);
        }
Ejemplo n.º 12
0
        internal static IntrinsicNumericTypeSymbol GetNumericTypeWithScalarType(this IntrinsicNumericTypeSymbol type, ScalarType scalarType)
        {
            switch (type.Kind)
            {
            case SymbolKind.IntrinsicMatrixType:
                var matrixType = (IntrinsicMatrixTypeSymbol)type;
                return(IntrinsicTypes.GetMatrixType(scalarType, matrixType.Rows, matrixType.Cols));

            case SymbolKind.IntrinsicScalarType:
                return(IntrinsicTypes.GetScalarType(scalarType));

            case SymbolKind.IntrinsicVectorType:
                return(IntrinsicTypes.GetVectorType(scalarType, ((IntrinsicVectorTypeSymbol)type).NumComponents));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 13
0
        internal static TypeSymbol GetMatchingBoolType(TypeSymbol numericType)
        {
            switch (numericType.Kind)
            {
            case SymbolKind.IntrinsicScalarType:
                return(IntrinsicTypes.Bool);

            case SymbolKind.IntrinsicVectorType:
                return(IntrinsicTypes.GetVectorType(ScalarType.Bool, ((IntrinsicVectorTypeSymbol)numericType).NumComponents));

            case SymbolKind.IntrinsicMatrixType:
                var matrixType = (IntrinsicMatrixTypeSymbol)numericType;
                return(IntrinsicTypes.GetMatrixType(ScalarType.Bool, matrixType.Rows, matrixType.Cols));

            default:
                throw new InvalidOperationException();
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     Generates the code for the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="baseDirectory">The base directory.</param>
        public void Generate(IXerusModel model, string baseDirectory, string name)
        {
            List <IXerusDataType> dataTypes = model.DataTypes.ToList();

            dataTypes.AddRange(IntrinsicTypes.GetTypes());


            //GenerateSourcePart serializer
            using (StreamWriter streamWriter = File.CreateText(baseDirectory + "\\" + name + ".h"))
            {
                var serializerHeader = new SerializerHeaderGenerator();
                streamWriter.Write(serializerHeader.Generate(model, dataTypes, name));
            }

            using (StreamWriter streamWriter = File.CreateText(baseDirectory + "\\" + name + ".cpp"))
            {
                var serializerSource = new SerializerSourceGenerator();
                streamWriter.Write(serializerSource.Generate(model, dataTypes, name));
            }
        }
Ejemplo n.º 15
0
        private IntrinsicObjectTypeSymbol BindObjectType(PredefinedObjectTypeSyntax node)
        {
            if (node.ObjectTypeToken.ContextualKind == SyntaxKind.ConstantBufferKeyword)
            {
                var valueTypeSyntax = (TypeSyntax)node.TemplateArgumentList.Arguments[0];
                var valueType       = Bind(valueTypeSyntax, x => BindType(x, null));
                return(IntrinsicTypes.CreateConstantBufferType(valueType.TypeSymbol));
            }

            var predefinedObjectType = SyntaxFacts.GetPredefinedObjectType(node.ObjectTypeToken.Kind);

            switch (predefinedObjectType)
            {
            case PredefinedObjectType.Buffer:
            case PredefinedObjectType.Texture1D:
            case PredefinedObjectType.Texture1DArray:
            case PredefinedObjectType.Texture2D:
            case PredefinedObjectType.Texture2DArray:
            case PredefinedObjectType.Texture3D:
            case PredefinedObjectType.TextureCube:
            case PredefinedObjectType.TextureCubeArray:
            case PredefinedObjectType.Texture2DMS:
            case PredefinedObjectType.Texture2DMSArray:
            {
                TypeSymbol valueType;
                ScalarType scalarType;
                GetTextureValueAndScalarType(node, out valueType, out scalarType);
                return(IntrinsicTypes.CreateTextureType(predefinedObjectType, valueType, scalarType));
            }

            case PredefinedObjectType.RWBuffer:
            case PredefinedObjectType.RasterizerOrderedBuffer:
            case PredefinedObjectType.RWTexture1D:
            case PredefinedObjectType.RWTexture1DArray:
            case PredefinedObjectType.RWTexture2D:
            case PredefinedObjectType.RWTexture2DArray:
            case PredefinedObjectType.RWTexture3D:
            case PredefinedObjectType.RasterizerOrderedTexture1D:
            case PredefinedObjectType.RasterizerOrderedTexture1DArray:
            case PredefinedObjectType.RasterizerOrderedTexture2D:
            case PredefinedObjectType.RasterizerOrderedTexture2DArray:
            case PredefinedObjectType.RasterizerOrderedTexture3D:
            {
                TypeSymbol valueType;
                ScalarType scalarType;
                GetTextureValueAndScalarType(node, out valueType, out scalarType);
                return(IntrinsicTypes.CreateRWTextureType(predefinedObjectType, valueType, scalarType));
            }

            case PredefinedObjectType.AppendStructuredBuffer:
            case PredefinedObjectType.ConsumeStructuredBuffer:
            case PredefinedObjectType.StructuredBuffer:
            case PredefinedObjectType.RWStructuredBuffer:
            case PredefinedObjectType.RasterizerOrderedStructuredBuffer:
            case PredefinedObjectType.InputPatch:
            case PredefinedObjectType.OutputPatch:
            case PredefinedObjectType.PointStream:
            case PredefinedObjectType.LineStream:
            case PredefinedObjectType.TriangleStream:
            {
                var valueTypeSyntax = (TypeSyntax)node.TemplateArgumentList.Arguments[0];
                var valueType       = Bind(valueTypeSyntax, x => BindType(x, null)).TypeSymbol;
                switch (predefinedObjectType)
                {
                case PredefinedObjectType.AppendStructuredBuffer:
                    return(IntrinsicTypes.CreateAppendStructuredBufferType(valueType));

                case PredefinedObjectType.ConsumeStructuredBuffer:
                    return(IntrinsicTypes.CreateConsumeStructuredBufferType(valueType));

                case PredefinedObjectType.StructuredBuffer:
                    return(IntrinsicTypes.CreateStructuredBufferType(valueType));

                case PredefinedObjectType.RWStructuredBuffer:
                    return(IntrinsicTypes.CreateRWStructuredBufferType(valueType));

                case PredefinedObjectType.RasterizerOrderedStructuredBuffer:
                    return(IntrinsicTypes.CreateRasterizerOrderedStructuredBufferType(valueType));

                case PredefinedObjectType.InputPatch:
                    return(IntrinsicTypes.CreateInputPatchType(valueType));

                case PredefinedObjectType.OutputPatch:
                    return(IntrinsicTypes.CreateOutputPatchType(valueType));

                case PredefinedObjectType.PointStream:
                case PredefinedObjectType.LineStream:
                case PredefinedObjectType.TriangleStream:
                    return(IntrinsicTypes.CreateStreamOutputType(predefinedObjectType, valueType));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            case PredefinedObjectType.ByteAddressBuffer:
                return(IntrinsicTypes.ByteAddressBuffer);

            case PredefinedObjectType.BlendState:
                return(IntrinsicTypes.BlendState);

            case PredefinedObjectType.DepthStencilState:
                return(IntrinsicTypes.DepthStencilState);

            case PredefinedObjectType.RasterizerState:
                return(IntrinsicTypes.RasterizerState);

            case PredefinedObjectType.RasterizerOrderedByteAddressBuffer:
                return(IntrinsicTypes.RasterizerOrderedByteAddressBuffer);

            case PredefinedObjectType.RWByteAddressBuffer:
                return(IntrinsicTypes.RWByteAddressBuffer);

            case PredefinedObjectType.Sampler:
                return(IntrinsicTypes.Sampler);

            case PredefinedObjectType.Sampler1D:
                return(IntrinsicTypes.Sampler1D);

            case PredefinedObjectType.Sampler2D:
                return(IntrinsicTypes.Sampler2D);

            case PredefinedObjectType.Sampler3D:
                return(IntrinsicTypes.Sampler3D);

            case PredefinedObjectType.SamplerCube:
                return(IntrinsicTypes.SamplerCube);

            case PredefinedObjectType.SamplerState:
                return(IntrinsicTypes.SamplerState);

            case PredefinedObjectType.SamplerComparisonState:
                return(IntrinsicTypes.SamplerComparisonState);

            case PredefinedObjectType.Texture:
                return(IntrinsicTypes.LegacyTexture);

            case PredefinedObjectType.GeometryShader:
                return(IntrinsicTypes.GeometryShader);

            case PredefinedObjectType.PixelShader:
                return(IntrinsicTypes.PixelShader);

            case PredefinedObjectType.VertexShader:
                return(IntrinsicTypes.VertexShader);

            default:
                throw new InvalidOperationException(predefinedObjectType.ToString());
            }
        }
Ejemplo n.º 16
0
        private static void BuildSmsTestModel()
        {
            EntityField field = null;

            /** User **/
            EntityClass user = new EntityClass();

            user.Name       = "Principal";
            user.Visibility = "public";

            field              = new EntityField();
            field.Name         = "Id";
            field.IsPrimaryKey = true;
            field.Type         = new Int();
            user.Fields.Add(field);

            /** IDescription Definition **/
            EntityInterface iDescription = new EntityInterface();

            iDescription.Name       = "IDescription";
            iDescription.Visibility = "public";
            EntityMethod getDescription = new EntityMethod();

            getDescription.Name = "GetDescription";
            EntityParameter param = new EntityParameter();

            param.IsReturn = true;
            param.Type     = IntrinsicTypes.Create("System.String");
            getDescription.ReturnEntity = param;
            iDescription.Methods.Add(getDescription);

            /** Category Definition **/

            EntityClass category = new EntityClass();

            category.Name       = "Category";
            category.Visibility = "public";
            //category.Interfaces.Add(iDescription);

            field              = new EntityField();
            field.Name         = "Id";
            field.IsPrimaryKey = true;
            field.Type         = new Int();
            category.Fields.Add(field);

            field            = new EntityField();
            field.Name       = "Description";
            field.IsRequired = true;
            field.MaxSize    = 500;
            field.Type       = new Loki.DataRepresentation.IntrinsicEntities.String();
            category.Fields.Add(field);

            /** Sms Definition **/

            EntityClass message = new EntityClass();

            message.Name       = "SmsBase";
            message.IsAbstract = true;
            message.Visibility = "public";
            //message.Interfaces.Add(iDescription);

            field              = new EntityField();
            field.Name         = "Id";
            field.IsPrimaryKey = true;
            field.Type         = new Int();
            message.Fields.Add(field);

            field            = new EntityField();
            field.Name       = "Description";
            field.IsRequired = true;
            field.MaxSize    = 500;
            field.Default    = "No Description";
            field.Type       = new Loki.DataRepresentation.IntrinsicEntities.String();
            message.Fields.Add(field);

            field            = new EntityField();
            field.Name       = "Category";
            field.Type       = category;
            field.Mult       = Multiplicity.ManyToOne;
            field.IsRequired = true;
            message.Fields.Add(field);

            field            = new EntityField();
            field.Name       = "Principal";
            field.Type       = user;
            field.Mult       = Multiplicity.ManyToOne;
            field.IsRequired = true;
            message.Fields.Add(field);

            field          = new EntityField();
            field.Name     = "Messages";
            field.Type     = message;
            field.Mult     = Multiplicity.OneToMany;
            field.InfoOnly = true;
            user.Fields.Add(field);

            field          = new EntityField();
            field.Name     = "Messages";
            field.Type     = message;
            field.InfoOnly = true;
            field.Mult     = Multiplicity.OneToMany;
            category.Fields.Add(field);

            /** ImageSms **/
            EntityClass imageSms = new EntityClass();

            imageSms.Name       = "ImageSms";
            imageSms.Visibility = "public";
            imageSms.Parent     = message;

            field            = new EntityField();
            field.Name       = "ImageUrl";
            field.Type       = new Loki.DataRepresentation.IntrinsicEntities.String();
            field.IsRequired = true;
            field.Default    = "#";
            imageSms.Fields.Add(field);

            /** TextSms **/
            EntityClass textSms = new EntityClass();

            textSms.Name       = "TextSms";
            textSms.Visibility = "public";
            textSms.Parent     = message;

            field            = new EntityField();
            field.Name       = "Text";
            field.Type       = new Loki.DataRepresentation.IntrinsicEntities.String();
            field.IsRequired = true;
            field.Default    = "Empty";
            textSms.Fields.Add(field);

            /** Setting up project **/
            Model list = new Model();

            list.Add(category);
            list.Add(iDescription);
            list.Add(user);
            list.Add(message);
            list.Add(imageSms);
            list.Add(textSms);
            smsTestModel.Model = list;
        }
        static IntrinsicNumericConstructors()
        {
            var allFunctions = new List <FunctionSymbol>();

            foreach (var scalarType in IntrinsicTypes.AllScalarTypes)
            {
                var vector1Type = IntrinsicTypes.GetVectorType(scalarType.ScalarType, 1);
                var vector2Type = IntrinsicTypes.GetVectorType(scalarType.ScalarType, 2);
                var vector3Type = IntrinsicTypes.GetVectorType(scalarType.ScalarType, 3);
                var vector4Type = IntrinsicTypes.GetVectorType(scalarType.ScalarType, 4);

                allFunctions.Add(new FunctionSymbol(
                                     scalarType.Name,
                                     $"Constructor function for {scalarType.Name}.",
                                     null,
                                     scalarType,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector1Type.Name,
                                     $"Constructor function for {vector1Type.Name}.",
                                     null,
                                     vector1Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector2Type.Name,
                                     $"Constructor function for {vector2Type.Name}.",
                                     null,
                                     vector2Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("y", "Value for the y component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector2Type.Name,
                                     $"Constructor function for {vector2Type.Name}.",
                                     null,
                                     vector2Type,
                                     f => new[]
                {
                    new ParameterSymbol("xy", "Value for the x and y components.", f, vector2Type)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector3Type.Name,
                                     $"Constructor function for {vector3Type.Name}.",
                                     null,
                                     vector3Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("y", "Value for the y component.", f, scalarType),
                    new ParameterSymbol("z", "Value for the z component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector3Type.Name,
                                     $"Constructor function for {vector3Type.Name}.",
                                     null,
                                     vector3Type,
                                     f => new[]
                {
                    new ParameterSymbol("xy", "Value for the x and y components.", f, vector2Type),
                    new ParameterSymbol("z", "Value for the z component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector3Type.Name,
                                     $"Constructor function for {vector3Type.Name}.",
                                     null,
                                     vector3Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("yz", "Value for the y and z components.", f, vector2Type)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector3Type.Name,
                                     $"Constructor function for {vector3Type.Name}.",
                                     null,
                                     vector3Type,
                                     f => new[]
                {
                    new ParameterSymbol("xyz", "Value for the x, y, and z components.", f, vector3Type),
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("y", "Value for the y component.", f, scalarType),
                    new ParameterSymbol("z", "Value for the z component.", f, scalarType),
                    new ParameterSymbol("w", "Value for the w component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("xy", "Value for the x and y components.", f, vector2Type),
                    new ParameterSymbol("z", "Value for the z component.", f, scalarType),
                    new ParameterSymbol("w", "Value for the w component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("xy", "Value for the x and y components.", f, vector2Type),
                    new ParameterSymbol("zw", "Value for the z and w components.", f, vector2Type)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("yz", "Value for the y and z components.", f, vector2Type),
                    new ParameterSymbol("w", "Value for the w component.", f, scalarType)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("y", "Value for the y component.", f, scalarType),
                    new ParameterSymbol("zw", "Value for the z and w components.", f, vector2Type)
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("x", "Value for the x component.", f, scalarType),
                    new ParameterSymbol("yzw", "Value for the y, z, and w components.", f, vector3Type),
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("xyz", "Value for the x, y, and z component.", f, vector3Type),
                    new ParameterSymbol("w", "Value for the w component.", f, scalarType),
                },
                                     isNumericConstructor: true));

                allFunctions.Add(new FunctionSymbol(
                                     vector4Type.Name,
                                     $"Constructor function for {vector4Type.Name}.",
                                     null,
                                     vector4Type,
                                     f => new[]
                {
                    new ParameterSymbol("xyzw", "Value for the x, y, z, and w components.", f, vector4Type),
                },
                                     isNumericConstructor: true));

                foreach (var matrixType in IntrinsicTypes.AllMatrixTypes.Where(x => x.ScalarType == scalarType.ScalarType))
                {
                    allFunctions.Add(new FunctionSymbol(
                                         matrixType.Name,
                                         $"Constructor function for {matrixType.Name}.",
                                         null,
                                         matrixType,
                                         f =>
                    {
                        var result = new List <ParameterSymbol>();
                        for (var rows = 1; rows <= matrixType.Rows; rows++)
                        {
                            for (var cols = 1; cols <= matrixType.Cols; cols++)
                            {
                                result.Add(new ParameterSymbol($"m{rows}{cols}", $"Value for the component in row {rows} and column {cols}.", f, scalarType));
                            }
                        }
                        return(result.ToArray());
                    },
                                         isNumericConstructor: true));

                    allFunctions.Add(new FunctionSymbol(
                                         matrixType.Name,
                                         $"Constructor function for {matrixType.Name}.",
                                         null,
                                         matrixType,
                                         f =>
                    {
                        var result = new List <ParameterSymbol>();
                        for (var rows = 0; rows < matrixType.Rows; rows++)
                        {
                            result.Add(new ParameterSymbol($"row{rows}", $"Value for the components in row {rows}.", f, IntrinsicTypes.GetVectorType(scalarType.ScalarType, matrixType.Cols)));
                        }
                        return(result.ToArray());
                    },
                                         isNumericConstructor: true));
                }
            }

            AllFunctions = allFunctions;
        }
Ejemplo n.º 18
0
        private static IEnumerable <FunctionSymbol> CreateSM6Functions()
        {
            var allFunctions = new List <FunctionSymbol>();

            allFunctions.Add(Create0(
                                 "WaveGetLaneCount",
                                 "Returns the number of lanes in a wave on this architecture.",
                                 IntrinsicTypes.Uint));

            allFunctions.Add(Create0(
                                 "WaveGetLaneIndex",
                                 "Returns the index of the current lane within the current wave.",
                                 IntrinsicTypes.Uint));

            allFunctions.Add(Create0(
                                 "WaveIsFirstLane",
                                 "Returns true only for the active lane in the current wave with the smallest index.",
                                 IntrinsicTypes.Bool));

            allFunctions.AddRange(Create1(
                                      "WaveActiveAnyTrue",
                                      "Returns true if the expression is true in any of the active lanes in the current wave.",
                                      new[] { IntrinsicTypes.Bool },
                                      "expr",
                                      "The boolean expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveAllTrue",
                                      "Returns true if the expression is true in all active lanes in the current wave.",
                                      new[] { IntrinsicTypes.Bool },
                                      "expr",
                                      "The boolean expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveBallot",
                                      "Returns a 4-bit unsigned integer bitmask of the evaluation of the Boolean expression for all active lanes in the specified wave.",
                                      new[] { IntrinsicTypes.Bool },
                                      "expr",
                                      "The boolean expression to evaluate.",
                                      new[] { IntrinsicTypes.Uint4 }));

            allFunctions.AddRange(Create2(
                                      "WaveReadLaneAt",
                                      "Returns the value of the expression for the given lane index within the specified wave.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate.",
                                      "laneIndex",
                                      "The input lane index must be uniform across the wave.",
                                      overrideParameterType2: IntrinsicTypes.Uint));

            allFunctions.AddRange(Create1(
                                      "WaveReadLaneFirst",
                                      "Returns the value of the expression for the active lane of the current wave with the smallest index.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveAllEqual",
                                      "Returns true if the expression is the same for every active lane in the current wave (and thus uniform across it).",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate.",
                                      new[] { IntrinsicTypes.Bool }));

            allFunctions.AddRange(Create1(
                                      "WaveActiveBitAnd",
                                      "Returns the bitwise AND of all the values of the expression across all active lanes in the current wave and replicates it back to all active lanes.",
                                      IntrinsicTypes.AllIntTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveBitOr",
                                      "Returns the bitwise OR of all the values of the expression across all active lanes in the current wave and replicates it back to all active lanes.",
                                      IntrinsicTypes.AllIntTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveBitXor",
                                      "Returns the bitwise XOR of all the values of the expression across all active lanes in the current wave and replicates it back to all active lanes.",
                                      IntrinsicTypes.AllIntTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveCountBits",
                                      "Counts the number of boolean variables which evaluate to true across all active lanes in the current wave, and replicates the result to all lanes in the wave.",
                                      new[] { IntrinsicTypes.Bool },
                                      "bBit",
                                      "The boolean variables to evaluate. Providing an explicit true Boolean value returns the number of active lanes.",
                                      new[] { IntrinsicTypes.Uint }));

            allFunctions.AddRange(Create1(
                                      "WaveActiveMax",
                                      "Returns the maximum value of the expression across all active lanes in the current wave and replicates it back to all active lanes.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveMin",
                                      "Returns the minimum value of the expression across all active lanes in the current wave and replicates it back to all active lanes.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveProduct",
                                      "Multiplies the values of the expression together across all active lanes in the current wave and replicates it back to all active lanes.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WaveActiveSum",
                                      "Sums up the value of the expression across all active lanes in the current wave and replicates it to all lanes in the current wave.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "expr",
                                      "The expression to evaluate."));

            allFunctions.AddRange(Create1(
                                      "WavePrefixCountBits",
                                      "Returns the sum of all the specified boolean variables set to true across all active lanes with indices smaller than the current lane.",
                                      new[] { IntrinsicTypes.Bool },
                                      "bBit",
                                      "The specified boolean variables.",
                                      new[] { IntrinsicTypes.Uint }));

            allFunctions.AddRange(Create1(
                                      "WavePrefixSum",
                                      "Returns the sum of all of the values in the active lanes with smaller indices than this one.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "value",
                                      "The value to sum up."));

            allFunctions.AddRange(Create1(
                                      "WavePrefixProduct",
                                      "Returns the product of all of the values in the active lanes in this wave with indices less than this lane.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "value",
                                      "The value to multiply."));

            allFunctions.AddRange(Create2(
                                      "QuadReadLaneAt",
                                      "Returns the specified source value from the lane identified by the lane ID within the current quad.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "sourceValue",
                                      "The requested type.",
                                      "quadLaneID",
                                      "The lane ID; this will be a value from 0 to 3.",
                                      overrideParameterType2: IntrinsicTypes.Uint));

            allFunctions.AddRange(Create1(
                                      "QuadReadAcrossDiagonal",
                                      "Returns the specified local value which is read from the diagonally opposite lane in this quad.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "localValue",
                                      "The requested type."));

            allFunctions.AddRange(Create1(
                                      "QuadReadAcrossX",
                                      "Returns the specified local value read from the other lane in this quad in the X direction.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "localValue",
                                      "The requested type."));

            allFunctions.AddRange(Create1(
                                      "QuadReadAcrossY",
                                      "Returns the specified local value read from the other lane in this quad in the Y direction.",
                                      IntrinsicTypes.AllNumericTypes,
                                      "localValue",
                                      "The requested type."));

            // DXR Intrinsic Functions

            allFunctions.Add(Create0(
                                 "AcceptHitAndEndSearch",
                                 "Used in an any hit shader to commit the current hit and then stop searching for more hits for the ray.",
                                 IntrinsicTypes.Void));

            // TODO: missing template feature for second parameter
            //allFunctions.AddRange(Create2(
            //    "CallShader",
            //    "Invokes another shader from within a shader.",
            //    IntrinsicTypes.AllTypes,
            //    "ShaderIndex",
            //    "An unsigned integer representing the index into the callable shader table specified in the call to DispatchRays",
            //    "Parameter",
            //    "The user-defined parameters to pass to the callable shader. This parameter structure must match the parameter structure used in the callable shader pointed to in the shader table.",
            //    IntrinsicTypes.Void,
            //    IntrinsicTypes.Uint,
            //    IntrinsicTypes.Template, // TODO: this feature is missing
            //    ParameterDirection.Inout));

            allFunctions.Add(Create0(
                                 "IgnoreHit",
                                 "Called from an any hit shader to reject the hit and end the shader.",
                                 IntrinsicTypes.Void));

            allFunctions.Add(Create0(
                                 "PrimitiveIndex",
                                 "Retrieves the autogenerated index of the primitive within the geometry inside the bottom-level acceleration structure instance.",
                                 IntrinsicTypes.Uint));

            // TODO: missing template feature for third parameter
            //allFunctions.AddRange(Create3(
            //    "ReportHit",
            //    "Called by an intersection shader to report a ray intersection.",
            //    IntrinsicTypes.AllTypes,
            //    "THit",
            //    "A float value specifying the parametric distance of the intersection.",
            //    "HitKind",
            //    "An unsigned integer that identifies the type of hit that occurred. This is a user-specified value in the range of 0-127. The value can be read by any hit or closest hit shaders with the HitKind intrinsic.",
            //    "Attributes",
            //    "The user-defined Intersection Attribute Structure specifying the intersection attributes.",
            //    IntrinsicTypes.Void,
            //    IntrinsicTypes.Float,
            //    IntrinsicTypes.Uint,
            //    IntrinsicTypes.AllTypes /* TODO: this feature is missing */));

            // TODO: missing template feature for last parameter
            //allFunctions.Add(new FunctionSymbol(
            //    "TraceRay",
            //    "Sends a ray into a search for hits in an acceleration structure.",
            //    null,
            //    IntrinsicTypes.Void,
            //    f => new[]
            //    {
            //        new ParameterSymbol("AccelerationStructure", "The top-level acceleration structure to use. Specifying a NULL acceleration structure forces a miss.", f, IntrinsicTypes.RaytracingAccelerationStructure),
            //        new ParameterSymbol("RayFlags", "Valid combination of ray_flag values. Only defined ray flags are propagated by the system, i.e. are visible to the RayFlags shader intrinsic.", f, IntrinsicTypes.Uint),
            //        new ParameterSymbol("InstanceInclusionMask", "An unsigned integer, the bottom 8 bits of which are used to include or reject geometry instances based on the InstanceMask in each instance.", f, IntrinsicTypes.Uint),
            //        new ParameterSymbol("RayContributionToHitGroupIndex", "An unsigned integer specifying the offset to add into addressing calculations within shader tables for hit group indexing. Only the bottom 4 bits of this value are used.", f, IntrinsicTypes.Uint),
            //        new ParameterSymbol("MultiplierForGeometryContributionToShaderIndex", "An unsigned integer specifying the stride to multiply by GeometryContributionToHitGroupIndex, which is just the 0 based index the geometry was supplied by the app into its bottom-level acceleration structure. Only the bottom 16 bits of this multiplier value are used.", f, IntrinsicTypes.Uint),
            //        new ParameterSymbol("MissShaderIndex", "An unsigned integer specifying the index of the miss shader within a shader table.", f, IntrinsicTypes.Uint),
            //        new ParameterSymbol("Ray", "A RayDesc representing the ray to be traced.", f, IntrinsicTypes.RayDesc),
            //        new ParameterSymbol("Payload", "A user defined ray payload accessed both for both input and output by shaders invoked during raytracing. After TraceRay completes, the caller can access the payload as well.", f, IntrinsicTypes.Template, ParameterDirection.Inout) // TODO: this feature is missing
            //    }));

            // DXR System Value Intrinsics

            allFunctions.Add(Create0(
                                 "DispatchRaysIndex",
                                 "Gets the current location within the width, height and depth obtained with the DispatchRaysDimensions system value intrinsic.",
                                 IntrinsicTypes.Uint3));

            allFunctions.Add(Create0(
                                 "DispatchRaysDimensions",
                                 "The width, height and depth values from the D3D12_DISPATCH_RAYS_DESC structure specified in the originating DispatchRays call.",
                                 IntrinsicTypes.Uint3));

            allFunctions.Add(Create0(
                                 "WorldRayOrigin",
                                 "The world-space origin of the current ray.",
                                 IntrinsicTypes.Float3));

            allFunctions.Add(Create0(
                                 "WorldRayDirection",
                                 "The world-space direction for the current ray.",
                                 IntrinsicTypes.Float3));

            allFunctions.Add(Create0(
                                 "RayTMin",
                                 "A float representing the current parametric starting point for the ray.",
                                 IntrinsicTypes.Float));

            allFunctions.Add(Create0(
                                 "RayTCurrent",
                                 "A float representing the current parametric ending point for the ray.",
                                 IntrinsicTypes.Float));

            allFunctions.Add(Create0(
                                 "RayFlags",
                                 "An unsigned integer containing the current ray_flag flags.",
                                 IntrinsicTypes.Uint));

            allFunctions.Add(Create0(
                                 "InstanceIndex",
                                 "The autogenerated index of the current instance in the top-level raytracing acceleration structure.",
                                 IntrinsicTypes.Uint));

            allFunctions.Add(Create0(
                                 "InstanceId",
                                 "The user-provided identifier for the instance on the bottom-level acceleration structure instance within the top-level structure.",
                                 IntrinsicTypes.Uint));

            allFunctions.Add(Create0(
                                 "PrimitiveIndex",
                                 "Retrieves the autogenerated index of the primitive within the geometry inside the bottom-level acceleration structure instance.",
                                 IntrinsicTypes.Uint));

            allFunctions.Add(Create0(
                                 "ObjectRayOrigin",
                                 "The object-space origin for the current ray. Object-space refers to the space of the current bottom-level acceleration structure.",
                                 IntrinsicTypes.Float3));

            allFunctions.Add(Create0(
                                 "ObjectRayDirection",
                                 "The object-space direction for the current ray. Object-space refers to the space of the current bottom-level acceleration structure.",
                                 IntrinsicTypes.Float3));

            allFunctions.Add(Create0(
                                 "ObjectToWorld3x4",
                                 "A matrix for transforming from object-space to world-space. Object-space refers to the space of the current bottom-level acceleration structure.",
                                 IntrinsicTypes.GetMatrixType(ScalarType.Float, 3, 4)));

            allFunctions.Add(Create0(
                                 "ObjectToWorld4x3",
                                 "A matrix for transforming from object-space to world-space. Object-space refers to the space of the current bottom-level acceleration structure.",
                                 IntrinsicTypes.GetMatrixType(ScalarType.Float, 4, 3)));

            allFunctions.Add(Create0(
                                 "WorldToObject3x4",
                                 "A matrix for transforming from world-space to object-space. Object-space refers to the space of the current bottom-level acceleration structure.",
                                 IntrinsicTypes.GetMatrixType(ScalarType.Float, 3, 4)));

            allFunctions.Add(Create0(
                                 "WorldToObject4x3",
                                 "A matrix for transforming from world-space to object-space. Object-space refers to the space of the current bottom-level acceleration structure.",
                                 IntrinsicTypes.GetMatrixType(ScalarType.Float, 4, 3)));

            allFunctions.Add(Create0(
                                 "HitKind",
                                 "Returns the value passed as the HitKind parameter to ReportHit.",
                                 IntrinsicTypes.Uint));

            return(allFunctions);
        }
Ejemplo n.º 19
0
        private TypeSymbol ResolveIntrinsicObjectType(PredefinedObjectTypeSyntax type, ISymbolTable symbolTable, Symbol contextSymbol)
        {
            var predefinedObjectType = SyntaxFacts.GetPredefinedObjectType(type.ObjectTypeToken.Kind);

            switch (predefinedObjectType)
            {
            case PredefinedObjectType.Buffer:
            case PredefinedObjectType.Texture1D:
            case PredefinedObjectType.Texture1DArray:
            case PredefinedObjectType.Texture2D:
            case PredefinedObjectType.Texture2DArray:
            case PredefinedObjectType.Texture3D:
            case PredefinedObjectType.TextureCube:
            case PredefinedObjectType.TextureCubeArray:
            case PredefinedObjectType.Texture2DMS:
            case PredefinedObjectType.Texture2DMSArray:
            {
                TypeSymbol valueType;
                ScalarType scalarType;
                if (type.TemplateArgumentList != null)
                {
                    var valueTypeSyntax = type.TemplateArgumentList.Arguments[0];
                    valueType = ResolveIntrinsicType((PredefinedTypeSyntax)valueTypeSyntax, symbolTable, contextSymbol);
                    switch (valueTypeSyntax.Kind)
                    {
                    case SyntaxKind.PredefinedScalarType:
                        scalarType = SyntaxFacts.GetScalarType(((ScalarTypeSyntax)valueTypeSyntax).TypeTokens.Select(x => x.Kind).ToArray());
                        break;

                    case SyntaxKind.PredefinedVectorType:
                        scalarType = SyntaxFacts.GetVectorType(((VectorTypeSyntax)valueTypeSyntax).TypeToken.Kind).Item1;
                        break;

                    case SyntaxKind.PredefinedGenericVectorType:
                        scalarType = SyntaxFacts.GetScalarType(((GenericVectorTypeSyntax)valueTypeSyntax).ScalarType.TypeTokens.Select(x => x.Kind).ToArray());
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    valueType  = IntrinsicTypes.Float4;
                    scalarType = ScalarType.Float;
                }
                return(IntrinsicTypes.CreateTextureType(predefinedObjectType, valueType, scalarType));
            }

            case PredefinedObjectType.RWBuffer:
            case PredefinedObjectType.RWTexture1D:
            case PredefinedObjectType.RWTexture1DArray:
            case PredefinedObjectType.RWTexture2D:
            case PredefinedObjectType.RWTexture2DArray:
            case PredefinedObjectType.RWTexture3D:
                throw new NotImplementedException();

            case PredefinedObjectType.AppendStructuredBuffer:
            case PredefinedObjectType.ConsumeStructuredBuffer:
            case PredefinedObjectType.StructuredBuffer:
            {
                var valueTypeSyntax = (TypeSyntax)type.TemplateArgumentList.Arguments[0];
                var valueType       = ResolveType(valueTypeSyntax, symbolTable, contextSymbol);
                switch (predefinedObjectType)
                {
                case PredefinedObjectType.AppendStructuredBuffer:
                    return(IntrinsicTypes.CreateAppendStructuredBufferType(valueType));

                case PredefinedObjectType.ConsumeStructuredBuffer:
                    return(IntrinsicTypes.CreateConsumeStructuredBufferType(valueType));

                case PredefinedObjectType.StructuredBuffer:
                    return(IntrinsicTypes.CreateStructuredBufferType(valueType));

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            case PredefinedObjectType.ByteAddressBuffer:
                return(IntrinsicTypes.CreateByteAddressBufferType());

            case PredefinedObjectType.RWByteAddressBuffer:
            case PredefinedObjectType.RWStructuredBuffer:
            case PredefinedObjectType.InputPatch:
            case PredefinedObjectType.OutputPatch:
            case PredefinedObjectType.PointStream:
            case PredefinedObjectType.LineStream:
            case PredefinedObjectType.TriangleStream:
                throw new NotImplementedException();

            case PredefinedObjectType.Sampler:
            case PredefinedObjectType.SamplerState:
                return(IntrinsicTypes.SamplerState);

            case PredefinedObjectType.SamplerComparisonState:
                return(IntrinsicTypes.SamplerComparisonState);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }