rsdScriptGroup.cpp revision bd726b2159c14bd78d45f3157befcb733037f8d4
1/* 2 * Copyright (C) 2011 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 "rsdCore.h" 18 19#include <bcc/BCCContext.h> 20#include <bcc/Renderscript/RSCompilerDriver.h> 21#include <bcc/Renderscript/RSExecutable.h> 22#include <bcc/Renderscript/RSInfo.h> 23 24#include "rsScript.h" 25#include "rsScriptGroup.h" 26#include "rsdScriptGroup.h" 27#include "rsdBcc.h" 28 29using namespace android; 30using namespace android::renderscript; 31 32 33bool rsdScriptGroupInit(const android::renderscript::Context *rsc, 34 const android::renderscript::ScriptGroup *sg) { 35 return true; 36} 37 38void rsdScriptGroupSetInput(const android::renderscript::Context *rsc, 39 const android::renderscript::ScriptGroup *sg, 40 const android::renderscript::ScriptKernelID *kid, 41 android::renderscript::Allocation *) { 42} 43 44void rsdScriptGroupSetOutput(const android::renderscript::Context *rsc, 45 const android::renderscript::ScriptGroup *sg, 46 const android::renderscript::ScriptKernelID *kid, 47 android::renderscript::Allocation *) { 48} 49 50void rsdScriptGroupExecute(const android::renderscript::Context *rsc, 51 const android::renderscript::ScriptGroup *sg) { 52 53 Vector<Allocation *> ins; 54 Vector<Allocation *> outs; 55 Vector<const ScriptKernelID *> kernels; 56 57 for (size_t ct=0; ct < sg->mNodes.size(); ct++) { 58 ScriptGroup::Node *n = sg->mNodes[ct]; 59 Script *s = n->mKernels[0]->mScript; 60 61 //ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size()); 62 63 for (size_t ct2=0; ct2 < n->mInputs.size(); ct2++) { 64 if (n->mInputs[ct2]->mDstField->mScript) { 65 //ALOGE("field %p %zu", n->mInputs[ct2]->mDstField->mScript, n->mInputs[ct2]->mDstField->mSlot); 66 s->setSlot(n->mInputs[ct2]->mDstField->mSlot, n->mInputs[ct2]->mAlloc.get()); 67 } 68 } 69 70 for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) { 71 const ScriptKernelID *k = n->mKernels[ct2]; 72 Allocation *ain = NULL; 73 Allocation *aout = NULL; 74 75 for (size_t ct3=0; ct3 < n->mInputs.size(); ct3++) { 76 if (n->mInputs[ct3]->mDstKernel.get() == k) { 77 ain = n->mInputs[ct3]->mAlloc.get(); 78 //ALOGE(" link in %p", ain); 79 } 80 } 81 for (size_t ct3=0; ct3 < sg->mInputs.size(); ct3++) { 82 if (sg->mInputs[ct3]->mKernel == k) { 83 ain = sg->mInputs[ct3]->mAlloc.get(); 84 //ALOGE(" io in %p", ain); 85 } 86 } 87 88 for (size_t ct3=0; ct3 < n->mOutputs.size(); ct3++) { 89 if (n->mOutputs[ct3]->mSource.get() == k) { 90 aout = n->mOutputs[ct3]->mAlloc.get(); 91 //ALOGE(" link out %p", aout); 92 } 93 } 94 for (size_t ct3=0; ct3 < sg->mOutputs.size(); ct3++) { 95 if (sg->mOutputs[ct3]->mKernel == k) { 96 aout = sg->mOutputs[ct3]->mAlloc.get(); 97 //ALOGE(" io out %p", aout); 98 } 99 } 100 101 ins.add(ain); 102 outs.add(aout); 103 kernels.add(k); 104 } 105 106 } 107 108 RsdHal * dc = (RsdHal *)rsc->mHal.drv; 109 MTLaunchStruct mtls; 110 for (size_t ct=0; ct < ins.size(); ct++) { 111 112 Script *s = kernels[ct]->mScript; 113 DrvScript *drv = (DrvScript *)s->mHal.drv; 114 uint32_t slot = kernels[ct]->mSlot; 115 116 rsdScriptInvokeForEachMtlsSetup(rsc, ins[ct], outs[ct], NULL, 0, NULL, &mtls); 117 mtls.script = s; 118 mtls.fep.slot = slot; 119 120 if (drv->mIntrinsicID) { 121 mtls.kernel = (void (*)())drv->mIntrinsicFuncs.root; 122 mtls.fep.usr = drv->mIntrinsicData; 123 } else { 124 mtls.kernel = reinterpret_cast<ForEachFunc_t>( 125 drv->mExecutable->getExportForeachFuncAddrs()[slot]); 126 rsAssert(mtls.kernel != NULL); 127 mtls.sig = drv->mExecutable->getInfo().getExportForeachFuncs()[slot].second; 128 } 129 130// typedef void (*outer_foreach_t)( 131 // const android::renderscript::RsForEachStubParamStruct *, 132 // uint32_t x1, uint32_t x2, 133 // uint32_t instep, uint32_t outstep); 134 //outer_foreach_t fn = (outer_foreach_t) mtls->kernel; 135 136 rsdScriptLaunchThreads(rsc, s, slot, ins[ct], outs[ct], NULL, 0, NULL, &mtls); 137 } 138 139} 140 141void rsdScriptGroupDestroy(const android::renderscript::Context *rsc, 142 const android::renderscript::ScriptGroup *sg) { 143} 144 145 146