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#ifndef RSD_BCC_H
18#define RSD_BCC_H
19
20#include <rs_hal.h>
21#include <rsRuntime.h>
22
23
24bool rsdScriptInit(const android::renderscript::Context *, android::renderscript::ScriptC *,
25                   char const *resName, char const *cacheDir,
26                   uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags);
27bool rsdInitIntrinsic(const android::renderscript::Context *rsc,
28                      android::renderscript::Script *s,
29                      RsScriptIntrinsicID iid,
30                      android::renderscript::Element *e);
31
32void rsdScriptInvokeFunction(const android::renderscript::Context *dc,
33                             android::renderscript::Script *script,
34                             uint32_t slot,
35                             const void *params,
36                             size_t paramLength);
37
38void rsdScriptInvokeForEach(const android::renderscript::Context *rsc,
39                            android::renderscript::Script *s,
40                            uint32_t slot,
41                            const android::renderscript::Allocation * ain,
42                            android::renderscript::Allocation * aout,
43                            const void * usr,
44                            uint32_t usrLen,
45                            const RsScriptCall *sc);
46
47int rsdScriptInvokeRoot(const android::renderscript::Context *dc,
48                        android::renderscript::Script *script);
49void rsdScriptInvokeInit(const android::renderscript::Context *dc,
50                         android::renderscript::Script *script);
51void rsdScriptInvokeFreeChildren(const android::renderscript::Context *dc,
52                                 android::renderscript::Script *script);
53
54void rsdScriptSetGlobalVar(const android::renderscript::Context *,
55                           const android::renderscript::Script *,
56                           uint32_t slot, void *data, size_t dataLen);
57void rsdScriptSetGlobalVarWithElemDims(const android::renderscript::Context *,
58                                       const android::renderscript::Script *,
59                                       uint32_t slot, void *data,
60                                       size_t dataLength,
61                                       const android::renderscript::Element *,
62                                       const size_t *dims,
63                                       size_t dimLength);
64void rsdScriptSetGlobalBind(const android::renderscript::Context *,
65                            const android::renderscript::Script *,
66                            uint32_t slot, android::renderscript::Allocation *data);
67void rsdScriptSetGlobalObj(const android::renderscript::Context *,
68                           const android::renderscript::Script *,
69                           uint32_t slot, android::renderscript::ObjectBase *data);
70
71void rsdScriptSetGlobal(const android::renderscript::Context *dc,
72                        const android::renderscript::Script *script,
73                        uint32_t slot,
74                        void *data,
75                        size_t dataLength);
76void rsdScriptGetGlobal(const android::renderscript::Context *dc,
77                        const android::renderscript::Script *script,
78                        uint32_t slot,
79                        void *data,
80                        size_t dataLength);
81void rsdScriptDestroy(const android::renderscript::Context *dc,
82                      android::renderscript::Script *script);
83
84android::renderscript::Allocation * rsdScriptGetAllocationForPointer(
85                        const android::renderscript::Context *dc,
86                        const android::renderscript::Script *script,
87                        const void *);
88
89
90typedef void (*outer_foreach_t)(
91    const android::renderscript::RsForEachStubParamStruct *,
92    uint32_t x1, uint32_t x2,
93    uint32_t instep, uint32_t outstep);
94
95typedef struct RsdIntriniscFuncs_rec {
96
97    void (*bind)(const android::renderscript::Context *dc,
98                 const android::renderscript::Script *script,
99                 void * intrinsicData,
100                 uint32_t slot, android::renderscript::Allocation *data);
101    void (*setVar)(const android::renderscript::Context *dc,
102                   const android::renderscript::Script *script,
103                   void * intrinsicData,
104                   uint32_t slot, void *data, size_t dataLength);
105    void (*root)(const android::renderscript::RsForEachStubParamStruct *,
106                 uint32_t x1, uint32_t x2, uint32_t instep, uint32_t outstep);
107
108    void (*destroy)(const android::renderscript::Context *dc,
109                    const android::renderscript::Script *script,
110                    void * intrinsicData);
111} RsdIntriniscFuncs_t;
112
113struct DrvScript {
114    RsScriptIntrinsicID mIntrinsicID;
115    void *mScriptSO;
116    RootFunc_t mRoot;
117    RootFunc_t mRootExpand;
118    InvokeFunc_t mInit;
119    InvokeFunc_t mFreeChildren;
120
121    InvokeFunc_t *mInvokeFunctions;
122    ForEachFunc_t *mForEachFunctions;
123    void **mFieldAddress;
124    bool *mFieldIsObject;
125    uint32_t *mForEachSignatures;
126
127    android::renderscript::Allocation **mBoundAllocs;
128    RsdIntriniscFuncs_t mIntrinsicFuncs;
129    void * mIntrinsicData;
130};
131
132typedef struct {
133    android::renderscript::RsForEachStubParamStruct fep;
134    uint32_t cpuIdx;
135
136} MTThreadStuct;
137
138typedef struct {
139    android::renderscript::RsForEachStubParamStruct fep;
140
141    android::renderscript::Context *rsc;
142    android::renderscript::Script *script;
143    ForEachFunc_t kernel;
144    uint32_t sig;
145    const android::renderscript::Allocation * ain;
146    android::renderscript::Allocation * aout;
147
148    uint32_t mSliceSize;
149    volatile int mSliceNum;
150
151    uint32_t xStart;
152    uint32_t xEnd;
153    uint32_t yStart;
154    uint32_t yEnd;
155    uint32_t zStart;
156    uint32_t zEnd;
157    uint32_t arrayStart;
158    uint32_t arrayEnd;
159} MTLaunchStruct;
160
161void rsdScriptLaunchThreads(const android::renderscript::Context *rsc,
162                            android::renderscript::Script *s,
163                            uint32_t slot,
164                            const android::renderscript::Allocation * ain,
165                            android::renderscript::Allocation * aout,
166                            const void * usr,
167                            uint32_t usrLen,
168                            const RsScriptCall *sc,
169                            MTLaunchStruct *mtls);
170
171void rsdScriptInvokeForEachMtlsSetup(const android::renderscript::Context *rsc,
172                                     const android::renderscript::Allocation * ain,
173                                     android::renderscript::Allocation * aout,
174                                     const void * usr,
175                                     uint32_t usrLen,
176                                     const RsScriptCall *sc,
177                                     MTLaunchStruct *mtls);
178
179
180
181
182#endif
183