Esempio n. 1
0
 public virtual void Visit(ShaderLibrary library)
 {
     foreach (var type in library.GetTypes())
     {
         Visit(type);
     }
 }
Esempio 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);
        }
Esempio n. 3
0
        public void CompileShaderProject()
        {
            var dependencies = new ShaderModule()
            {
                this.FragmentLibrary
            };

            this.ShaderLibrary = this.ShaderProject.CompileAndTranslate("Shader", dependencies, this.FrontEnd);
        }
Esempio n. 4
0
 public void GenerateIds(ShaderLibrary library, TypeDependencyCollector typeCollector)
 {
     foreach (var extLibraryImport in typeCollector.mReferencedExtensionLibraryImports)
     {
         GenerateIds(extLibraryImport);
     }
     foreach (var ir in typeCollector.mReferencedTypesConstantsAndGlobals)
     {
         GenerateIds(ir);
     }
     foreach (var function in typeCollector.mReferencedFunctions)
     {
         GenerateIds(function);
     }
 }
Esempio n. 5
0
        public void Write(SpirVStreamWriter writer, ShaderLibrary library, FrontEndTranslator frontEnd)
        {
            mWriter   = writer;
            mLibrary  = library;
            mFrontEnd = frontEnd;

            mTypeCollector = new TypeDependencyCollector(mLibrary);
            mTypeCollector.VisitLibrary();

            CreateDummyEntryPoint();
            IdGenerator.GenerateIds(mLibrary, mTypeCollector);
            WriteHeader();
            WriteDebugInstructions();
            WriteDecorations();
            WriteTypesConstantsAndGlobals();
            WriteTypeFunctions();
        }
        public void CreateDummyEntryPoint(TypeDependencyCollector typeCollector, ShaderLibrary library, FrontEndTranslator frontEnd)
        {
            var unitTestTypes = new List <ShaderType>();

            foreach (var ir in typeCollector.mReferencedTypesConstantsAndGlobals)
            {
                if (ir is ShaderType type)
                {
                    if (type.mMeta.mAttributes.Contains("UnitTest") && type.mEntryPoints.Count == 0)
                    {
                        unitTestTypes.Add(type);
                    }
                }
            }
            foreach (var type in unitTestTypes)
            {
                CreateDummyEntryPoint(typeCollector, library, frontEnd, type);
            }
        }
        public void CreateDummyEntryPoint(TypeDependencyCollector typeCollector, ShaderLibrary library, FrontEndTranslator frontEnd, ShaderType shaderType)
        {
            var context = new FrontEndContext();

            context.mCurrentType = shaderType;

            if (shaderType.mEntryPoints.Count != 0)
            {
                return;
            }

            ShaderEntryPointInfo entryPoint = null;

            if (shaderType.mFragmentType == FragmentType.Pixel || shaderType.mFragmentType == FragmentType.None)
            {
                entryPoint = EntryPointGeneration.GeneratePixel(frontEnd, shaderType, null);
            }
            else if (shaderType.mFragmentType == FragmentType.Vertex)
            {
                entryPoint = EntryPointGeneration.GenerateVertex(frontEnd, shaderType, null);
            }

            typeCollector.Visit(entryPoint);
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
 public TypeDependencyCollector(ShaderLibrary owningLibrary)
 {
     mOwningLibrary = owningLibrary;
 }
Esempio n. 10
0
 public void ClearShaderProject()
 {
     this.ShaderProject = new ShaderProject();
     this.ShaderLibrary = new ShaderLibrary();
     this.ShaderProject.ErrorHandlers.Add(this.OnTranslationError);
 }
Esempio n. 11
0
 public void CompileFragmentProject()
 {
     this.FragmentLibrary = this.FragmentProject.CompileAndTranslate("Fragments", this.CoreDependencies, this.FrontEnd);
 }
Esempio n. 12
0
 public void LoadFragmentProject(string directory)
 {
     FragmentLibrary = LoadAndCompileProject("Fragments", directory, this.CoreDependencies, out this.FragmentProject);
 }