/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="moduleMixin">the final shader information</param>
        /// <param name="log">The log.</param>
        /// <param name="context">all the mixins in the context</param>
        /// <param name="compositionsPerVariable">The compositions per variable.</param>
        /// <param name="cloneContext">The clone context.</param>
        /// <exception cref="System.ArgumentNullException">
        /// moduleMixin
        /// or
        /// log
        /// or
        /// context
        /// </exception>
        public XenkoShaderMixer(ModuleMixin moduleMixin, LoggerResult log, Dictionary<string, ModuleMixin> context, CompositionDictionary compositionsPerVariable, CloneContext cloneContext = null)
        {
            if (moduleMixin == null)
                throw new ArgumentNullException("moduleMixin");

            if (log == null) 
                throw new ArgumentNullException("log");

            if (context == null)
                throw new ArgumentNullException("context");

            this.log = log;

            mixContext = context;
            mainModuleMixin = moduleMixin;
            defaultCloneContext = cloneContext;

            if (compositionsPerVariable != null)
                CompositionsPerVariable = compositionsPerVariable;
            else
                CompositionsPerVariable = new CompositionDictionary();

            var mixinsToAnalyze = new Stack<ModuleMixin>(CompositionsPerVariable.Values.SelectMany(x => x));
            mixinsToAnalyze.Push(mainModuleMixin);

            while (mixinsToAnalyze.Count > 0)
                AddDefaultCompositions(mixinsToAnalyze);
        }
Esempio n. 2
0
        protected override void CloneTo(CloneContext clonectx, Expression target)
        {
            base.CloneTo (clonectx, target);

            AQueryClause t = (AQueryClause) target;

            if (block != null)
                t.block = (QueryBlock) clonectx.LookupBlock (block);

            if (next != null)
                t.next = (AQueryClause) next.Clone (clonectx);
        }
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 => new IncludeResultOperator(NavigationPropertyPath)
 {
     _chainedNavigationProperties = _chainedNavigationProperties
 };
Esempio n. 4
0
 public void SetUp()
 {
     _mainFromClause = ExpressionHelper.CreateMainFromClause_Int();
     _cloneContext   = new CloneContext(new QuerySourceMapping());
 }
		public Arguments Clone (CloneContext ctx)
		{
			Arguments cloned = new Arguments (args.Count);
			foreach (Argument a in args)
				cloned.Add (a.Clone (ctx));

			return cloned;
		}
Esempio n. 6
0
        /// <summary>
        /// create the context for each composition by cloning their dependencies
        /// </summary>
        /// <param name="shaderSource">the entry ShaderSource (root)</param>
        /// <param name="dictionary">the ouputed compositions</param>
        /// <param name="compilationContext">the compilation context</param>
        /// <param name="cloneContext">The clone context.</param>
        /// <returns>a list of all the needed mixins</returns>
        private static List<ModuleMixin> BuildCompositionsDictionary(ShaderSource shaderSource, CompositionDictionary dictionary, ShaderCompilationContext compilationContext, CloneContext cloneContext, LoggerResult log)
        {
            if (shaderSource is ShaderMixinSource)
            {
                var shaderMixinSource = shaderSource as ShaderMixinSource;

                var finalModule = compilationContext.GetModuleMixinFromShaderSource(shaderSource);

                //PerformanceLogger.Start(PerformanceStage.DeepClone);
                finalModule = finalModule.DeepClone(new CloneContext(cloneContext));
                //PerformanceLogger.Pause(PerformanceStage.DeepClone);

                foreach (var composition in shaderMixinSource.Compositions)
                {
                    //look for the key
                    var foundVars = finalModule.FindAllVariablesByName(composition.Key).Where(value => value.Variable.Qualifiers.Contains(ParadoxStorageQualifier.Compose)).ToList();

                    if (foundVars.Count > 1)
                    {
                        log.Error(ParadoxMessageCode.ErrorAmbiguousComposition, new SourceSpan(), composition.Key);
                    }
                    else if (foundVars.Count > 0)
                    {
                        Variable foundVar = foundVars[0].Variable;
                        var moduleMixins = BuildCompositionsDictionary(composition.Value, dictionary, compilationContext, cloneContext, log);
                        if (moduleMixins == null)
                            return null;

                        dictionary.Add(foundVar, moduleMixins);
                    }
                    else
                    {
                        // No matching variable was found
                        // TODO: log a message?
                    }
                }
                return new List<ModuleMixin> { finalModule };
            }


            if (shaderSource is ShaderClassSource)
            {
                var finalModule = compilationContext.GetModuleMixinFromShaderSource(shaderSource);

                //PerformanceLogger.Start(PerformanceStage.DeepClone);
                finalModule = finalModule.DeepClone(new CloneContext(cloneContext));
                //PerformanceLogger.Pause(PerformanceStage.DeepClone);

                return new List<ModuleMixin> { finalModule };
            }

            if (shaderSource is ShaderArraySource)
            {
                var shaderArraySource = shaderSource as ShaderArraySource;
                var compositionArray = new List<ModuleMixin>();
                foreach (var shader in shaderArraySource.Values)
                {
                    var mixin = BuildCompositionsDictionary(shader, dictionary, compilationContext, cloneContext, log);
                    if (mixin == null)
                        return null;
                    compositionArray.AddRange(mixin);
                }
                return compositionArray;
            }

            return null;
        }
		protected override void CloneTo (CloneContext clonectx, Statement t)
		{
			var target = (AsLocalFunction) t;

			target.Name = Name;
			target.MethodExpr = MethodExpr.Clone (clonectx) as AnonymousMethodExpression;
			target.VarDecl = VarDecl.Clone (clonectx) as BlockVariableDeclaration;
		}
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			var target = (AsObjectInitializer) t;

			target.elements = new List<Expression> (elements.Count);
			foreach (var element in elements)
				target.elements.Add (element.Clone (clonectx));
		}
