Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-09 Thread Matt Turner
On Wed, Sep 4, 2013 at 3:22 PM, Kenneth Graunke kenn...@whitecape.org wrote:
 +static bool
 +texture_query_lod(const _mesa_glsl_parse_state *state)
 +{
 +   return state-target == fragment_shader 
 +  (state-is_version(400, 0) || state-ARB_texture_query_lod_enable);
 +}

Reminder about the whole fiasco about textureQueryLOD vs
textureQueryLod. Probably just need to remove the
state-is_version(400, 0) for now.

 +ir_function_signature *
 +builtin_builder::_modf(const glsl_type *type)
 +{
 +   ir_variable *x = in_var(type, x);
 +   ir_variable *i = new(mem_ctx) ir_variable(type, i, ir_var_function_out);
 +   MAKE_SIG(type, v130, 2, x, i);
 +
 +   ir_variable *t = body.make_temp(type, t);
 +   body.emit(assign(t, expr(ir_unop_trunc, x)));
 +   body.emit(assign(i, t));
 +   body.emit(ret(sub(x, t)));
 +
 +   return sig;
 +}

Create an out_var() helper function and use it here.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-09 Thread Kenneth Graunke

On 09/09/2013 10:39 AM, Matt Turner wrote:

On Wed, Sep 4, 2013 at 3:22 PM, Kenneth Graunke kenn...@whitecape.org wrote:

+static bool
+texture_query_lod(const _mesa_glsl_parse_state *state)
+{
+   return state-target == fragment_shader 
+  (state-is_version(400, 0) || state-ARB_texture_query_lod_enable);
+}


Reminder about the whole fiasco about textureQueryLOD vs
textureQueryLod. Probably just need to remove the
state-is_version(400, 0) for now.


Already done.  Thanks for pointing this out.


+ir_function_signature *
+builtin_builder::_modf(const glsl_type *type)
+{
+   ir_variable *x = in_var(type, x);
+   ir_variable *i = new(mem_ctx) ir_variable(type, i, ir_var_function_out);
+   MAKE_SIG(type, v130, 2, x, i);
+
+   ir_variable *t = body.make_temp(type, t);
+   body.emit(assign(t, expr(ir_unop_trunc, x)));
+   body.emit(assign(i, t));
+   body.emit(ret(sub(x, t)));
+
+   return sig;
+}


Create an out_var() helper function and use it here.


Sure.  I hadn't since there was only one instance of an out var being 
created, but apparently there are more coming in future built-ins.  Done.


--Ken

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


Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-08 Thread Paul Berry
On 4 September 2013 15:22, Kenneth Graunke kenn...@whitecape.org wrote:

 This creates a new replacement for the existing built-in function code.
 The new module lives in builtin_functions.cpp (not builtin_function.cpp)
 and exists in parallel with the existing system.  It isn't used yet.

 The new built-in function code takes a significantly different approach:

 Instead of implementing built-ins via printed IR, build time scripts,
 and run time parsing, we now implement them directly in C++, using
 ir_builder.  This translates to faster load times, and a much less
 complex build system.

 It also takes a different approach to built-in availability: each
 signature now stores a boolean predicate, which makes it easy to
 construct arbitrary expressions based on _mesa_glsl_parse_state's
 fields.  This is much more flexible than the old system, and also
 easier to use.

 Built-ins are also now stored in a single gl_shader object, rather
 than being spread out across a number of shaders that need to be linked.
 When searching for a matching prototype, we simply consult the
 availability predicate.  This also simplifies the code.

 Signed-off-by: Kenneth Graunke kenn...@whitecape.org
 ---
  src/glsl/Makefile.sources  |1 +
  src/glsl/builtin_functions.cpp | 3466
 
  src/glsl/ir.h  |   10 +
  3 files changed, 3477 insertions(+)
  create mode 100644 src/glsl/builtin_functions.cpp


snip


 +static bool
 +legacy_vs_only(const _mesa_glsl_parse_state *state)
 +{
 +   return state-target == vertex_shader 
 +  state-language_version = 130 
 +  !state-es_shader;
 +}


