<div dir="ltr">\On 22 January 2013 00:52, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
Interfaces are structurally identical to structures from the compiler's<br>
point of view. They have some additional restrictions, and generally<br>
GPUs use different instructions to access them. Using a different base<br>
type should make this a bit easier.<br>
<br>
v2: Add serveral missing GLSL_TYPE_INTERFACE cases in switch-statements.<br>
<br></blockquote><div><br></div><div>Can we also note in the commit message that this patch adds glsl_type::interface_packing?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
---<br>
src/glsl/ast_to_hir.cpp | 1 +<br>
src/glsl/glsl_types.cpp | 73 +++++++++++++++++++++++---<br>
src/glsl/glsl_types.h | 36 ++++++++++++-<br>
src/glsl/ir_clone.cpp | 1 +<br>
src/glsl/link_uniform_initializers.cpp | 1 +<br>
src/glsl/tests/uniform_initializer_utils.cpp | 3 ++<br>
src/mesa/drivers/dri/i965/brw_fs.cpp | 1 +<br>
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 1 +<br>
src/mesa/drivers/dri/i965/brw_shader.cpp | 1 +<br>
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 1 +<br>
src/mesa/program/ir_to_mesa.cpp | 2 +<br>
11 files changed, 112 insertions(+), 9 deletions(-)<br>
<br>
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp<br>
index bce3488..575dd84 100644<br>
--- a/src/glsl/ast_to_hir.cpp<br>
+++ b/src/glsl/ast_to_hir.cpp<br>
@@ -857,6 +857,7 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)<br>
case GLSL_TYPE_ERROR:<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_SAMPLER:<br>
+ case GLSL_TYPE_INTERFACE:<br>
/* I assume a comparison of a struct containing a sampler just<br>
* ignores the sampler present in the type.<br>
*/<br>
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp<br>
index 46cc96e..0075550 100644<br>
--- a/src/glsl/glsl_types.cpp<br>
+++ b/src/glsl/glsl_types.cpp<br>
@@ -34,6 +34,7 @@ extern "C" {<br>
<br>
hash_table *glsl_type::array_types = NULL;<br>
hash_table *glsl_type::record_types = NULL;<br>
+hash_table *glsl_type::interface_types = NULL;<br>
void *glsl_type::mem_ctx = NULL;<br>
<br>
void<br>
@@ -51,7 +52,7 @@ glsl_type::glsl_type(GLenum gl_type,<br>
gl_type(gl_type),<br>
base_type(base_type),<br>
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),<br>
- sampler_type(0),<br>
+ sampler_type(0), interface_packing(0),<br>
vector_elements(vector_elements), matrix_columns(matrix_columns),<br>
length(0)<br>
{<br>
@@ -69,7 +70,7 @@ glsl_type::glsl_type(GLenum gl_type,<br>
gl_type(gl_type),<br>
base_type(GLSL_TYPE_SAMPLER),<br>
sampler_dimensionality(dim), sampler_shadow(shadow),<br>
- sampler_array(array), sampler_type(type),<br>
+ sampler_array(array), sampler_type(type), interface_packing(0),<br>
vector_elements(0), matrix_columns(0),<br>
length(0)<br>
{<br>
@@ -82,7 +83,29 @@ glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,<br>
const char *name) :<br>
base_type(GLSL_TYPE_STRUCT),<br>
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),<br>
- sampler_type(0),<br>
+ sampler_type(0), interface_packing(0),<br>
+ vector_elements(0), matrix_columns(0),<br>
+ length(num_fields)<br>
+{<br>
+ unsigned int i;<br>
+<br>
+ init_ralloc_type_ctx();<br>
+ this->name = ralloc_strdup(this->mem_ctx, name);<br>
+ this->fields.structure = ralloc_array(this->mem_ctx,<br>
+ glsl_struct_field, length);<br>
+ for (i = 0; i < length; i++) {<br>
+ this->fields.structure[i].type = fields[i].type;<br>
+ this->fields.structure[i].name = ralloc_strdup(this->fields.structure,<br>
+ fields[i].name);<br>
+ this->fields.structure[i].row_major = fields[i].row_major;<br>
+ }<br>
+}<br>
+<br>
+glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,<br>
+ enum glsl_interface_packing packing, const char *name) :<br>
+ base_type(GLSL_TYPE_INTERFACE),<br>
+ sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),<br>
+ sampler_type(0), interface_packing((unsigned) packing),<br>
vector_elements(0), matrix_columns(0),<br>
length(num_fields)<br>
{<br>
@@ -430,7 +453,7 @@ _mesa_glsl_release_types(void)<br>
glsl_type::glsl_type(const glsl_type *array, unsigned length) :<br>
base_type(GLSL_TYPE_ARRAY),<br>
sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),<br>
- sampler_type(0),<br>
+ sampler_type(0), interface_packing(0),<br>
vector_elements(0), matrix_columns(0),<br>
name(NULL), length(length)<br>
{<br>
@@ -562,12 +585,18 @@ glsl_type::record_key_compare(const void *a, const void *b)<br>
if (key1->length != key2->length)<br>
return 1;<br>
<br>
+ if (key1->interface_packing != key2->interface_packing)<br>
+ return 1;<br>
+<br>
for (unsigned i = 0; i < key1->length; i++) {<br>
if (key1->fields.structure[i].type != key2->fields.structure[i].type)<br>
return 1;<br>
if (strcmp(key1->fields.structure[i].name,<br>
key2->fields.structure[i].name) != 0)<br>
return 1;<br>
+ if (key1->fields.structure[i].row_major<br>
+ != key2->fields.structure[i].row_major)<br>
+ return 1;<br></blockquote><div><br></div><div>It seems like this hunk belongs in the previous patch (glsl: Add row_major field to glsl_struct_field).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
}<br>
<br>
return 0;<br>
@@ -622,9 +651,37 @@ glsl_type::get_record_instance(const glsl_struct_field *fields,<br>
<br>
<br>
const glsl_type *<br>
+glsl_type::get_interface_instance(const glsl_struct_field *fields,<br>
+ unsigned num_fields,<br>
+ enum glsl_interface_packing packing,<br>
+ const char *name)<br>
+{<br>
+ const glsl_type key(fields, num_fields, packing, name);<br>
+<br>
+ if (interface_types == NULL) {<br>
+ interface_types = hash_table_ctor(64, record_key_hash, record_key_compare);<br>
+ }<br>
+<br>
+ const glsl_type *t = (glsl_type *) hash_table_find(interface_types, & key);<br>
+ if (t == NULL) {<br>
+ t = new glsl_type(fields, num_fields, packing, name);<br>
+<br>
+ hash_table_insert(interface_types, (void *) t, t);<br>
+ }<br>
+<br>
+ assert(t->base_type == GLSL_TYPE_INTERFACE);<br>
+ assert(t->length == num_fields);<br>
+ assert(strcmp(t->name, name) == 0);<br>
+<br>
+ return t;<br>
+}<br>
+<br>
+<br>
+const glsl_type *<br>
glsl_type::field_type(const char *name) const<br>
{<br>
- if (this->base_type != GLSL_TYPE_STRUCT)<br>
+ if (this->base_type != GLSL_TYPE_STRUCT<br>
+ && this->base_type != GLSL_TYPE_INTERFACE)<br>
return error_type;<br>
<br>
for (unsigned i = 0; i < this->length; i++) {<br>
@@ -639,7 +696,8 @@ glsl_type::field_type(const char *name) const<br>
int<br>
glsl_type::field_index(const char *name) const<br>
{<br>
- if (this->base_type != GLSL_TYPE_STRUCT)<br>
+ if (this->base_type != GLSL_TYPE_STRUCT<br>
+ && this->base_type != GLSL_TYPE_INTERFACE)<br>
return -1;<br>
<br>
for (unsigned i = 0; i < this->length; i++) {<br>
@@ -661,7 +719,8 @@ glsl_type::component_slots() const<br>
case GLSL_TYPE_BOOL:<br>
return this->components();<br>
<br>
- case GLSL_TYPE_STRUCT: {<br>
+ case GLSL_TYPE_STRUCT:<br>
+ case GLSL_TYPE_INTERFACE: {<br>
unsigned size = 0;<br>
<br>
for (unsigned i = 0; i < this->length; i++)<br>
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h<br>
index 24ad844..8588685 100644<br>
--- a/src/glsl/glsl_types.h<br>
+++ b/src/glsl/glsl_types.h<br>
@@ -54,6 +54,7 @@ enum glsl_base_type {<br>
GLSL_TYPE_BOOL,<br>
GLSL_TYPE_SAMPLER,<br>
GLSL_TYPE_STRUCT,<br>
+ GLSL_TYPE_INTERFACE,<br>
GLSL_TYPE_ARRAY,<br>
GLSL_TYPE_VOID,<br>
GLSL_TYPE_ERROR<br>
@@ -69,6 +70,12 @@ enum glsl_sampler_dim {<br>
GLSL_SAMPLER_DIM_EXTERNAL<br>
};<br>
<br>
+enum glsl_interface_packing {<br>
+ GLSL_INTERFACE_PACKING_STD140,<br>
+ GLSL_INTERFACE_PACKING_SHARED,<br>
+ GLSL_INTERFACE_PACKING_PACKED<br>
+};<br>
+<br>
#ifdef __cplusplus<br>
#include "GL/gl.h"<br>
#include "ralloc.h"<br>
@@ -84,6 +91,7 @@ struct glsl_type {<br>
* only \c GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,<br>
* and \c GLSL_TYPE_UINT are valid.<br>
*/<br>
+ unsigned interface_packing:2;<br>
<br>
/* Callers of this ralloc-based new need not call delete. It's<br>
* easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */<br>
@@ -130,8 +138,9 @@ struct glsl_type {<br>
<br>
/**<br>
* For \c GLSL_TYPE_ARRAY, this is the length of the array. For<br>
- * \c GLSL_TYPE_STRUCT, it is the number of elements in the structure and<br>
- * the number of values pointed to by \c fields.structure (below).<br>
+ * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of<br>
+ * elements in the structure and the number of values pointed to by<br>
+ * \c fields.structure (below).<br>
*/<br>
unsigned length;<br>
<br>
@@ -232,6 +241,14 @@ struct glsl_type {<br>
const char *name);<br>
<br>
/**<br>
+ * Get the instance of an interface block type<br>
+ */<br>
+ static const glsl_type *get_interface_instance(const glsl_struct_field *fields,<br>
+ unsigned num_fields,<br>
+ enum glsl_interface_packing packing,<br>
+ const char *name);<br>
+<br>
+ /**<br>
* Query the total number of scalars that make up a scalar, vector or matrix<br>
*/<br>
unsigned components() const<br>
@@ -394,6 +411,14 @@ struct glsl_type {<br>
}<br>
<br>
/**<br>
+ * Query whether or not a type is an interface<br>
+ */<br>
+ bool is_interface() const<br>
+ {<br>
+ return base_type == GLSL_TYPE_INTERFACE;<br>
+ }<br>
+<br>
+ /**<br>
* Query whether or not a type is the void type singleton.<br>
*/<br>
bool is_void() const<br>
@@ -491,6 +516,10 @@ private:<br>
glsl_type(const glsl_struct_field *fields, unsigned num_fields,<br>
const char *name);<br>
<br>
+ /** Constructor for interface types */<br>
+ glsl_type(const glsl_struct_field *fields, unsigned num_fields,<br>
+ enum glsl_interface_packing packing, const char *name);<br>
+<br>
/** Constructor for array types */<br>
glsl_type(const glsl_type *array, unsigned length);<br>
<br>
@@ -500,6 +529,9 @@ private:<br>
/** Hash table containing the known record types. */<br>
static struct hash_table *record_types;<br>
<br>
+ /** Hash table containing the known interface types. */<br>
+ static struct hash_table *interface_types;<br>
+<br>
static int record_key_compare(const void *a, const void *b);<br>
static unsigned record_key_hash(const void *key);<br>
<br>
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp<br>
index 9b7981b..3e22f2d 100644<br>
--- a/src/glsl/ir_clone.cpp<br>
+++ b/src/glsl/ir_clone.cpp<br>
@@ -378,6 +378,7 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const<br>
case GLSL_TYPE_SAMPLER:<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(!"Should not get here.");<br>
break;<br>
}<br>
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp<br>
index 933df29..836a360 100644<br>
--- a/src/glsl/link_uniform_initializers.cpp<br>
+++ b/src/glsl/link_uniform_initializers.cpp<br>
@@ -69,6 +69,7 @@ copy_constant_to_storage(union gl_constant_value *storage,<br>
break;<br>
case GLSL_TYPE_ARRAY:<br>
case GLSL_TYPE_STRUCT:<br>
+ case GLSL_TYPE_INTERFACE:<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
/* All other types should have already been filtered by other<br>
diff --git a/src/glsl/tests/uniform_initializer_utils.cpp b/src/glsl/tests/uniform_initializer_utils.cpp<br>
index e7d274e..a04f5dd 100644<br>
--- a/src/glsl/tests/uniform_initializer_utils.cpp<br>
+++ b/src/glsl/tests/uniform_initializer_utils.cpp<br>
@@ -96,6 +96,7 @@ generate_data_element(void *mem_ctx, const glsl_type *type,<br>
case GLSL_TYPE_ARRAY:<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
ASSERT_TRUE(false);<br>
break;<br>
}<br>
@@ -122,6 +123,7 @@ generate_data_element(void *mem_ctx, const glsl_type *type,<br>
case GLSL_TYPE_ARRAY:<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
ASSERT_TRUE(false);<br>
break;<br>
}<br>
@@ -219,6 +221,7 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size,<br>
case GLSL_TYPE_ARRAY:<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
ASSERT_TRUE(false);<br>
break;<br>
}<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
index 03b0630..8e57eb0 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
@@ -457,6 +457,7 @@ fs_visitor::type_size(const struct glsl_type *type)<br>
return 0;<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(!"not reached");<br>
break;<br>
}<br>
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
index 07df1a8..1186291 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp<br>
@@ -685,6 +685,7 @@ fs_visitor::emit_assignment_writes(fs_reg &l, fs_reg &r,<br>
<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(!"not reached");<br>
break;<br>
}<br>
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
index 49e24d2..039c26c 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
@@ -255,6 +255,7 @@ brw_type_for_base_type(const struct glsl_type *type)<br>
return BRW_REGISTER_TYPE_UD;<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(!"not reached");<br>
break;<br>
}<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
index 7eda0fb..8aa67c2 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
@@ -396,6 +396,7 @@ type_size(const struct glsl_type *type)<br>
return 1;<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(0);<br>
break;<br>
}<br>
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp<br>
index 18527e6..637ab07 100644<br>
--- a/src/mesa/program/ir_to_mesa.cpp<br>
+++ b/src/mesa/program/ir_to_mesa.cpp<br>
@@ -625,6 +625,7 @@ type_size(const struct glsl_type *type)<br>
return 1;<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(!"Invalid type in type_size");<br>
break;<br>
}<br>
@@ -2529,6 +2530,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,<br>
case GLSL_TYPE_VOID:<br>
case GLSL_TYPE_STRUCT:<br>
case GLSL_TYPE_ERROR:<br>
+ case GLSL_TYPE_INTERFACE:<br>
assert(!"Should not get here.");<br>
break;<br>
}<br>
<span class=""><font color="#888888">--<br>
1.7.11.7<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br><br></div><div class="gmail_extra">With those minor changes, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div></div>