Esempio n. 9
0
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new UnionResultOperator(_itemName, _itemType, _source2));
 }
Esempio n. 10
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			Assign _target = (Assign) t;

			_target.target = target.Clone (clonectx);
			_target.source = source.Clone (clonectx);
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new CountAsyncResultOperator(_cancel));
 }
 /// <inheritdoc />
 public override ResultOperatorBase Clone(CloneContext cloneContext) =>
 new CountAsyncResultOperator();
Esempio n. 13
0
 /// <inheritdoc />
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new AllResultOperator(Predicate));
 }
Esempio n. 14
0
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new StatsResultOperator(Parameter));
 }
Esempio n. 15
0
        /// <summary>
        ///     Clones this clause.
        /// </summary>
        /// <param name="cloneContext">The clones of all query source clauses are registered with this <see cref="CloneContext" />.</param>
        /// <returns></returns>
        public virtual NestClause Clone(CloneContext cloneContext)
        {
            var clone = new NestClause(ItemName, ItemType, InnerSequence, KeySelector, IsLeftOuterNest);

            return(clone);
        }
Esempio n. 16
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     return new ThrowStatement()
     {
         ThrowExpr = this.ThrowExpr
     };
 }
 /// <summary>
 ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
 ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
 ///     any release. You should only use it directly in your code with extreme caution and knowing that
 ///     doing so can result in application failures when updating to a new Entity Framework Core release.
 /// </summary>
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 => new IgnoreQueryFiltersResultOperator();
Esempio n. 18
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     IfStatement clone = new IfStatement();
     ctx.Map(this, clone);
     foreach (Expression e in Conditions)
         clone.Conditions.Add(e);
     foreach (Statement b in Branches)
         clone.Branches.Add(b.GetClone(ctx));
     return clone;
 }
