glsl: Modify uniform_field_visitor::recursion to take a row_major parameter
[mesa.git] / src / glsl / linker.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2010 Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #pragma once
26 #ifndef GLSL_LINKER_H
27 #define GLSL_LINKER_H
28
29 extern bool
30 link_function_calls(gl_shader_program *prog, gl_shader *main,
31 gl_shader **shader_list, unsigned num_shaders);
32
33 extern void
34 link_invalidate_variable_locations(gl_shader *sh, enum ir_variable_mode mode,
35 int generic_base);
36
37 extern void
38 link_assign_uniform_locations(struct gl_shader_program *prog);
39
40 extern void
41 link_set_uniform_initializers(struct gl_shader_program *prog);
42
43 extern int
44 link_cross_validate_uniform_block(void *mem_ctx,
45 struct gl_uniform_block **linked_blocks,
46 unsigned int *num_linked_blocks,
47 struct gl_uniform_block *new_block);
48
49 void
50 link_assign_uniform_block_offsets(struct gl_shader *shader);
51
52 extern bool
53 link_uniform_blocks_are_compatible(const gl_uniform_block *a,
54 const gl_uniform_block *b);
55
56 /**
57 * Class for processing all of the leaf fields of an uniform
58 *
59 * Leaves are, roughly speaking, the parts of the uniform that the application
60 * could query with \c glGetUniformLocation (or that could be returned by
61 * \c glGetActiveUniforms).
62 *
63 * Classes my derive from this class to implement specific functionality.
64 * This class only provides the mechanism to iterate over the leaves. Derived
65 * classes must implement \c ::visit_field and may override \c ::process.
66 */
67 class uniform_field_visitor {
68 public:
69 /**
70 * Begin processing a uniform
71 *
72 * Classes that overload this function should call \c ::process from the
73 * base class to start the recursive processing of the uniform.
74 *
75 * \param var The uniform variable that is to be processed
76 *
77 * Calls \c ::visit_field for each leaf of the uniform.
78 *
79 * \warning
80 * This entry should only be used with uniform blocks in cases where the
81 * row / column ordering of matrices in the block does not matter. For
82 * example, enumerating the names of members of the block, but not for
83 * determining the offsets of members.
84 */
85 void process(ir_variable *var);
86
87 protected:
88 /**
89 * Method invoked for each leaf of the uniform
90 *
91 * \param type Type of the field.
92 * \param name Fully qualified name of the field.
93 */
94 virtual void visit_field(const glsl_type *type, const char *name) = 0;
95
96 private:
97 /**
98 * \param name_length Length of the current name \b not including the
99 * terminating \c NUL character.
100 */
101 void recursion(const glsl_type *t, char **name, size_t name_length,
102 bool row_major);
103 };
104
105 void
106 linker_error(gl_shader_program *prog, const char *fmt, ...);
107
108 void
109 linker_warning(gl_shader_program *prog, const char *fmt, ...);
110
111 unsigned
112 count_attribute_slots(const glsl_type *t);
113
114 #endif /* GLSL_LINKER_H */