[Mesa-dev] [PATCH v2 02/11] glsl: Add builtin barrier() function

2015-04-25 Thread Jordan Justen
From: Chris Forbes 

[jordan.l.jus...@intel.com: Add CS support]
Signed-off-by: Jordan Justen 
Reviewed-by: Ben Widawsky 
---
 src/glsl/builtin_functions.cpp | 29 +
 1 file changed, 29 insertions(+)

diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
index 524b8d6..778470d 100644
--- a/src/glsl/builtin_functions.cpp
+++ b/src/glsl/builtin_functions.cpp
@@ -99,6 +99,18 @@ gs_only(const _mesa_glsl_parse_state *state)
 }
 
 static bool
+tcs_only(const _mesa_glsl_parse_state *state)
+{
+   return false; /* TODO: state->stage == MESA_SHADER_TESS_CTRL; */
+}
+
+static bool
+cs_only(const _mesa_glsl_parse_state *state)
+{
+   return state->stage == MESA_SHADER_COMPUTE;
+}
+
+static bool
 v110(const _mesa_glsl_parse_state *state)
 {
return !state->es_shader;
@@ -387,6 +399,12 @@ fp64(const _mesa_glsl_parse_state *state)
return state->has_double();
 }
 
+static bool
+barrier_supported(const _mesa_glsl_parse_state *state)
+{
+   return tcs_only(state) || cs_only(state);
+}
+
 /** @} */
 
 
/**/
@@ -631,6 +649,7 @@ private:
 const glsl_type *stream_type);
ir_function_signature *_EndStreamPrimitive(builtin_available_predicate 
avail,
   const glsl_type *stream_type);
+   B0(barrier)
 
B2(textureQueryLod);
B1(textureQueryLevels);
@@ -1910,6 +1929,7 @@ builtin_builder::create_builtins()
 _EndStreamPrimitive(gs_streams, glsl_type::uint_type),
 _EndStreamPrimitive(gs_streams, glsl_type::int_type),
 NULL);
+   add_function("barrier", _barrier(), NULL);
 
add_function("textureQueryLOD",
 _textureQueryLod(glsl_type::sampler1D_type,  
glsl_type::float_type),
@@ -4262,6 +4282,15 @@ 
builtin_builder::_EndStreamPrimitive(builtin_available_predicate avail,
 }
 
 ir_function_signature *
+builtin_builder::_barrier()
+{
+   MAKE_SIG(glsl_type::void_type, barrier_supported, 0);
+
+   body.emit(new(mem_ctx) ir_barrier());
+   return sig;
+}
+
+ir_function_signature *
 builtin_builder::_textureQueryLod(const glsl_type *sampler_type,
   const glsl_type *coord_type)
 {
-- 
2.1.4

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH v2 02/11] glsl: Add builtin barrier() function

2015-04-27 Thread Kenneth Graunke
On Saturday, April 25, 2015 09:45:51 PM Jordan Justen wrote:
> From: Chris Forbes 
> 
> [jordan.l.jus...@intel.com: Add CS support]
> Signed-off-by: Jordan Justen 
> Reviewed-by: Ben Widawsky 
> ---
>  src/glsl/builtin_functions.cpp | 29 +
>  1 file changed, 29 insertions(+)
> 
> diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
> index 524b8d6..778470d 100644
> --- a/src/glsl/builtin_functions.cpp
> +++ b/src/glsl/builtin_functions.cpp
> @@ -99,6 +99,18 @@ gs_only(const _mesa_glsl_parse_state *state)
>  }
>  
>  static bool
> +tcs_only(const _mesa_glsl_parse_state *state)
> +{
> +   return false; /* TODO: state->stage == MESA_SHADER_TESS_CTRL; */
> +}
> +
> +static bool
> +cs_only(const _mesa_glsl_parse_state *state)
> +{
> +   return state->stage == MESA_SHADER_COMPUTE;
> +}
> +
> +static bool
>  v110(const _mesa_glsl_parse_state *state)
>  {
> return !state->es_shader;
> @@ -387,6 +399,12 @@ fp64(const _mesa_glsl_parse_state *state)
> return state->has_double();
>  }
>  
> +static bool
> +barrier_supported(const _mesa_glsl_parse_state *state)
> +{
> +   return tcs_only(state) || cs_only(state);
> +}
> +

I'd probably drop the cs_only/tcs_only functions unless you're going to
use them as a built-in predicate directly.

Writing this as:

static bool
barrier_supported(const _mesa_glsl_parse_state *state)
{
return state->stage == MESA_SHADER_COMPUTE;
/* TODO: || stage->state == MESA_SHADER_TESS_CTRL; */
}

seems simpler to me.

With that change, (or either way I guess),
Reviewed-by: Kenneth Graunke 


signature.asc
Description: This is a digitally signed message part.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev