| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 2 | * Copyright (C) 2009-2012 The Android Open Source Project |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 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" |
| Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 19 | |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 20 | #ifndef FAKE_ARM64_BUILD |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 21 | #ifndef RS_COMPATIBILITY_LIB |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 22 | #ifndef ANDROID_RS_SERIALIZE |
| 23 | #include <bcinfo/BitcodeTranslator.h> |
| Stephen Hines | f8d4469 | 2011-11-22 19:43:58 -0800 | [diff] [blame] | 24 | #include <bcinfo/BitcodeWrapper.h> |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 25 | #endif |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 26 | #endif |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 27 | #endif |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 28 | |
| Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 29 | #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) |
| Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 30 | #include "utils/Timers.h" |
| Tobias Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 31 | #include "cutils/trace.h" |
| Stephen Hines | 574854b | 2013-07-10 08:29:51 -0700 | [diff] [blame] | 32 | #endif |
| Tobias Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 33 | |
| Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 34 | #include <sys/stat.h> |
| 35 | |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 36 | using namespace android; |
| 37 | using namespace android::renderscript; |
| 38 | |
| Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 39 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 40 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 41 | Context * rsc = tls->mContext; \ |
| 42 | ScriptC * sc = (ScriptC *) tls->mScript |
| 43 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 44 | ScriptC::ScriptC(Context *rsc) : Script(rsc) { |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 45 | #ifndef FAKE_ARM64_BUILD |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 46 | #ifndef RS_COMPATIBILITY_LIB |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 47 | #ifndef ANDROID_RS_SERIALIZE |
| 48 | BT = NULL; |
| 49 | #endif |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 50 | #endif |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 51 | #endif |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 54 | ScriptC::~ScriptC() { |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 55 | #ifndef FAKE_ARM64_BUILD |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 56 | #ifndef RS_COMPATIBILITY_LIB |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 57 | #ifndef ANDROID_RS_SERIALIZE |
| 58 | if (BT) { |
| 59 | delete BT; |
| 60 | BT = NULL; |
| 61 | } |
| 62 | #endif |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 63 | #endif |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 64 | #endif |
| Jason Sams | 77020c5 | 2011-11-22 12:49:11 -0800 | [diff] [blame] | 65 | if (mInitialized) { |
| 66 | mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this); |
| 67 | mRSC->mHal.funcs.script.destroy(mRSC, this); |
| 68 | } |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 71 | #ifndef FAKE_ARM64_BUILD |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 72 | #ifndef RS_COMPATIBILITY_LIB |
| Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 73 | bool ScriptC::createCacheDir(const char *cacheDir) { |
| 74 | String8 cacheDirString, currentDir; |
| 75 | struct stat statBuf; |
| 76 | int statReturn = stat(cacheDir, &statBuf); |
| 77 | if (!statReturn) { |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | // String8 path functions strip leading /'s |
| 82 | // insert if necessary |
| 83 | if (cacheDir[0] == '/') { |
| 84 | currentDir += "/"; |
| 85 | } |
| 86 | |
| 87 | cacheDirString.setPathName(cacheDir); |
| 88 | |
| 89 | while (cacheDirString.length()) { |
| 90 | currentDir += (cacheDirString.walkPath(&cacheDirString)); |
| 91 | statReturn = stat(currentDir.string(), &statBuf); |
| 92 | if (statReturn) { |
| 93 | if (errno == ENOENT) { |
| 94 | if (mkdir(currentDir.string(), S_IRUSR | S_IWUSR | S_IXUSR)) { |
| 95 | ALOGE("Couldn't create cache directory: %s", |
| 96 | currentDir.string()); |
| 97 | ALOGE("Error: %s", strerror(errno)); |
| 98 | return false; |
| 99 | } |
| 100 | } else { |
| 101 | ALOGE("Stat error: %s", strerror(errno)); |
| 102 | return false; |
| 103 | } |
| 104 | } |
| 105 | currentDir += "/"; |
| 106 | } |
| 107 | return true; |
| 108 | } |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 109 | #endif |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 110 | #endif |
| Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 111 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 112 | void ScriptC::setupScript(Context *rsc) { |
| Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 113 | #ifndef RS_SERVER |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 114 | mEnviroment.mStartTimeMillis |
| 115 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 116 | #endif |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 117 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 118 | for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) { |
| Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 119 | if (mSlots[ct].get() && !mTypes[ct].get()) { |
| 120 | mTypes[ct].set(mSlots[ct]->getType()); |
| 121 | } |
| 122 | |
| 123 | if (!mTypes[ct].get()) |
| Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 124 | continue; |
| Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 125 | rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, mSlots[ct].get()); |
| Jason Sams | ada7f27 | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 129 | void ScriptC::setupGLState(Context *rsc) { |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 130 | #ifndef RS_COMPATIBILITY_LIB |
| Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 131 | if (mEnviroment.mFragmentStore.get()) { |
| Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 132 | rsc->setProgramStore(mEnviroment.mFragmentStore.get()); |
| Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 133 | } |
| 134 | if (mEnviroment.mFragment.get()) { |
| Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 135 | rsc->setProgramFragment(mEnviroment.mFragment.get()); |
| Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 136 | } |
| Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 137 | if (mEnviroment.mVertex.get()) { |
| Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 138 | rsc->setProgramVertex(mEnviroment.mVertex.get()); |
| Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 139 | } |
| Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 140 | if (mEnviroment.mRaster.get()) { |
| Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 141 | rsc->setProgramRaster(mEnviroment.mRaster.get()); |
| Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 142 | } |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 143 | #endif |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 144 | } |
| Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 145 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 146 | uint32_t ScriptC::run(Context *rsc) { |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 147 | if (mHal.info.root == NULL) { |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 148 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); |
| 149 | return 0; |
| Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 150 | } |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 151 | |
| Jason Sams | 1f24db4 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 152 | setupGLState(rsc); |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 153 | setupScript(rsc); |
| Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 154 | |
| Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 155 | uint32_t ret = 0; |
| Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 156 | |
| 157 | if (rsc->props.mLogScripts) { |
| Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 158 | ALOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root); |
| Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 161 | ret = rsc->mHal.funcs.script.invokeRoot(rsc, this); |
| Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 162 | |
| 163 | if (rsc->props.mLogScripts) { |
| Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 164 | ALOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret); |
| Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 167 | return ret; |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 170 | |
| Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 171 | void ScriptC::runForEach(Context *rsc, |
| Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 172 | uint32_t slot, |
| Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 173 | const Allocation * ain, |
| 174 | Allocation * aout, |
| 175 | const void * usr, |
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 176 | size_t usrBytes, |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 177 | const RsScriptCall *sc) { |
| Tobias Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 178 | // Trace this function call. |
| 179 | // To avoid overhead, we only build the string, if tracing is actually |
| 180 | // enabled. |
| 181 | String8 *AString = NULL; |
| 182 | const char *String = ""; |
| 183 | if (ATRACE_ENABLED()) { |
| 184 | AString = new String8("runForEach_"); |
| 185 | AString->append(mHal.info.exportedForeachFuncList[slot].first); |
| 186 | String = AString->string(); |
| 187 | } |
| 188 | ATRACE_NAME(String); |
| 189 | (void)String; |
| Tim Murray | fa85e91 | 2013-05-23 13:19:36 -0700 | [diff] [blame] | 190 | |
| Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 191 | Context::PushState ps(rsc); |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 192 | |
| Jason Sams | 1f24db4 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 193 | setupGLState(rsc); |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 194 | setupScript(rsc); |
| Stephen Hines | 4419977 | 2012-02-21 20:13:12 -0800 | [diff] [blame] | 195 | rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ain, aout, usr, usrBytes, sc); |
| Tobias Grosser | 47935ac | 2013-06-17 11:47:26 -0700 | [diff] [blame] | 196 | |
| 197 | if (AString) |
| 198 | delete AString; |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 201 | void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) { |
| Tim Murray | fa85e91 | 2013-05-23 13:19:36 -0700 | [diff] [blame] | 202 | ATRACE_CALL(); |
| 203 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 204 | if (slot >= mHal.info.exportedFunctionCount) { |
| Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 205 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); |
| 206 | return; |
| 207 | } |
| Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 208 | setupScript(rsc); |
| Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 209 | |
| Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 210 | if (rsc->props.mLogScripts) { |
| Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 211 | ALOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this); |
| Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 212 | } |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 213 | rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len); |
| Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 216 | ScriptCState::ScriptCState() { |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 217 | } |
| 218 | |
| Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 219 | ScriptCState::~ScriptCState() { |
| Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 222 | /* |
| Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 223 | static void* symbolLookup(void* pContext, char const* name) { |
| Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 224 | const ScriptCState::SymbolTable_t *sym; |
| Jason Sams | dd663fa | 2010-08-11 13:26:28 -0700 | [diff] [blame] | 225 | ScriptC *s = (ScriptC *)pContext; |
| Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 226 | if (!strcmp(name, "__isThreadable")) { |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 227 | return (void*) s->mHal.info.isThreadable; |
| Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 228 | } else if (!strcmp(name, "__clearThreadable")) { |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 229 | s->mHal.info.isThreadable = false; |
| Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 230 | return NULL; |
| 231 | } |
| Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 232 | sym = ScriptCState::lookupSymbol(name); |
| Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 233 | if (!sym) { |
| 234 | sym = ScriptCState::lookupSymbolCL(name); |
| Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 235 | } |
| Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 236 | if (!sym) { |
| 237 | sym = ScriptCState::lookupSymbolGL(name); |
| Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 238 | } |
| Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 239 | if (sym) { |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 240 | s->mHal.info.isThreadable &= sym->threadable; |
| Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 241 | return sym->mPtr; |
| 242 | } |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 243 | ALOGE("ScriptC sym lookup failed for %s", name); |
| Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 244 | return NULL; |
| 245 | } |
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 246 | */ |
| Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 247 | |
| Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 248 | #if 0 |
| Shih-wei Liao | 1f9ba73 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 249 | extern const char rs_runtime_lib_bc[]; |
| 250 | extern unsigned rs_runtime_lib_bc_size; |
| Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 251 | #endif |
| Shih-wei Liao | 1f9ba73 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 252 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 253 | bool ScriptC::runCompiler(Context *rsc, |
| 254 | const char *resName, |
| 255 | const char *cacheDir, |
| 256 | const uint8_t *bitcode, |
| 257 | size_t bitcodeLen) { |
| Tim Murray | fa85e91 | 2013-05-23 13:19:36 -0700 | [diff] [blame] | 258 | ATRACE_CALL(); |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 259 | //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen); |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 260 | #ifndef FAKE_ARM64_BUILD |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 261 | #ifndef RS_COMPATIBILITY_LIB |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 262 | #ifndef ANDROID_RS_SERIALIZE |
| Stephen Hines | f8d4469 | 2011-11-22 19:43:58 -0800 | [diff] [blame] | 263 | uint32_t sdkVersion = 0; |
| 264 | bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen); |
| 265 | if (!bcWrapper.unwrap()) { |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 266 | ALOGE("Bitcode is not in proper container format (raw or wrapper)"); |
| Stephen Hines | f8d4469 | 2011-11-22 19:43:58 -0800 | [diff] [blame] | 267 | return false; |
| 268 | } |
| 269 | |
| Stephen Hines | f8d4469 | 2011-11-22 19:43:58 -0800 | [diff] [blame] | 270 | if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) { |
| 271 | sdkVersion = bcWrapper.getTargetAPI(); |
| 272 | } |
| 273 | |
| 274 | if (sdkVersion == 0) { |
| 275 | // This signals that we didn't have a wrapper containing information |
| 276 | // about the bitcode. |
| 277 | sdkVersion = rsc->getTargetSdkVersion(); |
| 278 | } |
| 279 | |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 280 | if (BT) { |
| 281 | delete BT; |
| 282 | } |
| 283 | BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen, |
| 284 | sdkVersion); |
| 285 | if (!BT->translate()) { |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 286 | ALOGE("Failed to translate bitcode from version: %u", sdkVersion); |
| Stephen Hines | cbb0b8a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 287 | delete BT; |
| 288 | BT = NULL; |
| 289 | return false; |
| 290 | } |
| 291 | bitcode = (const uint8_t *) BT->getTranslatedBitcode(); |
| 292 | bitcodeLen = BT->getTranslatedBitcodeSize(); |
| Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 293 | |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 294 | #endif |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 295 | if (!cacheDir) { |
| 296 | // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED |
| 297 | cacheDir = getenv("EXTERNAL_STORAGE"); |
| 298 | ALOGV("Cache dir changed to %s", cacheDir); |
| 299 | } |
| 300 | |
| Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 301 | // ensure that cache dir exists |
| Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 302 | if (cacheDir && !createCacheDir(cacheDir)) { |
| Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 303 | return false; |
| 304 | } |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 305 | #endif |
| Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 306 | #endif |
| Tim Murray | e78c14b | 2012-10-01 15:27:18 -0700 | [diff] [blame] | 307 | |
| Jason Sams | 77020c5 | 2011-11-22 12:49:11 -0800 | [diff] [blame] | 308 | if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) { |
| 309 | return false; |
| 310 | } |
| Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 311 | |
| Jason Sams | 77020c5 | 2011-11-22 12:49:11 -0800 | [diff] [blame] | 312 | mInitialized = true; |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 313 | #ifndef RS_COMPATIBILITY_LIB |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 314 | mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 315 | mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
| 316 | mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); |
| 317 | mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 318 | #endif |
| Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 319 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 320 | rsc->mHal.funcs.script.invokeInit(rsc, this); |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 321 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 322 | for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) { |
| 323 | const char * key = mHal.info.exportedPragmaKeyList[i]; |
| 324 | const char * value = mHal.info.exportedPragmaValueList[i]; |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 325 | //ALOGE("pragma %s %s", keys[i], values[i]); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 326 | if (!strcmp(key, "version")) { |
| 327 | if (!strcmp(value, "1")) { |
| Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 328 | continue; |
| 329 | } |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 330 | ALOGE("Invalid version pragma value: %s\n", value); |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 331 | return false; |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 334 | #ifndef RS_COMPATIBILITY_LIB |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 335 | if (!strcmp(key, "stateVertex")) { |
| 336 | if (!strcmp(value, "default")) { |
| Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 337 | continue; |
| Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 338 | } |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 339 | if (!strcmp(value, "parent")) { |
| 340 | mEnviroment.mVertex.clear(); |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 341 | continue; |
| Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 342 | } |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 343 | ALOGE("Unrecognized value %s passed to stateVertex", value); |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 344 | return false; |
| Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 345 | } |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 346 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 347 | if (!strcmp(key, "stateRaster")) { |
| 348 | if (!strcmp(value, "default")) { |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 349 | continue; |
| 350 | } |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 351 | if (!strcmp(value, "parent")) { |
| 352 | mEnviroment.mRaster.clear(); |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 353 | continue; |
| 354 | } |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 355 | ALOGE("Unrecognized value %s passed to stateRaster", value); |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 356 | return false; |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 359 | if (!strcmp(key, "stateFragment")) { |
| 360 | if (!strcmp(value, "default")) { |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 361 | continue; |
| 362 | } |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 363 | if (!strcmp(value, "parent")) { |
| 364 | mEnviroment.mFragment.clear(); |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 365 | continue; |
| 366 | } |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 367 | ALOGE("Unrecognized value %s passed to stateFragment", value); |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 368 | return false; |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 369 | } |
| 370 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 371 | if (!strcmp(key, "stateStore")) { |
| 372 | if (!strcmp(value, "default")) { |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 373 | continue; |
| 374 | } |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 375 | if (!strcmp(value, "parent")) { |
| 376 | mEnviroment.mFragmentStore.clear(); |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 377 | continue; |
| 378 | } |
| Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 379 | ALOGE("Unrecognized value %s passed to stateStore", value); |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 380 | return false; |
| Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 381 | } |
| Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 382 | #endif |
| 383 | |
| Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 384 | } |
| Jason Sams | 2e8665d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 385 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 386 | mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount]; |
| 387 | mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount]; |
| Jason Sams | 2e8665d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 388 | |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 389 | return true; |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | namespace android { |
| 393 | namespace renderscript { |
| 394 | |
| Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 395 | RsScript rsi_ScriptCCreate(Context *rsc, |
| Alex Sakhartchouk | 70b83c1 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 396 | const char *resName, size_t resName_length, |
| 397 | const char *cacheDir, size_t cacheDir_length, |
| Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 398 | const char *text, size_t text_length) |
| Shih-wei Liao | 9503b66 | 2010-11-08 01:33:59 -0800 | [diff] [blame] | 399 | { |
| Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 400 | ScriptC *s = new ScriptC(rsc); |
| Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 401 | |
| Alex Sakhartchouk | 70b83c1 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 402 | if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) { |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 403 | // Error during compile, destroy s and return null. |
| Stephen Hines | 4769d68 | 2012-02-02 13:23:20 -0800 | [diff] [blame] | 404 | ObjectBase::checkDelete(s); |
| Jason Sams | 26b2c9f | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 405 | return NULL; |
| 406 | } |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 407 | |
| 408 | s->incUserRef(); |
| Jason Sams | 249d453 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 409 | return s; |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 412 | } |
| 413 | } |