imageworks/OpenShadingLanguage — pull request #146 by lgritz (2012-06-25 18:45:22+00:00)
Title: Review: matrix param initialization by constants

Matrix parms initialized by m=matrix(consta,constb,...) should statically initialize, not need init ops.

This makes it similar to triples, and makes oslinfo work sensibly for
a wider variety of cases.

To clarify, consider this shader:

shader test (point p = point(1,2,3),
matrix m = matrix(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15))
{ }

oslc will recognize that even though p is initialized by a point() operator (that is, code that assembled the point from individual floats), since those floats are all constants, it gets rid of that code ("initialization ops") and just statically sets the default values of p to [1 2 3]. This is reflected in the .oso file, and also makes the output of "oslinfo" very sensible.

However, before this patch, it will not similarly transform the initialization of matrices like m. This makes the "oslinfo" output misleading (and, perhaps, has a very minor performance penalty, but probably nothing you'll ever notice.

This patch fixes it, by recognizing constant matrices used shader parameter initializers, and promoting them to static initializers instead of runtime-executed "init ops."