Esempio n. 19
0
        /// <summary>
        /// Mixes shader parts to produces a single HLSL file shader.
        /// </summary>
        /// <param name="shaderMixinSource">The shader source.</param>
        /// <param name="macros">The shader perprocessor macros.</param>
        /// <param name="modifiedShaders">The list of modified shaders.</param>
        /// <returns>The combined shader in AST form.</returns>
        public ShaderMixinParsingResult Parse(ShaderMixinSource shaderMixinSource, Paradox.Shaders.ShaderMacro[] macros = null)
        {
            // Creates a parsing result
            HashSet <ModuleMixinInfo> mixinsToAnalyze;
            ShaderMixinParsingResult  parsingResult;
            var context = ParseAndAnalyze(shaderMixinSource, macros, out parsingResult, out mixinsToAnalyze);

            // Return directly if there was any errors
            if (parsingResult.HasErrors)
            {
                return(parsingResult);
            }

            // Update the clone context in case new instances of classes are created
            lock (hlslCloneContext)
            {
                HlslSemanticAnalysis.UpdateCloneContext(hlslCloneContext);
            }

            // only clone once the stage classes
            var mixCloneContext = new CloneContext(hlslCloneContext);

            foreach (var mixinInfo in mixinsToAnalyze)
            {
                foreach (var mixin in mixinInfo.Mixin.MinimalContext.Where(x => x.StageOnlyClass))
                {
                    mixin.DeepClone(mixCloneContext);
                }
            }

            // ----------------------------------------------------------
            // Perform Shader Mixer
            // ----------------------------------------------------------
            var externDict      = new Dictionary <Variable, List <ModuleMixin> >();
            var finalModuleList = BuildCompositionsDictionary(shaderMixinSource, externDict, context, mixCloneContext);
            //PerformanceLogger.Stop(PerformanceStage.DeepClone);
            var mixinDictionary = BuildMixinDictionary(finalModuleList);

            if (finalModuleList != null)
            {
                var finalModule = finalModuleList[0];
                //PerformanceLogger.Start(PerformanceStage.Mix);
                var mixer = new ParadoxShaderMixer(finalModule, parsingResult, mixinDictionary, externDict, new CloneContext(mixCloneContext));
                mixer.Mix();
                //PerformanceLogger.Stop(PerformanceStage.Mix);

                // Return directly if there was any errors
                if (parsingResult.HasErrors)
                {
                    return(parsingResult);
                }

                var finalShader = mixer.GetMixedShader();

                parsingResult.Reflection = new EffectReflection();
                var pdxShaderLinker = new ShaderLinker(parsingResult);
                pdxShaderLinker.Run(finalShader);

                // Return directly if there was any errors
                if (parsingResult.HasErrors)
                {
                    return(parsingResult);
                }

                // Find all entry points
                // TODO: make this configurable by CompileParameters
                foreach (var stage in new[] { ShaderStage.Compute, ShaderStage.Vertex, ShaderStage.Hull, ShaderStage.Domain, ShaderStage.Geometry, ShaderStage.Pixel })
                {
                    var entryPoint = finalShader.Declarations.OfType <MethodDefinition>().FirstOrDefault(f => f.Attributes.OfType <AttributeDeclaration>().Any(a => a.Name == "EntryPoint" && (string)a.Parameters[0].Value == stage.ToString()));

                    if (entryPoint == null)
                    {
                        continue;
                    }

                    parsingResult.EntryPoints[stage] = entryPoint.Name.Text;

                    // When this is a compute shader, there is no need to scan other stages
                    if (stage == ShaderStage.Compute)
                    {
                        break;
                    }
                }

                var typeCleaner = new ParadoxShaderCleaner();
                typeCleaner.Run(finalShader);

                //PerformanceLogger.Stop(PerformanceStage.Global);

                //PerformanceLogger.PrintLastResult();
                //SemanticPerformance.PrintResult();
                //MixPerformance.PrintResult();
                //GenerateShaderPerformance.PrintResult();
                //StreamCreatorPerformance.PrintResult();
                //ShaderLoader.PrintTime();

                //PerformanceLogger.WriteOut(52);

                parsingResult.Shader = finalShader;
            }

            return(parsingResult);
        }
