glsl: Add new atomic_uint built-in GLSL type.
authorFrancisco Jerez <currojerez@riseup.net>
Sun, 20 Oct 2013 19:35:47 +0000 (12:35 -0700)
committerFrancisco Jerez <currojerez@riseup.net>
Tue, 29 Oct 2013 19:40:55 +0000 (12:40 -0700)
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 <ian.d.romanick@intel.com>
16 files changed:
src/glsl/ast_to_hir.cpp
src/glsl/builtin_type_macros.h
src/glsl/builtin_types.cpp
src/glsl/glsl_types.cpp
src/glsl/glsl_types.h
src/glsl/ir.cpp
src/glsl/ir.h
src/glsl/ir_clone.cpp
src/glsl/link_uniform_initializers.cpp
src/glsl/tests/uniform_initializer_utils.cpp
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
src/mesa/program/ir_to_mesa.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index 3cc44a07089e1db6342ad2a803e3798394b0396b..fa0d8c94adeba411118ccaf3cdeaa861d4403719 100644 (file)
@@ -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.
        */
index fec38da125af20db057b5d6520ee19cc9647fc89..263fd83ffc156f38ad85e78dcfa96fd80eb5d014 100644 (file)
@@ -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)
index 1a5e5a190012818307fd6a94407df9a5ea5618d2..92e38605775453dddc2be493e8616aba3b0836e5 100644 (file)
@@ -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);
+   }
 }
 /** @} */
index bc8d87f5fa6ca1eeced6768acea093e3a0a4fdac..281e6902e8596c94ac8e4e345a9dc7d541b57a12 100644 (file)
@@ -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;
index b1050078d1733c0997b84cfb62936302bf3f1b17..69ad4b8655450c9b5d64b65d4b80d35421b57001 100644 (file)
@@ -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,
@@ -440,6 +441,27 @@ struct glsl_type {
       return base_type == GLSL_TYPE_ERROR;
    }
 
+   /**
+    * 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
     *
index c682e3ed536c97d467b6881a2f9b6143a9bc7451..09dbf401fe4f8c64238e33c3891f8dd02ae85bb4 100644 (file)
@@ -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;
index 8d5bec9c1efdf3874db48802e11738b697a1b1f7..85b4d057f5e2411edba208ef47d1a12e4f76d7d0 100644 (file)
@@ -638,6 +638,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
     *
index 105f9063a96ff2fbeeca343aec8754f2fb975ef4..b0f173a62e6c1b3a063bff66f62a32cf1d2a4109 100644 (file)
@@ -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:
index 3f667104759a41ed34d9e46006ee18a77c1d37c3..786aaf0b44082f60aebc40f0c7162873bc71e696 100644 (file)
@@ -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:
index a04f5ddc4b250805db1a95df8c383792413b898b..5e86c2432de94c1bf39277466159518632f5bac1 100644 (file)
@@ -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:
index b724dca4f60de873aef42b5a465a975065501450..6118cfad1f0edd45b04289f4dd415279db98469d 100644 (file)
@@ -496,6 +496,8 @@ fs_visitor::type_size(const struct glsl_type *type)
        * link time.
        */
       return 0;
+   case GLSL_TYPE_ATOMIC_UINT:
+      return 0;
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
    case GLSL_TYPE_INTERFACE:
index 9a5378a982b9f35962bde7c8995466c51582fe55..71b4bf9425957fcc29d3cb52389a7adf9fb7750e 100644 (file)
@@ -808,6 +808,7 @@ fs_visitor::emit_assignment_writes(fs_reg &l, fs_reg &r,
       break;
 
    case GLSL_TYPE_SAMPLER:
+   case GLSL_TYPE_ATOMIC_UINT:
       break;
 
    case GLSL_TYPE_VOID:
index 777ebfe5e3b5c8d5b065e68291cbb082bbcc872e..3efc201d5a21d40a2dbfeebd23d89d1e105c4f56 100644 (file)
@@ -304,6 +304,7 @@ brw_type_for_base_type(const struct glsl_type *type)
       return brw_type_for_base_type(type->fields.array);
    case GLSL_TYPE_STRUCT:
    case GLSL_TYPE_SAMPLER:
+   case GLSL_TYPE_ATOMIC_UINT:
       /* These should be overridden with the type of the member when
        * dereferenced into.  BRW_REGISTER_TYPE_UD seems like a likely
        * way to trip up if we don't.
index 64f869cdfd4f85d202f03504753745bf5c89d976..7f2ca951a834356420aeddba523c957dc58c5026 100644 (file)
@@ -569,6 +569,8 @@ type_size(const struct glsl_type *type)
        * at link time.
        */
       return 1;
+   case GLSL_TYPE_ATOMIC_UINT:
+      return 0;
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
    case GLSL_TYPE_INTERFACE:
index cfad91bc423c18d59c67e9acabe92a15c7e04324..c833a12f2aab1608d8b1c7c02d5a9882973231a7 100644 (file)
@@ -622,6 +622,7 @@ type_size(const struct glsl_type *type)
        * at link time.
        */
       return 1;
+   case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
    case GLSL_TYPE_INTERFACE:
@@ -2601,6 +2602,7 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
            format = uniform_native;
            columns = 1;
            break;
+         case GLSL_TYPE_ATOMIC_UINT:
          case GLSL_TYPE_ARRAY:
          case GLSL_TYPE_VOID:
          case GLSL_TYPE_STRUCT:
index 3e11cce24f7e548f6d858b05ce5347353c851aa6..0eaf7467b06076c23ce18c9f180f36cb4259ffd1 100644 (file)
@@ -993,6 +993,7 @@ type_size(const struct glsl_type *type)
        * at link time.
        */
       return 1;
+   case GLSL_TYPE_ATOMIC_UINT:
    case GLSL_TYPE_INTERFACE:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR: