aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl/builtin_functions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/glsl/builtin_functions.cpp')
-rw-r--r--mesalib/src/glsl/builtin_functions.cpp144
1 files changed, 132 insertions, 12 deletions
diff --git a/mesalib/src/glsl/builtin_functions.cpp b/mesalib/src/glsl/builtin_functions.cpp
index 840a6c9a2..038e47363 100644
--- a/mesalib/src/glsl/builtin_functions.cpp
+++ b/mesalib/src/glsl/builtin_functions.cpp
@@ -77,7 +77,7 @@ always_available(const _mesa_glsl_parse_state *state)
static bool
compatibility_vs_only(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_VERTEX &&
+ return state->stage == MESA_SHADER_VERTEX &&
state->language_version <= 130 &&
!state->es_shader;
}
@@ -85,13 +85,13 @@ compatibility_vs_only(const _mesa_glsl_parse_state *state)
static bool
fs_only(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_FRAGMENT;
+ return state->stage == MESA_SHADER_FRAGMENT;
}
static bool
gs_only(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_GEOMETRY;
+ return state->stage == MESA_SHADER_GEOMETRY;
}
static bool
@@ -103,7 +103,7 @@ v110(const _mesa_glsl_parse_state *state)
static bool
v110_fs_only(const _mesa_glsl_parse_state *state)
{
- return !state->es_shader && state->target == MESA_SHADER_FRAGMENT;
+ return !state->es_shader && state->stage == MESA_SHADER_FRAGMENT;
}
static bool
@@ -122,7 +122,7 @@ static bool
v130_fs_only(const _mesa_glsl_parse_state *state)
{
return state->is_version(130, 300) &&
- state->target == MESA_SHADER_FRAGMENT;
+ state->stage == MESA_SHADER_FRAGMENT;
}
static bool
@@ -155,7 +155,7 @@ lod_exists_in_stage(const _mesa_glsl_parse_state *state)
* Since ARB_shader_texture_lod can only be enabled on desktop GLSL, we
* don't need to explicitly check state->es_shader.
*/
- return state->target == MESA_SHADER_VERTEX ||
+ return state->stage == MESA_SHADER_VERTEX ||
state->is_version(130, 300) ||
state->ARB_shader_texture_lod_enable;
}
@@ -223,7 +223,7 @@ texture_array_lod(const _mesa_glsl_parse_state *state)
static bool
fs_texture_array(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_FRAGMENT &&
+ return state->stage == MESA_SHADER_FRAGMENT &&
state->EXT_texture_array_enable;
}
@@ -243,7 +243,7 @@ texture_multisample(const _mesa_glsl_parse_state *state)
static bool
fs_texture_cube_map_array(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_FRAGMENT &&
+ return state->stage == MESA_SHADER_FRAGMENT &&
(state->is_version(400, 0) ||
state->ARB_texture_cube_map_array_enable);
}
@@ -265,7 +265,7 @@ texture_query_levels(const _mesa_glsl_parse_state *state)
static bool
texture_query_lod(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_FRAGMENT &&
+ return state->stage == MESA_SHADER_FRAGMENT &&
state->ARB_texture_query_lod_enable;
}
@@ -292,7 +292,7 @@ texture_gather_only(const _mesa_glsl_parse_state *state)
static bool
fs_oes_derivatives(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_FRAGMENT &&
+ return state->stage == MESA_SHADER_FRAGMENT &&
(state->is_version(110, 300) ||
state->OES_standard_derivatives_enable);
}
@@ -318,7 +318,7 @@ tex3d(const _mesa_glsl_parse_state *state)
static bool
fs_tex3d(const _mesa_glsl_parse_state *state)
{
- return state->target == MESA_SHADER_FRAGMENT &&
+ return state->stage == MESA_SHADER_FRAGMENT &&
(!state->es_shader || state->OES_texture_3D_enable);
}
@@ -334,6 +334,12 @@ shader_atomic_counters(const _mesa_glsl_parse_state *state)
return state->ARB_shader_atomic_counters_enable;
}
+static bool
+shader_trinary_minmax(const _mesa_glsl_parse_state *state)
+{
+ return state->AMD_shader_trinary_minmax_enable;
+}
+
/** @} */
/******************************************************************************/
@@ -570,6 +576,21 @@ private:
ir_function_signature *_atomic_op(const char *intrinsic,
builtin_available_predicate avail);
+ ir_function_signature *_min3(builtin_available_predicate avail,
+ const glsl_type *x_type,
+ const glsl_type *y_type,
+ const glsl_type *z_type);
+
+ ir_function_signature *_max3(builtin_available_predicate avail,
+ const glsl_type *x_type,
+ const glsl_type *y_type,
+ const glsl_type *z_type);
+
+ ir_function_signature *_mid3(builtin_available_predicate avail,
+ const glsl_type *x_type,
+ const glsl_type *y_type,
+ const glsl_type *z_type);
+
#undef B0
#undef B1
#undef B2
@@ -2106,6 +2127,57 @@ builtin_builder::create_builtins()
shader_atomic_counters),
NULL);
+ add_function("min3",
+ _min3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type),
+ _min3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type),
+ _min3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type),
+ _min3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type),
+
+ _min3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type),
+ _min3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
+ _min3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
+ _min3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type),
+
+ _min3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type),
+ _min3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type),
+ _min3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type),
+ _min3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
+ NULL);
+
+ add_function("max3",
+ _max3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type),
+ _max3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type),
+ _max3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type),
+ _max3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type),
+
+ _max3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type),
+ _max3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
+ _max3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
+ _max3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type),
+
+ _max3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type),
+ _max3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type),
+ _max3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type),
+ _max3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
+ NULL);
+
+ add_function("mid3",
+ _mid3(shader_trinary_minmax, glsl_type::float_type, glsl_type::float_type, glsl_type::float_type),
+ _mid3(shader_trinary_minmax, glsl_type::vec2_type, glsl_type::vec2_type, glsl_type::vec2_type),
+ _mid3(shader_trinary_minmax, glsl_type::vec3_type, glsl_type::vec3_type, glsl_type::vec3_type),
+ _mid3(shader_trinary_minmax, glsl_type::vec4_type, glsl_type::vec4_type, glsl_type::vec4_type),
+
+ _mid3(shader_trinary_minmax, glsl_type::int_type, glsl_type::int_type, glsl_type::int_type),
+ _mid3(shader_trinary_minmax, glsl_type::ivec2_type, glsl_type::ivec2_type, glsl_type::ivec2_type),
+ _mid3(shader_trinary_minmax, glsl_type::ivec3_type, glsl_type::ivec3_type, glsl_type::ivec3_type),
+ _mid3(shader_trinary_minmax, glsl_type::ivec4_type, glsl_type::ivec4_type, glsl_type::ivec4_type),
+
+ _mid3(shader_trinary_minmax, glsl_type::uint_type, glsl_type::uint_type, glsl_type::uint_type),
+ _mid3(shader_trinary_minmax, glsl_type::uvec2_type, glsl_type::uvec2_type, glsl_type::uvec2_type),
+ _mid3(shader_trinary_minmax, glsl_type::uvec3_type, glsl_type::uvec3_type, glsl_type::uvec3_type),
+ _mid3(shader_trinary_minmax, glsl_type::uvec4_type, glsl_type::uvec4_type, glsl_type::uvec4_type),
+ NULL);
+
#undef F
#undef FI
#undef FIU
@@ -3864,7 +3936,7 @@ builtin_builder::_fma(const glsl_type *type)
ir_variable *c = in_var(type, "c");
MAKE_SIG(type, gpu_shader5, 3, a, b, c);
- body.emit(ret(fma(a, b, c)));
+ body.emit(ret(ir_builder::fma(a, b, c)));
return sig;
}
@@ -3991,6 +4063,54 @@ builtin_builder::_atomic_op(const char *intrinsic,
return sig;
}
+ir_function_signature *
+builtin_builder::_min3(builtin_available_predicate avail,
+ const glsl_type *x_type, const glsl_type *y_type,
+ const glsl_type *z_type)
+{
+ ir_variable *x = in_var(x_type, "x");
+ ir_variable *y = in_var(y_type, "y");
+ ir_variable *z = in_var(z_type, "z");
+ MAKE_SIG(x_type, avail, 3, x, y, z);
+
+ ir_expression *min3 = min2(x, min2(y,z));
+ body.emit(ret(min3));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_max3(builtin_available_predicate avail,
+ const glsl_type *x_type, const glsl_type *y_type,
+ const glsl_type *z_type)
+{
+ ir_variable *x = in_var(x_type, "x");
+ ir_variable *y = in_var(y_type, "y");
+ ir_variable *z = in_var(z_type, "z");
+ MAKE_SIG(x_type, avail, 3, x, y, z);
+
+ ir_expression *max3 = max2(x, max2(y,z));
+ body.emit(ret(max3));
+
+ return sig;
+}
+
+ir_function_signature *
+builtin_builder::_mid3(builtin_available_predicate avail,
+ const glsl_type *x_type, const glsl_type *y_type,
+ const glsl_type *z_type)
+{
+ ir_variable *x = in_var(x_type, "x");
+ ir_variable *y = in_var(y_type, "y");
+ ir_variable *z = in_var(z_type, "z");
+ MAKE_SIG(x_type, avail, 3, x, y, z);
+
+ ir_expression *mid3 = max2(min2(x, y), max2(min2(x, z), min2(y, z)));
+ body.emit(ret(mid3));
+
+ return sig;
+}
+
/** @} */
/******************************************************************************/