Esempio n. 20
0
        public void ExportDwgToJpg(string destPath)
        {
            string sourcePath = String.Format("{0}{1}.dwg", DefaultDwgFolder, Control.ControlNo);
            Dictionary<string, string> dictDim = new Dictionary<string, string>();

            foreach (ControlDrawingDetail detail in ControlDrawingDetails)
            {
                if (dictDim.ContainsKey(detail.Dim.DimNo) == false)
                {
                    dictDim.Add(detail.Dim.DimNo, detail.DimValue);
                }
            }

            try
            {
                DxfModel readModel = DwgReader.Read(sourcePath);
                DxfModel writeModel = new DxfModel();
                CloneContext ct = new CloneContext(readModel, ReferenceResolutionType.CloneMissing);
                TransformConfig tc = new TransformConfig();
                Matrix4D translation = Transformation4D.Translation(250, 0, 0);

                ct.RenameClashingBlocks = true;

                for (int i = 0; i < readModel.Entities.Count; i++)
                {
                    DxfEntity block = readModel.Entities[i];

                    if (block.GetType() == typeof(DxfMText))
                    {
                        DxfMText di = (DxfMText)block;
                        if (dictDim.ContainsKey(di.SimplifiedText))
                        {
                            di.Text = dictDim[di.SimplifiedText];
                            di.Width = di.BoxWidth * 2;
                        }

                        writeModel.Entities.Add(di);
                    }
                    else if (block.GetType() == typeof(DxfText))
                    {
                        DxfText di = (DxfText)block;
                        if (dictDim.ContainsKey(di.SimplifiedText))
                        {
                            di.Text = dictDim[di.SimplifiedText];
                        }

                        writeModel.Entities.Add(di);
                    }
                    else
                    {
                        writeModel.Entities.Add(block);
                    }
                }

                ct.ResolveReferences();
                CADHelper.ExportToJpg(writeModel, destPath);
            }
            catch (Exception exc)
            {
                Tracing.Tracer.LogError(exc.Message);
                Logger.For(this).Error(exc.Message);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// create the context for each composition by cloning their dependencies
        /// </summary>
        /// <param name="shaderSource">the entry ShaderSource (root)</param>
        /// <param name="dictionary">the ouputed compositions</param>
        /// <param name="compilationContext">the compilation context</param>
        /// <param name="cloneContext">The clone context.</param>
        /// <returns>a list of all the needed mixins</returns>
        private List <ModuleMixin> BuildCompositionsDictionary(ShaderSource shaderSource, Dictionary <Variable, List <ModuleMixin> > dictionary, ShaderCompilationContext compilationContext, CloneContext cloneContext)
        {
            if (shaderSource is ShaderMixinSource)
            {
                var shaderMixinSource = shaderSource as ShaderMixinSource;

                var finalModule = compilationContext.GetModuleMixinFromShaderSource(shaderSource);

                //PerformanceLogger.Start(PerformanceStage.DeepClone);
                finalModule = finalModule.DeepClone(new CloneContext(cloneContext));
                //PerformanceLogger.Pause(PerformanceStage.DeepClone);

                foreach (var composition in shaderMixinSource.Compositions)
                {
                    //look for the key
                    var foundVars = finalModule.FindAllVariablesByName(composition.Key).Where(value => value.Variable.Qualifiers.Contains(ParadoxStorageQualifier.Compose)).ToList();

                    if (foundVars.Count > 0)
                    {
                        Variable foundVar     = foundVars[0].Variable;
                        var      moduleMixins = BuildCompositionsDictionary(composition.Value, dictionary, compilationContext, cloneContext);
                        if (moduleMixins == null)
                        {
                            return(null);
                        }

                        dictionary.Add(foundVar, moduleMixins);
                    }
                    else
                    {
                        // TODO: log an error?
                    }
                }
                return(new List <ModuleMixin> {
                    finalModule
                });
            }


            if (shaderSource is ShaderClassSource)
            {
                var finalModule = compilationContext.GetModuleMixinFromShaderSource(shaderSource);

                //PerformanceLogger.Start(PerformanceStage.DeepClone);
                finalModule = finalModule.DeepClone(new CloneContext(cloneContext));
                //PerformanceLogger.Pause(PerformanceStage.DeepClone);

                return(new List <ModuleMixin> {
                    finalModule
                });
            }

            if (shaderSource is ShaderArraySource)
            {
                var shaderArraySource = shaderSource as ShaderArraySource;
                var compositionArray  = new List <ModuleMixin>();
                foreach (var shader in shaderArraySource.Values)
                {
                    var mixin = BuildCompositionsDictionary(shader, dictionary, compilationContext, cloneContext);
                    if (mixin == null)
                    {
                        return(null);
                    }
                    compositionArray.AddRange(mixin);
                }
                return(compositionArray);
            }

            return(null);
        }
Esempio n. 22
0
//		protected override void DoEmitJs (JsEmitContext jec) 
//		{
//			expr.EmitJs (jec);
//		}
		
//		public override void EmitJs (JsEmitContext jec)
//		{
//			DoEmitJs (jec);
//		}

		protected override void CloneTo (CloneContext clonectx, Statement target)
		{
			var t = target as AsNonAssignStatementExpression;
			t.expr = expr.Clone (clonectx);
		}
Esempio n. 23
0
 /// <summary>
 /// Clones this clause, adjusting all <see cref="QuerySourceReferenceExpression"/> instances held by it as defined by
 /// <paramref name="cloneContext"/>.
 /// </summary>
 /// <param name="cloneContext">The clones of all query source clauses are registered with this <see cref="CloneContext"/>.</param>
 /// <returns>A clone of this clause.</returns>
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new GroupResultOperator(ItemName, KeySelector, ElementSelector));
 }
Esempio n. 24
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			AsIn target = (AsIn) t;

			target.expr = expr.Clone (clonectx);
			target.objExpr = objExpr.Clone (clonectx);
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new DefaultIfEmptyResultOperator(OptionalDefaultValue));
 }
Esempio n. 26
0
            public void Initialize(CloneContext previousCloneContext)
            {
                // Clone original context
                var cloneContext = new CloneContext();

                foreach (var keyValurPair in previousCloneContext)
                {
                    cloneContext.Add(keyValurPair.Key, keyValurPair.Value);
                }

                // Removes the method to clone
                cloneContext.Remove(Method);

                // Clone the old method with the clone context
                NewMethod = Method.DeepClone(cloneContext);

                var oldParameters = NewMethod.Parameters;
                NewMethod.Parameters = new List<Parameter>();
                int j = 0;
                for (int i = 0; i < oldParameters.Count; i++)
                {
                    var parameter = oldParameters[i];
                    var variableValue = (Variable)this.Method.Parameters[i].GetTag(ScopeValueKey);
                    if (variableValue != null)
                    {
                        this.NewMethod.Body.Insert(j, new DeclarationStatement(parameter));
                        j++;
                        parameter.InitialValue = new VariableReferenceExpression(variableValue.Name) { TypeInference = { Declaration = variableValue, TargetType = variableValue.Type } };
                    }
                    else
                        NewMethod.Parameters.Add(parameter);
                }

                // Create new method with new method name
                var methodNameBuild = new StringBuilder();
                methodNameBuild.Append(Method.Name);
                foreach (var variable in Variables)
                {
                    methodNameBuild.Append("_");
                    methodNameBuild.Append(variable.Name);
                }
                methodName = methodNameBuild.ToString();
                NewMethod.Name = methodName;
            }
