Permalink
Browse files

Fix oso output of matrix parameter initialization.

(1) Some combinations not output at all!
(2) Initializing to 1 set the initialization to (1,1,1,1...) instead of ident.
(3) Initializing matrices to constructed constants would emit init ops even
    when not needed.  (Fixing this may reduce init ops and improve perf
    slightly by avoiding doubly-initializing matrices.)
Interestingly, #3 largely covered up #1 and #2, by re-copying the correct
value in the process of initializing redundantly.
  • Loading branch information...
1 parent 013549e commit f01d89b1b10bd8438c38cc72230ab564f58e42c4 @lgritz lgritz committed Sep 22, 2012
Showing with 42 additions and 15 deletions.
  1. +12 −14 src/liboslcomp/codegen.cpp
  2. +20 −0 testsuite/matrix/ref/out.txt
  3. +10 −1 testsuite/matrix/test.osl
View
@@ -648,12 +648,13 @@ ASTvariable_declaration::param_one_default_literal (const Symbol *sym,
completed = false;
}
} else if (type.is_matrix()) {
- float f = 0;
- if (islit && lit->typespec().is_int())
- f = lit->intval();
- else if (islit && lit->typespec().is_float())
- f = lit->floatval();
- else if (init && init->typespec() == type &&
+ if (islit && lit->typespec().is_int()) {
+ float f = lit->intval();
+ out += Strutil::format ("%.8g 0 0 0 0 %.8g 0 0 0 0 %.8g 0 0 0 0 %.8g ", f, f, f, f);
+ } else if (islit && lit->typespec().is_float()) {
+ float f = lit->floatval();
+ out += Strutil::format ("%.8g 0 0 0 0 %.8g 0 0 0 0 %.8g 0 0 0 0 %.8g ", f, f, f, f);
+ } else if (init && init->typespec() == type &&
init->nodetype() == ASTNode::type_constructor_node) {
ASTtype_constructor *ctr = (ASTtype_constructor *) init;
ASTNode::ref val = ctr->args();
@@ -665,26 +666,23 @@ ASTvariable_declaration::param_one_default_literal (const Symbol *sym,
if (val.get() && val->nodetype() == ASTNode::literal_node) {
f[c] = ((ASTliteral *)val.get())->floatval ();
val = val->next();
+ if (! val.get()) // we're done -- no more args
+ break;
} else {
f[c] = 0;
completed = false;
}
}
if (nargs == 1)
- out += Strutil::format ("%.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g ",
- f[0], f[0], f[0], f[0], f[0], f[0], f[0], f[0])
- + Strutil::format ("%.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g ",
- f[0], f[0], f[0], f[0], f[0], f[0], f[0], f[0]);
+ out += Strutil::format ("%.8g 0 0 0 0 %.8g 0 0 0 0 %.8g 0 0 0 0 %.8g ",
+ f[0], f[0], f[0], f[0]);
else
out += Strutil::format ("%.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g ",
f[0], f[1], f[2], f[3], f[4], f[5], f[6], f[7])
+ Strutil::format ("%.8g %.8g %.8g %.8g %.8g %.8g %.8g %.8g",
f[8], f[9], f[10], f[11], f[12], f[13], f[14], f[15]);
} else {
- f = 0;
- std::string s = Strutil::format ("%.8g ", f);
- for (int i = 0; i < 16; ++i)
- out += s;
+ out += "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ";
completed = false;
}
} else if (type.is_string()) {
@@ -1,4 +1,9 @@
Compiled test.osl -> test.oso
+Parameter initialization:
+ matrixparam0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ matrixparam1 = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+ matrixparam1m = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+
matrix (0.1) = 0.1 0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.1
matrix (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
= 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6
@@ -56,6 +61,11 @@ Testing matrix math:
(M!=M) ? 0
(M==Ident) ? 0
(M!=Ident) ? 1
+Parameter initialization:
+ matrixparam0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ matrixparam1 = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+ matrixparam1m = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+
matrix (0.1) = 0.1 0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.1
matrix (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
= 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6
@@ -112,6 +122,11 @@ Testing matrix math:
(M!=M) ? 0
(M==Ident) ? 0
(M!=Ident) ? 1
+Parameter initialization:
+ matrixparam0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ matrixparam1 = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+ matrixparam1m = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+
matrix (0.1) = 0.1 0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.1
matrix (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
= 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6
@@ -168,6 +183,11 @@ Testing matrix math:
(M!=M) ? 0
(M==Ident) ? 0
(M!=Ident) ? 1
+Parameter initialization:
+ matrixparam0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ matrixparam1 = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+ matrixparam1m = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
+
matrix (0.1) = 0.1 0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.1
matrix (0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6)
= 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6
View
@@ -21,8 +21,17 @@ void matrix_fromto (string from, string to)
shader
-test ()
+test (matrix matrixparam0 = 0,
+ matrix matrixparam1 = 1,
+ matrix matrixparam1m = matrix(1))
{
+ // Test parameter initialization
+ printf ("Parameter initialization:\n");
+ printf (" matrixparam0 = %g\n", matrixparam0);
+ printf (" matrixparam1 = %g\n", matrixparam1);
+ printf (" matrixparam1m = %g\n", matrixparam1m);
+ printf ("\n");
+
// Test matrix constructors
{
float a = 0.1, b = 0.2, c = 0.3, d = 0.4,

0 comments on commit f01d89b

Please sign in to comment.