[Mesa-dev] [PATCH 10/34] glsl: add builtins for geometry shaders.

Paul Berry stereotype441 at gmail.com
Sun Jul 28 23:03:36 PDT 2013


From: Bryan Cain <bryancain3 at gmail.com>

v2 (Paul Berry <stereotype441 at gmail.com>): Account for rework of
builtin_variables.cpp.  Use INTERP_QUALIFIER_FLAT for gl_PrimitiveID
so that it will obey provoking vertex conventions.  Convert to GLSL
1.50 style geometry shaders.
---
 src/glsl/builtin_variables.cpp               | 11 +++++++++--
 src/glsl/builtins/ir/EmitVertex.ir           |  5 +++++
 src/glsl/builtins/ir/EndPrimitive.ir         |  5 +++++
 src/glsl/builtins/profiles/150.geom          |  3 +++
 src/glsl/builtins/tools/generate_builtins.py |  6 ++++--
 5 files changed, 26 insertions(+), 4 deletions(-)
 create mode 100644 src/glsl/builtins/ir/EmitVertex.ir
 create mode 100644 src/glsl/builtins/ir/EndPrimitive.ir
 create mode 100644 src/glsl/builtins/profiles/150.geom

diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index 1e88b6a..9d927a4 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -686,8 +686,10 @@ builtin_variable_generator::generate_gs_special_vars()
     * the specific case of gl_PrimitiveIDIn.  So we don't need to treat
     * gl_PrimitiveIDIn as an {ARB,EXT}_geometry_shader4-only variable.
     */
-   add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveIDIn");
-   add_output(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID");
+   add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveIDIn")
+      ->interpolation = INTERP_QUALIFIER_FLAT;
+   add_output(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID")
+      ->interpolation = INTERP_QUALIFIER_FLAT;
 }
 
 
@@ -702,6 +704,11 @@ builtin_variable_generator::generate_fs_special_vars()
    if (state->is_version(120, 100))
       add_input(VARYING_SLOT_PNTC, vec2_t, "gl_PointCoord");
 
+   if (state->is_version(150, 0)) {
+      add_input(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID")
+         ->interpolation = INTERP_QUALIFIER_FLAT;
+   }
+
    /* gl_FragColor and gl_FragData were deprecated starting in desktop GLSL
     * 1.30, and were relegated to the compatibility profile in GLSL 4.20.
     * They were removed from GLSL ES 3.00.
diff --git a/src/glsl/builtins/ir/EmitVertex.ir b/src/glsl/builtins/ir/EmitVertex.ir
new file mode 100644
index 0000000..e08ec62
--- /dev/null
+++ b/src/glsl/builtins/ir/EmitVertex.ir
@@ -0,0 +1,5 @@
+((function EmitVertex
+  (signature void
+    (parameters)
+    ((emitvertex)))
+))
diff --git a/src/glsl/builtins/ir/EndPrimitive.ir b/src/glsl/builtins/ir/EndPrimitive.ir
new file mode 100644
index 0000000..ea6ecfd
--- /dev/null
+++ b/src/glsl/builtins/ir/EndPrimitive.ir
@@ -0,0 +1,5 @@
+((function EndPrimitive
+  (signature void
+    (parameters)
+    ((endprim)))
+))
diff --git a/src/glsl/builtins/profiles/150.geom b/src/glsl/builtins/profiles/150.geom
new file mode 100644
index 0000000..d2ab891
--- /dev/null
+++ b/src/glsl/builtins/profiles/150.geom
@@ -0,0 +1,3 @@
+#version 150
+void EmitVertex();
+void EndPrimitive();
diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py
index 85bd5dd..54c5a49 100755
--- a/src/glsl/builtins/tools/generate_builtins.py
+++ b/src/glsl/builtins/tools/generate_builtins.py
@@ -125,7 +125,7 @@ def write_profiles():
 
 def get_profile_list():
     profile_files = []
-    for extension in ['glsl', 'frag', 'vert']:
+    for extension in ['glsl', 'frag', 'vert', 'geom']:
         path_glob = path.join(
             path.join(builtins_dir, 'profiles'), '*.' + extension)
         profile_files.extend(glob(path_glob))
@@ -279,10 +279,12 @@ _mesa_glsl_initialize_functions(struct _mesa_glsl_parse_state *state)
             check = 'state->target == vertex_shader && '
         elif profile.endswith('_frag'):
             check = 'state->target == fragment_shader && '
+        elif profile.endswith('_geom'):
+            check = 'state->target == geometry_shader && '
         else:
             check = ''
 
-        version = re.sub(r'_(glsl|vert|frag)$', '', profile)
+        version = re.sub(r'_(glsl|vert|frag|geom)$', '', profile)
         if version[0].isdigit():
             is_es = version.endswith('es')
             if is_es:
-- 
1.8.3.4



More information about the mesa-dev mailing list