Exemple #1
0
        public static int Main(string[] args)
        {
            ShaderData sd = new ShaderData ();

            bool dump = false, trace = false, interpreter = false, help = false;
            OptionSet opts = new OptionSet () {
                { "d|dump", "Decompile the shader to stdout.", v => dump = true },
                { "t|trace", "Enable tracing of execution (best used with --interpreter).", v => trace = true },
                { "i|interpreter", "Use the interpreter instead of the JIT.", v => interpreter = true },
                { "h|help", "Show this message and exit.", v => help = true },
                { "c:", "Set the value of a constant register", (k, v) =>  sd.SetConstant (int.Parse (k), float.Parse (v)) }
            };

            List<string> extra;
            try {
                extra = opts.Parse (args);
            } catch (OptionException e) {
                Console.WriteLine ("{0}\nTry 'shader --help' for more information.", e.Message);
                return 1;
            }

            if (extra.Count != 3)
                help = true;

            if (help) {
                Console.WriteLine ("Usage: shader [options] shader input-image output-image");
                Console.WriteLine ("Apply the given shader to input-image and save it to output-image");
                opts.WriteOptionDescriptions (Console.Out);
                return 2;
            }

            if (trace)
                TracingConfig.Enable ();

            Parser parser = new Parser (extra [0]);
            var insList = parser.Parse ();
            if (dump) {
                foreach (var i in insList)
                    Console.WriteLine (i);
                return 0;
            }

            var srcImg = new CairoImageSurface (extra [1]);
            var dstImg = srcImg.CreateSimilar ();

            Texture intex = new CairoTexture (srcImg);
            Texture outtex =  new CairoTexture (dstImg);

            sd.SetSampler (0, new Sampler (intex));
            sd.SetOutputTexture (0, outtex);

            if (interpreter) {
                Interpreter interp = new Interpreter (insList);
                interp.Run (sd);
            } else {
                CodeGenContext ctx = new CodeGenContext (insList);
                CompiledShader shader = ctx.Compile ();
                shader (sd);
            }
            dstImg.SaveToPng (extra [2]);
            return 0;
        }
Exemple #2
0
 internal HeaderWriterVisitor(CodeGenContext ctx)
 {
     this.ctx = ctx;
 }
Exemple #3
0
 internal ShaderRequisitesVisitor(CodeGenContext ctx)
 {
     this.ctx = ctx;
 }
Exemple #4
0
 public override void EmitBody(CodeGenContext ctx)
 {
     throw new Exception ("can't handle " + this);
     /*ctx.LoadValue (src1);
     ctx.LoadValue (src2);
     ctx.EmitBinary (op);
     ctx.StoreValue (dest);*/
 }
Exemple #5
0
 internal CodeGenVisitor(CodeGenContext ctx)
 {
     this.ctx = ctx;
 }
Exemple #6
0
 public override void EmitHeader(CodeGenContext ctx)
 {
     ctx.DefineConst (reg, val);
 }
Exemple #7
0
        public override void EmitBody(CodeGenContext ctx)
        {
            if (sampler.Kind != RegKind.SamplerState)
                throw new Exception ("bad tex input reg "+tex.Kind);
            if (tex.Kind != RegKind.Texture)
                throw new Exception ("bad tex coord reg");

            ctx.SampleTexture (sampler.Number, tex.Number);
            ctx.StoreValue (dest);
        }
Exemple #8
0
 public override void EmitBody(CodeGenContext ctx)
 {
     ctx.LoadValue (src);
     ctx.StoreValue (dest);
 }
Exemple #9
0
 public virtual void EmitHeader(CodeGenContext ctx)
 {
 }
Exemple #10
0
 public virtual void EmitBody(CodeGenContext ctx)
 {
 }
Exemple #11
0
 public override void EmitHeader(CodeGenContext ctx)
 {
     ctx.DefineVar (kind, reg);
 }
Exemple #12
0
 public override void EmitBody(CodeGenContext ctx)
 {
     ctx.LoadValue (src1);
     ctx.LoadValue (src2);
     ctx.EmitBinary (op);
     ctx.StoreValue (dest);
 }