1 /*
2  * Copyright (C) 2013 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 RENDER_SCRIPT_DEFINES_H
18 #define RENDER_SCRIPT_DEFINES_H
19 
20 #include <stdint.h>
21 #include <sys/types.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 //////////////////////////////////////////////////////
28 //
29 
30 typedef void * RsAsyncVoidPtr;
31 
32 typedef void * RsAdapter1D;
33 typedef void * RsAdapter2D;
34 typedef void * RsAllocation;
35 typedef void * RsAnimation;
36 typedef void * RsClosure;
37 typedef void * RsContext;
38 typedef void * RsDevice;
39 typedef void * RsElement;
40 typedef void * RsFile;
41 typedef void * RsFont;
42 typedef void * RsSampler;
43 typedef void * RsScript;
44 typedef void * RsScriptKernelID;
45 typedef void * RsScriptInvokeID;
46 typedef void * RsScriptFieldID;
47 typedef void * RsScriptMethodID;
48 typedef void * RsScriptGroup;
49 typedef void * RsScriptGroup2;
50 typedef void * RsMesh;
51 typedef void * RsPath;
52 typedef void * RsType;
53 typedef void * RsObjectBase;
54 
55 typedef void * RsProgram;
56 typedef void * RsProgramVertex;
57 typedef void * RsProgramFragment;
58 typedef void * RsProgramStore;
59 typedef void * RsProgramRaster;
60 
61 typedef void * RsNativeWindow;
62 
63 typedef void (* RsBitmapCallback_t)(void *);
64 
65 typedef struct {
66     float m[16];
67 } rs_matrix4x4;
68 
69 typedef struct {
70     float m[9];
71 } rs_matrix3x3;
72 
73 typedef struct {
74     float m[4];
75 } rs_matrix2x2;
76 
77 enum RsDeviceParam {
78     RS_DEVICE_PARAM_FORCE_SOFTWARE_GL,
79     RS_DEVICE_PARAM_COUNT
80 };
81 
82 enum RsContextType {
83     RS_CONTEXT_TYPE_NORMAL,
84     RS_CONTEXT_TYPE_DEBUG,
85     RS_CONTEXT_TYPE_PROFILE
86 };
87 
88 
89 enum RsAllocationUsageType {
90     RS_ALLOCATION_USAGE_SCRIPT = 0x0001,
91     RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
92     RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
93     RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
94     RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010,
95     RS_ALLOCATION_USAGE_IO_INPUT = 0x0020,
96     RS_ALLOCATION_USAGE_IO_OUTPUT = 0x0040,
97     RS_ALLOCATION_USAGE_SHARED = 0x0080,
98 
99     RS_ALLOCATION_USAGE_OEM = 0x8000,
100     RS_ALLOCATION_USAGE_ALL = 0x80FF
101 };
102 
103 enum RsAllocationMipmapControl {
104     RS_ALLOCATION_MIPMAP_NONE = 0,
105     RS_ALLOCATION_MIPMAP_FULL = 1,
106     RS_ALLOCATION_MIPMAP_ON_SYNC_TO_TEXTURE = 2
107 };
108 
109 enum RsAllocationCubemapFace {
110     RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
111     RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
112     RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Y = 2,
113     RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Y = 3,
114     RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_Z = 4,
115     RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_Z = 5
116 };
117 
118 enum RsDataType {
119     RS_TYPE_NONE = 0,
120     RS_TYPE_FLOAT_16,
121     RS_TYPE_FLOAT_32,
122     RS_TYPE_FLOAT_64,
123     RS_TYPE_SIGNED_8,
124     RS_TYPE_SIGNED_16,
125     RS_TYPE_SIGNED_32,
126     RS_TYPE_SIGNED_64,
127     RS_TYPE_UNSIGNED_8,
128     RS_TYPE_UNSIGNED_16,
129     RS_TYPE_UNSIGNED_32,
130     RS_TYPE_UNSIGNED_64,
131 
132     RS_TYPE_BOOLEAN,
133 
134     RS_TYPE_UNSIGNED_5_6_5,
135     RS_TYPE_UNSIGNED_5_5_5_1,
136     RS_TYPE_UNSIGNED_4_4_4_4,
137 
138     RS_TYPE_MATRIX_4X4,
139     RS_TYPE_MATRIX_3X3,
140     RS_TYPE_MATRIX_2X2,
141 
142     RS_TYPE_ELEMENT = 1000,
143     RS_TYPE_TYPE,
144     RS_TYPE_ALLOCATION,
145     RS_TYPE_SAMPLER,
146     RS_TYPE_SCRIPT,
147     RS_TYPE_MESH,
148     RS_TYPE_PROGRAM_FRAGMENT,
149     RS_TYPE_PROGRAM_VERTEX,
150     RS_TYPE_PROGRAM_RASTER,
151     RS_TYPE_PROGRAM_STORE,
152     RS_TYPE_FONT,
153 
154     RS_TYPE_INVALID = 10000,
155 };
156 
157 enum RsDataKind {
158     RS_KIND_USER,
159 
160     RS_KIND_PIXEL_L = 7,
161     RS_KIND_PIXEL_A,
162     RS_KIND_PIXEL_LA,
163     RS_KIND_PIXEL_RGB,
164     RS_KIND_PIXEL_RGBA,
165     RS_KIND_PIXEL_DEPTH,
166     RS_KIND_PIXEL_YUV,
167 
168     RS_KIND_INVALID = 100,
169 };
170 
171 enum RsSamplerParam {
172     RS_SAMPLER_MIN_FILTER,
173     RS_SAMPLER_MAG_FILTER,
174     RS_SAMPLER_WRAP_S,
175     RS_SAMPLER_WRAP_T,
176     RS_SAMPLER_WRAP_R,
177     RS_SAMPLER_ANISO
178 };
179 
180 enum RsSamplerValue {
181     RS_SAMPLER_NEAREST,
182     RS_SAMPLER_LINEAR,
183     RS_SAMPLER_LINEAR_MIP_LINEAR,
184     RS_SAMPLER_WRAP,
185     RS_SAMPLER_CLAMP,
186     RS_SAMPLER_LINEAR_MIP_NEAREST,
187     RS_SAMPLER_MIRRORED_REPEAT,
188 
189     RS_SAMPLER_INVALID = 100,
190 };
191 
192 enum RsDimension {
193     RS_DIMENSION_X,
194     RS_DIMENSION_Y,
195     RS_DIMENSION_Z,
196     RS_DIMENSION_LOD,
197     RS_DIMENSION_FACE,
198 
199     RS_DIMENSION_ARRAY_0 = 100,
200     RS_DIMENSION_ARRAY_1,
201     RS_DIMENSION_ARRAY_2,
202     RS_DIMENSION_ARRAY_3,
203     RS_DIMENSION_MAX = RS_DIMENSION_ARRAY_3
204 };
205 
206 
207 enum RsError {
208     RS_ERROR_NONE = 0,
209     RS_ERROR_BAD_SHADER = 1,
210     RS_ERROR_BAD_SCRIPT = 2,
211     RS_ERROR_BAD_VALUE = 3,
212     RS_ERROR_OUT_OF_MEMORY = 4,
213     RS_ERROR_DRIVER = 5,
214 
215     // Errors that only occur in the debug context.
216     RS_ERROR_FATAL_DEBUG = 0x0800,
217 
218     RS_ERROR_FATAL_UNKNOWN = 0x1000,
219     RS_ERROR_FATAL_DRIVER = 0x1001,
220     RS_ERROR_FATAL_PROGRAM_LINK = 0x1002
221 };
222 
223 enum RsForEachStrategy {
224     RS_FOR_EACH_STRATEGY_SERIAL = 0,
225     RS_FOR_EACH_STRATEGY_DONT_CARE = 1,
226     RS_FOR_EACH_STRATEGY_DST_LINEAR = 2,
227     RS_FOR_EACH_STRATEGY_TILE_SMALL = 3,
228     RS_FOR_EACH_STRATEGY_TILE_MEDIUM = 4,
229     RS_FOR_EACH_STRATEGY_TILE_LARGE = 5
230 };
231 
232 // Script to Script
233 typedef struct {
234     enum RsForEachStrategy strategy;
235     uint32_t xStart;
236     uint32_t xEnd;
237     uint32_t yStart;
238     uint32_t yEnd;
239     uint32_t zStart;
240     uint32_t zEnd;
241     uint32_t arrayStart;
242     uint32_t arrayEnd;
243     uint32_t array2Start;
244     uint32_t array2End;
245     uint32_t array3Start;
246     uint32_t array3End;
247     uint32_t array4Start;
248     uint32_t array4End;
249 
250 } RsScriptCall;
251 
252 enum RsContextFlags {
253     RS_CONTEXT_SYNCHRONOUS      = 0x0001,
254     RS_CONTEXT_LOW_LATENCY      = 0x0002,
255     RS_CONTEXT_LOW_POWER        = 0x0004,
256     RS_CONTEXT_WAIT_FOR_ATTACH  = 0x0008
257 };
258 
259 enum RsBlasTranspose {
260     RsBlasNoTrans=111,
261     RsBlasTrans=112,
262     RsBlasConjTrans=113
263 };
264 
265 enum RsBlasUplo {
266     RsBlasUpper=121,
267     RsBlasLower=122
268 };
269 
270 enum RsBlasDiag {
271     RsBlasNonUnit=131,
272     RsBlasUnit=132
273 };
274 
275 enum RsBlasSide {
276     RsBlasLeft=141,
277     RsBlasRight=142
278 };
279 
280 enum RsBlasFunction {
281     RsBlas_nop = 0,
282     RsBlas_sdsdot = 1,
283     RsBlas_dsdot = 2,
284     RsBlas_sdot = 3,
285     RsBlas_ddot = 4,
286     RsBlas_cdotu_sub = 5,
287     RsBlas_cdotc_sub = 6,
288     RsBlas_zdotu_sub = 7,
289     RsBlas_zdotc_sub = 8,
290     RsBlas_snrm2 = 9,
291     RsBlas_sasum = 10,
292     RsBlas_dnrm2 = 11,
293     RsBlas_dasum = 12,
294     RsBlas_scnrm2 = 13,
295     RsBlas_scasum = 14,
296     RsBlas_dznrm2 = 15,
297     RsBlas_dzasum = 16,
298     RsBlas_isamax = 17,
299     RsBlas_idamax = 18,
300     RsBlas_icamax = 19,
301     RsBlas_izamax = 20,
302     RsBlas_sswap = 21,
303     RsBlas_scopy = 22,
304     RsBlas_saxpy = 23,
305     RsBlas_dswap = 24,
306     RsBlas_dcopy = 25,
307     RsBlas_daxpy = 26,
308     RsBlas_cswap = 27,
309     RsBlas_ccopy = 28,
310     RsBlas_caxpy = 29,
311     RsBlas_zswap = 30,
312     RsBlas_zcopy = 31,
313     RsBlas_zaxpy = 32,
314     RsBlas_srotg = 33,
315     RsBlas_srotmg = 34,
316     RsBlas_srot = 35,
317     RsBlas_srotm = 36,
318     RsBlas_drotg = 37,
319     RsBlas_drotmg = 38,
320     RsBlas_drot = 39,
321     RsBlas_drotm = 40,
322     RsBlas_sscal = 41,
323     RsBlas_dscal = 42,
324     RsBlas_cscal = 43,
325     RsBlas_zscal = 44,
326     RsBlas_csscal = 45,
327     RsBlas_zdscal = 46,
328     RsBlas_sgemv = 47,
329     RsBlas_sgbmv = 48,
330     RsBlas_strmv = 49,
331     RsBlas_stbmv = 50,
332     RsBlas_stpmv = 51,
333     RsBlas_strsv = 52,
334     RsBlas_stbsv = 53,
335     RsBlas_stpsv = 54,
336     RsBlas_dgemv = 55,
337     RsBlas_dgbmv = 56,
338     RsBlas_dtrmv = 57,
339     RsBlas_dtbmv = 58,
340     RsBlas_dtpmv = 59,
341     RsBlas_dtrsv = 60,
342     RsBlas_dtbsv = 61,
343     RsBlas_dtpsv = 62,
344     RsBlas_cgemv = 63,
345     RsBlas_cgbmv = 64,
346     RsBlas_ctrmv = 65,
347     RsBlas_ctbmv = 66,
348     RsBlas_ctpmv = 67,
349     RsBlas_ctrsv = 68,
350     RsBlas_ctbsv = 69,
351     RsBlas_ctpsv = 70,
352     RsBlas_zgemv = 71,
353     RsBlas_zgbmv = 72,
354     RsBlas_ztrmv = 73,
355     RsBlas_ztbmv = 74,
356     RsBlas_ztpmv = 75,
357     RsBlas_ztrsv = 76,
358     RsBlas_ztbsv = 77,
359     RsBlas_ztpsv = 78,
360     RsBlas_ssymv = 79,
361     RsBlas_ssbmv = 80,
362     RsBlas_sspmv = 81,
363     RsBlas_sger = 82,
364     RsBlas_ssyr = 83,
365     RsBlas_sspr = 84,
366     RsBlas_ssyr2 = 85,
367     RsBlas_sspr2 = 86,
368     RsBlas_dsymv = 87,
369     RsBlas_dsbmv = 88,
370     RsBlas_dspmv = 89,
371     RsBlas_dger = 90,
372     RsBlas_dsyr = 91,
373     RsBlas_dspr = 92,
374     RsBlas_dsyr2 = 93,
375     RsBlas_dspr2 = 94,
376     RsBlas_chemv = 95,
377     RsBlas_chbmv = 96,
378     RsBlas_chpmv = 97,
379     RsBlas_cgeru = 98,
380     RsBlas_cgerc = 99,
381     RsBlas_cher = 100,
382     RsBlas_chpr = 101,
383     RsBlas_cher2 = 102,
384     RsBlas_chpr2 = 103,
385     RsBlas_zhemv = 104,
386     RsBlas_zhbmv = 105,
387     RsBlas_zhpmv = 106,
388     RsBlas_zgeru = 107,
389     RsBlas_zgerc = 108,
390     RsBlas_zher = 109,
391     RsBlas_zhpr = 110,
392     RsBlas_zher2 = 111,
393     RsBlas_zhpr2 = 112,
394     RsBlas_sgemm = 113,
395     RsBlas_ssymm = 114,
396     RsBlas_ssyrk = 115,
397     RsBlas_ssyr2k = 116,
398     RsBlas_strmm = 117,
399     RsBlas_strsm = 118,
400     RsBlas_dgemm = 119,
401     RsBlas_dsymm = 120,
402     RsBlas_dsyrk = 121,
403     RsBlas_dsyr2k = 122,
404     RsBlas_dtrmm = 123,
405     RsBlas_dtrsm = 124,
406     RsBlas_cgemm = 125,
407     RsBlas_csymm = 126,
408     RsBlas_csyrk = 127,
409     RsBlas_csyr2k = 128,
410     RsBlas_ctrmm = 129,
411     RsBlas_ctrsm = 130,
412     RsBlas_zgemm = 131,
413     RsBlas_zsymm = 132,
414     RsBlas_zsyrk = 133,
415     RsBlas_zsyr2k = 134,
416     RsBlas_ztrmm = 135,
417     RsBlas_ztrsm = 136,
418     RsBlas_chemm = 137,
419     RsBlas_cherk = 138,
420     RsBlas_cher2k = 139,
421     RsBlas_zhemm = 140,
422     RsBlas_zherk = 141,
423     RsBlas_zher2k = 142,
424 
425     // BLAS extensions start here
426     RsBlas_bnnm = 1000,
427 };
428 
429 // custom complex types because of NDK support
430 typedef struct {
431     float r;
432     float i;
433 } RsFloatComplex;
434 
435 typedef struct {
436     double r;
437     double i;
438 } RsDoubleComplex;
439 
440 typedef union {
441     float f;
442     RsFloatComplex c;
443     double d;
444     RsDoubleComplex z;
445 } RsBlasScalar;
446 
447 typedef struct {
448     RsBlasFunction func;
449     RsBlasTranspose transA;
450     RsBlasTranspose transB;
451     RsBlasUplo uplo;
452     RsBlasDiag diag;
453     RsBlasSide side;
454     int M;
455     int N;
456     int K;
457     RsBlasScalar alpha;
458     RsBlasScalar beta;
459     int incX;
460     int incY;
461     int KL;
462     int KU;
463     uint8_t a_offset;
464     uint8_t b_offset;
465     int32_t c_offset;
466     int32_t c_mult_int;
467 } RsBlasCall;
468 
469 enum RsGlobalProperty {
470     RS_GLOBAL_TYPE     = 0x0000FFFF,
471     RS_GLOBAL_CONSTANT = 0x00010000,
472     RS_GLOBAL_STATIC   = 0x00020000,
473     RS_GLOBAL_POINTER  = 0x00040000
474 };
475 
476 // Special symbols embedded into a shared object compiled by bcc.
477 static const char kRoot[] = "root";
478 static const char kInit[] = "init";
479 static const char kRsDtor[] = ".rs.dtor";
480 static const char kRsInfo[] = ".rs.info";
481 static const char kRsGlobalEntries[] = ".rs.global_entries";
482 static const char kRsGlobalNames[] = ".rs.global_names";
483 static const char kRsGlobalAddresses[] = ".rs.global_addresses";
484 static const char kRsGlobalSizes[] = ".rs.global_sizes";
485 static const char kRsGlobalProperties[] = ".rs.global_properties";
486 
getGlobalRsType(uint32_t properties)487 static inline uint32_t getGlobalRsType(uint32_t properties) {
488     return properties & RS_GLOBAL_TYPE;
489 }
isGlobalConstant(uint32_t properties)490 static inline bool isGlobalConstant(uint32_t properties) {
491     return properties & RS_GLOBAL_CONSTANT;
492 }
isGlobalStatic(uint32_t properties)493 static inline bool isGlobalStatic(uint32_t properties) {
494     return properties & RS_GLOBAL_STATIC;
495 }
isGlobalPointer(uint32_t properties)496 static inline bool isGlobalPointer(uint32_t properties) {
497     return properties & RS_GLOBAL_POINTER;
498 }
499 
500 #ifdef __cplusplus
501 };
502 #endif
503 
504 #endif // RENDER_SCRIPT_DEFINES_H
505