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