[Mesa-dev] [PATCH v3 (part2) 35/56] glsl: Add atomic functions from ARB_shader_storage_buffer_object
Iago Toral Quiroga
itoral at igalia.com
Tue Jul 14 00:46:37 PDT 2015
---
src/glsl/builtin_functions.cpp | 185 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 185 insertions(+)
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 4ba6d6f..c8ecefe 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -386,6 +386,12 @@ shader_atomic_counters(const _mesa_glsl_parse_state *state)
}
static bool
+shader_storage_buffer_object(const _mesa_glsl_parse_state *state)
+{
+ return state->ARB_shader_storage_buffer_object_enable;
+}
+
+static bool
shader_trinary_minmax(const _mesa_glsl_parse_state *state)
{
return state->AMD_shader_trinary_minmax_enable;
@@ -700,6 +706,17 @@ private:
ir_function_signature *_atomic_counter_op(const char *intrinsic,
builtin_available_predicate avail);
+ ir_function_signature *_atomic_ssbo_intrinsic2(builtin_available_predicate avail,
+ const glsl_type *type);
+ ir_function_signature *_atomic_ssbo_op2(const char *intrinsic,
+ builtin_available_predicate avail,
+ const glsl_type *type);
+ ir_function_signature *_atomic_ssbo_intrinsic3(builtin_available_predicate avail,
+ const glsl_type *type);
+ ir_function_signature *_atomic_ssbo_op3(const char *intrinsic,
+ builtin_available_predicate avail,
+ const glsl_type *type);
+
B1(min3)
B1(max3)
B1(mid3)
@@ -834,6 +851,55 @@ builtin_builder::create_intrinsics()
_atomic_counter_intrinsic(shader_atomic_counters),
NULL);
+ add_function("__intrinsic_ssbo_atomic_add",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_min",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_max",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_and",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_or",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_xor",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_exchange",
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic2(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("__intrinsic_ssbo_atomic_comp_swap",
+ _atomic_ssbo_intrinsic3(shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_intrinsic3(shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+
add_image_functions(false);
add_function("__intrinsic_memory_barrier",
@@ -2459,6 +2525,71 @@ builtin_builder::create_builtins()
shader_atomic_counters),
NULL);
+ add_function("atomicAdd",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_add",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_add",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicMin",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_min",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_min",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicMax",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_max",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_max",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicAnd",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_and",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_and",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicOr",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_or",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_or",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicXor",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_xor",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_xor",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicExchange",
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_exchange",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op2("__intrinsic_ssbo_atomic_exchange",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+ add_function("atomicCompSwap",
+ _atomic_ssbo_op3("__intrinsic_ssbo_atomic_comp_swap",
+ shader_storage_buffer_object,
+ glsl_type::uint_type),
+ _atomic_ssbo_op3("__intrinsic_ssbo_atomic_comp_swap",
+ shader_storage_buffer_object,
+ glsl_type::int_type),
+ NULL);
+
add_function("min3",
_min3(glsl_type::float_type),
_min3(glsl_type::vec2_type),
@@ -4714,6 +4845,27 @@ builtin_builder::_atomic_counter_intrinsic(builtin_available_predicate avail)
}
ir_function_signature *
+builtin_builder::_atomic_ssbo_intrinsic2(builtin_available_predicate avail,
+ const glsl_type *type)
+{
+ ir_variable *atomic = in_var(type, "atomic");
+ ir_variable *data = in_var(type, "data");
+ MAKE_INTRINSIC(type, avail, 2, atomic, data);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_atomic_ssbo_intrinsic3(builtin_available_predicate avail,
+ const glsl_type *type)
+{
+ ir_variable *atomic = in_var(type, "atomic");
+ ir_variable *data1 = in_var(type, "data1");
+ ir_variable *data2 = in_var(type, "data2");
+ MAKE_INTRINSIC(type, avail, 3, atomic, data1, data2);
+ return sig;
+}
+
+ir_function_signature *
builtin_builder::_atomic_counter_op(const char *intrinsic,
builtin_available_predicate avail)
{
@@ -4728,6 +4880,39 @@ builtin_builder::_atomic_counter_op(const char *intrinsic,
}
ir_function_signature *
+builtin_builder::_atomic_ssbo_op2(const char *intrinsic,
+ builtin_available_predicate avail,
+ const glsl_type *type)
+{
+ ir_variable *atomic = in_var(type, "atomic_var");
+ ir_variable *data = in_var(type, "atomic_data");
+ MAKE_SIG(type, avail, 2, atomic, data);
+
+ ir_variable *retval = body.make_temp(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_ssbo_op3(const char *intrinsic,
+ builtin_available_predicate avail,
+ const glsl_type *type)
+{
+ ir_variable *atomic = in_var(type, "atomic_var");
+ ir_variable *data1 = in_var(type, "atomic_data1");
+ ir_variable *data2 = in_var(type, "atomic_data2");
+ MAKE_SIG(type, avail, 3, atomic, data1, data2);
+
+ ir_variable *retval = body.make_temp(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::_min3(const glsl_type *type)
{
ir_variable *x = in_var(type, "x");
--
1.9.1
More information about the mesa-dev
mailing list