support for GLSL 1.20 non-square matrices
authorBrian <brian@nostromo.localnet.net>
Sun, 8 Apr 2007 22:47:32 +0000 (16:47 -0600)
committerBrian <brian@nostromo.localnet.net>
Sun, 8 Apr 2007 22:47:32 +0000 (16:47 -0600)
src/mesa/shader/slang/library/slang_shader.syn
src/mesa/shader/slang/library/slang_shader_syn.h
src/mesa/shader/slang/slang_codegen.c
src/mesa/shader/slang/slang_compile.c
src/mesa/shader/slang/slang_compile_variable.c
src/mesa/shader/slang/slang_print.c
src/mesa/shader/slang/slang_storage.c
src/mesa/shader/slang/slang_typeinfo.c
src/mesa/shader/slang/slang_typeinfo.h

index 9389869da2361af9b26a1e6f2aed5624435f89d4..1764d1ae6898b370ddab8e640901243549d0b2fc 100644 (file)
 .emtcode TYPE_SPECIFIER_STRUCT                      24
 .emtcode TYPE_SPECIFIER_TYPENAME                    25
 
+/* OpenGL 2.1 */
+.emtcode TYPE_SPECIFIER_MAT23                       26
+.emtcode TYPE_SPECIFIER_MAT32                       27
+.emtcode TYPE_SPECIFIER_MAT24                       28
+.emtcode TYPE_SPECIFIER_MAT42                       29
+.emtcode TYPE_SPECIFIER_MAT34                       30
+.emtcode TYPE_SPECIFIER_MAT43                       31
+
+
 /* structure field */
 .emtcode FIELD_NONE                                 0
 .emtcode FIELD_NEXT                                 1
@@ -880,6 +889,12 @@ type_qualifier
                                           | "mat2"
                                           | "mat3"
                                           | "mat4"
+                                          | "mat2x3"
+                                          | "mat3x2"
+                                          | "mat2x4"
+                                          | "mat4x2"
+                                          | "mat3x4"
+                                          | "mat4x3"
                                           | "sampler1D"
                                           | "sampler2D"
                                           | "sampler3D"
@@ -908,6 +923,12 @@ type_specifier_space
     "mat2" .emit TYPE_SPECIFIER_MAT2 .or
     "mat3" .emit TYPE_SPECIFIER_MAT3 .or
     "mat4" .emit TYPE_SPECIFIER_MAT4 .or
+    "mat2x3" .emit TYPE_SPECIFIER_MAT23 .or
+    "mat3x2" .emit TYPE_SPECIFIER_MAT32 .or
+    "mat2x4" .emit TYPE_SPECIFIER_MAT24 .or
+    "mat4x2" .emit TYPE_SPECIFIER_MAT42 .or
+    "mat3x4" .emit TYPE_SPECIFIER_MAT34 .or
+    "mat4x3" .emit TYPE_SPECIFIER_MAT43 .or
     "sampler1D" .emit TYPE_SPECIFIER_SAMPLER1D .or
     "sampler2D" .emit TYPE_SPECIFIER_SAMPLER2D .or
     "sampler3D" .emit TYPE_SPECIFIER_SAMPLER3D .or
index 4863feda5bd0a6b578343bfe674a586519377938..fe37adcac4a4c52f23d3e65ceb9a1dda507e40e6 100644 (file)
 ".emtcode TYPE_SPECIFIER_SAMPLER2DRECTSHADOW 23\n"
 ".emtcode TYPE_SPECIFIER_STRUCT 24\n"
 ".emtcode TYPE_SPECIFIER_TYPENAME 25\n"
+".emtcode TYPE_SPECIFIER_MAT23 26\n"
+".emtcode TYPE_SPECIFIER_MAT32 27\n"
+".emtcode TYPE_SPECIFIER_MAT24 28\n"
+".emtcode TYPE_SPECIFIER_MAT42 29\n"
+".emtcode TYPE_SPECIFIER_MAT34 30\n"
+".emtcode TYPE_SPECIFIER_MAT43 31\n"
 ".emtcode FIELD_NONE 0\n"
 ".emtcode FIELD_NEXT 1\n"
 ".emtcode FIELD_ARRAY 2\n"
 " \"mat2\" .emit TYPE_SPECIFIER_MAT2 .or\n"
 " \"mat3\" .emit TYPE_SPECIFIER_MAT3 .or\n"
 " \"mat4\" .emit TYPE_SPECIFIER_MAT4 .or\n"
