[Mesa-dev] [PATCH 3/7] glsl: implement arb_shader_group_vote builtins via intrinsics

Nicolai Hähnle nhaehnle at gmail.com
Wed Apr 19 08:56:49 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/compiler/glsl/builtin_functions.cpp | 38 +++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
index 5d62d9f..6a45e5a 100644
--- a/src/compiler/glsl/builtin_functions.cpp
+++ b/src/compiler/glsl/builtin_functions.cpp
@@ -950,21 +950,23 @@ private:
 
    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);
+   ir_function_signature *_vote_intrinsic(builtin_available_predicate avail,
+                                          enum ir_intrinsic_id id);
+   ir_function_signature *_vote(const char *intrinsic_name);
 
 #undef B0
 #undef B1
 #undef B2
 #undef B3
 #undef BA1
 #undef BA2
    /** @} */
 };
 
@@ -1183,20 +1185,30 @@ builtin_builder::create_intrinsics()
                 NULL);
    add_function("__intrinsic_memory_barrier_shared",
                 _memory_barrier_intrinsic(compute_shader,
                                           ir_intrinsic_memory_barrier_shared),
                 NULL);
 
    add_function("__intrinsic_shader_clock",
                 _shader_clock_intrinsic(shader_clock,
                                         glsl_type::uvec2_type),
                 NULL);
+
+   add_function("__intrinsic_vote_all",
+                _vote_intrinsic(vote, ir_intrinsic_vote_all),
+                NULL);
+   add_function("__intrinsic_vote_any",
+                _vote_intrinsic(vote, ir_intrinsic_vote_any),
+                NULL);
+   add_function("__intrinsic_vote_eq",
+                _vote_intrinsic(vote, ir_intrinsic_vote_eq),
+                NULL);
 }
 
 /**
  * Create ir_function and ir_function_signature objects for each built-in.
  *
  * Contains a list of every available built-in.
  */
 void
 builtin_builder::create_builtins()
 {
@@ -3161,23 +3173,23 @@ builtin_builder::create_builtins()
    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);
 
-   add_function("anyInvocationARB", _vote(ir_unop_vote_any), NULL);
-   add_function("allInvocationsARB", _vote(ir_unop_vote_all), NULL);
-   add_function("allInvocationsEqualARB", _vote(ir_unop_vote_eq), NULL);
+   add_function("anyInvocationARB", _vote("__intrinsic_vote_any"), NULL);
+   add_function("allInvocationsARB", _vote("__intrinsic_vote_all"), NULL);
+   add_function("allInvocationsEqualARB", _vote("__intrinsic_vote_eq"), NULL);
 
    add_function("__builtin_idiv64",
                 generate_ir::idiv64(mem_ctx, integer_functions_supported),
                 NULL);
 
    add_function("__builtin_imod64",
                 generate_ir::imod64(mem_ctx, integer_functions_supported),
                 NULL);
 
    add_function("__builtin_sign64",
@@ -6055,26 +6067,40 @@ builtin_builder::_shader_clock(builtin_available_predicate avail,
    if (type == glsl_type::uint64_t_type) {
       body.emit(ret(expr(ir_unop_pack_uint_2x32, retval)));
    } else {
       body.emit(ret(retval));
    }
 
    return sig;
 }
 
 ir_function_signature *
-builtin_builder::_vote(enum ir_expression_operation opcode)
+builtin_builder::_vote_intrinsic(builtin_available_predicate avail,
+                                 enum ir_intrinsic_id id)
+{
+   ir_variable *value = in_var(glsl_type::bool_type, "value");
+   MAKE_INTRINSIC(glsl_type::bool_type, id, avail, 1, value);
+   return sig;
+}
+
+ir_function_signature *
+builtin_builder::_vote(const char *intrinsic_name)
 {
    ir_variable *value = in_var(glsl_type::bool_type, "value");
 
    MAKE_SIG(glsl_type::bool_type, vote, 1, value);
-   body.emit(ret(expr(opcode, value)));
+
+   ir_variable *retval = body.make_temp(glsl_type::bool_type, "retval");
+
+   body.emit(call(shader->symbols->get_function(intrinsic_name),
+                  retval, sig->parameters));
+   body.emit(ret(retval));
    return sig;
 }
 
 /** @} */
 
 /******************************************************************************/
 
 /* The singleton instance of builtin_builder. */
 static builtin_builder builtins;
 static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
-- 
2.9.3



More information about the mesa-dev mailing list