示例#1
0
        public IList <IList <HlslTreeNode> > GroupComponents(List <HlslTreeNode> nodes)
        {
            switch (nodes.Count)
            {
            case 0:
            case 1:
                return(new IList <HlslTreeNode>[] { nodes });
            }

            List <IList <HlslTreeNode> > groups;

            var multiplicationGroup = MatrixMultiplicationGrouper.TryGetMultiplicationGroup(nodes);

            if (multiplicationGroup != null)
            {
                int dimension = multiplicationGroup.Vector.Length;
                groups = new List <IList <HlslTreeNode> >(new[]
                                                          { nodes.Take(dimension).ToList() });
                if (dimension < nodes.Count)
                {
                    List <HlslTreeNode> rest = nodes.Skip(dimension).ToList();
                    groups.AddRange(GroupComponents(rest));
                }
                return(groups);
            }

            var normalizeGroup = NormalizeGrouper.TryGetContext(nodes);

            if (normalizeGroup != null)
            {
                int dimension = normalizeGroup.Length;
                groups = new List <IList <HlslTreeNode> >(new[]
                                                          { nodes.Take(dimension).ToList() });
                if (dimension < nodes.Count)
                {
                    List <HlslTreeNode> rest = nodes.Skip(dimension).ToList();
                    groups.AddRange(GroupComponents(rest));
                }
                return(groups);
            }

            groups = new List <IList <HlslTreeNode> >();

            int groupStart = 0;
            int nodeIndex;

            for (nodeIndex = 1; nodeIndex < nodes.Count; nodeIndex++)
            {
                HlslTreeNode node1 = nodes[groupStart];
                HlslTreeNode node2 = nodes[nodeIndex];
                if (CanGroupComponents(node1, node2) == false)
                {
                    groups.Add(nodes.GetRange(groupStart, nodeIndex - groupStart));
                    groupStart = nodeIndex;
                }
            }
            groups.Add(nodes.GetRange(groupStart, nodeIndex - groupStart));
            return(groups);
        }
示例#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;
 }
示例#3
0
 public NodeGrouper(RegisterState registers)
 {
     MatrixMultiplicationGrouper = new MatrixMultiplicationGrouper(registers);
     NormalizeGrouper            = new NormalizeGrouper();
     _registers = registers;
 }