示例#1
0
 public NodeCompiler(RegisterState registers)
 {
     _registers                    = registers;
     _nodeGrouper                  = new NodeGrouper(registers);
     _constantCompiler             = new ConstantCompiler(_nodeGrouper);
     _matrixMultiplicationCompiler = new MatrixMultiplicationCompiler(this);
 }
示例#2
0
 public NodeGrouper(RegisterState registers)
 {
     DotProductGrouper           = new DotProductGrouper(this);
     LengthGrouper               = new LengthGrouper(this);
     MatrixMultiplicationGrouper = new MatrixMultiplicationGrouper(this, registers);
     NormalizeGrouper            = new NormalizeGrouper(this);
     _registers = registers;
 }
 public MatrixMultiplicationGrouper(NodeGrouper nodeGrouper, RegisterState registers)
 {
     _nodeGrouper = nodeGrouper;
     _registers   = registers;
 }
示例#4
0
        protected override void Write()
        {
            if (_shader.Type == ShaderType.Expression)
            {
                Write($"// Writing expression");
                WriteExpression(_shader);
                return;
            }
            _registers = new RegisterState(_shader);

            WriteConstantDeclarations();

            if (_shader.Preshader != null)
            {
                WriteExpression(_shader.Preshader.Shader);
            }
            if (_registers.MethodInputRegisters.Count > 1)
            {
                WriteInputStructureDeclaration();
            }

            if (_registers.MethodOutputRegisters.Count > 1)
            {
                WriteOutputStructureDeclaration();
            }

            string methodReturnType = GetMethodReturnType();
            string methodParameters = GetMethodParameters();
            string methodSemantic   = GetMethodSemantic();

            WriteLine("{0} {1}({2}){3}",
                      methodReturnType,
                      _entryPoint,
                      methodParameters,
                      methodSemantic);
            WriteLine("{");
            Indent++;

            if (_registers.MethodOutputRegisters.Count > 1)
            {
                var outputStructType = _shader.Type == ShaderType.Pixel ? "PS_OUT" : "VS_OUT";
                WriteIndent();
                WriteLine($"{outputStructType} o;");
            }
            else
            {
                var output = _registers.MethodOutputRegisters.First().Value;
                WriteLine("{0} {1};", methodReturnType, _registers.GetRegisterName(output.RegisterKey));
            }
            WriteTemps();
            HlslAst ast = null;

            if (_doAstAnalysis)
            {
                var parser = new BytecodeParser();
                ast = parser.Parse(_shader);
                ast.ReduceTree();

                WriteAst(ast);
            }
            else
            {
                WriteInstructionList();

                if (_registers.MethodOutputRegisters.Count > 1)
                {
                    WriteLine($"return o;");
                }
                else
                {
                    var output = _registers.MethodOutputRegisters.First().Value;
                    WriteLine($"return {_registers.GetRegisterName(output.RegisterKey)};");
                }
            }
            Indent--;
            WriteLine("}");
        }
示例#5
0
        public void Write(Stream stream)
        {
            hlslWriter = new StreamWriter(stream);

            _registers = new RegisterState(_shader);

            WriteConstantDeclarations();

            if (_registers.MethodInputRegisters.Count > 1)
            {
                WriteInputStructureDeclaration();
            }

            if (_registers.MethodOutputRegisters.Count > 1)
            {
                WriteOutputStructureDeclaration();
            }

            string methodReturnType = GetMethodReturnType();
            string methodParameters = GetMethodParameters();
            string methodSemantic   = GetMethodSemantic();

            WriteLine("{0} main({1}){2}", methodReturnType, methodParameters, methodSemantic);
            WriteLine("{");
            indent = "\t";

            if (_registers.MethodOutputRegisters.Count > 1)
            {
                var outputStructType = _shader.Type == ShaderType.Pixel ? "PS_OUT" : "VS_OUT";
                WriteLine($"{outputStructType} o;");
                WriteLine();
            }
            else
            {
                var output = _registers.MethodOutputRegisters.First().Value;
                WriteLine("{0} {1};", methodReturnType, _registers.GetRegisterName(output.RegisterKey));
                WriteLine();
            }
            WriteTemps();
            HlslAst ast = null;

            if (_doAstAnalysis)
            {
                var parser = new BytecodeParser();
                ast = parser.Parse(_shader);
                ast.ReduceTree();

                WriteAst(ast);
            }
            else
            {
                WriteInstructionList();

                if (_registers.MethodOutputRegisters.Count > 1)
                {
                    WriteLine($"return o;");
                }
                else
                {
                    var output = _registers.MethodOutputRegisters.First().Value;
                    WriteLine($"return {_registers.GetRegisterName(output.RegisterKey)};");
                }
            }
            indent = "";
            WriteLine("}");
            hlslWriter.Flush();
        }