Mesa (master): glsl/builtins: Support stage-agnostic built-in profiles.

Kenneth Graunke kwg at kemper.freedesktop.org
Tue Apr 17 23:06:15 UTC 2012


Module: Mesa
Branch: master
Commit: fbea94ae59817c1d9db9b2f1e257daeadf7c15a9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fbea94ae59817c1d9db9b2f1e257daeadf7c15a9

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Apr 17 11:26:29 2012 -0700

glsl/builtins: Support stage-agnostic built-in profiles.

The built-in subsystem uses "profiles," or GLSL shaders containing
prototypes for all built-ins supported within a particular language
version (or extension) and shader stage.

Since profiles were stage-specific, we had to cut and paste almost all
the prototypes between (e.g.) 110.vert and 110.frag.  Naturally, this
led to sundry cut and paste bugs, where someone fixed an issue in .frag
but neglected to update .vert, or vice-versa.  Geometry shaders would
have only made this worse.

This patch introduces support for a new '.glsl' profile suffix which
contains prototypes common to all shader stages.  The existing '.frag'
and '.vert' profiles need only contain the few stage-specific built-ins.

Not only does this remove duplication, it makes built-in setup slightly
faster: we don't need to re-read the common prototypes and function
bodies for both the vertex and fragment shader stage.

Internally, this was trivial.  We already create a list of gl_shader
objects to search through for built-ins: one for the core language
version/stage, and additional shaders for any extensions in use.  This
patch simply adds another shader to the list: core/common, core/stage,
and extensions.

The next patch will update the profiles to remove the duplication.
It's separated out purely to make review easier.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Acked-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/glsl/builtins/tools/generate_builtins.py |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index f58196f..fb9052b 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -113,7 +113,7 @@ def write_profiles():
 
 def get_profile_list():
     profile_files = []
-    for extension in ['frag', 'vert']:
+    for extension in ['glsl', 'frag', 'vert']:
         path_glob = path.join(
             path.join(builtins_dir, 'profiles'), '*.' + extension)
         profile_files.extend(glob(path_glob))
@@ -260,8 +260,10 @@ _mesa_glsl_initialize_functions(struct _mesa_glsl_parse_state *state)
             check = 'state->target == vertex_shader && '
         elif profile.endswith('_frag'):
             check = 'state->target == fragment_shader && '
+        else:
+            check = ''
 
-        version = re.sub(r'_(vert|frag)$', '', profile)
+        version = re.sub(r'_(glsl|vert|frag)$', '', profile)
         if version.isdigit():
             check += 'state->language_version == ' + version
         else: # an extension name




More information about the mesa-commit mailing list