1 /* 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 17 #ifndef _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ // NOLINT 18 #define _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ 19 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, 16) \ 30 ENUM_PRIMITIVE_DATA_TYPE(Float32, "float", 32) \ 31 ENUM_PRIMITIVE_DATA_TYPE(Float64, "double", 64) \ 32 ENUM_PRIMITIVE_DATA_TYPE(Signed8, "char", 8) \ 33 ENUM_PRIMITIVE_DATA_TYPE(Signed16, "short", 16) \ 34 ENUM_PRIMITIVE_DATA_TYPE(Signed32, "int", 32) \ 35 ENUM_PRIMITIVE_DATA_TYPE(Signed64, "long", 64) \ 36 ENUM_PRIMITIVE_DATA_TYPE(Unsigned8, "uchar", 8) \ 37 ENUM_PRIMITIVE_DATA_TYPE(Unsigned16, "ushort", 16) \ 38 ENUM_PRIMITIVE_DATA_TYPE(Unsigned32, "uint", 32) \ 39 ENUM_PRIMITIVE_DATA_TYPE(Unsigned64, "ulong", 64) \ 40 ENUM_PRIMITIVE_DATA_TYPE(Boolean, "bool", 8) \ 41 ENUM_PRIMITIVE_DATA_TYPE(Unsigned565, "u565", 16) \ 42 ENUM_PRIMITIVE_DATA_TYPE(Unsigned5551, "u5551", 16) \ 43 ENUM_PRIMITIVE_DATA_TYPE(Unsigned4444, "u4444", 16) \ 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) 51 52 #define RS_OBJECT_DATA_TYPE_ENUMS \ 53 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(RSPath, "rs_path") \ 60 ENUM_RS_OBJECT_DATA_TYPE(RSProgramFragment, "rs_program_fragment") \ 61 ENUM_RS_OBJECT_DATA_TYPE(RSProgramVertex, "rs_program_vertex") \ 62 ENUM_RS_OBJECT_DATA_TYPE(RSProgramRaster, "rs_program_raster") \ 63 ENUM_RS_OBJECT_DATA_TYPE(RSProgramStore, "rs_program_store") \ 64 ENUM_RS_OBJECT_DATA_TYPE(RSFont, "rs_font") \ 65 RS_OBJECT_DATA_TYPE_RANGE(RSElement, RSFont) 66 67 enum RSTypeClass { 68 #define ENUM_RS_DATA_TYPE_CLASS(x) RS_TC_ ## x, 69 RS_DATA_TYPE_CLASS_ENUMS 70 #undef ENUM_RS_DATA_TYPE_CLASS 71 RS_TC_Max 72 }; 73 74 enum RSDataType { 75 #define ENUM_PRIMITIVE_DATA_TYPE(x, name, bits) RS_DT_ ## x, 76 #define PRIMITIVE_DATA_TYPE_RANGE(x, y) \ 77 RS_DT_FirstPrimitiveType = RS_DT_ ## x, \ 78 RS_DT_LastPrimitiveType = RS_DT_ ## y, 79 PRIMITIVE_DATA_TYPE_ENUMS 80 #undef ENUM_PRIMITIVE_DATA_TYPE 81 #undef PRIMITIVE_DATA_TYPE_RANGE 82 83 #define ENUM_RS_MATRIX_DATA_TYPE(x, name, dim) RS_DT_ ## x, 84 #define RS_MATRIX_DATA_TYPE_RANGE(x, y) \ 85 RS_DT_FirstMatrixType = RS_DT_ ## x, \ 86 RS_DT_LastMatrixType = RS_DT_ ## y, 87 RS_MATRIX_DATA_TYPE_ENUMS 88 #undef ENUM_RS_MATRIX_DATA_TYPE 89 #undef RS_MATRIX_DATA_TYPE_RANGE 90 91 #define ENUM_RS_OBJECT_DATA_TYPE(x, name) RS_DT_ ## x, 92 #define RS_OBJECT_DATA_TYPE_RANGE(x, y) \ 93 RS_DT_FirstRSObjectType = RS_DT_ ## x, \ 94 RS_DT_LastRSObjectType = RS_DT_ ## y, 95 RS_OBJECT_DATA_TYPE_ENUMS 96 #undef ENUM_RS_OBJECT_DATA_TYPE 97 #undef RS_OBJECT_DATA_TYPE_RANGE 98 99 RS_DT_USER_DEFINED 100 }; 101 102 // Forward declaration 103 union RSType; 104 105 // NOTE: Current design need to keep struct RSTypeBase as a 4-byte integer for 106 // efficient decoding process (see DecodeTypeMetadata). 107 struct RSTypeBase { 108 /* enum RSTypeClass tc; */ 109 // tc is encoded in b[0]. 110 union { 111 // FIXME: handle big-endianess case 112 unsigned bits; // NOTE: Little-endian is assumed. 113 unsigned char b[4]; 114 }; 115 }; 116 117 struct RSPrimitiveType { 118 struct RSTypeBase base; 119 /* enum RSDataType dt; */ 120 // dt is encoded in base.b[1] 121 }; 122 123 struct RSPointerType { 124 struct RSTypeBase base; 125 const union RSType *pointee; 126 }; 127 128 struct RSVectorType { 129 struct RSPrimitiveType base; // base type of vec must be in primitive type 130 /* unsigned char vsize; */ 131 // vsize is encoded in base.b[2] 132 }; 133 134 // RSMatrixType is actually a specialize class of RSPrimitiveType whose value of 135 // dt (data type) can only be RS_DT_RSMatrix2x2, RS_DT_RSMatrix3x3 and 136 // RS_DT_RSMatrix4x4. 137 struct RSMatrixType { 138 struct RSTypeBase base; 139 }; 140 141 struct RSConstantArrayType { 142 struct RSTypeBase base; 143 const union RSType *element_type; 144 /* unsigned esize; */ 145 // esize is encoded in base.bits{8-31} in little-endian way. This implicates 146 // the number of elements in any constant array type should never exceed 2^24. 147 }; 148 149 struct RSRecordField { 150 const char *name; // field name 151 const union RSType *type; 152 }; 153 154 struct RSRecordType { 155 struct RSTypeBase base; 156 const char *name; // type name 157 /* unsigned num_fields; */ 158 // num_fields is encoded in base.bits{16-31} in little-endian way. This 159 // implicates the number of fields defined in any record type should never 160 // exceed 2^16. 161 162 struct RSRecordField field[1]; 163 }; 164 165 union RSType { 166 struct RSTypeBase base; 167 struct RSPrimitiveType prim; 168 struct RSPointerType pointer; 169 struct RSVectorType vec; 170 struct RSConstantArrayType ca; 171 struct RSRecordType rec; 172 }; 173 174 #define RS_GET_TYPE_BASE(R) (&((R)->base)) 175 #define RS_CAST_TO_PRIMITIVE_TYPE(R) (&((R)->prim)) 176 #define RS_CAST_TO_POINTER_TYPE(R) (&((R)->pointer)) 177 #define RS_CAST_TO_VECTOR_TYPE(R) (&((R)->vec)) 178 #define RS_CAST_TO_CONSTANT_ARRAY_TYPE(R) (&((R)->ca)) 179 #define RS_CAST_TO_RECORD_TYPE(R) (&((R)->rec)) 180 181 // RSType 182 #define RS_TYPE_GET_CLASS(R) RS_GET_TYPE_BASE(R)->b[0] 183 #define RS_TYPE_SET_CLASS(R, V) RS_TYPE_GET_CLASS(R) = (V) 184 185 // RSPrimitiveType 186 #define RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R) \ 187 RS_CAST_TO_PRIMITIVE_TYPE(R)->base.b[1] 188 #define RS_PRIMITIVE_TYPE_SET_DATA_TYPE(R, V) \ 189 RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R) = (V) 190 191 // RSPointerType 192 #define RS_POINTER_TYPE_GET_POINTEE_TYPE(R) \ 193 RS_CAST_TO_POINTER_TYPE(R)->pointee 194 #define RS_POINTER_TYPE_SET_POINTEE_TYPE(R, V) \ 195 RS_POINTER_TYPE_GET_POINTEE_TYPE(R) = (V) 196 197 // RSVectorType 198 #define RS_VECTOR_TYPE_GET_ELEMENT_TYPE(R) \ 199 RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R) 200 #define RS_VECTOR_TYPE_SET_ELEMENT_TYPE(R, V) \ 201 RS_VECTOR_TYPE_GET_ELEMENT_TYPE(R) = (V) 202 203 #define RS_VECTOR_TYPE_GET_VECTOR_SIZE(R) \ 204 RS_CAST_TO_VECTOR_TYPE(R)->base.base.b[2] 205 #define RS_VECTOR_TYPE_SET_VECTOR_SIZE(R, V) \ 206 RS_VECTOR_TYPE_GET_VECTOR_SIZE(R) = (V) 207 208 // RSMatrixType 209 #define RS_MATRIX_TYPE_GET_DATA_TYPE(R) RS_PRIMITIVE_TYPE_GET_DATA_TYPE(R) 210 #define RS_MATRIX_TYPE_SET_DATA_TYPE(R, V) \ 211 RS_MATRIX_TYPE_GET_DATA_TYPE(R) = (V) 212 213 // RSConstantArrayType 214 #define RS_CONSTANT_ARRAY_TYPE_GET_ELEMENT_TYPE(R) \ 215 RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->element_type 216 #define RS_CONSTANT_ARRAY_TYPE_SET_ELEMENT_TYPE(R, V) \ 217 RS_CONSTANT_ARRAY_TYPE_GET_ELEMENT_TYPE(R) = (V) 218 219 #define RS_CONSTANT_ARRAY_TYPE_GET_ELEMENT_SIZE(R) \ 220 (RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->base.bits & 0x00ffffff) 221 #define RS_CONSTANT_ARRAY_TYPE_SET_ELEMENT_SIZE(R, V) \ 222 RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->base.bits = \ 223 ((RS_CAST_TO_CONSTANT_ARRAY_TYPE(R)->base.bits & 0x000000ff) | \ 224 ((V & 0xffffff) << 8)) 225 226 // RSRecordType 227 #define RS_RECORD_TYPE_GET_NAME(R) RS_CAST_TO_RECORD_TYPE(R)->name 228 #define RS_RECORD_TYPE_SET_NAME(R, V) RS_RECORD_TYPE_GET_NAME(R) = (V) 229 230 #define RS_RECORD_TYPE_GET_NUM_FIELDS(R) \ 231 ((RS_CAST_TO_RECORD_TYPE(R)->base.bits & 0xffff0000) >> 16) 232 #define RS_RECORD_TYPE_SET_NUM_FIELDS(R, V) \ 233 RS_CAST_TO_RECORD_TYPE(R)->base.bits = \ 234 ((RS_CAST_TO_RECORD_TYPE(R)->base.bits & 0x0000ffff) | ((V & 0xffff) << 16)) 235 236 #define RS_RECORD_TYPE_GET_FIELD_NAME(R, I) \ 237 RS_CAST_TO_RECORD_TYPE(R)->field[(I)].name 238 #define RS_RECORD_TYPE_SET_FIELD_NAME(R, I, V) \ 239 RS_RECORD_TYPE_GET_FIELD_NAME(R, I) = (V) 240 241 #define RS_RECORD_TYPE_GET_FIELD_TYPE(R, I) \ 242 RS_CAST_TO_RECORD_TYPE(R)->field[(I)].type 243 #define RS_RECORD_TYPE_SET_FIELD_TYPE(R, I, V) \ 244 RS_RECORD_TYPE_GET_FIELD_TYPE(R, I) = (V) 245 246 #endif // _COMPILE_SLANG_SLANG_RS_TYPE_SPEC_H_ NOLINT 247