Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "rsContext.h" |
| 18 | #include "rsScriptC.h" |
| 19 | #include "rsMatrix.h" |
Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 20 | #include "utils/Timers.h" |
Alex Sakhartchouk | b26fb04 | 2010-09-24 15:18:12 -0700 | [diff] [blame] | 21 | #include "utils/StopWatch.h" |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 22 | extern "C" { |
| 23 | #include "libdex/ZipArchive.h" |
| 24 | } |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 25 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 26 | #include <GLES/gl.h> |
| 27 | #include <GLES/glext.h> |
| 28 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 32 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 33 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 34 | Context * rsc = tls->mContext; \ |
| 35 | ScriptC * sc = (ScriptC *) tls->mScript |
| 36 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 37 | // Input: cacheDir |
| 38 | // Input: resName |
| 39 | // Input: extName |
| 40 | // |
| 41 | // Note: cacheFile = resName + extName |
| 42 | // |
| 43 | // Output: Returns cachePath == cacheDir + cacheFile |
| 44 | char *genCacheFileName(const char *cacheDir, |
| 45 | const char *resName, |
| 46 | const char *extName) { |
| 47 | char cachePath[512]; |
| 48 | char cacheFile[sizeof(cachePath)]; |
| 49 | const size_t kBufLen = sizeof(cachePath) - 1; |
| 50 | |
| 51 | cacheFile[0] = '\0'; |
| 52 | // Note: resName today is usually something like |
| 53 | // "/com.android.fountain:raw/fountain" |
| 54 | if (resName[0] != '/') { |
| 55 | // Get the absolute path of the raw/***.bc file. |
| 56 | |
| 57 | // Generate the absolute path. This doesn't do everything it |
| 58 | // should, e.g. if resName is "./out/whatever" it doesn't crunch |
| 59 | // the leading "./" out because this if-block is not triggered, |
| 60 | // but it'll make do. |
| 61 | // |
| 62 | if (getcwd(cacheFile, kBufLen) == NULL) { |
| 63 | LOGE("Can't get CWD while opening raw/***.bc file\n"); |
| 64 | return NULL; |
| 65 | } |
| 66 | // Append "/" at the end of cacheFile so far. |
| 67 | strncat(cacheFile, "/", kBufLen); |
| 68 | } |
| 69 | |
| 70 | // cacheFile = resName + extName |
| 71 | // |
| 72 | strncat(cacheFile, resName, kBufLen); |
| 73 | if (extName != NULL) { |
| 74 | // TODO(srhines): strncat() is a bit dangerous |
| 75 | strncat(cacheFile, extName, kBufLen); |
| 76 | } |
| 77 | |
| 78 | // Turn the path into a flat filename by replacing |
| 79 | // any slashes after the first one with '@' characters. |
| 80 | char *cp = cacheFile + 1; |
| 81 | while (*cp != '\0') { |
| 82 | if (*cp == '/') { |
| 83 | *cp = '@'; |
| 84 | } |
| 85 | cp++; |
| 86 | } |
| 87 | |
| 88 | // Tack on the file name for the actual cache file path. |
| 89 | strncpy(cachePath, cacheDir, kBufLen); |
| 90 | strncat(cachePath, cacheFile, kBufLen); |
| 91 | |
| 92 | LOGV("Cache file for '%s' '%s' is '%s'\n", resName, extName, cachePath); |
| 93 | return strdup(cachePath); |
| 94 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 95 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 96 | ScriptC::ScriptC(Context *rsc) : Script(rsc) { |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 97 | mBccScript = NULL; |
Jason Sams | efb8de1 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 98 | memset(&mProgram, 0, sizeof(mProgram)); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 101 | ScriptC::~ScriptC() { |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 102 | if (mBccScript) { |
Jason Sams | 2e8665d | 2011-01-27 00:14:13 -0800 | [diff] [blame^] | 103 | if (mProgram.mObjectSlotList) { |
| 104 | for (size_t ct=0; ct < mProgram.mObjectSlotCount; ct++) { |
| 105 | setVarObj(mProgram.mObjectSlotList[ct], NULL); |
| 106 | } |
| 107 | delete [] mProgram.mObjectSlotList; |
| 108 | mProgram.mObjectSlotList = NULL; |
| 109 | mProgram.mObjectSlotCount = 0; |
| 110 | } |
| 111 | |
| 112 | |
| 113 | LOGD(">>>> ~ScriptC bccDisposeScript(%p)", mBccScript); |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 114 | bccDisposeScript(mBccScript); |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 115 | } |
Jason Sams | e402ed3 | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 116 | free(mEnviroment.mScriptText); |
| 117 | mEnviroment.mScriptText = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 120 | void ScriptC::setupScript(Context *rsc) { |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 121 | mEnviroment.mStartTimeMillis |
| 122 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 123 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 124 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 125 | if (mSlots[ct].get() && !mTypes[ct].get()) { |
| 126 | mTypes[ct].set(mSlots[ct]->getType()); |
| 127 | } |
| 128 | |
| 129 | if (!mTypes[ct].get()) |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 130 | continue; |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 131 | void *ptr = NULL; |
| 132 | if (mSlots[ct].get()) { |
| 133 | ptr = mSlots[ct]->getPtr(); |
| 134 | } |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 135 | void **dest = ((void ***)mEnviroment.mFieldAddress)[ct]; |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 136 | |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 137 | if (rsc->props.mLogScripts) { |
Jason Sams | 2fad7e4 | 2010-11-16 12:19:26 -0800 | [diff] [blame] | 138 | if (mSlots[ct].get() != NULL) { |
| 139 | LOGV("%p ScriptC::setupScript slot=%i dst=%p src=%p type=%p", rsc, ct, dest, ptr, mSlots[ct]->getType()); |
| 140 | } else { |
| 141 | LOGV("%p ScriptC::setupScript slot=%i dst=%p src=%p type=null", rsc, ct, dest, ptr); |
| 142 | } |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 143 | } |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 144 | |
| 145 | if (dest) { |
| 146 | *dest = ptr; |
Jason Sams | ada7f27 | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 151 | const Allocation *ScriptC::ptrToAllocation(const void *ptr) const { |
Jason Sams | ce92d4b | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 152 | if (!ptr) { |
| 153 | return NULL; |
| 154 | } |
| 155 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
| 156 | if (!mSlots[ct].get()) |
| 157 | continue; |
| 158 | if (mSlots[ct]->getPtr() == ptr) { |
| 159 | return mSlots[ct].get(); |
| 160 | } |
| 161 | } |
| 162 | LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr); |
| 163 | return NULL; |
| 164 | } |
| 165 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 166 | Script * ScriptC::setTLS(Script *sc) { |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 167 | Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *) |
| 168 | pthread_getspecific(Context::gThreadTLSKey); |
| 169 | rsAssert(tls); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 170 | Script *old = tls->mScript; |
| 171 | tls->mScript = sc; |
| 172 | return old; |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 175 | void ScriptC::setupGLState(Context *rsc) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 176 | if (mEnviroment.mFragmentStore.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 177 | rsc->setProgramStore(mEnviroment.mFragmentStore.get()); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 178 | } |
| 179 | if (mEnviroment.mFragment.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 180 | rsc->setProgramFragment(mEnviroment.mFragment.get()); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 181 | } |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 182 | if (mEnviroment.mVertex.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 183 | rsc->setProgramVertex(mEnviroment.mVertex.get()); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 184 | } |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 185 | if (mEnviroment.mRaster.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 186 | rsc->setProgramRaster(mEnviroment.mRaster.get()); |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 187 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 188 | } |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 189 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 190 | uint32_t ScriptC::run(Context *rsc) { |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 191 | if (mProgram.mRoot == NULL) { |
| 192 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); |
| 193 | return 0; |
Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 194 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 195 | |
Jason Sams | 1f24db4 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 196 | setupGLState(rsc); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 197 | setupScript(rsc); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 198 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 199 | uint32_t ret = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 200 | Script * oldTLS = setTLS(this); |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 201 | |
| 202 | if (rsc->props.mLogScripts) { |
| 203 | LOGV("%p ScriptC::run invoking root, ptr %p", rsc, mProgram.mRoot); |
| 204 | } |
| 205 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 206 | ret = mProgram.mRoot(); |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 207 | |
| 208 | if (rsc->props.mLogScripts) { |
| 209 | LOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret); |
| 210 | } |
| 211 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 212 | setTLS(oldTLS); |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 213 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 216 | typedef struct { |
| 217 | Context *rsc; |
| 218 | ScriptC *script; |
| 219 | const Allocation * ain; |
| 220 | Allocation * aout; |
| 221 | const void * usr; |
| 222 | |
| 223 | uint32_t mSliceSize; |
| 224 | volatile int mSliceNum; |
| 225 | |
| 226 | const uint8_t *ptrIn; |
| 227 | uint32_t eStrideIn; |
| 228 | uint8_t *ptrOut; |
| 229 | uint32_t eStrideOut; |
| 230 | |
| 231 | uint32_t xStart; |
| 232 | uint32_t xEnd; |
| 233 | uint32_t yStart; |
| 234 | uint32_t yEnd; |
| 235 | uint32_t zStart; |
| 236 | uint32_t zEnd; |
| 237 | uint32_t arrayStart; |
| 238 | uint32_t arrayEnd; |
| 239 | |
| 240 | uint32_t dimX; |
| 241 | uint32_t dimY; |
| 242 | uint32_t dimZ; |
| 243 | uint32_t dimArray; |
| 244 | } MTLaunchStruct; |
| 245 | typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t); |
| 246 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 247 | static void wc_xy(void *usr, uint32_t idx) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 248 | MTLaunchStruct *mtls = (MTLaunchStruct *)usr; |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 249 | |
| 250 | while (1) { |
| 251 | uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); |
| 252 | uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize; |
| 253 | uint32_t yEnd = yStart + mtls->mSliceSize; |
| 254 | yEnd = rsMin(yEnd, mtls->yEnd); |
| 255 | if (yEnd <= yStart) { |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd); |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 260 | //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 261 | for (uint32_t y = yStart; y < yEnd; y++) { |
| 262 | uint32_t offset = mtls->dimX * y; |
| 263 | uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset); |
| 264 | const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset); |
| 265 | |
| 266 | for (uint32_t x = mtls->xStart; x < mtls->xEnd; x++) { |
| 267 | ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0); |
| 268 | xPtrIn += mtls->eStrideIn; |
| 269 | xPtrOut += mtls->eStrideOut; |
| 270 | } |
| 271 | } |
| 272 | } |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 275 | static void wc_x(void *usr, uint32_t idx) { |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 276 | MTLaunchStruct *mtls = (MTLaunchStruct *)usr; |
| 277 | |
| 278 | while (1) { |
| 279 | uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); |
| 280 | uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize; |
| 281 | uint32_t xEnd = xStart + mtls->mSliceSize; |
| 282 | xEnd = rsMin(xEnd, mtls->xEnd); |
| 283 | if (xEnd <= xStart) { |
| 284 | return; |
| 285 | } |
| 286 | |
| 287 | //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd); |
| 288 | //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); |
| 289 | uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * xStart); |
| 290 | const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * xStart); |
| 291 | for (uint32_t x = xStart; x < xEnd; x++) { |
| 292 | ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, 0, 0, 0); |
| 293 | xPtrIn += mtls->eStrideIn; |
| 294 | xPtrOut += mtls->eStrideOut; |
| 295 | } |
| 296 | } |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 299 | void ScriptC::runForEach(Context *rsc, |
| 300 | const Allocation * ain, |
| 301 | Allocation * aout, |
| 302 | const void * usr, |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 303 | const RsScriptCall *sc) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 304 | MTLaunchStruct mtls; |
| 305 | memset(&mtls, 0, sizeof(mtls)); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 306 | Context::PushState ps(rsc); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 307 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 308 | if (ain) { |
| 309 | mtls.dimX = ain->getType()->getDimX(); |
| 310 | mtls.dimY = ain->getType()->getDimY(); |
| 311 | mtls.dimZ = ain->getType()->getDimZ(); |
| 312 | //mtls.dimArray = ain->getType()->getDimArray(); |
| 313 | } else if (aout) { |
| 314 | mtls.dimX = aout->getType()->getDimX(); |
| 315 | mtls.dimY = aout->getType()->getDimY(); |
| 316 | mtls.dimZ = aout->getType()->getDimZ(); |
| 317 | //mtls.dimArray = aout->getType()->getDimArray(); |
| 318 | } else { |
| 319 | rsc->setError(RS_ERROR_BAD_SCRIPT, "rsForEach called with null allocations"); |
| 320 | return; |
| 321 | } |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 322 | |
| 323 | if (!sc || (sc->xEnd == 0)) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 324 | mtls.xEnd = mtls.dimX; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 325 | } else { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 326 | rsAssert(sc->xStart < mtls.dimX); |
| 327 | rsAssert(sc->xEnd <= mtls.dimX); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 328 | rsAssert(sc->xStart < sc->xEnd); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 329 | mtls.xStart = rsMin(mtls.dimX, sc->xStart); |
| 330 | mtls.xEnd = rsMin(mtls.dimX, sc->xEnd); |
| 331 | if (mtls.xStart >= mtls.xEnd) return; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | if (!sc || (sc->yEnd == 0)) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 335 | mtls.yEnd = mtls.dimY; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 336 | } else { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 337 | rsAssert(sc->yStart < mtls.dimY); |
| 338 | rsAssert(sc->yEnd <= mtls.dimY); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 339 | rsAssert(sc->yStart < sc->yEnd); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 340 | mtls.yStart = rsMin(mtls.dimY, sc->yStart); |
| 341 | mtls.yEnd = rsMin(mtls.dimY, sc->yEnd); |
| 342 | if (mtls.yStart >= mtls.yEnd) return; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 345 | mtls.xEnd = rsMax((uint32_t)1, mtls.xEnd); |
| 346 | mtls.yEnd = rsMax((uint32_t)1, mtls.yEnd); |
| 347 | mtls.zEnd = rsMax((uint32_t)1, mtls.zEnd); |
| 348 | mtls.arrayEnd = rsMax((uint32_t)1, mtls.arrayEnd); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 349 | |
| 350 | rsAssert(ain->getType()->getDimZ() == 0); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 351 | |
Jason Sams | 1f24db4 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 352 | setupGLState(rsc); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 353 | setupScript(rsc); |
| 354 | Script * oldTLS = setTLS(this); |
| 355 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 356 | mtls.rsc = rsc; |
| 357 | mtls.ain = ain; |
| 358 | mtls.aout = aout; |
| 359 | mtls.script = this; |
| 360 | mtls.usr = usr; |
| 361 | mtls.mSliceSize = 10; |
| 362 | mtls.mSliceNum = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 363 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 364 | mtls.ptrIn = NULL; |
| 365 | mtls.eStrideIn = 0; |
| 366 | if (ain) { |
| 367 | mtls.ptrIn = (const uint8_t *)ain->getPtr(); |
| 368 | mtls.eStrideIn = ain->getType()->getElementSizeBytes(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 371 | mtls.ptrOut = NULL; |
| 372 | mtls.eStrideOut = 0; |
| 373 | if (aout) { |
| 374 | mtls.ptrOut = (uint8_t *)aout->getPtr(); |
| 375 | mtls.eStrideOut = aout->getType()->getElementSizeBytes(); |
| 376 | } |
| 377 | |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 378 | if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable) { |
| 379 | if (mtls.dimY > 1) { |
| 380 | rsc->launchThreads(wc_xy, &mtls); |
| 381 | } else { |
| 382 | rsc->launchThreads(wc_x, &mtls); |
| 383 | } |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 384 | |
| 385 | //LOGE("launch 1"); |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 386 | } else { |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 387 | //LOGE("launch 3"); |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 388 | for (uint32_t ar = mtls.arrayStart; ar < mtls.arrayEnd; ar++) { |
| 389 | for (uint32_t z = mtls.zStart; z < mtls.zEnd; z++) { |
| 390 | for (uint32_t y = mtls.yStart; y < mtls.yEnd; y++) { |
| 391 | uint32_t offset = mtls.dimX * mtls.dimY * mtls.dimZ * ar + |
| 392 | mtls.dimX * mtls.dimY * z + |
| 393 | mtls.dimX * y; |
| 394 | uint8_t *xPtrOut = mtls.ptrOut + (mtls.eStrideOut * offset); |
| 395 | const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 396 | |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 397 | for (uint32_t x = mtls.xStart; x < mtls.xEnd; x++) { |
| 398 | ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar); |
| 399 | xPtrIn += mtls.eStrideIn; |
| 400 | xPtrOut += mtls.eStrideOut; |
| 401 | } |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 405 | } |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 406 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 407 | setTLS(oldTLS); |
| 408 | } |
| 409 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 410 | void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) { |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 411 | if ((slot >= mEnviroment.mInvokeFunctionCount) || |
| 412 | (mEnviroment.mInvokeFunctions[slot] == NULL)) { |
| 413 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); |
| 414 | return; |
| 415 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 416 | setupScript(rsc); |
| 417 | Script * oldTLS = setTLS(this); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 418 | |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 419 | if (rsc->props.mLogScripts) { |
| 420 | LOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, mEnviroment.mInvokeFunctions[slot]); |
| 421 | } |
Jason Sams | 2a63bf6 | 2010-06-08 15:40:48 -0700 | [diff] [blame] | 422 | ((void (*)(const void *, uint32_t)) |
| 423 | mEnviroment.mInvokeFunctions[slot])(data, len); |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 424 | if (rsc->props.mLogScripts) { |
| 425 | LOGV("%p ScriptC::Invoke complete", rsc); |
| 426 | } |
Jason Sams | 2a63bf6 | 2010-06-08 15:40:48 -0700 | [diff] [blame] | 427 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 428 | setTLS(oldTLS); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 431 | ScriptCState::ScriptCState() { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 434 | ScriptCState::~ScriptCState() { |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 437 | static void* symbolLookup(void* pContext, char const* name) { |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 438 | const ScriptCState::SymbolTable_t *sym; |
Jason Sams | dd663fa | 2010-08-11 13:26:28 -0700 | [diff] [blame] | 439 | ScriptC *s = (ScriptC *)pContext; |
Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 440 | if (!strcmp(name, "__isThreadable")) { |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 441 | return (void*) s->mEnviroment.mIsThreadable; |
Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 442 | } else if (!strcmp(name, "__clearThreadable")) { |
| 443 | s->mEnviroment.mIsThreadable = false; |
| 444 | return NULL; |
| 445 | } |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 446 | sym = ScriptCState::lookupSymbol(name); |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 447 | if (!sym) { |
| 448 | sym = ScriptCState::lookupSymbolCL(name); |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 449 | } |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 450 | if (!sym) { |
| 451 | sym = ScriptCState::lookupSymbolGL(name); |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 452 | } |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 453 | if (sym) { |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 454 | s->mEnviroment.mIsThreadable &= sym->threadable; |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 455 | return sym->mPtr; |
| 456 | } |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 457 | LOGE("ScriptC sym lookup failed for %s", name); |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 458 | return NULL; |
| 459 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 460 | |
Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 461 | #if 0 |
Shih-wei Liao | 1f9ba73 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 462 | extern const char rs_runtime_lib_bc[]; |
| 463 | extern unsigned rs_runtime_lib_bc_size; |
Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 464 | #endif |
Shih-wei Liao | 1f9ba73 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 465 | |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 466 | bool ScriptCState::runCompiler(Context *rsc, |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 467 | ScriptC *s, |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 468 | const char *resName, |
| 469 | const char *cacheDir) { |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 470 | s->mBccScript = bccCreateScript(); |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 471 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 472 | s->mEnviroment.mIsThreadable = true; |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 473 | |
Shih-wei Liao | fa6113e | 2011-01-20 12:35:44 -0800 | [diff] [blame] | 474 | if (bccRegisterSymbolCallback(s->mBccScript, symbolLookup, s) != 0) { |
| 475 | LOGE("bcc: FAILS to register symbol callback"); |
| 476 | return false; |
| 477 | } |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 478 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 479 | if (bccReadBC(s->mBccScript, |
| 480 | resName, |
| 481 | s->mEnviroment.mScriptText, |
| 482 | s->mEnviroment.mScriptTextLength, 0) != 0) { |
| 483 | LOGE("bcc: FAILS to read bitcode"); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 484 | return false; |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 485 | } |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 486 | |
Shih-wei Liao | 5439184 | 2011-01-19 02:18:45 -0800 | [diff] [blame] | 487 | #if 1 |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 488 | if (bccLinkBC(s->mBccScript, |
| 489 | resName, |
| 490 | NULL /*rs_runtime_lib_bc*/, |
| 491 | 1 /*rs_runtime_lib_bc_size*/ |
| 492 | /*"1" means skip buffer here, and let libbcc decide*/, |
| 493 | 0) != 0) { |
| 494 | LOGE("bcc: FAILS to link bitcode"); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 495 | return false; |
Alex Sakhartchouk | b26fb04 | 2010-09-24 15:18:12 -0700 | [diff] [blame] | 496 | } |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 497 | #endif |
| 498 | char *cachePath = genCacheFileName(cacheDir, resName, ".oBCC"); |
| 499 | |
| 500 | if (bccPrepareExecutable(s->mBccScript, cachePath, 0) != 0) { |
| 501 | LOGE("bcc: FAILS to prepare executable"); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 502 | return false; |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | free(cachePath); |
| 506 | |
| 507 | s->mProgram.mRoot = reinterpret_cast<int (*)()>(bccGetFuncAddr(s->mBccScript, "root")); |
| 508 | s->mProgram.mInit = reinterpret_cast<void (*)()>(bccGetFuncAddr(s->mBccScript, "init")); |
Jason Sams | f168504 | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 509 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 510 | if (s->mProgram.mInit) { |
| 511 | s->mProgram.mInit(); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 514 | s->mEnviroment.mInvokeFunctionCount = bccGetExportFuncCount(s->mBccScript); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 515 | if (s->mEnviroment.mInvokeFunctionCount <= 0) |
Jason Sams | 8c88090 | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 516 | s->mEnviroment.mInvokeFunctions = NULL; |
| 517 | else { |
| 518 | s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t)); |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 519 | bccGetExportFuncList(s->mBccScript, s->mEnviroment.mInvokeFunctionCount, (void **) s->mEnviroment.mInvokeFunctions); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 522 | s->mEnviroment.mFieldCount = bccGetExportVarCount(s->mBccScript); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 523 | if (s->mEnviroment.mFieldCount <= 0) |
Shih-wei Liao | a226b16 | 2010-07-20 16:43:25 -0700 | [diff] [blame] | 524 | s->mEnviroment.mFieldAddress = NULL; |
| 525 | else { |
| 526 | s->mEnviroment.mFieldAddress = (void **) calloc(s->mEnviroment.mFieldCount, sizeof(void *)); |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 527 | bccGetExportVarList(s->mBccScript, s->mEnviroment.mFieldCount, (void **) s->mEnviroment.mFieldAddress); |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 528 | s->initSlots(); |
Shih-wei Liao | a226b16 | 2010-07-20 16:43:25 -0700 | [diff] [blame] | 529 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 530 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 531 | s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 532 | s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 533 | s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 534 | s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 535 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 536 | const static int pragmaMax = 16; |
| 537 | size_t pragmaCount = bccGetPragmaCount(s->mBccScript); |
| 538 | char const *keys[pragmaMax]; |
| 539 | char const *values[pragmaMax]; |
| 540 | bccGetPragmaList(s->mBccScript, pragmaMax, keys, values); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 541 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 542 | for (size_t i=0; i < pragmaCount; ++i) { |
| 543 | //LOGE("pragma %s %s", keys[i], values[i]); |
| 544 | if (!strcmp(keys[i], "version")) { |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 545 | if (!strcmp(values[i], "1")) { |
| 546 | continue; |
| 547 | } |
| 548 | LOGE("Invalid version pragma value: %s\n", values[i]); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 549 | return false; |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | if (!strcmp(keys[i], "stateVertex")) { |
| 553 | if (!strcmp(values[i], "default")) { |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 554 | continue; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 555 | } |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 556 | if (!strcmp(values[i], "parent")) { |
| 557 | s->mEnviroment.mVertex.clear(); |
| 558 | continue; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 559 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 560 | LOGE("Unrecognized value %s passed to stateVertex", values[i]); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 561 | return false; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 562 | } |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 563 | |
| 564 | if (!strcmp(keys[i], "stateRaster")) { |
| 565 | if (!strcmp(values[i], "default")) { |
| 566 | continue; |
| 567 | } |
| 568 | if (!strcmp(values[i], "parent")) { |
| 569 | s->mEnviroment.mRaster.clear(); |
| 570 | continue; |
| 571 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 572 | LOGE("Unrecognized value %s passed to stateRaster", values[i]); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 573 | return false; |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | if (!strcmp(keys[i], "stateFragment")) { |
| 577 | if (!strcmp(values[i], "default")) { |
| 578 | continue; |
| 579 | } |
| 580 | if (!strcmp(values[i], "parent")) { |
| 581 | s->mEnviroment.mFragment.clear(); |
| 582 | continue; |
| 583 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 584 | LOGE("Unrecognized value %s passed to stateFragment", values[i]); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 585 | return false; |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | if (!strcmp(keys[i], "stateStore")) { |
| 589 | if (!strcmp(values[i], "default")) { |
| 590 | continue; |
| 591 | } |
| 592 | if (!strcmp(values[i], "parent")) { |
| 593 | s->mEnviroment.mFragmentStore.clear(); |
| 594 | continue; |
| 595 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 596 | LOGE("Unrecognized value %s passed to stateStore", values[i]); |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 597 | return false; |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 598 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 599 | } |
Jason Sams | 2e8665d | 2011-01-27 00:14:13 -0800 | [diff] [blame^] | 600 | |
| 601 | size_t objectSlotCount = bccGetObjectSlotCount(s->mBccScript); |
| 602 | uint32_t *objectSlots = NULL; |
| 603 | if (objectSlotCount) { |
| 604 | objectSlots = new uint32_t[objectSlotCount]; |
| 605 | bccGetObjectSlotList(s->mBccScript, objectSlotCount, objectSlots); |
| 606 | s->mProgram.mObjectSlotList = objectSlots; |
| 607 | s->mProgram.mObjectSlotCount = objectSlotCount; |
| 608 | } |
| 609 | |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 610 | return true; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | namespace android { |
| 614 | namespace renderscript { |
| 615 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 616 | void rsi_ScriptCBegin(Context * rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 619 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) { |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 620 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | e402ed3 | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 621 | |
| 622 | char *t = (char *)malloc(len + 1); |
| 623 | memcpy(t, text, len); |
| 624 | t[len] = 0; |
Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 625 | ss->mScriptText = t; |
| 626 | ss->mScriptLen = len; |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 629 | |
| 630 | RsScript rsi_ScriptCCreate(Context *rsc, |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 631 | const char *packageName /* deprecated */, |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 632 | const char *resName, |
| 633 | const char *cacheDir) |
Shih-wei Liao | 9503b66 | 2010-11-08 01:33:59 -0800 | [diff] [blame] | 634 | { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 635 | ScriptCState *ss = &rsc->mScriptC; |
| 636 | |
Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 637 | ScriptC *s = new ScriptC(rsc); |
| 638 | s->mEnviroment.mScriptText = ss->mScriptText; |
| 639 | s->mEnviroment.mScriptTextLength = ss->mScriptLen; |
| 640 | ss->mScriptText = NULL; |
| 641 | ss->mScriptLen = 0; |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 642 | s->incUserRef(); |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 643 | |
Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 644 | if (!ss->runCompiler(rsc, s, resName, cacheDir)) { |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 645 | // Error during compile, destroy s and return null. |
Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 646 | delete s; |
Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 647 | return NULL; |
| 648 | } |
Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 649 | return s; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 652 | } |
| 653 | } |