mesa: add GL_ARB_shader_atomic_counter_ops support
authorIlia Mirkin <imirkin@alum.mit.edu>
Sat, 20 Feb 2016 04:07:38 +0000 (23:07 -0500)
committerIlia Mirkin <imirkin@alum.mit.edu>
Fri, 11 Mar 2016 03:34:46 +0000 (22:34 -0500)
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/compiler/glsl/builtin_functions.cpp
src/compiler/glsl/glcpp/glcpp-parse.y
src/compiler/glsl/glsl_parser_extras.cpp
src/compiler/glsl/glsl_parser_extras.h
src/mesa/main/extensions_table.h
src/mesa/main/mtypes.h

index 10fb21b9a0df29a407588634c2c5b3feac07f5b6..ff6b628eb6488c4cd694617043b29850920f8f9e 100644 (file)
@@ -431,6 +431,12 @@ shader_atomic_counters(const _mesa_glsl_parse_state *state)
    return state->has_atomic_counters();
 }
 
+static bool
+shader_atomic_counter_ops(const _mesa_glsl_parse_state *state)
+{
+   return state->ARB_shader_atomic_counter_ops_enable;
+}
+
 static bool
 shader_clock(const _mesa_glsl_parse_state *state)
 {
@@ -792,8 +798,14 @@ private:
    B1(interpolateAtSample)
 
    ir_function_signature *_atomic_counter_intrinsic(builtin_available_predicate avail);
+   ir_function_signature *_atomic_counter_intrinsic1(builtin_available_predicate avail);
+   ir_function_signature *_atomic_counter_intrinsic2(builtin_available_predicate avail);
    ir_function_signature *_atomic_counter_op(const char *intrinsic,
                                              builtin_available_predicate avail);
+   ir_function_signature *_atomic_counter_op1(const char *intrinsic,
+                                              builtin_available_predicate avail);
+   ir_function_signature *_atomic_counter_op2(const char *intrinsic,
+                                              builtin_available_predicate avail);
 
    ir_function_signature *_atomic_intrinsic2(builtin_available_predicate avail,
                                              const glsl_type *type);
@@ -968,48 +980,59 @@ builtin_builder::create_intrinsics()
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
+                NULL);
+   add_function("__intrinsic_atomic_sub",
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_min",
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_max",
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_and",
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_or",
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_xor",
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_exchange",
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic2(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic1(shader_atomic_counter_ops),
                 NULL);
    add_function("__intrinsic_atomic_comp_swap",
                 _atomic_intrinsic3(buffer_atomics_supported,
                                    glsl_type::uint_type),
                 _atomic_intrinsic3(buffer_atomics_supported,
                                    glsl_type::int_type),
+                _atomic_counter_intrinsic2(shader_atomic_counter_ops),
                 NULL);
 
    add_image_functions(false);
@@ -2714,6 +2737,43 @@ builtin_builder::create_builtins()
                                    shader_atomic_counters),
                 NULL);
 
