From: Kenneth Graunke Date: Wed, 9 Jun 2010 22:17:41 +0000 (-0700) Subject: Implement matrixCompMult builtin - the last of the 110 builtins. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0c8ffadc8cc0b0497873a8ce46ae4e1ae03eee54;p=mesa.git Implement matrixCompMult builtin - the last of the 110 builtins. --- diff --git a/builtin_function.cpp b/builtin_function.cpp index 4ee43df5dc2..7072af25719 100644 --- a/builtin_function.cpp +++ b/builtin_function.cpp @@ -1165,6 +1165,41 @@ static const char *builtins_110_log2 = { "))\n" }; +static const char *builtins_110_matrixCompMult = { + "((function matrixCompMult\n" + " (signature mat2\n" + " (parameters\n" + " (declare (in) mat2 x)\n" + " (declare (in) mat2 y))\n" + " ((declare () mat2 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat3\n" + " (parameters\n" + " (declare (in) mat3 x)\n" + " (declare (in) mat3 y))\n" + " ((declare () mat3 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat4\n" + " (parameters\n" + " (declare (in) mat4 x)\n" + " (declare (in) mat4 y))\n" + " ((declare () mat4 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (3))) (expression vec4 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) \n" + "(return (var_ref z))))\n" + "))\n" + "\n" +}; + static const char *builtins_110_max = { "((function max\n" " (signature float\n" @@ -2473,6 +2508,7 @@ static const char *functions_for_110 [] = { builtins_110_lessThanEqual, builtins_110_log, builtins_110_log2, + builtins_110_matrixCompMult, builtins_110_max, builtins_110_min, builtins_110_mix, @@ -2709,6 +2745,76 @@ static const char *functions_for_110_vs [] = { builtins_110_vs_ftransform, }; +/* 120 builtins */ + +static const char *builtins_120_matrixCompMult = { + "((function matrixCompMult\n" + " (signature mat2x3\n" + " (parameters\n" + " (declare (in) mat2x3 x)\n" + " (declare (in) mat2x3 y))\n" + " ((declare () mat2x3 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat3x2\n" + " (parameters\n" + " (declare (in) mat3x2 x)\n" + " (declare (in) mat3x2 y))\n" + " ((declare () mat3x2 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat2x4\n" + " (parameters\n" + " (declare (in) mat2x4 x)\n" + " (declare (in) mat2x4 y))\n" + " ((declare () mat2x4 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat4x2\n" + " (parameters\n" + " (declare (in) mat4x2 x)\n" + " (declare (in) mat4x2 y))\n" + " ((declare () mat4x2 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (3))) (expression vec2 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat3x4\n" + " (parameters\n" + " (declare (in) mat3x4 x)\n" + " (declare (in) mat3x4 y))\n" + " ((declare () mat3x4 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) \n" + "(return (var_ref z))))\n" + "\n" + " (signature mat4x3\n" + " (parameters\n" + " (declare (in) mat4x3 x)\n" + " (declare (in) mat4x3 y))\n" + " ((declare () mat4x3 z)\n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) \n" + " (assign (constant bool (1)) (array_ref (var_ref z) (constant int (3))) (expression vec3 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) \n" + "(return (var_ref z))))\n" + "))\n" +}; + +static const char *functions_for_120 [] = { + builtins_120_matrixCompMult, +}; + /* 130 builtins */ static const char *builtins_130_equal = { @@ -4199,6 +4305,11 @@ _mesa_glsl_initialize_functions(exec_list *instructions, functions_for_110_vs, sizeof(functions_for_110_vs) / sizeof(const char *)); + if (state->language_version >= 120) + read_builtins(state, instructions, + functions_for_120, + sizeof(functions_for_120) / sizeof(const char *)); + if (state->language_version >= 130) read_builtins(state, instructions, functions_for_130, diff --git a/builtins/110/matrixCompMult b/builtins/110/matrixCompMult new file mode 100644 index 00000000000..cb5a2cb1f7b --- /dev/null +++ b/builtins/110/matrixCompMult @@ -0,0 +1,32 @@ +((function matrixCompMult + (signature mat2 + (parameters + (declare (in) mat2 x) + (declare (in) mat2 y)) + ((declare () mat2 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) +(return (var_ref z)))) + + (signature mat3 + (parameters + (declare (in) mat3 x) + (declare (in) mat3 y)) + ((declare () mat3 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) +(return (var_ref z)))) + + (signature mat4 + (parameters + (declare (in) mat4 x) + (declare (in) mat4 y)) + ((declare () mat4 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (3))) (expression vec4 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) +(return (var_ref z)))) +)) + diff --git a/builtins/120/matrixCompMult b/builtins/120/matrixCompMult new file mode 100644 index 00000000000..69331e26525 --- /dev/null +++ b/builtins/120/matrixCompMult @@ -0,0 +1,61 @@ +((function matrixCompMult + (signature mat2x3 + (parameters + (declare (in) mat2x3 x) + (declare (in) mat2x3 y)) + ((declare () mat2x3 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) +(return (var_ref z)))) + + (signature mat3x2 + (parameters + (declare (in) mat3x2 x) + (declare (in) mat3x2 y)) + ((declare () mat3x2 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) +(return (var_ref z)))) + + (signature mat2x4 + (parameters + (declare (in) mat2x4 x) + (declare (in) mat2x4 y)) + ((declare () mat2x4 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) +(return (var_ref z)))) + + (signature mat4x2 + (parameters + (declare (in) mat4x2 x) + (declare (in) mat4x2 y)) + ((declare () mat4x2 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec2 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec2 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec2 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (3))) (expression vec2 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) +(return (var_ref z)))) + + (signature mat3x4 + (parameters + (declare (in) mat3x4 x) + (declare (in) mat3x4 y)) + ((declare () mat3x4 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec4 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec4 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec4 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) +(return (var_ref z)))) + + (signature mat4x3 + (parameters + (declare (in) mat4x3 x) + (declare (in) mat4x3 y)) + ((declare () mat4x3 z) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (0))) (expression vec3 * (array_ref (var_ref x) (constant int (0))) (array_ref (var_ref y) (constant int (0))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (1))) (expression vec3 * (array_ref (var_ref x) (constant int (1))) (array_ref (var_ref y) (constant int (1))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (2))) (expression vec3 * (array_ref (var_ref x) (constant int (2))) (array_ref (var_ref y) (constant int (2))))) + (assign (constant bool (1)) (array_ref (var_ref z) (constant int (3))) (expression vec3 * (array_ref (var_ref x) (constant int (3))) (array_ref (var_ref y) (constant int (3))))) +(return (var_ref z)))) +)) diff --git a/builtins/tools/generate_matrixCompMultGLSL.py b/builtins/tools/generate_matrixCompMultGLSL.py new file mode 100755 index 00000000000..391ad110d37 --- /dev/null +++ b/builtins/tools/generate_matrixCompMultGLSL.py @@ -0,0 +1,28 @@ +#!/usr/bin/python + +def gen_matrix(x, y = 0): + if y == 0: + y = x + type = "mat" + str(x) + if x != y: + type = type + "x" + str(y) + print type + " matrixCompMult(" + type + " x, " + type + " y)\n{" + print " " + type + " z;" + + for i in range(x): + print " z[" + str(i) + "] = x[" + str(i) + "] * y[" + str(i) + "];" + print " return z;\n}" + +print "#version 120" +# 1.10 +gen_matrix(2) +gen_matrix(3) +gen_matrix(4) + +# 1.20 +gen_matrix(2,3) # mat2x3 means 2 columns, 3 rows +gen_matrix(3,2) +gen_matrix(2,4) +gen_matrix(4,2) +gen_matrix(3,4) +gen_matrix(4,3)