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