blob: 7442012fce95014540930423d564705eb0a7e3d6 [file] [log] [blame]
Zonr Chang1e2adce2012-04-12 13:29:43 +08001/*
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 Hinese198abe2012-07-27 18:05:41 -070018#include "bcc/Renderscript/RSInfo.h"
Zonr Chang1e2adce2012-04-12 13:29:43 +080019
Zonr Changf2907932012-04-13 11:56:21 +080020#include <dlfcn.h>
21
Zonr Chang1e2adce2012-04-12 13:29:43 +080022#include <cstring>
23#include <new>
Stephen Hines688e4c02012-12-12 18:04:18 -080024#include <string>
Zonr Chang1e2adce2012-04-12 13:29:43 +080025
Zonr Changc72c4dd2012-04-12 15:38:53 +080026#include "bcc/Support/FileBase.h"
Zonr Changef73a242012-04-12 16:44:01 +080027#include "bcc/Support/Log.h"
Zonr Chang1e2adce2012-04-12 13:29:43 +080028
Nick Kralevichb81d6972013-05-21 16:52:35 -070029#ifdef HAVE_ANDROID_OS
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -070030#include <cutils/properties.h>
Nick Kralevichb81d6972013-05-21 16:52:35 -070031#endif
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -070032
Zonr Chang1e2adce2012-04-12 13:29:43 +080033using namespace bcc;
34
35const char RSInfo::LibBCCPath[] = "/system/lib/libbcc.so";
Shih-wei Liaof7401ab2013-01-25 16:29:44 -080036const char RSInfo::LibCompilerRTPath[] = "/system/lib/libcompiler_rt.so";
Zonr Chang1e2adce2012-04-12 13:29:43 +080037const char RSInfo::LibRSPath[] = "/system/lib/libRS.so";
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070038const char RSInfo::LibCLCorePath[] = "/system/lib/libclcore.bc";
Stephen Hines8ee82d42013-04-16 19:57:34 -070039const char RSInfo::LibCLCoreDebugPath[] = "/system/lib/libclcore_debug.bc";
Michael Liaocdcce322012-09-25 21:59:39 -070040#if defined(ARCH_X86_HAVE_SSE2)
41const char RSInfo::LibCLCoreX86Path[] = "/system/lib/libclcore_x86.bc";
42#endif
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -070043#if defined(ARCH_ARM_HAVE_NEON)
44const char RSInfo::LibCLCoreNEONPath[] = "/system/lib/libclcore_neon.bc";
45#endif
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070046
Zonr Changf2907932012-04-13 11:56:21 +080047const uint8_t *RSInfo::LibBCCSHA1 = NULL;
Shih-wei Liaof7401ab2013-01-25 16:29:44 -080048const uint8_t *RSInfo::LibCompilerRTSHA1 = NULL;
Zonr Changf2907932012-04-13 11:56:21 +080049const uint8_t *RSInfo::LibRSSHA1 = NULL;
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070050const uint8_t *RSInfo::LibCLCoreSHA1 = NULL;
Stephen Hines8ee82d42013-04-16 19:57:34 -070051const uint8_t *RSInfo::LibCLCoreDebugSHA1 = NULL;
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -070052#if defined(ARCH_ARM_HAVE_NEON)
53const uint8_t *RSInfo::LibCLCoreNEONSHA1 = NULL;
54#endif
Zonr Chang1e2adce2012-04-12 13:29:43 +080055
Stephen Hines331310e2012-10-26 19:27:55 -070056bool RSInfo::LoadBuiltInSHA1Information() {
57#ifdef TARGET_BUILD
Zonr Changf2907932012-04-13 11:56:21 +080058 if (LibBCCSHA1 != NULL) {
59 // Loaded before.
Stephen Hines331310e2012-10-26 19:27:55 -070060 return true;
Zonr Chang1e2adce2012-04-12 13:29:43 +080061 }
62
Zonr Changf2907932012-04-13 11:56:21 +080063 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 Hines331310e2012-10-26 19:27:55 -070067 return false;
Zonr Changf2907932012-04-13 11:56:21 +080068 }
Zonr Chang1e2adce2012-04-12 13:29:43 +080069
Zonr Changf2907932012-04-13 11:56:21 +080070 LibBCCSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libbcc_so_SHA1"));
Shih-wei Liaof7401ab2013-01-25 16:29:44 -080071 LibCompilerRTSHA1 =
72 reinterpret_cast<const uint8_t *>(::dlsym(h, "libcompiler_rt_so_SHA1"));
Zonr Changf2907932012-04-13 11:56:21 +080073 LibRSSHA1 = reinterpret_cast<const uint8_t *>(::dlsym(h, "libRS_so_SHA1"));
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070074 LibCLCoreSHA1 =
75 reinterpret_cast<const uint8_t *>(::dlsym(h, "libclcore_bc_SHA1"));
Stephen Hines8ee82d42013-04-16 19:57:34 -070076 LibCLCoreDebugSHA1 =
77 reinterpret_cast<const uint8_t *>(::dlsym(h, "libclcore_debug_bc_SHA1"));
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -070078#if defined(ARCH_ARM_HAVE_NEON)
79 LibCLCoreNEONSHA1 =
80 reinterpret_cast<const uint8_t *>(::dlsym(h, "libclcore_neon_bc_SHA1"));
81#endif
Zonr Chang1e2adce2012-04-12 13:29:43 +080082
Stephen Hines331310e2012-10-26 19:27:55 -070083 return true;
84#else // TARGET_BUILD
85 return false;
86#endif // TARGET_BUILD
Zonr Chang1e2adce2012-04-12 13:29:43 +080087}
88
Stephen Hines01f05d42013-05-31 20:51:27 -070089android::String8 RSInfo::GetPath(const char *pFilename) {
90 android::String8 result(pFilename);
Zonr Chang1e2adce2012-04-12 13:29:43 +080091 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
104bool RSInfo::CheckDependency(const RSInfo &pInfo,
105 const char *pInputFilename,
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700106 const DependencyTableTy &pDeps) {
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -0700107 // 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 Liaof7401ab2013-01-25 16:29:44 -0800110 static const unsigned NumBuiltInDependencies = 5;
Stephen Hines8ee82d42013-04-16 19:57:34 -0700111#else
112 static const unsigned NumBuiltInDependencies = 6;
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -0700113#endif
Zonr Chang1e2adce2012-04-12 13:29:43 +0800114
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 Liaof7401ab2013-01-25 16:29:44 -0800126 const std::pair<const char *, const uint8_t *> &cache_libcompiler_rt_dep =
Zonr Chang1e2adce2012-04-12 13:29:43 +0800127 pInfo.mDependencyTable[1];
Shih-wei Liaof7401ab2013-01-25 16:29:44 -0800128 const std::pair<const char *, const uint8_t *> &cache_libRS_dep =
Shih-wei Liao2665c2f2012-04-25 04:06:52 -0700129 pInfo.mDependencyTable[2];
Shih-wei Liaof7401ab2013-01-25 16:29:44 -0800130 const std::pair<const char *, const uint8_t *> &cache_libclcore_dep =
131 pInfo.mDependencyTable[3];
Stephen Hines8ee82d42013-04-16 19:57:34 -0700132 const std::pair<const char *, const uint8_t *> &cache_libclcore_debug_dep =
133 pInfo.mDependencyTable[4];
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -0700134#if defined(ARCH_ARM_HAVE_NEON)
135 const std::pair<const char *, const uint8_t *> &cache_libclcore_neon_dep =
Stephen Hines8ee82d42013-04-16 19:57:34 -0700136 pInfo.mDependencyTable[5];
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -0700137#endif
Zonr Chang1e2adce2012-04-12 13:29:43 +0800138
139 // Check libbcc.so.
Zonr Changf2907932012-04-13 11:56:21 +0800140 if (::memcmp(cache_libbcc_dep.second, LibBCCSHA1, SHA1_DIGEST_LENGTH) != 0) {
Zonr Chang1e2adce2012-04-12 13:29:43 +0800141 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 Liaof7401ab2013-01-25 16:29:44 -0800149 // 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 Chang1e2adce2012-04-12 13:29:43 +0800160 // Check libRS.so.
Zonr Changf2907932012-04-13 11:56:21 +0800161 if (::memcmp(cache_libRS_dep.second, LibRSSHA1, SHA1_DIGEST_LENGTH) != 0) {
Zonr Chang1e2adce2012-04-12 13:29:43 +0800162 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 Liao2665c2f2012-04-25 04:06:52 -0700170 // 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 Hines8ee82d42013-04-16 19:57:34 -0700174 LibCLCorePath);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -0700175 PRINT_DEPENDENCY("current - ", LibCLCorePath, LibCLCoreSHA1);
176 PRINT_DEPENDENCY("cache - ", cache_libclcore_dep.first,
177 cache_libclcore_dep.second);
178 return false;
179 }
180
Stephen Hines8ee82d42013-04-16 19:57:34 -0700181 // 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 Liaob1cc74f2012-06-30 11:27:01 -0700192#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 Hines8ee82d42013-04-16 19:57:34 -0700197 LibCLCoreNEONPath);
Shih-wei Liaob1cc74f2012-06-30 11:27:01 -0700198 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 Chang1e2adce2012-04-12 13:29:43 +0800205 for (unsigned i = 0; i < pDeps.size(); i++) {
Zonr Chang1e2adce2012-04-12 13:29:43 +0800206 const std::pair<const char *, const uint8_t *> &cache_dep =
207 pInfo.mDependencyTable[i + NumBuiltInDependencies];
208
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700209 if ((::strcmp(pDeps[i].first, cache_dep.first) != 0) ||
210 (::memcmp(pDeps[i].second, cache_dep.second,
Zonr Changf2907932012-04-13 11:56:21 +0800211 SHA1_DIGEST_LENGTH) != 0)) {
Zonr Chang1e2adce2012-04-12 13:29:43 +0800212 ALOGD("Cache %s is dirty due to the source it dependends on has been "
213 "changed:", pInputFilename);
Shih-wei Liao7bcec852012-04-25 04:07:09 -0700214 PRINT_DEPENDENCY("given - ", pDeps[i].first, pDeps[i].second);
Zonr Chang1e2adce2012-04-12 13:29:43 +0800215 PRINT_DEPENDENCY("cache - ", cache_dep.first, cache_dep.second);
216 return false;
217 }
218 }
219 }
220
221 return true;
222}
223
224RSInfo::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
249RSInfo::~RSInfo() {
250 delete [] mStringPool;
251}
252
253bool 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
279void 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
339const 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
350rsinfo::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 Liaoed7fffb2012-06-30 11:27:59 -0700360RSInfo::FloatPrecision RSInfo::getFloatPrecisionRequirement() const {
Zonr Chang1e2adce2012-04-12 13:29:43 +0800361 // Check to see if we have any FP precision-related pragmas.
Stephen Hines688e4c02012-12-12 18:04:18 -0800362 std::string relaxed_pragma("rs_fp_relaxed");
363 std::string imprecise_pragma("rs_fp_imprecise");
364 std::string full_pragma("rs_fp_full");
Zonr Chang1e2adce2012-04-12 13:29:43 +0800365 bool relaxed_pragma_seen = false;
Stephen Hines688e4c02012-12-12 18:04:18 -0800366 bool imprecise_pragma_seen = false;
367 RSInfo::FloatPrecision result = FP_Full;
Zonr Chang1e2adce2012-04-12 13:29:43 +0800368
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 Hines688e4c02012-12-12 18:04:18 -0800373 if (!relaxed_pragma.compare(pragma_key)) {
374 if (relaxed_pragma_seen || imprecise_pragma_seen) {
375 ALOGE("Multiple float precision pragmas specified!");
Zonr Chang1e2adce2012-04-12 13:29:43 +0800376 }
Stephen Hines688e4c02012-12-12 18:04:18 -0800377 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 Chang1e2adce2012-04-12 13:29:43 +0800383 }
384 }
385
386 // Imprecise is selected over Relaxed precision.
387 // In the absence of both, we stick to the default Full precision.
Stephen Hines688e4c02012-12-12 18:04:18 -0800388 if (imprecise_pragma_seen) {
389 result = FP_Imprecise;
390 } else if (relaxed_pragma_seen) {
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700391 result = FP_Relaxed;
Zonr Chang1e2adce2012-04-12 13:29:43 +0800392 }
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700393
Nick Kralevichb81d6972013-05-21 16:52:35 -0700394#ifdef HAVE_ANDROID_OS
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700395 // 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 Hines688e4c02012-12-12 18:04:18 -0800403 if (!relaxed_pragma.compare(precision_prop_buf)) {
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700404 ALOGI("Switching to RS FP relaxed mode via setprop");
405 result = FP_Relaxed;
Stephen Hines688e4c02012-12-12 18:04:18 -0800406 } else if (!imprecise_pragma.compare(precision_prop_buf)) {
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700407 ALOGI("Switching to RS FP imprecise mode via setprop");
408 result = FP_Imprecise;
Stephen Hines688e4c02012-12-12 18:04:18 -0800409 } else if (!full_pragma.compare(precision_prop_buf)) {
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700410 ALOGI("Switching to RS FP full mode via setprop");
411 result = FP_Full;
412 }
413 }
Nick Kralevichb81d6972013-05-21 16:52:35 -0700414#endif
Shih-wei Liaoed7fffb2012-06-30 11:27:59 -0700415
416 return result;
Zonr Chang1e2adce2012-04-12 13:29:43 +0800417}