glsl: add arithmetic builtin functions for EXT_gpu_shader4
authorMarek Olšák <marek.olsak@amd.com>
Wed, 8 Aug 2018 01:31:09 +0000 (21:31 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 25 Apr 2019 00:45:15 +0000 (20:45 -0400)
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Tested-by: Dieter Nützel <Dieter@nuetzel-hh.de>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/glsl/builtin_functions.cpp

index 2849be8992e82be347bc63b850272d1b4fa5d669..cea307bff488fa2cb4c6507aded71645ed895c74 100644 (file)
@@ -280,6 +280,18 @@ shader_packing_or_es3_or_gpu_shader5(const _mesa_glsl_parse_state *state)
           state->is_version(400, 300);
 }
 
+static bool
+gpu_shader4(const _mesa_glsl_parse_state *state)
+{
+   return state->EXT_gpu_shader4_enable;
+}
+
+static bool
+v130_or_gpu_shader4(const _mesa_glsl_parse_state *state)
+{
+   return state->is_version(130, 300) || state->EXT_gpu_shader4_enable;
+}
+
 static bool
 gpu_shader5(const _mesa_glsl_parse_state *state)
 {
@@ -874,6 +886,7 @@ private:
    BA1(abs)
    BA1(sign)
    BA1(floor)
+   BA1(truncate)
    BA1(trunc)
    BA1(round)
    BA1(roundEven)
@@ -1488,9 +1501,9 @@ builtin_builder::create_builtins()
                 _##NAME(always_available, glsl_type::ivec3_type), \
                 _##NAME(always_available, glsl_type::ivec4_type), \
                                                                   \
-                _##NAME(v130, glsl_type::uvec2_type),             \
-                _##NAME(v130, glsl_type::uvec3_type),             \
-                _##NAME(v130, glsl_type::uvec4_type),             \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type), \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type), \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type), \
                 _##NAME(fp64, glsl_type::dvec2_type),  \
                 _##NAME(fp64, glsl_type::dvec3_type),  \
                 _##NAME(fp64, glsl_type::dvec4_type),  \
@@ -1527,9 +1540,9 @@ builtin_builder::create_builtins()
                 _##NAME(always_available, glsl_type::ivec3_type), \
                 _##NAME(always_available, glsl_type::ivec4_type), \
                                                                   \
-                _##NAME(v130, glsl_type::uvec2_type),             \
-                _##NAME(v130, glsl_type::uvec3_type),             \
-                _##NAME(v130, glsl_type::uvec4_type),             \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type), \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type), \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type), \
                                                                   \
                 _##NAME(always_available, glsl_type::bvec2_type), \
                 _##NAME(always_available, glsl_type::bvec3_type), \
@@ -1568,14 +1581,14 @@ builtin_builder::create_builtins()
                 _##NAME(always_available, glsl_type::ivec3_type, glsl_type::ivec3_type), \
                 _##NAME(always_available, glsl_type::ivec4_type, glsl_type::ivec4_type), \
                                                                                          \
-                _##NAME(v130, glsl_type::uint_type,  glsl_type::uint_type),              \
-                _##NAME(v130, glsl_type::uvec2_type, glsl_type::uint_type),              \
-                _##NAME(v130, glsl_type::uvec3_type, glsl_type::uint_type),              \
-                _##NAME(v130, glsl_type::uvec4_type, glsl_type::uint_type),              \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uint_type,  glsl_type::uint_type),  \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type, glsl_type::uint_type),  \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type, glsl_type::uint_type),  \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type, glsl_type::uint_type),  \
                                                                                          \
-                _##NAME(v130, glsl_type::uvec2_type, glsl_type::uvec2_type),             \
-                _##NAME(v130, glsl_type::uvec3_type, glsl_type::uvec3_type),             \
-                _##NAME(v130, glsl_type::uvec4_type, glsl_type::uvec4_type),             \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec2_type, glsl_type::uvec2_type), \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec3_type, glsl_type::uvec3_type), \
+                _##NAME(v130_or_gpu_shader4, glsl_type::uvec4_type, glsl_type::uvec4_type), \
                                                                                          \
                 _##NAME(fp64, glsl_type::double_type, glsl_type::double_type),           \
                 _##NAME(fp64, glsl_type::dvec2_type, glsl_type::double_type),           \
@@ -1642,6 +1655,14 @@ builtin_builder::create_builtins()
    FD(ceil)
    FD(fract)
 
+   add_function("truncate",
+                _truncate(gpu_shader4, glsl_type::float_type),
+                _truncate(gpu_shader4, glsl_type::vec2_type),
+                _truncate(gpu_shader4, glsl_type::vec3_type),
+                _truncate(gpu_shader4, glsl_type::vec4_type),
+                NULL);
+
+
    add_function("mod",
                 _mod(always_available, glsl_type::float_type, glsl_type::float_type),
                 _mod(always_available, glsl_type::vec2_type,  glsl_type::float_type),
@@ -4203,6 +4224,7 @@ UNOPA(inversesqrt, ir_unop_rsq)
 UNOPA(abs,       ir_unop_abs)
 UNOPA(sign,      ir_unop_sign)
 UNOPA(floor,     ir_unop_floor)
+UNOPA(truncate,  ir_unop_trunc)
 UNOPA(trunc,     ir_unop_trunc)
 UNOPA(round,     ir_unop_round_even)
 UNOPA(roundEven, ir_unop_round_even)