rsdBcc.cpp revision 6c1876bbef1b2c89975dce91230a168bd2d2ce4c
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#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
29#include "utils/Vector.h"
30#include "utils/Timers.h"
31#include "utils/StopWatch.h"
32#endif
33
34using namespace android;
35using namespace android::renderscript;
36
37
38bool rsdScriptInit(const Context *rsc,
39                     ScriptC *script,
40                     char const *resName,
41                     char const *cacheDir,
42                     uint8_t const *bitcode,
43                     size_t bitcodeSize,
44                     uint32_t flags) {
45    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
46    RsdCpuReference::CpuScript * cs =
47        dc->mCpuRef->createScript(script, resName, cacheDir, bitcode,
48                                  bitcodeSize, flags);
49    if (cs == nullptr) {
50        return false;
51    }
52    script->mHal.drv = cs;
53    cs->populateScript(script);
54    return true;
55}
56
57bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid,
58                      Element *e) {
59    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
60    RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e);
61    if (cs == nullptr) {
62        return false;
63    }
64    s->mHal.drv = cs;
65    cs->populateScript(s);
66    return true;
67}
68
69void rsdScriptInvokeForEach(const Context *rsc,
70                            Script *s,
71                            uint32_t slot,
72                            const Allocation * ain,
73                            Allocation * aout,
74                            const void * usr,
75                            size_t usrLen,
76                            const RsScriptCall *sc) {
77
78    if (ain == nullptr) {
79        rsdScriptInvokeForEachMulti(rsc, s, slot, nullptr, 0, aout, usr, usrLen,
80                                    sc);
81    } else {
82        const Allocation *ains[1] = {ain};
83
84        rsdScriptInvokeForEachMulti(rsc, s, slot, ains, 1, aout, usr, usrLen,
85                                    sc);
86    }
87}
88
89void rsdScriptInvokeForEachMulti(const Context *rsc,
90                                 Script *s,
91                                 uint32_t slot,
92                                 const Allocation ** ains,
93                                 size_t inLen,
94                                 Allocation * aout,
95                                 const void * usr,
96                                 size_t usrLen,
97                                 const RsScriptCall *sc) {
98
99    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
100    cs->invokeForEach(slot, ains, inLen, aout, usr, usrLen, sc);
101}
102
103
104int rsdScriptInvokeRoot(const Context *dc, Script *s) {
105    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
106    return cs->invokeRoot();
107}
108
109void rsdScriptInvokeInit(const Context *dc, Script *s) {
110    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
111    cs->invokeInit();
112}
113
114void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) {
115    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
116    cs->invokeFreeChildren();
117}
118
119void rsdScriptInvokeFunction(const Context *dc, Script *s,
120                            uint32_t slot,
121                            const void *params,
122                            size_t paramLength) {
123    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
124    cs->invokeFunction(slot, params, paramLength);
125}
126
127void rsdScriptInvokeReduce(const Context *dc, Script *s,
128                           uint32_t slot,
129                           const Allocation *ain,
130                           Allocation *aout,
131                           const RsScriptCall *sc) {
132    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
133    cs->invokeReduce(slot, ain, aout, sc);
134}
135
136void rsdScriptInvokeReduceNew(const Context *dc, Script *s,
137                              uint32_t slot,
138                              const Allocation ** ains, size_t inLen,
139                              Allocation *aout,
140                              const RsScriptCall *sc) {
141    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
142    cs->invokeReduceNew(slot, ains, inLen, aout, sc);
143}
144
145void rsdScriptSetGlobalVar(const Context *dc, const Script *s,
146                           uint32_t slot, void *data, size_t dataLength) {
147    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
148    cs->setGlobalVar(slot, data, dataLength);
149}
150
151void rsdScriptGetGlobalVar(const Context *dc, const Script *s,
152                           uint32_t slot, void *data, size_t dataLength) {
153    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
154    cs->getGlobalVar(slot, data, dataLength);
155}
156
157
158void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s,
159                                       uint32_t slot, void *data, size_t dataLength,
160                                       const android::renderscript::Element *elem,
161                                       const uint32_t *dims, size_t dimLength) {
162    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
163    cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength);
164}
165
166void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) {
167    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
168    cs->setGlobalBind(slot, data);
169}
170
171void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) {
172    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
173    cs->setGlobalObj(slot, data);
174}
175
176void rsdScriptDestroy(const Context *dc, Script *s) {
177    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
178    delete cs;
179    s->mHal.drv = nullptr;
180}
181
182
183Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
184                                              const android::renderscript::Script *sc,
185                                              const void *ptr) {
186    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
187    return cs->getAllocationForPointer(ptr);
188}
189
190void rsdScriptUpdateCachedObject(const Context *rsc,
191                                 const Script *script,
192                                 rs_script *obj)
193{
194    obj->p = script;
195#ifdef __LP64__
196    obj->r = nullptr;
197    if (script != nullptr) {
198        obj->v1 = script->mHal.drv;
199    } else {
200        obj->v1 = nullptr;
201    }
202    obj->v2 = nullptr;
203#endif
204}
205