+" \"mat2x3\" .emit TYPE_SPECIFIER_MAT23 .or\n"
+" \"mat3x2\" .emit TYPE_SPECIFIER_MAT32 .or\n"
+" \"mat2x4\" .emit TYPE_SPECIFIER_MAT24 .or\n"
+" \"mat4x2\" .emit TYPE_SPECIFIER_MAT42 .or\n"
+" \"mat3x4\" .emit TYPE_SPECIFIER_MAT34 .or\n"
+" \"mat4x3\" .emit TYPE_SPECIFIER_MAT43 .or\n"
 " \"sampler1D\" .emit TYPE_SPECIFIER_SAMPLER1D .or\n"
 " \"sampler2D\" .emit TYPE_SPECIFIER_SAMPLER2D .or\n"
 " \"sampler3D\" .emit TYPE_SPECIFIER_SAMPLER3D .or\n"
index 0c14e64cf97d9c7966a22985f3670ed0c8d2896e..a25037cd61c3ac566611a000d744210494310f1a 100644 (file)
@@ -143,6 +143,15 @@ _slang_sizeof_type_specifier(const slang_type_specifier *spec)
       return 3 * 3;
    case SLANG_SPEC_MAT4:
       return 4 * 4;
+   case SLANG_SPEC_MAT23:
+   case SLANG_SPEC_MAT32:
+      return 2 * 3;
+   case SLANG_SPEC_MAT24:
+   case SLANG_SPEC_MAT42:
+      return 2 * 4;
+   case SLANG_SPEC_MAT34:
+   case SLANG_SPEC_MAT43:
+      return 3 * 4;
    case SLANG_SPEC_SAMPLER1D:
    case SLANG_SPEC_SAMPLER2D:
    case SLANG_SPEC_SAMPLER3D:
index 85dd158698597aea82450ca07a74f9e2716a7f51..65522ae251ef671576e092c4a4e2d101c4622871 100644 (file)
@@ -491,6 +491,13 @@ parse_type_qualifier(slang_parse_ctx * C, slang_type_qualifier * qual)
 #define TYPE_SPECIFIER_SAMPLER2DRECTSHADOW 23
 #define TYPE_SPECIFIER_STRUCT 24
 #define TYPE_SPECIFIER_TYPENAME 25
