| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011-2012 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 |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 7 | * |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 17 | #include "rsCpuCore.h" |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 18 | #include "rsCpuScript.h" |
| Yang Ni | 2abfcc6 | 2015-02-17 16:05:19 -0800 | [diff] [blame] | 19 | #include "rsCpuExecutable.h" |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 20 | |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 21 | #ifdef RS_COMPATIBILITY_LIB |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 22 | #include <stdio.h> |
| Stephen Hines | ee48c0b | 2013-10-30 17:48:30 -0700 | [diff] [blame] | 23 | #include <sys/stat.h> |
| Stephen Hines | c2c11cc | 2013-07-19 01:07:42 -0700 | [diff] [blame] | 24 | #include <unistd.h> |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 25 | #else |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 26 | #include "rsCppUtils.h" |
| 27 | |
| Stephen Hines | 82e0a67 | 2014-05-05 15:40:56 -0700 | [diff] [blame] | 28 | #include <bcc/Config/Config.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 29 | #include <bcinfo/MetadataExtractor.h> |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 30 | #include <cutils/properties.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 31 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 32 | #include <zlib.h> |
| 33 | #include <sys/file.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 34 | #include <sys/types.h> |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 35 | #include <unistd.h> |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 36 | |
| 37 | #include <string> |
| 38 | #include <vector> |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 39 | #endif |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 40 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 41 | #include <set> |
| 42 | #include <string> |
| 43 | #include <dlfcn.h> |
| 44 | #include <stdlib.h> |
| 45 | #include <string.h> |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 46 | #include <iostream> |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 47 | #include <sstream> |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 48 | |
| 49 | #ifdef __LP64__ |
| 50 | #define SYSLIBPATH "/system/lib64" |
| 51 | #else |
| 52 | #define SYSLIBPATH "/system/lib" |
| 53 | #endif |
| 54 | |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 55 | namespace { |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 56 | |
| 57 | static const bool kDebugGlobalVariables = false; |
| 58 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 59 | #ifndef RS_COMPATIBILITY_LIB |
| 60 | |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 61 | static bool is_force_recompile() { |
| 62 | #ifdef RS_SERVER |
| 63 | return false; |
| 64 | #else |
| 65 | char buf[PROPERTY_VALUE_MAX]; |
| 66 | |
| 67 | // Re-compile if floating point precision has been overridden. |
| 68 | property_get("debug.rs.precision", buf, ""); |
| 69 | if (buf[0] != '\0') { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | // Re-compile if debug.rs.forcerecompile is set. |
| 74 | property_get("debug.rs.forcerecompile", buf, "0"); |
| 75 | if ((::strcmp(buf, "1") == 0) || (::strcmp(buf, "true") == 0)) { |
| 76 | return true; |
| 77 | } else { |
| 78 | return false; |
| 79 | } |
| 80 | #endif // RS_SERVER |
| 81 | } |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 82 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 83 | static void setCompileArguments(std::vector<const char*>* args, |
| 84 | const std::string& bcFileName, |
| 85 | const char* cacheDir, const char* resName, |
| 86 | const char* core_lib, bool useRSDebugContext, |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 87 | const char* bccPluginName, bool emitGlobalInfo, |
| 88 | bool emitGlobalInfoSkipConstant) { |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 89 | rsAssert(cacheDir && resName && core_lib); |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 90 | args->push_back(android::renderscript::RsdCpuScriptImpl::BCC_EXE_PATH); |
| Tim Murray | 687cfe8 | 2015-01-08 14:59:38 -0800 | [diff] [blame] | 91 | args->push_back("-unroll-runtime"); |
| 92 | args->push_back("-scalarize-load-store"); |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 93 | if (emitGlobalInfo) { |
| 94 | args->push_back("-rs-global-info"); |
| 95 | if (emitGlobalInfoSkipConstant) { |
| 96 | args->push_back("-rs-global-info-skip-constant"); |
| 97 | } |
| 98 | } |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 99 | args->push_back("-o"); |
| 100 | args->push_back(resName); |
| 101 | args->push_back("-output_path"); |
| 102 | args->push_back(cacheDir); |
| 103 | args->push_back("-bclib"); |
| 104 | args->push_back(core_lib); |
| 105 | args->push_back("-mtriple"); |
| 106 | args->push_back(DEFAULT_TARGET_TRIPLE_STRING); |
| 107 | |
| Tim Murray | 358ffb8 | 2014-12-09 11:53:06 -0800 | [diff] [blame] | 108 | // Enable workaround for A53 codegen by default. |
| 109 | #if defined(__aarch64__) && !defined(DISABLE_A53_WORKAROUND) |
| 110 | args->push_back("-aarch64-fix-cortex-a53-835769"); |
| 111 | #endif |
| 112 | |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 113 | // Execute the bcc compiler. |
| 114 | if (useRSDebugContext) { |
| 115 | args->push_back("-rs-debug-ctx"); |
| 116 | } else { |
| 117 | // Only load additional libraries for compiles that don't use |
| 118 | // the debug context. |
| 119 | if (bccPluginName && strlen(bccPluginName) > 0) { |
| 120 | args->push_back("-load"); |
| 121 | args->push_back(bccPluginName); |
| 122 | } |
| 123 | } |
| 124 | |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 125 | args->push_back("-fPIC"); |
| 126 | args->push_back("-embedRSInfo"); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 127 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 128 | args->push_back(bcFileName.c_str()); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 129 | args->push_back(nullptr); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 132 | static bool compileBitcode(const std::string &bcFileName, |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 133 | const char *bitcode, |
| 134 | size_t bitcodeSize, |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 135 | std::vector<const char *> &compileArguments) { |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 136 | rsAssert(bitcode && bitcodeSize); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 137 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 138 | FILE *bcfile = fopen(bcFileName.c_str(), "w"); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 139 | if (!bcfile) { |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 140 | ALOGE("Could not write to %s", bcFileName.c_str()); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 141 | return false; |
| 142 | } |
| 143 | size_t nwritten = fwrite(bitcode, 1, bitcodeSize, bcfile); |
| 144 | fclose(bcfile); |
| 145 | if (nwritten != bitcodeSize) { |
| 146 | ALOGE("Could not write %zu bytes to %s", bitcodeSize, |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 147 | bcFileName.c_str()); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 148 | return false; |
| 149 | } |
| 150 | |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 151 | return android::renderscript::rsuExecuteCommand( |
| 152 | android::renderscript::RsdCpuScriptImpl::BCC_EXE_PATH, |
| 153 | compileArguments.size()-1, compileArguments.data()); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 154 | } |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 155 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 156 | bool isChecksumNeeded() { |
| 157 | char buf[PROPERTY_VALUE_MAX]; |
| 158 | property_get("ro.debuggable", buf, ""); |
| 159 | return (buf[0] == '1'); |
| 160 | } |
| 161 | |
| 162 | bool addFileToChecksum(const char *fileName, uint32_t &checksum) { |
| 163 | int FD = open(fileName, O_RDONLY); |
| 164 | if (FD == -1) { |
| 165 | ALOGE("Cannot open file \'%s\' to compute checksum", fileName); |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | char buf[256]; |
| 170 | while (true) { |
| 171 | ssize_t nread = read(FD, buf, sizeof(buf)); |
| 172 | if (nread < 0) { // bail out on failed read |
| 173 | ALOGE("Error while computing checksum for file \'%s\'", fileName); |
| 174 | return false; |
| 175 | } |
| 176 | |
| 177 | checksum = adler32(checksum, (const unsigned char *) buf, nread); |
| 178 | if (static_cast<size_t>(nread) < sizeof(buf)) // EOF |
| 179 | break; |
| 180 | } |
| 181 | |
| Elliott Hughes | 2df5767 | 2015-05-15 17:06:47 -0700 | [diff] [blame] | 182 | if (close(FD) != 0) { |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 183 | ALOGE("Cannot close file \'%s\' after computing checksum", fileName); |
| 184 | return false; |
| 185 | } |
| 186 | return true; |
| 187 | } |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 188 | |
| 189 | #endif // !defined(RS_COMPATIBILITY_LIB) |
| 190 | } // namespace |
| 191 | |
| 192 | namespace android { |
| 193 | namespace renderscript { |
| 194 | |
| 195 | #ifndef RS_COMPATIBILITY_LIB |
| 196 | |
| 197 | uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize, |
| 198 | const char *commandLine, |
| 199 | const char** bccFiles, size_t numFiles) { |
| 200 | uint32_t checksum = adler32(0L, Z_NULL, 0); |
| 201 | |
| 202 | // include checksum of bitcode |
| 203 | if (bitcode != nullptr && bitcodeSize > 0) { |
| 204 | checksum = adler32(checksum, bitcode, bitcodeSize); |
| 205 | } |
| 206 | |
| 207 | // include checksum of command line arguments |
| 208 | checksum = adler32(checksum, (const unsigned char *) commandLine, |
| 209 | strlen(commandLine)); |
| 210 | |
| 211 | // include checksum of bccFiles |
| 212 | for (size_t i = 0; i < numFiles; i++) { |
| 213 | const char* bccFile = bccFiles[i]; |
| 214 | if (bccFile[0] != 0 && !addFileToChecksum(bccFile, checksum)) { |
| 215 | // return empty checksum instead of something partial/corrupt |
| 216 | return 0; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | return checksum; |
| 221 | } |
| 222 | |
| Yang Ni | f02a2b0 | 2015-04-07 16:00:31 -0700 | [diff] [blame] | 223 | #endif // !RS_COMPATIBILITY_LIB |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 224 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 225 | RsdCpuScriptImpl::RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s) { |
| 226 | mCtx = ctx; |
| 227 | mScript = s; |
| 228 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 229 | mScriptSO = nullptr; |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 230 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 231 | mRoot = nullptr; |
| 232 | mRootExpand = nullptr; |
| 233 | mInit = nullptr; |
| 234 | mFreeChildren = nullptr; |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 235 | mScriptExec = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 236 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 237 | mBoundAllocs = nullptr; |
| 238 | mIntrinsicData = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 239 | mIsThreadable = true; |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 240 | |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 241 | mBuildChecksum = 0; |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 242 | mChecksumNeeded = false; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 245 | bool RsdCpuScriptImpl::storeRSInfoFromSO() { |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 246 | // The shared object may have an invalid build checksum. |
| 247 | // Validate and fail early. |
| 248 | mScriptExec = ScriptExecutable::createFromSharedObject( |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 249 | mCtx->getContext(), mScriptSO, |
| 250 | mChecksumNeeded ? mBuildChecksum : 0); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 251 | |
| 252 | if (mScriptExec == nullptr) { |
| 253 | return false; |
| 254 | } |
| 255 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 256 | mRoot = (RootFunc_t) dlsym(mScriptSO, "root"); |
| 257 | if (mRoot) { |
| 258 | //ALOGE("Found root(): %p", mRoot); |
| 259 | } |
| 260 | mRootExpand = (RootFunc_t) dlsym(mScriptSO, "root.expand"); |
| 261 | if (mRootExpand) { |
| 262 | //ALOGE("Found root.expand(): %p", mRootExpand); |
| 263 | } |
| 264 | mInit = (InvokeFunc_t) dlsym(mScriptSO, "init"); |
| 265 | if (mInit) { |
| 266 | //ALOGE("Found init(): %p", mInit); |
| 267 | } |
| 268 | mFreeChildren = (InvokeFunc_t) dlsym(mScriptSO, ".rs.dtor"); |
| 269 | if (mFreeChildren) { |
| 270 | //ALOGE("Found .rs.dtor(): %p", mFreeChildren); |
| 271 | } |
| 272 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 273 | size_t varCount = mScriptExec->getExportedVariableCount(); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 274 | if (varCount > 0) { |
| 275 | mBoundAllocs = new Allocation *[varCount]; |
| 276 | memset(mBoundAllocs, 0, varCount * sizeof(*mBoundAllocs)); |
| 277 | } |
| 278 | |
| Pirama Arumuga Nainar | 68173de | 2015-01-28 12:12:36 -0800 | [diff] [blame] | 279 | mIsThreadable = mScriptExec->getThreadable(); |
| 280 | //ALOGE("Script isThreadable? %d", mIsThreadable); |
| 281 | |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 282 | if (kDebugGlobalVariables) { |
| 283 | mScriptExec->dumpGlobalInfo(); |
| 284 | } |
| 285 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 286 | return true; |
| 287 | } |
| 288 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 289 | bool RsdCpuScriptImpl::init(char const *resName, char const *cacheDir, |
| 290 | uint8_t const *bitcode, size_t bitcodeSize, |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 291 | uint32_t flags, char const *bccPluginName) { |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 292 | //ALOGE("rsdScriptCreate %p %p %p %p %i %i %p", rsc, resName, cacheDir, |
| 293 | // bitcode, bitcodeSize, flags, lookupFunc); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 294 | //ALOGE("rsdScriptInit %p %p", rsc, script); |
| 295 | |
| 296 | mCtx->lockMutex(); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 297 | #ifndef RS_COMPATIBILITY_LIB |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 298 | bool useRSDebugContext = false; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 299 | |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 300 | bcinfo::MetadataExtractor bitcodeMetadata((const char *) bitcode, bitcodeSize); |
| 301 | if (!bitcodeMetadata.extract()) { |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 302 | ALOGE("Could not extract metadata from bitcode"); |
| Stephen Hines | f94e8db | 2014-06-26 11:55:29 -0700 | [diff] [blame] | 303 | mCtx->unlockMutex(); |
| Stephen Hines | b58d9ad | 2013-06-19 19:26:19 -0700 | [diff] [blame] | 304 | return false; |
| 305 | } |
| 306 | |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 307 | const char* core_lib = findCoreLib(bitcodeMetadata, (const char*)bitcode, bitcodeSize); |
| Stephen Hines | cca3d6c | 2013-04-15 01:06:39 -0700 | [diff] [blame] | 308 | |
| 309 | if (mCtx->getContext()->getContextType() == RS_CONTEXT_TYPE_DEBUG) { |
| Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 310 | useRSDebugContext = true; |
| Stephen Hines | cca3d6c | 2013-04-15 01:06:39 -0700 | [diff] [blame] | 311 | } |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 312 | |
| Chris Wailes | 6847e73 | 2014-08-11 17:30:51 -0700 | [diff] [blame] | 313 | std::string bcFileName(cacheDir); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 314 | bcFileName.append("/"); |
| 315 | bcFileName.append(resName); |
| 316 | bcFileName.append(".bc"); |
| 317 | |
| 318 | std::vector<const char*> compileArguments; |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 319 | bool emitGlobalInfo = mCtx->getEmbedGlobalInfo(); |
| 320 | bool emitGlobalInfoSkipConstant = mCtx->getEmbedGlobalInfoSkipConstant(); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 321 | setCompileArguments(&compileArguments, bcFileName, cacheDir, resName, core_lib, |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 322 | useRSDebugContext, bccPluginName, emitGlobalInfo, |
| 323 | emitGlobalInfoSkipConstant); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 324 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 325 | mChecksumNeeded = isChecksumNeeded(); |
| 326 | if (mChecksumNeeded) { |
| 327 | std::vector<const char *> bccFiles = { BCC_EXE_PATH, |
| 328 | core_lib, |
| 329 | }; |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 330 | |
| 331 | // The last argument of compileArguments is a nullptr, so remove 1 from |
| 332 | // the size. |
| 333 | std::unique_ptr<const char> compileCommandLine( |
| 334 | rsuJoinStrings(compileArguments.size()-1, compileArguments.data())); |
| 335 | |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 336 | mBuildChecksum = constructBuildChecksum(bitcode, bitcodeSize, |
| 337 | compileCommandLine.get(), |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 338 | bccFiles.data(), bccFiles.size()); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 339 | |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 340 | if (mBuildChecksum == 0) { |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 341 | // cannot compute checksum but verification is enabled |
| 342 | mCtx->unlockMutex(); |
| 343 | return false; |
| 344 | } |
| 345 | } |
| 346 | else { |
| 347 | // add a dummy/constant as a checksum if verification is disabled |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 348 | mBuildChecksum = 0xabadcafe; |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | // Append build checksum to commandline |
| 352 | // Handle the terminal nullptr in compileArguments |
| 353 | compileArguments.pop_back(); |
| 354 | compileArguments.push_back("-build-checksum"); |
| Yang Ni | cb17015 | 2015-04-16 10:27:02 -0700 | [diff] [blame] | 355 | std::stringstream ss; |
| 356 | ss << std::hex << mBuildChecksum; |
| 357 | compileArguments.push_back(ss.str().c_str()); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 358 | compileArguments.push_back(nullptr); |
| 359 | |
| Tim Murray | bf96a52 | 2015-01-23 15:37:03 -0800 | [diff] [blame] | 360 | if (!is_force_recompile() && !useRSDebugContext) { |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 361 | mScriptSO = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName); |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 362 | |
| 363 | // Read RS info from the shared object to detect checksum mismatch |
| 364 | if (mScriptSO != nullptr && !storeRSInfoFromSO()) { |
| 365 | dlclose(mScriptSO); |
| 366 | mScriptSO = nullptr; |
| 367 | } |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | // If we can't, it's either not there or out of date. We compile the bit code and try loading |
| 371 | // again. |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 372 | if (mScriptSO == nullptr) { |
| 373 | if (!compileBitcode(bcFileName, (const char*)bitcode, bitcodeSize, |
| Pirama Arumuga Nainar | 2fa8a23 | 2015-03-25 17:21:40 -0700 | [diff] [blame] | 374 | compileArguments)) |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 375 | { |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 376 | ALOGE("bcc: FAILS to compile '%s'", resName); |
| 377 | mCtx->unlockMutex(); |
| 378 | return false; |
| 379 | } |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 380 | |
| Stephen Hines | 4c368af | 2015-05-06 00:43:02 -0700 | [diff] [blame] | 381 | if (!SharedLibraryUtils::createSharedLibrary(mCtx->getContext()->getDriverName(), |
| 382 | cacheDir, resName)) { |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 383 | ALOGE("Linker: Failed to link object file '%s'", resName); |
| 384 | mCtx->unlockMutex(); |
| 385 | return false; |
| 386 | } |
| 387 | |
| Yang Ni | 1c44cb6 | 2015-01-22 12:02:27 -0800 | [diff] [blame] | 388 | mScriptSO = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName); |
| Stephen Hines | 45e753a | 2015-01-19 20:58:44 -0800 | [diff] [blame] | 389 | if (mScriptSO == nullptr) { |
| 390 | ALOGE("Unable to load '%s'", resName); |
| Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 391 | mCtx->unlockMutex(); |
| 392 | return false; |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 393 | } |
| Pirama Arumuga Nainar | aa6757f | 2015-02-13 20:02:50 -0800 | [diff] [blame] | 394 | |
| 395 | // Read RS symbol information from the .so. |
| 396 | if (!storeRSInfoFromSO()) { |
| 397 | goto error; |
| 398 | } |
| Stephen Hines | ba17ae4 | 2013-06-05 17:18:04 -0700 | [diff] [blame] | 399 | } |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 400 | |
| Yang Ni | c31585b | 2015-02-15 11:43:50 -0800 | [diff] [blame] | 401 | mBitcodeFilePath.setTo(bcFileName.c_str()); |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 402 | |
| Jean-Luc Brouillet | f4d216e | 2014-06-09 18:04:16 -0700 | [diff] [blame] | 403 | #else // RS_COMPATIBILITY_LIB is defined |
| Miao Wang | f3213d7 | 2015-01-14 10:03:07 -0800 | [diff] [blame] | 404 | const char *nativeLibDir = mCtx->getContext()->getNativeLibDir(); |
| 405 | mScriptSO = SharedLibraryUtils::loadSharedLibrary(cacheDir, resName, nativeLibDir); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 406 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 407 | if (!mScriptSO) { |
| 408 | goto error; |
| 409 | } |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 410 | |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 411 | if (!storeRSInfoFromSO()) { |
| Stephen Hines | c2c11cc | 2013-07-19 01:07:42 -0700 | [diff] [blame] | 412 | goto error; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 413 | } |
| 414 | #endif |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 415 | mCtx->unlockMutex(); |
| 416 | return true; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 417 | |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 418 | error: |
| 419 | |
| 420 | mCtx->unlockMutex(); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 421 | if (mScriptSO) { |
| 422 | dlclose(mScriptSO); |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 423 | mScriptSO = nullptr; |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 424 | } |
| 425 | return false; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 428 | #ifndef RS_COMPATIBILITY_LIB |
| 429 | |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 430 | const char* RsdCpuScriptImpl::findCoreLib(const bcinfo::MetadataExtractor& ME, const char* bitcode, |
| 431 | size_t bitcodeSize) { |
| 432 | const char* defaultLib = SYSLIBPATH"/libclcore.bc"; |
| 433 | |
| 434 | // If we're debugging, use the debug library. |
| 435 | if (mCtx->getContext()->getContextType() == RS_CONTEXT_TYPE_DEBUG) { |
| 436 | return SYSLIBPATH"/libclcore_debug.bc"; |
| 437 | } |
| 438 | |
| 439 | // If a callback has been registered to specify a library, use that. |
| 440 | RSSelectRTCallback selectRTCallback = mCtx->getSelectRTCallback(); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 441 | if (selectRTCallback != nullptr) { |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 442 | return selectRTCallback((const char*)bitcode, bitcodeSize); |
| 443 | } |
| 444 | |
| 445 | // Check for a platform specific library |
| 446 | #if defined(ARCH_ARM_HAVE_NEON) && !defined(DISABLE_CLCORE_NEON) |
| 447 | enum bcinfo::RSFloatPrecision prec = ME.getRSFloatPrecision(); |
| Jean-Luc Brouillet | f4d3836 | 2014-07-09 17:46:03 -0700 | [diff] [blame] | 448 | if (prec == bcinfo::RS_FP_Relaxed) { |
| Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 449 | // NEON-capable ARMv7a devices can use an accelerated math library |
| 450 | // for all reduced precision scripts. |
| 451 | // ARMv8 does not use NEON, as ASIMD can be used with all precision |
| 452 | // levels. |
| 453 | return SYSLIBPATH"/libclcore_neon.bc"; |
| 454 | } else { |
| 455 | return defaultLib; |
| 456 | } |
| 457 | #elif defined(__i386__) || defined(__x86_64__) |
| 458 | // x86 devices will use an optimized library. |
| 459 | return SYSLIBPATH"/libclcore_x86.bc"; |
| 460 | #else |
| 461 | return defaultLib; |
| 462 | #endif |
| 463 | } |
| 464 | |
| 465 | #endif |
| 466 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 467 | void RsdCpuScriptImpl::populateScript(Script *script) { |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 468 | // Copy info over to runtime |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 469 | script->mHal.info.exportedFunctionCount = mScriptExec->getExportedFunctionCount(); |
| 470 | script->mHal.info.exportedVariableCount = mScriptExec->getExportedVariableCount(); |
| Pirama Arumuga Nainar | 577194a | 2015-01-23 14:27:33 -0800 | [diff] [blame] | 471 | script->mHal.info.exportedPragmaCount = mScriptExec->getPragmaCount();; |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 472 | script->mHal.info.exportedPragmaKeyList = mScriptExec->getPragmaKeys(); |
| 473 | script->mHal.info.exportedPragmaValueList = mScriptExec->getPragmaValues(); |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 474 | |
| 475 | // Bug, need to stash in metadata |
| 476 | if (mRootExpand) { |
| 477 | script->mHal.info.root = mRootExpand; |
| 478 | } else { |
| 479 | script->mHal.info.root = mRoot; |
| 480 | } |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 481 | } |
| 482 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 483 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 484 | bool RsdCpuScriptImpl::forEachMtlsSetup(const Allocation ** ains, |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 485 | uint32_t inLen, |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 486 | Allocation * aout, |
| 487 | const void * usr, uint32_t usrLen, |
| 488 | const RsScriptCall *sc, |
| 489 | MTLaunchStruct *mtls) { |
| 490 | |
| 491 | memset(mtls, 0, sizeof(MTLaunchStruct)); |
| 492 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 493 | for (int index = inLen; --index >= 0;) { |
| 494 | const Allocation* ain = ains[index]; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 495 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 496 | // possible for this to occur if IO_OUTPUT/IO_INPUT with no bound surface |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 497 | if (ain != nullptr && |
| 498 | (const uint8_t *)ain->mHal.drvState.lod[0].mallocPtr == nullptr) { |
| 499 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 500 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 501 | "rsForEach called with null in allocations"); |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 502 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 503 | } |
| 504 | } |
| 505 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 506 | if (aout && |
| 507 | (const uint8_t *)aout->mHal.drvState.lod[0].mallocPtr == nullptr) { |
| 508 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 509 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 510 | "rsForEach called with null out allocations"); |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 511 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 514 | if (inLen > 0) { |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 515 | const Allocation *ain0 = ains[0]; |
| 516 | const Type *inType = ain0->getType(); |
| 517 | |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 518 | mtls->fep.dim.x = inType->getDimX(); |
| 519 | mtls->fep.dim.y = inType->getDimY(); |
| 520 | mtls->fep.dim.z = inType->getDimZ(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 521 | |
| 522 | for (int Index = inLen; --Index >= 1;) { |
| 523 | if (!ain0->hasSameDims(ains[Index])) { |
| 524 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 525 | "Failed to launch kernel; dimensions of input and output" |
| 526 | "allocations do not match."); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 527 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 528 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 532 | } else if (aout != nullptr) { |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 533 | const Type *outType = aout->getType(); |
| 534 | |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 535 | mtls->fep.dim.x = outType->getDimX(); |
| 536 | mtls->fep.dim.y = outType->getDimY(); |
| 537 | mtls->fep.dim.z = outType->getDimZ(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 538 | |
| Jason Sams | a9139c7 | 2015-04-16 15:11:04 -0700 | [diff] [blame] | 539 | } else if (sc != nullptr) { |
| 540 | mtls->fep.dim.x = sc->xEnd; |
| 541 | mtls->fep.dim.y = sc->yEnd; |
| 542 | mtls->fep.dim.z = 0; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 543 | } else { |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 544 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 545 | "rsForEach called with null allocations"); |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 546 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 549 | if (inLen > 0 && aout != nullptr) { |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 550 | if (!ains[0]->hasSameDims(aout)) { |
| 551 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 552 | "Failed to launch kernel; dimensions of input and output allocations do not match."); |
| 553 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 554 | return false; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
| 558 | if (!sc || (sc->xEnd == 0)) { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 559 | mtls->end.x = mtls->fep.dim.x; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 560 | } else { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 561 | mtls->start.x = rsMin(mtls->fep.dim.x, sc->xStart); |
| 562 | mtls->end.x = rsMin(mtls->fep.dim.x, sc->xEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 563 | if (mtls->start.x >= mtls->end.x) { |
| 564 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 565 | "Failed to launch kernel; Invalid xStart or xEnd."); |
| 566 | return false; |
| 567 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | if (!sc || (sc->yEnd == 0)) { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 571 | mtls->end.y = mtls->fep.dim.y; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 572 | } else { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 573 | mtls->start.y = rsMin(mtls->fep.dim.y, sc->yStart); |
| 574 | mtls->end.y = rsMin(mtls->fep.dim.y, sc->yEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 575 | if (mtls->start.y >= mtls->end.y) { |
| 576 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 577 | "Failed to launch kernel; Invalid yStart or yEnd."); |
| 578 | return false; |
| 579 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | if (!sc || (sc->zEnd == 0)) { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 583 | mtls->end.z = mtls->fep.dim.z; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 584 | } else { |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 585 | mtls->start.z = rsMin(mtls->fep.dim.z, sc->zStart); |
| 586 | mtls->end.z = rsMin(mtls->fep.dim.z, sc->zEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 587 | if (mtls->start.z >= mtls->end.z) { |
| 588 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 589 | "Failed to launch kernel; Invalid zStart or zEnd."); |
| 590 | return false; |
| 591 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 594 | if (!sc || (sc->arrayEnd == 0)) { |
| 595 | mtls->end.array[0] = mtls->fep.dim.array[0]; |
| 596 | } else { |
| 597 | mtls->start.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayStart); |
| 598 | mtls->end.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayEnd); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 599 | if (mtls->start.array[0] >= mtls->end.array[0]) { |
| 600 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 601 | "Failed to launch kernel; Invalid arrayStart or arrayEnd."); |
| 602 | return false; |
| 603 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 604 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 605 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 606 | if (!sc || (sc->array2End == 0)) { |
| 607 | mtls->end.array[1] = mtls->fep.dim.array[1]; |
| 608 | } else { |
| 609 | mtls->start.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2Start); |
| 610 | mtls->end.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2End); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 611 | if (mtls->start.array[1] >= mtls->end.array[1]) { |
| 612 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 613 | "Failed to launch kernel; Invalid array2Start or array2End."); |
| 614 | return false; |
| 615 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | if (!sc || (sc->array3End == 0)) { |
| 619 | mtls->end.array[2] = mtls->fep.dim.array[2]; |
| 620 | } else { |
| 621 | mtls->start.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3Start); |
| 622 | mtls->end.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3End); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 623 | if (mtls->start.array[2] >= mtls->end.array[2]) { |
| 624 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 625 | "Failed to launch kernel; Invalid array3Start or array3End."); |
| 626 | return false; |
| 627 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | if (!sc || (sc->array4End == 0)) { |
| 631 | mtls->end.array[3] = mtls->fep.dim.array[3]; |
| 632 | } else { |
| 633 | mtls->start.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4Start); |
| 634 | mtls->end.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4End); |
| Pirama Arumuga Nainar | 80afd42 | 2015-04-28 15:41:48 -0700 | [diff] [blame] | 635 | if (mtls->start.array[3] >= mtls->end.array[3]) { |
| 636 | mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT, |
| 637 | "Failed to launch kernel; Invalid array4Start or array4End."); |
| 638 | return false; |
| 639 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | |
| 643 | // The X & Y walkers always want 0-1 min even if dim is not present |
| 644 | mtls->end.x = rsMax((uint32_t)1, mtls->end.x); |
| 645 | mtls->end.y = rsMax((uint32_t)1, mtls->end.y); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 646 | |
| 647 | mtls->rsc = mCtx; |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 648 | if (ains) { |
| 649 | memcpy(mtls->ains, ains, inLen * sizeof(ains[0])); |
| 650 | } |
| 651 | mtls->aout[0] = aout; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 652 | mtls->fep.usr = usr; |
| 653 | mtls->fep.usrLen = usrLen; |
| 654 | mtls->mSliceSize = 1; |
| 655 | mtls->mSliceNum = 0; |
| 656 | |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 657 | mtls->isThreadable = mIsThreadable; |
| 658 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 659 | if (inLen > 0) { |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 660 | mtls->fep.inLen = inLen; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 661 | for (int index = inLen; --index >= 0;) { |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 662 | mtls->fep.inPtr[index] = (const uint8_t*)ains[index]->mHal.drvState.lod[0].mallocPtr; |
| 663 | mtls->fep.inStride[index] = ains[index]->getType()->getElementSizeBytes(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 667 | if (aout != nullptr) { |
| Jason Sams | c0d6847 | 2015-01-20 14:29:52 -0800 | [diff] [blame] | 668 | mtls->fep.outPtr[0] = (uint8_t *)aout->mHal.drvState.lod[0].mallocPtr; |
| 669 | mtls->fep.outStride[0] = aout->getType()->getElementSizeBytes(); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 670 | } |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 671 | |
| 672 | // All validation passed, ok to launch threads |
| 673 | return true; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 676 | |
| 677 | void RsdCpuScriptImpl::invokeForEach(uint32_t slot, |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 678 | const Allocation ** ains, |
| 679 | uint32_t inLen, |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 680 | Allocation * aout, |
| 681 | const void * usr, |
| 682 | uint32_t usrLen, |
| 683 | const RsScriptCall *sc) { |
| 684 | |
| 685 | MTLaunchStruct mtls; |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 686 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 687 | if (forEachMtlsSetup(ains, inLen, aout, usr, usrLen, sc, &mtls)) { |
| 688 | forEachKernelSetup(slot, &mtls); |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 689 | |
| Jason Sams | bf2111d | 2015-01-26 18:13:41 -0800 | [diff] [blame] | 690 | RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this); |
| 691 | mCtx->launchThreads(ains, inLen, aout, sc, &mtls); |
| 692 | mCtx->setTLS(oldTLS); |
| 693 | } |
| Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 696 | void RsdCpuScriptImpl::forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 697 | mtls->script = this; |
| 698 | mtls->fep.slot = slot; |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 699 | mtls->kernel = mScriptExec->getForEachFunction(slot); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 700 | rsAssert(mtls->kernel != nullptr); |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 701 | mtls->sig = mScriptExec->getForEachSignature(slot); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | int RsdCpuScriptImpl::invokeRoot() { |
| 705 | RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this); |
| 706 | int ret = mRoot(); |
| 707 | mCtx->setTLS(oldTLS); |
| 708 | return ret; |
| 709 | } |
| 710 | |
| 711 | void RsdCpuScriptImpl::invokeInit() { |
| 712 | if (mInit) { |
| 713 | mInit(); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | void RsdCpuScriptImpl::invokeFreeChildren() { |
| 718 | if (mFreeChildren) { |
| 719 | mFreeChildren(); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | void RsdCpuScriptImpl::invokeFunction(uint32_t slot, const void *params, |
| 724 | size_t paramLength) { |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 725 | //ALOGE("invoke %i %p %zu", slot, params, paramLength); |
| Yong Chen | eaba5a3 | 2014-12-12 13:25:18 +0800 | [diff] [blame] | 726 | void * ap = nullptr; |
| 727 | |
| 728 | #if defined(__x86_64__) |
| 729 | // The invoked function could have input parameter of vector type for example float4 which |
| 730 | // requires void* params to be 16 bytes aligned when using SSE instructions for x86_64 platform. |
| 731 | // So try to align void* params before passing them into RS exported function. |
| 732 | |
| 733 | if ((uint8_t)(uint64_t)params & 0x0F) { |
| 734 | if ((ap = (void*)memalign(16, paramLength)) != nullptr) { |
| 735 | memcpy(ap, params, paramLength); |
| 736 | } else { |
| Yang Ni | e8f9fba | 2015-01-30 08:55:10 -0800 | [diff] [blame] | 737 | ALOGE("x86_64: invokeFunction memalign error, still use params which" |
| 738 | " is not 16 bytes aligned."); |
| Yong Chen | eaba5a3 | 2014-12-12 13:25:18 +0800 | [diff] [blame] | 739 | } |
| 740 | } |
| 741 | #endif |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 742 | |
| 743 | RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 744 | reinterpret_cast<void (*)(const void *, uint32_t)>( |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 745 | mScriptExec->getInvokeFunction(slot))(ap? (const void *) ap: params, paramLength); |
| Yong Chen | eaba5a3 | 2014-12-12 13:25:18 +0800 | [diff] [blame] | 746 | |
| Yong Chen | c246d91 | 2015-05-22 18:20:06 +0800 | [diff] [blame] | 747 | #if defined(__x86_64__) |
| 748 | free(ap); |
| 749 | #endif |
| 750 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 751 | mCtx->setTLS(oldTLS); |
| 752 | } |
| 753 | |
| 754 | void RsdCpuScriptImpl::setGlobalVar(uint32_t slot, const void *data, size_t dataLength) { |
| 755 | //rsAssert(!script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 756 | //ALOGE("setGlobalVar %i %p %zu", slot, data, dataLength); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 757 | |
| 758 | //if (mIntrinsicID) { |
| 759 | //mIntrinsicFuncs.setVar(dc, script, drv->mIntrinsicData, slot, data, dataLength); |
| 760 | //return; |
| 761 | //} |
| 762 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 763 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 764 | if (!destPtr) { |
| 765 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 766 | return; |
| 767 | } |
| 768 | |
| 769 | memcpy(destPtr, data, dataLength); |
| 770 | } |
| 771 | |
| Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 772 | void RsdCpuScriptImpl::getGlobalVar(uint32_t slot, void *data, size_t dataLength) { |
| 773 | //rsAssert(!script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 774 | //ALOGE("getGlobalVar %i %p %zu", slot, data, dataLength); |
| Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 775 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 776 | int32_t *srcPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 777 | if (!srcPtr) { |
| 778 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 779 | return; |
| 780 | } |
| 781 | memcpy(data, srcPtr, dataLength); |
| 782 | } |
| 783 | |
| 784 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 785 | void RsdCpuScriptImpl::setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
| 786 | const Element *elem, |
| Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 787 | const uint32_t *dims, size_t dimLength) { |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 788 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 789 | if (!destPtr) { |
| 790 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 791 | return; |
| 792 | } |
| 793 | |
| 794 | // We want to look at dimension in terms of integer components, |
| 795 | // but dimLength is given in terms of bytes. |
| 796 | dimLength /= sizeof(int); |
| 797 | |
| 798 | // Only a single dimension is currently supported. |
| 799 | rsAssert(dimLength == 1); |
| 800 | if (dimLength == 1) { |
| 801 | // First do the increment loop. |
| 802 | size_t stride = elem->getSizeBytes(); |
| 803 | const char *cVal = reinterpret_cast<const char *>(data); |
| Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 804 | for (uint32_t i = 0; i < dims[0]; i++) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 805 | elem->incRefs(cVal); |
| 806 | cVal += stride; |
| 807 | } |
| 808 | |
| 809 | // Decrement loop comes after (to prevent race conditions). |
| 810 | char *oldVal = reinterpret_cast<char *>(destPtr); |
| Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 811 | for (uint32_t i = 0; i < dims[0]; i++) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 812 | elem->decRefs(oldVal); |
| 813 | oldVal += stride; |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | memcpy(destPtr, data, dataLength); |
| 818 | } |
| 819 | |
| 820 | void RsdCpuScriptImpl::setGlobalBind(uint32_t slot, Allocation *data) { |
| 821 | |
| 822 | //rsAssert(!script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 823 | //ALOGE("setGlobalBind %i %p", slot, data); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 824 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 825 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 826 | if (!destPtr) { |
| 827 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 828 | return; |
| 829 | } |
| 830 | |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 831 | void *ptr = nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 832 | mBoundAllocs[slot] = data; |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 833 | if (data) { |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 834 | ptr = data->mHal.drvState.lod[0].mallocPtr; |
| 835 | } |
| 836 | memcpy(destPtr, &ptr, sizeof(void *)); |
| 837 | } |
| 838 | |
| 839 | void RsdCpuScriptImpl::setGlobalObj(uint32_t slot, ObjectBase *data) { |
| 840 | |
| 841 | //rsAssert(script->mFieldIsObject[slot]); |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 842 | //ALOGE("setGlobalObj %i %p", slot, data); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 843 | |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 844 | int32_t *destPtr = reinterpret_cast<int32_t *>(mScriptExec->getFieldAddress(slot)); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 845 | if (!destPtr) { |
| 846 | //ALOGV("Calling setVar on slot = %i which is null", slot); |
| 847 | return; |
| 848 | } |
| 849 | |
| Jason Sams | 05ef73f | 2014-08-05 14:59:22 -0700 | [diff] [blame] | 850 | rsrSetObject(mCtx->getContext(), (rs_object_base *)destPtr, data); |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 851 | } |
| 852 | |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 853 | const char* RsdCpuScriptImpl::getFieldName(uint32_t slot) const { |
| 854 | return mScriptExec->getFieldName(slot); |
| 855 | } |
| 856 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 857 | RsdCpuScriptImpl::~RsdCpuScriptImpl() { |
| Yang Ni | d9bae68 | 2015-01-20 15:31:15 -0800 | [diff] [blame] | 858 | if (mScriptExec != nullptr) { |
| 859 | delete mScriptExec; |
| Pirama Arumuga Nainar | dc0d8f7 | 2014-12-02 15:23:38 -0800 | [diff] [blame] | 860 | } |
| Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 861 | if (mBoundAllocs) delete[] mBoundAllocs; |
| 862 | if (mScriptSO) { |
| 863 | dlclose(mScriptSO); |
| 864 | } |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | Allocation * RsdCpuScriptImpl::getAllocationForPointer(const void *ptr) const { |
| 868 | if (!ptr) { |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 869 | return nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | for (uint32_t ct=0; ct < mScript->mHal.info.exportedVariableCount; ct++) { |
| 873 | Allocation *a = mBoundAllocs[ct]; |
| 874 | if (!a) continue; |
| 875 | if (a->mHal.drvState.lod[0].mallocPtr == ptr) { |
| 876 | return a; |
| 877 | } |
| 878 | } |
| 879 | ALOGE("rsGetAllocation, failed to find %p", ptr); |
| Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 880 | return nullptr; |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 881 | } |
| 882 | |
| Stephen Hines | 8409d64 | 2015-04-28 18:49:56 -0700 | [diff] [blame] | 883 | int RsdCpuScriptImpl::getGlobalEntries() const { |
| 884 | return mScriptExec->getGlobalEntries(); |
| 885 | } |
| 886 | |
| 887 | const char * RsdCpuScriptImpl::getGlobalName(int i) const { |
| 888 | return mScriptExec->getGlobalName(i); |
| 889 | } |
| 890 | |
| 891 | const void * RsdCpuScriptImpl::getGlobalAddress(int i) const { |
| 892 | return mScriptExec->getGlobalAddress(i); |
| 893 | } |
| 894 | |
| 895 | size_t RsdCpuScriptImpl::getGlobalSize(int i) const { |
| 896 | return mScriptExec->getGlobalSize(i); |
| 897 | } |
| 898 | |
| Stephen Hines | 5aa018c | 2015-05-20 18:09:57 -0700 | [diff] [blame] | 899 | uint32_t RsdCpuScriptImpl::getGlobalProperties(int i) const { |
| 900 | return mScriptExec->getGlobalProperties(i); |
| 901 | } |
| 902 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 903 | void RsdCpuScriptImpl::preLaunch(uint32_t slot, const Allocation ** ains, |
| 904 | uint32_t inLen, Allocation * aout, |
| 905 | const void * usr, uint32_t usrLen, |
| 906 | const RsScriptCall *sc) {} |
| Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 907 | |
| Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 908 | void RsdCpuScriptImpl::postLaunch(uint32_t slot, const Allocation ** ains, |
| 909 | uint32_t inLen, Allocation * aout, |
| 910 | const void * usr, uint32_t usrLen, |
| 911 | const RsScriptCall *sc) {} |
| Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 912 | |
| Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 913 | |
| 914 | } |
| 915 | } |