[Mesa-dev] [PATCH 11/24] glsl: Add built-in functions and constants required for ARB_shader_atomic_counters.

Francisco Jerez currojerez at riseup.net
Sun Sep 15 00:10:37 PDT 2013


---
 src/glsl/builtin_functions.cpp  | 33 +++++++++++++++++++++++++++++++++
 src/glsl/builtin_variables.cpp  | 15 +++++++++++++++
 src/glsl/glcpp/glcpp-parse.y    |  3 +++
 src/glsl/glsl_parser_extras.cpp |  6 ++++++
 src/glsl/glsl_parser_extras.h   |  7 +++++++
 5 files changed, 64 insertions(+)

diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 528af0d..7217166 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -300,6 +300,13 @@ tex3d_lod(const _mesa_glsl_parse_state *state)
 {
    return tex3d(state) && lod_exists_in_stage(state);
 }
+
+static bool
+shader_atomic_counters(const _mesa_glsl_parse_state *state)
+{
+   return state->ARB_shader_atomic_counters_enable;
+}
+
 /** @} */
 
 /******************************************************************************/
@@ -510,6 +517,10 @@ private:
    B1(findLSB)
    B1(findMSB)
    B1(fma)
+
+   ir_function_signature *_atomicOp(ir_atomic_opcode op,
+                                    builtin_available_predicate avail);
+
 #undef B0
 #undef B1
 #undef B2
@@ -1822,6 +1833,17 @@ builtin_builder::create_builtins()
    IU(findLSB)
    IU(findMSB)
    F(fma)
+
+   add_function("atomicCounter",
+                _atomicOp(ir_atomic_read, shader_atomic_counters),
+                NULL);
+   add_function("atomicCounterIncrement",
+                _atomicOp(ir_atomic_inc, shader_atomic_counters),
+                NULL);
+   add_function("atomicCounterDecrement",
+                _atomicOp(ir_atomic_dec, shader_atomic_counters),
+                NULL);
+
 #undef F
 #undef FI
 #undef FIU
@@ -3514,6 +3536,17 @@ builtin_builder::_fma(const glsl_type *type)
 
    return sig;
 }
+
+ir_function_signature *
+builtin_builder::_atomicOp(ir_atomic_opcode op,
+                           builtin_available_predicate avail)
+{
+   ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
+   MAKE_SIG(glsl_type::uint_type, avail, 1, counter);
+   body.emit(ret(atomic(op, counter)));
+   return sig;
+}
+
 /** @} */
 
 /******************************************************************************/
diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index 6a808c0..49f0f42 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -555,6 +555,21 @@ builtin_variable_generator::generate_constants()
        */
       add_const("gl_MaxTextureCoords", state->Const.MaxTextureCoords);
    }
+
+   if (state->ARB_shader_atomic_counters_enable) {
+      add_const("gl_MaxVertexAtomicCounters",
+                state->Const.MaxVertexAtomicCounters);
+      add_const("gl_MaxGeometryAtomicCounters",
+                state->Const.MaxGeometryAtomicCounters);
+      add_const("gl_MaxFragmentAtomicCounters",
+                state->Const.MaxFragmentAtomicCounters);
+      add_const("gl_MaxCombinedAtomicCounters",
+                state->Const.MaxCombinedAtomicCounters);
+      add_const("gl_MaxAtomicCounterBindings",
+                state->Const.MaxAtomicBufferBindings);
+      add_const("gl_MaxTessControlAtomicCounters", 0);
+      add_const("gl_MaxTessEvaluationAtomicCounters", 0);
+   }
 }
 
 
diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 6eaa5f9..2b4e988 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -1248,6 +1248,9 @@ glcpp_parser_create (const struct gl_extensions *extensions, int api)
 
 	      if (extensions->EXT_shader_integer_mix)
 	         add_builtin_define(parser, "GL_EXT_shader_integer_mix", 1);
+
+	      if (extensions->ARB_shader_atomic_counters)
+	         add_builtin_define(parser, "GL_ARB_shader_atomic_counters", 1);
 	   }
 	}
 
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index ff34864..d27b600 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -109,6 +109,12 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct gl_context *_ctx,
 
    this->Const.MaxDrawBuffers = ctx->Const.MaxDrawBuffers;
 
+   this->Const.MaxVertexAtomicCounters = ctx->Const.VertexProgram.MaxAtomicCounters;
+   this->Const.MaxGeometryAtomicCounters = ctx->Const.GeometryProgram.MaxAtomicCounters;
+   this->Const.MaxFragmentAtomicCounters = ctx->Const.FragmentProgram.MaxAtomicCounters;
+   this->Const.MaxCombinedAtomicCounters = ctx->Const.MaxCombinedAtomicCounters;
+   this->Const.MaxAtomicBufferBindings = ctx->Const.MaxAtomicBufferBindings;
+
    this->current_function = NULL;
    this->toplevel_ir = NULL;
    this->found_return = false;
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index d0e131a..f638d35 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -222,6 +222,13 @@ struct _mesa_glsl_parse_state {
       /* 3.00 ES */
       int MinProgramTexelOffset;
       int MaxProgramTexelOffset;
+
+      /* ARB_shader_atomic_counters */
+      unsigned MaxVertexAtomicCounters;
+      unsigned MaxGeometryAtomicCounters;
+      unsigned MaxFragmentAtomicCounters;
+      unsigned MaxCombinedAtomicCounters;
+      unsigned MaxAtomicBufferBindings;
    } Const;
 
    /**
-- 
1.8.3.4



More information about the mesa-dev mailing list