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
34 using namespace android;
35 using namespace android::renderscript;
36
37
rsdScriptInit(const Context * rsc,ScriptC * script,char const * resName,char const * cacheDir,uint8_t const * bitcode,size_t bitcodeSize,uint32_t flags)38 bool 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
rsdInitIntrinsic(const Context * rsc,Script * s,RsScriptIntrinsicID iid,Element * e)57 bool 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
rsdScriptInvokeForEach(const Context * rsc,Script * s,uint32_t slot,const Allocation * ain,Allocation * aout,const void * usr,size_t usrLen,const RsScriptCall * sc)69 void 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
rsdScriptInvokeForEachMulti(const Context * rsc,Script * s,uint32_t slot,const Allocation ** ains,size_t inLen,Allocation * aout,const void * usr,size_t usrLen,const RsScriptCall * sc)89 void 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
rsdScriptInvokeRoot(const Context * dc,Script * s)104 int rsdScriptInvokeRoot(const Context *dc, Script *s) {
105 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
106 return cs->invokeRoot();
107 }
108
rsdScriptInvokeInit(const Context * dc,Script * s)109 void rsdScriptInvokeInit(const Context *dc, Script *s) {
110 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
111 cs->invokeInit();
112 }
113
rsdScriptInvokeFreeChildren(const Context * dc,Script * s)114 void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) {
115 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
116 cs->invokeFreeChildren();
117 }
118
rsdScriptInvokeFunction(const Context * dc,Script * s,uint32_t slot,const void * params,size_t paramLength)119 void 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
rsdScriptSetGlobalVar(const Context * dc,const Script * s,uint32_t slot,void * data,size_t dataLength)127 void rsdScriptSetGlobalVar(const Context *dc, const Script *s,
128 uint32_t slot, void *data, size_t dataLength) {
129 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
130 cs->setGlobalVar(slot, data, dataLength);
131 }
132
rsdScriptGetGlobalVar(const Context * dc,const Script * s,uint32_t slot,void * data,size_t dataLength)133 void rsdScriptGetGlobalVar(const Context *dc, const Script *s,
134 uint32_t slot, void *data, size_t dataLength) {
135 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
136 cs->getGlobalVar(slot, data, dataLength);
137 }
138
139
rsdScriptSetGlobalVarWithElemDims(const Context * dc,const Script * s,uint32_t slot,void * data,size_t dataLength,const android::renderscript::Element * elem,const uint32_t * dims,size_t dimLength)140 void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s,
141 uint32_t slot, void *data, size_t dataLength,
142 const android::renderscript::Element *elem,
143 const uint32_t *dims, size_t dimLength) {
144 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
145 cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength);
146 }
147
rsdScriptSetGlobalBind(const Context * dc,const Script * s,uint32_t slot,Allocation * data)148 void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) {
149 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
150 cs->setGlobalBind(slot, data);
151 }
152
rsdScriptSetGlobalObj(const Context * dc,const Script * s,uint32_t slot,ObjectBase * data)153 void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) {
154 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
155 cs->setGlobalObj(slot, data);
156 }
157
rsdScriptDestroy(const Context * dc,Script * s)158 void rsdScriptDestroy(const Context *dc, Script *s) {
159 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
160 delete cs;
161 s->mHal.drv = nullptr;
162 }
163
164
rsdScriptGetAllocationForPointer(const android::renderscript::Context * dc,const android::renderscript::Script * sc,const void * ptr)165 Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
166 const android::renderscript::Script *sc,
167 const void *ptr) {
168 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
169 return cs->getAllocationForPointer(ptr);
170 }
171
rsdScriptUpdateCachedObject(const Context * rsc,const Script * script,rs_script * obj)172 void rsdScriptUpdateCachedObject(const Context *rsc,
173 const Script *script,
174 rs_script *obj)
175 {
176 obj->p = script;
177 #ifdef __LP64__
178 obj->r = nullptr;
179 if (script != nullptr) {
180 obj->v1 = script->mHal.drv;
181 } else {
182 obj->v1 = nullptr;
183 }
184 obj->v2 = nullptr;
185 #endif
186 }
187