Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame^] | 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 | |
| 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
| 32 | |
| 33 | bool rsdScriptGroupInit(const android::renderscript::Context *rsc, |
| 34 | const android::renderscript::ScriptGroup *sg) { |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | void rsdScriptGroupSetInput(const android::renderscript::Context *rsc, |
| 39 | const android::renderscript::ScriptGroup *sg, |
| 40 | const android::renderscript::ScriptKernelID *kid, |
| 41 | android::renderscript::Allocation *) { |
| 42 | } |
| 43 | |
| 44 | void rsdScriptGroupSetOutput(const android::renderscript::Context *rsc, |
| 45 | const android::renderscript::ScriptGroup *sg, |
| 46 | const android::renderscript::ScriptKernelID *kid, |
| 47 | android::renderscript::Allocation *) { |
| 48 | } |
| 49 | |
| 50 | void 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 | //ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size()); |
| 60 | |
| 61 | for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) { |
| 62 | const ScriptKernelID *k = n->mKernels[ct2]; |
| 63 | Allocation *ain = NULL; |
| 64 | Allocation *aout = NULL; |
| 65 | |
| 66 | for (size_t ct3=0; ct3 < n->mInputs.size(); ct3++) { |
| 67 | if (n->mInputs[ct3]->mDstKernel.get() == k) { |
| 68 | ain = n->mInputs[ct3]->mAlloc.get(); |
| 69 | //ALOGE(" link in %p", ain); |
| 70 | } |
| 71 | } |
| 72 | for (size_t ct3=0; ct3 < sg->mInputs.size(); ct3++) { |
| 73 | if (sg->mInputs[ct3]->mKernel == k) { |
| 74 | ain = sg->mInputs[ct3]->mAlloc.get(); |
| 75 | //ALOGE(" io in %p", ain); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | for (size_t ct3=0; ct3 < n->mOutputs.size(); ct3++) { |
| 80 | if (n->mOutputs[ct3]->mSource.get() == k) { |
| 81 | aout = n->mOutputs[ct3]->mAlloc.get(); |
| 82 | //ALOGE(" link out %p", aout); |
| 83 | } |
| 84 | } |
| 85 | for (size_t ct3=0; ct3 < sg->mOutputs.size(); ct3++) { |
| 86 | if (sg->mOutputs[ct3]->mKernel == k) { |
| 87 | aout = sg->mOutputs[ct3]->mAlloc.get(); |
| 88 | //ALOGE(" io out %p", aout); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | ins.add(ain); |
| 93 | outs.add(aout); |
| 94 | kernels.add(k); |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |
| 99 | RsdHal * dc = (RsdHal *)rsc->mHal.drv; |
| 100 | MTLaunchStruct mtls; |
| 101 | for (size_t ct=0; ct < ins.size(); ct++) { |
| 102 | |
| 103 | Script *s = kernels[ct]->mScript; |
| 104 | DrvScript *drv = (DrvScript *)s->mHal.drv; |
| 105 | uint32_t slot = kernels[ct]->mSlot; |
| 106 | |
| 107 | rsdScriptInvokeForEachMtlsSetup(rsc, ins[ct], outs[ct], NULL, 0, NULL, &mtls); |
| 108 | mtls.script = s; |
| 109 | |
| 110 | if (drv->mIntrinsicID) { |
| 111 | mtls.kernel = (void (*)())drv->mIntrinsicFuncs.root; |
| 112 | mtls.fep.usr = drv->mIntrinsicData; |
| 113 | } else { |
| 114 | mtls.kernel = reinterpret_cast<ForEachFunc_t>( |
| 115 | drv->mExecutable->getExportForeachFuncAddrs()[slot]); |
| 116 | rsAssert(mtls.kernel != NULL); |
| 117 | mtls.sig = drv->mExecutable->getInfo().getExportForeachFuncs()[slot].second; |
| 118 | } |
| 119 | |
| 120 | // typedef void (*outer_foreach_t)( |
| 121 | // const android::renderscript::RsForEachStubParamStruct *, |
| 122 | // uint32_t x1, uint32_t x2, |
| 123 | // uint32_t instep, uint32_t outstep); |
| 124 | //outer_foreach_t fn = (outer_foreach_t) mtls->kernel; |
| 125 | |
| 126 | rsdScriptLaunchThreads(rsc, s, slot, ins[ct], outs[ct], NULL, 0, NULL, &mtls); |
| 127 | } |
| 128 | |
| 129 | } |
| 130 | |
| 131 | void rsdScriptGroupDestroy(const android::renderscript::Context *rsc, |
| 132 | const android::renderscript::ScriptGroup *sg) { |
| 133 | } |
| 134 | |
| 135 | |