Пример #1
0
        private static void ReadShaderModel(string baseFilename, FileStream inputStream, bool doAstAnalysis)
        {
            using (var input = new ShaderReader(inputStream, true))
            {
                ShaderModel shader = input.ReadShader();

                AsmWriter writer = new AsmWriter(shader);
                string asmFilename = $"{baseFilename}.asm";
                Console.WriteLine("Writing {0}", asmFilename);
                writer.Write(asmFilename);

                var hlslWriter = CreateHlslWriter(shader, doAstAnalysis);
                string hlslFilename = $"{baseFilename}.fx";
                Console.WriteLine("Writing {0}", hlslFilename);
                hlslWriter.Write(hlslFilename);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Expected input filename");
                return;
            }

            string inputFilename = args[0];
            string baseFilename  = Path.GetFileNameWithoutExtension(inputFilename);

            using (var inputStream = File.Open(inputFilename, FileMode.Open, FileAccess.Read))
            {
                ShaderModel shader;
                AsmWriter   writer;
                HlslWriter  hlslWriter;

                var format = DetectFormat.Detect(inputStream);
                switch (format)
                {
                case ShaderFileFormat.Rgxa:
                    using (var input = new RgxaReader(inputStream, true))
                    {
                        int ivs = 0, ips = 0;
                        while (true)
                        {
                            shader = input.ReadShader();
                            if (shader == null)
                            {
                                break;
                            }

                            string outFilename;
                            if (shader.Type == ShaderType.Vertex)
                            {
                                outFilename = $"{baseFilename}_vs{ivs}";
                                ivs++;
                            }
                            else
                            {
                                outFilename = $"{baseFilename}_ps{ips}";
                                ips++;
                            }
                            Console.WriteLine(outFilename);

                            //shader.ToFile(outFilename.fxc", outFilename, i));

                            writer = new AsmWriter(shader);
                            writer.Write(outFilename + ".asm");

                            hlslWriter = new HlslWriter(shader);
                            hlslWriter.Write(outFilename + ".fx");

                            Console.WriteLine();
                        }
                    }
                    break;

                case ShaderFileFormat.Hlsl:
                    using (var input = new ShaderReader(inputStream, true))
                    {
                        Console.WriteLine();
                        Console.WriteLine("{0}", baseFilename);
                        shader = input.ReadShader();

                        writer = new AsmWriter(shader);
                        writer.Write($"{baseFilename}.asm");

                        hlslWriter = new HlslWriter(shader);
                        hlslWriter.Write($"{baseFilename}.fx");
                    }
                    break;

                case ShaderFileFormat.Unknown:
                    Console.WriteLine("Unknown file format!");
                    break;
                }
            }

            Console.ReadKey();
        }