rsdScriptGroup.cpp revision cf9ea9f4145cae663f439b1c2dab956fa37180bb
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        //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        mtls.fep.slot = slot;
110
111        if (drv->mIntrinsicID) {
112            mtls.kernel = (void (*)())drv->mIntrinsicFuncs.root;
113            mtls.fep.usr = drv->mIntrinsicData;
114        } else {
115            mtls.kernel = reinterpret_cast<ForEachFunc_t>(
116                              drv->mExecutable->getExportForeachFuncAddrs()[slot]);
117            rsAssert(mtls.kernel != NULL);
118            mtls.sig = drv->mExecutable->getInfo().getExportForeachFuncs()[slot].second;
119        }
120
121//        typedef void (*outer_foreach_t)(
122  //          const android::renderscript::RsForEachStubParamStruct *,
123    //        uint32_t x1, uint32_t x2,
124      //      uint32_t instep, uint32_t outstep);
125        //outer_foreach_t fn = (outer_foreach_t) mtls->kernel;
126
127        rsdScriptLaunchThreads(rsc, s, slot, ins[ct], outs[ct], NULL, 0, NULL, &mtls);
128    }
129
130}
131
132void rsdScriptGroupDestroy(const android::renderscript::Context *rsc,
133                           const android::renderscript::ScriptGroup *sg) {
134}
135
136
137