Ejemplo n.º 1
0
        public override void DefaultVisit(Node node)
        {
            if (node is Expression || node is TypeBase)
                VisitTypeInferencer((ITypeInferencer)node);

            base.DefaultVisit(node);
        }
Ejemplo n.º 2
0
        public override void DefaultVisit(Node node)
        {
            base.DefaultVisit(node);

            var typeBase = node as TypeBase;
            if (typeBase != null)
                AddReference(GetDeclarationContainer(), (Node)typeBase.TypeInference.Declaration);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Visits the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The filtered node</returns>
        public override Node DefaultVisit(Node node)
        {
            node = FilterFunction(node);
            if (node != null)
                node = base.DefaultVisit(node);

            return node;
        }
 public override void DefaultVisit(Node node)
 {
     var expression = node as Expression;
     if (expression != null)
     {
         if (!(expression is BinaryExpression || expression is MethodInvocationExpression || expression is VariableReferenceExpression || expression is LiteralExpression || expression is ParenthesizedExpression || expression is UnaryExpression))
             result.Error("Expression evaluation [{0}] is not supported", expression.Span, expression);
     }
 }
 public override Node DefaultVisit(Node node)
 {
     if (node == nodeToReplace)
     {
         complete = true;
         return replacementNode;
     }
     
     return base.DefaultVisit(node);
 }
Ejemplo n.º 6
0
 protected override Node Visit(Node node)
 {
     if (node == nodeToReplace)
     {
         complete = true;
         return replacementNode;
     }
     
     return base.Visit(node);
 }
Ejemplo n.º 7
0
 protected override Node Visit(Node node)
 {
     node.RemoveTag(ParadoxTags.ConstantBuffer);
     node.RemoveTag(ParadoxTags.ShaderScope);
     node.RemoveTag(ParadoxTags.StaticRef);
     node.RemoveTag(ParadoxTags.ExternRef);
     node.RemoveTag(ParadoxTags.StageInitRef);
     node.RemoveTag(ParadoxTags.CurrentShader);
     node.RemoveTag(ParadoxTags.VirtualTableReference);
     node.RemoveTag(ParadoxTags.BaseDeclarationMixin);
     node.RemoveTag(ParadoxTags.ShaderScope);
     return base.Visit(node);
 }
Ejemplo n.º 8
0
 public override void DefaultVisit(Node node)
 {
     // Keeping it for ShaderLinker (removed by XenkoShaderCleaner)
     //node.RemoveTag(XenkoTags.ConstantBuffer);
     node.RemoveTag(XenkoTags.ShaderScope);
     node.RemoveTag(XenkoTags.StaticRef);
     node.RemoveTag(XenkoTags.ExternRef);
     node.RemoveTag(XenkoTags.StageInitRef);
     node.RemoveTag(XenkoTags.CurrentShader);
     node.RemoveTag(XenkoTags.VirtualTableReference);
     node.RemoveTag(XenkoTags.BaseDeclarationMixin);
     node.RemoveTag(XenkoTags.ShaderScope);
     base.DefaultVisit(node);
 }
Ejemplo n.º 9
0
        protected override bool PreVisitNode(Node node)
        {
            // Sometimes it is desirable that constant buffer are not modified so that
            // they can be shared between different stages, even if some variables are unused.
            // In this case, use symetric reference so that using a constant buffer will include all its variables.
            if (KeepConstantBuffers && currentConstantBuffer != null && node is IDeclaration)
            {
                AddReference(node, currentConstantBuffer);
                AddReference(currentConstantBuffer, node);
            }

            return base.PreVisitNode(node);

        }
Ejemplo n.º 10
0
        public override Node DefaultVisit(Node node)
        {
            var qualifierNode = node as IQualifiers;
            if (qualifierNode != null)
            {
                qualifierNode.Qualifiers.Values.Remove(XenkoStorageQualifier.Stream);
                qualifierNode.Qualifiers.Values.Remove(XenkoStorageQualifier.Stage);
                qualifierNode.Qualifiers.Values.Remove(XenkoStorageQualifier.PatchStream);
                qualifierNode.Qualifiers.Values.Remove(XenkoStorageQualifier.Override);
                qualifierNode.Qualifiers.Values.Remove(XenkoStorageQualifier.Clone);
                qualifierNode.Qualifiers.Values.Remove(XenkoStorageQualifier.Stage);
            }

            return base.DefaultVisit(node);
        }
        public override void DefaultVisit(Node node)
        {
            base.DefaultVisit(node);

            var typeBase = node as TypeBase;
            if (typeBase != null)
            {
                if (sourceManager.IsClassExists(typeBase.Name.Text))
                {
                    FoundClasses.Add(typeBase.Name.Text);
                }
                else if (typeBase is ShaderTypeName)
                {
                    // Special case for ShaderTypeName as we must generate an error if it is not found
                    log.Error(XenkoMessageCode.ErrorClassNotFound, typeBase.Span, typeBase.Name.Text);
                }
            }
        }
Ejemplo n.º 12
0
 public ParadoxReplaceVisitor(Node toReplace, Node replacement) : base(false, false)
 {
     nodeToReplace = toReplace;
     replacementNode = replacement;
 }
        public override void DefaultVisit(Node node)
        {
            base.DefaultVisit(node);

            var typeBase = node as TypeBase;
            if (typeBase != null)
            {
                // Unhandled types only
                if (!(typeBase is TypeName || typeBase is ScalarType || typeBase is MatrixType || typeBase is TextureType || typeBase.IsStateType() || typeBase is ArrayType))
                {
                    Write(typeBase.Name);
                    ProcessInitialValueStatus = true;
                }
            }
        }
Ejemplo n.º 14
0
        private LocalParameterKey GetLinkParameterKey(Node node)
        {
            var qualifiers = node as IQualifiers;
            var attributable = node as IAttributes;

            if ((qualifiers != null && (qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Static) ||
                                        qualifiers.Qualifiers.Contains(StorageQualifier.Const) ||
                                        qualifiers.Qualifiers.Contains(SiliconStudio.Shaders.Ast.Hlsl.StorageQualifier.Groupshared)
                                       )) || attributable == null)
            {
                return null;
            }

            bool isColor = attributable.Attributes.OfType<AttributeDeclaration>().Any(x => x.Name == "Color");

            foreach (var annotation in attributable.Attributes.OfType<AttributeDeclaration>())
            {
                if (annotation.Name != "Link" || annotation.Parameters.Count < 1)
                {
                    continue;
                }

                var variableName = (string)annotation.Parameters[0].Value;
                var parameterKey = new LocalParameterKey() {Name = variableName};
                var variable = node as Variable;
                if (variable != null)
                {
                    var variableType = variable.Type;

                    if (variableType.TypeInference.TargetType != null)
                        variableType = variableType.TypeInference.TargetType;

                    if (variableType is ArrayType)
                    {
                        var arrayType = (ArrayType)variableType;
                        variableType = arrayType.Type;
                        parameterKey.Count = (int)((LiteralExpression)arrayType.Dimensions[0]).Literal.Value;

                        if (variableType.TypeInference.TargetType != null)
                            variableType = variableType.TypeInference.TargetType;
                    }
                    
                    if (variableType.IsBuiltIn)
                    {
                        var variableTypeName = variableType.Name.Text.ToLower();

                        switch (variableTypeName)
                        {
                            case "cbuffer":
                                parameterKey.Class = EffectParameterClass.ConstantBuffer;
                                parameterKey.Type = EffectParameterType.ConstantBuffer;
                                break;

                            case "tbuffer":
                                parameterKey.Class = EffectParameterClass.TextureBuffer;
                                parameterKey.Type = EffectParameterType.TextureBuffer;
                                break;

                            case "structuredbuffer":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.StructuredBuffer;
                                break;
                            case "rwstructuredbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWStructuredBuffer;
                                break;
                            case "consumestructuredbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.ConsumeStructuredBuffer;
                                break;
                            case "appendstructuredbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.AppendStructuredBuffer;
                                break;
                            case "buffer":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Buffer;
                                break;
                            case "rwbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWBuffer;
                                break;
                            case "byteaddressbuffer":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.ByteAddressBuffer;
                                break;
                            case "rwbyteaddressbuffer":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWByteAddressBuffer;
                                break;

                            case "texture1d":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Texture1D;
                                break;

                            case "texturecube":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.TextureCube;
                                break;

                            case "texture2d":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Texture2D;
                                break;

                            case "texture3d":
                                parameterKey.Class = EffectParameterClass.ShaderResourceView;
                                parameterKey.Type = EffectParameterType.Texture3D;
                                break;

                            case "rwtexture1d":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWTexture1D;
                                break;

                            case "rwtexture2d":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWTexture2D;
                                break;

                            case "rwtexture3d":
                                parameterKey.Class = EffectParameterClass.UnorderedAccessView;
                                parameterKey.Type = EffectParameterType.RWTexture3D;
                                break;

                            case "samplerstate":
                                parameterKey.Class = EffectParameterClass.Sampler;
                                parameterKey.Type = EffectParameterType.Sampler;
                                break;
                        }
                    }
                    else if (variableType is ScalarType)
                    {
                        // Uint and int are collapsed to int
                        if (variableType == ScalarType.Int || variableType == ScalarType.UInt)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type = variableType == ScalarType.Int ? EffectParameterType.Int : EffectParameterType.UInt;
                        }
                        else if (variableType == ScalarType.Float)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type = EffectParameterType.Float;
                        }
                        else if (variableType == ScalarType.Bool)
                        {
                            parameterKey.Class = EffectParameterClass.Scalar;
                            parameterKey.Type = EffectParameterType.Bool;
                        }

                        parameterKey.RowCount = 1;
                        parameterKey.ColumnCount = 1;
                    }
                    else if (variableType is VectorType)
                    {
                        if (variableType == VectorType.Float2 || variableType == VectorType.Float3 || variableType == VectorType.Float4)
                        {
                            parameterKey.Class = isColor ? EffectParameterClass.Color : EffectParameterClass.Vector;
                            parameterKey.Type = EffectParameterType.Float;
                        }
                        else if (variableType == VectorType.Int2 || variableType == VectorType.Int3 || variableType == VectorType.Int4)
                        {
                            parameterKey.Class = EffectParameterClass.Vector;
                            parameterKey.Type = EffectParameterType.Int;
                        }
                        else if (variableType == VectorType.UInt2 || variableType == VectorType.UInt3 || variableType == VectorType.UInt4)
                        {
                            parameterKey.Class = EffectParameterClass.Vector;
                            parameterKey.Type = EffectParameterType.UInt;
                        }

                        parameterKey.RowCount = 1;
                        parameterKey.ColumnCount = (variableType as VectorType).Dimension;
                    }
                    else if (variableType is MatrixType)
                    {
                        parameterKey.Class = EffectParameterClass.MatrixColumns;
                        parameterKey.Type = EffectParameterType.Float;
                        parameterKey.RowCount = (variableType as MatrixType).RowCount;
                        parameterKey.ColumnCount = (variableType as MatrixType).ColumnCount;
                    }
                    else if (variableType is StructType)
                    {
                        parameterKey.Class = EffectParameterClass.Struct;
                        parameterKey.RowCount = 1;
                        parameterKey.ColumnCount = 1;
                    }
                }

                return parameterKey;
            }

            return null;
        }
