Merge branch 'nouveau-import'
[mesa.git] / src / mesa / shader / slang / slang_storage.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #if !defined SLANG_STORAGE_H
26 #define SLANG_STORAGE_H
27
28 #include "slang_compile.h"
29 #include "slang_assemble.h"
30 #include "slang_execute.h"
31
32 #if defined __cplusplus
33 extern "C" {
34 #endif
35
36 /*
37 * Program variable data storage is kept completely transparent to the front-end compiler. It is
38 * up to the back-end how the data is actually allocated. The slang_storage_type enum
39 * provides the basic information about how the memory is interpreted. This abstract piece
40 * of memory is called a data slot. A data slot of a particular type has a fixed size.
41 *
42 * For now, only the three basic types are supported, that is bool, int and float. Other built-in
43 * types like vector or matrix can easily be decomposed into a series of basic types.
44 *
45 * If the vec4 module is enabled, 4-component vectors of floats are used when possible. 4x4 matrices
46 * are constructed of 4 vec4 slots.
47 */
48 typedef enum slang_storage_type_
49 {
50 /* core */
51 slang_stor_aggregate,
52 slang_stor_bool,
53 slang_stor_int,
54 slang_stor_float,
55 /* vec4 */
56 slang_stor_vec4
57 } slang_storage_type;
58
59 /*
60 * The slang_storage_array structure groups data slots of the same type into an array. This
61 * array has a fixed length. Arrays are required to have a size equal to the sum of sizes of its
62 * elements. They are also required to support indirect addressing. That is, if B references
63 * first data slot in the array, S is the size of the data slot and I is the integral index that
64 * is not known at compile time, B+I*S references I-th data slot.
65 *
66 * This structure is also used to break down built-in data types that are not supported directly.
67 * Vectors, like vec3, are constructed from arrays of their basic types. Matrices are formed of
68 * an array of column vectors, which are in turn processed as other vectors.
69 */
70 typedef struct slang_storage_array_
71 {
72 slang_storage_type type;
73 struct slang_storage_aggregate_ *aggregate; /* slang_stor_aggregate */
74 GLuint length;
75 } slang_storage_array;
76
77 GLboolean slang_storage_array_construct (slang_storage_array *);
78 GLvoid slang_storage_array_destruct (slang_storage_array *);
79
80 /*
81 * The slang_storage_aggregate structure relaxes the indirect addressing requirement for
82 * slang_storage_array structure. Aggregates are always accessed statically - its member
83 * addresses are well-known at compile time. For example, user-defined types are implemented as
84 * aggregates. Aggregates can collect data of a different type.
85 */
86 typedef struct slang_storage_aggregate_
87 {
88 slang_storage_array *arrays;
89 GLuint count;
90 } slang_storage_aggregate;
91
92 GLboolean slang_storage_aggregate_construct (slang_storage_aggregate *);
93 GLvoid slang_storage_aggregate_destruct (slang_storage_aggregate *);
94
95 extern GLboolean
96 _slang_aggregate_variable(slang_storage_aggregate *agg,
97 slang_type_specifier *spec,
98 GLuint array_len,
99 slang_function_scope *funcs,
100 slang_struct_scope *structs,
101 slang_variable_scope *vars,
102 slang_machine *mach,
103 slang_assembly_file *file,
104 slang_atom_pool *atoms);
105
106 extern GLboolean
107 _slang_evaluate_int(slang_assembly_file *file,
108 slang_machine *pmach,
109 slang_assembly_name_space *space,
110 slang_operation *array_size,
111 GLuint *pint,
112 slang_atom_pool *atoms);
113
114 /*
115 * Returns the size (in machine units) of the given storage type.
116 * It is an error to pass-in slang_stor_aggregate.
117 * Returns 0 on error.
118 */
119 extern GLuint
120 _slang_sizeof_type (slang_storage_type);
121
122 /*
123 * Returns total size (in machine units) of the given aggregate.
124 * Returns 0 on error.
125 */
126 GLuint _slang_sizeof_aggregate (const slang_storage_aggregate *);
127
128 /*
129 * Converts structured aggregate to a flat one, with arrays of generic type being
130 * one-element long.
131 * Returns GL_TRUE on success.
132 * Returns GL_FALSE otherwise.
133 */
134 GLboolean _slang_flatten_aggregate (slang_storage_aggregate *, const slang_storage_aggregate *);
135
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif
141