Esempio n. 27
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     return new BreakCaseStatement()
     {
         CaseStmt = (CaseStatement)ctx.Map(CaseStmt)
     };
 }
Esempio n. 28
0
		protected override void CloneTo (CloneContext clonectx, Expression target)
		{
			Join t = (Join) target;
			t.inner_selector = (QueryBlock) inner_selector.Clone (clonectx);
			t.outer_selector = (QueryBlock) outer_selector.Clone (clonectx);
			base.CloneTo (clonectx, t);
		}	
Esempio n. 29
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     GotoStatement result = new GotoStatement();
     if (Target != null)
         ctx.Complete += () => result.Target = ctx.Map(Target);
     return result;
 }
Esempio n. 30
0
 public void CopyFrom(CloneContext cloneContext, BackgroundFillInfo from)
 {
     this.double_0       = from.double_0;
     this.color_0        = from.color_0;
     this.transparency_0 = from.transparency_0;
 }
Esempio n. 31
0
 public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext)
 {
     base.CopyFrom(from, cloneContext);
     this.Distance = ((DxfBlockLinearGrip)from).Distance;
 }
Esempio n. 32
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     return new GotoCaseStatement()
     {
         CaseStmt = (CaseStatement)ctx.Map(CaseStmt),
         TargetIndex = this.TargetIndex
     };
 }
Esempio n. 33
0
 public override void CopyFrom(DxfHandledObject from, CloneContext cloneContext)
 {
     base.CopyFrom(from, cloneContext);
     this.IsPerpendicular = ((DxfBlockAlignmentParameter)from).IsPerpendicular;
 }
Esempio n. 34
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     return this;
 }
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new FirstResultOperator(ReturnDefaultWhenEmpty));
 }
Esempio n. 36
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     return new CallStatement()
     {
         Callee = this.Callee,
         Arguments = this.Arguments
     };
 }
Esempio n. 37
0
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new IntersectResultOperator(Source2));
 }
Esempio n. 38
0
 internal override Statement CloneInternal(CloneContext ctx)
 {
     CaseStatement clone = new CaseStatement()
     {
         Selector = this.Selector
     };
     ctx.Map(this, clone);
     foreach (Expression e in Cases)
         clone.Cases.Add(e);
     foreach (Statement b in Branches)
         clone.Branches.Add(b.GetClone(ctx));
     return clone;
 }
Esempio n. 39
0
 public override IGraphCloneable Clone(CloneContext cloneContext)
 {
     throw new Exception("The class is base. Clone shouldn't be used.");
 }
Esempio n. 40
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			CompoundAssign ctarget = (CompoundAssign) t;

			ctarget.right = ctarget.source = source.Clone (clonectx);
			ctarget.target = target.Clone (clonectx);
		}
 /// <inheritdoc />
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new AggregateFromSeedResultOperator(Seed, Func, OptionalResultSelector));
 }
Esempio n. 42
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			CompletionMemberAccess target = (CompletionMemberAccess) t;

			if (targs != null)
				target.targs = targs.Clone ();

			target.expr = expr.Clone (clonectx);
		}