Ejemplo n.º 15
0
 private Node OnProcessor(Node nodeArg, ref NodeProcessorContext explorer)
 {
     return VisitDynamic(nodeArg);
 }
Ejemplo n.º 16
0
        protected override Node Visit(Node node)
        {
            if (node is IDeclaration)
            {
                var parameterKey = this.GetLinkParameterKey(node);
                if (parameterKey != null)
                    LinkVariable(effectReflection, ((IDeclaration)node).Name, parameterKey);
            }

            node.Childrens(OnProcessor);
            return node;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Helper to collects the referenced declarations recursively.
        /// </summary>
        /// <param name="collectedReferences">The collected declarations.</param>
        /// <param name="reference">The reference to collect.</param>
        private void CollectReferences(List<Node> collectedReferences, Node reference)
        {
            if (!collectedReferences.Contains(reference))
            {
                // Collect reference (if not already added)
                collectedReferences.Add(reference);

                // Collect recursively
                HashSet<Node> referencedFunctions;
                if (indirectReferences.TryGetValue((Node)reference, out referencedFunctions))
                {
                    foreach (var referencedFunction in referencedFunctions)
                        CollectReferences(collectedReferences, referencedFunction);
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Writes a link line using #line preprocessing directive with the specified node
        /// </summary>
        /// <param name="node">The node to use the Span.</param>
        /// <returns>This instance</returns>
        protected ShaderWriter WriteLinkLine(Node node)
        {
            if (!EnablePreprocessorLine || node.Span.Location.Line == 0)
                return this;

            var newSourceFile = node.Span.Location.FileSource;
            var sourceLocation = string.Empty;
            if (previousSourceFileName != newSourceFile)
            {
                sourceLocation = string.Format(" \"{0}\"", newSourceFile);
                previousSourceFileName = newSourceFile;
            }

            Append(Environment.NewLine).Append("#line {0}{1}", node.Span.Location.Line, sourceLocation).Append(Environment.NewLine);
            NewLine = true;
            lineCount++;
            return this;
        }
Ejemplo n.º 19
0
        public bool Run(Node startNode)
        {
            Visit(startNode);

            return complete;
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Replace a MemberReferenceExpression by a VariableReferenceExpression in the AST
 /// </summary>
 /// <param name="memberReferenceExpression">the member reference expression.</param>
 /// <param name="variableReferenceExpression">the variable reference expression.</param>
 /// <param name="parentNode">the parent node.</param>
 private static void ReplaceMemberReferenceExpressionByVariableReferenceExpression(MemberReferenceExpression memberReferenceExpression, VariableReferenceExpression variableReferenceExpression, Node parentNode)
 {
     var replacor = new XenkoReplaceVisitor(memberReferenceExpression, variableReferenceExpression);
     replacor.Run(parentNode);
 }
 public ExpressionNodeCouple(Expression expression, Node node)
 {
     Expression = expression;
     Node = node;
 }
Ejemplo n.º 22
0
        private static bool CanStrip(Node declaration, ICollection<Node> collectedReferences, bool stripUniforms)
        {
            if (declaration is Variable)
            {
                var variableDeclaration = (Variable)declaration;
                if ((!stripUniforms && variableDeclaration.Qualifiers.Contains(Ast.StorageQualifier.Uniform)))
                    return false;

                if (variableDeclaration.IsGroup)
                {
                    variableDeclaration.SubVariables.RemoveAll(x => !collectedReferences.Contains(x));
                    if (variableDeclaration.SubVariables.Count == 0)
                    {
                        return true;
                    }
                }
                else if (!collectedReferences.Contains(declaration))
                {
                    return true;
                }
            }
            else if (declaration is IDeclaration && !collectedReferences.Contains(declaration))
            {
                return true;
            }
            else if (declaration is ConstantBuffer)
            {
                // Strip cbuffer only if all of its member can be
                var constantBuffer = (ConstantBuffer)declaration;
                foreach (var member in constantBuffer.Members)
                {
                    if (!CanStrip(member, collectedReferences, stripUniforms))
                        return false;
                }
                return true;
            }
            return false;
        }
Ejemplo n.º 23
0
 public void Run(Node startNode)
 {
     VisitDynamic(startNode);
 }
 public MemberReferenceExpressionNodeCouple(MemberReferenceExpression member, Node node)
 {
     Member = member;
     Node = node;
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Searches from the specified node.
 /// </summary>
 /// <param name="node">The node.</param>
 /// <param name="filter">The filter function to apply to each node.</param>
 /// <param name="buildScopeDeclaration">if set to <c>true</c> [build scope declaration].</param>
 /// <param name="useNodeStack">if set to <c>true</c> [use node stack].</param>
 public static void Run(Node node, Func<Node, Node> filter, bool buildScopeDeclaration = false, bool useNodeStack = false)
 {
     var visitor = new SearchVisitor(filter, buildScopeDeclaration, useNodeStack);
     visitor.VisitDynamic(node);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DeclarationStatement"/> class.
 /// </summary>
 /// <param name="content">
 /// The content.
 /// </param>
 public DeclarationStatement(Node content)
 {
     Content = content;
 }
Ejemplo n.º 27
0
        protected override bool PreVisitNode(Node node)
        {
            var fileSource = Path.GetFileName(node.Span.Location.FileSource);

            if (string.Compare(fileSource, "internal_hlsl_declarations.hlsl", true) != 0 && node.Span.Length > 0)
            {
                while (SourceLocations.Count < lineCount)
                {
                    SourceLocations.Add(new SourceLocation(node.Span.Location.FileSource, node.Span.Location.Position, node.Span.Location.Line, 1));
                }
            }

            return base.PreVisitNode(node);
        }
Ejemplo n.º 28
0
 public void Run(Node initialNode)
 {
     Visit(initialNode);
 }
Ejemplo n.º 29
0
 public StatementNodeCouple(Statement statement, Node node)
 {
     Statement = statement;
     Node = node;
 }
Ejemplo n.º 30
0
 private void AddReference(Node parent, Node declaration)
 {
     if (parent != null && declaration != null)
     {
         HashSet<Node> childReferences;
         if (!indirectReferences.TryGetValue(parent, out childReferences))
         {
             childReferences = new HashSet<Node>();
             indirectReferences[parent] = childReferences;
         }
         if (!childReferences.Contains(declaration))
             childReferences.Add(declaration);
     }
 }