Ejemplo n.º 1
0
        public static void WriteVertexShaders(EffectCodeGenerator generator,
                                              TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            Dictionary <string, List <string> > exports = new Dictionary <string, List <string> >();

            pass.ForEachFragment(generator, (codeGenerator, symbol, s) => WriteVertexShader(codeGenerator, symbol, s, exports));

            ScriptTextWriter writer = generator.Writer;

            // Write one vertex shader for each technique pass.
            writer.WriteLine("// -------- technique {0}, pass {1} vertex shader entrypoint --------", technique.Name, pass.Name);
            writer.WriteLine("{0}_VERTEXOUTPUT {0}_vs(const {0}_VERTEXINPUT i)", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tgVertexInput_{0} = i;", uniquePassName);
            writer.WriteLine();
            writer.WriteLine("\t{0}_VERTEXOUTPUT output = ({0}_VERTEXOUTPUT) 0;", uniquePassName);
            writer.WriteLine();

            pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_vs(gVertexInput_{0}.{1}, output);", uniquePassName, f.UniqueName));

            writer.WriteLine();
            writer.WriteLine("\treturn output;");
            writer.WriteLine("}");
            writer.WriteLine();
        }
Ejemplo n.º 2
0
        private static void WritePixelShaders(EffectCodeGenerator generator,
                                              TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            Dictionary <string, List <string> > exports = new Dictionary <string, List <string> >();

            pass.ForEachFragment(generator, (codeGenerator, symbol, s) => WritePixelShader(codeGenerator, symbol, s, exports));

            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- technique {0}, pass {1} pixel shader entrypoint --------", technique.Name, pass.Name);
            writer.WriteLine("{0}_PIXELOUTPUT {0}_ps(const {0}_PIXELINPUT i)", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tgPixelInput_{0} = i;", uniquePassName);
            writer.WriteLine();
            writer.WriteLine("\t{0}_PIXELOUTPUT output = ({0}_PIXELOUTPUT) 0;", uniquePassName);
            writer.WriteLine();
            pass.ForEachFragment(generator, (g, f, s) =>
            {
                ShaderCodeBlockNode shader = f.FragmentNode.PixelShaders.GetCodeBlock(generator.Context.TargetShaderProfile);
                if (shader != null)
                {
                    writer.WriteLine("\t{0}_{1}_ps(gPixelInput_{0}.{1}, output);", uniquePassName, f.UniqueName);
                }
            });
            writer.WriteLine();
            writer.WriteLine("\treturn output;");
            writer.WriteLine("}");
            writer.WriteLine();
        }
        private BoundNode BindTechniqueDeclaration(TechniqueSyntax declaration)
        {
            var techniqueSymbol = new TechniqueSymbol(declaration.Name.Text);

            AddSymbol(techniqueSymbol, declaration.Name.SourceRange);

            var techniqueBinder = new Binder(_sharedBinderState, this);
            var boundPasses     = declaration.Passes.Select(x => techniqueBinder.Bind(x, techniqueBinder.BindPass));

            return(new BoundTechnique(techniqueSymbol, boundPasses.ToImmutableArray()));
        }
Ejemplo n.º 4
0
        private static void GenerateTechnique(EffectCodeGenerator generator, TechniqueSymbol technique,
                                              bool generateVertexShader)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- technique {0} --------", technique.Name);
            writer.WriteLine("technique {0}", technique.Name);
            writer.WriteLine("{");

            foreach (TechniquePassSymbol pass in technique.Passes)
            {
                GeneratePass(generator, technique, pass, generateVertexShader);
            }

            writer.WriteLine("};");
        }
Ejemplo n.º 5
0
        private static void WritePixelInputStructs(EffectCodeGenerator generator,
                                                   TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            generator.Writer.WriteLine("// -------- pixel input structures --------");

            SemanticGenerator semanticGenerator = new SemanticGenerator("TEXCOORD");

            pass.ForEachFragment(generator, (g, f, s) => WritePixelInputStructure(g, f, s, semanticGenerator));

            generator.Writer.WriteLine("struct {0}_PIXELINPUT", uniquePassName);
            generator.Writer.WriteLine("{");
            pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_PIXELINPUT {1};", s, f.UniqueName));
            generator.Writer.WriteLine("};");
            generator.Writer.WriteLine();
            generator.Writer.WriteLine("static {0}_PIXELINPUT gPixelInput_{0};", uniquePassName);
            generator.Writer.WriteLine();
        }
Ejemplo n.º 6
0
        private static void GeneratePass(EffectCodeGenerator generator, TechniqueSymbol technique, TechniquePassSymbol pass,
                                         bool generateVertexShader)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("\tpass {0}", pass.Name);
            writer.WriteLine("\t{");
            if (generateVertexShader)
            {
                writer.WriteLine("\t\tVertexShader = compile vs_{0} {1}_{2}_vs();",
                                 generator.Context.TargetShaderProfile.GetDescription(),
                                 technique.Name, pass.Name);
            }
            writer.WriteLine("\t\tPixelShader = compile ps_{0} {1}_{2}_ps();",
                             generator.Context.TargetShaderProfile.GetDescription(),
                             technique.Name, pass.Name);
            writer.WriteLine("\t}");
        }