Esempio n. 43
0
        /// <summary>
        /// Mixes shader parts to produces a single HLSL file shader.
        /// </summary>
        /// <param name="shaderMixinSource">The shader source.</param>
        /// <param name="macros">The shader perprocessor macros.</param>
        /// <param name="modifiedShaders">The list of modified shaders.</param>
        /// <returns>The combined shader in AST form.</returns>
        public ShaderMixinParsingResult Parse(ShaderMixinSource shaderMixinSource, Stride.Shaders.ShaderMacro[] macros = null)
        {
            // Make in-memory shader classes known to the source manager
            foreach (var x in shaderMixinSource.Mixins.OfType <ShaderClassString>())
            {
                SourceManager.AddShaderSource(x.ClassName, x.ShaderSourceCode, x.ClassName);
            }

            // Creates a parsing result
            HashSet <ModuleMixinInfo> mixinsToAnalyze;
            ShaderMixinParsingResult  parsingResult;
            var context = ParseAndAnalyze(shaderMixinSource, macros, out parsingResult, out mixinsToAnalyze);

            // Return directly if there was any errors
            if (parsingResult.HasErrors)
            {
                return(parsingResult);
            }

            // Update the clone context in case new instances of classes are created
            CloneContext mixCloneContext;

            lock (hlslCloneContextLock)
            {
                if (hlslCloneContext == null)
                {
                    hlslCloneContext = new CloneContext();

                    // Create the clone context with the instances of Hlsl classes
                    HlslSemanticAnalysis.FillCloneContext(hlslCloneContext);
                }

                HlslSemanticAnalysis.UpdateCloneContext(hlslCloneContext);
                mixCloneContext = new CloneContext(hlslCloneContext);
            }

            // only clone once the stage classes
            foreach (var mixinInfo in mixinsToAnalyze)
            {
                foreach (var mixin in mixinInfo.Mixin.MinimalContext.Where(x => x.StageOnlyClass))
                {
                    mixin.DeepClone(mixCloneContext);
                }
            }

            // ----------------------------------------------------------
            // Perform Shader Mixer
            // ----------------------------------------------------------
            var externDict      = new CompositionDictionary();
            var finalModuleList = BuildCompositionsDictionary(shaderMixinSource, externDict, context, mixCloneContext, parsingResult);

            //PerformanceLogger.Stop(PerformanceStage.DeepClone);

            if (parsingResult.HasErrors)
            {
                return(parsingResult);
            }

            // look for stage compositions and add the links between variables and compositions when necessary
            var extraExternDict = new Dictionary <Variable, List <ModuleMixin> >();

            foreach (var item in externDict)
            {
                if (item.Key.Qualifiers.Contains(StrideStorageQualifier.Stage))
                {
                    FullLinkStageCompositions(item.Key, item.Value, externDict, extraExternDict, parsingResult);
                }
            }
            foreach (var item in extraExternDict)
            {
                externDict.Add(item.Key, item.Value);
            }

            var mixinDictionary = BuildMixinDictionary(finalModuleList);

            if (finalModuleList != null)
            {
                var finalModule = finalModuleList[0];
                //PerformanceLogger.Start(PerformanceStage.Mix);
                parsingResult.Reflection = new EffectReflection();
                var mixer = new StrideShaderMixer(finalModule, parsingResult, mixinDictionary, externDict, new CloneContext(mixCloneContext));
                mixer.Mix();
                //PerformanceLogger.Stop(PerformanceStage.Mix);

                // Return directly if there was any errors
                if (parsingResult.HasErrors)
                {
                    return(parsingResult);
                }

                var finalShader = mixer.GetMixedShader();

                // Simplifies the shader by removing dead code
                var simplifier = new ExpressionSimplifierVisitor();
                simplifier.Run(finalShader);

                var sdShaderLinker = new ShaderLinker(parsingResult);
                sdShaderLinker.Run(finalShader);

                // Return directly if there was any errors
                if (parsingResult.HasErrors)
                {
                    return(parsingResult);
                }

                // Find all entry points
                // TODO: make this configurable by CompileParameters
                foreach (var stage in new[] { ShaderStage.Compute, ShaderStage.Vertex, ShaderStage.Hull, ShaderStage.Domain, ShaderStage.Geometry, ShaderStage.Pixel })
                {
                    var entryPoint = finalShader.Declarations.OfType <MethodDefinition>().FirstOrDefault(f => f.Attributes.OfType <AttributeDeclaration>().Any(a => a.Name == "EntryPoint" && (string)a.Parameters[0].Value == stage.ToString()));

                    if (entryPoint == null)
                    {
                        continue;
                    }

                    parsingResult.EntryPoints[stage] = entryPoint.Name.Text;

                    // When this is a compute shader, there is no need to scan other stages
                    if (stage == ShaderStage.Compute)
                    {
                        break;
                    }
                }

                var typeCleaner = new StrideShaderCleaner();
                typeCleaner.Run(finalShader);

                //PerformanceLogger.Stop(PerformanceStage.Global);

                //PerformanceLogger.PrintLastResult();
                //SemanticPerformance.PrintResult();
                //MixPerformance.PrintResult();
                //GenerateShaderPerformance.PrintResult();
                //StreamCreatorPerformance.PrintResult();
                //ShaderLoader.PrintTime();

                //PerformanceLogger.WriteOut(52);

                parsingResult.Shader = finalShader;
            }

            return(parsingResult);
        }
Esempio n. 44
0
		protected override void CloneTo (CloneContext clonectx, Statement target)
		{
			// nothing needed.
		}
