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]; |
Jason Sams | bd726b2 | 2012-10-09 16:10:34 -0700 | [diff] [blame] | 59 | Script *s = n->mKernels[0]->mScript; |
| 60 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 61 | //ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size()); |
| 62 | |
Jason Sams | bd726b2 | 2012-10-09 16:10:34 -0700 | [diff] [blame] | 63 | for (size_t ct2=0; ct2 < n->mInputs.size(); ct2++) { |
Jason Sams | 15ff402 | 2012-10-12 14:21:49 -0700 | [diff] [blame] | 64 | if (n->mInputs[ct2]->mDstField.get() && n->mInputs[ct2]->mDstField->mScript) { |
Jason Sams | bd726b2 | 2012-10-09 16:10:34 -0700 | [diff] [blame] | 65 | //ALOGE("field %p %zu", n->mInputs[ct2]->mDstField->mScript, n->mInputs[ct2]->mDstField->mSlot); |
Jason Sams | 78b050e | 2012-10-15 16:25:53 -0700 | [diff] [blame] | 66 | s->setVarObj(n->mInputs[ct2]->mDstField->mSlot, n->mInputs[ct2]->mAlloc.get()); |
Jason Sams | bd726b2 | 2012-10-09 16:10:34 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 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 | |
Jason Sams | b801b94 | 2012-10-10 12:07:38 -0700 | [diff] [blame] | 101 | if ((k->mHasKernelOutput == (aout != NULL)) && |
| 102 | (k->mHasKernelInput == (ain != NULL))) { |
| 103 | ins.add(ain); |
| 104 | outs.add(aout); |
| 105 | kernels.add(k); |
| 106 | } |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | } |
| 110 | |
| 111 | RsdHal * dc = (RsdHal *)rsc->mHal.drv; |
| 112 | MTLaunchStruct mtls; |
| 113 | for (size_t ct=0; ct < ins.size(); ct++) { |
| 114 | |
| 115 | Script *s = kernels[ct]->mScript; |
| 116 | DrvScript *drv = (DrvScript *)s->mHal.drv; |
| 117 | uint32_t slot = kernels[ct]->mSlot; |
| 118 | |
| 119 | rsdScriptInvokeForEachMtlsSetup(rsc, ins[ct], outs[ct], NULL, 0, NULL, &mtls); |
| 120 | mtls.script = s; |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 121 | mtls.fep.slot = slot; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 122 | |
| 123 | if (drv->mIntrinsicID) { |
| 124 | mtls.kernel = (void (*)())drv->mIntrinsicFuncs.root; |
| 125 | mtls.fep.usr = drv->mIntrinsicData; |
| 126 | } else { |
| 127 | mtls.kernel = reinterpret_cast<ForEachFunc_t>( |
| 128 | drv->mExecutable->getExportForeachFuncAddrs()[slot]); |
| 129 | rsAssert(mtls.kernel != NULL); |
| 130 | mtls.sig = drv->mExecutable->getInfo().getExportForeachFuncs()[slot].second; |
| 131 | } |
| 132 | |
| 133 | // typedef void (*outer_foreach_t)( |
| 134 | // const android::renderscript::RsForEachStubParamStruct *, |
| 135 | // uint32_t x1, uint32_t x2, |
| 136 | // uint32_t instep, uint32_t outstep); |
| 137 | //outer_foreach_t fn = (outer_foreach_t) mtls->kernel; |
| 138 | |
| 139 | rsdScriptLaunchThreads(rsc, s, slot, ins[ct], outs[ct], NULL, 0, NULL, &mtls); |
| 140 | } |
| 141 | |
| 142 | } |
| 143 | |
| 144 | void rsdScriptGroupDestroy(const android::renderscript::Context *rsc, |
| 145 | const android::renderscript::ScriptGroup *sg) { |
| 146 | } |
| 147 | |
| 148 | |