+   add_function("atomicCounterAddARB",
+                _atomic_counter_op1("__intrinsic_atomic_add",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterSubtractARB",
+                _atomic_counter_op1("__intrinsic_atomic_sub",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterMinARB",
+                _atomic_counter_op1("__intrinsic_atomic_min",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterMaxARB",
+                _atomic_counter_op1("__intrinsic_atomic_max",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterAndARB",
+                _atomic_counter_op1("__intrinsic_atomic_and",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterOrARB",
+                _atomic_counter_op1("__intrinsic_atomic_or",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterXorARB",
+                _atomic_counter_op1("__intrinsic_atomic_xor",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterExchangeARB",
+                _atomic_counter_op1("__intrinsic_atomic_exchange",
+                                    shader_atomic_counter_ops),
+                NULL);
+   add_function("atomicCounterCompSwapARB",
+                _atomic_counter_op2("__intrinsic_atomic_comp_swap",
+                                    shader_atomic_counter_ops),
+                NULL);
+
    add_function("atomicAdd",
                 _atomic_op2("__intrinsic_atomic_add",
                             buffer_atomics_supported,
@@ -5144,6 +5204,25 @@ builtin_builder::_atomic_counter_intrinsic(builtin_available_predicate avail)
    return sig;
 }
 
+ir_function_signature *
+builtin_builder::_atomic_counter_intrinsic1(builtin_available_predicate avail)
+{
+   ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
+   ir_variable *data = in_var(glsl_type::uint_type, "data");
+   MAKE_INTRINSIC(glsl_type::uint_type, avail, 2, counter, data);
+   return sig;
+}
+
+ir_function_signature *
+builtin_builder::_atomic_counter_intrinsic2(builtin_available_predicate avail)
+{
+   ir_variable *counter = in_var(glsl_type::atomic_uint_type, "counter");
+   ir_variable *compare = in_var(glsl_type::uint_type, "compare");
+   ir_variable *data = in_var(glsl_type::uint_type, "data");
+   MAKE_INTRINSIC(glsl_type::uint_type, avail, 3, counter, compare, data);
+   return sig;
+}
+
 ir_function_signature *
 builtin_builder::_atomic_intrinsic2(builtin_available_predicate avail,
                                     const glsl_type *type)
@@ -5179,6 +5258,37 @@ builtin_builder::_atomic_counter_op(const char *intrinsic,
    return sig;
 }
 
+ir_function_signature *
+builtin_builder::_atomic_counter_op1(const char *intrinsic,
+                                     builtin_available_predicate avail)
+{
+   ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
+   ir_variable *data = in_var(glsl_type::uint_type, "data");
+   MAKE_SIG(glsl_type::uint_type, avail, 2, counter, data);
+
+   ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
+   body.emit(call(shader->symbols->get_function(intrinsic), retval,
+                  sig->parameters));
+   body.emit(ret(retval));
+   return sig;
+}
+
+ir_function_signature *
+builtin_builder::_atomic_counter_op2(const char *intrinsic,
+                                    builtin_available_predicate avail)
+{
+   ir_variable *counter = in_var(glsl_type::atomic_uint_type, "atomic_counter");
+   ir_variable *compare = in_var(glsl_type::uint_type, "compare");
+   ir_variable *data = in_var(glsl_type::uint_type, "data");
+   MAKE_SIG(glsl_type::uint_type, avail, 3, counter, compare, data);
+
+   ir_variable *retval = body.make_temp(glsl_type::uint_type, "atomic_retval");
+   body.emit(call(shader->symbols->get_function(intrinsic), retval,
+                  sig->parameters));
+   body.emit(ret(retval));
+   return sig;
+}
+
 ir_function_signature *
 builtin_builder::_atomic_op2(const char *intrinsic,
                              builtin_available_predicate avail,
index e677811d6a77e9138bfaca53da25fb12be12f212..007b70b020d0ed8c481bc4520f37088d8f063e92 100644 (file)
@@ -2482,6 +2482,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
              if (extensions->ARB_shader_atomic_counters)
                 add_builtin_define(parser, "GL_ARB_shader_atomic_counters", 1);
 
+             if (extensions->ARB_shader_atomic_counter_ops)
+                add_builtin_define(parser, "GL_ARB_shader_atomic_counter_ops", 1);
+
              if (extensions->ARB_viewport_array)
                 add_builtin_define(parser, "GL_ARB_viewport_array", 1);
 
index 7e4a891f1dce4ad812a5024c4d411bdfb70b841e..1c6cd43cd6885a770b4497538a6d62d3aff92ec0 100644 (file)
@@ -573,6 +573,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
    EXT(ARB_gpu_shader_fp64,              true,  false,     ARB_gpu_shader_fp64),
    EXT(ARB_sample_shading,               true,  false,     ARB_sample_shading),
    EXT(ARB_separate_shader_objects,      true,  false,     dummy_true),
+   EXT(ARB_shader_atomic_counter_ops,    true,  false,     ARB_shader_atomic_counter_ops),
    EXT(ARB_shader_atomic_counters,       true,  false,     ARB_shader_atomic_counters),
    EXT(ARB_shader_bit_encoding,          true,  false,     ARB_shader_bit_encoding),
    EXT(ARB_shader_clock,                 true,  false,     ARB_shader_clock),
index 74825a0bd3562987106ff763e0cdd2c793affe73..12a3a46928c91503481a84386b39379ac8ef2c21 100644 (file)
@@ -533,6 +533,8 @@ struct _mesa_glsl_parse_state {
    bool ARB_sample_shading_warn;
    bool ARB_separate_shader_objects_enable;
    bool ARB_separate_shader_objects_warn;
+   bool ARB_shader_atomic_counter_ops_enable;
+   bool ARB_shader_atomic_counter_ops_warn;
    bool ARB_shader_atomic_counters_enable;
    bool ARB_shader_atomic_counters_warn;
    bool ARB_shader_bit_encoding_enable;
index 674eb5c4ebfdc71ec66179545356c89b3b20e47d..54a5bb057a3be7c12d284464dc4a505e4a1dc46d 100644 (file)
@@ -96,6 +96,7 @@ EXT(ARB_sampler_objects                     , dummy_true
 EXT(ARB_seamless_cube_map                   , ARB_seamless_cube_map                  , GLL, GLC,  x ,  x , 2009)
 EXT(ARB_seamless_cubemap_per_texture        , AMD_seamless_cubemap_per_texture       , GLL, GLC,  x ,  x , 2013)
 EXT(ARB_separate_shader_objects             , dummy_true                             , GLL, GLC,  x ,  x , 2010)
+EXT(ARB_shader_atomic_counter_ops           , ARB_shader_atomic_counter_ops          , GLL, GLC,  x ,  x , 2015)
 EXT(ARB_shader_atomic_counters              , ARB_shader_atomic_counters             , GLL, GLC,  x ,  x , 2011)
 EXT(ARB_shader_bit_encoding                 , ARB_shader_bit_encoding                , GLL, GLC,  x ,  x , 2010)
 EXT(ARB_shader_clock                        , ARB_shader_clock                       , GLL, GLC,  x ,  x , 2015)
index b99f41cdc42e216020fd50083991482fd5d88870..5d8bfe4bb09e0abe1a293cc6c34e1c72aa32ec51 100644 (file)
@@ -3815,6 +3815,7 @@ struct gl_extensions
    GLboolean ARB_query_buffer_object;
    GLboolean ARB_sample_shading;
    GLboolean ARB_seamless_cube_map;
+   GLboolean ARB_shader_atomic_counter_ops;
    GLboolean ARB_shader_atomic_counters;
    GLboolean ARB_shader_bit_encoding;
    GLboolean ARB_shader_clock;