glsl: add support for builtins to the nir uniform linker
authorTimothy Arceri <tarceri@itsqueeze.com>
Mon, 27 Jan 2020 05:46:25 +0000 (16:46 +1100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 6 Mar 2020 23:22:14 +0000 (23:22 +0000)
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4050>

src/compiler/glsl/gl_nir_link_uniforms.c

index 7b5c21319601a6f4bf6e8cd9a14146ef041bd4c0..ec0c7afca5526b100093545be594a667d2703ce7 100644 (file)
 
 #define UNMAPPED_UNIFORM_LOC ~0u
 
+/**
+ * Built-in / reserved GL variables names start with "gl_"
+ */
+static inline bool
+is_gl_identifier(const char *s)
+{
+   return s && s[0] == 'g' && s[1] == 'l' && s[2] == '_';
+}
+
 static void
 nir_setup_uniform_remap_tables(struct gl_context *ctx,
                                struct gl_shader_program *prog)
@@ -856,7 +865,7 @@ nir_link_uniform(struct gl_context *ctx,
        * implement support for their specific features, like SSBO, atomics,
        * etc.
        */
-      uniform->builtin = false;
+      uniform->builtin = is_gl_identifier(uniform->name);
       uniform->atomic_buffer_index = -1;
       uniform->is_bindless = false;
 
@@ -930,7 +939,7 @@ nir_link_uniform(struct gl_context *ctx,
             state->num_values += values;
          }
       } else {
-         if (!state->var_is_in_block) {
+         if (!state->var_is_in_block && !is_gl_identifier(uniform->name)) {
             state->num_shader_uniform_components += values;
             state->num_values += values;
          }