gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx/libutil nvcode.py


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx/libutil nvcode.py
Date: Sat, 23 Nov 2002 12:02:31 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/11/23 12:02:31

Modified files:
        gfx/libutil    : nvcode.py 

Log message:
        Finish combiner code parser

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/nvcode.py.diff?tr1=1.4&tr2=1.5&r1=text&r2=text

Patches:
Index: gzz/gfx/libutil/nvcode.py
diff -u gzz/gfx/libutil/nvcode.py:1.4 gzz/gfx/libutil/nvcode.py:1.5
--- gzz/gfx/libutil/nvcode.py:1.4       Fri Nov 22 03:41:27 2002
+++ gzz/gfx/libutil/nvcode.py   Sat Nov 23 12:02:31 2002
@@ -103,9 +103,9 @@
             print pre + str(node)
 
 def parsecomp(name):
-    if name in ["a", "alpha"]: return "ALPHA"
-    if name in ["b", "blue"]: return "BLUE"
-    if name in ["rgb", "color", "col"]: return "RGB"
+    if name in ["a", "alpha", "ALPHA"]: return "ALPHA"
+    if name in ["b", "blue", "BLUE"]: return "BLUE"
+    if name in ["rgb", "color", "col", "RGB", "COLOR", "COL"]: return "RGB"
     return None
 
 def parseregs(tree):
@@ -122,6 +122,7 @@
         "CONST0": "CONSTANT_COLOR0_NV",
         "CONST1": "CONSTANT_COLOR1_NV",
         "ZERO": "ZERO",
+        "DISCARD": "DISCARD_NV",
         "EF": "E_TIMES_F_NV",
         "SPARE0_PLUS_COL1" : "SPARE0_PLUS_SECONDARY_COLOR_NV",
         }
@@ -142,295 +143,445 @@
                 else:
                     tree[i:i+1] = [("reg", regmap[node[1]], "RGB")]
         i += 1
-        
-def findregs(list, type = "reg"):
-    indlist = []
-    for i in range(0,len(list)):
-        if list[i] == type: indlist.append(i)
-    return indlist
-
-def parseinput(tree):
-    inputmap = {
-        ("+", "reg"): "SIGNED_IDENTITY_NV",
-        ("reg",): "UNSIGNED_IDENTITY_NV",
-        (2, "reg", "-", 1): "EXPAND_NORMAL_NV",
-        (2, "*", "reg", "-", 1): "EXPAND_NORMAL_NV",
-        ("reg", "-", .5): "HALF_BIAS_NORMAL_NV",
-        ("-", "reg"): "SIGNED_NEGATE_NV",
-        (1, "-", "reg"): "UNSIGNED_INVERT_NV",
-        (1, "-", 2, "reg"): "EXPAND_NEGATE_NV",
-        (1, "-", 2, "*", "reg"): "EXPAND_NEGATE_NV",
-        (.5, "-", "reg"): "HALF_BIAS_NEGATE"
-        }
 
-    key = tuple(map(lambda node: node[0], tree))
+def removeparen(tree):
+    # Remove extra parentheses
+    if len(tree) == 1 and tree[0][0] == "sub":
+        tree[:] = tree[0][1]
+    return tree
+    
+def parsekey(tree):
+    # Return list of node types
+    return map(lambda x: x[0], tree)
+    
+    
+def findregs(tree, type = "reg"):
+    def func(x, type=type): return x[0] == type
+    return filter(func, tree)
+
+def parseinput(tree, final = 0):
+    if final:
+        inputmap = {
+            ("reg",): "UNSIGNED_IDENTITY_NV",
+            (1, "-", "reg"): "UNSIGNED_INVERT_NV",
+            (1,): "UNSIGNED_INVERT_NV",
+            (0,): "UNSIGNED_IDENTITY_NV",
+            }
+    else:
+        inputmap = {
+            ("reg",): "UNSIGNED_IDENTITY_NV",
+            (1, "-", "reg"): "UNSIGNED_INVERT_NV",
+            ("+", "reg"): "SIGNED_IDENTITY_NV",
+            ("-", "reg"): "SIGNED_NEGATE_NV",
+            (2, "*", "reg", "-", 1): "EXPAND_NORMAL_NV",
+            (1, "-", 2, "*", "reg"): "EXPAND_NEGATE_NV",
+            ("reg", "-", .5): "HALF_BIAS_NORMAL_NV",
+            (.5, "-", "reg"): "HALF_BIAS_NEGATE_NV",
+
+            (0,): "UNSIGNED_IDENTITY_NV",
+            (1,): "UNSIGNED_INVERT_NV",
+            (.5,): "HALF_BIAS_NEGATE_NV",
+            ("+", 0): "SIGNED_IDENTITY_NV",
+            ("-", 0): "SIGNED_NEGATE_NV",
+            ("-", 1): "EXPAND_NORMAL_NV",
+            ("+", 1): "EXPAND_NEGATE_NV",
+            ("+", .5): "HALF_BIAS_NEGATE_NV",
+            ("-", .5): "HALF_BIAS_NORMAL_NV",
+            }
+
+    key = tuple(parsekey(tree))
     
     if inputmap.has_key(key):
