rsdRuntimeStubs.cpp revision c500e74d0848b721bf01cf0ab344a6adb035c312
1/*
2 * Copyright (C) 2011 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 "rsMatrix4x4.h"
20#include "rsMatrix3x3.h"
21#include "rsMatrix2x2.h"
22#include "rsRuntime.h"
23
24#include "utils/Timers.h"
25#include "rsdCore.h"
26
27#include "rsdRuntime.h"
28
29#include <time.h>
30
31using namespace android;
32using namespace android::renderscript;
33
34#define GET_TLS()  ScriptTLSStruct * tls = \
35    (ScriptTLSStruct *)pthread_getspecific(rsdgThreadTLSKey); \
36    Context * rsc = tls->mContext; \
37    ScriptC * sc = (ScriptC *) tls->mScript
38
39
40
41//////////////////////////////////////////////////////////////////////////////
42// Allocation
43//////////////////////////////////////////////////////////////////////////////
44
45static uint32_t SC_allocGetDimX(Allocation *a) {
46    return a->mHal.state.dimensionX;
47}
48
49static uint32_t SC_allocGetDimY(Allocation *a) {
50    return a->mHal.state.dimensionY;
51}
52
53static uint32_t SC_allocGetDimZ(Allocation *a) {
54    return a->mHal.state.dimensionZ;
55}
56
57static uint32_t SC_allocGetDimLOD(Allocation *a) {
58    return a->mHal.state.hasMipmaps;
59}
60
61static uint32_t SC_allocGetDimFaces(Allocation *a) {
62    return a->mHal.state.hasFaces;
63}
64
65static const void * SC_getElementAtX(Allocation *a, uint32_t x) {
66    const uint8_t *p = (const uint8_t *)a->getPtr();
67    return &p[a->mHal.state.elementSizeBytes * x];
68}
69
70static const void * SC_getElementAtXY(Allocation *a, uint32_t x, uint32_t y) {
71    const uint8_t *p = (const uint8_t *)a->getPtr();
72    return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX)];
73}
74
75static const void * SC_getElementAtXYZ(Allocation *a, uint32_t x, uint32_t y, uint32_t z) {
76    const uint8_t *p = (const uint8_t *)a->getPtr();
77    return &p[a->mHal.state.elementSizeBytes * (x + y * a->mHal.state.dimensionX +
78              z * a->mHal.state.dimensionX * a->mHal.state.dimensionY)];
79}
80
81static void SC_AllocationSyncAll2(Allocation *a, RsAllocationUsageType source) {
82    GET_TLS();
83    rsrAllocationSyncAll(rsc, sc, a, source);
84}
85
86static void SC_AllocationSyncAll(Allocation *a) {
87    GET_TLS();
88    rsrAllocationSyncAll(rsc, sc, a, RS_ALLOCATION_USAGE_SCRIPT);
89}
90
91static void SC_AllocationCopy1DRange(Allocation *dstAlloc,
92                                     uint32_t dstOff,
93                                     uint32_t dstMip,
94                                     uint32_t count,
95                                     Allocation *srcAlloc,
96                                     uint32_t srcOff, uint32_t srcMip) {
97    GET_TLS();
98    rsrAllocationCopy1DRange(rsc, dstAlloc, dstOff, dstMip, count,
99                             srcAlloc, srcOff, srcMip);
100}
101
102static void SC_AllocationCopy2DRange(Allocation *dstAlloc,
103                                     uint32_t dstXoff, uint32_t dstYoff,
104                                     uint32_t dstMip, uint32_t dstFace,
105                                     uint32_t width, uint32_t height,
106                                     Allocation *srcAlloc,
107                                     uint32_t srcXoff, uint32_t srcYoff,
108                                     uint32_t srcMip, uint32_t srcFace) {
109    GET_TLS();
110    rsrAllocationCopy2DRange(rsc, dstAlloc,
111                             dstXoff, dstYoff, dstMip, dstFace,
112                             width, height,
113                             srcAlloc,
114                             srcXoff, srcYoff, srcMip, srcFace);
115}
116
117
118const Allocation * SC_getAllocation(const void *ptr) {
119    GET_TLS();
120    return rsrGetAllocation(rsc, sc, ptr);
121}
122
123
124//////////////////////////////////////////////////////////////////////////////
125// Context
126//////////////////////////////////////////////////////////////////////////////
127
128static void SC_BindTexture(ProgramFragment *pf, uint32_t slot, Allocation *a) {
129    GET_TLS();
130    rsrBindTexture(rsc, sc, pf, slot, a);
131}
132
133static void SC_BindSampler(ProgramFragment *pf, uint32_t slot, Sampler *s) {
134    GET_TLS();
135    rsrBindSampler(rsc, sc, pf, slot, s);
136}
137
138static void SC_BindProgramStore(ProgramStore *ps) {
139    GET_TLS();
140    rsrBindProgramStore(rsc, sc, ps);
141}
142
143static void SC_BindProgramFragment(ProgramFragment *pf) {
144    GET_TLS();
145    rsrBindProgramFragment(rsc, sc, pf);
146}
147
148static void SC_BindProgramVertex(ProgramVertex *pv) {
149    GET_TLS();
150    rsrBindProgramVertex(rsc, sc, pv);
151}
152
153static void SC_BindProgramRaster(ProgramRaster *pr) {
154    GET_TLS();
155    rsrBindProgramRaster(rsc, sc, pr);
156}
157
158static void SC_BindFrameBufferObjectColorTarget(Allocation *a, uint32_t slot) {
159    GET_TLS();
160    rsrBindFrameBufferObjectColorTarget(rsc, sc, a, slot);
161}
162
163static void SC_BindFrameBufferObjectDepthTarget(Allocation *a) {
164    GET_TLS();
165    rsrBindFrameBufferObjectDepthTarget(rsc, sc, a);
166}
167
168static void SC_ClearFrameBufferObjectColorTarget(uint32_t slot) {
169    GET_TLS();
170    rsrClearFrameBufferObjectColorTarget(rsc, sc, slot);
171}
172
173static void SC_ClearFrameBufferObjectDepthTarget(Context *, Script *) {
174    GET_TLS();
175    rsrClearFrameBufferObjectDepthTarget(rsc, sc);
176}
177
178static void SC_ClearFrameBufferObjectTargets(Context *, Script *) {
179    GET_TLS();
180    rsrClearFrameBufferObjectTargets(rsc, sc);
181}
182
183
184//////////////////////////////////////////////////////////////////////////////
185// VP
186//////////////////////////////////////////////////////////////////////////////
187
188static void SC_VpLoadProjectionMatrix(const rsc_Matrix *m) {
189    GET_TLS();
190    rsrVpLoadProjectionMatrix(rsc, sc, m);
191}
192
193static void SC_VpLoadModelMatrix(const rsc_Matrix *m) {
194    GET_TLS();
195    rsrVpLoadModelMatrix(rsc, sc, m);
196}
197
198static void SC_VpLoadTextureMatrix(const rsc_Matrix *m) {
199    GET_TLS();
200    rsrVpLoadTextureMatrix(rsc, sc, m);
201}
202
203static void SC_PfConstantColor(ProgramFragment *pf, float r, float g, float b, float a) {
204    GET_TLS();
205    rsrPfConstantColor(rsc, sc, pf, r, g, b, a);
206}
207
208static void SC_VpGetProjectionMatrix(rsc_Matrix *m) {
209    GET_TLS();
210    rsrVpGetProjectionMatrix(rsc, sc, m);
211}
212
213
214//////////////////////////////////////////////////////////////////////////////
215// Drawing
216//////////////////////////////////////////////////////////////////////////////
217
218static void SC_DrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1,
219                                 float x2, float y2, float z2, float u2, float v2,
220                                 float x3, float y3, float z3, float u3, float v3,
221                                 float x4, float y4, float z4, float u4, float v4) {
222    GET_TLS();
223    rsrDrawQuadTexCoords(rsc, sc,
224                         x1, y1, z1, u1, v1,
225                         x2, y2, z2, u2, v2,
226                         x3, y3, z3, u3, v3,
227                         x4, y4, z4, u4, v4);
228}
229
230static void SC_DrawQuad(float x1, float y1, float z1,
231                        float x2, float y2, float z2,
232                        float x3, float y3, float z3,
233                        float x4, float y4, float z4) {
234    GET_TLS();
235    rsrDrawQuad(rsc, sc, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4);
236}
237
238static void SC_DrawSpriteScreenspace(float x, float y, float z, float w, float h) {
239    GET_TLS();
240    rsrDrawSpriteScreenspace(rsc, sc, x, y, z, w, h);
241}
242
243static void SC_DrawRect(float x1, float y1, float x2, float y2, float z) {
244    GET_TLS();
245    rsrDrawRect(rsc, sc, x1, y1, x2, y2, z);
246}
247
248static void SC_DrawMesh(Mesh *m) {
249    GET_TLS();
250    rsrDrawMesh(rsc, sc, m);
251}
252
253static void SC_DrawMeshPrimitive(Mesh *m, uint32_t primIndex) {
254    GET_TLS();
255    rsrDrawMeshPrimitive(rsc, sc, m, primIndex);
256}
257
258static void SC_DrawMeshPrimitiveRange(Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len) {
259    GET_TLS();
260    rsrDrawMeshPrimitiveRange(rsc, sc, m, primIndex, start, len);
261}
262
263static void SC_MeshComputeBoundingBox(Mesh *m,
264                               float *minX, float *minY, float *minZ,
265                               float *maxX, float *maxY, float *maxZ) {
266    GET_TLS();
267    rsrMeshComputeBoundingBox(rsc, sc, m, minX, minY, minZ, maxX, maxY, maxZ);
268}
269
270
271
272//////////////////////////////////////////////////////////////////////////////
273//
274//////////////////////////////////////////////////////////////////////////////
275
276
277static void SC_Color(float r, float g, float b, float a) {
278    GET_TLS();
279    rsrColor(rsc, sc, r, g, b, a);
280}
281
282static void SC_Finish() {
283    GET_TLS();
284    rsrFinish(rsc, sc);
285}
286
287static void SC_ClearColor(float r, float g, float b, float a) {
288    GET_TLS();
289    rsrClearColor(rsc, sc, r, g, b, a);
290}
291
292static void SC_ClearDepth(float v) {
293    GET_TLS();
294    rsrClearDepth(rsc, sc, v);
295}
296
297static uint32_t SC_GetWidth() {
298    GET_TLS();
299    return rsrGetWidth(rsc, sc);
300}
301
302static uint32_t SC_GetHeight() {
303    GET_TLS();
304    return rsrGetHeight(rsc, sc);
305}
306
307static void SC_DrawTextAlloc(Allocation *a, int x, int y) {
308    GET_TLS();
309    rsrDrawTextAlloc(rsc, sc, a, x, y);
310}
311
312static void SC_DrawText(const char *text, int x, int y) {
313    GET_TLS();
314    rsrDrawText(rsc, sc, text, x, y);
315}
316
317static void SC_MeasureTextAlloc(Allocation *a,
318                         int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) {
319    GET_TLS();
320    rsrMeasureTextAlloc(rsc, sc, a, left, right, top, bottom);
321}
322
323static void SC_MeasureText(const char *text,
324                    int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) {
325    GET_TLS();
326    rsrMeasureText(rsc, sc, text, left, right, top, bottom);
327}
328
329static void SC_BindFont(Font *f) {
330    GET_TLS();
331    rsrBindFont(rsc, sc, f);
332}
333
334static void SC_FontColor(float r, float g, float b, float a) {
335    GET_TLS();
336    rsrFontColor(rsc, sc, r, g, b, a);
337}
338
339
340
341//////////////////////////////////////////////////////////////////////////////
342//
343//////////////////////////////////////////////////////////////////////////////
344
345static void SC_SetObject(ObjectBase **dst, ObjectBase * src) {
346    GET_TLS();
347    rsrSetObject(rsc, sc, dst, src);
348}
349
350static void SC_ClearObject(ObjectBase **dst) {
351    GET_TLS();
352    rsrClearObject(rsc, sc, dst);
353}
354
355static bool SC_IsObject(const ObjectBase *src) {
356    GET_TLS();
357    return rsrIsObject(rsc, sc, src);
358}
359
360
361
362
363static const Allocation * SC_GetAllocation(const void *ptr) {
364    GET_TLS();
365    return rsrGetAllocation(rsc, sc, ptr);
366}
367
368static void SC_ForEach_SAA(Script *target,
369                            Allocation *in,
370                            Allocation *out) {
371    GET_TLS();
372    rsrForEach(rsc, sc, target, in, out, NULL, 0, NULL);
373}
374
375static void SC_ForEach_SAAU(Script *target,
376                            Allocation *in,
377                            Allocation *out,
378                            const void *usr) {
379    GET_TLS();
380    rsrForEach(rsc, sc, target, in, out, usr, 0, NULL);
381}
382
383static void SC_ForEach_SAAUS(Script *target,
384                             Allocation *in,
385                             Allocation *out,
386                             const void *usr,
387                             const RsScriptCall *call) {
388    GET_TLS();
389    rsrForEach(rsc, sc, target, in, out, usr, 0, call);
390}
391
392static void SC_ForEach_SAAUL(Script *target,
393                             Allocation *in,
394                             Allocation *out,
395                             const void *usr,
396                             uint32_t usrLen) {
397    GET_TLS();
398    rsrForEach(rsc, sc, target, in, out, usr, usrLen, NULL);
399}
400
401static void SC_ForEach_SAAULS(Script *target,
402                              Allocation *in,
403                              Allocation *out,
404                              const void *usr,
405                              uint32_t usrLen,
406                              const RsScriptCall *call) {
407    GET_TLS();
408    rsrForEach(rsc, sc, target, in, out, usr, usrLen, call);
409}
410
411
412
413//////////////////////////////////////////////////////////////////////////////
414// Time routines
415//////////////////////////////////////////////////////////////////////////////
416
417static float SC_GetDt() {
418    GET_TLS();
419    return rsrGetDt(rsc, sc);
420}
421
422time_t SC_Time(time_t *timer) {
423    GET_TLS();
424    return rsrTime(rsc, sc, timer);
425}
426
427tm* SC_LocalTime(tm *local, time_t *timer) {
428    GET_TLS();
429    return rsrLocalTime(rsc, sc, local, timer);
430}
431
432int64_t SC_UptimeMillis() {
433    GET_TLS();
434    return rsrUptimeMillis(rsc, sc);
435}
436
437int64_t SC_UptimeNanos() {
438    GET_TLS();
439    return rsrUptimeNanos(rsc, sc);
440}
441
442//////////////////////////////////////////////////////////////////////////////
443// Message routines
444//////////////////////////////////////////////////////////////////////////////
445
446static uint32_t SC_ToClient2(int cmdID, void *data, int len) {
447    GET_TLS();
448    return rsrToClient(rsc, sc, cmdID, data, len);
449}
450
451static uint32_t SC_ToClient(int cmdID) {
452    GET_TLS();
453    return rsrToClient(rsc, sc, cmdID, NULL, 0);
454}
455
456static uint32_t SC_ToClientBlocking2(int cmdID, void *data, int len) {
457    GET_TLS();
458    return rsrToClientBlocking(rsc, sc, cmdID, data, len);
459}
460
461static uint32_t SC_ToClientBlocking(int cmdID) {
462    GET_TLS();
463    return rsrToClientBlocking(rsc, sc, cmdID, NULL, 0);
464}
465
466int SC_divsi3(int a, int b) {
467    return a / b;
468}
469
470int SC_modsi3(int a, int b) {
471    return a % b;
472}
473
474unsigned int SC_udivsi3(unsigned int a, unsigned int b) {
475    return a / b;
476}
477
478unsigned int SC_umodsi3(unsigned int a, unsigned int b) {
479    return a % b;
480}
481
482static void SC_debugF(const char *s, float f) {
483    LOGD("%s %f, 0x%08x", s, f, *((int *) (&f)));
484}
485static void SC_debugFv2(const char *s, float f1, float f2) {
486    LOGD("%s {%f, %f}", s, f1, f2);
487}
488static void SC_debugFv3(const char *s, float f1, float f2, float f3) {
489    LOGD("%s {%f, %f, %f}", s, f1, f2, f3);
490}
491static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) {
492    LOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4);
493}
494static void SC_debugD(const char *s, double d) {
495    LOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d)));
496}
497static void SC_debugFM4v4(const char *s, const float *f) {
498    LOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]);
499    LOGD("%s  %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]);
500    LOGD("%s  %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]);
501    LOGD("%s  %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]);
502}
503static void SC_debugFM3v3(const char *s, const float *f) {
504    LOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]);
505    LOGD("%s  %f, %f, %f", s, f[1], f[4], f[7]);
506    LOGD("%s  %f, %f, %f}",s, f[2], f[5], f[8]);
507}
508static void SC_debugFM2v2(const char *s, const float *f) {
509    LOGD("%s {%f, %f", s, f[0], f[2]);
510    LOGD("%s  %f, %f}",s, f[1], f[3]);
511}
512
513static void SC_debugI32(const char *s, int32_t i) {
514    LOGD("%s %i  0x%x", s, i, i);
515}
516static void SC_debugU32(const char *s, uint32_t i) {
517    LOGD("%s %u  0x%x", s, i, i);
518}
519static void SC_debugLL64(const char *s, long long ll) {
520    LOGD("%s %lld  0x%llx", s, ll, ll);
521}
522static void SC_debugULL64(const char *s, unsigned long long ll) {
523    LOGD("%s %llu  0x%llx", s, ll, ll);
524}
525
526static void SC_debugP(const char *s, const void *p) {
527    LOGD("%s %p", s, p);
528}
529
530
531//////////////////////////////////////////////////////////////////////////////
532// Stub implementation
533//////////////////////////////////////////////////////////////////////////////
534
535// llvm name mangling ref
536//  <builtin-type> ::= v  # void
537//                 ::= b  # bool
538//                 ::= c  # char
539//                 ::= a  # signed char
540//                 ::= h  # unsigned char
541//                 ::= s  # short
542//                 ::= t  # unsigned short
543//                 ::= i  # int
544//                 ::= j  # unsigned int
545//                 ::= l  # long
546//                 ::= m  # unsigned long
547//                 ::= x  # long long, __int64
548//                 ::= y  # unsigned long long, __int64
549//                 ::= f  # float
550//                 ::= d  # double
551
552static RsdSymbolTable gSyms[] = {
553    { "memset", (void *)&memset, true },
554    { "memcpy", (void *)&memcpy, true },
555
556    // Refcounting
557    { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_SetObject, true },
558    { "_Z13rsClearObjectP10rs_element", (void *)&SC_ClearObject, true },
559    { "_Z10rsIsObject10rs_element", (void *)&SC_IsObject, true },
560
561    { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_SetObject, true },
562    { "_Z13rsClearObjectP7rs_type", (void *)&SC_ClearObject, true },
563    { "_Z10rsIsObject7rs_type", (void *)&SC_IsObject, true },
564
565    { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_SetObject, true },
566    { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_ClearObject, true },
567    { "_Z10rsIsObject13rs_allocation", (void *)&SC_IsObject, true },
568
569    { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_SetObject, true },
570    { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_ClearObject, true },
571    { "_Z10rsIsObject10rs_sampler", (void *)&SC_IsObject, true },
572
573    { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_SetObject, true },
574    { "_Z13rsClearObjectP9rs_script", (void *)&SC_ClearObject, true },
575    { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject, true },
576
577    { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_SetObject, true },
578    { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_ClearObject, true },
579    { "_Z10rsIsObject7rs_mesh", (void *)&SC_IsObject, true },
580
581    { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_SetObject, true },
582    { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_ClearObject, true },
583    { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_IsObject, true },
584
585    { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_SetObject, true },
586    { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_ClearObject, true },
587    { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_IsObject, true },
588
589    { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_SetObject, true },
590    { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_ClearObject, true },
591    { "_Z10rsIsObject17rs_program_raster", (void *)&SC_IsObject, true },
592
593    { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_SetObject, true },
594    { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_ClearObject, true },
595    { "_Z10rsIsObject16rs_program_store", (void *)&SC_IsObject, true },
596
597    { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_SetObject, true },
598    { "_Z13rsClearObjectP7rs_font", (void *)&SC_ClearObject, true },
599    { "_Z10rsIsObject7rs_font", (void *)&SC_IsObject, true },
600
601    // Allocation ops
602    { "_Z19rsAllocationGetDimX13rs_allocation", (void *)&SC_allocGetDimX, true },
603    { "_Z19rsAllocationGetDimY13rs_allocation", (void *)&SC_allocGetDimY, true },
604    { "_Z19rsAllocationGetDimZ13rs_allocation", (void *)&SC_allocGetDimZ, true },
605    { "_Z21rsAllocationGetDimLOD13rs_allocation", (void *)&SC_allocGetDimLOD, true },
606    { "_Z23rsAllocationGetDimFaces13rs_allocation", (void *)&SC_allocGetDimFaces, true },
607
608    { "_Z14rsGetElementAt13rs_allocationj", (void *)&SC_getElementAtX, true },
609    { "_Z14rsGetElementAt13rs_allocationjj", (void *)&SC_getElementAtXY, true },
610    { "_Z14rsGetElementAt13rs_allocationjjj", (void *)&SC_getElementAtXYZ, true },
611
612    { "_Z15rsGetAllocationPKv", (void *)&SC_getAllocation, true },
613
614    { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true },
615    { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false },
616    { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false },
617    { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false },
618    { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true },
619
620    { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false },
621    { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false },
622
623    // Messaging
624
625    { "_Z14rsSendToClienti", (void *)&SC_ToClient, false },
626    { "_Z14rsSendToClientiPKvj", (void *)&SC_ToClient2, false },
627    { "_Z22rsSendToClientBlockingi", (void *)&SC_ToClientBlocking, false },
628    { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_ToClientBlocking2, false },
629
630    { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_BindProgramFragment, false },
631    { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_BindProgramStore, false },
632    { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_BindProgramVertex, false },
633    { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_BindProgramRaster, false },
634    { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_BindSampler, false },
635    { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_BindTexture, false },
636
637    { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadProjectionMatrix, false },
638    { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadModelMatrix, false },
639    { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadTextureMatrix, false },
640
641    { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_VpGetProjectionMatrix, false },
642
643    { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_PfConstantColor, false },
644
645    { "_Z11rsgGetWidthv", (void *)&SC_GetWidth, false },
646    { "_Z12rsgGetHeightv", (void *)&SC_GetHeight, false },
647
648
649    { "_Z11rsgDrawRectfffff", (void *)&SC_DrawRect, false },
650    { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_DrawQuad, false },
651    { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_DrawQuadTexCoords, false },
652    { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_DrawSpriteScreenspace, false },
653
654    { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_DrawMesh, false },
655    { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_DrawMeshPrimitive, false },
656    { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_DrawMeshPrimitiveRange, false },
657    { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_MeshComputeBoundingBox, false },
658
659    { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false },
660    { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false },
661
662    { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false },
663    { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false },
664    { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false },
665    { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false },
666
667    { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false },
668    { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false },
669
670    { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_BindFrameBufferObjectColorTarget, false },
671    { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_BindFrameBufferObjectDepthTarget, false },
672    { "_Z19rsgClearColorTargetj", (void *)&SC_ClearFrameBufferObjectColorTarget, false },
673    { "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false },
674    { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false },
675
676    { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, false },
677    { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, false },
678    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvPK16rs_script_call_t", (void *)&SC_ForEach_SAAUS, false },
679    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach_SAAUL, false },
680    { "_Z9rsForEach9rs_script13rs_allocationS0_PKvjPK16rs_script_call_t", (void *)&SC_ForEach_SAAULS, false },
681
682    // time
683    { "_Z6rsTimePi", (void *)&SC_Time, true },
684    { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_LocalTime, true },
685    { "_Z14rsUptimeMillisv", (void*)&SC_UptimeMillis, true },
686    { "_Z13rsUptimeNanosv", (void*)&SC_UptimeNanos, true },
687    { "_Z7rsGetDtv", (void*)&SC_GetDt, false },
688
689    // misc
690    { "_Z5colorffff", (void *)&SC_Color, false },
691    { "_Z9rsgFinishv", (void *)&SC_Finish, false },
692
693    // Debug
694    { "_Z7rsDebugPKcf", (void *)&SC_debugF, true },
695    { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true },
696    { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true },
697    { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true },
698    { "_Z7rsDebugPKcd", (void *)&SC_debugD, true },
699    { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true },
700    { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true },
701    { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true },
702    { "_Z7rsDebugPKci", (void *)&SC_debugI32, true },
703    { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true },
704    // Both "long" and "unsigned long" need to be redirected to their
705    // 64-bit counterparts, since we have hacked Slang to use 64-bit
706    // for "long" on Arm (to be similar to Java).
707    { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true },
708    { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true },
709    { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true },
710    { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true },
711    { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true },
712
713    { NULL, NULL, false }
714};
715
716
717void* rsdLookupRuntimeStub(void* pContext, char const* name) {
718    ScriptC *s = (ScriptC *)pContext;
719    if (!strcmp(name, "__isThreadable")) {
720      return (void*) s->mHal.info.isThreadable;
721    } else if (!strcmp(name, "__clearThreadable")) {
722      s->mHal.info.isThreadable = false;
723      return NULL;
724    }
725
726    RsdSymbolTable *syms = gSyms;
727    const RsdSymbolTable *sym = rsdLookupSymbolMath(name);
728
729    if (!sym) {
730        while (syms->mPtr) {
731            if (!strcmp(syms->mName, name)) {
732                sym = syms;
733            }
734            syms++;
735        }
736    }
737
738    if (sym) {
739        s->mHal.info.isThreadable &= sym->threadable;
740        return sym->mPtr;
741    }
742    LOGE("ScriptC sym lookup failed for %s", name);
743    return NULL;
744}
745
746
747