Ejemplo n.º 1
0
        public void CompileShaderProject()
        {
            var dependencies = new ShaderModule()
            {
                this.FragmentLibrary
            };

            this.ShaderLibrary = this.ShaderProject.CompileAndTranslate("Shader", dependencies, this.FrontEnd);
        }
Ejemplo n.º 2
0
        public ShaderLibrary CompileAndTranslate(string compilationName, ShaderModule dependencies, FrontEndTranslator translator)
        {
            List <SyntaxTree> trees;
            var compilation = Compile(compilationName, dependencies, translator, out trees);
            var library     = new ShaderLibrary();

            Translate(compilation, trees, dependencies, translator, library);
            return(library);
        }
Ejemplo n.º 3
0
        ShaderLibrary LoadAndCompileProject(string projectName, string directory, ShaderModule dependencies, out ShaderProject shaderProject)
        {
            shaderProject = CreateProjectFromDirectory(directory);
            shaderProject.ErrorHandlers.Add(this.OnTranslationError);

            var shaderLibrary = shaderProject.CompileAndTranslate(projectName, dependencies, this.FrontEnd);

            return(shaderLibrary);
        }
Ejemplo n.º 4
0
        public CSharpCompilation Compile(string compilationName, ShaderModule dependencies, FrontEndTranslator translator, out List <SyntaxTree> trees)
        {
            var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, false);

            trees = BuildSyntaxTrees();
            var references  = BuildReferences(dependencies);
            var compilation = CSharpCompilation.Create(compilationName, trees, references, options);

            CheckDiagnostics(compilation);
            return(compilation);
        }
Ejemplo n.º 5
0
        private List <MetadataReference> BuildReferences(ShaderModule dependencies)
        {
            // Walk all references of this library, making sure to not visit any dependency more than once
            var references        = new List <MetadataReference>();
            var visitedReferences = new HashSet <ShaderLibrary>();
            var stack             = new Stack <ShaderLibrary>();

            // Always forcibly add C#'s core library
            var netStandardLibrary = MetadataReference.CreateFromFile(@"Binaries\netstandard.dll");

            references.Add(netStandardLibrary);

            // Get the first level of dependencies
            if (dependencies != null)
            {
                foreach (var dependency in dependencies)
                {
                    stack.Push(dependency);
                }
            }

            // Visit every dependency if we haven't already
            while (stack.Count != 0)
            {
                var library = stack.Pop();
                if (visitedReferences.Contains(library))
                {
                    continue;
                }

                // Get the C# reference if it exists
                if (library.SourceCompilation != null)
                {
                    references.Add(library.SourceCompilation.ToMetadataReference());
                }

                // Add all sub-dependencies
                if (library.mDependencies != null)
                {
                    foreach (var subDependency in library.mDependencies)
                    {
                        if (visitedReferences.Contains(library))
                        {
                            continue;
                        }
                        stack.Push(subDependency);
                    }
                }
            }
            return(references);
        }
Ejemplo n.º 6
0
        public void LoadDependencies(string directory)
        {
            var core = new CoreShaderLibrary(this.FrontEnd);

            var utilitiesPath   = Path.Combine(directory, "Utilities");
            var utilitiesModule = new ShaderModule()
            {
                core
            };
            ShaderProject shaderProject;
            var           utilitiesLibrary = LoadAndCompileProject("Utilities", utilitiesPath, utilitiesModule, out shaderProject);

            this.CoreDependencies = new ShaderModule()
            {
                utilitiesLibrary
            };
        }
Ejemplo n.º 7
0
        public void Translate(CSharpCompilation compilation, List <SyntaxTree> trees, ShaderModule dependencies, FrontEndTranslator translator, ShaderLibrary library)
        {
            FrontEndTranslator frontEnd = new FrontEndTranslator();

            translator.CurrentProject  = this;
            translator.mCurrentLibrary = library;
            translator.mCurrentLibrary.SourceCompilation = compilation;
            translator.mCurrentLibrary.mDependencies     = dependencies;

            FrontEndPipeline pipeline = new FrontEndPipeline();

            pipeline.Translate(translator, compilation, trees);
        }