summaryrefslogtreecommitdiff
path: root/src/mesa/shader/slang/slang_assemble_typeinfo.c
diff options
context:
space:
mode:
authorMichal Krol <mjkrol@gmail.org>2006-02-13 11:38:37 +0000
committerMichal Krol <mjkrol@gmail.org>2006-02-13 11:38:37 +0000
commit02eb9acc5e4307db09662592951ef44319a0cda5 (patch)
tree585a539ed6d6775801dcc9e685759521680da9f9 /src/mesa/shader/slang/slang_assemble_typeinfo.c
parent44e9ccc708bb0a92dfeaf038ded60295dfe2d3ae (diff)
Get it running for ARB_vertex_shader.
Add experimental print functions to builtin library. Some functionality missing: - automatic arrays; - general constructors; - local variable initialization; - texture sampling and noise; - semantic error checking; - function prototypes.
Diffstat (limited to 'src/mesa/shader/slang/slang_assemble_typeinfo.c')
-rw-r--r--src/mesa/shader/slang/slang_assemble_typeinfo.c367
1 files changed, 215 insertions, 152 deletions
diff --git a/src/mesa/shader/slang/slang_assemble_typeinfo.c b/src/mesa/shader/slang/slang_assemble_typeinfo.c
index f550556763..778ba04ced 100644
--- a/src/mesa/shader/slang/slang_assemble_typeinfo.c
+++ b/src/mesa/shader/slang/slang_assemble_typeinfo.c
@@ -34,20 +34,37 @@
/* slang_assembly_typeinfo */
-void slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
+int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
{
- slang_type_specifier_construct (&ti->spec);
+ if (!slang_type_specifier_construct (&ti->spec))
+ return 0;
+ ti->array_size = NULL;
+ return 1;
}
void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
{
slang_type_specifier_destruct (&ti->spec);
+ /* do not free ti->array_size */
}
/* _slang_typeof_operation() */
+static int typeof_existing_function (const char *name, slang_operation *params,
+ unsigned int num_params, slang_assembly_name_space *space, slang_type_specifier *spec,
+ slang_atom_pool *atoms)
+{
+ slang_atom atom;
+ int exists;
+
+ atom = slang_atom_pool_atom (atoms, name);
+ if (!_slang_typeof_function (atom, params, num_params, space, spec, &exists, atoms))
+ return 0;
+ return exists;
+}
+
int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,
- slang_assembly_typeinfo *ti)
+ slang_assembly_typeinfo *ti, slang_atom_pool *atoms)
{
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -77,7 +94,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_divassign:
case slang_oper_preincrement:
case slang_oper_predecrement:
- if (!_slang_typeof_operation (op->children, space, ti))
+ if (!_slang_typeof_operation (op->children, space, ti, atoms))
return 0;
break;
case slang_oper_literal_bool:
@@ -103,17 +120,18 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
{
slang_variable *var;
- var = _slang_locate_variable (op->locals, op->identifier, 1);
+ var = _slang_locate_variable (op->locals, op->a_id, 1);
if (var == NULL)
return 0;
if (!slang_type_specifier_copy (&ti->spec, &var->type.specifier))
return 0;
ti->can_be_referenced = 1;
+ ti->array_size = var->array_size;
}
break;
case slang_oper_sequence:
/* TODO: check [0] and [1] if they match */
- if (!_slang_typeof_operation (op->children + 1, space, ti))
+ if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -126,7 +144,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/*case slang_oper_andassign:*/
case slang_oper_select:
/* TODO: check [1] and [2] if they match */
- if (!_slang_typeof_operation (op->children + 1, space, ti))
+ if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -137,107 +155,61 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/*case slang_oper_lshift:*/
/*case slang_oper_rshift:*/
case slang_oper_add:
- {
- int exists;
- if (!_slang_typeof_function ("+", op->children, 2, space, &ti->spec, &exists))
- return 0;
- if (!exists)
- return 0;
- }
+ if (!typeof_existing_function ("+", op->children, 2, space, &ti->spec, atoms))
+ return 0;
break;
case slang_oper_subtract:
- {
- int exists;
- if (!_slang_typeof_function ("-", op->children, 2, space, &ti->spec, &exists))
- return 0;
- if (!exists)
- return 0;
- }
+ if (!typeof_existing_function ("-", op->children, 2, space, &ti->spec, atoms))
+ return 0;
break;
case slang_oper_multiply:
- {
- int exists;
- if (!_slang_typeof_function ("*", op->children, 2, space, &ti->spec, &exists))
- return 0;
- if (!exists)
- return 0;
- }
+ if (!typeof_existing_function ("*", op->children, 2, space, &ti->spec, atoms))
+ return 0;
break;
case slang_oper_divide:
- {
- int exists;
- if (!_slang_typeof_function ("/", op->children, 2, space, &ti->spec, &exists))
- return 0;
- if (!exists)
- return 0;
- }
+ if (!typeof_existing_function ("/", op->children, 2, space, &ti->spec, atoms))
+ return 0;
break;
/*case slang_oper_modulus:*/
case slang_oper_plus:
- {
- int exists;
- if (!_slang_typeof_function ("+", op->children, 1, space, &ti->spec, &exists))
- return 0;
- if (!exists)
- return 0;
- }
+ if (!_slang_typeof_operation (op->children, space, ti, atoms))
+ return 0;
+ ti->can_be_referenced = 0;
+ ti->is_swizzled = 0;
break;
case slang_oper_minus:
- {
- int exists;
- if (!_slang_typeof_function ("-", op->children, 1, space, &ti->spec, &exists))
- return 0;
- if (!exists)
- return 0;
- }
+ if (!typeof_existing_function ("-", op->children, 1, space, &ti->spec, atoms))
+ return 0;
break;
/*case slang_oper_complement:*/
case slang_oper_subscript:
{
slang_assembly_typeinfo _ti;
- slang_assembly_typeinfo_construct (&_ti);
- if (!_slang_typeof_operation (op->children, space, &_ti))
+
+ if (!slang_assembly_typeinfo_construct (&_ti))
+ return 0;
+ if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
ti->can_be_referenced = _ti.can_be_referenced;
- switch (_ti.spec.type)
+ if (_ti.spec.type == slang_spec_array)
{
- case slang_spec_bvec2:
- case slang_spec_bvec3:
- case slang_spec_bvec4:
- ti->spec.type = slang_spec_bool;
- break;
- case slang_spec_ivec2:
- case slang_spec_ivec3:
- case slang_spec_ivec4:
- ti->spec.type = slang_spec_int;
- break;
- case slang_spec_vec2:
- case slang_spec_vec3:
- case slang_spec_vec4:
- ti->spec.type = slang_spec_float;
- break;
- case slang_spec_mat2:
- ti->spec.type = slang_spec_vec2;
- break;
- case slang_spec_mat3:
- ti->spec.type = slang_spec_vec3;
- break;
- case slang_spec_mat4:
- ti->spec.type = slang_spec_vec4;
- break;
- case slang_spec_array:
if (!slang_type_specifier_copy (&ti->spec, _ti.spec._array))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
- break;
- default:
- slang_assembly_typeinfo_destruct (&_ti);
- return 0;
+ }
+ else
+ {
+ if (!_slang_type_is_vector (_ti.spec.type) && !_slang_type_is_matrix (_ti.spec.type))
+ {
+ slang_assembly_typeinfo_destruct (&_ti);
+ return 0;
+ }
+ ti->spec.type = _slang_type_base (_ti.spec.type);
}
slang_assembly_typeinfo_destruct (&_ti);
}
@@ -245,12 +217,13 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_call:
{
int exists;
- if (!_slang_typeof_function (op->identifier, op->children, op->num_children, space,
- &ti->spec, &exists))
+
+ if (!_slang_typeof_function (op->a_id, op->children, op->num_children, space, &ti->spec,
+ &exists, atoms))
return 0;
if (!exists)
{
- slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);
+/* slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);
if (s != NULL)
{
ti->spec.type = slang_spec_struct;
@@ -267,9 +240,12 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
return 0;
}
else
- {
- slang_type_specifier_type type = slang_type_specifier_type_from_string (
- op->identifier);
+*/ {
+ const char *name;
+ slang_type_specifier_type type;
+
+ name = slang_atom_pool_id (atoms, op->a_id);
+ type = slang_type_specifier_type_from_string (name);
if (type == slang_spec_void)
return 0;
ti->spec.type = type;
@@ -280,16 +256,19 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_field:
{
slang_assembly_typeinfo _ti;
- slang_assembly_typeinfo_construct (&_ti);
- if (!_slang_typeof_operation (op->children, space, &_ti))
+
+ if (!slang_assembly_typeinfo_construct (&_ti))
+ return 0;
+ if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
if (_ti.spec.type == slang_spec_struct)
{
- slang_variable *field = _slang_locate_variable (_ti.spec._struct->fields,
- op->identifier, 0);
+ slang_variable *field;
+
+ field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, 0);
if (field == NULL)
{
slang_assembly_typeinfo_destruct (&_ti);
@@ -300,112 +279,96 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
+ ti->can_be_referenced = _ti.can_be_referenced;
}
else
{
unsigned int rows;
- switch (_ti.spec.type)
+ const char *swizzle;
+ slang_type_specifier_type base;
+
+ /* determine the swizzle of the field expression */
+ if (!_slang_type_is_vector (_ti.spec.type))
{
- case slang_spec_vec2:
- case slang_spec_ivec2:
- case slang_spec_bvec2:
- rows = 2;
- break;
- case slang_spec_vec3:
- case slang_spec_ivec3:
- case slang_spec_bvec3:
- rows = 3;
- break;
- case slang_spec_vec4:
- case slang_spec_ivec4:
- case slang_spec_bvec4:
- rows = 4;
- break;
- default:
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
- if (!_slang_is_swizzle (op->identifier, rows, &ti->swz))
+ rows = _slang_type_dim (_ti.spec.type);
+ swizzle = slang_atom_pool_id (atoms, op->a_id);
+ if (!_slang_is_swizzle (swizzle, rows, &ti->swz))
+ {
+ slang_assembly_typeinfo_destruct (&_ti);
return 0;
+ }
ti->is_swizzled = 1;
ti->can_be_referenced = _ti.can_be_referenced && _slang_is_swizzle_mask (&ti->swz,
rows);
if (_ti.is_swizzled)
{
slang_swizzle swz;
+
+ /* swizzle the swizzle */
_slang_multiply_swizzles (&swz, &_ti.swz, &ti->swz);
ti->swz = swz;
}
- switch (_ti.spec.type)
+ base = _slang_type_base (_ti.spec.type);
+ switch (ti->swz.num_components)
{
- case slang_spec_vec2:
- case slang_spec_vec3:
- case slang_spec_vec4:
- switch (ti->swz.num_components)
+ case 1:
+ ti->spec.type = base;
+ break;
+ case 2:
+ switch (base)
{
- case 1:
- ti->spec.type = slang_spec_float;
- break;
- case 2:
+ case slang_spec_float:
ti->spec.type = slang_spec_vec2;
break;
- case 3:
- ti->spec.type = slang_spec_vec3;
+ case slang_spec_int:
+ ti->spec.type = slang_spec_ivec2;
break;
- case 4:
- ti->spec.type = slang_spec_vec4;
+ case slang_spec_bool:
+ ti->spec.type = slang_spec_bvec2;
break;
}
break;
- case slang_spec_ivec2:
- case slang_spec_ivec3:
- case slang_spec_ivec4:
- switch (ti->swz.num_components)
+ case 3:
+ switch (base)
{
- case 1:
- ti->spec.type = slang_spec_int;
- break;
- case 2:
- ti->spec.type = slang_spec_ivec2;
+ case slang_spec_float:
+ ti->spec.type = slang_spec_vec3;
break;
- case 3:
+ case slang_spec_int:
ti->spec.type = slang_spec_ivec3;
break;
- case 4:
- ti->spec.type = slang_spec_ivec4;
+ case slang_spec_bool:
+ ti->spec.type = slang_spec_bvec3;
break;
}
break;
- case slang_spec_bvec2:
- case slang_spec_bvec3:
- case slang_spec_bvec4:
- switch (ti->swz.num_components)
+ case 4:
+ switch (base)
{
- case 1:
- ti->spec.type = slang_spec_bool;
- break;
- case 2:
- ti->spec.type = slang_spec_bvec2;
+ case slang_spec_float:
+ ti->spec.type = slang_spec_vec4;
break;
- case 3:
- ti->spec.type = slang_spec_bvec3;
+ case slang_spec_int:
+ ti->spec.type = slang_spec_ivec4;
break;
- case 4:
+ case slang_spec_bool:
ti->spec.type = slang_spec_bvec4;
break;
}
break;
default:
- break;
+ break;
}
}
slang_assembly_typeinfo_destruct (&_ti);
- return 1;
}
break;
case slang_oper_postincrement:
case slang_oper_postdecrement:
- if (!_slang_typeof_operation (op->children, space, ti))
+ if (!_slang_typeof_operation (op->children, space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -418,13 +381,113 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/* _slang_typeof_function() */
-int _slang_typeof_function (const char *name, slang_operation *params, unsigned int num_params,
- slang_assembly_name_space *space, slang_type_specifier *spec, int *exists)
+int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
+ slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *atoms)
{
- slang_function *fun = _slang_locate_function (name, params, num_params, space);
+ slang_function *fun;
+
+ fun = _slang_locate_function (space->funcs, a_name, params, num_params, space, atoms);
*exists = fun != NULL;
if (fun == NULL)
return 1;
return slang_type_specifier_copy (spec, &fun->header.type.specifier);
}
+/* _slang_type_is_matrix() */
+
+int _slang_type_is_matrix (slang_type_specifier_type ty)
+{
+ switch (ty)
+ {
+ case slang_spec_mat2:
+ case slang_spec_mat3:
+ case slang_spec_mat4:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+/* _slang_type_is_vector() */
+
+int _slang_type_is_vector (slang_type_specifier_type ty)
+{
+ switch (ty)
+ {
+ case slang_spec_vec2:
+ case slang_spec_vec3:
+ case slang_spec_vec4:
+ case slang_spec_ivec2:
+ case slang_spec_ivec3:
+ case slang_spec_ivec4:
+ case slang_spec_bvec2:
+ case slang_spec_bvec3:
+ case slang_spec_bvec4:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+/* _slang_type_base_of_vector() */
+
+slang_type_specifier_type _slang_type_base (slang_type_specifier_type ty)
+{
+ switch (ty)
+ {
+ case slang_spec_float:
+ case slang_spec_vec2:
+ case slang_spec_vec3:
+ case slang_spec_vec4:
+ return slang_spec_float;
+ case slang_spec_int:
+ case slang_spec_ivec2:
+ case slang_spec_ivec3:
+ case slang_spec_ivec4:
+ return slang_spec_int;
+ case slang_spec_bool:
+ case slang_spec_bvec2:
+ case slang_spec_bvec3:
+ case slang_spec_bvec4:
+ return slang_spec_bool;
+ case slang_spec_mat2:
+ return slang_spec_vec2;
+ case slang_spec_mat3:
+ return slang_spec_vec3;
+ case slang_spec_mat4:
+ return slang_spec_vec4;
+ default:
+ return slang_spec_void;
+ }
+}
+
+/* _slang_type_dim */
+
+unsigned int _slang_type_dim (slang_type_specifier_type ty)
+{
+ switch (ty)
+ {
+ case slang_spec_float:
+ case slang_spec_int:
+ case slang_spec_bool:
+ return 1;
+ case slang_spec_vec2:
+ case slang_spec_ivec2:
+ case slang_spec_bvec2:
+ case slang_spec_mat2:
+ return 2;
+ case slang_spec_vec3:
+ case slang_spec_ivec3:
+ case slang_spec_bvec3:
+ case slang_spec_mat3:
+ return 3;
+ case slang_spec_vec4:
+ case slang_spec_ivec4:
+ case slang_spec_bvec4:
+ case slang_spec_mat4:
+ return 4;
+ default:
+ return 0;
+ }
+}
+