Ejemplo n.º 7
0
        private static void WriteVertexOutputStructs(EffectCodeGenerator generator,
                                                     TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- vertex output structures --------");
            writer.WriteLine("struct {0}_VERTEXOUTPUT", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tfloat4 position : POSITION;");
            pass.ForEachFragment(generator, (g, f, s) =>
            {
                if (f.FragmentNode.Interpolators != null && f.FragmentNode.Interpolators.VariableDeclarations.Any())
                {
                    g.Writer.WriteLine("\t{0}_{1}_PIXELINPUT {1};", uniquePassName, f.UniqueName);
                }
            });
            writer.WriteLine("};");
            writer.WriteLine();
        }
Ejemplo n.º 8
0
        private static void WriteVertexInputStructures(EffectCodeGenerator generator,
                                                       TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- vertex input structures --------");

            SemanticGenerator semanticGenerator = new SemanticGenerator("TEXCOORD");

            pass.ForEachFragment(generator, (g, f, s) => WriteVertexInputStructure(g, f, s, semanticGenerator));

            writer.WriteLine("struct {0}_VERTEXINPUT", uniquePassName);
            writer.WriteLine("{");

            pass.ForEachFragment(generator, (g, f, s) => g.Writer.WriteLine("\t{0}_{1}_VERTEXINPUT {1};", uniquePassName, f.UniqueName));

            writer.WriteLine("};");
            writer.WriteLine();
            writer.WriteLine("static {0}_VERTEXINPUT gVertexInput_{0};", uniquePassName);
            writer.WriteLine();
        }
Ejemplo n.º 9
0
        private static void WritePixelOutputStructs(EffectCodeGenerator generator,
                                                    TechniqueSymbol technique, TechniquePassSymbol pass, string uniquePassName)
        {
            ScriptTextWriter writer = generator.Writer;

            writer.WriteLine("// -------- pixel output structures --------");

            SemanticGenerator semanticGenerator = new SemanticGenerator("COLOR", 1);

            pass.ForEachFragment(generator, (g, f, n) => WritePixelOutputStructure(g, f, n, semanticGenerator));

            writer.WriteLine("struct {0}_PIXELOUTPUT", uniquePassName);
            writer.WriteLine("{");
            writer.WriteLine("\tfloat4 color : COLOR0;");
            pass.ForEachFragment(generator, (g, f, s) =>
            {
                if (f.FragmentNode.PixelOutputs != null && f.FragmentNode.PixelOutputs.VariableDeclarations.Any())
                {
                    writer.WriteLine("\t{0}_{1}_PIXELOUTPUT {1};", s, f.UniqueName);
                }
            });
            writer.WriteLine("};");
            writer.WriteLine();
        }
Ejemplo n.º 10
0
 public BoundTechnique(TechniqueSymbol techniqueSymbol, ImmutableArray <BoundPass> passes)
     : base(BoundNodeKind.Technique)
 {
     TechniqueSymbol = techniqueSymbol;
     Passes          = passes;
 }
Ejemplo n.º 11
0
        private static void AppendTechnique(this ICollection <SymbolMarkupToken> markup, TechniqueSymbol symbol)
        {
            markup.AppendKeyword("technique");
            markup.AppendSpace();

            markup.AppendName(SymbolMarkupKind.TechniqueName, symbol.Name);
        }
Ejemplo n.º 12
0
        private static void AppendTechnique(this ICollection<SymbolMarkupToken> markup, TechniqueSymbol symbol)
        {
            markup.AppendKeyword("technique");
            markup.AppendSpace();

            markup.AppendName(SymbolMarkupKind.TechniqueName, symbol.Name);
        }
Ejemplo n.º 13
0
        private static void AppendTechnique(this ICollection <SymbolMarkupToken> markup, TechniqueSymbol symbol, SymbolDisplayFormat format)
        {
            if (format == SymbolDisplayFormat.QuickInfo)
            {
                markup.AppendKeyword("technique");
                markup.AppendSpace();
            }

            markup.AppendName(SymbolMarkupKind.TechniqueName, symbol.Name);
        }