From: Kenneth Graunke Date: Wed, 9 Jun 2010 22:47:09 +0000 (-0700) Subject: Implement 1.20 'outerProduct' builtin. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=43ff6fc4ae5f47f1537707b794253929780cafc1;p=mesa.git Implement 1.20 'outerProduct' builtin. --- diff --git a/builtin_function.cpp b/builtin_function.cpp index 7072af25719..dc07f85136f 100644 --- a/builtin_function.cpp +++ b/builtin_function.cpp @@ -2811,8 +2811,104 @@ static const char *builtins_120_matrixCompMult = { "))\n" }; +static const char *builtins_120_outerProduct = { + "((function outerProduct\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) vec2 u)\n" + " (declare (in) vec2 v))\n" + " ((declare () mat2 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref v) (swiz y (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) vec2 u)\n" + " (declare (in) vec3 v))\n" + " ((declare () mat2x3 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref v) (swiz y (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) vec2 u)\n" + " (declare (in) vec4 v))\n" + " ((declare () mat2x4 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref v) (swiz y (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) vec3 u)\n" + " (declare (in) vec2 v))\n" + " ((declare () mat3x2 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref v) (swiz y (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref v) (swiz z (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) vec3 u)\n" + " (declare (in) vec3 v))\n" + " ((declare () mat3 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref v) (swiz y (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref v) (swiz z (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) vec3 u)\n" + " (declare (in) vec4 v))\n" + " ((declare () mat3x4 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref v) (swiz y (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref v) (swiz z (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) vec4 u)\n" + " (declare (in) vec2 v))\n" + " ((declare () mat4x2 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref v) (swiz y (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref v) (swiz z (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (3))) (expression vec2 * (var_ref v) (swiz w (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) vec4 u)\n" + " (declare (in) vec3 v))\n" + " ((declare () mat4x3 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref v) (swiz y (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref v) (swiz z (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (3))) (expression vec3 * (var_ref v) (swiz w (var_ref u)))) \n" + "(return (var_ref m))))\n" + "\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) vec4 u)\n" + " (declare (in) vec4 v))\n" + " ((declare () mat4 m)\n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref v) (swiz x (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref v) (swiz y (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref v) (swiz z (var_ref u)))) \n" + " (assign (constant bool (1)) (array_ref (var_ref m) (constant int (3))) (expression vec4 * (var_ref v) (swiz w (var_ref u)))) \n" + "(return (var_ref m))))\n" + "))\n" + "\n" +}; + static const char *functions_for_120 [] = { builtins_120_matrixCompMult, + builtins_120_outerProduct, }; /* 130 builtins */ diff --git a/builtins/120/outerProduct b/builtins/120/outerProduct new file mode 100644 index 00000000000..b401ba02337 --- /dev/null +++ b/builtins/120/outerProduct @@ -0,0 +1,92 @@ +((function outerProduct + (signature mat2 + (parameters + (declare (in) vec2 u) + (declare (in) vec2 v)) + ((declare () mat2 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref v) (swiz y (var_ref u)))) +(return (var_ref m)))) + + (signature mat2x3 + (parameters + (declare (in) vec2 u) + (declare (in) vec3 v)) + ((declare () mat2x3 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref v) (swiz y (var_ref u)))) +(return (var_ref m)))) + + (signature mat2x4 + (parameters + (declare (in) vec2 u) + (declare (in) vec4 v)) + ((declare () mat2x4 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref v) (swiz y (var_ref u)))) +(return (var_ref m)))) + + (signature mat3x2 + (parameters + (declare (in) vec3 u) + (declare (in) vec2 v)) + ((declare () mat3x2 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref v) (swiz y (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref v) (swiz z (var_ref u)))) +(return (var_ref m)))) + + (signature mat3 + (parameters + (declare (in) vec3 u) + (declare (in) vec3 v)) + ((declare () mat3 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref v) (swiz y (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref v) (swiz z (var_ref u)))) +(return (var_ref m)))) + + (signature mat3x4 + (parameters + (declare (in) vec3 u) + (declare (in) vec4 v)) + ((declare () mat3x4 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref v) (swiz y (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref v) (swiz z (var_ref u)))) +(return (var_ref m)))) + + (signature mat4x2 + (parameters + (declare (in) vec4 u) + (declare (in) vec2 v)) + ((declare () mat4x2 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec2 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec2 * (var_ref v) (swiz y (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec2 * (var_ref v) (swiz z (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (3))) (expression vec2 * (var_ref v) (swiz w (var_ref u)))) +(return (var_ref m)))) + + (signature mat4x3 + (parameters + (declare (in) vec4 u) + (declare (in) vec3 v)) + ((declare () mat4x3 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec3 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec3 * (var_ref v) (swiz y (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec3 * (var_ref v) (swiz z (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (3))) (expression vec3 * (var_ref v) (swiz w (var_ref u)))) +(return (var_ref m)))) + + (signature mat4 + (parameters + (declare (in) vec4 u) + (declare (in) vec4 v)) + ((declare () mat4 m) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (0))) (expression vec4 * (var_ref v) (swiz x (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (1))) (expression vec4 * (var_ref v) (swiz y (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (2))) (expression vec4 * (var_ref v) (swiz z (var_ref u)))) + (assign (constant bool (1)) (array_ref (var_ref m) (constant int (3))) (expression vec4 * (var_ref v) (swiz w (var_ref u)))) +(return (var_ref m)))) +)) + diff --git a/builtins/tools/generate_outerProductGLSL.py b/builtins/tools/generate_outerProductGLSL.py new file mode 100755 index 00000000000..48fb72197c3 --- /dev/null +++ b/builtins/tools/generate_outerProductGLSL.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +def gen(x, y): + type = "mat" + str(x) + if x != y: + type = type + "x" + str(y) + print type + " outerProduct(vec" + str(x) + " u, vec" + str(y) + " v)\n{" + print " " + type + " m;" + + for i in range(x): + print " m[" + str(i) + "] = v * u[" + str(i) + "];" + print " return m;\n}" + +print "#version 120" +gen(2,2) +gen(2,3) # mat2x3 means 2 columns, 3 rows +gen(2,4) +gen(3,2) +gen(3,3) +gen(3,4) +gen(4,2) +gen(4,3) +gen(4,4)