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
20using namespace android;
21using namespace android::renderscript;
22
23RsdCpuScriptIntrinsic::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
31RsdCpuScriptIntrinsic::~RsdCpuScriptIntrinsic() {
32}
33
34void 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
39int RsdCpuScriptIntrinsic::invokeRoot() {
40    mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
41                                 "Unexpected RsdCpuScriptIntrinsic::invokeRoot");
42    return 0;
43}
44
45void RsdCpuScriptIntrinsic::invokeInit() {
46    mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
47                                 "Unexpected RsdCpuScriptIntrinsic::invokeInit");
48}
49
50void 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
55void RsdCpuScriptIntrinsic::setGlobalVarWithElemDims(uint32_t slot, const void *data,
56                                                     size_t dataLength, const Element *e,
57                                                     const size_t *dims, size_t dimLength) {
58    mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
59                                 "Unexpected RsdCpuScriptIntrinsic::setGlobalVarWithElemDims");
60}
61
62void RsdCpuScriptIntrinsic::setGlobalBind(uint32_t slot, Allocation *data) {
63    mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
64                                 "Unexpected RsdCpuScriptIntrinsic::setGlobalBind");
65}
66
67void RsdCpuScriptIntrinsic::setGlobalObj(uint32_t slot, ObjectBase *data) {
68    mCtx->getContext()->setError(RS_ERROR_FATAL_DRIVER,
69                                 "Unexpected RsdCpuScriptIntrinsic::setGlobalObj");
70}
71
72void RsdCpuScriptIntrinsic::invokeFreeChildren() {
73}
74
75
76void RsdCpuScriptIntrinsic::preLaunch(uint32_t slot, const Allocation * ain,
77                                      Allocation * aout, const void * usr,
78                                      uint32_t usrLen, const RsScriptCall *sc) {
79}
80
81void RsdCpuScriptIntrinsic::postLaunch(uint32_t slot, const Allocation * ain,
82                                       Allocation * aout, const void * usr,
83                                       uint32_t usrLen, const RsScriptCall *sc) {
84}
85
86void 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
110void RsdCpuScriptIntrinsic::forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls) {
111
112    mtls->script = this;
113    mtls->fep.slot = slot;
114    mtls->kernel = (void (*)())mRootPtr;
115    mtls->fep.usr = this;
116}
117
118
119
120