nir/linker: Add nir_build_program_resource_list()
authorEduardo Lima Mitev <elima@igalia.com>
Tue, 14 Nov 2017 23:29:28 +0000 (00:29 +0100)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Thu, 21 Jun 2018 12:25:05 +0000 (14:25 +0200)
This function is equivalent to the linker.cpp
build_program_resource_list() but will extract the resources from NIR
shaders instead.

For now, only uniforms and program inputs are implemented.

v2: move from compiler/nir to compiler/glsl (Timothy Arceri)

v3: remove support for inputs, that is still WIP (spotted by Timothy
    Arceri)

Signed-off-by: Eduardo Lima <elima@igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/Makefile.sources
src/compiler/glsl/gl_nir_linker.c [new file with mode: 0644]
src/compiler/glsl/gl_nir_linker.h
src/compiler/glsl/meson.build

index 89702a7c5d5540ff267600b0722757fb3ea55607..231c5cbfae1ea82002fc523bc3af0581b698156e 100644 (file)
@@ -30,6 +30,7 @@ LIBGLSL_FILES = \
        glsl/gl_nir_lower_samplers_as_deref.c \
        glsl/gl_nir_link_uniform_initializers.c \
        glsl/gl_nir_link_uniforms.c \
+       glsl/gl_nir_linker.c \
        glsl/gl_nir_linker.h \
        glsl/gl_nir.h \
        glsl/glsl_parser_extras.cpp \
diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c
new file mode 100644 (file)
index 0000000..d09a2c0
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright © 2018 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.
+ */
+
+#include "nir.h"
+#include "gl_nir_linker.h"
+#include "linker_util.h"
+#include "main/mtypes.h"
+#include "ir_uniform.h" /* for gl_uniform_storage */
+
+/* This file included general link methods, using NIR, instead of IR as
+ * the counter-part glsl/linker.cpp
+ *
+ * Also note that this is tailored for ARB_gl_spirv needs and particularities
+ */
+
+void
+nir_build_program_resource_list(struct gl_context *ctx,
+                                struct gl_shader_program *prog)
+{
+   /* Rebuild resource list. */
+   if (prog->data->ProgramResourceList) {
+      ralloc_free(prog->data->ProgramResourceList);
+      prog->data->ProgramResourceList = NULL;
+      prog->data->NumProgramResourceList = 0;
+   }
+
+   struct set *resource_set = _mesa_set_create(NULL,
+                                               _mesa_hash_pointer,
+                                               _mesa_key_pointer_equal);
+
+   /* Add uniforms
+    *
+    * Here, it is expected that nir_link_uniforms() has already been
+    * called, so that UniformStorage table is already available.
+    */
+   for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
+      struct gl_uniform_storage *uniform = &prog->data->UniformStorage[i];
+
+      if (!link_util_add_program_resource(prog, resource_set, GL_UNIFORM, uniform,
+                                          uniform->active_shader_mask)) {
+         return;
+      }
+   }
+
+
+   _mesa_set_destroy(resource_set, NULL);
+}
index 5c650ce0455a0aa528ebaca2291d00b9a9fbf08e..9567b9e7b8e5fbd0c97a081c51c27532c958fce9 100644 (file)
@@ -37,6 +37,9 @@ bool gl_nir_link_uniforms(struct gl_context *ctx,
 void gl_nir_set_uniform_initializers(struct gl_context *ctx,
                                      struct gl_shader_program *prog);
 
+void nir_build_program_resource_list(struct gl_context *ctx,
+                                     struct gl_shader_program *prog);
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
index 88a49c6997efe6d78951ff22023a6ebc49bc3a38..81d0fbea521185e21d7172fc833f943228f859db 100644 (file)
@@ -71,6 +71,7 @@ files_libglsl = files(
   'gl_nir_lower_samplers_as_deref.c',
   'gl_nir_link_uniform_initializers.c',
   'gl_nir_link_uniforms.c',
+  'gl_nir_linker.c',
   'gl_nir_linker.h',
   'gl_nir.h',
   'glsl_parser_extras.cpp',