rsdBcc.cpp revision 709a0978ae141198018ca9769f8d96292a8928e6
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#include "utils/Vector.h" 29#include "utils/Timers.h" 30#include "utils/StopWatch.h" 31 32using namespace android; 33using namespace android::renderscript; 34 35 36bool rsdScriptInit(const Context *rsc, 37 ScriptC *script, 38 char const *resName, 39 char const *cacheDir, 40 uint8_t const *bitcode, 41 size_t bitcodeSize, 42 uint32_t flags) { 43 RsdHal *dc = (RsdHal *)rsc->mHal.drv; 44 RsdCpuReference::CpuScript * cs = dc->mCpuRef->createScript(script, resName, cacheDir, 45 bitcode, bitcodeSize, flags); 46 if (cs == NULL) { 47 return false; 48 } 49 script->mHal.drv = cs; 50 cs->populateScript(script); 51 return true; 52} 53 54bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) { 55 RsdHal *dc = (RsdHal *)rsc->mHal.drv; 56 RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e); 57 if (cs == NULL) { 58 return false; 59 } 60 s->mHal.drv = cs; 61 cs->populateScript(s); 62 return true; 63} 64 65void rsdScriptInvokeForEach(const Context *rsc, 66 Script *s, 67 uint32_t slot, 68 const Allocation * ain, 69 Allocation * aout, 70 const void * usr, 71 uint32_t usrLen, 72 const RsScriptCall *sc) { 73 74 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 75 cs->invokeForEach(slot, ain, aout, usr, usrLen, sc); 76} 77 78 79int rsdScriptInvokeRoot(const Context *dc, Script *s) { 80 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 81 return cs->invokeRoot(); 82} 83 84void rsdScriptInvokeInit(const Context *dc, Script *s) { 85 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 86 cs->invokeInit(); 87} 88 89void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) { 90 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 91 cs->invokeFreeChildren(); 92} 93 94void rsdScriptInvokeFunction(const Context *dc, Script *s, 95 uint32_t slot, 96 const void *params, 97 size_t paramLength) { 98 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 99 cs->invokeFunction(slot, params, paramLength); 100} 101 102void rsdScriptSetGlobalVar(const Context *dc, const Script *s, 103 uint32_t slot, void *data, size_t dataLength) { 104 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 105 cs->setGlobalVar(slot, data, dataLength); 106} 107 108void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s, 109 uint32_t slot, void *data, size_t dataLength, 110 const android::renderscript::Element *elem, 111 const size_t *dims, size_t dimLength) { 112 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 113 cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength); 114} 115 116void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) { 117 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 118 cs->setGlobalBind(slot, data); 119} 120 121void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) { 122 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 123 cs->setGlobalObj(slot, data); 124} 125 126void rsdScriptDestroy(const Context *dc, Script *s) { 127 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; 128 delete cs; 129 s->mHal.drv = NULL; 130} 131 132 133Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc, 134 const android::renderscript::Script *sc, 135 const void *ptr) { 136 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv; 137 return cs->getAllocationForPointer(ptr); 138} 139 140