+#define TYPE_SPECIFIER_MAT23 26
+#define TYPE_SPECIFIER_MAT32 27
+#define TYPE_SPECIFIER_MAT24 28
+#define TYPE_SPECIFIER_MAT42 29
+#define TYPE_SPECIFIER_MAT34 30
+#define TYPE_SPECIFIER_MAT43 31
+
 
 static int
 parse_type_specifier(slang_parse_ctx * C, slang_output_ctx * O,
@@ -545,6 +552,24 @@ parse_type_specifier(slang_parse_ctx * C, slang_output_ctx * O,
    case TYPE_SPECIFIER_MAT4:
       spec->type = SLANG_SPEC_MAT4;
       break;
+   case TYPE_SPECIFIER_MAT23:
+      spec->type = SLANG_SPEC_MAT23;
+      break;
+   case TYPE_SPECIFIER_MAT32:
+      spec->type = SLANG_SPEC_MAT32;
+      break;
+   case TYPE_SPECIFIER_MAT24:
+      spec->type = SLANG_SPEC_MAT24;
+      break;
+   case TYPE_SPECIFIER_MAT42:
+      spec->type = SLANG_SPEC_MAT42;
+      break;
+   case TYPE_SPECIFIER_MAT34:
+      spec->type = SLANG_SPEC_MAT34;
+      break;
+   case TYPE_SPECIFIER_MAT43:
+      spec->type = SLANG_SPEC_MAT43;
+      break;
    case TYPE_SPECIFIER_SAMPLER1D:
       spec->type = SLANG_SPEC_SAMPLER1D;
       break;
index 9a0b985507d02aacc2b931d62e01798f88718d2a..819b4f901b3b486101c5d2eea0c200cff0677b58 100644 (file)
@@ -56,6 +56,12 @@ static const type_specifier_type_name type_specifier_type_names[] = {
    {"mat2", SLANG_SPEC_MAT2},
    {"mat3", SLANG_SPEC_MAT3},
    {"mat4", SLANG_SPEC_MAT4},
+   {"mat2x3", SLANG_SPEC_MAT23},
+   {"mat3x2", SLANG_SPEC_MAT32},
+   {"mat2x4", SLANG_SPEC_MAT24},
+   {"mat4x2", SLANG_SPEC_MAT42},
+   {"mat3x4", SLANG_SPEC_MAT34},
+   {"mat4x3", SLANG_SPEC_MAT43},
    {"sampler1D", SLANG_SPEC_SAMPLER1D},
    {"sampler2D", SLANG_SPEC_SAMPLER2D},
    {"sampler3D", SLANG_SPEC_SAMPLER3D},
@@ -367,6 +373,18 @@ gl_type_from_specifier(const slang_type_specifier * type)
       return GL_FLOAT_MAT3_ARB;
    case SLANG_SPEC_MAT4:
       return GL_FLOAT_MAT4_ARB;
+   case SLANG_SPEC_MAT23:
+      return GL_FLOAT_MAT2x3_ARB;
+   case SLANG_SPEC_MAT32:
+      return GL_FLOAT_MAT3x2_ARB;
+   case SLANG_SPEC_MAT24:
+      return GL_FLOAT_MAT2x4_ARB;
+   case SLANG_SPEC_MAT42:
+      return GL_FLOAT_MAT4x2_ARB;
+   case SLANG_SPEC_MAT34:
+      return GL_FLOAT_MAT3x4_ARB;
+   case SLANG_SPEC_MAT43:
+      return GL_FLOAT_MAT4x3_ARB;
    case SLANG_SPEC_SAMPLER1D:
       return GL_SAMPLER_1D_ARB;
    case SLANG_SPEC_SAMPLER2D:
index 90e6fe2a965ef9ff6becb419c54cb10903d21f03..f3e127cb13f0ad1337f51348d2fa0101746f7ce1 100644 (file)
@@ -101,6 +101,24 @@ print_type(const slang_fully_specified_type *t)
    case SLANG_SPEC_MAT4:
       printf("mat4");
       break;
+   case SLANG_SPEC_MAT23:
+      printf("mat2x3");
+      break;
+   case SLANG_SPEC_MAT32:
+      printf("mat3x2");
+      break;
+   case SLANG_SPEC_MAT24:
+      printf("mat2x4");
+      break;
+   case SLANG_SPEC_MAT42:
+      printf("mat4x2");
+      break;
+   case SLANG_SPEC_MAT34:
+      printf("mat3x4");
+      break;
+   case SLANG_SPEC_MAT43:
+      printf("mat4x3");
+      break;
    case SLANG_SPEC_SAMPLER1D:
       printf("sampler1D");
       break;
index 6d6a6d9ac47b80bd33cc04a2fb212b4dee8d30a9..ecd60481b6b25f2e89f4868f1c26ea65b8ec1188 100644 (file)
@@ -105,13 +105,13 @@ aggregate_vector(slang_storage_aggregate * agg, slang_storage_type basic_type,
 
 static GLboolean
 aggregate_matrix(slang_storage_aggregate * agg, slang_storage_type basic_type,
-                 GLuint dimension)
+                 GLuint columns, GLuint rows)
 {
    slang_storage_array *arr = slang_storage_aggregate_push_new(agg);
    if (arr == NULL)
       return GL_FALSE;
    arr->type = SLANG_STORE_AGGREGATE;
-   arr->length = dimension;
+   arr->length = columns;
    arr->aggregate =
       (slang_storage_aggregate *)
       slang_alloc_malloc(sizeof(slang_storage_aggregate));
@@ -122,7 +122,7 @@ aggregate_matrix(slang_storage_aggregate * agg, slang_storage_type basic_type,
       arr->aggregate = NULL;
       return GL_FALSE;
    }
-   if (!aggregate_vector(arr->aggregate, basic_type, dimension))
+   if (!aggregate_vector(arr->aggregate, basic_type, rows))
       return GL_FALSE;
    return GL_TRUE;
 }
@@ -180,11 +180,25 @@ _slang_aggregate_variable(slang_storage_aggregate * agg,
    case SLANG_SPEC_VEC4:
       return aggregate_vector(agg, SLANG_STORE_FLOAT, 4);
    case SLANG_SPEC_MAT2:
-      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2);
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2, 2);
    case SLANG_SPEC_MAT3:
-      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3);
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3, 3);
    case SLANG_SPEC_MAT4:
