[Mesa-dev] [PATCH 1/3] glsl: Add new barrier functions for compute shaders
Jordan Justen
jordan.l.justen at intel.com
Tue Nov 3 14:47:55 PST 2015
When these functions are called in GLSL code, we create an intrinsic
function call:
* groupMemoryBarrier => __intrinsic_group_memory_barrier
* memoryBarrierAtomicCounter => __intrinsic_memory_barrier_atomic_counter
* memoryBarrierBuffer => __intrinsic_memory_barrier_buffer
* memoryBarrierImage => __intrinsic_memory_barrier_image
* memoryBarrierShared => __intrinsic_memory_barrier_shared
Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
---
Notes:
git://people.freedesktop.org/~jljusten/mesa cs-shader-barrier-funcs-v1
http://patchwork.freedesktop.org/bundle/jljusten/cs-shader-barrier-funcs-v1
Tested with the OpenGLES 3.1 CTS test suite on my cs branch. With
these patches reverted, these tests fail:
* ES31-CTS.compute_shader.work-group-size
* ES31-CTS.compute_shader.shared-simple
* ES31-CTS.compute_shader.shared-struct
* ES31-CTS.compute_shader.atomic-case1
* ES31-CTS.compute_shader.shared-indexing
src/glsl/builtin_functions.cpp | 134 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 133 insertions(+), 1 deletion(-)
diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 509a57b..2bb7bcb 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -459,9 +459,15 @@ fp64(const _mesa_glsl_parse_state *state)
}
static bool
+compute_shader(const _mesa_glsl_parse_state *state)
+{
+ return state->stage == MESA_SHADER_COMPUTE;
+}
+
+static bool
barrier_supported(const _mesa_glsl_parse_state *state)
{
- return state->stage == MESA_SHADER_COMPUTE ||
+ return compute_shader(state) ||
state->stage == MESA_SHADER_TESS_CTRL;
}
@@ -715,6 +721,11 @@ private:
ir_function_signature *_EndStreamPrimitive(builtin_available_predicate avail,
const glsl_type *stream_type);
B0(barrier)
+ B0(groupMemoryBarrier)
+ B0(memoryBarrierAtomicCounter)
+ B0(memoryBarrierBuffer)
+ B0(memoryBarrierImage)
+ B0(memoryBarrierShared)
BA2(textureQueryLod);
B1(textureQueryLevels);
@@ -787,6 +798,26 @@ private:
builtin_available_predicate avail);
ir_function_signature *_memory_barrier(
builtin_available_predicate avail);
+ ir_function_signature *_group_memory_barrier_intrinsic(
+ builtin_available_predicate avail);
+ ir_function_signature *_group_memory_barrier(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_atomic_counter_intrinsic(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_atomic_counter(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_buffer_intrinsic(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_buffer(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_image_intrinsic(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_image(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_shared_intrinsic(
+ builtin_available_predicate avail);
+ ir_function_signature *_memory_barrier_shared(
+ builtin_available_predicate avail);
ir_function_signature *_shader_clock_intrinsic(builtin_available_predicate avail,
const glsl_type *type);
@@ -968,6 +999,22 @@ builtin_builder::create_intrinsics()
_shader_clock_intrinsic(shader_clock,
glsl_type::uvec2_type),
NULL);
+
+ add_function("__intrinsic_group_memory_barrier",
+ _group_memory_barrier_intrinsic(compute_shader),
+ NULL);
+ add_function("__intrinsic_memory_barrier_atomic_counter",
+ _memory_barrier_atomic_counter_intrinsic(compute_shader),
+ NULL);
+ add_function("__intrinsic_memory_barrier_buffer",
+ _memory_barrier_buffer_intrinsic(compute_shader),
+ NULL);
+ add_function("__intrinsic_memory_barrier_image",
+ _memory_barrier_image_intrinsic(compute_shader),
+ NULL);
+ add_function("__intrinsic_memory_barrier_shared",
+ _memory_barrier_shared_intrinsic(compute_shader),
+ NULL);
}
/**
@@ -2081,6 +2128,11 @@ builtin_builder::create_builtins()
_EndStreamPrimitive(gs_streams, glsl_type::int_type),
NULL);
add_function("barrier", _barrier(), NULL);
+ add_function("groupMemoryBarrier", _group_memory_barrier(compute_shader), NULL);
+ add_function("memoryBarrierAtomicCounter", _memory_barrier_atomic_counter(compute_shader), NULL);
+ add_function("memoryBarrierBuffer", _memory_barrier_buffer(compute_shader), NULL);
+ add_function("memoryBarrierImage", _memory_barrier_image(compute_shader), NULL);
+ add_function("memoryBarrierShared", _memory_barrier_shared(compute_shader), NULL);
add_function("textureQueryLOD",
_textureQueryLod(texture_query_lod, glsl_type::sampler1D_type, glsl_type::float_type),
@@ -5294,6 +5346,86 @@ builtin_builder::_shader_clock(builtin_available_predicate avail,
return sig;
}
+ir_function_signature *
+builtin_builder::_group_memory_barrier_intrinsic(builtin_available_predicate avail)
+{
+ MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_group_memory_barrier(builtin_available_predicate avail)
+{
+ MAKE_SIG(glsl_type::void_type, avail, 0);
+ body.emit(call(shader->symbols->get_function("__intrinsic_group_memory_barrier"),
+ NULL, sig->parameters));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_atomic_counter_intrinsic(builtin_available_predicate avail)
+{
+ MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_atomic_counter(builtin_available_predicate avail)
+{
+ MAKE_SIG(glsl_type::void_type, avail, 0);
+ body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier_atomic_counter"),
+ NULL, sig->parameters));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_buffer_intrinsic(builtin_available_predicate avail)
+{
+ MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_buffer(builtin_available_predicate avail)
+{
+ MAKE_SIG(glsl_type::void_type, avail, 0);
+ body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier_buffer"),
+ NULL, sig->parameters));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_image_intrinsic(builtin_available_predicate avail)
+{
+ MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_image(builtin_available_predicate avail)
+{
+ MAKE_SIG(glsl_type::void_type, avail, 0);
+ body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier_image"),
+ NULL, sig->parameters));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_shared_intrinsic(builtin_available_predicate avail)
+{
+ MAKE_INTRINSIC(glsl_type::void_type, avail, 0);
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_memory_barrier_shared(builtin_available_predicate avail)
+{
+ MAKE_SIG(glsl_type::void_type, avail, 0);
+ body.emit(call(shader->symbols->get_function("__intrinsic_memory_barrier_shared"),
+ NULL, sig->parameters));
+ return sig;
+}
+
/** @} */
/******************************************************************************/
--
2.6.2
More information about the mesa-dev
mailing list