rsdRuntimeStubs.cpp revision a3af2cd3cc684aee2a090475f797936f3bd1b8cb
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#include "rsdPath.h" 29#include "rsdAllocation.h" 30 31#include <time.h> 32 33using namespace android; 34using namespace android::renderscript; 35 36#define GET_TLS() ScriptTLSStruct * tls = \ 37 (ScriptTLSStruct *)pthread_getspecific(rsdgThreadTLSKey); \ 38 Context * rsc = tls->mContext; \ 39 ScriptC * sc = (ScriptC *) tls->mScript 40 41typedef float float2 __attribute__((ext_vector_type(2))); 42typedef float float3 __attribute__((ext_vector_type(3))); 43typedef float float4 __attribute__((ext_vector_type(4))); 44typedef char char2 __attribute__((ext_vector_type(2))); 45typedef char char3 __attribute__((ext_vector_type(3))); 46typedef char char4 __attribute__((ext_vector_type(4))); 47typedef unsigned char uchar2 __attribute__((ext_vector_type(2))); 48typedef unsigned char uchar3 __attribute__((ext_vector_type(3))); 49typedef unsigned char uchar4 __attribute__((ext_vector_type(4))); 50typedef short short2 __attribute__((ext_vector_type(2))); 51typedef short short3 __attribute__((ext_vector_type(3))); 52typedef short short4 __attribute__((ext_vector_type(4))); 53typedef unsigned short ushort2 __attribute__((ext_vector_type(2))); 54typedef unsigned short ushort3 __attribute__((ext_vector_type(3))); 55typedef unsigned short ushort4 __attribute__((ext_vector_type(4))); 56typedef int32_t int2 __attribute__((ext_vector_type(2))); 57typedef int32_t int3 __attribute__((ext_vector_type(3))); 58typedef int32_t int4 __attribute__((ext_vector_type(4))); 59typedef uint32_t uint2 __attribute__((ext_vector_type(2))); 60typedef uint32_t uint3 __attribute__((ext_vector_type(3))); 61typedef uint32_t uint4 __attribute__((ext_vector_type(4))); 62typedef long long long2 __attribute__((ext_vector_type(2))); 63typedef long long long3 __attribute__((ext_vector_type(3))); 64typedef long long long4 __attribute__((ext_vector_type(4))); 65typedef unsigned long long ulong2 __attribute__((ext_vector_type(2))); 66typedef unsigned long long ulong3 __attribute__((ext_vector_type(3))); 67typedef unsigned long long ulong4 __attribute__((ext_vector_type(4))); 68 69 70////////////////////////////////////////////////////////////////////////////// 71// Allocation 72////////////////////////////////////////////////////////////////////////////// 73 74 75static void SC_AllocationSyncAll2(Allocation *a, RsAllocationUsageType source) { 76 GET_TLS(); 77 rsrAllocationSyncAll(rsc, sc, a, source); 78} 79 80static void SC_AllocationSyncAll(Allocation *a) { 81 GET_TLS(); 82 rsrAllocationSyncAll(rsc, sc, a, RS_ALLOCATION_USAGE_SCRIPT); 83} 84 85static void SC_AllocationCopy1DRange(Allocation *dstAlloc, 86 uint32_t dstOff, 87 uint32_t dstMip, 88 uint32_t count, 89 Allocation *srcAlloc, 90 uint32_t srcOff, uint32_t srcMip) { 91 GET_TLS(); 92 rsrAllocationCopy1DRange(rsc, dstAlloc, dstOff, dstMip, count, 93 srcAlloc, srcOff, srcMip); 94} 95 96static void SC_AllocationCopy2DRange(Allocation *dstAlloc, 97 uint32_t dstXoff, uint32_t dstYoff, 98 uint32_t dstMip, uint32_t dstFace, 99 uint32_t width, uint32_t height, 100 Allocation *srcAlloc, 101 uint32_t srcXoff, uint32_t srcYoff, 102 uint32_t srcMip, uint32_t srcFace) { 103 GET_TLS(); 104 rsrAllocationCopy2DRange(rsc, dstAlloc, 105 dstXoff, dstYoff, dstMip, dstFace, 106 width, height, 107 srcAlloc, 108 srcXoff, srcYoff, srcMip, srcFace); 109} 110 111static void SC_AllocationIoSend(Allocation *alloc) { 112 GET_TLS(); 113 rsdAllocationIoSend(rsc, alloc); 114} 115 116 117static void SC_AllocationIoReceive(Allocation *alloc) { 118 GET_TLS(); 119 rsdAllocationIoReceive(rsc, alloc); 120} 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_BindVertexConstant(ProgramVertex *pv, uint32_t slot, Allocation *a) { 134 GET_TLS(); 135 rsrBindConstant(rsc, sc, pv, slot, a); 136} 137 138static void SC_BindFragmentConstant(ProgramFragment *pf, uint32_t slot, Allocation *a) { 139 GET_TLS(); 140 rsrBindConstant(rsc, sc, pf, slot, a); 141} 142 143static void SC_BindSampler(ProgramFragment *pf, uint32_t slot, Sampler *s) { 144 GET_TLS(); 145 rsrBindSampler(rsc, sc, pf, slot, s); 146} 147 148static void SC_BindProgramStore(ProgramStore *ps) { 149 GET_TLS(); 150 rsrBindProgramStore(rsc, sc, ps); 151} 152 153static void SC_BindProgramFragment(ProgramFragment *pf) { 154 GET_TLS(); 155 rsrBindProgramFragment(rsc, sc, pf); 156} 157 158static void SC_BindProgramVertex(ProgramVertex *pv) { 159 GET_TLS(); 160 rsrBindProgramVertex(rsc, sc, pv); 161} 162 163static void SC_BindProgramRaster(ProgramRaster *pr) { 164 GET_TLS(); 165 rsrBindProgramRaster(rsc, sc, pr); 166} 167 168static void SC_BindFrameBufferObjectColorTarget(Allocation *a, uint32_t slot) { 169 GET_TLS(); 170 rsrBindFrameBufferObjectColorTarget(rsc, sc, a, slot); 171} 172 173static void SC_BindFrameBufferObjectDepthTarget(Allocation *a) { 174 GET_TLS(); 175 rsrBindFrameBufferObjectDepthTarget(rsc, sc, a); 176} 177 178static void SC_ClearFrameBufferObjectColorTarget(uint32_t slot) { 179 GET_TLS(); 180 rsrClearFrameBufferObjectColorTarget(rsc, sc, slot); 181} 182 183static void SC_ClearFrameBufferObjectDepthTarget(Context *, Script *) { 184 GET_TLS(); 185 rsrClearFrameBufferObjectDepthTarget(rsc, sc); 186} 187 188static void SC_ClearFrameBufferObjectTargets(Context *, Script *) { 189 GET_TLS(); 190 rsrClearFrameBufferObjectTargets(rsc, sc); 191} 192 193 194////////////////////////////////////////////////////////////////////////////// 195// VP 196////////////////////////////////////////////////////////////////////////////// 197 198static void SC_VpLoadProjectionMatrix(const rsc_Matrix *m) { 199 GET_TLS(); 200 rsrVpLoadProjectionMatrix(rsc, sc, m); 201} 202 203static void SC_VpLoadModelMatrix(const rsc_Matrix *m) { 204 GET_TLS(); 205 rsrVpLoadModelMatrix(rsc, sc, m); 206} 207 208static void SC_VpLoadTextureMatrix(const rsc_Matrix *m) { 209 GET_TLS(); 210 rsrVpLoadTextureMatrix(rsc, sc, m); 211} 212 213static void SC_PfConstantColor(ProgramFragment *pf, float r, float g, float b, float a) { 214 GET_TLS(); 215 rsrPfConstantColor(rsc, sc, pf, r, g, b, a); 216} 217 218static void SC_VpGetProjectionMatrix(rsc_Matrix *m) { 219 GET_TLS(); 220 rsrVpGetProjectionMatrix(rsc, sc, m); 221} 222 223 224////////////////////////////////////////////////////////////////////////////// 225// Drawing 226////////////////////////////////////////////////////////////////////////////// 227 228static void SC_DrawQuadTexCoords(float x1, float y1, float z1, float u1, float v1, 229 float x2, float y2, float z2, float u2, float v2, 230 float x3, float y3, float z3, float u3, float v3, 231 float x4, float y4, float z4, float u4, float v4) { 232 GET_TLS(); 233 rsrDrawQuadTexCoords(rsc, sc, 234 x1, y1, z1, u1, v1, 235 x2, y2, z2, u2, v2, 236 x3, y3, z3, u3, v3, 237 x4, y4, z4, u4, v4); 238} 239 240static void SC_DrawQuad(float x1, float y1, float z1, 241 float x2, float y2, float z2, 242 float x3, float y3, float z3, 243 float x4, float y4, float z4) { 244 GET_TLS(); 245 rsrDrawQuad(rsc, sc, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4); 246} 247 248static void SC_DrawSpriteScreenspace(float x, float y, float z, float w, float h) { 249 GET_TLS(); 250 rsrDrawSpriteScreenspace(rsc, sc, x, y, z, w, h); 251} 252 253static void SC_DrawRect(float x1, float y1, float x2, float y2, float z) { 254 GET_TLS(); 255 rsrDrawRect(rsc, sc, x1, y1, x2, y2, z); 256} 257 258static void SC_DrawPath(Path *p) { 259 GET_TLS(); 260 //rsrDrawPath(rsc, sc, p); 261 rsdPathDraw(rsc, p); 262} 263 264static void SC_DrawMesh(Mesh *m) { 265 GET_TLS(); 266 rsrDrawMesh(rsc, sc, m); 267} 268 269static void SC_DrawMeshPrimitive(Mesh *m, uint32_t primIndex) { 270 GET_TLS(); 271 rsrDrawMeshPrimitive(rsc, sc, m, primIndex); 272} 273 274static void SC_DrawMeshPrimitiveRange(Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len) { 275 GET_TLS(); 276 rsrDrawMeshPrimitiveRange(rsc, sc, m, primIndex, start, len); 277} 278 279static void SC_MeshComputeBoundingBox(Mesh *m, 280 float *minX, float *minY, float *minZ, 281 float *maxX, float *maxY, float *maxZ) { 282 GET_TLS(); 283 rsrMeshComputeBoundingBox(rsc, sc, m, minX, minY, minZ, maxX, maxY, maxZ); 284} 285 286 287 288////////////////////////////////////////////////////////////////////////////// 289// 290////////////////////////////////////////////////////////////////////////////// 291 292 293static void SC_Color(float r, float g, float b, float a) { 294 GET_TLS(); 295 rsrColor(rsc, sc, r, g, b, a); 296} 297 298static void SC_Finish() { 299 GET_TLS(); 300 rsdGLFinish(rsc); 301} 302 303static void SC_ClearColor(float r, float g, float b, float a) { 304 GET_TLS(); 305 rsrPrepareClear(rsc, sc); 306 rsdGLClearColor(rsc, r, g, b, a); 307} 308 309static void SC_ClearDepth(float v) { 310 GET_TLS(); 311 rsrPrepareClear(rsc, sc); 312 rsdGLClearDepth(rsc, v); 313} 314 315static uint32_t SC_GetWidth() { 316 GET_TLS(); 317 return rsrGetWidth(rsc, sc); 318} 319 320static uint32_t SC_GetHeight() { 321 GET_TLS(); 322 return rsrGetHeight(rsc, sc); 323} 324 325static void SC_DrawTextAlloc(Allocation *a, int x, int y) { 326 GET_TLS(); 327 rsrDrawTextAlloc(rsc, sc, a, x, y); 328} 329 330static void SC_DrawText(const char *text, int x, int y) { 331 GET_TLS(); 332 rsrDrawText(rsc, sc, text, x, y); 333} 334 335static void SC_MeasureTextAlloc(Allocation *a, 336 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { 337 GET_TLS(); 338 rsrMeasureTextAlloc(rsc, sc, a, left, right, top, bottom); 339} 340 341static void SC_MeasureText(const char *text, 342 int32_t *left, int32_t *right, int32_t *top, int32_t *bottom) { 343 GET_TLS(); 344 rsrMeasureText(rsc, sc, text, left, right, top, bottom); 345} 346 347static void SC_BindFont(Font *f) { 348 GET_TLS(); 349 rsrBindFont(rsc, sc, f); 350} 351 352static void SC_FontColor(float r, float g, float b, float a) { 353 GET_TLS(); 354 rsrFontColor(rsc, sc, r, g, b, a); 355} 356 357 358 359////////////////////////////////////////////////////////////////////////////// 360// 361////////////////////////////////////////////////////////////////////////////// 362 363static void SC_SetObject(ObjectBase **dst, ObjectBase * src) { 364 GET_TLS(); 365 rsrSetObject(rsc, sc, dst, src); 366} 367 368static void SC_ClearObject(ObjectBase **dst) { 369 GET_TLS(); 370 rsrClearObject(rsc, sc, dst); 371} 372 373static bool SC_IsObject(const ObjectBase *src) { 374 GET_TLS(); 375 return rsrIsObject(rsc, sc, src); 376} 377 378 379 380 381static const Allocation * SC_GetAllocation(const void *ptr) { 382 GET_TLS(); 383 return rsrGetAllocation(rsc, sc, ptr); 384} 385 386static void SC_ForEach_SAA(Script *target, 387 Allocation *in, 388 Allocation *out) { 389 GET_TLS(); 390 rsrForEach(rsc, sc, target, in, out, NULL, 0, NULL); 391} 392 393static void SC_ForEach_SAAU(Script *target, 394 Allocation *in, 395 Allocation *out, 396 const void *usr) { 397 GET_TLS(); 398 rsrForEach(rsc, sc, target, in, out, usr, 0, NULL); 399} 400 401static void SC_ForEach_SAAUS(Script *target, 402 Allocation *in, 403 Allocation *out, 404 const void *usr, 405 const RsScriptCall *call) { 406 GET_TLS(); 407 rsrForEach(rsc, sc, target, in, out, usr, 0, call); 408} 409 410static void SC_ForEach_SAAUL(Script *target, 411 Allocation *in, 412 Allocation *out, 413 const void *usr, 414 uint32_t usrLen) { 415 GET_TLS(); 416 rsrForEach(rsc, sc, target, in, out, usr, usrLen, NULL); 417} 418 419static void SC_ForEach_SAAULS(Script *target, 420 Allocation *in, 421 Allocation *out, 422 const void *usr, 423 uint32_t usrLen, 424 const RsScriptCall *call) { 425 GET_TLS(); 426 rsrForEach(rsc, sc, target, in, out, usr, usrLen, call); 427} 428 429 430 431////////////////////////////////////////////////////////////////////////////// 432// Time routines 433////////////////////////////////////////////////////////////////////////////// 434 435static float SC_GetDt() { 436 GET_TLS(); 437 return rsrGetDt(rsc, sc); 438} 439 440time_t SC_Time(time_t *timer) { 441 GET_TLS(); 442 return rsrTime(rsc, sc, timer); 443} 444 445tm* SC_LocalTime(tm *local, time_t *timer) { 446 GET_TLS(); 447 return rsrLocalTime(rsc, sc, local, timer); 448} 449 450int64_t SC_UptimeMillis() { 451 GET_TLS(); 452 return rsrUptimeMillis(rsc, sc); 453} 454 455int64_t SC_UptimeNanos() { 456 GET_TLS(); 457 return rsrUptimeNanos(rsc, sc); 458} 459 460////////////////////////////////////////////////////////////////////////////// 461// Message routines 462////////////////////////////////////////////////////////////////////////////// 463 464static uint32_t SC_ToClient2(int cmdID, void *data, int len) { 465 GET_TLS(); 466 return rsrToClient(rsc, sc, cmdID, data, len); 467} 468 469static uint32_t SC_ToClient(int cmdID) { 470 GET_TLS(); 471 return rsrToClient(rsc, sc, cmdID, NULL, 0); 472} 473 474static uint32_t SC_ToClientBlocking2(int cmdID, void *data, int len) { 475 GET_TLS(); 476 return rsrToClientBlocking(rsc, sc, cmdID, data, len); 477} 478 479static uint32_t SC_ToClientBlocking(int cmdID) { 480 GET_TLS(); 481 return rsrToClientBlocking(rsc, sc, cmdID, NULL, 0); 482} 483 484int SC_divsi3(int a, int b) { 485 return a / b; 486} 487 488int SC_modsi3(int a, int b) { 489 return a % b; 490} 491 492unsigned int SC_udivsi3(unsigned int a, unsigned int b) { 493 return a / b; 494} 495 496unsigned int SC_umodsi3(unsigned int a, unsigned int b) { 497 return a % b; 498} 499 500static void SC_debugF(const char *s, float f) { 501 ALOGD("%s %f, 0x%08x", s, f, *((int *) (&f))); 502} 503static void SC_debugFv2(const char *s, float f1, float f2) { 504 ALOGD("%s {%f, %f}", s, f1, f2); 505} 506static void SC_debugFv3(const char *s, float f1, float f2, float f3) { 507 ALOGD("%s {%f, %f, %f}", s, f1, f2, f3); 508} 509static void SC_debugFv4(const char *s, float f1, float f2, float f3, float f4) { 510 ALOGD("%s {%f, %f, %f, %f}", s, f1, f2, f3, f4); 511} 512static void SC_debugF2(const char *s, float2 f) { 513 ALOGD("%s {%f, %f}", s, f.x, f.y); 514} 515static void SC_debugF3(const char *s, float3 f) { 516 ALOGD("%s {%f, %f, %f}", s, f.x, f.y, f.z); 517} 518static void SC_debugF4(const char *s, float4 f) { 519 ALOGD("%s {%f, %f, %f, %f}", s, f.x, f.y, f.z, f.w); 520} 521static void SC_debugD(const char *s, double d) { 522 ALOGD("%s %f, 0x%08llx", s, d, *((long long *) (&d))); 523} 524static void SC_debugFM4v4(const char *s, const float *f) { 525 ALOGD("%s {%f, %f, %f, %f", s, f[0], f[4], f[8], f[12]); 526 ALOGD("%s %f, %f, %f, %f", s, f[1], f[5], f[9], f[13]); 527 ALOGD("%s %f, %f, %f, %f", s, f[2], f[6], f[10], f[14]); 528 ALOGD("%s %f, %f, %f, %f}", s, f[3], f[7], f[11], f[15]); 529} 530static void SC_debugFM3v3(const char *s, const float *f) { 531 ALOGD("%s {%f, %f, %f", s, f[0], f[3], f[6]); 532 ALOGD("%s %f, %f, %f", s, f[1], f[4], f[7]); 533 ALOGD("%s %f, %f, %f}",s, f[2], f[5], f[8]); 534} 535static void SC_debugFM2v2(const char *s, const float *f) { 536 ALOGD("%s {%f, %f", s, f[0], f[2]); 537 ALOGD("%s %f, %f}",s, f[1], f[3]); 538} 539static void SC_debugI8(const char *s, char c) { 540 ALOGD("%s %hhd 0x%hhx", s, c, (unsigned char)c); 541} 542static void SC_debugC2(const char *s, char2 c) { 543 ALOGD("%s {%hhd, %hhd} 0x%hhx 0x%hhx", s, c.x, c.y, (unsigned char)c.x, (unsigned char)c.y); 544} 545static void SC_debugC3(const char *s, char3 c) { 546 ALOGD("%s {%hhd, %hhd, %hhd} 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, (unsigned char)c.x, (unsigned char)c.y, (unsigned char)c.z); 547} 548static void SC_debugC4(const char *s, char4 c) { 549 ALOGD("%s {%hhd, %hhd, %hhd, %hhd} 0x%hhx 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.w, (unsigned char)c.x, (unsigned char)c.y, (unsigned char)c.z, (unsigned char)c.w); 550} 551static void SC_debugU8(const char *s, unsigned char c) { 552 ALOGD("%s %hhu 0x%hhx", s, c, c); 553} 554static void SC_debugUC2(const char *s, uchar2 c) { 555 ALOGD("%s {%hhu, %hhu} 0x%hhx 0x%hhx", s, c.x, c.y, c.x, c.y); 556} 557static void SC_debugUC3(const char *s, uchar3 c) { 558 ALOGD("%s {%hhu, %hhu, %hhu} 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.x, c.y, c.z); 559} 560static void SC_debugUC4(const char *s, uchar4 c) { 561 ALOGD("%s {%hhu, %hhu, %hhu, %hhu} 0x%hhx 0x%hhx 0x%hhx 0x%hhx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w); 562} 563static void SC_debugI16(const char *s, short c) { 564 ALOGD("%s %hd 0x%hx", s, c, c); 565} 566static void SC_debugS2(const char *s, short2 c) { 567 ALOGD("%s {%hd, %hd} 0x%hx 0x%hx", s, c.x, c.y, c.x, c.y); 568} 569static void SC_debugS3(const char *s, short3 c) { 570 ALOGD("%s {%hd, %hd, %hd} 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.x, c.y, c.z); 571} 572static void SC_debugS4(const char *s, short4 c) { 573 ALOGD("%s {%hd, %hd, %hd, %hd} 0x%hx 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w); 574} 575static void SC_debugU16(const char *s, unsigned short c) { 576 ALOGD("%s %hu 0x%hx", s, c, c); 577} 578static void SC_debugUS2(const char *s, ushort2 c) { 579 ALOGD("%s {%hu, %hu} 0x%hx 0x%hx", s, c.x, c.y, c.x, c.y); 580} 581static void SC_debugUS3(const char *s, ushort3 c) { 582 ALOGD("%s {%hu, %hu, %hu} 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.x, c.y, c.z); 583} 584static void SC_debugUS4(const char *s, ushort4 c) { 585 ALOGD("%s {%hu, %hu, %hu, %hu} 0x%hx 0x%hx 0x%hx 0x%hx", s, c.x, c.y, c.z, c.w, c.x, c.y, c.z, c.w); 586} 587static void SC_debugI32(const char *s, int32_t i) { 588 ALOGD("%s %d 0x%x", s, i, i); 589} 590static void SC_debugI2(const char *s, int2 i) { 591 ALOGD("%s {%d, %d} 0x%x 0x%x", s, i.x, i.y, i.x, i.y); 592} 593static void SC_debugI3(const char *s, int3 i) { 594 ALOGD("%s {%d, %d, %d} 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.x, i.y, i.z); 595} 596static void SC_debugI4(const char *s, int4 i) { 597 ALOGD("%s {%d, %d, %d, %d} 0x%x 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.w, i.x, i.y, i.z, i.w); 598} 599static void SC_debugU32(const char *s, uint32_t i) { 600 ALOGD("%s %u 0x%x", s, i, i); 601} 602static void SC_debugUI2(const char *s, uint2 i) { 603 ALOGD("%s {%u, %u} 0x%x 0x%x", s, i.x, i.y, i.x, i.y); 604} 605static void SC_debugUI3(const char *s, uint3 i) { 606 ALOGD("%s {%u, %u, %u} 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.x, i.y, i.z); 607} 608static void SC_debugUI4(const char *s, uint4 i) { 609 ALOGD("%s {%u, %u, %u, %u} 0x%x 0x%x 0x%x 0x%x", s, i.x, i.y, i.z, i.w, i.x, i.y, i.z, i.w); 610} 611static void SC_debugLL64(const char *s, long long ll) { 612 ALOGD("%s %lld 0x%llx", s, ll, ll); 613} 614static void SC_debugL2(const char *s, long2 ll) { 615 ALOGD("%s {%lld, %lld} 0x%llx 0x%llx", s, ll.x, ll.y, ll.x, ll.y); 616} 617static void SC_debugL3(const char *s, long3 ll) { 618 ALOGD("%s {%lld, %lld, %lld} 0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.x, ll.y, ll.z); 619} 620static void SC_debugL4(const char *s, long4 ll) { 621 ALOGD("%s {%lld, %lld, %lld, %lld} 0x%llx 0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.w, ll.x, ll.y, ll.z, ll.w); 622} 623static void SC_debugULL64(const char *s, unsigned long long ll) { 624 ALOGD("%s %llu 0x%llx", s, ll, ll); 625} 626static void SC_debugUL2(const char *s, ulong2 ll) { 627 ALOGD("%s {%llu, %llu} 0x%llx 0x%llx", s, ll.x, ll.y, ll.x, ll.y); 628} 629static void SC_debugUL3(const char *s, ulong3 ll) { 630 ALOGD("%s {%llu, %llu, %llu} 0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.x, ll.y, ll.z); 631} 632static void SC_debugUL4(const char *s, ulong4 ll) { 633 ALOGD("%s {%llu, %llu, %llu, %llu} 0x%llx 0x%llx 0x%llx 0x%llx", s, ll.x, ll.y, ll.z, ll.w, ll.x, ll.y, ll.z, ll.w); 634} 635static void SC_debugP(const char *s, const void *p) { 636 ALOGD("%s %p", s, p); 637} 638 639 640////////////////////////////////////////////////////////////////////////////// 641// Stub implementation 642////////////////////////////////////////////////////////////////////////////// 643 644// llvm name mangling ref 645// <builtin-type> ::= v # void 646// ::= b # bool 647// ::= c # char 648// ::= a # signed char 649// ::= h # unsigned char 650// ::= s # short 651// ::= t # unsigned short 652// ::= i # int 653// ::= j # unsigned int 654// ::= l # long 655// ::= m # unsigned long 656// ::= x # long long, __int64 657// ::= y # unsigned long long, __int64 658// ::= f # float 659// ::= d # double 660 661static RsdSymbolTable gSyms[] = { 662 { "memset", (void *)&memset, true }, 663 { "memcpy", (void *)&memcpy, true }, 664 665 // Refcounting 666 { "_Z11rsSetObjectP10rs_elementS_", (void *)&SC_SetObject, true }, 667 { "_Z13rsClearObjectP10rs_element", (void *)&SC_ClearObject, true }, 668 { "_Z10rsIsObject10rs_element", (void *)&SC_IsObject, true }, 669 670 { "_Z11rsSetObjectP7rs_typeS_", (void *)&SC_SetObject, true }, 671 { "_Z13rsClearObjectP7rs_type", (void *)&SC_ClearObject, true }, 672 { "_Z10rsIsObject7rs_type", (void *)&SC_IsObject, true }, 673 674 { "_Z11rsSetObjectP13rs_allocationS_", (void *)&SC_SetObject, true }, 675 { "_Z13rsClearObjectP13rs_allocation", (void *)&SC_ClearObject, true }, 676 { "_Z10rsIsObject13rs_allocation", (void *)&SC_IsObject, true }, 677 678 { "_Z11rsSetObjectP10rs_samplerS_", (void *)&SC_SetObject, true }, 679 { "_Z13rsClearObjectP10rs_sampler", (void *)&SC_ClearObject, true }, 680 { "_Z10rsIsObject10rs_sampler", (void *)&SC_IsObject, true }, 681 682 { "_Z11rsSetObjectP9rs_scriptS_", (void *)&SC_SetObject, true }, 683 { "_Z13rsClearObjectP9rs_script", (void *)&SC_ClearObject, true }, 684 { "_Z10rsIsObject9rs_script", (void *)&SC_IsObject, true }, 685 686 { "_Z11rsSetObjectP7rs_pathS_", (void *)&SC_SetObject, true }, 687 { "_Z13rsClearObjectP7rs_path", (void *)&SC_ClearObject, true }, 688 { "_Z10rsIsObject7rs_path", (void *)&SC_IsObject, true }, 689 690 { "_Z11rsSetObjectP7rs_meshS_", (void *)&SC_SetObject, true }, 691 { "_Z13rsClearObjectP7rs_mesh", (void *)&SC_ClearObject, true }, 692 { "_Z10rsIsObject7rs_mesh", (void *)&SC_IsObject, true }, 693 694 { "_Z11rsSetObjectP19rs_program_fragmentS_", (void *)&SC_SetObject, true }, 695 { "_Z13rsClearObjectP19rs_program_fragment", (void *)&SC_ClearObject, true }, 696 { "_Z10rsIsObject19rs_program_fragment", (void *)&SC_IsObject, true }, 697 698 { "_Z11rsSetObjectP17rs_program_vertexS_", (void *)&SC_SetObject, true }, 699 { "_Z13rsClearObjectP17rs_program_vertex", (void *)&SC_ClearObject, true }, 700 { "_Z10rsIsObject17rs_program_vertex", (void *)&SC_IsObject, true }, 701 702 { "_Z11rsSetObjectP17rs_program_rasterS_", (void *)&SC_SetObject, true }, 703 { "_Z13rsClearObjectP17rs_program_raster", (void *)&SC_ClearObject, true }, 704 { "_Z10rsIsObject17rs_program_raster", (void *)&SC_IsObject, true }, 705 706 { "_Z11rsSetObjectP16rs_program_storeS_", (void *)&SC_SetObject, true }, 707 { "_Z13rsClearObjectP16rs_program_store", (void *)&SC_ClearObject, true }, 708 { "_Z10rsIsObject16rs_program_store", (void *)&SC_IsObject, true }, 709 710 { "_Z11rsSetObjectP7rs_fontS_", (void *)&SC_SetObject, true }, 711 { "_Z13rsClearObjectP7rs_font", (void *)&SC_ClearObject, true }, 712 { "_Z10rsIsObject7rs_font", (void *)&SC_IsObject, true }, 713 714 // Allocation ops 715 { "_Z21rsAllocationMarkDirty13rs_allocation", (void *)&SC_AllocationSyncAll, true }, 716 { "_Z20rsgAllocationSyncAll13rs_allocation", (void *)&SC_AllocationSyncAll, false }, 717 { "_Z20rsgAllocationSyncAll13rs_allocationj", (void *)&SC_AllocationSyncAll2, false }, 718 { "_Z20rsgAllocationSyncAll13rs_allocation24rs_allocation_usage_type", (void *)&SC_AllocationSyncAll2, false }, 719 { "_Z15rsGetAllocationPKv", (void *)&SC_GetAllocation, true }, 720 { "_Z18rsAllocationIoSend13rs_allocation", (void *)&SC_AllocationIoSend, false }, 721 { "_Z21rsAllocationIoReceive13rs_allocation", (void *)&SC_AllocationIoReceive, false }, 722 { "_Z23rsAllocationCopy1DRange13rs_allocationjjjS_jj", (void *)&SC_AllocationCopy1DRange, false }, 723 { "_Z23rsAllocationCopy2DRange13rs_allocationjjj26rs_allocation_cubemap_facejjS_jjjS0_", (void *)&SC_AllocationCopy2DRange, false }, 724 725 // Messaging 726 727 { "_Z14rsSendToClienti", (void *)&SC_ToClient, false }, 728 { "_Z14rsSendToClientiPKvj", (void *)&SC_ToClient2, false }, 729 { "_Z22rsSendToClientBlockingi", (void *)&SC_ToClientBlocking, false }, 730 { "_Z22rsSendToClientBlockingiPKvj", (void *)&SC_ToClientBlocking2, false }, 731 732 { "_Z22rsgBindProgramFragment19rs_program_fragment", (void *)&SC_BindProgramFragment, false }, 733 { "_Z19rsgBindProgramStore16rs_program_store", (void *)&SC_BindProgramStore, false }, 734 { "_Z20rsgBindProgramVertex17rs_program_vertex", (void *)&SC_BindProgramVertex, false }, 735 { "_Z20rsgBindProgramRaster17rs_program_raster", (void *)&SC_BindProgramRaster, false }, 736 { "_Z14rsgBindSampler19rs_program_fragmentj10rs_sampler", (void *)&SC_BindSampler, false }, 737 { "_Z14rsgBindTexture19rs_program_fragmentj13rs_allocation", (void *)&SC_BindTexture, false }, 738 { "_Z15rsgBindConstant19rs_program_fragmentj13rs_allocation", (void *)&SC_BindFragmentConstant, false }, 739 { "_Z15rsgBindConstant17rs_program_vertexj13rs_allocation", (void *)&SC_BindVertexConstant, false }, 740 741 { "_Z36rsgProgramVertexLoadProjectionMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadProjectionMatrix, false }, 742 { "_Z31rsgProgramVertexLoadModelMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadModelMatrix, false }, 743 { "_Z33rsgProgramVertexLoadTextureMatrixPK12rs_matrix4x4", (void *)&SC_VpLoadTextureMatrix, false }, 744 745 { "_Z35rsgProgramVertexGetProjectionMatrixP12rs_matrix4x4", (void *)&SC_VpGetProjectionMatrix, false }, 746 747 { "_Z31rsgProgramFragmentConstantColor19rs_program_fragmentffff", (void *)&SC_PfConstantColor, false }, 748 749 { "_Z11rsgGetWidthv", (void *)&SC_GetWidth, false }, 750 { "_Z12rsgGetHeightv", (void *)&SC_GetHeight, false }, 751 752 753 { "_Z11rsgDrawRectfffff", (void *)&SC_DrawRect, false }, 754 { "_Z11rsgDrawQuadffffffffffff", (void *)&SC_DrawQuad, false }, 755 { "_Z20rsgDrawQuadTexCoordsffffffffffffffffffff", (void *)&SC_DrawQuadTexCoords, false }, 756 { "_Z24rsgDrawSpriteScreenspacefffff", (void *)&SC_DrawSpriteScreenspace, false }, 757 758 { "_Z11rsgDrawMesh7rs_mesh", (void *)&SC_DrawMesh, false }, 759 { "_Z11rsgDrawMesh7rs_meshj", (void *)&SC_DrawMeshPrimitive, false }, 760 { "_Z11rsgDrawMesh7rs_meshjjj", (void *)&SC_DrawMeshPrimitiveRange, false }, 761 { "_Z25rsgMeshComputeBoundingBox7rs_meshPfS0_S0_S0_S0_S0_", (void *)&SC_MeshComputeBoundingBox, false }, 762 763 { "_Z11rsgDrawPath7rs_path", (void *)&SC_DrawPath, false }, 764 765 { "_Z13rsgClearColorffff", (void *)&SC_ClearColor, false }, 766 { "_Z13rsgClearDepthf", (void *)&SC_ClearDepth, false }, 767 768 { "_Z11rsgDrawTextPKcii", (void *)&SC_DrawText, false }, 769 { "_Z11rsgDrawText13rs_allocationii", (void *)&SC_DrawTextAlloc, false }, 770 { "_Z14rsgMeasureTextPKcPiS1_S1_S1_", (void *)&SC_MeasureText, false }, 771 { "_Z14rsgMeasureText13rs_allocationPiS0_S0_S0_", (void *)&SC_MeasureTextAlloc, false }, 772 773 { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false }, 774 { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false }, 775 776 { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_BindFrameBufferObjectColorTarget, false }, 777 { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_BindFrameBufferObjectDepthTarget, false }, 778 { "_Z19rsgClearColorTargetj", (void *)&SC_ClearFrameBufferObjectColorTarget, false }, 779 { "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false }, 780 { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false }, 781 782 { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, true }, 783 { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, true }, 784 { "_Z9rsForEach9rs_script13rs_allocationS0_PKvPK16rs_script_call_t", (void *)&SC_ForEach_SAAUS, true }, 785 { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach_SAAUL, true }, 786 { "_Z9rsForEach9rs_script13rs_allocationS0_PKvjPK16rs_script_call_t", (void *)&SC_ForEach_SAAULS, true }, 787 788 // time 789 { "_Z6rsTimePi", (void *)&SC_Time, true }, 790 { "_Z11rsLocaltimeP5rs_tmPKi", (void *)&SC_LocalTime, true }, 791 { "_Z14rsUptimeMillisv", (void*)&SC_UptimeMillis, true }, 792 { "_Z13rsUptimeNanosv", (void*)&SC_UptimeNanos, true }, 793 { "_Z7rsGetDtv", (void*)&SC_GetDt, false }, 794 795 // misc 796 { "_Z5colorffff", (void *)&SC_Color, false }, 797 { "_Z9rsgFinishv", (void *)&SC_Finish, false }, 798 799 // Debug 800 { "_Z7rsDebugPKcf", (void *)&SC_debugF, true }, 801 { "_Z7rsDebugPKcff", (void *)&SC_debugFv2, true }, 802 { "_Z7rsDebugPKcfff", (void *)&SC_debugFv3, true }, 803 { "_Z7rsDebugPKcffff", (void *)&SC_debugFv4, true }, 804 { "_Z7rsDebugPKcDv2_f", (void *)&SC_debugF2, true }, 805 { "_Z7rsDebugPKcDv3_f", (void *)&SC_debugF3, true }, 806 { "_Z7rsDebugPKcDv4_f", (void *)&SC_debugF4, true }, 807 { "_Z7rsDebugPKcd", (void *)&SC_debugD, true }, 808 { "_Z7rsDebugPKcPK12rs_matrix4x4", (void *)&SC_debugFM4v4, true }, 809 { "_Z7rsDebugPKcPK12rs_matrix3x3", (void *)&SC_debugFM3v3, true }, 810 { "_Z7rsDebugPKcPK12rs_matrix2x2", (void *)&SC_debugFM2v2, true }, 811 { "_Z7rsDebugPKcc", (void *)&SC_debugI8, true }, 812 { "_Z7rsDebugPKcDv2_c", (void *)&SC_debugC2, true }, 813 { "_Z7rsDebugPKcDv3_c", (void *)&SC_debugC3, true }, 814 { "_Z7rsDebugPKcDv4_c", (void *)&SC_debugC4, true }, 815 { "_Z7rsDebugPKch", (void *)&SC_debugU8, true }, 816 { "_Z7rsDebugPKcDv2_h", (void *)&SC_debugUC2, true }, 817 { "_Z7rsDebugPKcDv3_h", (void *)&SC_debugUC3, true }, 818 { "_Z7rsDebugPKcDv4_h", (void *)&SC_debugUC4, true }, 819 { "_Z7rsDebugPKcs", (void *)&SC_debugI16, true }, 820 { "_Z7rsDebugPKcDv2_s", (void *)&SC_debugS2, true }, 821 { "_Z7rsDebugPKcDv3_s", (void *)&SC_debugS3, true }, 822 { "_Z7rsDebugPKcDv4_s", (void *)&SC_debugS4, true }, 823 { "_Z7rsDebugPKct", (void *)&SC_debugU16, true }, 824 { "_Z7rsDebugPKcDv2_t", (void *)&SC_debugUS2, true }, 825 { "_Z7rsDebugPKcDv3_t", (void *)&SC_debugUS3, true }, 826 { "_Z7rsDebugPKcDv4_t", (void *)&SC_debugUS4, true }, 827 { "_Z7rsDebugPKci", (void *)&SC_debugI32, true }, 828 { "_Z7rsDebugPKcDv2_i", (void *)&SC_debugI2, true }, 829 { "_Z7rsDebugPKcDv3_i", (void *)&SC_debugI3, true }, 830 { "_Z7rsDebugPKcDv4_i", (void *)&SC_debugI4, true }, 831 { "_Z7rsDebugPKcj", (void *)&SC_debugU32, true }, 832 { "_Z7rsDebugPKcDv2_j", (void *)&SC_debugUI2, true }, 833 { "_Z7rsDebugPKcDv3_j", (void *)&SC_debugUI3, true }, 834 { "_Z7rsDebugPKcDv4_j", (void *)&SC_debugUI4, true }, 835 // Both "long" and "unsigned long" need to be redirected to their 836 // 64-bit counterparts, since we have hacked Slang to use 64-bit 837 // for "long" on Arm (to be similar to Java). 838 { "_Z7rsDebugPKcl", (void *)&SC_debugLL64, true }, 839 { "_Z7rsDebugPKcDv2_l", (void *)&SC_debugL2, true }, 840 { "_Z7rsDebugPKcDv3_l", (void *)&SC_debugL3, true }, 841 { "_Z7rsDebugPKcDv4_l", (void *)&SC_debugL4, true }, 842 { "_Z7rsDebugPKcm", (void *)&SC_debugULL64, true }, 843 { "_Z7rsDebugPKcDv2_m", (void *)&SC_debugUL2, true }, 844 { "_Z7rsDebugPKcDv3_m", (void *)&SC_debugUL3, true }, 845 { "_Z7rsDebugPKcDv4_m", (void *)&SC_debugUL4, true }, 846 { "_Z7rsDebugPKcx", (void *)&SC_debugLL64, true }, 847 { "_Z7rsDebugPKcDv2_x", (void *)&SC_debugL2, true }, 848 { "_Z7rsDebugPKcDv3_x", (void *)&SC_debugL3, true }, 849 { "_Z7rsDebugPKcDv4_x", (void *)&SC_debugL4, true }, 850 { "_Z7rsDebugPKcy", (void *)&SC_debugULL64, true }, 851 { "_Z7rsDebugPKcDv2_y", (void *)&SC_debugUL2, true }, 852 { "_Z7rsDebugPKcDv3_y", (void *)&SC_debugUL3, true }, 853 { "_Z7rsDebugPKcDv4_y", (void *)&SC_debugUL4, true }, 854 { "_Z7rsDebugPKcPKv", (void *)&SC_debugP, true }, 855 856 { NULL, NULL, false } 857}; 858 859 860void* rsdLookupRuntimeStub(void* pContext, char const* name) { 861 ScriptC *s = (ScriptC *)pContext; 862 RsdSymbolTable *syms = gSyms; 863 const RsdSymbolTable *sym = rsdLookupSymbolMath(name); 864 865 if (!sym) { 866 while (syms->mPtr) { 867 if (!strcmp(syms->mName, name)) { 868 sym = syms; 869 } 870 syms++; 871 } 872 } 873 874 if (sym) { 875 s->mHal.info.isThreadable &= sym->threadable; 876 return sym->mPtr; 877 } 878 ALOGE("ScriptC sym lookup failed for %s", name); 879 return NULL; 880} 881 882 883