rsdBcc.cpp revision 4b2bea3dc20865f3a198797702e19912a6a2171c
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 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#include "../cpu_ref/rsd_cpu.h" 18 19#include "rsdCore.h" 20 21#include "rsdBcc.h" 22#include "rsdAllocation.h" 23 24#include "rsContext.h" 25#include "rsElement.h" 26#include "rsScriptC.h" 27 28#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) 29#include "utils/Vector.h" 30#include "utils/Timers.h" 31#include "utils/StopWatch.h" 32#endif 33 34using namespace android; 35using namespace android::renderscript; 36 37 38bool rsdScriptInit(const Context *rsc, 39 ScriptC *script, 40 char const *resName, 41 char const *cacheDir, 42 uint8_t const *bitcode, 43 size_t bitcodeSize, 44 uint32_t flags) { 45 RsdHal *dc = (RsdHal *)rsc->mHal.drv; 46 RsdCpuReference::CpuScript * cs = dc->mCpuRef->createScript(script, resName, cacheDir, 47 bitcode, bitcodeSize, flags); 48 if (cs == NULL) { 49 return false; 50 } 51 script->mHal.drv = cs; 52 cs->populateScript(script); 53 return true; 54} 55 56bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) { 57 RsdHal *dc = (RsdHal *)rsc->mHal.drv; 58 RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e); 59 if (cs == NULL) { 60 return false; 61 } 62 s->mHal.drv = cs; 63 cs->populateScript(s); 64 return true; 65} 66 67void rsdScriptInvokeForEach(const Context *rsc, 68 Script *s, 69 uint32_t slot, 70 const Allocation * ain, 71 Allocation * aout, 72 const void * usr, 73 size_t usrLen, 74 const RsScriptCall *sc) { 75 76 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 77 cs->invokeForEach(slot, ain, aout, usr, usrLen, sc); 78} 79 80void rsdScriptInvokeForEachMulti(const Context *rsc, 81 Script *s, 82 uint32_t slot, 83 const Allocation ** ains, 84 size_t inLen, 85 Allocation * aout, 86 const void * usr, 87 size_t usrLen, 88 const RsScriptCall *sc) { 89 90 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 91 cs->invokeForEachMulti(slot, ains, inLen, aout, usr, usrLen, sc); 92} 93 94 95int rsdScriptInvokeRoot(const Context *dc, Script *s) { 96 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 97 return cs->invokeRoot(); 98} 99 100void rsdScriptInvokeInit(const Context *dc, Script *s) { 101 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 102 cs->invokeInit(); 103} 104 105void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) { 106 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 107 cs->invokeFreeChildren(); 108} 109 110void rsdScriptInvokeFunction(const Context *dc, Script *s, 111 uint32_t slot, 112 const void *params, 113 size_t paramLength) { 114 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 115 cs->invokeFunction(slot, params, paramLength); 116} 117 118void rsdScriptSetGlobalVar(const Context *dc, const Script *s, 119 uint32_t slot, void *data, size_t dataLength) { 120 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 121 cs->setGlobalVar(slot, data, dataLength); 122} 123 124void rsdScriptGetGlobalVar(const Context *dc, const Script *s, 125 uint32_t slot, void *data, size_t dataLength) { 126 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 127 cs->getGlobalVar(slot, data, dataLength); 128} 129 130 131void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s, 132 uint32_t slot, void *data, size_t dataLength, 133 const android::renderscript::Element *elem, 134 const uint32_t *dims, size_t dimLength) { 135 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 136 cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength); 137} 138 139void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) { 140 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 141 cs->setGlobalBind(slot, data); 142} 143 144void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) { 145 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 146 cs->setGlobalObj(slot, data); 147} 148 149void rsdScriptDestroy(const Context *dc, Script *s) { 150 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 151 delete cs; 152 s->mHal.drv = NULL; 153} 154 155 156Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc, 157 const android::renderscript::Script *sc, 158 const void *ptr) { 159 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv; 160 return cs->getAllocationForPointer(ptr); 161} 162 163void rsdScriptUpdateCachedObject(const Context *rsc, 164 const Script *script, 165 rs_script *obj) 166{ 167 obj->p = script; 168#ifdef __LP64__ 169 obj->r = NULL; 170 if (script != NULL) { 171 obj->v1 = script->mHal.drv; 172 } else { 173 obj->v1 = NULL; 174 } 175 obj->v2 = NULL; 176#endif 177} 178