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