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: Mon, 27 Jan 2003 09:04:51 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        03/01/27 09:04:51

Modified files:
        gfx/libutil    : nvcode.py 

Log message:
        start fragment program emulation of register combiners

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

Patches:
Index: gzz/gfx/libutil/nvcode.py
diff -u gzz/gfx/libutil/nvcode.py:1.13 gzz/gfx/libutil/nvcode.py:1.14
--- gzz/gfx/libutil/nvcode.py:1.13      Mon Jan 27 06:18:44 2003
+++ gzz/gfx/libutil/nvcode.py   Mon Jan 27 09:04:51 2003
@@ -598,4 +598,142 @@
     init += "CombinerParameterNV NUM_GENERAL_COMBINERS_NV %s\n" % stage["num"]
         
     return init + code
+
+
+
+
+# Fragment program implementation of register combiners
+# Not finished yet
+class fpCombiner:
+    def __init__(self):
+        self.initializedRegs = {}
         
+        self.generalinput = [{} for i in range(0,16)]
+        
+        self.code = """
+        temp A, B, C, D;
+        temp AB, CD, SUM;
+        """
+
+        self.colorSumClamp = 0
+        
+        self.finalinput = {}
+
+    def initreg(self, reg, output = 0):
+        initmap = {
+            "TEXTURE0": "TXP TEXTURE0, fragment.texcoord[0], texture[0], 2D;",
+            "TEXTURE1": "TXP TEXTURE1, fragment.texcoord[1], texture[1], 2D;",
+            "TEXTURE2": "TXP TEXTURE2, fragment.texcoord[2], texture[2], 2D;",
+            "TEXTURE3": "TXP TEXTURE3, fragment.texcoord[3], texture[3], 2D;",
+            "PRIMARY_COLOR_NV": "mov PRIMARY_COLOR_NV, 
fragment.color.primary;",
+            "SECONDARY_COLOR_NV": "mov SECONDARY_COLOR_NV, 
fragment.color.secondary;",
+            "FOG": "mov FOG, state.fog.color;",
+            "SPARE0_NV": "mov SPARE0_NV.w, TEXTURE0;",
+            "SPARE1_NV": "",
+            "CONSTANT_COLOR0_NV": "",
+            "CONSTANT_COLOR1_NV": "",
+            "ZERO": "mov ZERO, 0;",
+            "E_TIMES_F_NV": "MUL E_TIMES_F_NV, E, F;",
+            "SPARE0_PLUS_SECONDARY_COLOR_NV": "ADD 
SPARE0_PLUS_SECONDARY_COLOR_NV, SPARE0, SECONDARY_COLOR_NV;"
+            }
+
+        if self.colorSumClamp:
+            initmap["SPARE0_PLUS_SECONDARY_COLOR_NV"] = "ADD_SAT 
SPARE0_PLUS_SECONDARY_COLOR_NV, SPARE0, SECONDARY_COLOR_NV;"
+
+        if not self.initializedRegs.has_key(reg):
+            self.code += "TEMP %s;\n";
+            if not output:
+                if reg == "SPARE0_NV":
+                    self.initreg("TEXTURE0")
+            
+                self.code += initmap[reg] + "\n";
+
+            self.initializedRegs[reg] = 1
+    
+
+    def genInputMapping(var, reg, mapping, comp):
+        inmap = {
+            # Might need to consider clamping the SIGNED_ mappings, too.
+            "UNSIGNED_IDENTITY_NV": "MOV_SAT TMP, %s;\n",
+            "UNSIGNED_INVERT_NV":   "SUB_SAT TMP, 1, %s;\n",
+            "SIGNED_IDENTITY_NV":   "MOV TMP, %s;\n",
+            "SIGNED_NEGATE_NV":     "MOV TMP, -%s;\n",
+            "EXPAND_NORMAL_NV":     "MOV_SAT TMP, %s; MAD TMP, 2, TMP, -1;\n",
+            "EXPAND_NEGATE_NV":     "MOV_SAT TMP, %s; MAD TMP, 2, -TMP, 1;\n",
+            "HALF_BIAS_NORMAL_NV":  "MOV_SAT TMP, %s; SUB TMP, TMP, .5;\n",
+            "HALF_BIAS_NEGATE_NV":  "MOV_SAT TMP, %s; SUB TMP, .5, TMP;\n",
+            }
+
+        self.initreg(reg)
+
+        if comp == "BLUE": reg += ".z"
+        if comp == "ALPHA": reg += ".w"
+
+        self.code += inmap[mapping].replace("TMP", var) % reg;
+
+    def genOutputMapping(reg, tmp, scale, bias):
+        self.initreg(reg, output = 1)
+            
+        outmap = {
+            ("SCALE_BY_ONE_HALF_NV","NONE"): "MUL %s, .5, %s;\n",
+            ("NONE","NONE"): "MOV %s, %s;\n",
+            ("NONE","BIAS_BY_NEGATIVE_ONE_HALF_NV"): "SUB %s, %s, .5;\n",
+            ("SCALE_BY_TWO_NV","NONE"): "MUL %s, %s, 2;\n",
+            ("SCALE_BY_TWO_NV","BIAS_BY_NEGATIVE_ONE_HALF_NV"): "MAD %s, %s, 
2, -1",
+            ("SCALE_BY_FOUR_NV","NONE"): "MUL %s, %s, 4;\n",
+            }
+        return outmap[(scale,bias)] % (reg, tmp);
+
+
+    def genGeneralCombiner(self, abOut, cdOut, sumOut, scale, bias, abDot, 
cdDot, muxSum, comp = "RGB"):
+        suff = ""
+        if comp == "ALPHA": suff = ".w"
+        
+        if abOut != "DISCARD_NV" or sumOut != "DISCARD_NV":
+            if abDot:
+                self.code += "DP3 AB, A, B;\n"
+            else:
+                self.code += "MUL AB, A, B;\n"
+                
+            if abOut != "DISCARD_NV":
+                self.genOutputMapping(abOut + suff, "AB", scale, bias);
+                    
+        if cdOut != "DISCARD_NV" or sumOut != "DISCARD_NV":
+            if cdDot:
+                self.code += "DP3 CD, C, D;\n"
+            else:
+                self.code += "MUL CD, C, D;\n"
+
+            if cdOut != "DISCARD_NV":
+                self.genOutputMapping(cdOut + suff, "CD", scale, bias);
+
+        if sumOut != "DISCARD_NV":
+            if muxSum:
+                # FIXME:
+                print "ERROR: mux not supported yet!\n"
+            else:
+                self.code += "ADD SUM, AB, CD;\n"
+                self.genOutputMapping(sumOut + suff, "SUM", scale, bias);
+
+
+    def genFinalCombiner(self):
+        self.code += """
+        # Final combiner
+        TEMP E, F, G;
+        """
+
+        vars = self.finalinput
+
+        # E and F need to be first for the proper initialization order
+        for var in "E", "F", "A", "B", "C", "D", "G":
+            if vars.has_key(var):
+                self.genInputMapping(var, vars[var][0], vars[var][1], 
vars[var][2])
+
+        self.code += """
+        MAD D, A, B, D;
+        TEMP invA;
+        SUB invA, 1, A;
+        MAD_SAT result.color.xyz, invA, C, D;
+        
+        MOV result.color.w, G;
+        """




reply via email to

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