gl_nir_linker.c revision b8e80941
1/*
2 * Copyright © 2018 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24#include "nir.h"
25#include "gl_nir_linker.h"
26#include "linker_util.h"
27#include "main/mtypes.h"
28#include "ir_uniform.h" /* for gl_uniform_storage */
29
30/* This file included general link methods, using NIR, instead of IR as
31 * the counter-part glsl/linker.cpp
32 *
33 * Also note that this is tailored for ARB_gl_spirv needs and particularities
34 */
35
36void
37nir_build_program_resource_list(struct gl_context *ctx,
38                                struct gl_shader_program *prog)
39{
40   /* Rebuild resource list. */
41   if (prog->data->ProgramResourceList) {
42      ralloc_free(prog->data->ProgramResourceList);
43      prog->data->ProgramResourceList = NULL;
44      prog->data->NumProgramResourceList = 0;
45   }
46
47   struct set *resource_set = _mesa_pointer_set_create(NULL);
48
49   /* Add uniforms
50    *
51    * Here, it is expected that nir_link_uniforms() has already been
52    * called, so that UniformStorage table is already available.
53    */
54   for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
55      struct gl_uniform_storage *uniform = &prog->data->UniformStorage[i];
56
57      /* Do not add uniforms internally used by Mesa. */
58      if (uniform->hidden)
59         continue;
60
61      if (!link_util_add_program_resource(prog, resource_set, GL_UNIFORM, uniform,
62                                          uniform->active_shader_mask)) {
63         return;
64      }
65   }
66
67
68   _mesa_set_destroy(resource_set, NULL);
69}
70