Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 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 |
| 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 | //#define LOG_NDEBUG 0 |
Stephen Hines | e198abe | 2012-07-27 18:05:41 -0700 | [diff] [blame] | 18 | #include "bcc/Renderscript/RSInfo.h" |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 19 | |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 20 | #include <dlfcn.h> |
| 21 | |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 22 | #include <cstring> |
| 23 | #include <new> |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 24 | #include <string> |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 25 | |
Zonr Chang | c72c4dd | 2012-04-12 15:38:53 +0800 | [diff] [blame] | 26 | #include "bcc/Support/FileBase.h" |
Zonr Chang | ef73a24 | 2012-04-12 16:44:01 +0800 | [diff] [blame] | 27 | #include "bcc/Support/Log.h" |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 28 | |
Nick Kralevich | b81d697 | 2013-05-21 16:52:35 -0700 | [diff] [blame^] | 29 | #ifdef HAVE_ANDROID_OS |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 30 | #include <cutils/properties.h> |
Nick Kralevich | b81d697 | 2013-05-21 16:52:35 -0700 | [diff] [blame^] | 31 | #endif |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 32 | |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 33 | using namespace bcc; |
| 34 | |
| 35 | const char RSInfo::LibBCCPath[] = "/system/lib/libbcc.so"; |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 36 | const char RSInfo::LibCompilerRTPath[] = "/system/lib/libcompiler_rt.so"; |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 37 | const char RSInfo::LibRSPath[] = "/system/lib/libRS.so"; |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 38 | const char RSInfo::LibCLCorePath[] = "/system/lib/libclcore.bc"; |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 39 | const char RSInfo::LibCLCoreDebugPath[] = "/system/lib/libclcore_debug.bc"; |
Michael Liao | cdcce32 | 2012-09-25 21:59:39 -0700 | [diff] [blame] | 40 | #if defined(ARCH_X86_HAVE_SSE2) |
| 41 | const char RSInfo::LibCLCoreX86Path[] = "/system/lib/libclcore_x86.bc"; |
| 42 | #endif |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 43 | #if defined(ARCH_ARM_HAVE_NEON) |
| 44 | const char RSInfo::LibCLCoreNEONPath[] = "/system/lib/libclcore_neon.bc"; |
| 45 | #endif |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 46 | |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 47 | const uint8_t *RSInfo::LibBCCSHA1 = NULL; |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 48 | const uint8_t *RSInfo::LibCompilerRTSHA1 = NULL; |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 49 | const uint8_t *RSInfo::LibRSSHA1 = NULL; |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 50 | const uint8_t *RSInfo::LibCLCoreSHA1 = NULL; |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 51 | const uint8_t *RSInfo::LibCLCoreDebugSHA1 = NULL; |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 52 | #if defined(ARCH_ARM_HAVE_NEON) |
| 53 | const uint8_t *RSInfo::LibCLCoreNEONSHA1 = NULL; |
| 54 | #endif |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 55 | |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 56 | bool RSInfo::LoadBuiltInSHA1Information() { |
| 57 | #ifdef TARGET_BUILD |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 58 | if (LibBCCSHA1 != NULL) { |
| 59 | // Loaded before. |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 60 | return true; |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 61 | } |
| 62 | |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 63 | void *h = ::dlopen("/system/lib/libbcc.sha1.so", RTLD_LAZY | RTLD_NOW); |
| 64 | if (h == NULL) { |
| 65 | ALOGE("Failed to load SHA-1 information from shared library '" |
| 66 | "/system/lib/libbcc.sha1.so'! (%s)", ::dlerror()); |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 67 | return false; |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 68 | } |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 69 | |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 70 | LibBCCSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libbcc_so_SHA1")); |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 71 | LibCompilerRTSHA1 = |
| 72 | reinterpret_cast<const uint8_t *>(::dlsym(h, "libcompiler_rt_so_SHA1")); |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 73 | LibRSSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libRS_so_SHA1")); |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 74 | LibCLCoreSHA1 = |
| 75 | reinterpret_cast<const uint8_t *>(::dlsym(h, "libclcore_bc_SHA1")); |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 76 | LibCLCoreDebugSHA1 = |
| 77 | reinterpret_cast<const uint8_t *>(::dlsym(h, "libclcore_debug_bc_SHA1")); |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 78 | #if defined(ARCH_ARM_HAVE_NEON) |
| 79 | LibCLCoreNEONSHA1 = |
| 80 | reinterpret_cast<const uint8_t *>(::dlsym(h, "libclcore_neon_bc_SHA1")); |
| 81 | #endif |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 82 | |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 83 | return true; |
| 84 | #else // TARGET_BUILD |
| 85 | return false; |
| 86 | #endif // TARGET_BUILD |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | android::String8 RSInfo::GetPath(const FileBase &pFile) { |
| 90 | android::String8 result(pFile.getName().c_str()); |
| 91 | result.append(".info"); |
| 92 | return result; |
| 93 | } |
| 94 | |
| 95 | #define PRINT_DEPENDENCY(PREFIX, N, X) \ |
| 96 | ALOGV("\t" PREFIX "Source name: %s, " \ |
| 97 | "SHA-1: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" \ |
| 98 | "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", \ |
| 99 | (N), (X)[ 0], (X)[ 1], (X)[ 2], (X)[ 3], (X)[ 4], (X)[ 5], \ |
| 100 | (X)[ 6], (X)[ 7], (X)[ 8], (X)[ 9], (X)[10], (X)[11], \ |
| 101 | (X)[12], (X)[13], (X)[14], (X)[15], (X)[16], (X)[17], \ |
| 102 | (X)[18], (X)[19]); |
| 103 | |
| 104 | bool RSInfo::CheckDependency(const RSInfo &pInfo, |
| 105 | const char *pInputFilename, |
Shih-wei Liao | 7bcec85 | 2012-04-25 04:07:09 -0700 | [diff] [blame] | 106 | const DependencyTableTy &pDeps) { |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 107 | // Built-in dependencies are libbcc.so, libRS.so and libclcore.bc plus |
| 108 | // libclcore_neon.bc if NEON is available on the target device. |
| 109 | #if !defined(ARCH_ARM_HAVE_NEON) |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 110 | static const unsigned NumBuiltInDependencies = 5; |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 111 | #else |
| 112 | static const unsigned NumBuiltInDependencies = 6; |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 113 | #endif |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 114 | |
| 115 | LoadBuiltInSHA1Information(); |
| 116 | |
| 117 | if (pInfo.mDependencyTable.size() != (pDeps.size() + NumBuiltInDependencies)) { |
| 118 | ALOGD("Number of dependencies recorded mismatch (%lu v.s. %lu) in %s!", |
| 119 | static_cast<unsigned long>(pInfo.mDependencyTable.size()), |
| 120 | static_cast<unsigned long>(pDeps.size()), pInputFilename); |
| 121 | return false; |
| 122 | } else { |
| 123 | // Built-in dependencies always go first. |
| 124 | const std::pair<const char *, const uint8_t *> &cache_libbcc_dep = |
| 125 | pInfo.mDependencyTable[0]; |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 126 | const std::pair<const char *, const uint8_t *> &cache_libcompiler_rt_dep = |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 127 | pInfo.mDependencyTable[1]; |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 128 | const std::pair<const char *, const uint8_t *> &cache_libRS_dep = |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 129 | pInfo.mDependencyTable[2]; |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 130 | const std::pair<const char *, const uint8_t *> &cache_libclcore_dep = |
| 131 | pInfo.mDependencyTable[3]; |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 132 | const std::pair<const char *, const uint8_t *> &cache_libclcore_debug_dep = |
| 133 | pInfo.mDependencyTable[4]; |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 134 | #if defined(ARCH_ARM_HAVE_NEON) |
| 135 | const std::pair<const char *, const uint8_t *> &cache_libclcore_neon_dep = |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 136 | pInfo.mDependencyTable[5]; |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 137 | #endif |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 138 | |
| 139 | // Check libbcc.so. |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 140 | if (::memcmp(cache_libbcc_dep.second, LibBCCSHA1, SHA1_DIGEST_LENGTH) != 0) { |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 141 | ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename, |
| 142 | LibBCCPath); |
| 143 | PRINT_DEPENDENCY("current - ", LibBCCPath, LibBCCSHA1); |
| 144 | PRINT_DEPENDENCY("cache - ", cache_libbcc_dep.first, |
| 145 | cache_libbcc_dep.second); |
| 146 | return false; |
| 147 | } |
| 148 | |
Shih-wei Liao | f7401ab | 2013-01-25 16:29:44 -0800 | [diff] [blame] | 149 | // Check libcompiler_rt.so. |
| 150 | if (::memcmp(cache_libcompiler_rt_dep.second, LibCompilerRTSHA1, |
| 151 | SHA1_DIGEST_LENGTH) != 0) { |
| 152 | ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename, |
| 153 | LibCompilerRTPath); |
| 154 | PRINT_DEPENDENCY("current - ", LibCompilerRTPath, LibCompilerRTSHA1); |
| 155 | PRINT_DEPENDENCY("cache - ", cache_libcompiler_rt_dep.first, |
| 156 | cache_libcompiler_rt_dep.second); |
| 157 | return false; |
| 158 | } |
| 159 | |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 160 | // Check libRS.so. |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 161 | if (::memcmp(cache_libRS_dep.second, LibRSSHA1, SHA1_DIGEST_LENGTH) != 0) { |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 162 | ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename, |
| 163 | LibRSPath); |
| 164 | PRINT_DEPENDENCY("current - ", LibRSPath, LibRSSHA1); |
| 165 | PRINT_DEPENDENCY("cache - ", cache_libRS_dep.first, |
| 166 | cache_libRS_dep.second); |
| 167 | return false; |
| 168 | } |
| 169 | |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 170 | // Check libclcore.bc. |
| 171 | if (::memcmp(cache_libclcore_dep.second, LibCLCoreSHA1, |
| 172 | SHA1_DIGEST_LENGTH) != 0) { |
| 173 | ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename, |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 174 | LibCLCorePath); |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 175 | PRINT_DEPENDENCY("current - ", LibCLCorePath, LibCLCoreSHA1); |
| 176 | PRINT_DEPENDENCY("cache - ", cache_libclcore_dep.first, |
| 177 | cache_libclcore_dep.second); |
| 178 | return false; |
| 179 | } |
| 180 | |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 181 | // Check libclcore_debug.bc. |
| 182 | if (::memcmp(cache_libclcore_debug_dep.second, LibCLCoreDebugSHA1, |
| 183 | SHA1_DIGEST_LENGTH) != 0) { |
| 184 | ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename, |
| 185 | LibCLCoreDebugPath); |
| 186 | PRINT_DEPENDENCY("current - ", LibCLCoreDebugPath, LibCLCoreDebugSHA1); |
| 187 | PRINT_DEPENDENCY("cache - ", cache_libclcore_debug_dep.first, |
| 188 | cache_libclcore_debug_dep.second); |
| 189 | return false; |
| 190 | } |
| 191 | |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 192 | #if defined(ARCH_ARM_HAVE_NEON) |
| 193 | // Check libclcore_neon.bc if NEON is available. |
| 194 | if (::memcmp(cache_libclcore_neon_dep.second, LibCLCoreNEONSHA1, |
| 195 | SHA1_DIGEST_LENGTH) != 0) { |
| 196 | ALOGD("Cache %s is dirty due to %s has been updated.", pInputFilename, |
Stephen Hines | 8ee82d4 | 2013-04-16 19:57:34 -0700 | [diff] [blame] | 197 | LibCLCoreNEONPath); |
Shih-wei Liao | b1cc74f | 2012-06-30 11:27:01 -0700 | [diff] [blame] | 198 | PRINT_DEPENDENCY("current - ", LibCLCoreNEONPath, LibCLCoreNEONSHA1); |
| 199 | PRINT_DEPENDENCY("cache - ", cache_libclcore_neon_dep.first, |
| 200 | cache_libclcore_neon_dep.second); |
| 201 | return false; |
| 202 | } |
| 203 | #endif |
| 204 | |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 205 | for (unsigned i = 0; i < pDeps.size(); i++) { |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 206 | const std::pair<const char *, const uint8_t *> &cache_dep = |
| 207 | pInfo.mDependencyTable[i + NumBuiltInDependencies]; |
| 208 | |
Shih-wei Liao | 7bcec85 | 2012-04-25 04:07:09 -0700 | [diff] [blame] | 209 | if ((::strcmp(pDeps[i].first, cache_dep.first) != 0) || |
| 210 | (::memcmp(pDeps[i].second, cache_dep.second, |
Zonr Chang | f290793 | 2012-04-13 11:56:21 +0800 | [diff] [blame] | 211 | SHA1_DIGEST_LENGTH) != 0)) { |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 212 | ALOGD("Cache %s is dirty due to the source it dependends on has been " |
| 213 | "changed:", pInputFilename); |
Shih-wei Liao | 7bcec85 | 2012-04-25 04:07:09 -0700 | [diff] [blame] | 214 | PRINT_DEPENDENCY("given - ", pDeps[i].first, pDeps[i].second); |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 215 | PRINT_DEPENDENCY("cache - ", cache_dep.first, cache_dep.second); |
| 216 | return false; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | return true; |
| 222 | } |
| 223 | |
| 224 | RSInfo::RSInfo(size_t pStringPoolSize) : mStringPool(NULL) { |
| 225 | ::memset(&mHeader, 0, sizeof(mHeader)); |
| 226 | |
| 227 | ::memcpy(mHeader.magic, RSINFO_MAGIC, sizeof(mHeader.magic)); |
| 228 | ::memcpy(mHeader.version, RSINFO_VERSION, sizeof(mHeader.version)); |
| 229 | |
| 230 | mHeader.headerSize = sizeof(mHeader); |
| 231 | |
| 232 | mHeader.dependencyTable.itemSize = sizeof(rsinfo::DependencyTableItem); |
| 233 | mHeader.pragmaList.itemSize = sizeof(rsinfo::PragmaItem); |
| 234 | mHeader.objectSlotList.itemSize = sizeof(rsinfo::ObjectSlotItem); |
| 235 | mHeader.exportVarNameList.itemSize = sizeof(rsinfo::ExportVarNameItem); |
| 236 | mHeader.exportFuncNameList.itemSize = sizeof(rsinfo::ExportFuncNameItem); |
| 237 | mHeader.exportForeachFuncList.itemSize = sizeof(rsinfo::ExportForeachFuncItem); |
| 238 | |
| 239 | if (pStringPoolSize > 0) { |
| 240 | mHeader.strPoolSize = pStringPoolSize; |
| 241 | mStringPool = new (std::nothrow) char [ mHeader.strPoolSize ]; |
| 242 | if (mStringPool == NULL) { |
| 243 | ALOGE("Out of memory when allocate memory for string pool in RSInfo " |
| 244 | "constructor (size: %u)!", mHeader.strPoolSize); |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | RSInfo::~RSInfo() { |
| 250 | delete [] mStringPool; |
| 251 | } |
| 252 | |
| 253 | bool RSInfo::layout(off_t initial_offset) { |
| 254 | mHeader.dependencyTable.offset = initial_offset + |
| 255 | mHeader.headerSize + |
| 256 | mHeader.strPoolSize; |
| 257 | mHeader.dependencyTable.count = mDependencyTable.size(); |
| 258 | |
| 259 | #define AFTER(_list) ((_list).offset + (_list).itemSize * (_list).count) |
| 260 | mHeader.pragmaList.offset = AFTER(mHeader.dependencyTable); |
| 261 | mHeader.pragmaList.count = mPragmas.size(); |
| 262 | |
| 263 | mHeader.objectSlotList.offset = AFTER(mHeader.pragmaList); |
| 264 | mHeader.objectSlotList.count = mObjectSlots.size(); |
| 265 | |
| 266 | mHeader.exportVarNameList.offset = AFTER(mHeader.objectSlotList); |
| 267 | mHeader.exportVarNameList.count = mExportVarNames.size(); |
| 268 | |
| 269 | mHeader.exportFuncNameList.offset = AFTER(mHeader.exportVarNameList); |
| 270 | mHeader.exportFuncNameList.count = mExportFuncNames.size(); |
| 271 | |
| 272 | mHeader.exportForeachFuncList.offset = AFTER(mHeader.exportFuncNameList); |
| 273 | mHeader.exportForeachFuncList.count = mExportForeachFuncs.size(); |
| 274 | #undef AFTER |
| 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | void RSInfo::dump() const { |
| 280 | // Hide the codes to save the code size when debugging is disabled. |
| 281 | #if !LOG_NDEBUG |
| 282 | |
| 283 | // Dump header |
| 284 | ALOGV("RSInfo Header:"); |
| 285 | ALOGV("\tIs threadable: %s", ((mHeader.isThreadable) ? "true" : "false")); |
| 286 | ALOGV("\tHeader size: %u", mHeader.headerSize); |
| 287 | ALOGV("\tString pool size: %u", mHeader.strPoolSize); |
| 288 | |
| 289 | #define DUMP_LIST_HEADER(_name, _header) do { \ |
| 290 | ALOGV(_name ":"); \ |
| 291 | ALOGV("\toffset: %u", (_header).offset); \ |
| 292 | ALOGV("\t# of item: %u", (_header).count); \ |
| 293 | ALOGV("\tsize of each item: %u", (_header).itemSize); \ |
| 294 | } while (false) |
| 295 | DUMP_LIST_HEADER("Dependency table", mHeader.dependencyTable); |
| 296 | for (DependencyTableTy::const_iterator dep_iter = mDependencyTable.begin(), |
| 297 | dep_end = mDependencyTable.end(); dep_iter != dep_end; dep_iter++) { |
| 298 | PRINT_DEPENDENCY("", dep_iter->first, dep_iter->second); |
| 299 | } |
| 300 | |
| 301 | DUMP_LIST_HEADER("Pragma list", mHeader.pragmaList); |
| 302 | for (PragmaListTy::const_iterator pragma_iter = mPragmas.begin(), |
| 303 | pragma_end = mPragmas.end(); pragma_iter != pragma_end; pragma_iter++) { |
| 304 | ALOGV("\tkey: %s, value: %s", pragma_iter->first, pragma_iter->second); |
| 305 | } |
| 306 | |
| 307 | DUMP_LIST_HEADER("RS object slots", mHeader.objectSlotList); |
| 308 | for (ObjectSlotListTy::const_iterator slot_iter = mObjectSlots.begin(), |
| 309 | slot_end = mObjectSlots.end(); slot_iter != slot_end; slot_iter++) { |
| 310 | ALOGV("slot: %u", *slot_iter); |
| 311 | } |
| 312 | |
| 313 | DUMP_LIST_HEADER("RS export variables", mHeader.exportVarNameList); |
| 314 | for (ExportVarNameListTy::const_iterator var_iter = mExportVarNames.begin(), |
| 315 | var_end = mExportVarNames.end(); var_iter != var_end; var_iter++) { |
| 316 | ALOGV("name: %s", *var_iter); |
| 317 | } |
| 318 | |
| 319 | DUMP_LIST_HEADER("RS export functions", mHeader.exportFuncNameList); |
| 320 | for (ExportFuncNameListTy::const_iterator func_iter = mExportFuncNames.begin(), |
| 321 | func_end = mExportFuncNames.end(); func_iter != func_end; func_iter++) { |
| 322 | ALOGV("name: %s", *func_iter); |
| 323 | } |
| 324 | |
| 325 | DUMP_LIST_HEADER("RS foreach list", mHeader.exportForeachFuncList); |
| 326 | for (ExportForeachFuncListTy::const_iterator |
| 327 | foreach_iter = mExportForeachFuncs.begin(), |
| 328 | foreach_end = mExportForeachFuncs.end(); foreach_iter != foreach_end; |
| 329 | foreach_iter++) { |
| 330 | ALOGV("name: %s, signature: %05x", foreach_iter->first, |
| 331 | foreach_iter->second); |
| 332 | } |
| 333 | #undef DUMP_LIST_HEADER |
| 334 | |
| 335 | #endif // LOG_NDEBUG |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | const char *RSInfo::getStringFromPool(rsinfo::StringIndexTy pStrIdx) const { |
| 340 | // String pool uses direct indexing. Ensure that the pStrIdx is within the |
| 341 | // range. |
| 342 | if (pStrIdx >= mHeader.strPoolSize) { |
| 343 | ALOGE("String index #%u is out of range in string pool (size: %u)!", |
| 344 | pStrIdx, mHeader.strPoolSize); |
| 345 | return NULL; |
| 346 | } |
| 347 | return &mStringPool[ pStrIdx ]; |
| 348 | } |
| 349 | |
| 350 | rsinfo::StringIndexTy RSInfo::getStringIdxInPool(const char *pStr) const { |
| 351 | // Assume we are on the flat memory architecture (i.e., the memory space is |
| 352 | // continuous.) |
| 353 | if ((mStringPool + mHeader.strPoolSize) < pStr) { |
| 354 | ALOGE("String %s does not in the string pool!", pStr); |
| 355 | return rsinfo::gInvalidStringIndex; |
| 356 | } |
| 357 | return (pStr - mStringPool); |
| 358 | } |
| 359 | |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 360 | RSInfo::FloatPrecision RSInfo::getFloatPrecisionRequirement() const { |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 361 | // Check to see if we have any FP precision-related pragmas. |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 362 | std::string relaxed_pragma("rs_fp_relaxed"); |
| 363 | std::string imprecise_pragma("rs_fp_imprecise"); |
| 364 | std::string full_pragma("rs_fp_full"); |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 365 | bool relaxed_pragma_seen = false; |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 366 | bool imprecise_pragma_seen = false; |
| 367 | RSInfo::FloatPrecision result = FP_Full; |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 368 | |
| 369 | for (PragmaListTy::const_iterator pragma_iter = mPragmas.begin(), |
| 370 | pragma_end = mPragmas.end(); pragma_iter != pragma_end; |
| 371 | pragma_iter++) { |
| 372 | const char *pragma_key = pragma_iter->first; |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 373 | if (!relaxed_pragma.compare(pragma_key)) { |
| 374 | if (relaxed_pragma_seen || imprecise_pragma_seen) { |
| 375 | ALOGE("Multiple float precision pragmas specified!"); |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 376 | } |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 377 | relaxed_pragma_seen = true; |
| 378 | } else if (!imprecise_pragma.compare(pragma_key)) { |
| 379 | if (relaxed_pragma_seen || imprecise_pragma_seen) { |
| 380 | ALOGE("Multiple float precision pragmas specified!"); |
| 381 | } |
| 382 | imprecise_pragma_seen = true; |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
| 386 | // Imprecise is selected over Relaxed precision. |
| 387 | // In the absence of both, we stick to the default Full precision. |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 388 | if (imprecise_pragma_seen) { |
| 389 | result = FP_Imprecise; |
| 390 | } else if (relaxed_pragma_seen) { |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 391 | result = FP_Relaxed; |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 392 | } |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 393 | |
Nick Kralevich | b81d697 | 2013-05-21 16:52:35 -0700 | [diff] [blame^] | 394 | #ifdef HAVE_ANDROID_OS |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 395 | // Provide an override for precsion via adb shell setprop |
| 396 | // adb shell setprop debug.rs.precision rs_fp_full |
| 397 | // adb shell setprop debug.rs.precision rs_fp_relaxed |
| 398 | // adb shell setprop debug.rs.precision rs_fp_imprecise |
| 399 | char precision_prop_buf[PROPERTY_VALUE_MAX]; |
| 400 | property_get("debug.rs.precision", precision_prop_buf, ""); |
| 401 | |
| 402 | if (precision_prop_buf[0]) { |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 403 | if (!relaxed_pragma.compare(precision_prop_buf)) { |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 404 | ALOGI("Switching to RS FP relaxed mode via setprop"); |
| 405 | result = FP_Relaxed; |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 406 | } else if (!imprecise_pragma.compare(precision_prop_buf)) { |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 407 | ALOGI("Switching to RS FP imprecise mode via setprop"); |
| 408 | result = FP_Imprecise; |
Stephen Hines | 688e4c0 | 2012-12-12 18:04:18 -0800 | [diff] [blame] | 409 | } else if (!full_pragma.compare(precision_prop_buf)) { |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 410 | ALOGI("Switching to RS FP full mode via setprop"); |
| 411 | result = FP_Full; |
| 412 | } |
| 413 | } |
Nick Kralevich | b81d697 | 2013-05-21 16:52:35 -0700 | [diff] [blame^] | 414 | #endif |
Shih-wei Liao | ed7fffb | 2012-06-30 11:27:59 -0700 | [diff] [blame] | 415 | |
| 416 | return result; |
Zonr Chang | 1e2adce | 2012-04-12 13:29:43 +0800 | [diff] [blame] | 417 | } |