Esempio n. 45
0
        /// <summary>
        /// create the context for each composition by cloning their dependencies
        /// </summary>
        /// <param name="shaderSource">the entry ShaderSource (root)</param>
        /// <param name="dictionary">the ouputed compositions</param>
        /// <param name="compilationContext">the compilation context</param>
        /// <param name="cloneContext">The clone context.</param>
        /// <returns>a list of all the needed mixins</returns>
        private static List <ModuleMixin> BuildCompositionsDictionary(ShaderSource shaderSource, CompositionDictionary dictionary, ShaderCompilationContext compilationContext, CloneContext cloneContext, LoggerResult log)
        {
            if (shaderSource is ShaderMixinSource)
            {
                var shaderMixinSource = shaderSource as ShaderMixinSource;

                var finalModule = compilationContext.GetModuleMixinFromShaderSource(shaderSource);

                //PerformanceLogger.Start(PerformanceStage.DeepClone);
                finalModule = finalModule.DeepClone(new CloneContext(cloneContext));
                //PerformanceLogger.Pause(PerformanceStage.DeepClone);

                foreach (var composition in shaderMixinSource.Compositions)
                {
                    //look for the key
                    var foundVars = finalModule.FindAllVariablesByName(composition.Key).Where(value => value.Variable.Qualifiers.Contains(StrideStorageQualifier.Compose)).ToList();

                    if (foundVars.Count > 1)
                    {
                        log.Error(StrideMessageCode.ErrorAmbiguousComposition, new SourceSpan(), composition.Key);
                    }
                    else if (foundVars.Count > 0)
                    {
                        Variable foundVar     = foundVars[0].Variable;
                        var      moduleMixins = BuildCompositionsDictionary(composition.Value, dictionary, compilationContext, cloneContext, log);
                        if (moduleMixins == null)
                        {
                            return(null);
                        }

                        dictionary.Add(foundVar, moduleMixins);
                    }
                    else
                    {
                        // No matching variable was found
                        // TODO: log a message?
                    }
                }
                return(new List <ModuleMixin> {
                    finalModule
                });
            }


            if (shaderSource is ShaderClassCode)
            {
                var finalModule = compilationContext.GetModuleMixinFromShaderSource(shaderSource);

                //PerformanceLogger.Start(PerformanceStage.DeepClone);
                finalModule = finalModule.DeepClone(new CloneContext(cloneContext));
                //PerformanceLogger.Pause(PerformanceStage.DeepClone);

                return(new List <ModuleMixin> {
                    finalModule
                });
            }

            if (shaderSource is ShaderArraySource)
            {
                var shaderArraySource = shaderSource as ShaderArraySource;
                var compositionArray  = new List <ModuleMixin>();
                foreach (var shader in shaderArraySource.Values)
                {
                    var mixin = BuildCompositionsDictionary(shader, dictionary, compilationContext, cloneContext, log);
                    if (mixin == null)
                    {
                        return(null);
                    }
                    compositionArray.AddRange(mixin);
                }
                return(compositionArray);
            }

            return(null);
        }
Esempio n. 46
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			AsXmlQueryExpression target = (AsXmlQueryExpression) t;
			
			target.expr = expr.Clone (clonectx);
			target.query = query.Clone (clonectx);
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new PaginationFilterResultOperator(FirstParameter, PageSize));
 }
Esempio n. 48
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			var target = (AsDelete) t;
			
			target.Expr = Expr.Clone (clonectx);
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new ParentIdFilterResultOperator(FirstParameter, ParentIds));
 }
Esempio n. 50
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     throw new NotImplementedException();
 }
Esempio n. 52
0
		public Argument Clone (CloneContext clonectx)
		{
			return Clone (Expr.Clone (clonectx));
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new CountResultOperator());
 }
