rs_hal.h revision dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48
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 RS_HAL_H
18#define RS_HAL_H
19
20#include <rsDefines.h>
21
22struct ANativeWindow;
23
24namespace android {
25namespace renderscript {
26
27class Context;
28class ObjectBase;
29class Element;
30class Type;
31class Allocation;
32class Script;
33class ScriptKernelID;
34class ScriptFieldID;
35class ScriptMethodID;
36class ScriptC;
37class ScriptGroup;
38class Path;
39class Program;
40class ProgramStore;
41class ProgramRaster;
42class ProgramVertex;
43class ProgramFragment;
44class Mesh;
45class Sampler;
46class FBOCache;
47
48typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
49
50typedef struct {
51    const void *in;
52    void *out;
53    const void *usr;
54    size_t usrLen;
55    uint32_t x;
56    uint32_t y;
57    uint32_t z;
58    uint32_t lod;
59    RsAllocationCubemapFace face;
60    uint32_t ar[16];
61
62    uint32_t dimX;
63    uint32_t dimY;
64    uint32_t dimZ;
65    uint32_t dimArray;
66
67    const uint8_t *ptrIn;
68    uint8_t *ptrOut;
69    uint32_t eStrideIn;
70    uint32_t eStrideOut;
71    uint32_t yStrideIn;
72    uint32_t yStrideOut;
73} RsForEachStubParamStruct;
74
75/**
76 * Script management functions
77 */
78typedef struct {
79    bool (*initGraphics)(const Context *);
80    void (*shutdownGraphics)(const Context *);
81    bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
82    void (*swap)(const Context *);
83
84    void (*shutdownDriver)(Context *);
85    void (*getVersion)(unsigned int *major, unsigned int *minor);
86    void (*setPriority)(const Context *, int32_t priority);
87
88
89
90    struct {
91        bool (*init)(const Context *rsc, ScriptC *s,
92                     char const *resName,
93                     char const *cacheDir,
94                     uint8_t const *bitcode,
95                     size_t bitcodeSize,
96                     uint32_t flags);
97        bool (*initIntrinsic)(const Context *rsc, Script *s,
98                              RsScriptIntrinsicID iid,
99                              Element *e);
100
101        void (*invokeFunction)(const Context *rsc, Script *s,
102                               uint32_t slot,
103                               const void *params,
104                               size_t paramLength);
105        int (*invokeRoot)(const Context *rsc, Script *s);
106        void (*invokeForEach)(const Context *rsc,
107                              Script *s,
108                              uint32_t slot,
109                              const Allocation * ain,
110                              Allocation * aout,
111                              const void * usr,
112                              uint32_t usrLen,
113                              const RsScriptCall *sc);
114        void (*invokeInit)(const Context *rsc, Script *s);
115        void (*invokeFreeChildren)(const Context *rsc, Script *s);
116
117        void (*setGlobalVar)(const Context *rsc, const Script *s,
118                             uint32_t slot,
119                             void *data,
120                             size_t dataLength);
121        void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
122                                         uint32_t slot,
123                                         void *data,
124                                         size_t dataLength,
125                                         const Element *e,
126                                         const size_t *dims,
127                                         size_t dimLength);
128        void (*setGlobalBind)(const Context *rsc, const Script *s,
129                              uint32_t slot,
130                              Allocation *data);
131        void (*setGlobalObj)(const Context *rsc, const Script *s,
132                             uint32_t slot,
133                             ObjectBase *data);
134
135        void (*destroy)(const Context *rsc, Script *s);
136    } script;
137
138    struct {
139        bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
140        void (*destroy)(const Context *rsc, Allocation *alloc);
141
142        void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
143                       bool zeroNew);
144        void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
145        void (*markDirty)(const Context *rsc, const Allocation *alloc);
146
147        int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc);
148        void (*setSurfaceTexture)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
149        void (*ioSend)(const Context *rsc, Allocation *alloc);
150        void (*ioReceive)(const Context *rsc, Allocation *alloc);
151
152        void (*data1D)(const Context *rsc, const Allocation *alloc,
153                       uint32_t xoff, uint32_t lod, uint32_t count,
154                       const void *data, size_t sizeBytes);
155        void (*data2D)(const Context *rsc, const Allocation *alloc,
156                       uint32_t xoff, uint32_t yoff, uint32_t lod,
157                       RsAllocationCubemapFace face, uint32_t w, uint32_t h,
158                       const void *data, size_t sizeBytes);
159        void (*data3D)(const Context *rsc, const Allocation *alloc,
160                       uint32_t xoff, uint32_t yoff, uint32_t zoff,
161                       uint32_t lod, RsAllocationCubemapFace face,
162                       uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes);
163
164        void (*read1D)(const Context *rsc, const Allocation *alloc,
165                       uint32_t xoff, uint32_t lod, uint32_t count,
166                       void *data, size_t sizeBytes);
167        void (*read2D)(const Context *rsc, const Allocation *alloc,
168                       uint32_t xoff, uint32_t yoff, uint32_t lod,
169                       RsAllocationCubemapFace face, uint32_t w, uint32_t h,
170                       void *data, size_t sizeBytes);
171        void (*read3D)(const Context *rsc, const Allocation *alloc,
172                       uint32_t xoff, uint32_t yoff, uint32_t zoff,
173                       uint32_t lod, RsAllocationCubemapFace face,
174                       uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes);
175
176        // Lock and unlock make a 1D region of memory available to the CPU
177        // for direct access by pointer.  Once unlock is called control is
178        // returned to the SOC driver.
179        void * (*lock1D)(const Context *rsc, const Allocation *alloc);
180        void (*unlock1D)(const Context *rsc, const Allocation *alloc);
181
182        // Allocation to allocation copies
183        void (*allocData1D)(const Context *rsc,
184                            const Allocation *dstAlloc,
185                            uint32_t dstXoff, uint32_t dstLod, uint32_t count,
186                            const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
187        void (*allocData2D)(const Context *rsc,
188                            const Allocation *dstAlloc,
189                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
190                            RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
191                            const Allocation *srcAlloc,
192                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
193                            RsAllocationCubemapFace srcFace);
194        void (*allocData3D)(const Context *rsc,
195                            const Allocation *dstAlloc,
196                            uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
197                            uint32_t dstLod, RsAllocationCubemapFace dstFace,
198                            uint32_t w, uint32_t h, uint32_t d,
199                            const Allocation *srcAlloc,
200                            uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
201                            uint32_t srcLod, RsAllocationCubemapFace srcFace);
202
203        void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
204                              const void *data, uint32_t elementOff, size_t sizeBytes);
205        void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
206                              const void *data, uint32_t elementOff, size_t sizeBytes);
207
208        void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
209    } allocation;
210
211    struct {
212        bool (*init)(const Context *rsc, const ProgramStore *ps);
213        void (*setActive)(const Context *rsc, const ProgramStore *ps);
214        void (*destroy)(const Context *rsc, const ProgramStore *ps);
215    } store;
216
217    struct {
218        bool (*init)(const Context *rsc, const ProgramRaster *ps);
219        void (*setActive)(const Context *rsc, const ProgramRaster *ps);
220        void (*destroy)(const Context *rsc, const ProgramRaster *ps);
221    } raster;
222
223    struct {
224        bool (*init)(const Context *rsc, const ProgramVertex *pv,
225                     const char* shader, size_t shaderLen,
226                     const char** textureNames, size_t textureNamesCount,
227                     const size_t *textureNamesLength);
228        void (*setActive)(const Context *rsc, const ProgramVertex *pv);
229        void (*destroy)(const Context *rsc, const ProgramVertex *pv);
230    } vertex;
231
232    struct {
233        bool (*init)(const Context *rsc, const ProgramFragment *pf,
234                     const char* shader, size_t shaderLen,
235                     const char** textureNames, size_t textureNamesCount,
236                     const size_t *textureNamesLength);
237        void (*setActive)(const Context *rsc, const ProgramFragment *pf);
238        void (*destroy)(const Context *rsc, const ProgramFragment *pf);
239    } fragment;
240
241    struct {
242        bool (*init)(const Context *rsc, const Mesh *m);
243        void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
244        void (*destroy)(const Context *rsc, const Mesh *m);
245    } mesh;
246
247    struct {
248        bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
249        bool (*initDynamic)(const Context *rsc, const Path *m);
250        void (*draw)(const Context *rsc, const Path *m);
251        void (*destroy)(const Context *rsc, const Path *m);
252    } path;
253
254    struct {
255        bool (*init)(const Context *rsc, const Sampler *m);
256        void (*destroy)(const Context *rsc, const Sampler *m);
257    } sampler;
258
259    struct {
260        bool (*init)(const Context *rsc, const FBOCache *fb);
261        void (*setActive)(const Context *rsc, const FBOCache *fb);
262        void (*destroy)(const Context *rsc, const FBOCache *fb);
263    } framebuffer;
264
265    struct {
266        bool (*init)(const Context *rsc, const ScriptGroup *sg);
267        void (*setInput)(const Context *rsc, const ScriptGroup *sg,
268                         const ScriptKernelID *kid, Allocation *);
269        void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
270                          const ScriptKernelID *kid, Allocation *);
271        void (*execute)(const Context *rsc, const ScriptGroup *sg);
272        void (*destroy)(const Context *rsc, const ScriptGroup *sg);
273    } scriptgroup;
274
275} RsdHalFunctions;
276
277
278}
279}
280
281#ifdef __cplusplus
282extern "C" {
283#endif
284
285bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
286
287#ifdef __cplusplus
288}
289#endif
290
291#endif
292
293