blob: 8a85f6ed5308b65c8d56be4a70d336eadfe777eb [file] [log] [blame]
Jason Samse45ac6e2009-07-20 14:31:06 -07001/*
2 * Copyright (C) 2009 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#include "rsContext.h"
18#include "rsScriptC.h"
19#include "rsMatrix.h"
20
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070021#include "utils/Timers.h"
Jason Samse45ac6e2009-07-20 14:31:06 -070022
Romain Guy98e10fd2009-07-30 18:45:01 -070023#include <time.h>
Romain Guy98e10fd2009-07-30 18:45:01 -070024
Jason Samse45ac6e2009-07-20 14:31:06 -070025using namespace android;
26using namespace android::renderscript;
27
28#define GET_TLS() Context::ScriptTLSStruct * tls = \
29 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
30 Context * rsc = tls->mContext; \
31 ScriptC * sc = (ScriptC *) tls->mScript
32
Jason Samsbe36bf32010-05-11 14:03:58 -070033
Jason Samse45ac6e2009-07-20 14:31:06 -070034//////////////////////////////////////////////////////////////////////////////
35// Math routines
36//////////////////////////////////////////////////////////////////////////////
37
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080038static float SC_sinf_fast(float x) {
Romain Guy2275d632009-08-18 11:39:17 -070039 const float A = 1.0f / (2.0f * M_PI);
40 const float B = -16.0f;
41 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -070042
Romain Guy2275d632009-08-18 11:39:17 -070043 // scale angle for easy argument reduction
44 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -070045
Romain Guy2275d632009-08-18 11:39:17 -070046 if (fabsf(x) >= 0.5f) {
47 // argument reduction
48 x = x - ceilf(x + 0.5f) + 1.0f;
49 }
Jason Samsa57c0a72009-09-04 14:42:41 -070050
Romain Guy2275d632009-08-18 11:39:17 -070051 const float y = B * x * fabsf(x) + C * x;
52 return 0.2215f * (y * fabsf(y) - y) + y;
53}
54
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080055static float SC_cosf_fast(float x) {
Romain Guy2275d632009-08-18 11:39:17 -070056 x += float(M_PI / 2);
57
58 const float A = 1.0f / (2.0f * M_PI);
59 const float B = -16.0f;
60 const float C = 8.0f;
Jason Samsa57c0a72009-09-04 14:42:41 -070061
Romain Guy2275d632009-08-18 11:39:17 -070062 // scale angle for easy argument reduction
63 x *= A;
Jason Samsa57c0a72009-09-04 14:42:41 -070064
Romain Guy2275d632009-08-18 11:39:17 -070065 if (fabsf(x) >= 0.5f) {
66 // argument reduction
67 x = x - ceilf(x + 0.5f) + 1.0f;
68 }
Jason Samsa57c0a72009-09-04 14:42:41 -070069
Romain Guy2275d632009-08-18 11:39:17 -070070 const float y = B * x * fabsf(x) + C * x;
71 return 0.2215f * (y * fabsf(y) - y) + y;
72}
73
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080074static float SC_randf(float max) {
Jason Samse45ac6e2009-07-20 14:31:06 -070075 float r = (float)rand();
Jason Sams366c9c82010-12-08 16:14:36 -080076 r *= max;
77 return r / RAND_MAX;
Jason Samse45ac6e2009-07-20 14:31:06 -070078}
79
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080080static float SC_randf2(float min, float max) {
Romain Guy39dbc802009-07-31 11:20:59 -070081 float r = (float)rand();
Jason Sams366c9c82010-12-08 16:14:36 -080082 r = r * (max - min) + min;
83 return r / RAND_MAX;
Romain Guy39dbc802009-07-31 11:20:59 -070084}
85
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080086static int SC_randi(int max) {
Jason Sams22fa3712010-05-19 17:22:57 -070087 return (int)SC_randf(max);
88}
89
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080090static int SC_randi2(int min, int max) {
Jason Sams22fa3712010-05-19 17:22:57 -070091 return (int)SC_randf2(min, max);
92}
93
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080094static float SC_frac(float v) {
Jason Samsbe36bf32010-05-11 14:03:58 -070095 int i = (int)floor(v);
96 return fmin(v - i, 0x1.fffffep-1f);
97}
98
Romain Guy98e10fd2009-07-30 18:45:01 -070099//////////////////////////////////////////////////////////////////////////////
100// Time routines
101//////////////////////////////////////////////////////////////////////////////
Jason Samse45ac6e2009-07-20 14:31:06 -0700102
Stephen Hinesca3f09c2011-01-07 15:11:30 -0800103static time_t SC_time(time_t *timer) {
Romain Guy98e10fd2009-07-30 18:45:01 -0700104 GET_TLS();
Stephen Hinesca3f09c2011-01-07 15:11:30 -0800105 return time(timer);
Romain Guy98e10fd2009-07-30 18:45:01 -0700106}
107
Stephen Hinesca3f09c2011-01-07 15:11:30 -0800108static tm* SC_localtime(tm *local, time_t *timer) {
Romain Guy98e10fd2009-07-30 18:45:01 -0700109 GET_TLS();
Stephen Hinesca3f09c2011-01-07 15:11:30 -0800110 if (!local) {
111 return NULL;
112 }
Jason Samse5ffb872009-08-09 17:01:55 -0700113
Stephen Hinesca3f09c2011-01-07 15:11:30 -0800114 // The native localtime function is not thread-safe, so we
115 // have to apply locking for proper behavior in RenderScript.
116 pthread_mutex_lock(&rsc->gLibMutex);
117 tm *tmp = localtime(timer);
118 memcpy(local, tmp, sizeof(*tmp));
119 pthread_mutex_unlock(&rsc->gLibMutex);
120 return local;
Romain Guy39dbc802009-07-31 11:20:59 -0700121}
122
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800123static int64_t SC_uptimeMillis() {
Jason Sams22fa3712010-05-19 17:22:57 -0700124 return nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
125}
126
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800127static int64_t SC_uptimeNanos() {
Jason Sams73495472010-07-29 17:31:14 -0700128 return systemTime(SYSTEM_TIME_MONOTONIC);
Jason Sams22fa3712010-05-19 17:22:57 -0700129}
130
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800131static float SC_getDt() {
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700132 GET_TLS();
Jason Samsef5867a2010-07-28 11:17:53 -0700133 int64_t l = sc->mEnviroment.mLastDtTime;
134 sc->mEnviroment.mLastDtTime = systemTime(SYSTEM_TIME_MONOTONIC);
135 return ((float)(sc->mEnviroment.mLastDtTime - l)) / 1.0e9;
Jason Samse45ac6e2009-07-20 14:31:06 -0700136}
137
Jason Samse45ac6e2009-07-20 14:31:06 -0700138//////////////////////////////////////////////////////////////////////////////
139//
140//////////////////////////////////////////////////////////////////////////////
141
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800142static uint32_t SC_allocGetDimX(RsAllocation va) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700143 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700144 CHECK_OBJ(a);
145 //LOGE("SC_allocGetDimX a=%p type=%p", a, a->getType());
Jason Samsbe36bf32010-05-11 14:03:58 -0700146 return a->getType()->getDimX();
147}
148
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800149static uint32_t SC_allocGetDimY(RsAllocation va) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700150 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700151 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700152 return a->getType()->getDimY();
153}
154
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800155static uint32_t SC_allocGetDimZ(RsAllocation va) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700156 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700157 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700158 return a->getType()->getDimZ();
159}
160
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800161static uint32_t SC_allocGetDimLOD(RsAllocation va) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700162 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700163 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700164 return a->getType()->getDimLOD();
165}
166
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800167static uint32_t SC_allocGetDimFaces(RsAllocation va) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700168 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700169 CHECK_OBJ(a);
Jason Samsbe36bf32010-05-11 14:03:58 -0700170 return a->getType()->getDimFaces();
171}
172
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800173static const void * SC_getElementAtX(RsAllocation va, uint32_t x) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700174 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700175 CHECK_OBJ(a);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700176 const Type *t = a->getType();
Jason Sams605048a2010-09-30 18:15:52 -0700177 CHECK_OBJ(t);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700178 const uint8_t *p = (const uint8_t *)a->getPtr();
179 return &p[t->getElementSizeBytes() * x];
180}
181
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800182static const void * SC_getElementAtXY(RsAllocation va, uint32_t x, uint32_t y) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700183 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700184 CHECK_OBJ(a);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700185 const Type *t = a->getType();
Jason Sams605048a2010-09-30 18:15:52 -0700186 CHECK_OBJ(t);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700187 const uint8_t *p = (const uint8_t *)a->getPtr();
188 return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
189}
190
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800191static const void * SC_getElementAtXYZ(RsAllocation va, uint32_t x, uint32_t y, uint32_t z) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700192 const Allocation *a = static_cast<const Allocation *>(va);
Jason Sams605048a2010-09-30 18:15:52 -0700193 CHECK_OBJ(a);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700194 const Type *t = a->getType();
Jason Sams605048a2010-09-30 18:15:52 -0700195 CHECK_OBJ(t);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700196 const uint8_t *p = (const uint8_t *)a->getPtr();
197 return &p[t->getElementSizeBytes() * (x + y*t->getDimX())];
198}
Jason Samsbe36bf32010-05-11 14:03:58 -0700199
Jason Samsc0936852010-08-16 12:41:48 -0700200static void SC_setObject(void **vdst, void * vsrc) {
Jason Samsf24d7d02010-09-17 13:17:17 -0700201 //LOGE("SC_setObject %p,%p %p", vdst, *vdst, vsrc);
202 if (vsrc) {
Jason Sams605048a2010-09-30 18:15:52 -0700203 CHECK_OBJ(vsrc);
Jason Samsf24d7d02010-09-17 13:17:17 -0700204 static_cast<ObjectBase *>(vsrc)->incSysRef();
205 }
206 if (vdst[0]) {
Jason Sams605048a2010-09-30 18:15:52 -0700207 CHECK_OBJ(vdst[0]);
Jason Samsf24d7d02010-09-17 13:17:17 -0700208 static_cast<ObjectBase *>(vdst[0])->decSysRef();
209 }
Jason Samsc0936852010-08-16 12:41:48 -0700210 *vdst = vsrc;
Jason Samsf24d7d02010-09-17 13:17:17 -0700211 //LOGE("SC_setObject *");
Jason Samsc0936852010-08-16 12:41:48 -0700212}
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800213
Jason Samsc0936852010-08-16 12:41:48 -0700214static void SC_clearObject(void **vdst) {
Jason Samsf24d7d02010-09-17 13:17:17 -0700215 //LOGE("SC_clearObject %p,%p", vdst, *vdst);
216 if (vdst[0]) {
Jason Sams605048a2010-09-30 18:15:52 -0700217 CHECK_OBJ(vdst[0]);
Jason Samsf24d7d02010-09-17 13:17:17 -0700218 static_cast<ObjectBase *>(vdst[0])->decSysRef();
219 }
Jason Samsc0936852010-08-16 12:41:48 -0700220 *vdst = NULL;
Jason Samsf24d7d02010-09-17 13:17:17 -0700221 //LOGE("SC_clearObject *");
Jason Samsc0936852010-08-16 12:41:48 -0700222}
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800223
Jason Samsc0936852010-08-16 12:41:48 -0700224static bool SC_isObject(RsAllocation vsrc) {
225 return vsrc != NULL;
226}
227
Jason Sams22fa3712010-05-19 17:22:57 -0700228static void SC_debugF(const char *s, float f) {
Jason Samsfca82b12011-01-18 18:22:19 -0800229 LOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
Jason Samsc9d43db2009-07-28 12:02:16 -0700230}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700231static void SC_debugFv2(const char *s, float f1, float f2) {
Jason Samsfca82b12011-01-18 18:22:19 -0800232 LOGD("%s {%f, %f}", s, f1, f2);
Romain Guy370ed152009-08-20 17:08:33 -0700233}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700234static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
Jason Samsfca82b12011-01-18 18:22:19 -0800235 LOGD("%s {%f, %f, %f}", s, f1, f2, f3);
Jason Samsc9d43db2009-07-28 12:02:16 -0700236}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700237static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
Jason Samsfca82b12011-01-18 18:22:19 -0800238 LOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
Jason Sams22fa3712010-05-19 17:22:57 -0700239}
Stephen Hinesdf097192010-10-15 12:47:49 -0700240static void SC_debugD(const char *s, double d) {
Jason Samsfca82b12011-01-18 18:22:19 -0800241 LOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
Stephen Hinesdf097192010-10-15 12:47:49 -0700242}
Jason Sams7dce6bc2010-08-06 16:22:50 -0700243static void SC_debugFM4v4(const char *s, const float *f) {
Jason Samsfca82b12011-01-18 18:22:19 -0800244 LOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
245 LOGD("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
246 LOGD("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
247 LOGD("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
Jason Sams7dce6bc2010-08-06 16:22:50 -0700248}
249static void SC_debugFM3v3(const char *s, const float *f) {
Jason Samsfca82b12011-01-18 18:22:19 -0800250 LOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
251 LOGD("%s %f, %f, %f", s, f[1], f[4], f[7]);
252 LOGD("%s %f, %f, %f}",s, f[2], f[5], f[8]);
Jason Sams7dce6bc2010-08-06 16:22:50 -0700253}
254static void SC_debugFM2v2(const char *s, const float *f) {
Jason Samsfca82b12011-01-18 18:22:19 -0800255 LOGD("%s {%f, %f", s, f[0], f[2]);
256 LOGD("%s %f, %f}",s, f[1], f[3]);
Jason Sams7dce6bc2010-08-06 16:22:50 -0700257}
258
Jason Sams22fa3712010-05-19 17:22:57 -0700259static void SC_debugI32(const char *s, int32_t i) {
Jason Samsfca82b12011-01-18 18:22:19 -0800260 LOGD("%s %i 0x%x", s, i, i);
Romain Guy370ed152009-08-20 17:08:33 -0700261}
Jason Samsef5867a2010-07-28 11:17:53 -0700262static void SC_debugU32(const char *s, uint32_t i) {
Jason Samsfca82b12011-01-18 18:22:19 -0800263 LOGD("%s %u 0x%x", s, i, i);
Stephen Hinesdf097192010-10-15 12:47:49 -0700264}
265static void SC_debugLL64(const char *s, long long ll) {
Jason Samsfca82b12011-01-18 18:22:19 -0800266 LOGD("%s %lld 0x%llx", s, ll, ll);
Stephen Hinesdf097192010-10-15 12:47:49 -0700267}
268static void SC_debugULL64(const char *s, unsigned long long ll) {
Jason Samsfca82b12011-01-18 18:22:19 -0800269 LOGD("%s %llu 0x%llx", s, ll, ll);
Jason Samsef5867a2010-07-28 11:17:53 -0700270}
Romain Guy370ed152009-08-20 17:08:33 -0700271
Jason Sams7bf29dd2010-07-19 15:38:19 -0700272static void SC_debugP(const char *s, const void *p) {
Jason Samsfca82b12011-01-18 18:22:19 -0800273 LOGD("%s %p", s, p);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700274}
275
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800276static uint32_t SC_toClient2(int cmdID, void *data, int len) {
Jason Sams8c401ef2009-10-06 13:58:47 -0700277 GET_TLS();
Jason Samsef5867a2010-07-28 11:17:53 -0700278 //LOGE("SC_toClient %i %i %i", cmdID, len);
Jason Samsaad4bc52010-11-08 17:06:46 -0800279 return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, false);
Jason Sams8c401ef2009-10-06 13:58:47 -0700280}
281
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800282static uint32_t SC_toClient(int cmdID) {
Jason Sams3a27c952009-10-07 18:14:01 -0700283 GET_TLS();
Jason Samsef5867a2010-07-28 11:17:53 -0700284 //LOGE("SC_toClient %i", cmdID);
Jason Samsaad4bc52010-11-08 17:06:46 -0800285 return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, false);
Jason Samsef5867a2010-07-28 11:17:53 -0700286}
287
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800288static uint32_t SC_toClientBlocking2(int cmdID, void *data, int len) {
Jason Samsef5867a2010-07-28 11:17:53 -0700289 GET_TLS();
290 //LOGE("SC_toClientBlocking %i %i", cmdID, len);
Jason Samsaad4bc52010-11-08 17:06:46 -0800291 return rsc->sendMessageToClient(data, RS_MESSAGE_TO_CLIENT_USER, cmdID, len, true);
Jason Samsef5867a2010-07-28 11:17:53 -0700292}
293
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800294static uint32_t SC_toClientBlocking(int cmdID) {
Jason Samsef5867a2010-07-28 11:17:53 -0700295 GET_TLS();
296 //LOGE("SC_toClientBlocking %i", cmdID);
Jason Samsaad4bc52010-11-08 17:06:46 -0800297 return rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_USER, cmdID, 0, true);
Jason Sams3a27c952009-10-07 18:14:01 -0700298}
299
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800300int SC_divsi3(int a, int b) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700301 return a / b;
302}
Jason Sams3a27c952009-10-07 18:14:01 -0700303
Bryan Mawhinneycb082a32010-11-11 14:33:12 +0000304int SC_modsi3(int a, int b) {
305 return a % b;
306}
307
Stephen Hines711e7312011-01-24 12:03:51 -0800308unsigned int SC_udivsi3(unsigned int a, unsigned int b) {
309 return a / b;
310}
311
312unsigned int SC_umodsi3(unsigned int a, unsigned int b) {
313 return a % b;
314}
315
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800316int SC_getAllocation(const void *ptr) {
Jason Samsce92d4b2010-05-17 14:55:34 -0700317 GET_TLS();
318 const Allocation *alloc = sc->ptrToAllocation(ptr);
319 return (int)alloc;
320}
321
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800322void SC_allocationMarkDirty(RsAllocation a) {
Alex Sakhartchouk1e5168d2010-09-01 16:34:48 -0700323 Allocation *alloc = static_cast<Allocation *>(a);
324 alloc->sendDirty();
325}
Jason Samsce92d4b2010-05-17 14:55:34 -0700326
Jason Samsace3e012010-07-15 17:11:13 -0700327void SC_ForEach(RsScript vs,
328 RsAllocation vin,
329 RsAllocation vout,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800330 const void *usr) {
Jason Samsc61346b2010-05-28 18:23:22 -0700331 GET_TLS();
Jason Samsace3e012010-07-15 17:11:13 -0700332 const Allocation *ain = static_cast<const Allocation *>(vin);
Jason Samsc61346b2010-05-28 18:23:22 -0700333 Allocation *aout = static_cast<Allocation *>(vout);
Jason Samsace3e012010-07-15 17:11:13 -0700334 Script *s = static_cast<Script *>(vs);
335 s->runForEach(rsc, ain, aout, usr);
Jason Samsc61346b2010-05-28 18:23:22 -0700336}
337
Jason Samsace3e012010-07-15 17:11:13 -0700338void SC_ForEach2(RsScript vs,
339 RsAllocation vin,
340 RsAllocation vout,
341 const void *usr,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800342 const RsScriptCall *call) {
Jason Samsc61346b2010-05-28 18:23:22 -0700343 GET_TLS();
Jason Samsace3e012010-07-15 17:11:13 -0700344 const Allocation *ain = static_cast<const Allocation *>(vin);
Jason Samsc61346b2010-05-28 18:23:22 -0700345 Allocation *aout = static_cast<Allocation *>(vout);
Jason Samsc61346b2010-05-28 18:23:22 -0700346 Script *s = static_cast<Script *>(vs);
Jason Samsace3e012010-07-15 17:11:13 -0700347 s->runForEach(rsc, ain, aout, usr, call);
Jason Samsc61346b2010-05-28 18:23:22 -0700348}
349
Jason Sams693080e2011-01-25 21:33:44 -0800350
351//////////////////////////////////////////////////////////////////////////////
352// Heavy math functions
353//////////////////////////////////////////////////////////////////////////////
354
355typedef struct {
356 float m[16];
357} rs_matrix4x4;
358
359typedef struct {
360 float m[9];
361} rs_matrix3x3;
362
363typedef struct {
364 float m[4];
365} rs_matrix2x2;
366
367static inline void
368rsMatrixSet(rs_matrix4x4 *m, uint32_t row, uint32_t col, float v) {
369 m->m[row * 4 + col] = v;
370}
371
372static inline float
373rsMatrixGet(const rs_matrix4x4 *m, uint32_t row, uint32_t col) {
374 return m->m[row * 4 + col];
375}
376
377static inline void
378rsMatrixSet(rs_matrix3x3 *m, uint32_t row, uint32_t col, float v) {
379 m->m[row * 3 + col] = v;
380}
381
382static inline float
383rsMatrixGet(const rs_matrix3x3 *m, uint32_t row, uint32_t col) {
384 return m->m[row * 3 + col];
385}
386
387static inline void
388rsMatrixSet(rs_matrix2x2 *m, uint32_t row, uint32_t col, float v) {
389 m->m[row * 2 + col] = v;
390}
391
392static inline float
393rsMatrixGet(const rs_matrix2x2 *m, uint32_t row, uint32_t col) {
394 return m->m[row * 2 + col];
395}
396
397
398static void SC_MatrixLoadIdentity_4x4(rs_matrix4x4 *m) {
399 m->m[0] = 1.f;
400 m->m[1] = 0.f;
401 m->m[2] = 0.f;
402 m->m[3] = 0.f;
403 m->m[4] = 0.f;
404 m->m[5] = 1.f;
405 m->m[6] = 0.f;
406 m->m[7] = 0.f;
407 m->m[8] = 0.f;
408 m->m[9] = 0.f;
409 m->m[10] = 1.f;
410 m->m[11] = 0.f;
411 m->m[12] = 0.f;
412 m->m[13] = 0.f;
413 m->m[14] = 0.f;
414 m->m[15] = 1.f;
415}
416
417static void SC_MatrixLoadIdentity_3x3(rs_matrix3x3 *m) {
418 m->m[0] = 1.f;
419 m->m[1] = 0.f;
420 m->m[2] = 0.f;
421 m->m[3] = 0.f;
422 m->m[4] = 1.f;
423 m->m[5] = 0.f;
424 m->m[6] = 0.f;
425 m->m[7] = 0.f;
426 m->m[8] = 1.f;
427}
428
429static void SC_MatrixLoadIdentity_2x2(rs_matrix2x2 *m) {
430 m->m[0] = 1.f;
431 m->m[1] = 0.f;
432 m->m[2] = 0.f;
433 m->m[3] = 1.f;
434}
435
436static void SC_MatrixLoad_4x4_f(rs_matrix4x4 *m, const float *v) {
437 m->m[0] = v[0];
438 m->m[1] = v[1];
439 m->m[2] = v[2];
440 m->m[3] = v[3];
441 m->m[4] = v[4];
442 m->m[5] = v[5];
443 m->m[6] = v[6];
444 m->m[7] = v[7];
445 m->m[8] = v[8];
446 m->m[9] = v[9];
447 m->m[10] = v[10];
448 m->m[11] = v[11];
449 m->m[12] = v[12];
450 m->m[13] = v[13];
451 m->m[14] = v[14];
452 m->m[15] = v[15];
453}
454
455static void SC_MatrixLoad_3x3_f(rs_matrix3x3 *m, const float *v) {
456 m->m[0] = v[0];
457 m->m[1] = v[1];
458 m->m[2] = v[2];
459 m->m[3] = v[3];
460 m->m[4] = v[4];
461 m->m[5] = v[5];
462 m->m[6] = v[6];
463 m->m[7] = v[7];
464 m->m[8] = v[8];
465}
466
467static void SC_MatrixLoad_2x2_f(rs_matrix2x2 *m, const float *v) {
468 m->m[0] = v[0];
469 m->m[1] = v[1];
470 m->m[2] = v[2];
471 m->m[3] = v[3];
472}
473
474static void SC_MatrixLoad_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *v) {
475 m->m[0] = v->m[0];
476 m->m[1] = v->m[1];
477 m->m[2] = v->m[2];
478 m->m[3] = v->m[3];
479 m->m[4] = v->m[4];
480 m->m[5] = v->m[5];
481 m->m[6] = v->m[6];
482 m->m[7] = v->m[7];
483 m->m[8] = v->m[8];
484 m->m[9] = v->m[9];
485 m->m[10] = v->m[10];
486 m->m[11] = v->m[11];
487 m->m[12] = v->m[12];
488 m->m[13] = v->m[13];
489 m->m[14] = v->m[14];
490 m->m[15] = v->m[15];
491}
492
493static void SC_MatrixLoad_4x4_3x3(rs_matrix4x4 *m, const rs_matrix3x3 *v) {
494 m->m[0] = v->m[0];
495 m->m[1] = v->m[1];
496 m->m[2] = v->m[2];
497 m->m[3] = 0.f;
498 m->m[4] = v->m[3];
499 m->m[5] = v->m[4];
500 m->m[6] = v->m[5];
501 m->m[7] = 0.f;
502 m->m[8] = v->m[6];
503 m->m[9] = v->m[7];
504 m->m[10] = v->m[8];
505 m->m[11] = 0.f;
506 m->m[12] = 0.f;
507 m->m[13] = 0.f;
508 m->m[14] = 0.f;
509 m->m[15] = 1.f;
510}
511
512static void SC_MatrixLoad_4x4_2x2(rs_matrix4x4 *m, const rs_matrix2x2 *v) {
513 m->m[0] = v->m[0];
514 m->m[1] = v->m[1];
515 m->m[2] = 0.f;
516 m->m[3] = 0.f;
517 m->m[4] = v->m[2];
518 m->m[5] = v->m[3];
519 m->m[6] = 0.f;
520 m->m[7] = 0.f;
521 m->m[8] = 0.f;
522 m->m[9] = 0.f;
523 m->m[10] = 1.f;
524 m->m[11] = 0.f;
525 m->m[12] = 0.f;
526 m->m[13] = 0.f;
527 m->m[14] = 0.f;
528 m->m[15] = 1.f;
529}
530
531static void SC_MatrixLoad_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *v) {
532 m->m[0] = v->m[0];
533 m->m[1] = v->m[1];
534 m->m[2] = v->m[2];
535 m->m[3] = v->m[3];
536 m->m[4] = v->m[4];
537 m->m[5] = v->m[5];
538 m->m[6] = v->m[6];
539 m->m[7] = v->m[7];
540 m->m[8] = v->m[8];
541}
542
543static void SC_MatrixLoad_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *v) {
544 m->m[0] = v->m[0];
545 m->m[1] = v->m[1];
546 m->m[2] = v->m[2];
547 m->m[3] = v->m[3];
548}
549
550static void SC_MatrixLoadRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
551 float c, s;
552 m->m[3] = 0;
553 m->m[7] = 0;
554 m->m[11]= 0;
555 m->m[12]= 0;
556 m->m[13]= 0;
557 m->m[14]= 0;
558 m->m[15]= 1;
559 rot *= (float)(M_PI / 180.0f);
560 c = cos(rot);
561 s = sin(rot);
562
563 const float len = x*x + y*y + z*z;
564 if (len != 1) {
565 const float recipLen = 1.f / sqrt(len);
566 x *= recipLen;
567 y *= recipLen;
568 z *= recipLen;
569 }
570 const float nc = 1.0f - c;
571 const float xy = x * y;
572 const float yz = y * z;
573 const float zx = z * x;
574 const float xs = x * s;
575 const float ys = y * s;
576 const float zs = z * s;
577 m->m[ 0] = x*x*nc + c;
578 m->m[ 4] = xy*nc - zs;
579 m->m[ 8] = zx*nc + ys;
580 m->m[ 1] = xy*nc + zs;
581 m->m[ 5] = y*y*nc + c;
582 m->m[ 9] = yz*nc - xs;
583 m->m[ 2] = zx*nc - ys;
584 m->m[ 6] = yz*nc + xs;
585 m->m[10] = z*z*nc + c;
586}
587
588static void SC_MatrixLoadScale(rs_matrix4x4 *m, float x, float y, float z) {
589 SC_MatrixLoadIdentity_4x4(m);
590 m->m[0] = x;
591 m->m[5] = y;
592 m->m[10] = z;
593}
594
595static void SC_MatrixLoadTranslate(rs_matrix4x4 *m, float x, float y, float z) {
596 SC_MatrixLoadIdentity_4x4(m);
597 m->m[12] = x;
598 m->m[13] = y;
599 m->m[14] = z;
600}
601
602static void SC_MatrixLoadMultiply_4x4_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *lhs, const rs_matrix4x4 *rhs) {
603 for (int i=0 ; i<4 ; i++) {
604 float ri0 = 0;
605 float ri1 = 0;
606 float ri2 = 0;
607 float ri3 = 0;
608 for (int j=0 ; j<4 ; j++) {
609 const float rhs_ij = rsMatrixGet(rhs, i,j);
610 ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
611 ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
612 ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
613 ri3 += rsMatrixGet(lhs, j, 3) * rhs_ij;
614 }
615 rsMatrixSet(m, i, 0, ri0);
616 rsMatrixSet(m, i, 1, ri1);
617 rsMatrixSet(m, i, 2, ri2);
618 rsMatrixSet(m, i, 3, ri3);
619 }
620}
621
622static void SC_MatrixMultiply_4x4_4x4(rs_matrix4x4 *m, const rs_matrix4x4 *rhs) {
623 rs_matrix4x4 mt;
624 SC_MatrixLoadMultiply_4x4_4x4_4x4(&mt, m, rhs);
625 SC_MatrixLoad_4x4_4x4(m, &mt);
626}
627
628static void SC_MatrixLoadMultiply_3x3_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *lhs, const rs_matrix3x3 *rhs) {
629 for (int i=0 ; i<3 ; i++) {
630 float ri0 = 0;
631 float ri1 = 0;
632 float ri2 = 0;
633 for (int j=0 ; j<3 ; j++) {
634 const float rhs_ij = rsMatrixGet(rhs, i,j);
635 ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
636 ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
637 ri2 += rsMatrixGet(lhs, j, 2) * rhs_ij;
638 }
639 rsMatrixSet(m, i, 0, ri0);
640 rsMatrixSet(m, i, 1, ri1);
641 rsMatrixSet(m, i, 2, ri2);
642 }
643}
644
645static void SC_MatrixMultiply_3x3_3x3(rs_matrix3x3 *m, const rs_matrix3x3 *rhs) {
646 rs_matrix3x3 mt;
647 SC_MatrixLoadMultiply_3x3_3x3_3x3(&mt, m, rhs);
648 SC_MatrixLoad_3x3_3x3(m, &mt);
649}
650
651static void SC_MatrixLoadMultiply_2x2_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *lhs, const rs_matrix2x2 *rhs) {
652 for (int i=0 ; i<2 ; i++) {
653 float ri0 = 0;
654 float ri1 = 0;
655 for (int j=0 ; j<2 ; j++) {
656 const float rhs_ij = rsMatrixGet(rhs, i,j);
657 ri0 += rsMatrixGet(lhs, j, 0) * rhs_ij;
658 ri1 += rsMatrixGet(lhs, j, 1) * rhs_ij;
659 }
660 rsMatrixSet(m, i, 0, ri0);
661 rsMatrixSet(m, i, 1, ri1);
662 }
663}
664
665static void SC_MatrixMultiply_2x2_2x2(rs_matrix2x2 *m, const rs_matrix2x2 *rhs) {
666 rs_matrix2x2 mt;
667 SC_MatrixLoadMultiply_2x2_2x2_2x2(&mt, m, rhs);
668 SC_MatrixLoad_2x2_2x2(m, &mt);
669}
670
671static void SC_MatrixRotate(rs_matrix4x4 *m, float rot, float x, float y, float z) {
672 rs_matrix4x4 m1;
673 SC_MatrixLoadRotate(&m1, rot, x, y, z);
674 SC_MatrixMultiply_4x4_4x4(m, &m1);
675}
676
677static void SC_MatrixScale(rs_matrix4x4 *m, float x, float y, float z) {
678 rs_matrix4x4 m1;
679 SC_MatrixLoadScale(&m1, x, y, z);
680 SC_MatrixMultiply_4x4_4x4(m, &m1);
681}
682
683static void SC_MatrixTranslate(rs_matrix4x4 *m, float x, float y, float z) {
684 rs_matrix4x4 m1;
685 SC_MatrixLoadTranslate(&m1, x, y, z);
686 SC_MatrixMultiply_4x4_4x4(m, &m1);
687}
688
689static void SC_MatrixLoadOrtho(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
690 SC_MatrixLoadIdentity_4x4(m);
691 m->m[0] = 2.f / (right - left);
692 m->m[5] = 2.f / (top - bottom);
693 m->m[10]= -2.f / (far - near);
694 m->m[12]= -(right + left) / (right - left);
695 m->m[13]= -(top + bottom) / (top - bottom);
696 m->m[14]= -(far + near) / (far - near);
697}
698
699static void SC_MatrixLoadFrustum(rs_matrix4x4 *m, float left, float right, float bottom, float top, float near, float far) {
700 SC_MatrixLoadIdentity_4x4(m);
701 m->m[0] = 2.f * near / (right - left);
702 m->m[5] = 2.f * near / (top - bottom);
703 m->m[8] = (right + left) / (right - left);
704 m->m[9] = (top + bottom) / (top - bottom);
705 m->m[10]= -(far + near) / (far - near);
706 m->m[11]= -1.f;
707 m->m[14]= -2.f * far * near / (far - near);
708 m->m[15]= 0.f;
709}
710
711static void SC_MatrixLoadPerspective(rs_matrix4x4* m, float fovy, float aspect, float near, float far) {
712 float top = near * tan((float) (fovy * M_PI / 360.0f));
713 float bottom = -top;
714 float left = bottom * aspect;
715 float right = top * aspect;
716 SC_MatrixLoadFrustum(m, left, right, bottom, top, near, far);
717}
718
719
720// Returns true if the matrix was successfully inversed
721static bool SC_MatrixInverse_4x4(rs_matrix4x4 *m) {
722 rs_matrix4x4 result;
723
724 int i, j;
725 for (i = 0; i < 4; ++i) {
726 for (j = 0; j < 4; ++j) {
727 // computeCofactor for int i, int j
728 int c0 = (i+1) % 4;
729 int c1 = (i+2) % 4;
730 int c2 = (i+3) % 4;
731 int r0 = (j+1) % 4;
732 int r1 = (j+2) % 4;
733 int r2 = (j+3) % 4;
734
735 float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
736 - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
737 + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
738
739 float cofactor = (i+j) & 1 ? -minor : minor;
740
741 result.m[4*i + j] = cofactor;
742 }
743 }
744
745 // Dot product of 0th column of source and 0th row of result
746 float det = m->m[0]*result.m[0] + m->m[4]*result.m[1] +
747 m->m[8]*result.m[2] + m->m[12]*result.m[3];
748
749 if (fabs(det) < 1e-6) {
750 return false;
751 }
752
753 det = 1.0f / det;
754 for (i = 0; i < 16; ++i) {
755 m->m[i] = result.m[i] * det;
756 }
757
758 return true;
759}
760
761// Returns true if the matrix was successfully inversed
762static bool SC_MatrixInverseTranspose_4x4(rs_matrix4x4 *m) {
763 rs_matrix4x4 result;
764
765 int i, j;
766 for (i = 0; i < 4; ++i) {
767 for (j = 0; j < 4; ++j) {
768 // computeCofactor for int i, int j
769 int c0 = (i+1) % 4;
770 int c1 = (i+2) % 4;
771 int c2 = (i+3) % 4;
772 int r0 = (j+1) % 4;
773 int r1 = (j+2) % 4;
774 int r2 = (j+3) % 4;
775
776 float minor = (m->m[c0 + 4*r0] * (m->m[c1 + 4*r1] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r1]))
777 - (m->m[c0 + 4*r1] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r2] - m->m[c1 + 4*r2] * m->m[c2 + 4*r0]))
778 + (m->m[c0 + 4*r2] * (m->m[c1 + 4*r0] * m->m[c2 + 4*r1] - m->m[c1 + 4*r1] * m->m[c2 + 4*r0]));
779
780 float cofactor = (i+j) & 1 ? -minor : minor;
781
782 result.m[4*j + i] = cofactor;
783 }
784 }
785
786 // Dot product of 0th column of source and 0th column of result
787 float det = m->m[0]*result.m[0] + m->m[4]*result.m[4] +
788 m->m[8]*result.m[8] + m->m[12]*result.m[12];
789
790 if (fabs(det) < 1e-6) {
791 return false;
792 }
793
794 det = 1.0f / det;
795 for (i = 0; i < 16; ++i) {
796 m->m[i] = result.m[i] * det;
797 }
798
799 return true;
800}
801
802static void SC_MatrixTranspose_4x4(rs_matrix4x4 *m) {
803 int i, j;
804 float temp;
805 for (i = 0; i < 3; ++i) {
806 for (j = i + 1; j < 4; ++j) {
807 temp = m->m[i*4 + j];
808 m->m[i*4 + j] = m->m[j*4 + i];
809 m->m[j*4 + i] = temp;
810 }
811 }
812}
813
814static void SC_MatrixTranspose_3x3(rs_matrix3x3 *m) {
815 int i, j;
816 float temp;
817 for (i = 0; i < 2; ++i) {
818 for (j = i + 1; j < 3; ++j) {
819 temp = m->m[i*3 + j];
820 m->m[i*3 + j] = m->m[j*4 + i];
821 m->m[j*3 + i] = temp;
822 }
823 }
824}
825
826static void SC_MatrixTranspose_2x2(rs_matrix2x2 *m) {
827 float temp = m->m[1];
828 m->m[1] = m->m[2];
829 m->m[2] = temp;
830}
831
832
Jason Samse45ac6e2009-07-20 14:31:06 -0700833//////////////////////////////////////////////////////////////////////////////
834// Class implementation
835//////////////////////////////////////////////////////////////////////////////
836
Jason Samsbe36bf32010-05-11 14:03:58 -0700837// llvm name mangling ref
838// <builtin-type> ::= v # void
839// ::= b # bool
840// ::= c # char
841// ::= a # signed char
842// ::= h # unsigned char
843// ::= s # short
844// ::= t # unsigned short
845// ::= i # int
846// ::= j # unsigned int
847// ::= l # long
848// ::= m # unsigned long
849// ::= x # long long, __int64
850// ::= y # unsigned long long, __int64
851// ::= f # float
852// ::= d # double
Jason Samse45ac6e2009-07-20 14:31:06 -0700853
Jason Samsaeb094b2010-05-18 13:35:45 -0700854static ScriptCState::SymbolTable_t gSyms[] = {
Jason Sams6bfc1b92010-11-01 14:26:30 -0700855 { "__divsi3", (void *)&SC_divsi3, true },
Bryan Mawhinneycb082a32010-11-11 14:33:12 +0000856 { "__modsi3", (void *)&SC_modsi3, true },
Stephen Hines711e7312011-01-24 12:03:51 -0800857 { "__udivsi3", (void *)&SC_udivsi3, true },
858 { "__umodsi3", (void *)&SC_umodsi3, true },
Jason Samsbe36bf32010-05-11 14:03:58 -0700859
Jason Sams22fa3712010-05-19 17:22:57 -0700860 // allocation
Jason Sams6bfc1b92010-11-01 14:26:30 -0700861 { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true },
862 { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true },
863 { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true },
864 { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true },
865 { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true },
866 { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700867
Jason Sams6bfc1b92010-11-01 14:26:30 -0700868 { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true },
869 { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true },
870 { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true },
Jason Sams7bf29dd2010-07-19 15:38:19 -0700871
Jason Sams6bfc1b92010-11-01 14:26:30 -0700872 { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_setObject, true },
873 { "_Z13rsClearObjectP10rs_element", (void *)&SC_clearObject, true },
874 { "_Z10rsIsObject10rs_element", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700875
Jason Sams6bfc1b92010-11-01 14:26:30 -0700876 { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_setObject, true },
877 { "_Z13rsClearObjectP7rs_type", (void *)&SC_clearObject, true },
878 { "_Z10rsIsObject7rs_type", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700879
Jason Sams6bfc1b92010-11-01 14:26:30 -0700880 { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_setObject, true },
881 { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_clearObject, true },
882 { "_Z10rsIsObject13rs_allocation", (void *)&SC_isObject, true },
Jason Samsc0936852010-08-16 12:41:48 -0700883
Jason Sams6bfc1b92010-11-01 14:26:30 -0700884 { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_setObject, true },
885 { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_clearObject, true },
886 { "_Z10rsIsObject10rs_sampler", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700887
Jason Sams6bfc1b92010-11-01 14:26:30 -0700888 { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_setObject, true },
889 { "_Z13rsClearObjectP9rs_script", (void *)&SC_clearObject, true },
890 { "_Z10rsIsObject9rs_script", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700891
Jason Sams6bfc1b92010-11-01 14:26:30 -0700892 { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_setObject, true },
893 { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_clearObject, true },
894 { "_Z10rsIsObject7rs_mesh", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700895
Jason Sams6bfc1b92010-11-01 14:26:30 -0700896 { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_setObject, true },
897 { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_clearObject, true },
898 { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700899
Jason Sams6bfc1b92010-11-01 14:26:30 -0700900 { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_setObject, true },
901 { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_clearObject, true },
902 { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700903
Jason Sams6bfc1b92010-11-01 14:26:30 -0700904 { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_setObject, true },
905 { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_clearObject, true },
906 { "_Z10rsIsObject17rs_program_raster", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700907
Jason Sams6bfc1b92010-11-01 14:26:30 -0700908 { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_setObject, true },
909 { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_clearObject, true },
910 { "_Z10rsIsObject16rs_program_store", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700911
Jason Sams6bfc1b92010-11-01 14:26:30 -0700912 { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_setObject, true },
913 { "_Z13rsClearObjectP7rs_font", (void *)&SC_clearObject, true },
914 { "_Z10rsIsObject7rs_font", (void *)&SC_isObject, true },
Jason Samsf24d7d02010-09-17 13:17:17 -0700915
916
Jason Sams6bfc1b92010-11-01 14:26:30 -0700917 { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_allocationMarkDirty, true },
Alex Sakhartchouk1e5168d2010-09-01 16:34:48 -0700918
Jason Samsc0936852010-08-16 12:41:48 -0700919
Jason Sams22fa3712010-05-19 17:22:57 -0700920 // Debug
Jason Sams6bfc1b92010-11-01 14:26:30 -0700921 { "_Z7rsDebugPKcf", (void *)&SC_debugF, true },
922 { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true },
923 { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true },
924 { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true },
925 { "_Z7rsDebugPKcd", (void *)&SC_debugD, true },
926 { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true },
927 { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true },
928 { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true },
929 { "_Z7rsDebugPKci", (void *)&SC_debugI32, true },
930 { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true },
Stephen Hinesdf097192010-10-15 12:47:49 -0700931 // Both "long" and "unsigned long" need to be redirected to their
932 // 64-bit counterparts, since we have hacked Slang to use 64-bit
933 // for "long" on Arm (to be similar to Java).
Jason Sams6bfc1b92010-11-01 14:26:30 -0700934 { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true },
935 { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true },
936 { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true },
937 { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true },
938 { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700939
940 // RS Math
Jason Sams6bfc1b92010-11-01 14:26:30 -0700941 { "_Z6rsRandi", (void *)&SC_randi, true },
942 { "_Z6rsRandii", (void *)&SC_randi2, true },
943 { "_Z6rsRandf", (void *)&SC_randf, true },
944 { "_Z6rsRandff", (void *)&SC_randf2, true },
945 { "_Z6rsFracf", (void *)&SC_frac, true },
Jason Sams22fa3712010-05-19 17:22:57 -0700946
947 // time
Stephen Hinesca3f09c2011-01-07 15:11:30 -0800948 { "_Z6rsTimePi", (void *)&SC_time, true },
949 { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_localtime, true },
Jason Sams6bfc1b92010-11-01 14:26:30 -0700950 { "_Z14rsUptimeMillisv", (void*)&SC_uptimeMillis, true },
951 { "_Z13rsUptimeNanosv", (void*)&SC_uptimeNanos, true },
952 { "_Z7rsGetDtv", (void*)&SC_getDt, false },
Jason Sams22fa3712010-05-19 17:22:57 -0700953
Jason Sams6bfc1b92010-11-01 14:26:30 -0700954 { "_Z14rsSendToClienti", (void *)&SC_toClient, false },
955 { "_Z14rsSendToClientiPKvj", (void *)&SC_toClient2, false },
956 { "_Z22rsSendToClientBlockingi", (void *)&SC_toClientBlocking, false },
957 { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_toClientBlocking2, false },
Jason Sams22fa3712010-05-19 17:22:57 -0700958
Jason Sams693080e2011-01-25 21:33:44 -0800959 // matrix
960 { "_Z20rsMatrixLoadIdentityP12rs_matrix4x4", (void *)&SC_MatrixLoadIdentity_4x4, false },
961 { "_Z20rsMatrixLoadIdentityP12rs_matrix3x3", (void *)&SC_MatrixLoadIdentity_3x3, false },
962 { "_Z20rsMatrixLoadIdentityP12rs_matrix2x2", (void *)&SC_MatrixLoadIdentity_2x2, false },
963
964 { "_Z12rsMatrixLoadP12rs_matrix4x4PKf", (void *)&SC_MatrixLoad_4x4_f, false },
965 { "_Z12rsMatrixLoadP12rs_matrix3x3PKf", (void *)&SC_MatrixLoad_3x3_f, false },
966 { "_Z12rsMatrixLoadP12rs_matrix2x2PKf", (void *)&SC_MatrixLoad_2x2_f, false },
967
968 { "_Z12rsMatrixLoadP12rs_matrix4x4PKS_", (void *)&SC_MatrixLoad_4x4_4x4, false },
969 { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix3x3", (void *)&SC_MatrixLoad_4x4_3x3, false },
970 { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix2x2", (void *)&SC_MatrixLoad_4x4_2x2, false },
971 { "_Z12rsMatrixLoadP12rs_matrix3x3PKS_", (void *)&SC_MatrixLoad_3x3_3x3, false },
972 { "_Z12rsMatrixLoadP12rs_matrix2x2PKS_", (void *)&SC_MatrixLoad_2x2_2x2, false },
973
974 { "_Z18rsMatrixLoadRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadRotate, false },
975 { "_Z17rsMatrixLoadScaleP12rs_matrix4x4fff", (void *)&SC_MatrixLoadScale, false },
976 { "_Z21rsMatrixLoadTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixLoadTranslate, false },
977 { "_Z14rsMatrixRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixRotate, false },
978 { "_Z13rsMatrixScaleP12rs_matrix4x4fff", (void *)&SC_MatrixScale, false },
979 { "_Z17rsMatrixTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixTranslate, false },
980
981 { "_Z20rsMatrixLoadMultiplyP12rs_matrix4x4PKS_S2_", (void *)&SC_MatrixLoadMultiply_4x4_4x4_4x4, false },
982 { "_Z16rsMatrixMultiplyP12rs_matrix4x4PKS_", (void *)&SC_MatrixMultiply_4x4_4x4, false },
983 { "_Z20rsMatrixLoadMultiplyP12rs_matrix3x3PKS_S2_", (void *)&SC_MatrixLoadMultiply_3x3_3x3_3x3, false },
984 { "_Z16rsMatrixMultiplyP12rs_matrix3x3PKS_", (void *)&SC_MatrixMultiply_3x3_3x3, false },
985 { "_Z20rsMatrixLoadMultiplyP12rs_matrix2x2PKS_S2_", (void *)&SC_MatrixLoadMultiply_2x2_2x2_2x2, false },
986 { "_Z16rsMatrixMultiplyP12rs_matrix2x2PKS_", (void *)&SC_MatrixMultiply_2x2_2x2, false },
987
988 { "_Z17rsMatrixLoadOrthoP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadOrtho, false },
989 { "_Z19rsMatrixLoadFrustumP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadFrustum, false },
990 { "_Z23rsMatrixLoadPerspectiveP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadPerspective, false },
991
992 { "_Z15rsMatrixInverseP12rs_matrix4x4", (void *)&SC_MatrixInverse_4x4, false },
993 { "_Z24rsMatrixInverseTransposeP12rs_matrix4x4", (void *)&SC_MatrixInverseTranspose_4x4, false },
994 { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_4x4, false },
995 { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_3x3, false },
996 { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, false },
997
Jason Sams6bfc1b92010-11-01 14:26:30 -0700998 { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false },
999 //{ "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach2, true },
Jason Sams22fa3712010-05-19 17:22:57 -07001000
1001////////////////////////////////////////////////////////////////////
1002
Jason Sams6bfc1b92010-11-01 14:26:30 -07001003 //{ "sinf_fast", (void *)&SC_sinf_fast, true },
1004 //{ "cosf_fast", (void *)&SC_cosf_fast, true },
Jason Samse45ac6e2009-07-20 14:31:06 -07001005
Jason Sams6bfc1b92010-11-01 14:26:30 -07001006 { NULL, NULL, false }
Jason Samse45ac6e2009-07-20 14:31:06 -07001007};
1008
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -08001009const ScriptCState::SymbolTable_t * ScriptCState::lookupSymbol(const char *sym) {
Jason Samse45ac6e2009-07-20 14:31:06 -07001010 ScriptCState::SymbolTable_t *syms = gSyms;
1011
1012 while (syms->mPtr) {
1013 if (!strcmp(syms->mName, sym)) {
1014 return syms;
1015 }
1016 syms++;
1017 }
1018 return NULL;
1019}