Пример #1
0
 private ParadoxStreamCreator(ShaderClassType shaderClassType, ModuleMixin mixin, List<ModuleMixin> mixins, LoggerResult errorLog)
 {
     shader = shaderClassType;
     mainModuleMixin = mixin;
     mixinInheritance = mixins;
     errorWarningLog = errorLog ?? new LoggerResult();
 }
 private ParadoxClassInstantiator(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);
 }
Пример #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;
 }
Пример #4
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.OccurenceId == 1))
                MixedShader.Members.AddRange(mixin.ParsingInfo.Typedefs);
            foreach (var mixin in MixinInheritance.Where(x => x.OccurenceId == 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
            ParadoxStreamCreator.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();
        }
Пример #5
0
        private void Visit(ShaderClassType shaderClassType)
        {
            Visit((Node)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);
            }
        }
Пример #6
0
        /// <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(ParadoxStorageQualifier.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;
                        }
                    }
                }
            }
        }
Пример #7
0
 public void Run(ShaderClassType shaderClassType)
 {
     var shader = new Shader();
     shader.Declarations.Add(shaderClassType);
     Run(shader);
 }
Пример #8
0
 public static void Run(ShaderClassType shaderClassType, ModuleMixin mixin, List<ModuleMixin> mixins, LoggerResult errorLog)
 {
     var streamCreator = new ParadoxStreamCreator(shaderClassType, mixin, mixins, errorLog);
     streamCreator.Run();
 }
 public MethodDeclarationShaderCouple(MethodDeclaration method, ShaderClassType shader)
 {
     Method = method;
     Shader = shader;
 }
Пример #10
0
 private 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>());
 }
Пример #11
0
 protected virtual void Visit(ShaderClassType shader)
 {
     Write(shader.Qualifiers.Any(qualifier => qualifier == ParadoxStorageQualifier.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();
     }
 }
Пример #12
0
 public void Run(ShaderClassType shaderClassType)
 {
     shaderName = shaderClassType.Name.Text;
     Visit(shaderClassType);
 }
Пример #13
0
 public static void Instantiate(ShaderClassType classType, Dictionary<string, Expression> expressions, Dictionary<string, Identifier> identifiers, bool autoGenericInstances, LoggerResult log)
 {
     var instantiator = new ParadoxClassInstantiator(classType, expressions, identifiers, autoGenericInstances, log);
     instantiator.Run();
 }
Пример #14
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;
 }
Пример #15
0
 public void Run(ShaderClassType shader)
 {
     Visit(shader);
 }
Пример #16
0
        /// <summary>
        /// Build the ModuleMixinInfo class
        /// </summary>
        /// <param name="shaderSource">the ShaderSource to load</param>
        /// <param name="macros">the macros applied on the source</param>
        /// <returns>the ModuleMixinInfo</returns>
        private ModuleMixinInfo BuildMixinInfo(ShaderSource shaderSource, SiliconStudio.Shaders.Parser.ShaderMacro[] macros)
        {
            ModuleMixinInfo mixinInfo = null;
            
            if (shaderSource is ShaderClassSource)
            {
                var shaderClassSource = shaderSource as ShaderClassSource;
                mixinInfo = new ModuleMixinInfo { ShaderSource = shaderClassSource, Macros = macros };
                LoadMixinFromClassSource(mixinInfo);
            }
            else if (shaderSource is ShaderMixinSource)
            {
                var shaderMixinSource = shaderSource as ShaderMixinSource;

                var shaderName = "Mix" + lastMixIndex;
                ++lastMixIndex;
                var fakeAst = new ShaderClassType(shaderName);
                foreach (var classSource in shaderMixinSource.Mixins)
                {
                    Identifier name;
                    if (classSource.GenericArguments != null && classSource.GenericArguments.Length > 0)
                        name = new IdentifierGeneric(classSource.ClassName, classSource.GenericArguments.Select(x => new Identifier(x.ToString())).ToArray());
                    else
                        name = new Identifier(classSource.ClassName);

                    fakeAst.BaseClasses.Add(new TypeName(name));
                }

                mixinInfo = new ModuleMixinInfo
                    {
                        MixinGenericName = shaderName,
                        Macros = macros, 
                        MixinAst = fakeAst, 
                        ShaderSource =  shaderSource,
                        SourceHash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(shaderName)), 
                        Instanciated = true
                    };
            }

            return mixinInfo;
        }
Пример #17
0
 public VariableShaderCouple(Variable variable, ShaderClassType shader)
 {
     Variable = variable;
     Shader = shader;
 }