6dd1f535451434343f4ce49b4afa0ce6312638fe
2 * Copyright © 2011 Intel Corporation
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:
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
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
21 * DEALINGS IN THE SOFTWARE.
24 #include "main/core.h"
27 #include "glsl_symbol_table.h"
28 #include "program/hash_table.h"
31 * \file link_uniforms.cpp
32 * Assign locations for GLSL uniforms.
34 * \author Ian Romanick <ian.d.romanick@intel.com>
38 uniform_field_visitor::process(ir_variable
*var
)
40 const glsl_type
*t
= var
->type
;
42 /* Only strdup the name if we actually will need to modify it. */
43 if (t
->is_record() || (t
->is_array() && t
->fields
.array
->is_record())) {
44 char *name
= ralloc_strdup(NULL
, var
->name
);
45 recursion(var
->type
, &name
, strlen(name
));
48 this->visit_field(t
, var
->name
);
53 uniform_field_visitor::recursion(const glsl_type
*t
, char **name
,
56 /* Records need to have each field processed individually.
58 * Arrays of records need to have each array element processed
59 * individually, then each field of the resulting array elements processed
63 for (unsigned i
= 0; i
< t
->length
; i
++) {
64 const char *field
= t
->fields
.structure
[i
].name
;
66 /* Append '.field' to the current uniform name. */
67 ralloc_asprintf_rewrite_tail(name
, name_length
, ".%s", field
);
69 recursion(t
->fields
.structure
[i
].type
, name
,
70 name_length
+ 1 + strlen(field
));
72 } else if (t
->is_array() && t
->fields
.array
->is_record()) {
73 for (unsigned i
= 0; i
< t
->length
; i
++) {
76 /* Append the subscript to the current uniform name */
77 const unsigned subscript_length
= snprintf(subscript
, 13, "[%u]", i
);
78 ralloc_asprintf_rewrite_tail(name
, name_length
, "%s", subscript
);
80 recursion(t
->fields
.array
, name
, name_length
+ subscript_length
);
83 this->visit_field(t
, *name
);