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