private XenkoStreamCreator(ShaderClassType shaderClassType, ModuleMixin mixin, List<ModuleMixin> mixins, LoggerResult errorLog)
 {
     shader = shaderClassType;
     mainModuleMixin = mixin;
     mixinInheritance = mixins;
     errorWarningLog = errorLog ?? new LoggerResult();
 }
 private XenkoClassInstantiator(ShaderClassType classType, Dictionary<string, Expression> expressions, Dictionary<string, Identifier> identifiers, bool autoGenericInstances, LoggerResult log)
     : base(false, false)
 {
     shaderClassType = classType;
     expressionGenerics = expressions;
     identifiersGenerics = identifiers;
     this.autoGenericInstances = autoGenericInstances;
     logger = log;
     variableGenerics = shaderClassType.ShaderGenerics.ToDictionary(x => x.Name.Text, x => x);
 }
Exemplo n.º 3
0
 protected static void ParseClassGenerics(Identifier input, ShaderClassType dest)
 {
     // Parse generic identifier and convert it to simple identifier by adding contraint to the class type
     var genericIdentifier = input as ClassIdentifierGeneric;
     if (genericIdentifier != null)
     {
         foreach (var genericIdentifierItem in genericIdentifier.Generics)
         {
             dest.ShaderGenerics.Add(genericIdentifierItem);
         }
         input = new Identifier(input.Text) { Span = genericIdentifier.Span };
     }
     dest.Name = input;
 }
        public override Node Visit(ShaderClassType shaderClassType)
        {
            base.Visit(shaderClassType);

            // Allow to navigate to base classes
            foreach (var baseClass in shaderClassType.BaseClasses)
            {
                var firstOrDefault = analyzedModuleMixin.InheritanceList.FirstOrDefault(moduleMixin => moduleMixin.Shader.Name.Text == baseClass.Name.Text);
                if (firstOrDefault != null)
                {
                    var declaration = firstOrDefault.Shader;
                    baseClass.TypeInference.Declaration = declaration;
                }

                parsingInfo.NavigableNodes.Add(baseClass);
            }

            return shaderClassType;
        }
        /// <summary>
        /// Finds the member type reference.
        /// </summary>
        /// <param name="shaderDecl">Type of the shader</param>
        /// <param name="memberReference">The member reference.</param>
        protected void FindMemberTypeReference(ShaderClassType shaderDecl, MemberReferenceExpression memberReference)
        {
            var mixin = moduleMixins.FirstOrDefault(x => x.Shader == shaderDecl);
            if (mixin != null)
            {
                var shader = mixin.InheritanceList.FirstOrDefault(x => x.MixinName == memberReference.Member.Text);
                if (shader != null)
                {
                    memberReference.TypeInference.Declaration = shader.Shader;
                    memberReference.TypeInference.TargetType = shader.Shader;
                    return;
                }

                var variableDecl = mixin.VirtualTable.Variables.FirstOrDefault(x => x.Variable.Name.Text == memberReference.Member.Text);
                if (variableDecl != null)
                {
                    var isStream = IsStreamMember(memberReference);
                    if (!isStream || variableDecl.Variable.Qualifiers.Contains(XenkoStorageQualifier.Stream))
                    {
                        memberReference.TypeInference.Declaration = variableDecl.Variable;
                        memberReference.TypeInference.TargetType = variableDecl.Variable.Type.ResolveType();
                        return;
                    }
                }

                if (ParentNode is MethodInvocationExpression)
                {
                    var invocationExpression = ParentNode as MethodInvocationExpression;
                    if (ReferenceEquals(invocationExpression.Target, memberReference))
                    {
                        var methodDecl = mixin.VirtualTable.Methods.Select(x => x.Method).FirstOrDefault(x => x.IsSameSignature(invocationExpression));
                        if (methodDecl != null)
                        {
                            memberReference.TypeInference.Declaration = methodDecl;
                            invocationExpression.TypeInference.TargetType = methodDecl.ReturnType.ResolveType();
                            return;
                        }
                    }
                }
            }
        }
 public void Run(ShaderClassType shaderClassType)
 {
     Visit(shaderClassType);
 }
 public void Run(ShaderClassType shaderClassType)
 {
     shaderName = shaderClassType.Name.Text;
     Visit(shaderClassType);
 }
 public override void Visit(ShaderClassType shaderClassType)
 {
     // Check if there are any parameter keys in ShaderClassType and ConstantBuffer
     CheckParameterKeys(shaderClassType.Members.OfType<Variable>());
     CheckParameterKeys(shaderClassType.Members.OfType<ConstantBuffer>().SelectMany(cbuffer => cbuffer.Members).OfType<Variable>());
 }
 public override void Visit(ShaderClassType shader)
 {
     Write(shader.Qualifiers.Any(qualifier => qualifier == XenkoStorageQualifier.Internal) ? "internal " : "public ");
     Write("static partial class ");
     Write(shader.Name);
     Write("Keys");
     {
         OpenBrace();
         foreach (var decl in shader.Members)
         {
             if (decl is Variable)
             {
                 VisitDynamic(decl);
             }
             else if (decl is ConstantBuffer)
             {
                 foreach (var subDecl in ((ConstantBuffer)decl).Members.OfType<Variable>())
                 {
                     VisitDynamic(subDecl);
                 }
             }
         }
         CloseBrace();
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Creates a new AST with all the definitions
        /// </summary>
        private void GenerateShader()
        {
            MixedShader = new ShaderClassType(mainModuleMixin.MixinName);

            // add constants
            var constants = mainModuleMixin.ClassReferences.VariablesReferences.Select(x => x.Key).Where(x => x.Qualifiers.Contains(StorageQualifier.Const)).ToList();
            MixedShader.Members.AddRange(constants);
            
            // Add structures, typedefs
            foreach (var mixin in MixinInheritance.Where(x => x.OccurrenceId == 1))
                MixedShader.Members.AddRange(mixin.ParsingInfo.Typedefs);
            foreach (var mixin in MixinInheritance.Where(x => x.OccurrenceId == 1))
                MixedShader.Members.AddRange(mixin.ParsingInfo.StructureDefinitions);

            var sortedNodes = SortNodes(MixedShader.Members);
            MixedShader.Members.Clear();
            MixedShader.Members.AddRange(sortedNodes);

            // Create constant buffer
            GroupByConstantBuffer();
            
            // add the methods
            MixedShader.Members.AddRange(mainModuleMixin.ClassReferences.MethodsReferences.Select(x => x.Key).Where(x => x is MethodDefinition));

            // remove duplicates
            MixedShader.Members = MixedShader.Members.Distinct().ToList();

            // Create streams
            XenkoStreamCreator.Run(MixedShader, mainModuleMixin, MixinInheritance, log);
            
            if (log.HasErrors)
                return;

            // deal with foreach statements
            ExpandForEachStatements(mainModuleMixin);
            foreach (var externMixList in CompositionsPerVariable.Values)
            {
                foreach (var externMix in externMixList)
                    ExpandForEachStatements(externMix);
            }
            
            // remove useless variables
            RemoveUselessVariables();
        }
 public VariableShaderCouple(Variable variable, ShaderClassType shader)
 {
     Variable = variable;
     Shader = shader;
 }
Exemplo n.º 12
0
 public static void Run(ShaderClassType shaderClassType, ModuleMixin mixin, List<ModuleMixin> mixins, LoggerResult errorLog)
 {
     var streamCreator = new XenkoStreamCreator(shaderClassType, mixin, mixins, errorLog);
     streamCreator.Run();
 }
Exemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="shader">the shader AST</param>
 public void SetShaderAst(ShaderClassType shader)
 {
     if (Shader != null)
         throw new Exception("[ModuleMixin.SetShaderAst] Shader has already been set");
     Shader = shader;
     MixinName = shader.Name.Text;
 }
Exemplo n.º 14
0
 public void Run(ShaderClassType shaderClassType)
 {
     var shader = new Shader();
     shader.Declarations.Add(shaderClassType);
     Run(shader);
 }
 public static void Instantiate(ShaderClassType classType, Dictionary<string, Expression> expressions, Dictionary<string, Identifier> identifiers, bool autoGenericInstances, LoggerResult log)
 {
     var instantiator = new XenkoClassInstantiator(classType, expressions, identifiers, autoGenericInstances, log);
     instantiator.Run();
 }