/// <summary>
        /// Initializes a new instance of the <see cref="XenkoSemanticAnalysis"/> class.
        /// </summary>
        /// <param name="result">The result</param>
        /// <param name="analyzedMixin">the context in which the analysis is set</param>
        /// <param name="moduleMixinsInCompilationGroup">the list of all the modules that are not in the inheritance hierarchy of the context</param>
        public XenkoSemanticAnalysis(ParsingResult result, ModuleMixin analyzedMixin, List<ModuleMixin> moduleMixinsInCompilationGroup)
            : base(result)
        {
            analyzedModuleMixin = analyzedMixin;
            
            ScopeStack.First().AddDeclaration(StreamsType.ThisStreams);

            var currentScope = new ScopeDeclaration(analyzedMixin.Shader);
            ScopeStack.Push(currentScope);

            currentScope.AddDeclarations(analyzedMixin.VirtualTable.Typedefs);
            currentScope.AddDeclarations(analyzedMixin.VirtualTable.StructureTypes);
            currentScope.AddDeclarations(analyzedMixin.VirtualTable.Variables.Select(x => x.Variable));
            currentScope.AddDeclarations(analyzedMixin.VirtualTable.Methods.Select(x => x.Method));
            currentScope.AddDeclarations(analyzedMixin.InheritanceList.Select(x => x.Shader));

            // add the mixins in the compilation group
            var sd = new ScopeDeclaration();
            ScopeStack.Push(sd);
            foreach (var mixin in moduleMixinsInCompilationGroup)
            {
                moduleMixins.Add(mixin);
                sd.AddDeclaration(mixin.Shader);
            }
        }
Пример #2
0
        /// <summary>
        /// Decodes the swizzle.
        /// </summary>
        /// <param name="memberReference">The member reference.</param>
        /// <param name="result">The result.</param>
        /// <returns></returns>
        public static List<MatrixType.Indexer> MatrixSwizzleDecode(MemberReferenceExpression memberReference, ParsingResult result = null)
        {
            string components = memberReference.Member.Text;

            var matrixDecl = (MatrixType)(memberReference.Target.TypeInference.TargetType);

            var span = matrixDecl.Span;

            var swizzles = (List<MatrixType.Indexer>)memberReference.GetTag(SwizzleTag);
            if (swizzles != null)
                return swizzles;

            swizzles = new List<MatrixType.Indexer>();

            if (components.StartsWith("_"))
            {
                string[] splitComponents;
                int indexOffset = 0;
                if (components.StartsWith("_m"))
                {
                    splitComponents = components.Split(new[] { "_m" }, StringSplitOptions.RemoveEmptyEntries);
                }
                else
                {
                    splitComponents = components.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
                    indexOffset = 1;
                }

                int dimension = 0;

                if (splitComponents.Length == 0 && result != null)
                {
                    result.Error(MessageCode.ErrorMatrixInvalidMemberReference, span, components);
                }

                foreach (var splitComponent in splitComponents)
                {
                    if (splitComponent.Length != 2 || !IsValidIndex(span, splitComponent[0], indexOffset, indexOffset + 3) || !IsValidIndex(span, splitComponent[1], indexOffset, indexOffset + 3))
                    {
                        swizzles.Clear();
                        break;
                    }

                    swizzles.Add(new MatrixType.Indexer(int.Parse(splitComponent[0].ToString()) - indexOffset, int.Parse(splitComponent[1].ToString()) - indexOffset));
                    dimension++;
                }
            }

            memberReference.SetTag(SwizzleTag, swizzles);
            return swizzles;
        }
Пример #3
0
 public static Shader Check(ParsingResult result, string sourceFileName)
 {
     // Throws an exception if there are any errors.
     // Todo provide better handling
     if (result.HasErrors)
     {
         var errorText = new StringBuilder();
         errorText.AppendFormat("Unable to parse file [{0}]", sourceFileName).AppendLine();
         foreach (var reportMessage in result.Messages)
         {
             errorText.AppendLine(reportMessage.ToString());
         }
         throw new InvalidOperationException(errorText.ToString());
     }
     return(result.Shader);
 }
Пример #4
0
        public bool Run(ForStatement forStatement, Variable breakFlag, string keywordName, ParsingResult logger)
        {
            keyword = keywordName;

            Visit(forStatement.Body);

            if (logger != null)
                parserResult.CopyTo(logger);

            if (parserResult.HasErrors)
                return false;

            TransformBreaks(breakFlag);
            
            return scopeList.Count > 0;
        }
        /// <summary>
        /// Run the analysis
        /// </summary>
        /// <param name="mixinToAnalyze">the current context (virtual table) from mixin inheritance</param>
        /// <param name="compilationContext">List of all the mixin in the compilation context</param>
        /// <returns>true if the shader is correct, false otherwise</returns>
        public static XenkoParsingInfo RunAnalysis(ModuleMixin mixinToAnalyze, List<ModuleMixin> compilationContext, bool transformForEach = false)
        {
            var shader = new Shader();
            shader.Declarations.Add(mixinToAnalyze.Shader);
            var toParse = new ParsingResult { Shader = shader };
            var analysis = new XenkoSemanticAnalysis(toParse, mixinToAnalyze, compilationContext) { parsingInfo = new XenkoParsingInfo() };
            analysis.expandForEachStatements = transformForEach;
            analysis.Run();

            // look at the static classes
            analysis.parsingInfo.StaticClasses.UnionWith(analysis.parsingInfo.StaticReferences.VariablesReferences.Select(x => x.Key.GetTag(XenkoTags.ShaderScope) as ModuleMixin));
            analysis.parsingInfo.StaticClasses.UnionWith(analysis.parsingInfo.StaticReferences.MethodsReferences.Select(x => x.Key.GetTag(XenkoTags.ShaderScope) as ModuleMixin));
            analysis.parsingInfo.StaticClasses.Remove(mixinToAnalyze);
            analysis.parsingInfo.ErrorsWarnings = analysis.ParsingResult;

            return analysis.parsingInfo;
        }