-      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4);
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4, 4);
+
+   case SLANG_SPEC_MAT23:
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2, 3);
+   case SLANG_SPEC_MAT32:
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3, 2);
+   case SLANG_SPEC_MAT24:
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 2, 4);
+   case SLANG_SPEC_MAT42:
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4, 2);
+   case SLANG_SPEC_MAT34:
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 3, 4);
+   case SLANG_SPEC_MAT43:
+      return aggregate_matrix(agg, SLANG_STORE_FLOAT, 4, 3);
+
    case SLANG_SPEC_SAMPLER1D:
    case SLANG_SPEC_SAMPLER2D:
    case SLANG_SPEC_SAMPLER3D:
index fef5575631b7379f11b4562ed2ab5008499b6f25..2af8eb736bb76928e03811db8c7df80fe7defc6b 100644 (file)
@@ -815,6 +815,12 @@ _slang_type_is_matrix(slang_type_specifier_type ty)
    case SLANG_SPEC_MAT2:
    case SLANG_SPEC_MAT3:
    case SLANG_SPEC_MAT4:
+   case SLANG_SPEC_MAT23:
+   case SLANG_SPEC_MAT32:
+   case SLANG_SPEC_MAT24:
+   case SLANG_SPEC_MAT42:
+   case SLANG_SPEC_MAT34:
+   case SLANG_SPEC_MAT43:
       return GL_TRUE;
    default:
       return GL_FALSE;
@@ -847,7 +853,8 @@ _slang_type_is_vector(slang_type_specifier_type ty)
 
 
 /**
- * Given a vector type, return the type of the vector's elements
+ * Given a vector type, return the type of the vector's elements.
+ * For a matrix, return the type of the columns.
  */
 slang_type_specifier_type
 _slang_type_base(slang_type_specifier_type ty)
@@ -874,6 +881,18 @@ _slang_type_base(slang_type_specifier_type ty)
       return SLANG_SPEC_VEC3;
    case SLANG_SPEC_MAT4:
       return SLANG_SPEC_VEC4;
+   case SLANG_SPEC_MAT23:
+      return SLANG_SPEC_VEC3;
+   case SLANG_SPEC_MAT32:
+      return SLANG_SPEC_VEC2;
+   case SLANG_SPEC_MAT24:
+      return SLANG_SPEC_VEC4;
+   case SLANG_SPEC_MAT42:
+      return SLANG_SPEC_VEC2;
+   case SLANG_SPEC_MAT34:
+      return SLANG_SPEC_VEC4;
+   case SLANG_SPEC_MAT43:
+      return SLANG_SPEC_VEC3;
    default:
       return SLANG_SPEC_VOID;
    }
@@ -881,7 +900,8 @@ _slang_type_base(slang_type_specifier_type ty)
 
 
 /**
- * Return the dimensionality of a vector or matrix type.
+ * Return the dimensionality of a vector, or for a matrix, return number
+ * of columns.
  */
 GLuint
 _slang_type_dim(slang_type_specifier_type ty)
@@ -906,6 +926,20 @@ _slang_type_dim(slang_type_specifier_type ty)
    case SLANG_SPEC_BVEC4:
    case SLANG_SPEC_MAT4:
       return 4;
+
+   case SLANG_SPEC_MAT23:
+      return 2;
+   case SLANG_SPEC_MAT32:
+      return 3;
+   case SLANG_SPEC_MAT24:
+      return 2;
+   case SLANG_SPEC_MAT42:
+      return 4;
+   case SLANG_SPEC_MAT34:
+      return 3;
+   case SLANG_SPEC_MAT43:
+      return 4;
+
    default:
       return 0;
    }
index c815c9914a98bc05e13d27c172ef3b6754865e28..ffffd09a5c29c28113f4bb7441c8cd38aeb70e5b 100644 (file)
@@ -108,6 +108,12 @@ typedef enum slang_type_specifier_type_
    SLANG_SPEC_MAT2,
    SLANG_SPEC_MAT3,
    SLANG_SPEC_MAT4,
+   SLANG_SPEC_MAT23,
+   SLANG_SPEC_MAT32,
+   SLANG_SPEC_MAT24,
+   SLANG_SPEC_MAT42,
+   SLANG_SPEC_MAT34,
+   SLANG_SPEC_MAT43,
    SLANG_SPEC_SAMPLER1D,
    SLANG_SPEC_SAMPLER2D,
    SLANG_SPEC_SAMPLER3D,