glsl: Add built-in functions for INTEL_shader_integer_functions2

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/767>
This commit is contained in:
Ian Romanick 2018-09-10 23:17:49 -07:00 committed by Marge Bot
parent 5eda9f5832
commit cb518df775
1 changed files with 311 additions and 0 deletions

View File

@ -826,6 +826,18 @@ demote_to_helper_invocation(const _mesa_glsl_parse_state *state)
return state->EXT_demote_to_helper_invocation_enable;
}
static bool
shader_integer_functions2(const _mesa_glsl_parse_state *state)
{
return state->INTEL_shader_integer_functions2_enable;
}
static bool
shader_integer_functions2_int64(const _mesa_glsl_parse_state *state)
{
return state->INTEL_shader_integer_functions2_enable && state->has_int64();
}
static bool
is_nir(const _mesa_glsl_parse_state *state)
{
@ -1115,13 +1127,21 @@ private:
B1(bitCount)
B1(findLSB)
B1(findMSB)
BA1(countLeadingZeros)
BA1(countTrailingZeros)
BA1(fma)
B2(ldexp)
B2(frexp)
B2(dfrexp)
B1(uaddCarry)
B1(usubBorrow)
BA1(addSaturate)
BA1(subtractSaturate)
BA1(absoluteDifference)
BA1(average)
BA1(averageRounded)
B1(mulExtended)
BA1(multiply32x16)
B1(interpolateAtCentroid)
B1(interpolateAtOffset)
B1(interpolateAtSample)
@ -4292,6 +4312,227 @@ builtin_builder::create_builtins()
generate_ir::umul64(mem_ctx, integer_functions_supported),
NULL);
add_function("countLeadingZeros",
_countLeadingZeros(shader_integer_functions2,
glsl_type::uint_type),
_countLeadingZeros(shader_integer_functions2,
glsl_type::uvec2_type),
_countLeadingZeros(shader_integer_functions2,
glsl_type::uvec3_type),
_countLeadingZeros(shader_integer_functions2,
glsl_type::uvec4_type),
NULL);
add_function("countTrailingZeros",
_countTrailingZeros(shader_integer_functions2,
glsl_type::uint_type),
_countTrailingZeros(shader_integer_functions2,
glsl_type::uvec2_type),
_countTrailingZeros(shader_integer_functions2,
glsl_type::uvec3_type),
_countTrailingZeros(shader_integer_functions2,
glsl_type::uvec4_type),
NULL);
add_function("absoluteDifference",
_absoluteDifference(shader_integer_functions2,
glsl_type::int_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::ivec2_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::ivec3_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::ivec4_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::uint_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::uvec2_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::uvec3_type),
_absoluteDifference(shader_integer_functions2,
glsl_type::uvec4_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::int64_t_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::i64vec2_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::i64vec3_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::i64vec4_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::uint64_t_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::u64vec2_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::u64vec3_type),
_absoluteDifference(shader_integer_functions2_int64,
glsl_type::u64vec4_type),
NULL);
add_function("addSaturate",
_addSaturate(shader_integer_functions2,
glsl_type::int_type),
_addSaturate(shader_integer_functions2,
glsl_type::ivec2_type),
_addSaturate(shader_integer_functions2,
glsl_type::ivec3_type),
_addSaturate(shader_integer_functions2,
glsl_type::ivec4_type),
_addSaturate(shader_integer_functions2,
glsl_type::uint_type),
_addSaturate(shader_integer_functions2,
glsl_type::uvec2_type),
_addSaturate(shader_integer_functions2,
glsl_type::uvec3_type),
_addSaturate(shader_integer_functions2,
glsl_type::uvec4_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::int64_t_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::i64vec2_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::i64vec3_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::i64vec4_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::uint64_t_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::u64vec2_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::u64vec3_type),
_addSaturate(shader_integer_functions2_int64,
glsl_type::u64vec4_type),
NULL);
add_function("average",
_average(shader_integer_functions2,
glsl_type::int_type),
_average(shader_integer_functions2,
glsl_type::ivec2_type),
_average(shader_integer_functions2,
glsl_type::ivec3_type),
_average(shader_integer_functions2,
glsl_type::ivec4_type),
_average(shader_integer_functions2,
glsl_type::uint_type),
_average(shader_integer_functions2,
glsl_type::uvec2_type),
_average(shader_integer_functions2,
glsl_type::uvec3_type),
_average(shader_integer_functions2,
glsl_type::uvec4_type),
_average(shader_integer_functions2_int64,
glsl_type::int64_t_type),
_average(shader_integer_functions2_int64,
glsl_type::i64vec2_type),
_average(shader_integer_functions2_int64,
glsl_type::i64vec3_type),
_average(shader_integer_functions2_int64,
glsl_type::i64vec4_type),
_average(shader_integer_functions2_int64,
glsl_type::uint64_t_type),
_average(shader_integer_functions2_int64,
glsl_type::u64vec2_type),
_average(shader_integer_functions2_int64,
glsl_type::u64vec3_type),
_average(shader_integer_functions2_int64,
glsl_type::u64vec4_type),
NULL);
add_function("averageRounded",
_averageRounded(shader_integer_functions2,
glsl_type::int_type),
_averageRounded(shader_integer_functions2,
glsl_type::ivec2_type),
_averageRounded(shader_integer_functions2,
glsl_type::ivec3_type),
_averageRounded(shader_integer_functions2,
glsl_type::ivec4_type),
_averageRounded(shader_integer_functions2,
glsl_type::uint_type),
_averageRounded(shader_integer_functions2,
glsl_type::uvec2_type),
_averageRounded(shader_integer_functions2,
glsl_type::uvec3_type),
_averageRounded(shader_integer_functions2,
glsl_type::uvec4_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::int64_t_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::i64vec2_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::i64vec3_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::i64vec4_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::uint64_t_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::u64vec2_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::u64vec3_type),
_averageRounded(shader_integer_functions2_int64,
glsl_type::u64vec4_type),
NULL);
add_function("subtractSaturate",
_subtractSaturate(shader_integer_functions2,
glsl_type::int_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::ivec2_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::ivec3_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::ivec4_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::uint_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::uvec2_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::uvec3_type),
_subtractSaturate(shader_integer_functions2,
glsl_type::uvec4_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::int64_t_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::i64vec2_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::i64vec3_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::i64vec4_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::uint64_t_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::u64vec2_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::u64vec3_type),
_subtractSaturate(shader_integer_functions2_int64,
glsl_type::u64vec4_type),
NULL);
add_function("multiply32x16",
_multiply32x16(shader_integer_functions2,
glsl_type::int_type),
_multiply32x16(shader_integer_functions2,
glsl_type::ivec2_type),
_multiply32x16(shader_integer_functions2,
glsl_type::ivec3_type),
_multiply32x16(shader_integer_functions2,
glsl_type::ivec4_type),
_multiply32x16(shader_integer_functions2,
glsl_type::uint_type),
_multiply32x16(shader_integer_functions2,
glsl_type::uvec2_type),
_multiply32x16(shader_integer_functions2,
glsl_type::uvec3_type),
_multiply32x16(shader_integer_functions2,
glsl_type::uvec4_type),
NULL);
#undef F
#undef FI
#undef FIUD_VEC
@ -6598,6 +6839,28 @@ builtin_builder::_findMSB(const glsl_type *type)
glsl_type::ivec(type->vector_elements), type);
}
ir_function_signature *
builtin_builder::_countLeadingZeros(builtin_available_predicate avail,
const glsl_type *type)
{
return unop(avail, ir_unop_clz,
glsl_type::uvec(type->vector_elements), type);
}
ir_function_signature *
builtin_builder::_countTrailingZeros(builtin_available_predicate avail,
const glsl_type *type)
{
ir_variable *a = in_var(type, "a");
MAKE_SIG(glsl_type::uvec(type->vector_elements), avail, 1, a);
body.emit(ret(ir_builder::min2(
ir_builder::i2u(ir_builder::expr(ir_unop_find_lsb, a)),
imm(32u))));
return sig;
}
ir_function_signature *
builtin_builder::_fma(builtin_available_predicate avail, const glsl_type *type)
{
@ -6693,6 +6956,13 @@ builtin_builder::_uaddCarry(const glsl_type *type)
return sig;
}
ir_function_signature *
builtin_builder::_addSaturate(builtin_available_predicate avail,
const glsl_type *type)
{
return binop(avail, ir_binop_add_sat, type, type, type);
}
ir_function_signature *
builtin_builder::_usubBorrow(const glsl_type *type)
{
@ -6707,6 +6977,40 @@ builtin_builder::_usubBorrow(const glsl_type *type)
return sig;
}
ir_function_signature *
builtin_builder::_subtractSaturate(builtin_available_predicate avail,
const glsl_type *type)
{
return binop(avail, ir_binop_sub_sat, type, type, type);
}
ir_function_signature *
builtin_builder::_absoluteDifference(builtin_available_predicate avail,
const glsl_type *type)
{
/* absoluteDifference returns an unsigned type that has the same number of
* bits and number of vector elements as the type of the operands.
*/
return binop(avail, ir_binop_abs_sub,
glsl_type::get_instance(glsl_unsigned_base_type_of(type->base_type),
type->vector_elements, 1),
type, type);
}
ir_function_signature *
builtin_builder::_average(builtin_available_predicate avail,
const glsl_type *type)
{
return binop(avail, ir_binop_avg, type, type, type);
}
ir_function_signature *
builtin_builder::_averageRounded(builtin_available_predicate avail,
const glsl_type *type)
{
return binop(avail, ir_binop_avg_round, type, type, type);
}
/**
* For both imulExtended() and umulExtended() built-ins.
*/
@ -6753,6 +7057,13 @@ builtin_builder::_mulExtended(const glsl_type *type)
return sig;
}
ir_function_signature *
builtin_builder::_multiply32x16(builtin_available_predicate avail,
const glsl_type *type)
{
return binop(avail, ir_binop_mul_32x16, type, type, type);
}
ir_function_signature *
builtin_builder::_interpolateAtCentroid(const glsl_type *type)
{