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