[Mesa-dev] [PATCH 1/5] mesa: hook up core bits of GL_ARB_shader_group_vote
Ian Romanick
idr at freedesktop.org
Mon Jun 6 22:00:19 UTC 2016
On 05/29/2016 11:01 AM, Ilia Mirkin wrote:
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
> src/compiler/glsl/builtin_functions.cpp | 22 ++++++++++++++++++++++
> src/compiler/glsl/glcpp/glcpp-parse.y | 3 +++
> src/compiler/glsl/glsl_parser_extras.cpp | 1 +
> src/compiler/glsl/glsl_parser_extras.h | 2 ++
> src/compiler/glsl/ir.cpp | 6 ++++++
> src/compiler/glsl/ir.h | 9 ++++++++-
> src/compiler/glsl/ir_validate.cpp | 8 ++++++++
> .../dri/i965/brw_fs_channel_expressions.cpp | 5 +++++
> src/mesa/main/extensions_table.h | 1 +
> src/mesa/main/mtypes.h | 1 +
> src/mesa/program/ir_to_mesa.cpp | 3 +++
> src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 4 ++++
> 12 files changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
> index edd02bb..db0dcb6 100644
> --- a/src/compiler/glsl/builtin_functions.cpp
> +++ b/src/compiler/glsl/builtin_functions.cpp
> @@ -528,6 +528,12 @@ barrier_supported(const _mesa_glsl_parse_state *state)
> state->stage == MESA_SHADER_TESS_CTRL;
> }
>
> +static bool
> +vote(const _mesa_glsl_parse_state *state)
> +{
> + return state->ARB_shader_group_vote_enable;
> +}
> +
> /** @} */
>
> /******************************************************************************/
> @@ -853,6 +859,8 @@ private:
> 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
> @@ -2935,6 +2943,10 @@ builtin_builder::create_builtins()
> glsl_type::uvec2_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);
> +
> #undef F
> #undef FI
> #undef FIUD
> @@ -5576,6 +5588,16 @@ builtin_builder::_shader_clock(builtin_available_predicate avail,
> return sig;
> }
>
> +ir_function_signature *
> +builtin_builder::_vote(enum ir_expression_operation opcode)
> +{
> + 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)));
> + return sig;
> +}
> +
> /** @} */
>
> /******************************************************************************/
> diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
> index 4022727..2cfa6a6 100644
> --- a/src/compiler/glsl/glcpp/glcpp-parse.y
> +++ b/src/compiler/glsl/glcpp/glcpp-parse.y
> @@ -2467,6 +2467,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
>
> if (extensions->ARB_cull_distance)
> add_builtin_define(parser, "GL_ARB_cull_distance", 1);
> +
> + if (extensions->ARB_shader_group_vote)
> + add_builtin_define(parser, "GL_ARB_shader_group_vote", 1);
> }
> }
>
> diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp
> index 843998d..0db5be0 100644
> --- a/src/compiler/glsl/glsl_parser_extras.cpp
> +++ b/src/compiler/glsl/glsl_parser_extras.cpp
> @@ -594,6 +594,7 @@ static const _mesa_glsl_extension _mesa_glsl_supported_extensions[] = {
> EXT(ARB_shader_bit_encoding, true, false, ARB_shader_bit_encoding),
> EXT(ARB_shader_clock, true, false, ARB_shader_clock),
> EXT(ARB_shader_draw_parameters, true, false, ARB_shader_draw_parameters),
> + EXT(ARB_shader_group_vote, true, false, ARB_shader_group_vote),
> EXT(ARB_shader_image_load_store, true, false, ARB_shader_image_load_store),
> EXT(ARB_shader_image_size, true, false, ARB_shader_image_size),
> EXT(ARB_shader_precision, true, false, ARB_shader_precision),
> diff --git a/src/compiler/glsl/glsl_parser_extras.h b/src/compiler/glsl/glsl_parser_extras.h
> index a0c1903..8c43292 100644
> --- a/src/compiler/glsl/glsl_parser_extras.h
> +++ b/src/compiler/glsl/glsl_parser_extras.h
> @@ -575,6 +575,8 @@ struct _mesa_glsl_parse_state {
> bool ARB_shader_clock_warn;
> bool ARB_shader_draw_parameters_enable;
> bool ARB_shader_draw_parameters_warn;
> + bool ARB_shader_group_vote_enable;
> + bool ARB_shader_group_vote_warn;
> bool ARB_shader_image_load_store_enable;
> bool ARB_shader_image_load_store_warn;
> bool ARB_shader_image_size_enable;
> diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
> index 5bb3ac3..90b8f50 100644
> --- a/src/compiler/glsl/ir.cpp
> +++ b/src/compiler/glsl/ir.cpp
> @@ -341,6 +341,12 @@ ir_expression::ir_expression(int op, ir_rvalue *op0)
> this->type = glsl_type::int_type;
> break;
>
> + case ir_unop_vote_any:
> + case ir_unop_vote_all:
> + case ir_unop_vote_eq:
> + this->type = glsl_type::bool_type;
> + break;
> +
> default:
> assert(!"not reached: missing automatic type setup for ir_expression");
> this->type = op0->type;
> diff --git a/src/compiler/glsl/ir.h b/src/compiler/glsl/ir.h
> index e8efd27..b82f26b 100644
> --- a/src/compiler/glsl/ir.h
> +++ b/src/compiler/glsl/ir.h
> @@ -1478,9 +1478,16 @@ enum ir_expression_operation {
> ir_unop_ssbo_unsized_array_length,
>
> /**
> + * Vote among threads on the value of the boolean argument.
> + */
> + ir_unop_vote_any,
> + ir_unop_vote_all,
> + ir_unop_vote_eq,
> +
> + /**
> * A sentinel marking the last of the unary operations.
> */
> - ir_last_unop = ir_unop_ssbo_unsized_array_length,
> + ir_last_unop = ir_unop_vote_eq,
>
> ir_binop_add,
> ir_binop_sub,
> diff --git a/src/compiler/glsl/ir_validate.cpp b/src/compiler/glsl/ir_validate.cpp
> index 757f17c..bd69cd2 100644
> --- a/src/compiler/glsl/ir_validate.cpp
> +++ b/src/compiler/glsl/ir_validate.cpp
> @@ -453,6 +453,14 @@ ir_validate::visit_leave(ir_expression *ir)
> assert(ir->operands[0]->type->base_type == GLSL_TYPE_SUBROUTINE);
> assert(ir->type->base_type == GLSL_TYPE_INT);
> break;
> +
> + case ir_unop_vote_any:
> + case ir_unop_vote_all:
> + case ir_unop_vote_eq:
> + assert(ir->type->base_type == GLSL_TYPE_BOOL);
> + assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL);
The inputs and output are always scalar Boolean, so I think it's better
to check ir->type == glsl_type::bool_type. With that changed, this patch is
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
One other side comment below.
> + break;
> +
> case ir_binop_add:
> case ir_binop_sub:
> case ir_binop_mul:
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> index 3d2e619..5eac8d4 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_channel_expressions.cpp
> @@ -433,6 +433,11 @@ ir_channel_expressions_visitor::visit_leave(ir_assignment *ir)
> case ir_unop_frexp_sig:
> case ir_unop_frexp_exp:
> unreachable("should have been lowered by lower_instructions");
> +
> + case ir_unop_vote_any:
> + case ir_unop_vote_all:
> + case ir_unop_vote_eq:
> + unreachable("unsupported");
> }
>
> ir->remove();
> diff --git a/src/mesa/main/extensions_table.h b/src/mesa/main/extensions_table.h
> index b715f7c..e3a99ec 100644
> --- a/src/mesa/main/extensions_table.h
> +++ b/src/mesa/main/extensions_table.h
> @@ -105,6 +105,7 @@ EXT(ARB_shader_atomic_counters , ARB_shader_atomic_counters
> EXT(ARB_shader_bit_encoding , ARB_shader_bit_encoding , GLL, GLC, x , x , 2010)
> EXT(ARB_shader_clock , ARB_shader_clock , GLL, GLC, x , x , 2015)
> EXT(ARB_shader_draw_parameters , ARB_shader_draw_parameters , GLL, GLC, x , x , 2013)
> +EXT(ARB_shader_group_vote , ARB_shader_group_vote , GLL, GLC, x , x , 2013)
> EXT(ARB_shader_image_load_store , ARB_shader_image_load_store , GLL, GLC, x , x , 2011)
> EXT(ARB_shader_image_size , ARB_shader_image_size , GLL, GLC, x , x , 2012)
> EXT(ARB_shader_objects , dummy_true , GLL, GLC, x , x , 2002)
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 2233526..f61315b 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -3831,6 +3831,7 @@ struct gl_extensions
> GLboolean ARB_shader_bit_encoding;
> GLboolean ARB_shader_clock;
> GLboolean ARB_shader_draw_parameters;
> + GLboolean ARB_shader_group_vote;
> GLboolean ARB_shader_image_load_store;
> GLboolean ARB_shader_image_size;
> GLboolean ARB_shader_precision;
> diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
> index 7f24a9e..b10648b 100644
> --- a/src/mesa/program/ir_to_mesa.cpp
> +++ b/src/mesa/program/ir_to_mesa.cpp
> @@ -1375,6 +1375,9 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
> case ir_unop_dFdy_fine:
> case ir_unop_subroutine_to_int:
> case ir_unop_get_buffer_size:
> + case ir_unop_vote_any:
> + case ir_unop_vote_all:
> + case ir_unop_vote_eq:
> assert(!"not supported");
I'd also support a follow-on patch that converts this to unreachable().
> break;
>
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index aa443a5..0c7400c 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -2249,6 +2249,10 @@ glsl_to_tgsi_visitor::visit_expression(ir_expression* ir, st_src_reg *op)
> case ir_binop_carry:
> case ir_binop_borrow:
> case ir_unop_ssbo_unsized_array_length:
> +
> + case ir_unop_vote_any:
> + case ir_unop_vote_all:
> + case ir_unop_vote_eq:
> /* This operation is not supported, or should have already been handled.
> */
> assert(!"Invalid ir opcode in glsl_to_tgsi_visitor::visit()");
>
More information about the mesa-dev
mailing list