[Mesa-dev] [PATCH 04/19] glsl: add ARB_shader_ballot builtin functions
Nicolai Hähnle
nhaehnle at gmail.com
Fri Mar 31 17:14:04 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/compiler/glsl/builtin_functions.cpp | 77 +++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 683217d..5351b98 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -460,20 +460,26 @@ 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_ballot(const _mesa_glsl_parse_state *state)
+{
+ return state->ARB_shader_ballot_enable;
+}
+
+static bool
shader_clock(const _mesa_glsl_parse_state *state)
{
return state->ARB_shader_clock_enable;
}
static bool
shader_clock_int64(const _mesa_glsl_parse_state *state)
{
return state->ARB_shader_clock_enable &&
state->ARB_gpu_shader_int64_enable;
@@ -915,20 +921,24 @@ private:
unsigned num_arguments,
unsigned flags,
enum ir_intrinsic_id id);
ir_function_signature *_memory_barrier_intrinsic(
builtin_available_predicate avail,
enum ir_intrinsic_id id);
ir_function_signature *_memory_barrier(const char *intrinsic_name,
builtin_available_predicate avail);
+ ir_function_signature *_ballot();
+ ir_function_signature *_read_first_invocation(const glsl_type *type);
+ ir_function_signature *_read_invocation(const glsl_type *type);
+
ir_function_signature *_shader_clock_intrinsic(builtin_available_predicate avail,
const glsl_type *type);
ir_function_signature *_shader_clock(builtin_available_predicate avail,
const glsl_type *type);
ir_function_signature *_vote(enum ir_expression_operation opcode);
#undef B0
#undef B1
#undef B2
@@ -3085,20 +3095,56 @@ builtin_builder::create_builtins()
NULL);
add_function("memoryBarrierImage",
_memory_barrier("__intrinsic_memory_barrier_image",
compute_shader_supported),
NULL);
add_function("memoryBarrierShared",
_memory_barrier("__intrinsic_memory_barrier_shared",
compute_shader),
NULL);
+ add_function("ballotARB", _ballot(), NULL);
+
+ add_function("readInvocationARB",
+ _read_invocation(glsl_type::float_type),
+ _read_invocation(glsl_type::vec2_type),
+ _read_invocation(glsl_type::vec3_type),
+ _read_invocation(glsl_type::vec4_type),
+
+ _read_invocation(glsl_type::int_type),
+ _read_invocation(glsl_type::ivec2_type),
+ _read_invocation(glsl_type::ivec3_type),
+ _read_invocation(glsl_type::ivec4_type),
+
+ _read_invocation(glsl_type::uint_type),
+ _read_invocation(glsl_type::uvec2_type),
+ _read_invocation(glsl_type::uvec3_type),
+ _read_invocation(glsl_type::uvec4_type),
+ NULL);
+
+ add_function("readFirstInvocationARB",
+ _read_first_invocation(glsl_type::float_type),
+ _read_first_invocation(glsl_type::vec2_type),
+ _read_first_invocation(glsl_type::vec3_type),
+ _read_first_invocation(glsl_type::vec4_type),
+
+ _read_first_invocation(glsl_type::int_type),
+ _read_first_invocation(glsl_type::ivec2_type),
+ _read_first_invocation(glsl_type::ivec3_type),
+ _read_first_invocation(glsl_type::ivec4_type),
+
+ _read_first_invocation(glsl_type::uint_type),
+ _read_first_invocation(glsl_type::uvec2_type),
+ _read_first_invocation(glsl_type::uvec3_type),
+ _read_first_invocation(glsl_type::uvec4_type),
+ NULL);
+
add_function("clock2x32ARB",
_shader_clock(shader_clock,
glsl_type::uvec2_type),
NULL);
add_function("clockARB",
_shader_clock(shader_clock_int64,
glsl_type::uint64_t_type),
NULL);
@@ -5927,20 +5973,51 @@ ir_function_signature *
builtin_builder::_memory_barrier(const char *intrinsic_name,
builtin_available_predicate avail)
{
MAKE_SIG(glsl_type::void_type, avail, 0);
body.emit(call(shader->symbols->get_function(intrinsic_name),
NULL, sig->parameters));
return sig;
}
ir_function_signature *
+builtin_builder::_ballot()
+{
+ ir_variable *value = in_var(glsl_type::bool_type, "value");
+
+ MAKE_SIG(glsl_type::uint64_t_type, shader_ballot, 1, value);
+ body.emit(ret(expr(ir_unop_ballot, value)));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_read_first_invocation(const glsl_type *type)
+{
+ ir_variable *value = in_var(type, "value");
+
+ MAKE_SIG(type, shader_ballot, 1, value);
+ body.emit(ret(expr(ir_unop_read_first_invocation, value)));
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_read_invocation(const glsl_type *type)
+{
+ ir_variable *value = in_var(type, "value");
+ ir_variable *invocation = in_var(glsl_type::uint_type, "invocation");
+
+ MAKE_SIG(type, shader_ballot, 2, value, invocation);
+ body.emit(ret(expr(ir_binop_read_invocation, value, invocation)));
+ return sig;
+}
+
+ir_function_signature *
builtin_builder::_shader_clock_intrinsic(builtin_available_predicate avail,
const glsl_type *type)
{
MAKE_INTRINSIC(type, ir_intrinsic_shader_clock, avail, 0);
return sig;
}
ir_function_signature *
builtin_builder::_shader_clock(builtin_available_predicate avail,
const glsl_type *type)
--
2.9.3
More information about the mesa-dev
mailing list