-        i = findregs(key)[0]
-        tree[:] = [("in", tree[i][1], inputmap[key], tree[i][2])]
+        reg = (findregs(tree) + [("reg", "ZERO", "ALPHA")])[0]
+        tree[:] = [("in", reg[1], inputmap[key], reg[2])]
     else:
         for i in range(0,len(tree)):
             if tree[i][0] == "sub":
-                parseinput(tree[i][1])
+                parseinput(tree[i][1], final)
                 if len(tree[i][1]) == 1:
                     tree[i] = tree[i][1][0]
-            elif tree[i][0] == "reg":
-                tree[i] = ("in", tree[i][1], inputmap["reg",], tree[i][2])
-
-def setcheck(hash, name, value):
-    if hash.has_key(name):
-        if hash[name] != value:
-            print "ERROR: Incompatible <" + name + ">'s"
-            return 0
-    else:
-        hash[name] = value
-    return 1
+            else:
+                # Search for substring matches, too, for single-node keys
+                key = (tree[i][0],)
+                if inputmap.has_key(key):
+                    reg = ("reg", "ZERO", "ALPHA")
+                    if key == ("reg",): reg = tree[i]
+                    tree[i] = ("in", reg[1], inputmap[key], reg[2])
 
-def parseoutput(tree, out, outreg = "OUTREG"):
 
-    scale = "NONE"
-    bias = "NONE"
+def parseGeneralCombiner(outreg, tree):
+    out = {
+        "scale": "NONE",
+        "bias": "NONE"
+        }
 
     outputscale = {
-        ("*", .5): "SCALE_BY_ONE_HALF_NV",
-        ("/", 2): "SCALE_BY_ONE_HALF_NV",
-        ("*", 1): "NONE",
-        ("*", 2): "SCALE_BY_TWO_NV",
-        ("*", 4): "SCALE_BY_FOUR_NV"
+        (sub, "*", .5): "SCALE_BY_ONE_HALF_NV",
+        (sub, "/", 2): "SCALE_BY_ONE_HALF_NV",
+        (sub, "*", 1): "NONE",
+        (sub, "*", 2): "SCALE_BY_TWO_NV",
+        (sub, "*", 4): "SCALE_BY_FOUR_NV"
         }
     outputbias = {
         ("-", .5): "BIAS_BY_NEGATIVE_ONE_HALF_NV",
+        ("-", 0): "NONE",
         }
     
-    l = map(lambda node: node[0], tree)
-    if len(l) >= 2:
-        key = tuple(l[1:])
-        if outputscale.has_key(key):
-            scale = outputscale[key]
-            tree[:] = tree[:-2]
-            if len(tree) == 1 and tree[0][0] == "sub":
-                tree[:] = tree[0][1]
-
-    l = map(lambda node: node[0], tree)
-    if len(l) >= 2:
-        key = tuple(l[-2:])
-        if outputbias.has_key(key):
-            bias = outputbias[key]
-            tree[:] = tree[:-2]
+    key = tuple(parsekey(tree))
+    if outputscale.has_key(key):
+        out["scale"] = outputscale[key]
+        tree[:] = tree[:-2]
+        removeparen(tree)
+
+    key = tuple(parsekey(tree)[-2:])
+    if outputbias.has_key(key):
+        out["bias"] = outputbias[key]
+        tree[:] = tree[:-2]
 
