• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
18 #include "rsCpuIntrinsic.h"
19 
20 using namespace android;
21 using namespace android::renderscript;
22 
RsdCpuScriptIntrinsic(RsdCpuReferenceImpl * ctx,const Script * s,const Element * e,RsScriptIntrinsicID iid)23 RsdCpuScriptIntrinsic::RsdCpuScriptIntrinsic(RsdCpuReferenceImpl *ctx, const Script *s,
24                                              const Element *e, RsScriptIntrinsicID iid)
25         : RsdCpuScriptImpl(ctx, s) {
26 
27     mID = iid;
28     mElement.set(e);
29 }
30 
~RsdCpuScriptIntrinsic()31 RsdCpuScriptIntrinsic::~RsdCpuScriptIntrinsic() {
32 }
33 
invokeFunction(uint32_t slot,const void * params,size_t paramLength)34 void RsdCpuScriptIntrinsic::invokeFunction(uint32_t slot, const void *params, size_t paramLength) {
35     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
36                                  "Unexpected RsdCpuScriptIntrinsic::invokeFunction");
37 }
38 
invokeRoot()39 int RsdCpuScriptIntrinsic::invokeRoot() {
40     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
41                                  "Unexpected RsdCpuScriptIntrinsic::invokeRoot");
42     return 0;
43 }
44 
invokeInit()45 void RsdCpuScriptIntrinsic::invokeInit() {
46     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
47                                  "Unexpected RsdCpuScriptIntrinsic::invokeInit");
48 }
49 
setGlobalVar(uint32_t slot,const void * data,size_t dataLength)50 void RsdCpuScriptIntrinsic::setGlobalVar(uint32_t slot, const void *data, size_t dataLength) {
51     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
52                                  "Unexpected RsdCpuScriptIntrinsic::setGlobalVar");
53 }
54 
setGlobalVarWithElemDims(uint32_t slot,const void * data,size_t dataLength,const Element * e,const uint32_t * dims,size_t dimLength)55 void RsdCpuScriptIntrinsic::setGlobalVarWithElemDims(uint32_t slot, const void *data,
56                                                      size_t dataLength, const Element *e,
57                                                      const uint32_t *dims, size_t dimLength) {
58     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
59                                  "Unexpected RsdCpuScriptIntrinsic::setGlobalVarWithElemDims");
60 }
61 
setGlobalBind(uint32_t slot,Allocation * data)62 void RsdCpuScriptIntrinsic::setGlobalBind(uint32_t slot, Allocation *data) {
63     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
64                                  "Unexpected RsdCpuScriptIntrinsic::setGlobalBind");
65 }
66 
setGlobalObj(uint32_t slot,ObjectBase * data)67 void RsdCpuScriptIntrinsic::setGlobalObj(uint32_t slot, ObjectBase *data) {
68     mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
69                                  "Unexpected RsdCpuScriptIntrinsic::setGlobalObj");
70 }
71 
invokeFreeChildren()72 void RsdCpuScriptIntrinsic::invokeFreeChildren() {
73 }
74 
75 
preLaunch(uint32_t slot,const Allocation * ain,Allocation * aout,const void * usr,uint32_t usrLen,const RsScriptCall * sc)76 void RsdCpuScriptIntrinsic::preLaunch(uint32_t slot, const Allocation * ain,
77                                       Allocation * aout, const void * usr,
78                                       uint32_t usrLen, const RsScriptCall *sc) {
79 }
80 
postLaunch(uint32_t slot,const Allocation * ain,Allocation * aout,const void * usr,uint32_t usrLen,const RsScriptCall * sc)81 void RsdCpuScriptIntrinsic::postLaunch(uint32_t slot, const Allocation * ain,
82                                        Allocation * aout, const void * usr,
83                                        uint32_t usrLen, const RsScriptCall *sc) {
84 }
85 
invokeForEach(uint32_t slot,const Allocation * ain,Allocation * aout,const void * usr,uint32_t usrLen,const RsScriptCall * sc)86 void RsdCpuScriptIntrinsic::invokeForEach(uint32_t slot,
87                                           const Allocation * ain,
88                                           Allocation * aout,
89                                           const void * usr,
90                                           uint32_t usrLen,
91                                           const RsScriptCall *sc) {
92 
93     MTLaunchStruct mtls;
94     preLaunch(slot, ain, aout, usr, usrLen, sc);
95 
96     forEachMtlsSetup(ain, aout, usr, usrLen, sc, &mtls);
97     mtls.script = this;
98     mtls.fep.slot = slot;
99 
100     mtls.kernel = (void (*)())mRootPtr;
101     mtls.fep.usr = this;
102 
103     RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this);
104     mCtx->launchThreads(ain, aout, sc, &mtls);
105     mCtx->setTLS(oldTLS);
106 
107     postLaunch(slot, ain, aout, usr, usrLen, sc);
108 }
109 
invokeForEachMulti(uint32_t slot,const Allocation ** ains,uint32_t inLen,Allocation * aout,const void * usr,uint32_t usrLen,const RsScriptCall * sc)110 void RsdCpuScriptIntrinsic::invokeForEachMulti(uint32_t slot,
111                                                const Allocation ** ains,
112                                                uint32_t inLen,
113                                                Allocation * aout,
114                                                const void * usr,
115                                                uint32_t usrLen,
116                                                const RsScriptCall *sc) {
117 
118     MTLaunchStruct mtls;
119     /*
120      * FIXME: Possibly create new preLaunch and postLaunch functions that take
121      *        all of the input allocation pointers.
122      */
123     preLaunch(slot, ains[0], aout, usr, usrLen, sc);
124 
125     forEachMtlsSetup(ains, inLen, aout, usr, usrLen, sc, &mtls);
126     mtls.script = this;
127     mtls.fep.slot = slot;
128 
129     mtls.kernel = (void (*)())mRootPtr;
130     mtls.fep.usr = this;
131 
132     RsdCpuScriptImpl * oldTLS = mCtx->setTLS(this);
133     mCtx->launchThreads(ains, inLen, aout, sc, &mtls);
134     mCtx->setTLS(oldTLS);
135 
136     postLaunch(slot, ains[0], aout, usr, usrLen, sc);
137 }
138 
forEachKernelSetup(uint32_t slot,MTLaunchStruct * mtls)139 void RsdCpuScriptIntrinsic::forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls) {
140 
141     mtls->script = this;
142     mtls->fep.slot = slot;
143     mtls->kernel = (void (*)())mRootPtr;
144     mtls->fep.usr = this;
145 }
146