Esempio n. 54
0
        /// <summary>
        /// Mixes shader parts to produces a single HLSL file shader.
        /// </summary>
        /// <param name="shaderMixinSource">The shader source.</param>
        /// <param name="macros">The shader perprocessor macros.</param>
        /// <param name="modifiedShaders">The list of modified shaders.</param>
        /// <returns>The combined shader in AST form.</returns>
        public ShaderMixinParsingResult Parse(ShaderMixinSource shaderMixinSource, Paradox.Shaders.ShaderMacro[] macros = null)
        {
            // Creates a parsing result
            HashSet<ModuleMixinInfo> mixinsToAnalyze;
            ShaderMixinParsingResult parsingResult;
            var context = ParseAndAnalyze(shaderMixinSource, macros, out parsingResult, out mixinsToAnalyze);

            // Return directly if there was any errors
            if (parsingResult.HasErrors)
                return parsingResult;

            // Update the clone context in case new instances of classes are created
            lock (hlslCloneContext)
            {
                HlslSemanticAnalysis.UpdateCloneContext(hlslCloneContext);
            }

            // only clone once the stage classes
            var mixCloneContext = new CloneContext(hlslCloneContext);
            foreach (var mixinInfo in mixinsToAnalyze)
            {
                foreach (var mixin in mixinInfo.Mixin.MinimalContext.Where(x => x.StageOnlyClass))
                {
                    mixin.DeepClone(mixCloneContext);
                }
            }

            // ----------------------------------------------------------
            // Perform Shader Mixer
            // ----------------------------------------------------------
            var externDict = new CompositionDictionary();
            var finalModuleList = BuildCompositionsDictionary(shaderMixinSource, externDict, context, mixCloneContext, parsingResult);
            //PerformanceLogger.Stop(PerformanceStage.DeepClone);

            if (parsingResult.HasErrors)
                return parsingResult;

            // look for stage compositions and add the links between variables and compositions when necessary
            var extraExternDict = new Dictionary<Variable, List<ModuleMixin>>();
            foreach (var item in externDict)
            {
                if (item.Key.Qualifiers.Contains(ParadoxStorageQualifier.Stage))
                    FullLinkStageCompositions(item.Key, item.Value, externDict, extraExternDict, parsingResult);
            }
            foreach (var item in extraExternDict)
                externDict.Add(item.Key, item.Value);

            var mixinDictionary = BuildMixinDictionary(finalModuleList);

            if (finalModuleList != null)
            {
                var finalModule = finalModuleList[0];
                //PerformanceLogger.Start(PerformanceStage.Mix);
                var mixer = new ParadoxShaderMixer(finalModule, parsingResult, mixinDictionary, externDict, new CloneContext(mixCloneContext));
                mixer.Mix();
                //PerformanceLogger.Stop(PerformanceStage.Mix);

                // Return directly if there was any errors
                if (parsingResult.HasErrors)
                    return parsingResult;

                var finalShader = mixer.GetMixedShader();

                // Simplifies the shader by removing dead code
                var simplifier = new ExpressionSimplifierVisitor();
                simplifier.Run(finalShader);

                parsingResult.Reflection = new EffectReflection();
                var pdxShaderLinker = new ShaderLinker(parsingResult);
                pdxShaderLinker.Run(finalShader);

                // Return directly if there was any errors
                if (parsingResult.HasErrors)
                    return parsingResult;

                // Find all entry points
                // TODO: make this configurable by CompileParameters
                foreach (var stage in new[] {ShaderStage.Compute, ShaderStage.Vertex, ShaderStage.Hull, ShaderStage.Domain, ShaderStage.Geometry, ShaderStage.Pixel})
                {
                    var entryPoint = finalShader.Declarations.OfType<MethodDefinition>().FirstOrDefault(f => f.Attributes.OfType<AttributeDeclaration>().Any(a => a.Name == "EntryPoint" && (string)a.Parameters[0].Value == stage.ToString()));

                    if (entryPoint == null)
                    {
                        continue;
                    }

                    parsingResult.EntryPoints[stage] = entryPoint.Name.Text;
                    
                    // When this is a compute shader, there is no need to scan other stages
                    if (stage == ShaderStage.Compute)
                        break;
                }

                var typeCleaner = new ParadoxShaderCleaner();
                typeCleaner.Run(finalShader);

                //PerformanceLogger.Stop(PerformanceStage.Global);

                //PerformanceLogger.PrintLastResult();
                //SemanticPerformance.PrintResult();
                //MixPerformance.PrintResult();
                //GenerateShaderPerformance.PrintResult();
                //StreamCreatorPerformance.PrintResult();
                //ShaderLoader.PrintTime();

                //PerformanceLogger.WriteOut(52);

                parsingResult.Shader = finalShader;
            }

            return parsingResult;
        }
Esempio n. 55
0
 IBodyClause IBodyClause.Clone(CloneContext cloneContext)
 {
     return(Clone(cloneContext));
 }
Esempio n. 56
0
		protected override void CloneTo (CloneContext clonectx, Expression target)
		{
			GroupBy t = (GroupBy) target;
			if (element_selector != null) {
				t.element_selector = element_selector.Clone (clonectx);
				t.element_block = (QueryBlock) element_block.Clone (clonectx);
			}

			base.CloneTo (clonectx, t);
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new TransformToJsonResultOperator(_transformName));
 }
Esempio n. 58
0
		protected override void CloneTo (CloneContext clonectx, Expression t)
		{
			NullCoalescingOperator target = (NullCoalescingOperator) t;

			target.left = left.Clone (clonectx);
			target.right = right.Clone (clonectx);
		}
 public override ResultOperatorBase Clone(CloneContext cloneContext)
 {
     return(new ContainsResultOperator(Item));
 }