Beispiel #1
0
        public override string VisitInclude(ShaderInputsParser.IncludeContext context)
        {
            string filename = context.FILEPATH().GetText();
            string filepath = Program.InputDir + "/" + filename;

            if (!File.Exists(filepath))
            {
                throw new Exception("Include file " + filepath + " doesn't exist");
            }

            string includeContent = File.ReadAllText(filepath);

            ShaderInputsParser parser = Program.InitializeAntlr(includeContent);

            ShaderInputsParser.InputFileContext ictx = parser.inputFile();

            ShaderInputsVisitor visitor = new ShaderInputsVisitor(m_globalCtx);

            visitor.Visit(ictx);

            OutputContext.Merge(visitor.OutputContext);

            return(base.VisitInclude(context));
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            ParseCommandLine(args);
            try
            {
                if (InputDir == null)
                {
                    throw new InvalidCommandLineException("Input (inDir) directory isn't set in the command line");
                }
                if (!Directory.Exists(InputDir))
                {
                    throw new InvalidCommandLineException("Input directory doesn't exist (" + InputDir + ")");
                }

                if (TemplatesDir == null)
                {
                    throw new InvalidCommandLineException("Template (templatesDir) directory isn't set in the command line");
                }
                if (!Directory.Exists(TemplatesDir))
                {
                    throw new InvalidCommandLineException("Template directory doesn't exist (" + TemplatesDir + ")");
                }

                if (HlslOutputDir == null)
                {
                    throw new InvalidCommandLineException("Hlsl directory isn't set in the command line");
                }

                if (CppOutputDir == null)
                {
                    throw new InvalidCommandLineException("Cpp output directory isn't set in the command line");
                }
            }
            catch (InvalidCommandLineException ex)
            {
                Console.WriteLine(ex.Message);
            }

            CreateOutputDirectories(false);

            DateTime lastInputUpdateTime;
            string   updateTimeFilepath;

            if (CompareOutputsVersion(out lastInputUpdateTime, out updateTimeFilepath) && !ForceRegenerate)
            {
                return;
            }

            Console.WriteLine("Generating...\n");
            string[] files = Directory.GetFiles(InputDir, "*.sinp", SearchOption.AllDirectories);
            ShaderOutputGlobalContext globalContext = new ShaderOutputGlobalContext();

            foreach (var filepath in files)
            {
                Console.WriteLine("Parsing file " + filepath + '\n');
                try
                {
                    string content = File.ReadAllText(filepath);

                    ShaderInputsParser parser = InitializeAntlr(content);
                    ShaderInputsParser.InputFileContext ctx = parser.inputFile();

                    ShaderInputsVisitor visitor = new ShaderInputsVisitor(globalContext);
                    visitor.Visit(ctx);
                    ShaderOutputContext outputCtx = visitor.OutputContext;

                    //Validator validator = new Validator();
                    //validator.Validate(outputCtx.ConstantBuffers);

                    BindpointManager bindpointManager = new BindpointManager();
                    bindpointManager.AssignBindpoints(outputCtx);

                    string            filename   = Path.GetFileNameWithoutExtension(filepath);
                    HlslHeadersWriter hlslWriter = new HlslHeadersWriter();
                    hlslWriter.WriteHeaders(outputCtx, filename);
                    CppHeaderWriter cppWriter = new CppHeaderWriter();
                    cppWriter.WriteHeaders(outputCtx, filename);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception occurred while parsing file " + filepath);
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    throw;
                }
            }
            Console.WriteLine("Writing common structures...");
            CommonStructHeaderWriter commonStructWriter = new CommonStructHeaderWriter();

            commonStructWriter.WriteHeaders(globalContext);

            Console.WriteLine("Writing outputs...\n");
            FactoryWriter factoryWriter = new FactoryWriter();

            factoryWriter.WriteFactory(files);
            Console.WriteLine("Writing done\n");

            UpdateOutputVersionFile(lastInputUpdateTime, updateTimeFilepath);

            Console.Write("Output file timestamp updated\n");

            Console.Write("\n******* SHADERS OUTPUT FILES ARE UPDATED WITH SUCESS ******\n");
        }