diff options
| author | Jason Sams <rjsams@android.com> | 2011-04-20 15:09:01 -0700 |
|---|---|---|
| committer | Jason Sams <rjsams@android.com> | 2011-04-20 15:09:01 -0700 |
| commit | 87fe59a2f4d4c74539bfa0bff5f9a7e320e99415 (patch) | |
| tree | 34d774d54f75657d949e034858149dba4e3368ff /driver | |
| parent | eed1b156ca3e439f3d178ce99a4fa736527b15f9 (diff) | |
| download | android_frameworks_rs-87fe59a2f4d4c74539bfa0bff5f9a7e320e99415.tar.gz android_frameworks_rs-87fe59a2f4d4c74539bfa0bff5f9a7e320e99415.tar.bz2 android_frameworks_rs-87fe59a2f4d4c74539bfa0bff5f9a7e320e99415.zip | |
Create runtime stubs for compute driver.
Change-Id: I8e0250a642844a2ad3ff6efc38e385445b7da032
Diffstat (limited to 'driver')
| -rw-r--r-- | driver/rsdBcc.cpp | 12 | ||||
| -rw-r--r-- | driver/rsdBcc.h | 4 | ||||
| -rw-r--r-- | driver/rsdCore.cpp | 10 | ||||
| -rw-r--r-- | driver/rsdCore.h | 10 | ||||
| -rw-r--r-- | driver/rsdGL.cpp | 10 | ||||
| -rw-r--r-- | driver/rsdRuntime.h | 29 | ||||
| -rw-r--r-- | driver/rsdRuntimeMath.cpp | 440 | ||||
| -rw-r--r-- | driver/rsdRuntimeStubs.cpp | 693 |
8 files changed, 1188 insertions, 20 deletions
diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp index 20aef493..2c6840b9 100644 --- a/driver/rsdBcc.cpp +++ b/driver/rsdBcc.cpp @@ -17,6 +17,7 @@ #include "rsdCore.h" #include "rsdBcc.h" +#include "rsdRuntime.h" #include "rsContext.h" #include "rsScriptC.h" @@ -129,8 +130,7 @@ bool rsdScriptInit(const Context *rsc, char const *cacheDir, uint8_t const *bitcode, size_t bitcodeSize, - uint32_t flags, - RsHalSymbolLookupFunc lookupFunc) { + uint32_t flags) { //LOGE("rsdScriptCreate %p %p %p %p %i %i %p", rsc, resName, cacheDir, bitcode, bitcodeSize, flags, lookupFunc); char *cachePath = NULL; @@ -149,7 +149,7 @@ bool rsdScriptInit(const Context *rsc, //LOGE("mBccScript %p", script->mBccScript); - if (bccRegisterSymbolCallback(drv->mBccScript, lookupFunc, script) != 0) { + if (bccRegisterSymbolCallback(drv->mBccScript, &rsdLookupRuntimeStub, script) != 0) { LOGE("bcc: FAILS to register symbol callback"); goto error; } @@ -334,7 +334,7 @@ void rsdScriptInvokeForEach(const Context *rsc, uint32_t usrLen, const RsScriptCall *sc) { - RsHal * dc = (RsHal *)rsc->mHal.drv; + RsdHal * dc = (RsdHal *)rsc->mHal.drv; MTLaunchStruct mtls; memset(&mtls, 0, sizeof(mtls)); @@ -513,7 +513,7 @@ void rsdScriptSetGlobalObj(const Context *dc, const Script *script, uint32_t slo return; } - rsiSetObject((ObjectBase **)destPtr, data); + rsrSetObject(dc, script, (ObjectBase **)destPtr, data); } void rsdScriptDestroy(const Context *dc, Script *script) { @@ -525,7 +525,7 @@ void rsdScriptDestroy(const Context *dc, Script *script) { // The field address can be NULL if the script-side has // optimized the corresponding global variable away. if (drv->mFieldAddress[ct]) { - rsiClearObject((ObjectBase **)drv->mFieldAddress[ct]); + rsrClearObject(dc, script, (ObjectBase **)drv->mFieldAddress[ct]); } } } diff --git a/driver/rsdBcc.h b/driver/rsdBcc.h index ae7a7af3..62b50f47 100644 --- a/driver/rsdBcc.h +++ b/driver/rsdBcc.h @@ -18,12 +18,12 @@ #define RSD_BCC_H #include <rs_hal.h> +#include <rsRuntime.h> bool rsdScriptInit(const android::renderscript::Context *, android::renderscript::ScriptC *, char const *resName, char const *cacheDir, - uint8_t const *bitcode, size_t bitcodeSize, - uint32_t flags, android::renderscript::RsHalSymbolLookupFunc lookupFunc); + uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags); void rsdScriptInvokeFunction(const android::renderscript::Context *dc, android::renderscript::Script *script, uint32_t slot, diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp index 75f4d6b0..c01e5ab5 100644 --- a/driver/rsdCore.cpp +++ b/driver/rsdCore.cpp @@ -77,7 +77,7 @@ static RsdHalFunctions FunctionTable = { static void * HelperThreadProc(void *vrsc) { Context *rsc = static_cast<Context *>(vrsc); - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; uint32_t idx = (uint32_t)android_atomic_inc(&dc->mWorkers.mLaunchCount); @@ -116,7 +116,7 @@ static void * HelperThreadProc(void *vrsc) { } void rsdLaunchThreads(Context *rsc, WorkerCallback_t cbk, void *data) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; dc->mWorkers.mLaunchData = data; dc->mWorkers.mLaunchCallback = cbk; @@ -132,7 +132,7 @@ void rsdLaunchThreads(Context *rsc, WorkerCallback_t cbk, void *data) { bool rsdHalInit(Context *rsc, uint32_t version_major, uint32_t version_minor) { rsc->mHal.funcs = FunctionTable; - RsHal *dc = (RsHal *)calloc(1, sizeof(RsHal)); + RsdHal *dc = (RsdHal *)calloc(1, sizeof(RsdHal)); if (!dc) { LOGE("Calloc for driver hal failed."); return false; @@ -181,14 +181,14 @@ bool rsdHalInit(Context *rsc, uint32_t version_major, uint32_t version_minor) { void SetPriority(const Context *rsc, int32_t priority) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; for (uint32_t ct=0; ct < dc->mWorkers.mCount; ct++) { setpriority(PRIO_PROCESS, dc->mWorkers.mNativeThreadId[ct], priority); } } void Shutdown(Context *rsc) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; dc->mExit = true; dc->mWorkers.mLaunchData = NULL; diff --git a/driver/rsdCore.h b/driver/rsdCore.h index e37698b7..c8df5753 100644 --- a/driver/rsdCore.h +++ b/driver/rsdCore.h @@ -28,7 +28,13 @@ typedef void (* InvokeFunc_t)(void); typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); -typedef struct RsHalRec { +typedef struct RsdSymbolTableRec { + const char * mName; + void * mPtr; + bool threadable; +} RsdSymbolTable; + +typedef struct RsdHalRec { uint32_t version_major; uint32_t version_minor; @@ -48,7 +54,7 @@ typedef struct RsHalRec { bool mExit; RsdGL gl; -} RsHal; +} RsdHal; diff --git a/driver/rsdGL.cpp b/driver/rsdGL.cpp index 86dfa0fa..6238edd6 100644 --- a/driver/rsdGL.cpp +++ b/driver/rsdGL.cpp @@ -107,7 +107,7 @@ static void printEGLConfiguration(EGLDisplay dpy, EGLConfig config) { } } -static void DumpDebug(RsHal *dc) { +static void DumpDebug(RsdHal *dc) { LOGE(" EGL ver %i %i", dc->gl.egl.majorVersion, dc->gl.egl.minorVersion); LOGE(" EGL context %p surface %p, Display=%p", dc->gl.egl.context, dc->gl.egl.surface, dc->gl.egl.display); @@ -126,7 +126,7 @@ static void DumpDebug(RsHal *dc) { } void rsdGLShutdown(const Context *rsc) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; LOGV("%p, deinitEGL", rsc); @@ -147,7 +147,7 @@ void rsdGLShutdown(const Context *rsc) { } bool rsdGLInit(const Context *rsc) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; dc->gl.egl.numConfigs = -1; EGLint configAttribs[128]; @@ -289,7 +289,7 @@ bool rsdGLInit(const Context *rsc) { bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, ANativeWindow *sur) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; EGLBoolean ret; // WAR: Some drivers fail to handle 0 size surfaces correcntly. @@ -327,7 +327,7 @@ bool rsdGLSetSurface(const Context *rsc, uint32_t w, uint32_t h, ANativeWindow * } void rsdGLSwap(const android::renderscript::Context *rsc) { - RsHal *dc = (RsHal *)rsc->mHal.drv; + RsdHal *dc = (RsdHal *)rsc->mHal.drv; eglSwapBuffers(dc->gl.egl.display, dc->gl.egl.surface); } diff --git a/driver/rsdRuntime.h b/driver/rsdRuntime.h new file mode 100644 index 00000000..840eced7 --- /dev/null +++ b/driver/rsdRuntime.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef RSD_RUNTIME_STUBS_H +#define RSD_RUNTIME_STUBS_H + +#include <rs_hal.h> +#include <bcc/bcc.h> + +#include "rsMutex.h" + +const RsdSymbolTable * rsdLookupSymbolMath(const char *sym); + +void* rsdLookupRuntimeStub(void* pContext, char const* name); + +#endif diff --git a/driver/rsdRuntimeMath.cpp b/driver/rsdRuntimeMath.cpp new file mode 100644 index 00000000..bd1fd0e8 --- /dev/null +++ b/driver/rsdRuntimeMath.cpp @@ -0,0 +1,440 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rsContext.h" +#include "rsScriptC.h" +#include "rsMatrix4x4.h" +#include "rsMatrix3x3.h" +#include "rsMatrix2x2.h" + +#include "rsdCore.h" +#include "rsdRuntime.h" + + +using namespace android; +using namespace android::renderscript; + + +static float SC_exp10(float v) { + return pow(10.f, v); +} + +static float SC_fract(float v, int *iptr) { + int i = (int)floor(v); + iptr[0] = i; + return fmin(v - i, 0x1.fffffep-1f); +} + +static float SC_log2(float v) { + return log10(v) / log10(2.f); +} + +static float SC_mad(float v1, float v2, float v3) { + return v1 * v2 + v3; +} + +#if 0 +static float SC_pown(float v, int p) { + return powf(v, (float)p); +} + +static float SC_powr(float v, float p) { + return powf(v, p); +} +#endif + +float SC_rootn(float v, int r) { + return pow(v, 1.f / r); +} + +float SC_rsqrt(float v) { + return 1.f / sqrtf(v); +} + +float SC_sincos(float v, float *cosptr) { + *cosptr = cosf(v); + return sinf(v); +} + +////////////////////////////////////////////////////////////////////////////// +// Integer +////////////////////////////////////////////////////////////////////////////// + + +static uint32_t SC_abs_i32(int32_t v) {return abs(v);} +static uint16_t SC_abs_i16(int16_t v) {return (uint16_t)abs(v);} +static uint8_t SC_abs_i8(int8_t v) {return (uint8_t)abs(v);} + +static uint32_t SC_clz_u32(uint32_t v) {return __builtin_clz(v);} +static uint16_t SC_clz_u16(uint16_t v) {return (uint16_t)__builtin_clz(v);} +static uint8_t SC_clz_u8(uint8_t v) {return (uint8_t)__builtin_clz(v);} +static int32_t SC_clz_i32(int32_t v) {return (int32_t)__builtin_clz((uint32_t)v);} +static int16_t SC_clz_i16(int16_t v) {return (int16_t)__builtin_clz(v);} +static int8_t SC_clz_i8(int8_t v) {return (int8_t)__builtin_clz(v);} + +static uint32_t SC_max_u32(uint32_t v, uint32_t v2) {return rsMax(v, v2);} +static uint16_t SC_max_u16(uint16_t v, uint16_t v2) {return rsMax(v, v2);} +static uint8_t SC_max_u8(uint8_t v, uint8_t v2) {return rsMax(v, v2);} +static int32_t SC_max_i32(int32_t v, int32_t v2) {return rsMax(v, v2);} +static int16_t SC_max_i16(int16_t v, int16_t v2) {return rsMax(v, v2);} +static int8_t SC_max_i8(int8_t v, int8_t v2) {return rsMax(v, v2);} + +static uint32_t SC_min_u32(uint32_t v, uint32_t v2) {return rsMin(v, v2);} +static uint16_t SC_min_u16(uint16_t v, uint16_t v2) {return rsMin(v, v2);} +static uint8_t SC_min_u8(uint8_t v, uint8_t v2) {return rsMin(v, v2);} +static int32_t SC_min_i32(int32_t v, int32_t v2) {return rsMin(v, v2);} +static int16_t SC_min_i16(int16_t v, int16_t v2) {return rsMin(v, v2);} +static int8_t SC_min_i8(int8_t v, int8_t v2) {return rsMin(v, v2);} + +////////////////////////////////////////////////////////////////////////////// +// Float util +////////////////////////////////////////////////////////////////////////////// + +static float SC_clamp_f32(float amount, float low, float high) { + return amount < low ? low : (amount > high ? high : amount); +} + +static float SC_degrees(float radians) { + return radians * (180.f / M_PI); +} + +static float SC_max_f32(float v, float v2) { + return rsMax(v, v2); +} + +static float SC_min_f32(float v, float v2) { + return rsMin(v, v2); +} + +static float SC_mix_f32(float start, float stop, float amount) { + //LOGE("lerpf %f %f %f", start, stop, amount); + return start + (stop - start) * amount; +} + +static float SC_radians(float degrees) { + return degrees * (M_PI / 180.f); +} + +static float SC_step_f32(float edge, float v) { + if (v < edge) return 0.f; + return 1.f; +} + +static float SC_sign_f32(float value) { + if (value > 0) return 1.f; + if (value < 0) return -1.f; + return value; +} + +static void SC_MatrixLoadIdentity_4x4(Matrix4x4 *m) { + m->loadIdentity(); +} +static void SC_MatrixLoadIdentity_3x3(Matrix3x3 *m) { + m->loadIdentity(); +} +static void SC_MatrixLoadIdentity_2x2(Matrix2x2 *m) { + m->loadIdentity(); +} + +static void SC_MatrixLoad_4x4_f(Matrix4x4 *m, const float *f) { + m->load(f); +} +static void SC_MatrixLoad_3x3_f(Matrix3x3 *m, const float *f) { + m->load(f); +} +static void SC_MatrixLoad_2x2_f(Matrix2x2 *m, const float *f) { + m->load(f); +} + +static void SC_MatrixLoad_4x4_4x4(Matrix4x4 *m, const Matrix4x4 *s) { + m->load(s); +} +static void SC_MatrixLoad_4x4_3x3(Matrix4x4 *m, const Matrix3x3 *s) { + m->load(s); +} +static void SC_MatrixLoad_4x4_2x2(Matrix4x4 *m, const Matrix2x2 *s) { + m->load(s); +} +static void SC_MatrixLoad_3x3_3x3(Matrix3x3 *m, const Matrix3x3 *s) { + m->load(s); +} +static void SC_MatrixLoad_2x2_2x2(Matrix2x2 *m, const Matrix2x2 *s) { + m->load(s); +} + +static void SC_MatrixLoadRotate(Matrix4x4 *m, float rot, float x, float y, float z) { + m->loadRotate(rot, x, y, z); +} +static void SC_MatrixLoadScale(Matrix4x4 *m, float x, float y, float z) { + m->loadScale(x, y, z); +} +static void SC_MatrixLoadTranslate(Matrix4x4 *m, float x, float y, float z) { + m->loadTranslate(x, y, z); +} +static void SC_MatrixRotate(Matrix4x4 *m, float rot, float x, float y, float z) { + m->rotate(rot, x, y, z); +} +static void SC_MatrixScale(Matrix4x4 *m, float x, float y, float z) { + m->scale(x, y, z); +} +static void SC_MatrixTranslate(Matrix4x4 *m, float x, float y, float z) { + m->translate(x, y, z); +} + +static void SC_MatrixLoadMultiply_4x4_4x4_4x4(Matrix4x4 *m, const Matrix4x4 *lhs, const Matrix4x4 *rhs) { + m->loadMultiply(lhs, rhs); +} +static void SC_MatrixLoadMultiply_3x3_3x3_3x3(Matrix3x3 *m, const Matrix3x3 *lhs, const Matrix3x3 *rhs) { + m->loadMultiply(lhs, rhs); +} +static void SC_MatrixLoadMultiply_2x2_2x2_2x2(Matrix2x2 *m, const Matrix2x2 *lhs, const Matrix2x2 *rhs) { + m->loadMultiply(lhs, rhs); +} + +static void SC_MatrixMultiply_4x4_4x4(Matrix4x4 *m, const Matrix4x4 *rhs) { + m->multiply(rhs); +} +static void SC_MatrixMultiply_3x3_3x3(Matrix3x3 *m, const Matrix3x3 *rhs) { + m->multiply(rhs); +} +static void SC_MatrixMultiply_2x2_2x2(Matrix2x2 *m, const Matrix2x2 *rhs) { + m->multiply(rhs); +} + +static void SC_MatrixLoadOrtho(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) { + m->loadOrtho(l, r, b, t, n, f); +} +static void SC_MatrixLoadFrustum(Matrix4x4 *m, float l, float r, float b, float t, float n, float f) { + m->loadFrustum(l, r, b, t, n, f); +} +static void SC_MatrixLoadPerspective(Matrix4x4 *m, float fovy, float aspect, float near, float far) { + m->loadPerspective(fovy, aspect, near, far); +} + +static bool SC_MatrixInverse_4x4(Matrix4x4 *m) { + return m->inverse(); +} +static bool SC_MatrixInverseTranspose_4x4(Matrix4x4 *m) { + return m->inverseTranspose(); +} +static void SC_MatrixTranspose_4x4(Matrix4x4 *m) { + m->transpose(); +} +static void SC_MatrixTranspose_3x3(Matrix3x3 *m) { + m->transpose(); +} +static void SC_MatrixTranspose_2x2(Matrix2x2 *m) { + m->transpose(); +} + +static float SC_randf(float max) { + float r = (float)rand(); + r *= max; + return r / RAND_MAX; +} + +static float SC_randf2(float min, float max) { + float r = (float)rand(); + r = r * (max - min) + min; + return r / RAND_MAX; +} + +static int SC_randi(int max) { + return (int)SC_randf(max); +} + +static int SC_randi2(int min, int max) { + return (int)SC_randf2(min, max); +} + +static float SC_frac(float v) { + int i = (int)floor(v); + return fmin(v - i, 0x1.fffffep-1f); +} + + +////////////////////////////////////////////////////////////////////////////// +// Class implementation +////////////////////////////////////////////////////////////////////////////// + +// llvm name mangling ref +// <builtin-type> ::= v # void +// ::= b # bool +// ::= c # char +// ::= a # signed char +// ::= h # unsigned char +// ::= s # short +// ::= t # unsigned short +// ::= i # int +// ::= j # unsigned int +// ::= l # long +// ::= m # unsigned long +// ::= x # long long, __int64 +// ::= y # unsigned long long, __int64 +// ::= f # float +// ::= d # double + +static RsdSymbolTable gSyms[] = { + { "_Z4acosf", (void *)&acosf, true }, + { "_Z5acoshf", (void *)&acoshf, true }, + { "_Z4asinf", (void *)&asinf, true }, + { "_Z5asinhf", (void *)&asinhf, true }, + { "_Z4atanf", (void *)&atanf, true }, + { "_Z5atan2ff", (void *)&atan2f, true }, + { "_Z5atanhf", (void *)&atanhf, true }, + { "_Z4cbrtf", (void *)&cbrtf, true }, + { "_Z4ceilf", (void *)&ceilf, true }, + { "_Z8copysignff", (void *)©signf, true }, + { "_Z3cosf", (void *)&cosf, true }, + { "_Z4coshf", (void *)&coshf, true }, + { "_Z4erfcf", (void *)&erfcf, true }, + { "_Z3erff", (void *)&erff, true }, + { "_Z3expf", (void *)&expf, true }, + { "_Z4exp2f", (void *)&exp2f, true }, + { "_Z5exp10f", (void *)&SC_exp10, true }, + { "_Z5expm1f", (void *)&expm1f, true }, + { "_Z4fabsf", (void *)&fabsf, true }, + { "_Z4fdimff", (void *)&fdimf, true }, + { "_Z5floorf", (void *)&floorf, true }, + { "_Z3fmafff", (void *)&fmaf, true }, + { "_Z4fmaxff", (void *)&fmaxf, true }, + { "_Z4fminff", (void *)&fminf, true }, // float fmin(float, float) + { "_Z4fmodff", (void *)&fmodf, true }, + { "_Z5fractfPf", (void *)&SC_fract, true }, + { "_Z5frexpfPi", (void *)&frexpf, true }, + { "_Z5hypotff", (void *)&hypotf, true }, + { "_Z5ilogbf", (void *)&ilogbf, true }, + { "_Z5ldexpfi", (void *)&ldexpf, true }, + { "_Z6lgammaf", (void *)&lgammaf, true }, + { "_Z6lgammafPi", (void *)&lgammaf_r, true }, + { "_Z3logf", (void *)&logf, true }, + { "_Z4log2f", (void *)&SC_log2, true }, + { "_Z5log10f", (void *)&log10f, true }, + { "_Z5log1pf", (void *)&log1pf, true }, + { "_Z4logbf", (void *)&logbf, true }, + { "_Z3madfff", (void *)&SC_mad, true }, + { "_Z4modffPf", (void *)&modff, true }, + //{ "_Z3nanj", (void *)&SC_nan, true }, + { "_Z9nextafterff", (void *)&nextafterf, true }, + { "_Z3powff", (void *)&powf, true }, + { "_Z9remainderff", (void *)&remainderf, true }, + { "_Z6remquoffPi", (void *)&remquof, true }, + { "_Z4rintf", (void *)&rintf, true }, + { "_Z5rootnfi", (void *)&SC_rootn, true }, + { "_Z5roundf", (void *)&roundf, true }, + { "_Z5rsqrtf", (void *)&SC_rsqrt, true }, + { "_Z3sinf", (void *)&sinf, true }, + { "_Z6sincosfPf", (void *)&SC_sincos, true }, + { "_Z4sinhf", (void *)&sinhf, true }, + { "_Z4sqrtf", (void *)&sqrtf, true }, + { "_Z3tanf", (void *)&tanf, true }, + { "_Z4tanhf", (void *)&tanhf, true }, + { "_Z6tgammaf", (void *)&tgammaf, true }, + { "_Z5truncf", (void *)&truncf, true }, + + { "_Z3absi", (void *)&SC_abs_i32, true }, + { "_Z3abss", (void *)&SC_abs_i16, true }, + { "_Z3absc", (void *)&SC_abs_i8, true }, + { "_Z3clzj", (void *)&SC_clz_u32, true }, + { "_Z3clzt", (void *)&SC_clz_u16, true }, + { "_Z3clzh", (void *)&SC_clz_u8, true }, + { "_Z3clzi", (void *)&SC_clz_i32, true }, + { "_Z3clzs", (void *)&SC_clz_i16, true }, + { "_Z3clzc", (void *)&SC_clz_i8, true }, + { "_Z3maxjj", (void *)&SC_max_u32, true }, + { "_Z3maxtt", (void *)&SC_max_u16, true }, + { "_Z3maxhh", (void *)&SC_max_u8, true }, + { "_Z3maxii", (void *)&SC_max_i32, true }, + { "_Z3maxss", (void *)&SC_max_i16, true }, + { "_Z3maxcc", (void *)&SC_max_i8, true }, + { "_Z3minjj", (void *)&SC_min_u32, true }, + { "_Z3mintt", (void *)&SC_min_u16, true }, + { "_Z3minhh", (void *)&SC_min_u8, true }, + { "_Z3minii", (void *)&SC_min_i32, true }, + { "_Z3minss", (void *)&SC_min_i16, true }, + { "_Z3mincc", (void *)&SC_min_i8, true }, + + { "_Z5clampfff", (void *)&SC_clamp_f32, true }, + { "_Z7degreesf", (void *)&SC_degrees, true }, + { "_Z3maxff", (void *)&SC_max_f32, true }, + { "_Z3minff", (void *)&SC_min_f32, true }, + { "_Z3mixfff", (void *)&SC_mix_f32, true }, + { "_Z7radiansf", (void *)&SC_radians, true }, + { "_Z4stepff", (void *)&SC_step_f32, true }, + //{ "smoothstep", (void *)&, true }, + { "_Z4signf", (void *)&SC_sign_f32, true }, + + // matrix + { "_Z20rsMatrixLoadIdentityP12rs_matrix4x4", (void *)&SC_MatrixLoadIdentity_4x4, true }, + { "_Z20rsMatrixLoadIdentityP12rs_matrix3x3", (void *)&SC_MatrixLoadIdentity_3x3, true }, + { "_Z20rsMatrixLoadIdentityP12rs_matrix2x2", (void *)&SC_MatrixLoadIdentity_2x2, true }, + + { "_Z12rsMatrixLoadP12rs_matrix4x4PKf", (void *)&SC_MatrixLoad_4x4_f, true }, + { "_Z12rsMatrixLoadP12rs_matrix3x3PKf", (void *)&SC_MatrixLoad_3x3_f, true }, + { "_Z12rsMatrixLoadP12rs_matrix2x2PKf", (void *)&SC_MatrixLoad_2x2_f, true }, + + { "_Z12rsMatrixLoadP12rs_matrix4x4PKS_", (void *)&SC_MatrixLoad_4x4_4x4, true }, + { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix3x3", (void *)&SC_MatrixLoad_4x4_3x3, true }, + { "_Z12rsMatrixLoadP12rs_matrix4x4PK12rs_matrix2x2", (void *)&SC_MatrixLoad_4x4_2x2, true }, + { "_Z12rsMatrixLoadP12rs_matrix3x3PKS_", (void *)&SC_MatrixLoad_3x3_3x3, true }, + { "_Z12rsMatrixLoadP12rs_matrix2x2PKS_", (void *)&SC_MatrixLoad_2x2_2x2, true }, + + { "_Z18rsMatrixLoadRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadRotate, true }, + { "_Z17rsMatrixLoadScaleP12rs_matrix4x4fff", (void *)&SC_MatrixLoadScale, true }, + { "_Z21rsMatrixLoadTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixLoadTranslate, true }, + { "_Z14rsMatrixRotateP12rs_matrix4x4ffff", (void *)&SC_MatrixRotate, true }, + { "_Z13rsMatrixScaleP12rs_matrix4x4fff", (void *)&SC_MatrixScale, true }, + { "_Z17rsMatrixTranslateP12rs_matrix4x4fff", (void *)&SC_MatrixTranslate, true }, + + { "_Z20rsMatrixLoadMultiplyP12rs_matrix4x4PKS_S2_", (void *)&SC_MatrixLoadMultiply_4x4_4x4_4x4, true }, + { "_Z16rsMatrixMultiplyP12rs_matrix4x4PKS_", (void *)&SC_MatrixMultiply_4x4_4x4, true }, + { "_Z20rsMatrixLoadMultiplyP12rs_matrix3x3PKS_S2_", (void *)&SC_MatrixLoadMultiply_3x3_3x3_3x3, true }, + { "_Z16rsMatrixMultiplyP12rs_matrix3x3PKS_", (void *)&SC_MatrixMultiply_3x3_3x3, true }, + { "_Z20rsMatrixLoadMultiplyP12rs_matrix2x2PKS_S2_", (void *)&SC_MatrixLoadMultiply_2x2_2x2_2x2, true }, + { "_Z16rsMatrixMultiplyP12rs_matrix2x2PKS_", (void *)&SC_MatrixMultiply_2x2_2x2, true }, + + { "_Z17rsMatrixLoadOrthoP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadOrtho, true }, + { "_Z19rsMatrixLoadFrustumP12rs_matrix4x4ffffff", (void *)&SC_MatrixLoadFrustum, true }, + { "_Z23rsMatrixLoadPerspectiveP12rs_matrix4x4ffff", (void *)&SC_MatrixLoadPerspective, true }, + + { "_Z15rsMatrixInverseP12rs_matrix4x4", (void *)&SC_MatrixInverse_4x4, true }, + { "_Z24rsMatrixInverseTransposeP12rs_matrix4x4", (void *)&SC_MatrixInverseTranspose_4x4, true }, + { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_4x4, true }, + { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_3x3, true }, + { "_Z17rsMatrixTransposeP12rs_matrix4x4", (void *)&SC_MatrixTranspose_2x2, true }, + + // RS Math + { "_Z6rsRandi", (void *)&SC_randi, true }, + { "_Z6rsRandii", (void *)&SC_randi2, true }, + { "_Z6rsRandf", (void *)&SC_randf, true }, + { "_Z6rsRandff", (void *)&SC_randf2, true }, + { "_Z6rsFracf", (void *)&SC_frac, true }, + + { NULL, NULL, false } +}; + +const RsdSymbolTable * rsdLookupSymbolMath(const char *sym) { + const RsdSymbolTable *syms = gSyms; + + while (syms->mPtr) { + if (!strcmp(syms->mName, sym)) { + return syms; + } + syms++; + } + return NULL; +} + diff --git a/driver/rsdRuntimeStubs.cpp b/driver/rsdRuntimeStubs.cpp new file mode 100644 index 00000000..c16dd314 --- /dev/null +++ b/driver/rsdRuntimeStubs.cpp @@ -0,0 +1,693 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "rsContext.h" +#include "rsScriptC.h" +#include "rsMatrix4x4.h" +#include "rsMatrix3x3.h" +#include "rsMatrix2x2.h" +#include "rsRuntime.h" + +#include "utils/Timers.h" +#include "rsdCore.h" + +#include "rsdRuntime.h" + +#include <time.h> + +using namespace android; +using namespace android::renderscript; + +#define GET_TLS() ScriptTLSStruct * tls = \ + (ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ + Context * rsc = tls->mContext; \ + ScriptC * sc = (ScriptC *) tls->mScript + + + +////////////////////////////////////////////////////////////////////////////// +// Allocation +////////////////////////////////////////////////////////////////////////////// + +static uint32_t SC_allocGetDimX(Allocation *a) { + LOGE("SC_allocGetDimX %p", a); + return a->mHal.state.dimensionX; +} + +static uint32_t SC_allocGetDimY(Allocation *a) { + return a->mHal.state.dimensionY; +} + +static uint32_t SC_allocGetDimZ(Allocation *a) { + return a->mHal.state.dimensionZ; +} + +static uint32_t SC_allocGetDimLOD(Allocation *a) { + return a->mHal.state.hasMipmaps; +} + +static uint32_t SC_allocGetDimFaces(Allocation *a) { + return a->mHal.state.hasFaces; +} + +static const void * SC_getElementAtX(Allocation *a, uint32_t x) { + const uint8_t *p = (const uint8_t *)a->getPtr(); + return &p[a->mHal.state.elementSizeBytes * x]; +} + +static const void * SC_getElementAtXY(Allocation *a, uint32_t x, uint32_t y) { + const uint8_t *p = (const uint8_t *)a->getPtr(); + return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX)]; +} + +static const void * SC_getElementAtXYZ(Allocation *a, uint32_t x, uint32_t y, uint32_t z) { + const uint8_t *p = (const uint8_t *)a->getPtr(); + return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX + + z * a->mHal.state.dimensionX * a->mHal.state.dimensionY)]; +} + +static void SC_AllocationSyncAll2(Allocation *a, RsAllocationUsageType source) { + GET_TLS(); + rsrAllocationSyncAll(rsc, sc, a, source); +} + +static void SC_AllocationSyncAll(Allocation *a) { + GET_TLS(); + rsrAllocationSyncAll(rsc, sc, a, RS_ALLOCATION_USAGE_SCRIPT); +} + +const Allocation * SC_getAllocation(const void *ptr) { + GET_TLS(); + return rsrGetAllocation(rsc, sc, ptr); +} + + +////////////////////////////////////////////////////////////////////////////// +// Context +////////////////////////////////////////////////////////////////////////////// + +static void SC_BindTexture(ProgramFragment *pf, uint32_t slot, Allocation *a) { + GET_TLS(); + rsrBindTexture(rsc, sc, pf, slot, a); +} + +static void SC_BindSampler(ProgramFragment *pf, uint32_t slot, Sampler *s) { + GET_TLS(); + rsrBindSampler(rsc, sc, pf, slot, s); +} + +static void SC_BindProgramStore(ProgramStore *ps) { + GET_TLS(); + rsrBindProgramStore(rsc, sc, ps); +} + +static void SC_BindProgramFragment(ProgramFragment *pf) { + GET_TLS(); + rsrBindProgramFragment(rsc, sc, pf); +} + +static void SC_BindProgramVertex(ProgramVertex *pv) { + GET_TLS(); + rsrBindProgramVertex(rsc, sc, pv); +} + +static void SC_BindProgramRaster(ProgramRaster *pr) { + GET_TLS(); + rsrBindProgramRaster(rsc, sc, pr); +} + +static void SC_BindFrameBufferObjectColorTarget(Allocation *a, uint32_t slot) { + GET_TLS(); + rsrBindFrameBufferObjectColorTarget(rsc, sc, a, slot); +} + +static void SC_BindFrameBufferObjectDepthTarget(Allocation *a) { + GET_TLS(); + rsrBindFrameBufferObjectDepthTarget(rsc, sc, a); +} + +static void SC_ClearFrameBufferObjectColorTarget(uint32_t slot) { + GET_TLS(); + rsrClearFrameBufferObjectColorTarget(rsc, sc, slot); +} + +static void SC_ClearFrameBufferObjectDepthTarget(Context *, Script *) { + GET_TLS(); + rsrClearFrameBufferObjectDepthTarget(rsc, sc); +} + +static void SC_ClearFrameBufferObjectTargets(Context *, Script *) { + GET_TLS(); + rsrClearFrameBufferObjectTargets(rsc, sc); +} + + +////////////////////////////////////////////////////////////////////////////// +// VP +////////////////////////////////////////////////////////////////////////////// + +static void SC_VpLoadProjectionMatrix(const rsc_Matrix *m) { + GET_TLS(); + rsrVpLoadProjectionMatrix(rsc, sc, m); +} + +static void SC_VpLoadModelMatrix(const rsc_Matrix *m) { + GET_TLS(); + rsrVpLoadModelMatrix(rsc, sc, m); +} + +static void SC_VpLoadTextureMatrix(const rsc_Matrix *m) { + GET_TLS(); + rsrVpLoadTextureMatrix(rsc, sc, m); +} + +static void SC_PfConstantColor(ProgramFragment *pf, float r, float g, float b, float a) { + GET_TLS(); + rsrPfConstantColor(rsc, sc, pf, r, g, b, a); +} + +static void SC_VpGetProjectionMatrix(rsc_Matrix *m) { + GET_TLS(); + rsrVpGetProjectionMatrix(rsc, sc, m); +} + + +////////////////////////////////////////////////////////////////////////////// +// Drawing +////////////////////////////////////////////////////////////////////////////// + +static void SC_DrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1, + float x2, float y2, float z2, float u2, float v2, + float x3, float y3, float z3, float u3, float v3, + float x4, float y4, float z4, float u4, float v4) { + GET_TLS(); + rsrDrawQuadTexCoords(rsc, sc, + x1, y1, z1, u1, v1, + x2, y2, z2, u2, v2, + x3, y3, z3, u3, v3, + x4, y4, z4, u4, v4); +} + +static void SC_DrawQuad(float x1, float y1, float z1, + float x2, float y2, float z2, + float x3, float y3, float z3, + float x4, float y4, float z4) { + GET_TLS(); + rsrDrawQuad(rsc, sc, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4); +} + +static void SC_DrawSpriteScreenspace(float x, float y, float z, float w, float h) { + GET_TLS(); + rsrDrawSpriteScreenspace(rsc, sc, x, y, z, w, h); +} + +static void SC_DrawRect(float x1, float y1, float x2, float y2, float z) { + GET_TLS(); + rsrDrawRect(rsc, sc, x1, y1, x2, y2, z); +} + +static void SC_DrawMesh(Mesh *m) { + GET_TLS(); + rsrDrawMesh(rsc, sc, m); +} + +static void SC_DrawMeshPrimitive(Mesh *m, uint32_t primIndex) { + GET_TLS(); + rsrDrawMeshPrimitive(rsc, sc, m, primIndex); +} + +static void SC_DrawMeshPrimitiveRange(Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len) { + GET_TLS(); + rsrDrawMeshPrimitiveRange(rsc, sc, m, primIndex, start, len); +} + +static void SC_MeshComputeBoundingBox(Mesh *m, + float *minX, float *minY, float *minZ, + float *maxX, float *maxY, float *maxZ) { + GET_TLS(); + rsrMeshComputeBoundingBox(rsc, sc, m, minX, minY, minZ, maxX, maxY, maxZ); +} + + + +////////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////////// + + +static void SC_Color(float r, float g, float b, float a) { + GET_TLS(); + rsrColor(rsc, sc, r, g, b, a); +} + +static void SC_Finish() { + GET_TLS(); + rsrFinish(rsc, sc); +} + +static void SC_ClearColor(float r, float g, float b, float a) { + GET_TLS(); + rsrClearColor(rsc, sc, r, g, b, a); +} + +static void SC_ClearDepth(float v) { + GET_TLS(); + rsrClearDepth(rsc, sc, v); +} + +static uint32_t SC_GetWidth() { + GET_TLS(); + return rsrGetWidth(rsc, sc); +} + +static uint32_t SC_GetHeight() { + GET_TLS(); + return rsrGetHeight(rsc, sc); +} + +static void SC_DrawTextAlloc(Allocation *a, int x, int y) { + GET_TLS(); + rsrDrawTextAlloc(rsc, sc, a, x, y); +} + +static void SC_DrawText(const char *text, int x, int y) { + GET_TLS(); + rsrDrawText(rsc, sc, text, x, y); +} + +static void SC_MeasureTextAlloc(Allocation *a, + int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { + GET_TLS(); + rsrMeasureTextAlloc(rsc, sc, a, left, right, top, bottom); +} + +static void SC_MeasureText(const char *text, + int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { + GET_TLS(); + rsrMeasureText(rsc, sc, text, left, right, top, bottom); +} + +static void SC_BindFont(Font *f) { + GET_TLS(); + rsrBindFont(rsc, sc, f); +} + +static void SC_FontColor(float r, float g, float b, float a) { + GET_TLS(); + rsrFontColor(rsc, sc, r, g, b, a); +} + + + +////////////////////////////////////////////////////////////////////////////// +// +////////////////////////////////////////////////////////////////////////////// + +static void SC_SetObject(ObjectBase **dst, ObjectBase * src) { + GET_TLS(); + rsrSetObject(rsc, sc, dst, src); +} + +static void SC_ClearObject(ObjectBase **dst) { + GET_TLS(); + rsrClearObject(rsc, sc, dst); +} + +static bool SC_IsObject(const ObjectBase *src) { + GET_TLS(); + return rsrIsObject(rsc, sc, src); +} + + + + +static const Allocation * SC_GetAllocation(const void *ptr) { + GET_TLS(); + return rsrGetAllocation(rsc, sc, ptr); +} + +static void SC_ForEach(Script *target, + Allocation *in, + Allocation *out, + const void *usr, + const RsScriptCall *call) { + GET_TLS(); + rsrForEach(rsc, sc, target, in, out, usr, 0, NULL); +} + +static void SC_ForEach2(Script *target, + Allocation *in, + Allocation *out, + const void *usr, + const RsScriptCall *call) { + GET_TLS(); + rsrForEach(rsc, sc, target, in, out, usr, 0, call); +} + + + +////////////////////////////////////////////////////////////////////////////// +// Time routines +////////////////////////////////////////////////////////////////////////////// + +static float SC_GetDt() { + GET_TLS(); + return rsrGetDt(rsc, sc); +} + +time_t SC_Time(time_t *timer) { + GET_TLS(); + return rsrTime(rsc, sc, timer); +} + +tm* SC_LocalTime(tm *local, time_t *timer) { + GET_TLS(); + return rsrLocalTime(rsc, sc, local, timer); +} + +int64_t SC_UptimeMillis() { + GET_TLS(); + return rsrUptimeMillis(rsc, sc); +} + +int64_t SC_UptimeNanos() { + GET_TLS(); + return rsrUptimeNanos(rsc, sc); +} + +////////////////////////////////////////////////////////////////////////////// +// Message routines +////////////////////////////////////////////////////////////////////////////// + +static uint32_t SC_ToClient2(int cmdID, void *data, int len) { + GET_TLS(); + return rsrToClient(rsc, sc, cmdID, data, len); +} + +static uint32_t SC_ToClient(int cmdID) { + GET_TLS(); + return rsrToClient(rsc, sc, cmdID, NULL, 0); +} + +static uint32_t SC_ToClientBlocking2(int cmdID, void *data, int len) { + GET_TLS(); + return rsrToClientBlocking(rsc, sc, cmdID, data, len); +} + +static uint32_t SC_ToClientBlocking(int cmdID) { + GET_TLS(); + return rsrToClientBlocking(rsc, sc, cmdID, NULL, 0); +} + +int SC_divsi3(int a, int b) { + return a / b; +} + +int SC_modsi3(int a, int b) { + return a % b; +} + +unsigned int SC_udivsi3(unsigned int a, unsigned int b) { + return a / b; +} + +unsigned int SC_umodsi3(unsigned int a, unsigned int b) { + return a % b; +} + +static void SC_debugF(const char *s, float f) { + LOGD("%s %f, 0x%08x", s, f, *((int *) (&f))); +} +static void SC_debugFv2(const char *s, float f1, float f2) { + LOGD("%s {%f, %f}", s, f1, f2); +} +static void SC_debugFv3(const char *s, float f1, float f2, float f3) { + LOGD("%s {%f, %f, %f}", s, f1, f2, f3); +} +static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) { + LOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4); +} +static void SC_debugD(const char *s, double d) { + LOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d))); +} +static void SC_debugFM4v4(const char *s, const float *f) { + LOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]); + LOGD("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]); + LOGD("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]); + LOGD("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]); +} +static void SC_debugFM3v3(const char *s, const float *f) { + LOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]); + LOGD("%s %f, %f, %f", s, f[1], f[4], f[7]); + LOGD("%s %f, %f, %f}",s, f[2], f[5], f[8]); +} +static void SC_debugFM2v2(const char *s, const float *f) { + LOGD("%s {%f, %f", s, f[0], f[2]); + LOGD("%s %f, %f}",s, f[1], f[3]); +} + +static void SC_debugI32(const char *s, int32_t i) { + LOGD("%s %i 0x%x", s, i, i); +} +static void SC_debugU32(const char *s, uint32_t i) { + LOGD("%s %u 0x%x", s, i, i); +} +static void SC_debugLL64(const char *s, long long ll) { + LOGD("%s %lld 0x%llx", s, ll, ll); +} +static void SC_debugULL64(const char *s, unsigned long long ll) { + LOGD("%s %llu 0x%llx", s, ll, ll); +} + +static void SC_debugP(const char *s, const void *p) { + LOGD("%s %p", s, p); +} + + +////////////////////////////////////////////////////////////////////////////// +// Stub implementation +////////////////////////////////////////////////////////////////////////////// + +// llvm name mangling ref +// <builtin-type> ::= v # void +// ::= b # bool +// ::= c # char +// ::= a # signed char +// ::= h # unsigned char +// ::= s # short +// ::= t # unsigned short +// ::= i # int +// ::= j # unsigned int +// ::= l # long +// ::= m # unsigned long +// ::= x # long long, __int64 +// ::= y # unsigned long long, __int64 +// ::= f # float +// ::= d # double + +static RsdSymbolTable gSyms[] = { + { "__divsi3", (void *)&SC_divsi3, true }, + { "__modsi3", (void *)&SC_modsi3, true }, + { "__udivsi3", (void *)&SC_udivsi3, true }, + { "__umodsi3", (void *)&SC_umodsi3, true }, + { "memset", (void *)&memset, true }, + { "memcpy", (void *)&memcpy, true }, + + // Refcounting + { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP10rs_element", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject10rs_element", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP7rs_type", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject7rs_type", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject13rs_allocation", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject10rs_sampler", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP9rs_script", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject7rs_mesh", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject17rs_program_raster", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject16rs_program_store", (void *)&SC_IsObject, true }, + + { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_SetObject, true }, + { "_Z13rsClearObjectP7rs_font", (void *)&SC_ClearObject, true }, + { "_Z10rsIsObject7rs_font", (void *)&SC_IsObject, true }, + + // Allocation ops + { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true }, + { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true }, + { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true }, + { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true }, + { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true }, + + { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true }, + { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true }, + { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true }, + + { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true }, + + { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true }, + { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false }, + { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false }, + { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true }, + + + // Messaging + + { "_Z14rsSendToClienti", (void *)&SC_ToClient, false }, + { "_Z14rsSendToClientiPKvj", (void *)&SC_ToClient2, false }, + { "_Z22rsSendToClientBlockingi", (void *)&SC_ToClientBlocking, false }, + { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_ToClientBlocking2, false }, + + { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_BindProgramFragment, false }, + { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_BindProgramStore, false }, + { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_BindProgramVertex, false }, + { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_BindProgramRaster, false }, + { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_BindSampler, false }, + { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_BindTexture, false }, + + { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadProjectionMatrix, false }, + { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadModelMatrix, false }, + { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadTextureMatrix, false }, + + { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_VpGetProjectionMatrix, false }, + + { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_PfConstantColor, false }, + + { "_Z11rsgGetWidthv", (void *)&SC_GetWidth, false }, + { "_Z12rsgGetHeightv", (void *)&SC_GetHeight, false }, + + + { "_Z11rsgDrawRectfffff", (void *)&SC_DrawRect, false }, + { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_DrawQuad, false }, + { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_DrawQuadTexCoords, false }, + { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_DrawSpriteScreenspace, false }, + + { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_DrawMesh, false }, + { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_DrawMeshPrimitive, false }, + { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_DrawMeshPrimitiveRange, false }, + { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_MeshComputeBoundingBox, false }, + + { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false }, + { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false }, + + { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false }, + { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false }, + { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false }, + { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false }, + + { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false }, + { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false }, + + { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_BindFrameBufferObjectColorTarget, false }, + { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_BindFrameBufferObjectDepthTarget, false }, + { "_Z19rsgClearColorTargetj", (void *)&SC_ClearFrameBufferObjectColorTarget, false }, + { "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false }, + { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false }, + + { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false }, + { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach2, false }, + + // time + { "_Z6rsTimePi", (void *)&SC_Time, true }, + { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_LocalTime, true }, + { "_Z14rsUptimeMillisv", (void*)&SC_UptimeMillis, true }, + { "_Z13rsUptimeNanosv", (void*)&SC_UptimeNanos, true }, + { "_Z7rsGetDtv", (void*)&SC_GetDt, false }, + + // misc + { "_Z5colorffff", (void *)&SC_Color, false }, + { "_Z9rsgFinishv", (void *)&SC_Finish, false }, + + // Debug + { "_Z7rsDebugPKcf", (void *)&SC_debugF, true }, + { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true }, + { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true }, + { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true }, + { "_Z7rsDebugPKcd", (void *)&SC_debugD, true }, + { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true }, + { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true }, + { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true }, + { "_Z7rsDebugPKci", (void *)&SC_debugI32, true }, + { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true }, + // Both "long" and "unsigned long" need to be redirected to their + // 64-bit counterparts, since we have hacked Slang to use 64-bit + // for "long" on Arm (to be similar to Java). + { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true }, + { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true }, + { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true }, + { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true }, + { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true }, + + { NULL, NULL, false } +}; + + +void* rsdLookupRuntimeStub(void* pContext, char const* name) { + ScriptC *s = (ScriptC *)pContext; + if (!strcmp(name, "__isThreadable")) { + return (void*) s->mHal.info.isThreadable; + } else if (!strcmp(name, "__clearThreadable")) { + s->mHal.info.isThreadable = false; + return NULL; + } + + RsdSymbolTable *syms = gSyms; + const RsdSymbolTable *sym = rsdLookupSymbolMath(name); + + if (!sym) { + while (syms->mPtr) { + if (!strcmp(syms->mName, name)) { + sym = syms; + } + syms++; + } + } + + if (sym) { + s->mHal.info.isThreadable &= sym->threadable; + return sym->mPtr; + } + LOGE("ScriptC sym lookup failed for %s", name); + return NULL; +} + + |