-    setcheck(out, "bias", bias)
-    setcheck(out, "scale", scale)
+    removeparen(tree)
+    parseinput(tree)
 
-    funcmap1 = {
+    funcmap = {
         ("in", ".", "in"): ("AB", "TRUE"),
-        ("in",): ("A", "FALSE"),
-        ("in", "*", "in"): ("AB", "TRUE"),
-        }
-    
-    funcmap2 = {
-        ("in", "+", "in"): ("AC", "FALSE"),
-        ("in", "+", "in", "*", "in"): ("ACD", "FALSE"),
-        ("in", "*", "in", "+", "in"): ("ABC", "FALSE"),
+        ("in",):           ("A",  "FALSE"),
+        ("in", "*", "in"): ("AB", "FALSE"),
+
+        ("in", "+", "in"):                       ("AC",   "FALSE"),
+        ("in", "+", "in", "*", "in"):            ("ACD",  "FALSE"),
+        ("in", "*", "in", "+", "in"):            ("ABC",  "FALSE"),
         ("in", "*", "in", "+", "in", "*", "in"): ("ABCD", "FALSE"),
-        ("in", "|", "in"): ("AC", "TRUE"),
-        ("in", "|", "in", "*", "in"): ("ACD", "TRUE"),
-        ("in", "*", "in", "|", "in"): ("ABC", "TRUE"),
+        ("in", "|", "in"):                       ("AC",   "TRUE"),
+        ("in", "|", "in", "*", "in"):            ("ACD",  "TRUE"),
+        ("in", "*", "in", "|", "in"):            ("ABC",  "TRUE"),
         ("in", "*", "in", "|", "in", "*", "in"): ("ABCD", "TRUE"),
         }
 
-    key = tuple(map(lambda node: node[0], tree))
-    if funcmap1.has_key(key):
-        func = funcmap1[key]
-        regs = findregs(key, "in")
-
-        foo = [ " ".join(tree[reg][1:]) for reg in regs ]
-        if len(foo) == 1: foo += ["ZERO UNSIGNED_IDENTITY_NV ALPHA"]
-
-        if (out.has_key("A") and out["A"] != foo[0] or
-            out.has_key("B") and out["B"] != foo[1] or
-            out.has_key("abDot") and out["abDot"] != func[1] or
-            out.has_key("abOut")):
-            setcheck(out, "C", foo[0])
-            setcheck(out, "D", foo[1])
-            setcheck(out, "cdDot", func[1])
-            setcheck(out, "cdOut", outreg)
+    key = tuple(parsekey(tree))
+    if funcmap.has_key(key):
+        func = funcmap[key]
+        regs = findregs(tree, "in")
+
+        if "C" in func[0]:
+            regset = "ABCD"
+            out["muxSum"] = func[1]
+            out["sumOut"] = outreg
         else:
-            setcheck(out, "A", foo[0])
-            setcheck(out, "B", foo[1])
-            setcheck(out, "abDot", func[1])
-            setcheck(out, "abOut", outreg)
-        
-    elif funcmap2.has_key(key):
-        func = funcmap2[key]
-        regs = findregs(key, "in")
+            regset = "AB"
+            out["abDot"] = func[1]
+            out["abOut"] = outreg
 
         for i in range(0,len(regs)):
-            setcheck(out, func[0][i], " ".join(tree[regs[i]][1:]))
+            out[func[0][i]] = " ".join(regs[i][1:])
 
-        for name in "ABCD":
-            if name not in func[0]:
-                setcheck(out, name, "ZERO UNSIGNED_IDENTITY_NV ALPHA")
+        for reg in regset:
+            if reg not in func[0]:
+                out[reg] = "ZERO UNSIGNED_IDENTITY_NV ALPHA"
 
-        setcheck(out, "sumOut", outreg)
-        setcheck(out, "muxSum", func[1])
     else:
-        print "Function not recognized"
-        printtree(tree)
-        return 0
+        print "ERROR: General combiner function", key, "not recognized"
+        return None
 
-    return 1
+    return out
 
-# Parse general combiner stage code from lines such as
-#   SPARE0 = (COL0 . COL1 - .5) * 2
-#   SPARE1 = (CONST0 * (1 - COL0) - .5) * 2
-#   SPARE0.alpha = (1 - 2 * COL0.alpha) + COL1.blue
-def parseGeneralCombiner(lines, stage = 0):
-    out = {
-        "RGB": {},
-        "ALPHA": {}
-        }
-    
-    for line in lines:
-        mid = line.find("=")
-        if mid == -1:
-            print "ERROR: '=' not found:", line
-            return ""
-        
-        (left, lend) = exptree(line, 0)
-        (right, rend) = exptree(line, mid + 1)
-        if lend < mid:
-            print "ERROR: extra input:", line[lend:mid]
-            return ""
-        if rend < len(line):
-            print "ERROR: extra input:", line[rend:]
-            return ""
+def addStageComp(out, new):
+    def remapAB(old):
+        new = old.copy()
+        new["C"] = new["A"]; del new["A"]; 
+        new["D"] = new["B"]; del new["B"]; 
+        new["cdDot"] = new["abDot"]; del new["abDot"]; 
+        new["cdOut"] = new["abOut"]; del new["abOut"]; 
+        return new
+
+    for key in new.keys():
+        if out.has_key(key) and (out[key] != new[key] or key.endswith("Out")):
+            return new.has_key("abOut") and addStageComp(out, remapAB(new))
         
-        parseregs(left)
-        parseregs(right)
-        
-        if len(left) != 1 or left[0][0] != "reg":
-            print "ERROR: left side not a register:"
-            printtree(left)
-            return ""
- 
-        outreg = left[0][1]
-        outcomp = left[0][2]
-
-        parseinput(right)
-        if not parseoutput(right, out[outcomp], outreg):
-            return ""
+    out.update(new)
+    return 1
 
-    code = "".join(map(lambda x: "# " + x + "\n", lines))
+# Output general combiner stage, and initialize for the next stage
+def outputGeneralCombiner(stage):
+    code = ""
+    if not stage["RGB"] and not stage["ALPHA"]:
+        for c in "CONSTANT_COLOR0_NV", "CONSTANT_COLOR1_NV":
+            if stage.has_key(c):
+                code += "CombinerParameterNV %s %s\n" % (c, stage[c])
+                stage["globalConst"] = stage["num"]
+                del stage[c]
+        return code
+
+    for c in "CONSTANT_COLOR0_NV", "CONSTANT_COLOR1_NV":
+        if stage.has_key(c):
+            code += ("CombinerStageParameterNV COMBINER%s_NV %s %s\n"
+                     % (stage["num"], c, stage[c]))
+            stage["perStageConst"] = stage["num"]
+            del stage[c]
+            
     for comp in "RGB", "ALPHA":
-        if out[comp]:
+        #if stage[comp]:
             for var in "A", "B", "C", "D":
-                if out[comp].has_key(var):
+                if stage[comp].has_key(var):
                     code += (
                         "CombinerInputNV COMBINER%s_NV %s VARIABLE_%s_NV %s\n"
-                        % (stage, comp, var, out[comp][var]))
+                        % (stage["num"], comp, var, stage[comp][var]))
 
             code += (
                 "CombinerOutputNV COMBINER%s_NV %s %s %s %s %s %s %s %s %s\n"
-                % (stage, comp,
-                   out[comp].get("abOut", "DISCARD_NV"),
-                   out[comp].get("cdOut", "DISCARD_NV"),
-                   out[comp].get("sumOut", "DISCARD_NV"),
-                   out[comp]["scale"],
-                   out[comp]["bias"],
-                   out[comp].get("abDot", "FALSE"),
-                   out[comp].get("cdDot", "FALSE"),
-                   out[comp].get("muxSum", "FALSE"),
+                % (stage["num"], comp,
+                   stage[comp].get("abOut", "DISCARD_NV"),
+                   stage[comp].get("cdOut", "DISCARD_NV"),
+                   stage[comp].get("sumOut", "DISCARD_NV"),
+                   stage[comp].get("scale", "NONE"),
+                   stage[comp].get("bias", "NONE"),
+                   stage[comp].get("abDot", "FALSE"),
+                   stage[comp].get("cdDot", "FALSE"),
+                   stage[comp].get("muxSum", "FALSE"),
                    )
                 )
+            stage[comp] = {}
+
+    stage["num"] += 1
 
     return code
 
 
-# Parse final combiner code from lines such as
+def parseFinalCombiner(outreg, tree):
+    parseinput(tree, final = 1)
+
+    key = tuple(parsekey(tree))
+
+    if outreg == "EF":
+        if key != ("in", "*", "in"):
+            print "ERROR: EF must be a product, got", key
+            return ""
+        return ("FinalCombinerInput VARIABLE_E_NV " + 
+                " ".join(tree[0][1:]) + "\n" +
+                "FinalCombinerInput VARIABLE_F_NV " + 
+                " ".join(tree[2][1:]) + "\n")
+    elif outreg == "ALPHA":
+        if key != ("in",):
+            print "ERROR: alpha must be an input mapped register, got", key
+            return ""
+        return ("FinalCombinerInput VARIABLE_G_NV " + 
+                " ".join(tree[0][1:]) + "\n")
+    else:
+        funcmap = {
+            ("in", "*", "in", "+", "in", "*", "in", "+", "in"): "ABACD",
+            ("in", "*", "in", "+", "in", "*", "in"): "ABAC",
+            ("in", "*", "in", "+", "in"): "ABD",
+            ("in", "+", "in"): "CD",
+            ("in", "*", "in"): "AB",
+            ("in",): "D",
+            }
+        if funcmap.has_key(key):
+            func = funcmap[key]
+            regs = findregs(tree, "in")
+
+            code = ""
+            for i in range(0,len(regs)):
+                if i > 0 and func[i] == "A":
+                    if (regs[i][1] != regs[0][1] or
+                        regs[i][2] == regs[0][2] or
+                        regs[i][3] != regs[0][3]):
+                        print ("ERROR: inconsistent A variables:",
+                               regs[0], regs[i])
+                        return ""
+                else:
+                    code += ("FinalCombinerInput VARIABLE_%s_NV %s\n"
+                             % (func[i], " ".join(regs[i][1:])))
+
+            for reg in "ABCD":
+                if reg not in func:
+                    code += ("FinalCombinerInput VARIABLE_%s_NV "
+                             "ZERO UNSIGNED_IDENTITY_NV ALPHA\n" % reg)
+
+            return code
+        else:
+            print "ERROR: Final combiner function", key, "not recognized:"
+            return ""
+
+"""
+REGNAME = COL0 | COL1
+        | TEX0 | TEX1 | TEX2 | TEX3
+        | SPARE0 | SPARE1
+        | FOG
+        | CONST0 | CONST1
+        | ZERO | DISCARD 
+       | EF | SPARE0_PLUS_COL1
+
+ALPHA_COMP = a | alpha | ALPHA
+BLUE_COMP = b | blue | BLUE
+RGB_COMP = rgb | col | color | RGB | COL | COLOR
+
+REG = REGNAME
+    | REGNAME . ALPHA_COMP
+    | REGNAME . BLUE_COMP
+    | REGNAME . RGB_COMP
+
+IN = REG
+   | (1 - REG)
+   | (+REG)
+   | (-REG)
+   | (2 * REG - 1)
+   | (1 - 2 * REG)
+   | (REG - .5)
+   | (.5 - REG)
+   | 0 | .5 | 1 | (-1) | (-.5) | (-0) | (+0) | (+.5) | (+1)
+   | (IN)
+
+EXP = IN . IN 
+    | IN
+    | IN * IN
+    | IN + IN
+    | IN + IN * IN
+    | IN * IN + IN
+    | IN * IN + IN * IN
+    | IN '|' IN
+    | IN '|' IN * IN
+    | IN * IN '|' IN
+    | IN * IN '|' IN * IN
+
+PAREN_EXP = EXP
+         | (EXP)
+
+BIASED_EXP = PAREN_EXP
+          | PAREN_EXP - .5
+          | PAREN_EXP - 0
+
+OUT = BIASED_EXP
+    | (BIASED_EXP) / 2
+    | (BIASED_EXP) * .5
+    | (BIASED_EXP) * 1
+    | (BIASED_EXP) * 2
+    | (BIASED_EXP) * 4
+          
+
+FINAL_IN = REG
+        | (1 - REG)
+        | 0 | 1
+        | (FINAL_IN)
+
+FINAL_OUT = FINAL_IN * FINAL_IN + FINAL_IN * FINAL_IN + FINAL_IN
+          | FINAL_IN * FINAL_IN + FINAL_IN * FINAL_IN
+          | FINAL_IN * FINAL_IN + FINAL_IN
+          | FINAL_IN + FINAL_IN
+          | FINAL_IN * FINAL_IN
+          | FINAL_IN
+
+FUNC = REG '=' OUT
+     | RGB_COMP '=' FINAL_OUT
+     | ALPHA_COMP '=' FINAL_IN
+     | EF '=' FINAL_IN * FINAL_IN
+     | CONST0 '=' vector
+     | CONST1 '=' vector
+"""
+# Parse register combiner code from lines containing a '=' character.
+# The syntax is given by FUNC above.
+# Code from lines not containing a '=' is passed through.
+#
+#   str     The code lines separated by '\n' or ';'. '#'-comments are removed.
+#   returns The generated code
+#
+# NUM_GENERAL_COMBINERS_NV and PER_STAGE_CONSTANTS_NV are automatically set.
+#
+# Semantics:
+#   - A new combiner stage is started for all combiner code lines except for 
+#     those adjacent "REG = OUT" assignments that can fit in the current stage.
+#   - Per stage constants are enabled unless all constant assignments are 
+#     either before or after all general combiner register assignments 
+#   - Only syntax is verified; Semantic errors may not be detected until
+#     the code is executed
+#
+# Example:
+#   CONST0 = .2 .3 .4 .5
+#   SPARE0 = (COL0 . COL1 - .5) * 2
+#   SPARE1 = (CONST0 * (1 - COL0) - .5) * 2
+#   SPARE0.alpha = (1 - 2 * COL0.alpha) + COL1.blue
 #   alpha = 1-SPARE0
 #   EF = COL0 * (1 - COL1.alpha)
 #   color = EF * FOG + (1-EF) * SPARE1
-def parseFinalCombiner(lines):
-    code = "".join(map(lambda x: "# " + x + "\n", lines))
-    for line in lines:
-        mid = line.find("=")
-        if mid == -1:
-            print "ERROR: '=' not found:", line
-            return ""
+#
+def parseCombiner(str):
+    def removeComment(line):
+        pos = line.find("#")
+        if pos >= 0: return line[:pos]
+        return line
         
+    lines = ";".join(map(removeComment,str.splitlines())).split(";")
+
+
+    code = ""
+    
+    stage = {
+        "RGB": {},
+        "ALPHA": {},
+        "num": 0,
+        }
+
+    for line in lines:
+        line = line.strip()
+        if not line: continue
+
+        pos = line.find("=")
+        if pos == -1:
+            code += line + "\n"
+            continue
+
         (left, lend) = exptree(line, 0)
-        (right, rend) = exptree(line, mid + 1)
-        if lend < mid:
-            print "ERROR: extra input:", line[lend:mid]
+        (right, rend) = exptree(line, pos + 1)
+        if lend < pos:
+            print "ERROR: extra input:", line[lend:pos]
             return ""
         if rend < len(line):
             print "ERROR: extra input:", line[rend:]
             return ""
 
-        outreg = None
-        if len(left) == 1 and left[0][0] == "id": 
-            if left[0][1] == "EF":
-                outreg = "EF"
-            else:
-                outreg = parsecomp(left[0][1])
-
-        if outreg not in ["EF", "RGB", "ALPHA"]:
-            print "ERROR: left side must be EF, color, or alpha:"
-            printtree(left)
-            return ""
 
         parseregs(right)
-        parseinput(right)
 
-        key = tuple(map(lambda node: node[0], right))
+        outreg = None
+        if len(left) == 1 and left[0][0] == "id":
+            outreg = parsecomp(left[0][1]) or left[0][1]
 
-        if outreg == "EF":
-            if key != ("in", "*", "in"):
-                print "ERROR: EF must be a product"
-                printtree(right)
-                return ""
-            code += ("FinalCombinerInput VARIABLE_E_NV " + 
-                     " ".join(right[0][1:]) + "\n" +
-                     "FinalCombinerInput VARIABLE_F_NV " + 
-                     " ".join(right[2][1:]) + "\n")
-        elif outreg == "ALPHA":
-            if key != ("in",):
-                print "ERROR: alpha must be an input mapped register"
-                printtree(right)
+        if outreg in ("EF", "RGB", "ALPHA"):
+            code += outputGeneralCombiner(stage)
+            str = parseFinalCombiner(outreg, right)
+            if not str: return ""
+            code += "# " + line + "\n"
+            code += str
+        else:
+            parseregs(left)
+            if len(left) == 1 and left[0][0] == "reg":
+                outreg = left[0][1]
+                outcomp = left[0][2]
+
+                if outreg.startswith("CONST"):
+                    code += outputGeneralCombiner(stage)
+                    stage[outreg] = line[pos+1:]
+                else:
+                    out = parseGeneralCombiner(outreg, right)
+                    if not out: return ""
+
+                    if not addStageComp(stage[outcomp], out):
+                        code += outputGeneralCombiner(stage)
+                        stage[outcomp] = out
+
+                code += "# " + line + "\n"
+            else:
+                print "ERROR: left side must be register:", line
                 return ""
-            code += ("FinalCombinerInput VARIABLE_G_NV " + 
-                     " ".join(right[0][1:]) + "\n")
+
+    code += outputGeneralCombiner(stage)
+
+    init = ""
+    if stage.has_key("perStageConst"):
+        if stage["perStageConst"] > 0 or stage.has_key("globalConst"):
+            init += "Enable PER_STAGE_CONSTANTS_NV\n"
         else:
-            funcmap = {
-                ("in", "*", "in", "+", "in", "*", "in", "+", "in"): "ABACD",
-                ("in", "*", "in", "+", "in", "*", "in"): "ABAC",
-                ("in", "*", "in"): "AB",
-                ("in"): "D",
-                }
-            if funcmap.has_key(key):
-                func = funcmap[key]
-                regs = findregs(key, "in")
-
-                for i in range(0,len(regs)):
-                    inreg = [foo for foo in right[regs[i]][1:]]
-                    
-                    if i > 0 and func[i] == "A":
-                        if inreg[1] == "UNSIGNED_IDENTITY_NV":
-                            inreg[1] = "UNSIGNED_INVERT_NV"
-                        if inreg[1] ==  "UNSIGNED_INVERT_NV":
-                            inreg[1] = "UNSIGNED_IDENTITY_NV"
-                        if inreg[1] != right[0][2] or inreg[0] != right[0][1]:
-                            print "ERROR: inconsistent A variables"
-                            printtree(right)
-                            return ""
-                    else:
-                        code += ("FinalCombinerInput VARIABLE_%s_NV %s\n"
-                                 % (func[i], " ".join(inreg)))
-
-                for reg in "ABCD":
-                    if reg not in func:
-                        code += ("FinalCombinerInput VARIABLE_%s_NV "
-                                 "ZERO UNSIGNED_IDENTITY_NV ALPHA\n" % reg)
+            code = code.replace("CombinerStageParameterNV COMBINER0_NV",
+                                "CombinerParameterNV")
 
-    return code
-    
+    init += "CombinerParameterNV NUM_GENERAL_COMBINERS_NV %s\n" % stage["num"]
+        
+    return init + code
+        




reply via email to

[Prev in Thread] Current Thread [Next in Thread]