diff options
author | Ian Romanick <[email protected]> | 2018-09-10 23:17:49 -0700 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-01-23 00:18:57 +0000 |
commit | cb518df775f222e34a4e724be2fa825df9388b0a (patch) | |
tree | ce2621190dbc9123480407858cda74edede13144 /src/compiler | |
parent | 5eda9f5832105bea0b3f75bcc866c760dd801718 (diff) |
glsl: Add built-in functions for INTEL_shader_integer_functions2
Reviewed-by: Caio Marcelo de Oliveira Filho <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/767>
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/glsl/builtin_functions.cpp | 311 |
1 files changed, 311 insertions, 0 deletions
diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp index e262a1ec780..d77404ee77f 100644 --- a/src/compiler/glsl/builtin_functions.cpp +++ b/src/compiler/glsl/builtin_functions.cpp @@ -827,6 +827,18 @@ demote_to_helper_invocation(const _mesa_glsl_parse_state *state) } 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) { return state->ctx->Const.ShaderCompilerOptions[state->stage].NirOptions; @@ -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 @@ -6599,6 +6840,28 @@ builtin_builder::_findMSB(const glsl_type *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) { ir_variable *a = in_var(type, "a"); @@ -6694,6 +6957,13 @@ builtin_builder::_uaddCarry(const glsl_type *type) } 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) { ir_variable *x = in_var(type, "x"); @@ -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. */ @@ -6754,6 +7058,13 @@ builtin_builder::_mulExtended(const glsl_type *type) } 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) { ir_variable *interpolant = in_var(type, "interpolant"); |