summaryrefslogtreecommitdiffstats
path: root/src/glsl
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2013-10-20 12:35:47 -0700
committerFrancisco Jerez <[email protected]>2013-10-29 12:40:55 -0700
commit26db3b933f7fbc81d6c2bead2a8b0479a3691424 (patch)
tree217193e3025d3946565e809793508ad797497279 /src/glsl
parent0bed1ab73bc8a673b4d7d590d9d39b76fd8bf797 (diff)
glsl: Add new atomic_uint built-in GLSL type.
v2: Fix GLSL version in which the type became available. Add contains_atomic() convenience method. Split off atomic counter comparison error checking to a separate patch that will handle all opaque types. Include new ir_variable fields for atomic types. Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/glsl')
-rw-r--r--src/glsl/ast_to_hir.cpp1
-rw-r--r--src/glsl/builtin_type_macros.h2
-rw-r--r--src/glsl/builtin_types.cpp6
-rw-r--r--src/glsl/glsl_types.cpp2
-rw-r--r--src/glsl/glsl_types.h22
-rw-r--r--src/glsl/ir.cpp2
-rw-r--r--src/glsl/ir.h8
-rw-r--r--src/glsl/ir_clone.cpp3
-rw-r--r--src/glsl/link_uniform_initializers.cpp1
-rw-r--r--src/glsl/tests/uniform_initializer_utils.cpp3
10 files changed, 49 insertions, 1 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 3cc44a07089..fa0d8c94ade 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -943,6 +943,7 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
case GLSL_TYPE_VOID:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_INTERFACE:
+ case GLSL_TYPE_ATOMIC_UINT:
/* I assume a comparison of a struct containing a sampler just
* ignores the sampler present in the type.
*/
diff --git a/src/glsl/builtin_type_macros.h b/src/glsl/builtin_type_macros.h
index fec38da125a..263fd83ffc1 100644
--- a/src/glsl/builtin_type_macros.h
+++ b/src/glsl/builtin_type_macros.h
@@ -110,6 +110,8 @@ DECL_TYPE(sampler2DRectShadow, GL_SAMPLER_2D_RECT_SHADOW, GLSL_SAMPLER
DECL_TYPE(samplerExternalOES, GL_SAMPLER_EXTERNAL_OES, GLSL_SAMPLER_DIM_EXTERNAL, 0, 0, GLSL_TYPE_FLOAT)
+DECL_TYPE(atomic_uint, GL_UNSIGNED_INT_ATOMIC_COUNTER, GLSL_TYPE_ATOMIC_UINT, 1, 1)
+
STRUCT_TYPE(gl_DepthRangeParameters)
STRUCT_TYPE(gl_PointParameters)
STRUCT_TYPE(gl_MaterialParameters)
diff --git a/src/glsl/builtin_types.cpp b/src/glsl/builtin_types.cpp
index 1a5e5a19001..92e38605775 100644
--- a/src/glsl/builtin_types.cpp
+++ b/src/glsl/builtin_types.cpp
@@ -203,6 +203,8 @@ const static struct builtin_type_versions {
T(sampler2DRectShadow, 140, 999)
T(struct_gl_DepthRangeParameters, 110, 100)
+
+ T(atomic_uint, 420, 999)
};
const glsl_type *const deprecated_types[] = {
@@ -284,5 +286,9 @@ _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state)
if (state->OES_texture_3D_enable) {
add_type(symbols, glsl_type::sampler3D_type);
}
+
+ if (state->ARB_shader_atomic_counters_enable) {
+ add_type(symbols, glsl_type::atomic_uint_type);
+ }
}
/** @} */
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index bc8d87f5fa6..281e6902e85 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -601,6 +601,7 @@ glsl_type::component_slots() const
return this->length * this->fields.array->component_slots();
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
break;
@@ -889,6 +890,7 @@ glsl_type::count_attribute_slots() const
return this->length * this->fields.array->count_attribute_slots();
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
break;
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index b1050078d17..69ad4b86554 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -53,6 +53,7 @@ enum glsl_base_type {
GLSL_TYPE_FLOAT,
GLSL_TYPE_BOOL,
GLSL_TYPE_SAMPLER,
+ GLSL_TYPE_ATOMIC_UINT,
GLSL_TYPE_STRUCT,
GLSL_TYPE_INTERFACE,
GLSL_TYPE_ARRAY,
@@ -441,6 +442,27 @@ struct glsl_type {
}
/**
+ * Return the amount of atomic counter storage required for a type.
+ */
+ unsigned atomic_size() const
+ {
+ if (base_type == GLSL_TYPE_ATOMIC_UINT)
+ return ATOMIC_COUNTER_SIZE;
+ else if (is_array())
+ return length * element_type()->atomic_size();
+ else
+ return 0;
+ }
+
+ /**
+ * Return whether a type contains any atomic counters.
+ */
+ bool contains_atomic() const
+ {
+ return atomic_size();
+ }
+
+ /**
* Query the full type of a matrix row
*
* \return
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index c682e3ed536..09dbf401fe4 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1586,7 +1586,7 @@ ir_variable::ir_variable(const struct glsl_type *type, const char *name,
ir_variable_mode mode)
: max_array_access(0), max_ifc_array_access(NULL),
read_only(false), centroid(false), invariant(false),
- mode(mode), interpolation(INTERP_QUALIFIER_NONE)
+ mode(mode), interpolation(INTERP_QUALIFIER_NONE), atomic()
{
this->ir_type = ir_type_variable;
this->type = type;
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 8d5bec9c1ef..85b4d057f5e 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -639,6 +639,14 @@ public:
int binding;
/**
+ * Location an atomic counter is stored at.
+ */
+ struct {
+ unsigned buffer_index;
+ unsigned offset;
+ } atomic;
+
+ /**
* Built-in state that backs this uniform
*
* Once set at variable creation, \c state_slots must remain invariant.
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 105f9063a96..b0f173a62e6 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -57,6 +57,8 @@ ir_variable::clone(void *mem_ctx, struct hash_table *ht) const
var->location = this->location;
var->index = this->index;
var->binding = this->binding;
+ var->atomic.buffer_index = this->atomic.buffer_index;
+ var->atomic.offset = this->atomic.offset;
var->warn_extension = this->warn_extension;
var->origin_upper_left = this->origin_upper_left;
var->pixel_center_integer = this->pixel_center_integer;
@@ -395,6 +397,7 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
}
case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp
index 3f667104759..786aaf0b440 100644
--- a/src/glsl/link_uniform_initializers.cpp
+++ b/src/glsl/link_uniform_initializers.cpp
@@ -69,6 +69,7 @@ copy_constant_to_storage(union gl_constant_value *storage,
break;
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_STRUCT:
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_INTERFACE:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
diff --git a/src/glsl/tests/uniform_initializer_utils.cpp b/src/glsl/tests/uniform_initializer_utils.cpp
index a04f5ddc4b2..5e86c2432de 100644
--- a/src/glsl/tests/uniform_initializer_utils.cpp
+++ b/src/glsl/tests/uniform_initializer_utils.cpp
@@ -92,6 +92,7 @@ generate_data_element(void *mem_ctx, const glsl_type *type,
case GLSL_TYPE_BOOL:
data.b[i] = bool(values[idx]);
break;
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_VOID:
@@ -119,6 +120,7 @@ generate_data_element(void *mem_ctx, const glsl_type *type,
case GLSL_TYPE_BOOL:
ASSERT_EQ(data.b[i], val->value.b[i]);
break;
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_VOID:
@@ -217,6 +219,7 @@ verify_data(gl_constant_value *storage, unsigned storage_array_size,
case GLSL_TYPE_BOOL:
EXPECT_EQ(int(val->value.b[i]), storage[i].i);
break;
+ case GLSL_TYPE_ATOMIC_UINT:
case GLSL_TYPE_STRUCT:
case GLSL_TYPE_ARRAY:
case GLSL_TYPE_VOID: