mtx_t glsl_type::hash_mutex = _MTX_INITIALIZER_NP;
+hash_table *glsl_type::explicit_matrix_types = NULL;
hash_table *glsl_type::array_types = NULL;
hash_table *glsl_type::record_types = NULL;
hash_table *glsl_type::interface_types = NULL;
glsl_type::glsl_type(GLenum gl_type,
glsl_base_type base_type, unsigned vector_elements,
- unsigned matrix_columns, const char *name) :
+ unsigned matrix_columns, const char *name,
+ unsigned explicit_stride, bool row_major) :
gl_type(gl_type),
base_type(base_type), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
- interface_packing(0), interface_row_major(0),
+ interface_packing(0), interface_row_major(row_major),
vector_elements(vector_elements), matrix_columns(matrix_columns),
- length(0)
+ length(0), explicit_stride(explicit_stride)
{
/* Values of these types must fit in the two bits of
* glsl_type::sampled_type.
base_type(base_type), sampled_type(type),
sampler_dimensionality(dim), sampler_shadow(shadow),
sampler_array(array), interface_packing(0),
- interface_row_major(0), length(0)
+ interface_row_major(0),
+ length(0), explicit_stride(0)
{
this->mem_ctx = ralloc_context(NULL);
assert(this->mem_ctx != NULL);
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
interface_packing(0), interface_row_major(0),
vector_elements(0), matrix_columns(0),
- length(num_fields)
+ length(num_fields), explicit_stride(0)
{
unsigned int i;
interface_packing((unsigned) packing),
interface_row_major((unsigned) row_major),
vector_elements(0), matrix_columns(0),
- length(num_fields)
+ length(num_fields), explicit_stride(0)
{
unsigned int i;
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
interface_packing(0), interface_row_major(0),
vector_elements(0), matrix_columns(0),
- length(num_params)
+ length(num_params), explicit_stride(0)
{
unsigned int i;
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
interface_packing(0), interface_row_major(0),
vector_elements(1), matrix_columns(1),
- length(0)
+ length(0), explicit_stride(0)
{
this->mem_ctx = ralloc_context(NULL);
assert(this->mem_ctx != NULL);
}
+const glsl_type *glsl_type::get_bare_type() const
+{
+ switch (this->base_type) {
+ case GLSL_TYPE_UINT8:
+ case GLSL_TYPE_INT8:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
+ case GLSL_TYPE_FLOAT16:
+ case GLSL_TYPE_UINT:
+ case GLSL_TYPE_INT:
+ case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_INT64:
+ return get_instance(this->base_type, this->vector_elements,
+ this->matrix_columns);
+
+ case GLSL_TYPE_STRUCT:
+ case GLSL_TYPE_INTERFACE: {
+ glsl_struct_field *bare_fields = new glsl_struct_field[this->length];
+ for (unsigned i = 0; i < this->length; i++) {
+ bare_fields[i].type = this->fields.structure[i].type->get_bare_type();
+ bare_fields[i].name = this->fields.structure[i].name;
+ }
+ const glsl_type *bare_type =
+ get_record_instance(bare_fields, this->length, this->name);
+ delete[] bare_fields;
+ return bare_type;
+ }
+
+ case GLSL_TYPE_ARRAY:
+ return get_array_instance(this->fields.array->get_bare_type(),
+ this->length);
+
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_ATOMIC_UINT:
+ case GLSL_TYPE_VOID:
+ case GLSL_TYPE_SUBROUTINE:
+ case GLSL_TYPE_FUNCTION:
+ case GLSL_TYPE_ERROR:
+ return this;
+ }
+
+ unreachable("Invalid base type");
+}
+
+
static void
hash_free_type_function(struct hash_entry *entry)
{
* object, or if process terminates), so no mutex-locking should be
* necessary.
*/
+ if (glsl_type::explicit_matrix_types != NULL) {
+ _mesa_hash_table_destroy(glsl_type::explicit_matrix_types,
+ hash_free_type_function);
+ glsl_type::explicit_matrix_types = NULL;
+ }
+
if (glsl_type::array_types != NULL) {
_mesa_hash_table_destroy(glsl_type::array_types, hash_free_type_function);
glsl_type::array_types = NULL;
}
-glsl_type::glsl_type(const glsl_type *array, unsigned length) :
+glsl_type::glsl_type(const glsl_type *array, unsigned length,
+ unsigned explicit_stride) :
base_type(GLSL_TYPE_ARRAY), sampled_type(GLSL_TYPE_VOID),
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
interface_packing(0), interface_row_major(0),
vector_elements(0), matrix_columns(0),
- length(length), name(NULL)
+ length(length), name(NULL), explicit_stride(explicit_stride)
{
this->fields.array = array;
/* Inherit the gl type of the base. The GL type is used for
VECN(components, uint8_t, u8vec)
const glsl_type *
-glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
+glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns,
+ unsigned explicit_stride, bool row_major)
{
- if (base_type == GLSL_TYPE_VOID)
+ if (base_type == GLSL_TYPE_VOID) {
+ assert(explicit_stride == 0 && !row_major);
return void_type;
+ }
+
+ /* Matrix and vector types with explicit strides have to be looked up in a
+ * table so they're handled separately.
+ */
+ if (explicit_stride > 0) {
+ const glsl_type *bare_type = get_instance(base_type, rows, columns);
+
+ assert(columns > 1 || !row_major);
+
+ char name[128];
+ util_snprintf(name, sizeof(name), "%sx%uB%s", bare_type->name,
+ explicit_stride, row_major ? "RM" : "");
+
+ mtx_lock(&glsl_type::hash_mutex);
+
+ if (explicit_matrix_types == NULL) {
+ explicit_matrix_types =
+ _mesa_hash_table_create(NULL, _mesa_key_hash_string,
+ _mesa_key_string_equal);
+ }
+
+ const struct hash_entry *entry =
+ _mesa_hash_table_search(explicit_matrix_types, name);
+ if (entry == NULL) {
+ const glsl_type *t = new glsl_type(bare_type->gl_type,
+ (glsl_base_type)base_type,
+ rows, columns, name,
+ explicit_stride, row_major);
+
+ entry = _mesa_hash_table_insert(explicit_matrix_types,
+ t->name, (void *)t);
+ }
+
+ assert(((glsl_type *) entry->data)->base_type == base_type);
+ assert(((glsl_type *) entry->data)->vector_elements == rows);
+ assert(((glsl_type *) entry->data)->matrix_columns == columns);
+ assert(((glsl_type *) entry->data)->explicit_stride == explicit_stride);
+
+ mtx_unlock(&glsl_type::hash_mutex);
+
+ return (const glsl_type *) entry->data;
+ }
+
+ assert(!row_major);
/* Treat GLSL vectors as Nx1 matrices.
*/
}
const glsl_type *
-glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
+glsl_type::get_array_instance(const glsl_type *base,
+ unsigned array_size,
+ unsigned explicit_stride)
{
/* Generate a name using the base type pointer in the key. This is
* done because the name of the base type may not be unique across
* named 'foo'.
*/
char key[128];
- util_snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size);
+ util_snprintf(key, sizeof(key), "%p[%u]x%uB", (void *) base, array_size,
+ explicit_stride);
mtx_lock(&glsl_type::hash_mutex);
const struct hash_entry *entry = _mesa_hash_table_search(array_types, key);
if (entry == NULL) {
- const glsl_type *t = new glsl_type(base, array_size);
+ const glsl_type *t = new glsl_type(base, array_size, explicit_stride);
entry = _mesa_hash_table_insert(array_types,
strdup(key),
* <N> basic machine units, the base alignment is 4<N>.
*/
if (this->is_scalar() || this->is_vector()) {
+ assert(this->explicit_stride == 0);
return this->vector_elements * N;
}
array_len = 1;
}
+ assert(element_type->explicit_stride == 0);
+
if (row_major) {
vec_type = get_instance(element_type->base_type,
element_type->matrix_columns, 1);
* the array are laid out in order, according to rule (9).
*/
if (this->is_array()) {
+ assert(this->explicit_stride == 0);
if (this->without_array()->is_record()) {
return this->arrays_of_arrays_size() *
this->without_array()->std140_size(row_major);
{
unsigned N = is_64bit() ? 8 : 4;
+ assert(explicit_stride == 0);
+
/* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
* See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
*
* stride of arrays of scalars and vectors in rule 4 and of structures
* in rule 9 are not rounded up a multiple of the base alignment of a vec4.
*/
- if (this->is_scalar() || this->is_vector())
- return this->vector_elements * N;
+ if (this->is_scalar() || this->is_vector()) {
+ assert(this->explicit_stride == 0);
+ return this->vector_elements * N;
+ }
if (this->without_array()->is_matrix()) {
const struct glsl_type *element_type;
array_len = 1;
}
+ assert(element_type->explicit_stride == 0);
+
if (row_major) {
vec_type = get_instance(element_type->base_type,
element_type->matrix_columns, 1);
}
if (this->is_array()) {
+ assert(this->explicit_stride == 0);
if (this->without_array()->is_record())
return this->arrays_of_arrays_size() *
this->without_array()->std430_size(row_major);
case GLSL_TYPE_INT64:
case GLSL_TYPE_BOOL:
encoding = (type->base_type << 24) |
+ (type->interface_row_major << 10) |
(type->vector_elements << 4) |
(type->matrix_columns);
- break;
+ blob_write_uint32(blob, encoding);
+ blob_write_uint32(blob, type->explicit_stride);
+ return;
case GLSL_TYPE_SAMPLER:
encoding = (type->base_type) << 24 |
(type->sampler_dimensionality << 4) |
case GLSL_TYPE_ARRAY:
blob_write_uint32(blob, (type->base_type) << 24);
blob_write_uint32(blob, type->length);
+ blob_write_uint32(blob, type->explicit_stride);
encode_type_to_blob(blob, type->fields.array);
return;
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_INT16:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
- case GLSL_TYPE_BOOL:
- return glsl_type::get_instance(base_type, (u >> 4) & 0x0f, u & 0x0f);
+ case GLSL_TYPE_BOOL: {
+ unsigned explicit_stride = blob_read_uint32(blob);
+ return glsl_type::get_instance(base_type, (u >> 4) & 0x0f, u & 0x0f,
+ explicit_stride, (u >> 10) & 0x1);
+ }
case GLSL_TYPE_SAMPLER:
return glsl_type::get_sampler_instance((enum glsl_sampler_dim) ((u >> 4) & 0x07),
(u >> 3) & 0x01,
return glsl_type::atomic_uint_type;
case GLSL_TYPE_ARRAY: {
unsigned length = blob_read_uint32(blob);
+ unsigned explicit_stride = blob_read_uint32(blob);
return glsl_type::get_array_instance(decode_type_from_blob(blob),
- length);
+ length, explicit_stride);
}
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_INTERFACE: {
*/
const char *name;
+ /**
+ * Explicit array, matrix, or vector stride. This is used to communicate
+ * explicit array layouts from SPIR-V. Should be 0 if the type has no
+ * explicit stride.
+ */
+ unsigned explicit_stride;
+
/**
* Subtype of composite data types.
*/
*/
const glsl_type *get_scalar_type() const;
+ /**
+ * Gets the "bare" type without any decorations or layout information.
+ */
+ const glsl_type *get_bare_type() const;
+
/**
* Get the instance of a built-in scalar, vector, or matrix type
*/
static const glsl_type *get_instance(unsigned base_type, unsigned rows,
- unsigned columns);
+ unsigned columns,
+ unsigned explicit_stride = 0,
+ bool row_major = false);
/**
* Get the instance of a sampler type
* Get the instance of an array type
*/
static const glsl_type *get_array_instance(const glsl_type *base,
- unsigned elements);
+ unsigned elements,
+ unsigned explicit_stride = 0);
/**
* Get the instance of a record type
*/
const glsl_type *row_type() const
{
- return is_matrix()
- ? get_instance(base_type, matrix_columns, 1)
- : error_type;
+ if (!is_matrix())
+ return error_type;
+
+ if (explicit_stride && !interface_row_major)
+ return get_instance(base_type, matrix_columns, 1, explicit_stride);
+ else
+ return get_instance(base_type, matrix_columns, 1);
}
/**
*/
const glsl_type *column_type() const
{
- return is_matrix()
- ? get_instance(base_type, vector_elements, 1)
- : error_type;
+ if (!is_matrix())
+ return error_type;
+
+ if (explicit_stride && interface_row_major)
+ return get_instance(base_type, vector_elements, 1, explicit_stride);
+ else
+ return get_instance(base_type, vector_elements, 1);
}
/**
/** Constructor for vector and matrix types */
glsl_type(GLenum gl_type,
- glsl_base_type base_type, unsigned vector_elements,
- unsigned matrix_columns, const char *name);
+ glsl_base_type base_type, unsigned vector_elements,
+ unsigned matrix_columns, const char *name,
+ unsigned explicit_stride = 0, bool row_major = false);
/** Constructor for sampler or image types */
glsl_type(GLenum gl_type, glsl_base_type base_type,
glsl_type(const glsl_type *return_type,
const glsl_function_param *params, unsigned num_params);
- /** Constructor for array types */
- glsl_type(const glsl_type *array, unsigned length);
+ /** Constructors for array types */
+ glsl_type(const glsl_type *array, unsigned length, unsigned explicit_stride);
/** Constructor for subroutine types */
glsl_type(const char *name);
+ /** Hash table containing the known explicit matrix and vector types. */
+ static struct hash_table *explicit_matrix_types;
+
/** Hash table containing the known array types. */
static struct hash_table *array_types;