Elsewhere in src/glsl, we use the term compatibility instead of
legacy.  Maybe rename for consistency?

snip


 +class builtin_builder {
 +public:
 +   builtin_builder();
 +   ~builtin_builder();
 +
 +   void initialize();
 +   void release();
 +   ir_function_signature *find(_mesa_glsl_parse_state *state,
 +   const char *name, exec_list
 *actual_parameters);
 +
 +private:
 +   void *mem_ctx;
 +   gl_shader *shader;


It would be nice to have a comment here explaining that shader is the
shader that we're building to hold all the built-ins, not a user-defined
shader that's getting compiled.

snip


 +ir_function_signature *
 +builtin_builder::find(_mesa_glsl_parse_state *state,
 +  const char *name, exec_list *actual_parameters)
 +{
 +   /* The shader needs to link against the built-ins. */
 +   state-builtins_to_link[0] = shader;


This is confusing because the word shader in the comment refers to
something different from the variable shader.  Maybe something like this
instead?

/* The shader being compiled needs to link against the built-ins contained
in shader */

snip


 +extern C struct gl_shader *
 +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type);


Why not #include main/shaderobj.h to get access to this function?


 +
 +void
 +builtin_builder::create_shader()
 +{
 +   shader = _mesa_new_shader(NULL, 0, GL_VERTEX_SHADER);


It would be nice to have a comment explaining why it's ok to pass
GL_VERTEX_SHADER here, even though we're creating a shader object to hold
all built-ins for all shader stages.

snip


 +#define FIU(NAME)   \
 +   add_function(#NAME,  \
 +_##NAME(glsl_type::float_type), \
 +_##NAME(glsl_type::vec2_type),  \
 +_##NAME(glsl_type::vec3_type),  \
 +_##NAME(glsl_type::vec4_type),  \
 +\
 +_##NAME(glsl_type::int_type),   \
 +_##NAME(glsl_type::ivec2_type), \
 +_##NAME(glsl_type::ivec3_type), \
 +_##NAME(glsl_type::ivec4_type), \
 +\
 +/* XXX: need to make uints only available in 1.30+ */  \


Is this still an open issue?  It seems like we ought to come up with a plan
for addressing it before we land the series.


 +_##NAME(glsl_type::uint_type),  \
 +_##NAME(glsl_type::uvec2_type), \
 +_##NAME(glsl_type::uvec3_type), \
 +_##NAME(glsl_type::uvec4_type), \
 +NULL);
 +


snip


 +
 +   add_function(smoothstep,
 +_smoothstep(glsl_type::float_type, glsl_type::float_type),
 +_smoothstep(glsl_type::float_type, glsl_type::vec2_type),
 +_smoothstep(glsl_type::float_type, glsl_type::vec3_type),
 +_smoothstep(glsl_type::float_type, glsl_type::vec4_type),
 +
 +_smoothstep(glsl_type::vec2_type,  glsl_type::vec2_type),
 +_smoothstep(glsl_type::vec3_type,  glsl_type::vec3_type),
 +_smoothstep(glsl_type::vec4_type,  glsl_type::vec4_type),
 +NULL);
 +


There's some stray whitespace around smoothstep.

snip


 +void
 

Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-08 Thread Kenneth Graunke
On 09/08/2013 09:57 AM, Paul Berry wrote:
 On 4 September 2013 15:22, Kenneth Graunke kenn...@whitecape.org 
 mailto:kenn...@whitecape.org wrote:
 
 This creates a new replacement for the existing built-in function code.
 The new module lives in builtin_functions.cpp (not builtin_function.cpp)
 and exists in parallel with the existing system.  It isn't used yet.
 
 The new built-in function code takes a significantly different approach:
 
 Instead of implementing built-ins via printed IR, build time scripts,
 and run time parsing, we now implement them directly in C++, using
 ir_builder.  This translates to faster load times, and a much less
 complex build system.
 
 It also takes a different approach to built-in availability: each
 signature now stores a boolean predicate, which makes it easy to
 construct arbitrary expressions based on _mesa_glsl_parse_state's
 fields.  This is much more flexible than the old system, and also
 easier to use.
 
 Built-ins are also now stored in a single gl_shader object, rather
 than being spread out across a number of shaders that need to be linked.
 When searching for a matching prototype, we simply consult the
 availability predicate.  This also simplifies the code.
 
 Signed-off-by: Kenneth Graunke kenn...@whitecape.org
 mailto:kenn...@whitecape.org
 ---
   src/glsl/Makefile.sources  |1 +
   src/glsl/builtin_functions.cpp | 3466
 
   src/glsl/ir.h  |   10 +
   3 files changed, 3477 insertions(+)
   create mode 100644 src/glsl/builtin_functions.cpp
 
 
 snip
 
 +static bool
 +legacy_vs_only(const _mesa_glsl_parse_state *state)
 +{
 +   return state-target == vertex_shader 
 +  state-language_version = 130 
 +  !state-es_shader;
 +}
 
 
 Elsewhere in src/glsl, we use the term compatibility instead of 
 legacy.  Maybe rename for consistency?
 
 snip

Changed to compatibility_vs_only.

 
 +class builtin_builder {
 +public:
 +   builtin_builder();
 +   ~builtin_builder();
 +
 +   void initialize();
 +   void release();
 +   ir_function_signature *find(_mesa_glsl_parse_state *state,
 +   const char *name, exec_list
 *actual_parameters);
 +
 +private:
 +   void *mem_ctx;
 +   gl_shader *shader;
 
 
 It would be nice to have a comment here explaining that shader is the 
 shader that we're building to hold all the built-ins, not a user-defined 
 shader that's getting compiled.

Added:

/**
 * A shader to hold all the built-in signatures; created by this module.
 *
 * This includes signatures for every built-in, regardless of version or
 * enabled extensions.  The availability predicate associated with each
 * signature allows matching_signature() to filter out the irrelevant ones.
 */

 
 snip
 
 +ir_function_signature *
 +builtin_builder::find(_mesa_glsl_parse_state *state,
 +  const char *name, exec_list *actual_parameters)
 +{
 +   /* The shader needs to link against the built-ins. */
 +   state-builtins_to_link[0] = shader;
 
 
 This is confusing because the word shader in the comment refers to 
 something different from the variable shader.  Maybe something like 
 this instead?
 
 /* The shader being compiled needs to link against the built-ins 
 contained in shader */

Replaced with:

/* The shader currently being compiled requested a built-in function;
 * it needs to link against builtin_builder::shader in order to get them.
 *
 * Even if we don't find a matching signature, we still need to do this so
 * that the no matching signature error will list potential candidates
 * from the available built-ins.
 */

 
 snip
 
 +extern C struct gl_shader *
 +_mesa_new_shader(struct gl_context *ctx, GLuint name, GLenum type);
 
 
 Why not #include main/shaderobj.h to get access to this function?

That would be sensible, wouldn't it.  I think this was a vestige of the
old two-phase build insanity.

 +
 +void
 +builtin_builder::create_shader()
 +{
 +   shader = _mesa_new_shader(NULL, 0, GL_VERTEX_SHADER);
 
 
 It would be nice to have a comment explaining why it's ok to pass 
 GL_VERTEX_SHADER here, even though we're creating a shader object to 
 hold all built-ins for all shader stages.

Yeah, we've done this trick since 2010 so I didn't think to add a comment.
It wouldn't hurt though.  Added:

/* The target doesn't actually matter.  There's no target for generic
 * GLSL utility code that could be linked against any stage, so just
 * arbitrarily pick GL_VERTEX_SHADER.
 */

 snip
 
 +#define FIU(NAME)   \
 +   add_function(#NAME,  \
 +_##NAME(glsl_type::float_type), \
 +_##NAME(glsl_type::vec2_type),  \
 + 

Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-05 Thread Pohjolainen, Topi
On Wed, Sep 04, 2013 at 03:22:41PM -0700, Kenneth Graunke wrote:
 This creates a new replacement for the existing built-in function code.
 The new module lives in builtin_functions.cpp (not builtin_function.cpp)
 and exists in parallel with the existing system.  It isn't used yet.
 
 The new built-in function code takes a significantly different approach:
 
 Instead of implementing built-ins via printed IR, build time scripts,
 and run time parsing, we now implement them directly in C++, using
 ir_builder.  This translates to faster load times, and a much less
 complex build system.
 
 It also takes a different approach to built-in availability: each
 signature now stores a boolean predicate, which makes it easy to
 construct arbitrary expressions based on _mesa_glsl_parse_state's
 fields.  This is much more flexible than the old system, and also
 easier to use.
 
 Built-ins are also now stored in a single gl_shader object, rather
 than being spread out across a number of shaders that need to be linked.
 When searching for a matching prototype, we simply consult the
 availability predicate.  This also simplifies the code.
 
 Signed-off-by: Kenneth Graunke kenn...@whitecape.org
 ---
  src/glsl/Makefile.sources  |1 +
  src/glsl/builtin_functions.cpp | 3466 
 
  src/glsl/ir.h  |   10 +
  3 files changed, 3477 insertions(+)
  create mode 100644 src/glsl/builtin_functions.cpp
 
 diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
 index 979c416..3e706ef 100644
 --- a/src/glsl/Makefile.sources
 +++ b/src/glsl/Makefile.sources
 @@ -21,6 +21,7 @@ LIBGLSL_FILES = \
   $(GLSL_SRCDIR)/ast_function.cpp \
   $(GLSL_SRCDIR)/ast_to_hir.cpp \
   $(GLSL_SRCDIR)/ast_type.cpp \
 + $(GLSL_SRCDIR)/builtin_functions.cpp \
   $(GLSL_SRCDIR)/builtin_types.cpp \
   $(GLSL_SRCDIR)/builtin_variables.cpp \
   $(GLSL_SRCDIR)/glsl_parser_extras.cpp \
 diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
 new file mode 100644
 index 000..440ec41
 --- /dev/null
 +++ b/src/glsl/builtin_functions.cpp
 @@ -0,0 +1,3466 @@
 +/*
 + * Copyright © 2013 Intel Corporation
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the Software),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice (including the next
 + * paragraph) shall be included in all copies or substantial portions of the
 + * Software.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 + * DEALINGS IN THE SOFTWARE.
 + */
 +
 +/**
 + * \file builtin_functions.cpp
 + *
 + * Support for GLSL built-in functions.
 + *
 + * This file is split into several main components:
 + *
 + * 1. Availability predicates
 + *
 + *A series of small functions that check whether the current shader
 + *supports the version/extensions required to expose a built-in.
 + *
 + * 2. Core builtin_builder class functionality
 + *
 + * 3. Lists of built-in functions
 + *
 + *The builtin_builder::create_builtins() function contains lists of all
 + *built-in function signatures, where they're available, what types they
 + *take, and so on.
 + *
 + * 4. Implementations of built-in function signatures
 + *
 + *A series of functions which create ir_function_signatures and emit IR
 + *via ir_builder to implement them.
 + *
 + * 5. External API
 + *
 + *A few functions the rest of the compiler can use to interact with the
 + *built-in function module.  For example, searching for a built-in by
 + *name and parameters.
 + */
 +
 +#include stdarg.h
 +#include stdio.h
 +#include main/core.h /* for struct gl_shader */
 +#include ir_builder.h
 +#include glsl_parser_extras.h
 +#include program/prog_instruction.h
 +#include limits
 +
 +using namespace ir_builder;
 +
 +/**
 + * Availability predicates:
 + *  @{
 + */
 +static bool
 +always_available(const _mesa_glsl_parse_state *state)
 +{
 +   return true;
 +}
 +
 +static bool
 +legacy_vs_only(const _mesa_glsl_parse_state *state)
 +{
 +   return state-target == vertex_shader 
 +  state-language_version = 130 
 +  !state-es_shader;
 +}
 +
 +static bool
 +fs_only(const 

Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-05 Thread Pohjolainen, Topi
On Wed, Sep 04, 2013 at 03:22:41PM -0700, Kenneth Graunke wrote:
 This creates a new replacement for the existing built-in function code.
 The new module lives in builtin_functions.cpp (not builtin_function.cpp)
 and exists in parallel with the existing system.  It isn't used yet.
 
 The new built-in function code takes a significantly different approach:
 
 Instead of implementing built-ins via printed IR, build time scripts,
 and run time parsing, we now implement them directly in C++, using
 ir_builder.  This translates to faster load times, and a much less
 complex build system.
 
 It also takes a different approach to built-in availability: each
 signature now stores a boolean predicate, which makes it easy to
 construct arbitrary expressions based on _mesa_glsl_parse_state's
 fields.  This is much more flexible than the old system, and also
 easier to use.
 
 Built-ins are also now stored in a single gl_shader object, rather
 than being spread out across a number of shaders that need to be linked.
 When searching for a matching prototype, we simply consult the
 availability predicate.  This also simplifies the code.
 
 Signed-off-by: Kenneth Graunke kenn...@whitecape.org
 ---
  src/glsl/Makefile.sources  |1 +
  src/glsl/builtin_functions.cpp | 3466 
 
  src/glsl/ir.h  |   10 +
  3 files changed, 3477 insertions(+)
  create mode 100644 src/glsl/builtin_functions.cpp
 
 diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
 index 979c416..3e706ef 100644
 --- a/src/glsl/Makefile.sources
 +++ b/src/glsl/Makefile.sources
 @@ -21,6 +21,7 @@ LIBGLSL_FILES = \
   $(GLSL_SRCDIR)/ast_function.cpp \
   $(GLSL_SRCDIR)/ast_to_hir.cpp \
   $(GLSL_SRCDIR)/ast_type.cpp \
 + $(GLSL_SRCDIR)/builtin_functions.cpp \
   $(GLSL_SRCDIR)/builtin_types.cpp \
   $(GLSL_SRCDIR)/builtin_variables.cpp \
   $(GLSL_SRCDIR)/glsl_parser_extras.cpp \
 diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
 new file mode 100644
 index 000..440ec41
 --- /dev/null
 +++ b/src/glsl/builtin_functions.cpp
 @@ -0,0 +1,3466 @@
 +/*
 + * Copyright © 2013 Intel Corporation
 + *
 + * Permission is hereby granted, free of charge, to any person obtaining a
 + * copy of this software and associated documentation files (the Software),
 + * to deal in the Software without restriction, including without limitation
 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 + * and/or sell copies of the Software, and to permit persons to whom the
 + * Software is furnished to do so, subject to the following conditions:
 + *
 + * The above copyright notice and this permission notice (including the next
 + * paragraph) shall be included in all copies or substantial portions of the
 + * Software.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 + * DEALINGS IN THE SOFTWARE.
 + */
 +
 +/**
 + * \file builtin_functions.cpp
 + *
 + * Support for GLSL built-in functions.
 + *
 + * This file is split into several main components:
 + *
 + * 1. Availability predicates
 + *
 + *A series of small functions that check whether the current shader
 + *supports the version/extensions required to expose a built-in.
 + *
 + * 2. Core builtin_builder class functionality
 + *
 + * 3. Lists of built-in functions
 + *
 + *The builtin_builder::create_builtins() function contains lists of all
 + *built-in function signatures, where they're available, what types they
 + *take, and so on.
 + *
 + * 4. Implementations of built-in function signatures
 + *
 + *A series of functions which create ir_function_signatures and emit IR
 + *via ir_builder to implement them.
 + *
 + * 5. External API
 + *
 + *A few functions the rest of the compiler can use to interact with the
 + *built-in function module.  For example, searching for a built-in by
 + *name and parameters.
 + */
 +
 +#include stdarg.h
 +#include stdio.h
 +#include main/core.h /* for struct gl_shader */
 +#include ir_builder.h
 +#include glsl_parser_extras.h
 +#include program/prog_instruction.h
 +#include limits
 +
 +using namespace ir_builder;
 +
 +/**
 + * Availability predicates:
 + *  @{
 + */
 +static bool
 +always_available(const _mesa_glsl_parse_state *state)
 +{
 +   return true;
 +}
 +
 +static bool
 +legacy_vs_only(const _mesa_glsl_parse_state *state)
 +{
 +   return state-target == vertex_shader 
 +  state-language_version = 130 
 +  !state-es_shader;
 +}
 +
 +static bool
 +fs_only(const 

Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-05 Thread Pohjolainen, Topi
On Thu, Sep 05, 2013 at 02:27:04PM +0300, Pohjolainen, Topi wrote:
 On Wed, Sep 04, 2013 at 03:22:41PM -0700, Kenneth Graunke wrote:
  This creates a new replacement for the existing built-in function code.
  The new module lives in builtin_functions.cpp (not builtin_function.cpp)
  and exists in parallel with the existing system.  It isn't used yet.
  
  The new built-in function code takes a significantly different approach:
  
  Instead of implementing built-ins via printed IR, build time scripts,
  and run time parsing, we now implement them directly in C++, using
  ir_builder.  This translates to faster load times, and a much less
  complex build system.
  
  It also takes a different approach to built-in availability: each
  signature now stores a boolean predicate, which makes it easy to
  construct arbitrary expressions based on _mesa_glsl_parse_state's
  fields.  This is much more flexible than the old system, and also
  easier to use.
  
  Built-ins are also now stored in a single gl_shader object, rather
  than being spread out across a number of shaders that need to be linked.
  When searching for a matching prototype, we simply consult the
  availability predicate.  This also simplifies the code.
  
  Signed-off-by: Kenneth Graunke kenn...@whitecape.org
  ---
   src/glsl/Makefile.sources  |1 +
   src/glsl/builtin_functions.cpp | 3466 
  
   src/glsl/ir.h  |   10 +
   3 files changed, 3477 insertions(+)
   create mode 100644 src/glsl/builtin_functions.cpp
  
  diff --git a/src/glsl/Makefile.sources b/src/glsl/Makefile.sources
  index 979c416..3e706ef 100644
  --- a/src/glsl/Makefile.sources
  +++ b/src/glsl/Makefile.sources
  @@ -21,6 +21,7 @@ LIBGLSL_FILES = \
  $(GLSL_SRCDIR)/ast_function.cpp \
  $(GLSL_SRCDIR)/ast_to_hir.cpp \
  $(GLSL_SRCDIR)/ast_type.cpp \
  +   $(GLSL_SRCDIR)/builtin_functions.cpp \
  $(GLSL_SRCDIR)/builtin_types.cpp \
  $(GLSL_SRCDIR)/builtin_variables.cpp \
  $(GLSL_SRCDIR)/glsl_parser_extras.cpp \
  diff --git a/src/glsl/builtin_functions.cpp b/src/glsl/builtin_functions.cpp
  new file mode 100644
  index 000..440ec41
  --- /dev/null
  +++ b/src/glsl/builtin_functions.cpp
  @@ -0,0 +1,3466 @@
  +/*
  + * Copyright © 2013 Intel Corporation
  + *
  + * Permission is hereby granted, free of charge, to any person obtaining a
  + * copy of this software and associated documentation files (the 
  Software),
  + * to deal in the Software without restriction, including without 
  limitation
  + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  + * and/or sell copies of the Software, and to permit persons to whom the
  + * Software is furnished to do so, subject to the following conditions:
  + *
  + * The above copyright notice and this permission notice (including the 
  next
  + * paragraph) shall be included in all copies or substantial portions of 
  the
  + * Software.
  + *
  + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS 
  OR
  + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 
  OTHER
  + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  + * DEALINGS IN THE SOFTWARE.
  + */
  +
  +/**
  + * \file builtin_functions.cpp
  + *
  + * Support for GLSL built-in functions.
  + *
  + * This file is split into several main components:
  + *
  + * 1. Availability predicates
  + *
  + *A series of small functions that check whether the current shader
  + *supports the version/extensions required to expose a built-in.
  + *
  + * 2. Core builtin_builder class functionality
  + *
  + * 3. Lists of built-in functions
  + *
  + *The builtin_builder::create_builtins() function contains lists of all
  + *built-in function signatures, where they're available, what types 
  they
  + *take, and so on.
  + *
  + * 4. Implementations of built-in function signatures
  + *
  + *A series of functions which create ir_function_signatures and emit IR
  + *via ir_builder to implement them.
  + *
  + * 5. External API
  + *
  + *A few functions the rest of the compiler can use to interact with the
  + *built-in function module.  For example, searching for a built-in by
  + *name and parameters.
  + */
  +
  +#include stdarg.h
  +#include stdio.h
  +#include main/core.h /* for struct gl_shader */
  +#include ir_builder.h
  +#include glsl_parser_extras.h
  +#include program/prog_instruction.h
  +#include limits
  +
  +using namespace ir_builder;
  +
  +/**
  + * Availability predicates:
  + *  @{
  + */
  +static bool
  +always_available(const _mesa_glsl_parse_state *state)
  +{
  +   return true;
  +}
  +
  +static bool
  

Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-05 Thread Kenneth Graunke

On 09/05/2013 04:20 AM, Pohjolainen, Topi wrote:

On Wed, Sep 04, 2013 at 03:22:41PM -0700, Kenneth Graunke wrote:

[snip]

+/**
+ * builtin_builder: A singleton object representing the core of the built-in
+ * function module.
+ *
+ * It has code to generate
+ * It generates IR for every built-in function signature, and organizes them
+ * into functions.


I guess there are some leftovers here in the comment (or something missing
perhaps).


Whoops.  Thanks!  I deleted the first partial sentence.

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


Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-04 Thread Erik Faye-Lund
On Thu, Sep 5, 2013 at 12:22 AM, Kenneth Graunke kenn...@whitecape.org wrote:
 +#define B0(X) ir_function_signature *_##X();
 +#define B1(X) ir_function_signature *_##X(const glsl_type *);
 +#define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type 
 *);
 +#define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type 
 *, const glsl_type *);
 +   B1(radians)
 +   B1(degrees)
 +   B1(sin)
 +   B1(cos)
snip
 +   B1(bitCount)
 +   B1(findLSB)
 +   B1(findMSB)
 +   B1(fma)
 +#undef B

Shouldn't this be:
#undef B0
#undef B1
#undef B2
#undef B3

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


Re: [Mesa-dev] [PATCH 18/21] glsl: Write a new built-in function module.

2013-09-04 Thread Kenneth Graunke

On 09/04/2013 04:36 PM, Erik Faye-Lund wrote:

On Thu, Sep 5, 2013 at 12:22 AM, Kenneth Graunke kenn...@whitecape.org wrote:

+#define B0(X) ir_function_signature *_##X();
+#define B1(X) ir_function_signature *_##X(const glsl_type *);
+#define B2(X) ir_function_signature *_##X(const glsl_type *, const glsl_type 
*);
+#define B3(X) ir_function_signature *_##X(const glsl_type *, const glsl_type 
*, const glsl_type *);
+   B1(radians)
+   B1(degrees)
+   B1(sin)
+   B1(cos)

snip

+   B1(bitCount)
+   B1(findLSB)
+   B1(findMSB)
+   B1(fma)
+#undef B


Shouldn't this be:
#undef B0
#undef B1
#undef B2
#undef B3

?


Yes, it should...thanks for catching that.  I've fixed this, and also 
added #undefs for the other FIU* macros as well.


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