hash_table *glsl_type::array_types = NULL;
hash_table *glsl_type::record_types = NULL;
+hash_table *glsl_type::interface_types = NULL;
void *glsl_type::mem_ctx = NULL;
void
gl_type(gl_type),
base_type(base_type),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- sampler_type(0),
+ sampler_type(0), interface_packing(0),
vector_elements(vector_elements), matrix_columns(matrix_columns),
length(0)
{
gl_type(gl_type),
base_type(GLSL_TYPE_SAMPLER),
sampler_dimensionality(dim), sampler_shadow(shadow),
- sampler_array(array), sampler_type(type),
+ sampler_array(array), sampler_type(type), interface_packing(0),
vector_elements(0), matrix_columns(0),
length(0)
{
const char *name) :
base_type(GLSL_TYPE_STRUCT),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- sampler_type(0),
+ sampler_type(0), interface_packing(0),
+ vector_elements(0), matrix_columns(0),
+ length(num_fields)
+{
+ unsigned int i;
+
+ init_ralloc_type_ctx();
+ this->name = ralloc_strdup(this->mem_ctx, name);
+ this->fields.structure = ralloc_array(this->mem_ctx,
+ glsl_struct_field, length);
+ for (i = 0; i < length; i++) {
+ this->fields.structure[i].type = fields[i].type;
+ this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
+ fields[i].name);
+ this->fields.structure[i].row_major = fields[i].row_major;
+ }
+}
+
+glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
+ enum glsl_interface_packing packing, const char *name) :
+ base_type(GLSL_TYPE_INTERFACE),
+ sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
+ sampler_type(0), interface_packing((unsigned) packing),
vector_elements(0), matrix_columns(0),
length(num_fields)
{
glsl_type::glsl_type(const glsl_type *array, unsigned length) :
base_type(GLSL_TYPE_ARRAY),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- sampler_type(0),
+ sampler_type(0), interface_packing(0),
vector_elements(0), matrix_columns(0),
name(NULL), length(length)
{
if (key1->length != key2->length)
return 1;
+ if (key1->interface_packing != key2->interface_packing)
+ return 1;
+
for (unsigned i = 0; i < key1->length; i++) {
if (key1->fields.structure[i].type != key2->fields.structure[i].type)
return 1;
}
+const glsl_type *
+glsl_type::get_interface_instance(const glsl_struct_field *fields,
+ unsigned num_fields,
+ enum glsl_interface_packing packing,
+ const char *name)
+{
+ const glsl_type key(fields, num_fields, packing, name);
+
+ if (interface_types == NULL) {
+ interface_types = hash_table_ctor(64, record_key_hash, record_key_compare);
+ }
+
+ const glsl_type *t = (glsl_type *) hash_table_find(interface_types, & key);
+ if (t == NULL) {
+ t = new glsl_type(fields, num_fields, packing, name);
+
+ hash_table_insert(interface_types, (void *) t, t);
+ }
+
+ assert(t->base_type == GLSL_TYPE_INTERFACE);
+ assert(t->length == num_fields);
+ assert(strcmp(t->name, name) == 0);
+
+ return t;
+}
+
+
const glsl_type *
glsl_type::field_type(const char *name) const
{
- if (this->base_type != GLSL_TYPE_STRUCT)
+ if (this->base_type != GLSL_TYPE_STRUCT
+ && this->base_type != GLSL_TYPE_INTERFACE)
return error_type;
for (unsigned i = 0; i < this->length; i++) {
int
glsl_type::field_index(const char *name) const
{
- if (this->base_type != GLSL_TYPE_STRUCT)
+ if (this->base_type != GLSL_TYPE_STRUCT
+ && this->base_type != GLSL_TYPE_INTERFACE)
return -1;
for (unsigned i = 0; i < this->length; i++) {
case GLSL_TYPE_BOOL:
return this->components();
- case GLSL_TYPE_STRUCT: {
+ case GLSL_TYPE_STRUCT:
+ case GLSL_TYPE_INTERFACE: {
unsigned size = 0;
for (unsigned i = 0; i < this->length; i++)
GLSL_TYPE_BOOL,
GLSL_TYPE_SAMPLER,
GLSL_TYPE_STRUCT,
+ GLSL_TYPE_INTERFACE,
GLSL_TYPE_ARRAY,
GLSL_TYPE_VOID,
GLSL_TYPE_ERROR
GLSL_SAMPLER_DIM_EXTERNAL
};
+enum glsl_interface_packing {
+ GLSL_INTERFACE_PACKING_STD140,
+ GLSL_INTERFACE_PACKING_SHARED,
+ GLSL_INTERFACE_PACKING_PACKED
+};
+
#ifdef __cplusplus
#include "GL/gl.h"
#include "ralloc.h"
* only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
* and \c GLSL_TYPE_UINT are valid.
*/
+ unsigned interface_packing:2;
/* Callers of this ralloc-based new need not call delete. It's
* easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */
/**
* For \c GLSL_TYPE_ARRAY, this is the length of the array. For
- * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and
- * the number of values pointed to by \c fields.structure (below).
+ * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
+ * elements in the structure and the number of values pointed to by
+ * \c fields.structure (below).
*/
unsigned length;
unsigned num_fields,
const char *name);
+ /**
+ * Get the instance of an interface block type
+ */
+ static const glsl_type *get_interface_instance(const glsl_struct_field *fields,
+ unsigned num_fields,
+ enum glsl_interface_packing packing,
+ const char *name);
+
/**
* Query the total number of scalars that make up a scalar, vector or matrix
*/
return base_type == GLSL_TYPE_STRUCT;
}
+ /**
+ * Query whether or not a type is an interface
+ */
+ bool is_interface() const
+ {
+ return base_type == GLSL_TYPE_INTERFACE;
+ }
+
/**
* Query whether or not a type is the void type singleton.
*/
glsl_type(const glsl_struct_field *fields, unsigned num_fields,
const char *name);
+ /** Constructor for interface types */
+ glsl_type(const glsl_struct_field *fields, unsigned num_fields,
+ enum glsl_interface_packing packing, const char *name);
+
/** Constructor for array types */
glsl_type(const glsl_type *array, unsigned length);
/** Hash table containing the known record types. */
static struct hash_table *record_types;
+ /** Hash table containing the known interface types. */
+ static struct hash_table *interface_types;
+
static int record_key_compare(const void *a, const void *b);
static unsigned record_key_hash(const void *key);