From 075a5742bf65b35d19a1d86346db1c02f6dba9b2 Mon Sep 17 00:00:00 2001 From: Ilia Mirkin Date: Fri, 19 Feb 2016 23:07:38 -0500 Subject: mesa: add GL_ARB_shader_atomic_counter_ops support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ilia Mirkin Reviewed-by: Nicolai Hähnle --- src/compiler/glsl/builtin_functions.cpp | 110 +++++++++++++++++++++++++++++++ src/compiler/glsl/glcpp/glcpp-parse.y | 3 + src/compiler/glsl/glsl_parser_extras.cpp | 1 + src/compiler/glsl/glsl_parser_extras.h | 2 + 4 files changed, 116 insertions(+) (limited to 'src/compiler') diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp index 10fb21b9a0d..ff6b628eb64 100644 --- a/src/compiler/glsl/builtin_functions.cpp +++ b/src/compiler/glsl/builtin_functions.cpp @@ -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, diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y index e677811d6a7..007b70b020d 100644 --- a/src/compiler/glsl/glcpp/glcpp-parse.y +++ b/src/compiler/glsl/glcpp/glcpp-parse.y @@ -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); diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 7e4a891f1dc..1c6cd43cd68 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -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), diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h index 74825a0bd35..12a3a46928c 100644 --- a/src/compiler/glsl/glsl_parser_extras.h +++ b/src/compiler/glsl/glsl_parser_extras.h @@ -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; -- cgit v1.2.3