Beispiel #1
0
        protected bool TryDiscoverStructure(string setName, string name, out StructureDefinition sd)
        {
            ITypeSymbol type = Compilation.FindTypeByMetadataName(name);

            if (type == null)
            {
                sd = null;
                return(false);
                // throw new ShaderGenerationException("Unable to obtain compilation type metadata for " + name);
            }
            else if (type.OriginalDefinition.DeclaringSyntaxReferences.Length == 0)
            {
                if (TryReflectStructure(setName, type, out sd))
                {
                    AddStructure(setName, sd);
                    return(true);
                }
            }
            else
            {
                SyntaxNode declaringSyntax = type.OriginalDefinition.DeclaringSyntaxReferences[0].GetSyntax();
                if (declaringSyntax is StructDeclarationSyntax sds)
                {
                    if (ShaderSyntaxWalker.TryGetStructDefinition(Compilation.GetSemanticModel(sds.SyntaxTree), sds, out sd))
                    {
                        AddStructure(setName, sd);
                        return(true);
                    }
                }
            }

            sd = null;
            return(false);
        }
Beispiel #2
0
        private void GenerateShaders(ShaderSetInfo ss, ShaderGenerationResult result)
        {
            TypeAndMethodName vertexFunctionName   = ss.VertexShader;
            TypeAndMethodName fragmentFunctionName = ss.FragmentShader;

            HashSet <SyntaxTree> treesToVisit = new HashSet <SyntaxTree>();

            if (vertexFunctionName != null)
            {
                GetTrees(treesToVisit, vertexFunctionName.TypeName);
            }
            if (fragmentFunctionName != null)
            {
                GetTrees(treesToVisit, fragmentFunctionName.TypeName);
            }

            foreach (LanguageBackend language in _languages)
            {
                language.InitContext(ss.Name);
            }

            ShaderSyntaxWalker walker = new ShaderSyntaxWalker(_compilation, _languages.ToArray(), ss);

            foreach (SyntaxTree tree in treesToVisit)
            {
                walker.Visit(tree.GetRoot());
            }

            foreach (LanguageBackend language in _languages)
            {
                ShaderModel    model  = language.GetShaderModel(ss.Name);
                ShaderFunction vsFunc = (ss.VertexShader != null)
                    ? model.GetFunction(ss.VertexShader.FullName)
                    : null;
                ShaderFunction fsFunc = (ss.FragmentShader != null)
                    ? model.GetFunction(ss.FragmentShader.FullName)
                    : null;
                {
                    string vsCode = null;
                    string fsCode = null;
                    if (vsFunc != null)
                    {
                        vsCode = language.GetCode(ss.Name, vsFunc);
                    }
                    if (fsFunc != null)
                    {
                        fsCode = language.GetCode(ss.Name, fsFunc);
                    }

                    result.AddShaderSet(language, new GeneratedShaderSet(ss.Name, vsCode, fsCode, vsFunc, fsFunc, model));
                }
            }
        }