1ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang/* 2ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * Copyright 2012, The Android Open Source Project 3ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * 4ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * Licensed under the Apache License, Version 2.0 (the "License"); 5ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * you may not use this file except in compliance with the License. 6ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * You may obtain a copy of the License at 7ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * 8ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * http://www.apache.org/licenses/LICENSE-2.0 9ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * 10ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * Unless required by applicable law or agreed to in writing, software 11ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * distributed under the License is distributed on an "AS IS" BASIS, 12ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * See the License for the specific language governing permissions and 14ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang * limitations under the License. 15ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang */ 16ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang 17e198abec6c5e3eab380ccf6897b0a0b9c2dd92ddStephen Hines#include "bcc/Renderscript/RSScript.h" 18ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang 19e198abec6c5e3eab380ccf6897b0a0b9c2dd92ddStephen Hines#include "bcc/Renderscript/RSInfo.h" 202665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao#include "bcc/Source.h" 21ef73a242762bcd8113b9b65ceccbe7d909b5acbcZonr Chang#include "bcc/Support/Log.h" 22ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang 23ade92778b99382413ff9c556c724dd3f447e5dfbZonr Changusing namespace bcc; 24ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang 252665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liaobool RSScript::LinkRuntime(RSScript &pScript) { 262665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao // Using the same context with the source in pScript. 272665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao BCCContext &context = pScript.getSource().getContext(); 28b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao const char* core_lib = RSInfo::LibCLCorePath; 29b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao 30b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao // NEON-capable devices can use an accelerated math library for all 31b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao // reduced precision scripts. 32b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao#if defined(ARCH_ARM_HAVE_NEON) 33b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao const RSInfo* info = pScript.getInfo(); 34b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao if ((info != NULL) && 35b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao (info->getFloatPrecisionRequirement() != RSInfo::FP_Full)) { 36b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao core_lib = RSInfo::LibCLCoreNEONPath; 37b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao } 38b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao#endif 39b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao 40b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao Source *libclcore_source = Source::CreateFromFile(context, core_lib); 412665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao if (libclcore_source == NULL) { 42b8f9fb12f2d879f8f83e8dda1f302741a124513dShih-wei Liao ALOGE("Failed to load Renderscript library '%s' to link!", core_lib); 432665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao return false; 442665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao } 452665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao 462665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao if (!pScript.getSource().merge(*libclcore_source, 472665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao /* pPreserveSource */false)) { 48e198abec6c5e3eab380ccf6897b0a0b9c2dd92ddStephen Hines ALOGE("Failed to link Renderscript library '%s'!", core_lib); 492665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao delete libclcore_source; 502665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao return false; 512665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao } 522665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao 532665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao return true; 542665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao} 552665c2f94ed14c1d15925d83b47aa519a11dafe5Shih-wei Liao 56ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr ChangRSScript::RSScript(Source &pSource) 57ade92778b99382413ff9c556c724dd3f447e5dfbZonr Chang : Script(pSource), mInfo(NULL), mCompilerVersion(0), 58ade92778b99382413ff9c556c724dd3f447e5dfbZonr Chang mOptimizationLevel(kOptLvl3) { } 59ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang 60ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Changbool RSScript::doReset() { 61ade92778b99382413ff9c556c724dd3f447e5dfbZonr Chang mInfo = NULL; 62ade92778b99382413ff9c556c724dd3f447e5dfbZonr Chang mCompilerVersion = 0; 63ade92778b99382413ff9c556c724dd3f447e5dfbZonr Chang mOptimizationLevel = kOptLvl3; 64ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang return true; 65ccc39a8f412edaec2d231ed1ec70ff25fa83af37Zonr Chang} 66