public virtual void Visit(ShaderLibrary library) { foreach (var type in library.GetTypes()) { Visit(type); } }
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); }
public void CompileShaderProject() { var dependencies = new ShaderModule() { this.FragmentLibrary }; this.ShaderLibrary = this.ShaderProject.CompileAndTranslate("Shader", dependencies, this.FrontEnd); }
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); } }
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); }
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); }
public TypeDependencyCollector(ShaderLibrary owningLibrary) { mOwningLibrary = owningLibrary; }
public void ClearShaderProject() { this.ShaderProject = new ShaderProject(); this.ShaderLibrary = new ShaderLibrary(); this.ShaderProject.ErrorHandlers.Add(this.OnTranslationError); }
public void CompileFragmentProject() { this.FragmentLibrary = this.FragmentProject.CompileAndTranslate("Fragments", this.CoreDependencies, this.FrontEnd); }
public void LoadFragmentProject(string directory) { FragmentLibrary = LoadAndCompileProject("Fragments", directory, this.CoreDependencies, out this.FragmentProject); }