blob: bd7b1571723d5848dee3ffb577ce12657004288d [file] [log] [blame]
Zonr Chang0307eaa2010-10-22 02:29:53 +08001/*
2 * Copyright 2010, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Stephen Hinese639eb52010-11-08 19:27:20 -080017#ifndef _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ // NOLINT
18#define _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_
Zonr Chang0307eaa2010-10-22 02:29:53 +080019
20#define RS_DATA_TYPE_CLASS_ENUMS \
21 ENUM_RS_DATA_TYPE_CLASS(Primitive) \
22 ENUM_RS_DATA_TYPE_CLASS(Pointer) \
23 ENUM_RS_DATA_TYPE_CLASS(Vector) \
24 ENUM_RS_DATA_TYPE_CLASS(Matrix) \
25 ENUM_RS_DATA_TYPE_CLASS(ConstantArray) \
26 ENUM_RS_DATA_TYPE_CLASS(Record)
27
28#define PRIMITIVE_DATA_TYPE_ENUMS \
29 ENUM_PRIMITIVE_DATA_TYPE(Float16, NULL, 128) \
30 ENUM_PRIMITIVE_DATA_TYPE(Float32, "float", 256) \
31 ENUM_PRIMITIVE_DATA_TYPE(Float64, "double", 512) \
32 ENUM_PRIMITIVE_DATA_TYPE(Signed8, "char", 64) \
33 ENUM_PRIMITIVE_DATA_TYPE(Signed16, "short", 128) \
34 ENUM_PRIMITIVE_DATA_TYPE(Signed32, "int", 256) \
35 ENUM_PRIMITIVE_DATA_TYPE(Signed64, "long", 512) \
36 ENUM_PRIMITIVE_DATA_TYPE(Unsigned8, "uchar", 64) \
37 ENUM_PRIMITIVE_DATA_TYPE(Unsigned16, "ushort", 128) \
38 ENUM_PRIMITIVE_DATA_TYPE(Unsigned32, "uint", 256) \
39 ENUM_PRIMITIVE_DATA_TYPE(Unsigned64, "ulong", 512) \
40 ENUM_PRIMITIVE_DATA_TYPE(Boolean, "bool", 8) \
41 ENUM_PRIMITIVE_DATA_TYPE(Unsigned565, "u565", 128) \
42 ENUM_PRIMITIVE_DATA_TYPE(Unsigned5551, "u5551", 128) \
Zonr Changb1771ef2010-10-22 18:03:46 +080043 ENUM_PRIMITIVE_DATA_TYPE(Unsigned4444, "u4444", 128) \
44 PRIMITIVE_DATA_TYPE_RANGE(Float16, Unsigned4444)
45
46#define RS_MATRIX_DATA_TYPE_ENUMS \
47 ENUM_RS_MATRIX_DATA_TYPE(RSMatrix2x2, "rs_matrix2x2", 2) \
48 ENUM_RS_MATRIX_DATA_TYPE(RSMatrix3x3, "rs_matrix3x3", 3) \
49 ENUM_RS_MATRIX_DATA_TYPE(RSMatrix4x4, "rs_matrix4x4", 4) \
50 RS_MATRIX_DATA_TYPE_RANGE(RSMatrix2x2, RSMatrix4x4)
Zonr Chang0307eaa2010-10-22 02:29:53 +080051
52#define RS_OBJECT_DATA_TYPE_ENUMS \
Zonr Chang0307eaa2010-10-22 02:29:53 +080053 ENUM_RS_OBJECT_DATA_TYPE(RSElement, "rs_element") \
54 ENUM_RS_OBJECT_DATA_TYPE(RSType, "rs_type") \
55 ENUM_RS_OBJECT_DATA_TYPE(RSAllocation, "rs_allocation") \
56 ENUM_RS_OBJECT_DATA_TYPE(RSSampler, "rs_sampler") \
57 ENUM_RS_OBJECT_DATA_TYPE(RSScript, "rs_script") \
58 ENUM_RS_OBJECT_DATA_TYPE(RSMesh, "rs_mesh") \
59 ENUM_RS_OBJECT_DATA_TYPE(RSProgramFragment, "rs_program_fragment") \
60 ENUM_RS_OBJECT_DATA_TYPE(RSProgramVertex, "rs_program_vertex") \
61 ENUM_RS_OBJECT_DATA_TYPE(RSProgramRaster, "rs_program_raster") \
62 ENUM_RS_OBJECT_DATA_TYPE(RSProgramStore, "rs_program_store") \
Zonr Changb1771ef2010-10-22 18:03:46 +080063 ENUM_RS_OBJECT_DATA_TYPE(RSFont, "rs_font") \
64 RS_OBJECT_DATA_TYPE_RANGE(RSElement, RSFont)
Zonr Chang0307eaa2010-10-22 02:29:53 +080065
66#define RS_DATA_KIND_ENUMS \
67 ENUM_RS_DATA_KIND(User) \
68 ENUM_RS_DATA_KIND(PixelL) \
69 ENUM_RS_DATA_KIND(PixelA) \
70 ENUM_RS_DATA_KIND(PixelLA) \
71 ENUM_RS_DATA_KIND(PixelRGB) \
72 ENUM_RS_DATA_KIND(PixelRGBA)
73
74enum RSTypeClass {
75#define ENUM_RS_DATA_TYPE_CLASS(x) RS_TC_ ## x,
76 RS_DATA_TYPE_CLASS_ENUMS
77#undef ENUM_RS_DATA_TYPE_CLASS
78 RS_TC_Max
79};
80
81enum RSDataType {
82#define ENUM_PRIMITIVE_DATA_TYPE(x, name, bits) RS_DT_ ## x,
Zonr Changb1771ef2010-10-22 18:03:46 +080083#define PRIMITIVE_DATA_TYPE_RANGE(x, y) \
84 RS_DT_FirstPrimitiveType = RS_DT_ ## x, \
85 RS_DT_LastPrimitiveType = RS_DT_ ## y,
Zonr Chang0307eaa2010-10-22 02:29:53 +080086 PRIMITIVE_DATA_TYPE_ENUMS
Zonr Chang0307eaa2010-10-22 02:29:53 +080087#undef ENUM_PRIMITIVE_DATA_TYPE
Zonr Changb1771ef2010-10-22 18:03:46 +080088#undef PRIMITIVE_DATA_TYPE_RANGE
89
90#define ENUM_RS_MATRIX_DATA_TYPE(x, name, dim) RS_DT_ ## x,
91#define RS_MATRIX_DATA_TYPE_RANGE(x, y) \
92 RS_DT_FirstMatrixType = RS_DT_ ## x, \
93 RS_DT_LastMatrixType = RS_DT_ ## y,
94 RS_MATRIX_DATA_TYPE_ENUMS
95#undef ENUM_RS_MATRIX_DATA_TYPE
96#undef RS_MATRIX_DATA_TYPE_RANGE
97
98#define ENUM_RS_OBJECT_DATA_TYPE(x, name) RS_DT_ ## x,
99#define RS_OBJECT_DATA_TYPE_RANGE(x, y) \
100 RS_DT_FirstRSObjectType = RS_DT_ ## x, \
101 RS_DT_LastRSObjectType = RS_DT_ ## y,
102 RS_OBJECT_DATA_TYPE_ENUMS
Zonr Chang0307eaa2010-10-22 02:29:53 +0800103#undef ENUM_RS_OBJECT_DATA_TYPE
Zonr Changb1771ef2010-10-22 18:03:46 +0800104#undef RS_OBJECT_DATA_TYPE_RANGE
105
Zonr Chang0307eaa2010-10-22 02:29:53 +0800106 RS_DT_USER_DEFINED
107};
108
109enum RSDataKind {
110#define ENUM_RS_DATA_KIND(x) RS_DK_ ## x,
111 RS_DATA_KIND_ENUMS
112#undef ENUM_RS_DATA_KIND
113 RS_DK_Max
114};
115
116// Forward declaration
117union RSType;
118
119// NOTE: Current design need to keep struct RSTypeBase as a 4-byte integer for
120// efficient decoding process (see DecodeTypeMetadata).
121struct RSTypeBase {
122 /* enum RSTypeClass tc; */
123 // tc is encoded in b[0].
124 union {
125 // FIXME: handle big-endianess case
126 unsigned bits; // NOTE: Little-endian is assumed.
127 unsigned char b[4];
128 };
129};
130
131struct RSPrimitiveType {
132 struct RSTypeBase base;
133 /* enum RSDataType dt; */
134 // dt is encoded in base.b[1]
135};
136
137struct RSPointerType {
138 struct RSTypeBase base;
139 const union RSType *pointee;
140};
141
142struct RSVectorType {
143 struct RSPrimitiveType base; // base type of vec must be in primitive type
144 /* unsigned char vsize; */
145 // vsize is encoded in base.b[2]
146};
147
Zonr Changa7a828d2010-10-22 03:44:27 +0800148// RSMatrixType is actually a specialize class of RSPrimitiveType whose value of
149// dt (data type) can only be RS_DT_RSMatrix2x2, RS_DT_RSMatrix3x3 and
150// RS_DT_RSMatrix4x4.
Zonr Chang0307eaa2010-10-22 02:29:53 +0800151struct RSMatrixType {
152 struct RSTypeBase base;
153};
154
155struct RSConstantArrayType {
156 struct RSTypeBase base;
157 const union RSType *element_type;
158 /* unsigned esize; */
159 // esize is encoded in base.bits{8-31} in little-endian way. This implicates
160 // the number of elements in any constant array type should never exceed 2^24.
161};
162
163struct RSRecordField {
Stephen Hinese639eb52010-11-08 19:27:20 -0800164 const char *name; // field name
Zonr Chang0307eaa2010-10-22 02:29:53 +0800165 const union RSType *type;
166 enum RSDataKind dk;
167};
168
169struct RSRecordType {
170 struct RSTypeBase base;
171 const char *name; // type name
172 /* unsigned num_fields; */
173 // num_fields is encoded in base.bits{16-31} in little-endian way. This
174 // implicates the number of fields defined in any record type should never
175 // exceed 2^16.
176
177 struct RSRecordField field[1];
178};
179
180union RSType {
181 struct RSTypeBase base;
182 struct RSPrimitiveType prim;
183 struct RSPointerType pointer;
184 struct RSVectorType vec;
185 struct RSConstantArrayType ca;
186 struct RSRecordType rec;
187};
188
189#define RS_GET_TYPE_BASE(R) (&((R)->base))
190#define RS_CAST_TO_PRIMITIVE_TYPE(R) (&((R)->prim))
191#define RS_CAST_TO_POINTER_TYPE(R) (&((R)->pointer))
192#define RS_CAST_TO_VECTOR_TYPE(R) (&((R)->vec))
193#define RS_CAST_TO_CONSTANT_ARRAY_TYPE(R) (&((R)->ca))
194#define RS_CAST_TO_RECORD_TYPE(R) (&((R)->rec))
195
196// RSType
197#define RS_TYPE_GET_CLASS(R) RS_GET_TYPE_BASE(R)->b[0]
198#define RS_TYPE_SET_CLASS(R, V) RS_TYPE_GET_CLASS(R) = (V)
199
200// RSPrimitiveType
201#define RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R) \
202 RS_CAST_TO_PRIMITIVE_TYPE(R)->base.b[1]
203#define RS_PRIMITIVE_TYPE_SET_DATA_TYPE(R, V) \
204 RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R) = (V)
205
206// RSPointerType
207#define RS_POINTER_TYPE_GET_POINTEE_TYPE(R) \
208 RS_CAST_TO_POINTER_TYPE(R)->pointee
209#define RS_POINTER_TYPE_SET_POINTEE_TYPE(R, V) \
210 RS_POINTER_TYPE_GET_POINTEE_TYPE(R) = (V)
211
212// RSVectorType
213#define RS_VECTOR_TYPE_GET_ELEMENT_TYPE(R) \
214 RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R)
215#define RS_VECTOR_TYPE_SET_ELEMENT_TYPE(R, V) \
216 RS_VECTOR_TYPE_GET_ELEMENT_TYPE(R) = (V)
217
218#define RS_VECTOR_TYPE_GET_VECTOR_SIZE(R) \
219 RS_CAST_TO_VECTOR_TYPE(R)->base.base.b[2]
220#define RS_VECTOR_TYPE_SET_VECTOR_SIZE(R, V) \
221 RS_VECTOR_TYPE_GET_VECTOR_SIZE(R) = (V)
222
223// RSMatrixType
Zonr Changa7a828d2010-10-22 03:44:27 +0800224#define RS_MATRIX_TYPE_GET_DATA_TYPE(R) RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R)
225#define RS_MATRIX_TYPE_SET_DATA_TYPE(R, V) \
226 RS_MATRIX_TYPE_GET_DATA_TYPE(R) = (V)
Zonr Chang0307eaa2010-10-22 02:29:53 +0800227
228// RSConstantArrayType
229#define RS_CONSTANT_ARRAY_TYPE_GET_ELEMENT_TYPE(R) \
230 RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->element_type
231#define RS_CONSTANT_ARRAY_TYPE_SET_ELEMENT_TYPE(R, V) \
232 RS_CONSTANT_ARRAY_TYPE_GET_ELEMENT_TYPE(R) = (V)
233
234#define RS_CONSTANT_ARRAY_TYPE_GET_ELEMENT_SIZE(R) \
235 (RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->base.bits & 0x00ffffff)
236#define RS_CONSTANT_ARRAY_TYPE_SET_ELEMENT_SIZE(R, V) \
237 RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->base.bits = \
238 ((RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->base.bits & 0x000000ff) | \
239 ((V & 0xffffff) << 8))
240
241// RSRecordType
242#define RS_RECORD_TYPE_GET_NAME(R) RS_CAST_TO_RECORD_TYPE(R)->name
243#define RS_RECORD_TYPE_SET_NAME(R, V) RS_RECORD_TYPE_GET_NAME(R) = (V)
244
245#define RS_RECORD_TYPE_GET_NUM_FIELDS(R) \
246 ((RS_CAST_TO_RECORD_TYPE(R)->base.bits & 0xffff0000) >> 16)
247#define RS_RECORD_TYPE_SET_NUM_FIELDS(R, V) \
248 RS_CAST_TO_RECORD_TYPE(R)->base.bits = \
249 ((RS_CAST_TO_RECORD_TYPE(R)->base.bits & 0x0000ffff) | ((V & 0xffff) << 16))
250
251#define RS_RECORD_TYPE_GET_FIELD_NAME(R, I) \
252 RS_CAST_TO_RECORD_TYPE(R)->field[(I)].name
253#define RS_RECORD_TYPE_SET_FIELD_NAME(R, I, V) \
254 RS_RECORD_TYPE_GET_FIELD_NAME(R, I) = (V)
255
256#define RS_RECORD_TYPE_GET_FIELD_TYPE(R, I) \
257 RS_CAST_TO_RECORD_TYPE(R)->field[(I)].type
258#define RS_RECORD_TYPE_SET_FIELD_TYPE(R, I, V) \
259 RS_RECORD_TYPE_GET_FIELD_TYPE(R, I) = (V)
260
261#define RS_RECORD_TYPE_GET_FIELD_DATA_KIND(R, I) \
262 RS_CAST_TO_RECORD_TYPE(R)->field[(I)].dk
263#define RS_RECORD_TYPE_SET_FIELD_DATA_KIND(R, I, V) \
264 RS_RECORD_TYPE_GET_FIELD_DATA_KIND(R, I) = (V)
265
Stephen Hinese639eb52010-11-08 19:27:20 -0800266#endif // _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ NOLINT