Пример #6
0
 public CastAnalysis(ParsingResult result) : base(result)
 {
 }
Пример #7
0
        /// <summary>
        /// Converts the specified hlsl source code to glsl.
        /// </summary>
        /// <param name="hlslEntryPoint">The HLSL entry point.</param>
        /// <param name="stage">The stage to convert.</param>
        /// <param name="shader">The shader.</param>
        /// <param name="inputHlslFilepath">The input HLSL filepath.</param>
        /// <returns>
        /// The resulting glsl AST tree.
        /// </returns>
        private global::SiliconStudio.Shaders.Ast.Shader Convert(ParsingResult result, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, LoggerResult log)
        {
            try
            {
                var convertor = new HlslToGlslConvertor(hlslEntryPoint, stage, ShaderModel.Model40) // TODO HARDCODED VALUE to change
                {
                    KeepConstantBuffer = !isOpenGLES || isOpenGLES3,
                    TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
                    NoSwapForBinaryMatrixOperation = true,
                    UseBindingLayout = false,
                    UseLocationLayout = false,
                    UseSemanticForVariable = true,
                    IsPointSpriteShader = false,
                    ViewFrustumRemap = true,
                    FlipRenderTargetFlag = "ParadoxFlipRendertarget",
                    KeepNonUniformArrayInitializers = !isOpenGLES,
                    IsOpenGLES2 = isOpenGLES && !isOpenGLES3
                };
                convertor.Run(result);

                // After the converter we display the errors but we don't stop writing output glsl
                if (result.HasErrors)
                {
                    //DisplayError(log, result, "Error while converting file:");
                }


                return result.Shader;
            }
            catch (Exception ex)
            {
                log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
                return null;
            }
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisBase"/> class.
 /// </summary>
 /// <param name="result">The result.</param>
 protected AnalysisBase(ParsingResult result) : base(true, true)
 {
     ParsingResult = result;
 }
Пример #9
0
 public XenkoTypeAnalysis(ParsingResult result)
     : base(result)
 {
     SetupHlslAnalyzer();
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SemanticAnalysis"/> class.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 public SemanticAnalysis(ParsingResult result)
     : base(result)
 {
 }
Пример #11
0
 public static void Run(ParsingResult toParse, List<IDeclaration> builtinDeclarations = null)
 {
     var analysis = new HlslSemanticAnalysis(toParse);
     analysis.SetupHlslAnalyzer(builtinDeclarations);
     analysis.Run();
 }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HlslSemanticAnalysis"/> class.
 /// </summary>
 /// <param name="result">
 /// The result.
 /// </param>
 protected HlslSemanticAnalysis(ParsingResult result) : base(result)
 {
 }
Пример #13
0
        private static bool IsValidIndex(SourceSpan span, char valueChar, int min, int max, ParsingResult result = null)
        {
            int value;
            var isParseOk = int.TryParse(valueChar.ToString(), out value);

            if (!isParseOk || value < min || value > max)
            {
                if (result != null)
                    result.Error(MessageCode.ErrorMatrixInvalidIndex, span, valueChar, min, max);
                return false;
            }

            return true;
        }
Пример #14
0
        /// <summary>
        /// Converts the specified hlsl source code to glsl.
        /// </summary>
        /// <param name="hlslEntryPoint">The HLSL entry point.</param>
        /// <param name="stage">The stage to convert.</param>
        /// <param name="shader">The shader.</param>
        /// <param name="inputHlslFilepath">The input HLSL filepath.</param>
        /// <returns>
        /// The resulting glsl AST tree.
        /// </returns>
        private global::SiliconStudio.Shaders.Ast.Shader Convert(ParsingResult result, string hlslEntryPoint, PipelineStage stage, string inputHlslFilepath, IDictionary<int, string> inputAttributeNames, LoggerResult log)
        {
            try
            {
                var convertor = new HlslToGlslConvertor(shaderPlatform, shaderVersion, hlslEntryPoint, stage, ShaderModel.Model40) // TODO HARDCODED VALUE to change
                {
                    // Those settings are now default values
                    //NoSwapForBinaryMatrixOperation = true,
                    //UnrollForLoops = true,
                    //ViewFrustumRemap = true,
                    //FlipRenderTarget = true,
                    //KeepConstantBuffer = !isOpenGLES || isOpenGLES3,
                    //TextureFunctionsCompatibilityProfile = isOpenGLES && !isOpenGLES3,
                    //KeepNonUniformArrayInitializers = !isOpenGLES,

                    UseBindingLayout = false,
                    UseSemanticForVariable = true,
                    IsPointSpriteShader = false,
                    InputAttributeNames = inputAttributeNames
                };
                convertor.Run(result);

                // After the converter we display the errors but we don't stop writing output glsl
                if (result.HasErrors)
                {
                    //DisplayError(log, result, "Error while converting file:");
                }


                return result.Shader;
            }
            catch (Exception ex)
            {
                log.Error("Unexpected error while converting file [{0}] with entry point [{1}]", ex, inputHlslFilepath, hlslEntryPoint);
                return null;
            }
        }
Пример #15
0
 public BreakContinueVisitor()
     : base(false, true)
 {
     parserResult = new ParsingResult();
 }
Пример #16
0
 public ParadoxTypeAnalysis(ParsingResult result)
     : base(result)
 {
     SetupHlslAnalyzer();
 }