Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +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 | |
Stephen Hines | e198abe | 2012-07-27 18:05:41 -0700 | [diff] [blame] | 17 | #include "bcc/Renderscript/RSScript.h" |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 18 | |
Stephen Hines | e198abe | 2012-07-27 18:05:41 -0700 | [diff] [blame] | 19 | #include "bcc/Renderscript/RSInfo.h" |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 20 | #include "bcc/Source.h" |
Zonr Chang | ef73a24 | 2012-04-12 16:44:01 +0800 | [diff] [blame] | 21 | #include "bcc/Support/Log.h" |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 22 | |
Zonr Chang | ade9277 | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 23 | using namespace bcc; |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 24 | |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 25 | bool RSScript::LinkRuntime(RSScript &pScript, const char *rt_path) { |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 26 | // Using the same context with the source in pScript. |
| 27 | BCCContext &context = pScript.getSource().getContext(); |
Shih-wei Liao | b8f9fb1 | 2012-06-30 11:28:25 -0700 | [diff] [blame] | 28 | const char* core_lib = RSInfo::LibCLCorePath; |
| 29 | |
Stephen Hines | 5aa70e1 | 2013-10-02 18:12:31 -0700 | [diff] [blame] | 30 | // x86 devices will use an optimized library. |
WeiTang | 36e642c | 2014-04-04 23:36:34 +0800 | [diff] [blame^] | 31 | #if defined(__i386__) || defined(__x86_64__) |
Michael Liao | cdcce32 | 2012-09-25 21:59:39 -0700 | [diff] [blame] | 32 | core_lib = RSInfo::LibCLCoreX86Path; |
| 33 | #endif |
| 34 | |
Shih-wei Liao | b8f9fb1 | 2012-06-30 11:28:25 -0700 | [diff] [blame] | 35 | // NEON-capable devices can use an accelerated math library for all |
| 36 | // reduced precision scripts. |
| 37 | #if defined(ARCH_ARM_HAVE_NEON) |
| 38 | const RSInfo* info = pScript.getInfo(); |
| 39 | if ((info != NULL) && |
| 40 | (info->getFloatPrecisionRequirement() != RSInfo::FP_Full)) { |
| 41 | core_lib = RSInfo::LibCLCoreNEONPath; |
| 42 | } |
| 43 | #endif |
| 44 | |
Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 45 | if (rt_path != NULL) { |
| 46 | core_lib = rt_path; |
| 47 | } |
| 48 | |
Shih-wei Liao | b8f9fb1 | 2012-06-30 11:28:25 -0700 | [diff] [blame] | 49 | Source *libclcore_source = Source::CreateFromFile(context, core_lib); |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 50 | if (libclcore_source == NULL) { |
Shih-wei Liao | b8f9fb1 | 2012-06-30 11:28:25 -0700 | [diff] [blame] | 51 | ALOGE("Failed to load Renderscript library '%s' to link!", core_lib); |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 52 | return false; |
| 53 | } |
| 54 | |
Stephen Hines | 06731a6 | 2013-02-12 19:29:42 -0800 | [diff] [blame] | 55 | if (NULL != pScript.mLinkRuntimeCallback) { |
| 56 | pScript.mLinkRuntimeCallback(&pScript, |
| 57 | &pScript.getSource().getModule(), &libclcore_source->getModule()); |
| 58 | } |
| 59 | |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 60 | if (!pScript.getSource().merge(*libclcore_source, |
| 61 | /* pPreserveSource */false)) { |
Stephen Hines | e198abe | 2012-07-27 18:05:41 -0700 | [diff] [blame] | 62 | ALOGE("Failed to link Renderscript library '%s'!", core_lib); |
Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 63 | delete libclcore_source; |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 70 | RSScript::RSScript(Source &pSource) |
Zonr Chang | ade9277 | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 71 | : Script(pSource), mInfo(NULL), mCompilerVersion(0), |
Stephen Hines | 06731a6 | 2013-02-12 19:29:42 -0800 | [diff] [blame] | 72 | mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(NULL), |
| 73 | mEmbedInfo(false) { } |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 74 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 75 | bool RSScript::doReset() { |
Zonr Chang | ade9277 | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 76 | mInfo = NULL; |
| 77 | mCompilerVersion = 0; |
| 78 | mOptimizationLevel = kOptLvl3; |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 79 | return true; |
| 80 | } |