blob: 9a4e9a50065307b741d0f8cb7a4daa2c21176c59 [file] [log] [blame]
Jason Samsbad80742011-03-16 16:29:28 -07001/*
Stephen Hines2980f072012-04-09 18:26:29 -07002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsbad80742011-03-16 16:29:28 -07003 *
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
Jason Sams66f0a162014-11-11 13:46:38 -080020#include <rsInternalDefines.h>
Jason Samsbad80742011-03-16 16:29:28 -070021
Jason Sams7ac2a4d2012-02-15 12:04:24 -080022struct ANativeWindow;
23
Jason Samsbad80742011-03-16 16:29:28 -070024namespace android {
25namespace renderscript {
26
27class Context;
28class ObjectBase;
29class Element;
30class Type;
31class Allocation;
32class Script;
Jason Samsdbe66d62012-09-17 13:54:41 -070033class ScriptKernelID;
34class ScriptFieldID;
35class ScriptMethodID;
Jason Samsbad80742011-03-16 16:29:28 -070036class ScriptC;
Jason Samsdbe66d62012-09-17 13:54:41 -070037class ScriptGroup;
Yang Ni1ffd86b2015-01-07 09:16:40 -080038class ScriptGroupBase;
Jason Sams9e0afb52011-10-31 13:23:43 -070039class Path;
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070040class Program;
Jason Sams8feea4e2011-03-18 15:03:25 -070041class ProgramStore;
Jason Sams721acc42011-04-06 11:23:54 -070042class ProgramRaster;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070043class ProgramVertex;
44class ProgramFragment;
45class Mesh;
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070046class Sampler;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070047class FBOCache;
Jason Samsbad80742011-03-16 16:29:28 -070048
Jason Samsa36c50a2014-06-17 12:06:06 -070049/**
50 * Define the internal object types. This ia a mirror of the
51 * definition in rs_types.rsh except with the p value typed
52 * correctly.
53 *
54 * p = pointer to internal object implementation
55 * r = reserved by libRS runtime
56 * v1 = Mirror of p->mHal.drv
57 * v2 = reserved for use by vendor drivers
58 */
59
60#ifndef __LP64__
61#define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; } __attribute__((packed, aligned(4)))
62#else
63#define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; const void* r; const void* v1; const void* v2; }
64#endif
65
Jason Sams05ef73f2014-08-05 14:59:22 -070066RS_BASE_OBJ(ObjectBase) rs_object_base;
Jason Samsa36c50a2014-06-17 12:06:06 -070067RS_BASE_OBJ(Element) rs_element;
68RS_BASE_OBJ(Type) rs_type;
69RS_BASE_OBJ(Allocation) rs_allocation;
70RS_BASE_OBJ(Sampler) rs_sampler;
71RS_BASE_OBJ(Script) rs_script;
72RS_BASE_OBJ(ScriptGroup) rs_script_group;
73
74#ifndef __LP64__
75typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_mesh;
76typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_path;
77typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_fragment;
78typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_vertex;
79typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_raster;
80typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_store;
81typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_font;
82#endif // __LP64__
83
84
Jason Samsbad80742011-03-16 16:29:28 -070085typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
86
Jason Samsbad80742011-03-16 16:29:28 -070087/**
88 * Script management functions
89 */
90typedef struct {
Jason Sams4b3de472011-04-06 17:52:23 -070091 bool (*initGraphics)(const Context *);
92 void (*shutdownGraphics)(const Context *);
Alex Sakhartchouk7257c7e2011-05-17 12:32:47 -070093 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
Jason Sams4b3de472011-04-06 17:52:23 -070094 void (*swap)(const Context *);
95
Jason Samscdfdb8f2011-03-17 16:12:47 -070096 void (*shutdownDriver)(Context *);
Jason Samsbad80742011-03-16 16:29:28 -070097 void (*getVersion)(unsigned int *major, unsigned int *minor);
Jason Samscdfdb8f2011-03-17 16:12:47 -070098 void (*setPriority)(const Context *, int32_t priority);
Jason Samsbad80742011-03-16 16:29:28 -070099
Tim Murray34689382013-03-11 12:12:03 -0700100 void* (*allocRuntimeMem)(size_t size, uint32_t flags);
101 void (*freeRuntimeMem)(void* ptr);
Jason Samsbad80742011-03-16 16:29:28 -0700102
103 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700104 bool (*init)(const Context *rsc, ScriptC *s,
105 char const *resName,
106 char const *cacheDir,
107 uint8_t const *bitcode,
108 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -0700109 uint32_t flags);
Jason Sams8eaba4f2012-08-14 14:38:05 -0700110 bool (*initIntrinsic)(const Context *rsc, Script *s,
Stephen Hines41d6c762012-08-21 17:07:38 -0700111 RsScriptIntrinsicID iid,
Jason Sams8eaba4f2012-08-14 14:38:05 -0700112 Element *e);
Jason Samsbad80742011-03-16 16:29:28 -0700113
Jason Samscdfdb8f2011-03-17 16:12:47 -0700114 void (*invokeFunction)(const Context *rsc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -0700115 uint32_t slot,
116 const void *params,
117 size_t paramLength);
Jason Samscdfdb8f2011-03-17 16:12:47 -0700118 int (*invokeRoot)(const Context *rsc, Script *s);
119 void (*invokeForEach)(const Context *rsc,
120 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -0700121 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700122 const Allocation * ain,
123 Allocation * aout,
124 const void * usr,
Tim Murray099bc262013-03-20 16:54:03 -0700125 size_t usrLen,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700126 const RsScriptCall *sc);
127 void (*invokeInit)(const Context *rsc, Script *s);
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700128 void (*invokeFreeChildren)(const Context *rsc, Script *s);
Jason Samsbad80742011-03-16 16:29:28 -0700129
130 void (*setGlobalVar)(const Context *rsc, const Script *s,
131 uint32_t slot,
132 void *data,
133 size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -0700134 void (*getGlobalVar)(const Context *rsc, const Script *s,
135 uint32_t slot,
136 void *data,
137 size_t dataLength);
Stephen Hines2980f072012-04-09 18:26:29 -0700138 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
139 uint32_t slot,
140 void *data,
141 size_t dataLength,
142 const Element *e,
Stephen Hinesac8d1462014-06-25 00:01:23 -0700143 const uint32_t *dims,
Stephen Hines2980f072012-04-09 18:26:29 -0700144 size_t dimLength);
Jason Samsbad80742011-03-16 16:29:28 -0700145 void (*setGlobalBind)(const Context *rsc, const Script *s,
146 uint32_t slot,
Jason Sams807fdc42012-07-25 17:55:39 -0700147 Allocation *data);
Jason Samsbad80742011-03-16 16:29:28 -0700148 void (*setGlobalObj)(const Context *rsc, const Script *s,
149 uint32_t slot,
150 ObjectBase *data);
151
152 void (*destroy)(const Context *rsc, Script *s);
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700153 void (*invokeForEachMulti)(const Context *rsc,
154 Script *s,
155 uint32_t slot,
156 const Allocation ** ains,
157 size_t inLen,
158 Allocation * aout,
159 const void * usr,
160 size_t usrLen,
161 const RsScriptCall *sc);
Jason Samsa36c50a2014-06-17 12:06:06 -0700162 void (*updateCachedObject)(const Context *rsc, const Script *, rs_script *obj);
Jason Samsbad80742011-03-16 16:29:28 -0700163 } script;
164
Jason Sams8feea4e2011-03-18 15:03:25 -0700165 struct {
Jason Samseb4fe182011-05-26 16:33:01 -0700166 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
Jason Samsbc9dc272015-02-09 12:50:22 -0800167 bool (*initAdapter)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700168 void (*destroy)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700169 uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700170
171 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
172 bool zeroNew);
173 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
174 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800175
Jason Sams733396b2013-02-22 12:46:18 -0800176 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800177 void (*ioSend)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700178
179 /**
180 * A new gralloc buffer is in use. The pointers and strides in
181 * mHal.drvState.lod[0-2] will be updated with the new values.
182 *
183 * The new gralloc handle is provided in mHal.state.nativeBuffer
184 *
185 */
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800186 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700187
188 void (*data1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700189 uint32_t xoff, uint32_t lod, size_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800190 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700191 void (*data2D)(const Context *rsc, const Allocation *alloc,
192 uint32_t xoff, uint32_t yoff, uint32_t lod,
193 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800194 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700195 void (*data3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700196 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
197 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
198 size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700199
Jason Sams807fdc42012-07-25 17:55:39 -0700200 void (*read1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700201 uint32_t xoff, uint32_t lod, size_t count,
Jason Sams807fdc42012-07-25 17:55:39 -0700202 void *data, size_t sizeBytes);
203 void (*read2D)(const Context *rsc, const Allocation *alloc,
204 uint32_t xoff, uint32_t yoff, uint32_t lod,
205 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800206 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700207 void (*read3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700208 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
209 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
210 size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700211
212 // Lock and unlock make a 1D region of memory available to the CPU
213 // for direct access by pointer. Once unlock is called control is
214 // returned to the SOC driver.
215 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
216 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
217
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700218 // Allocation to allocation copies
219 void (*allocData1D)(const Context *rsc,
220 const Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700221 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700222 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
223 void (*allocData2D)(const Context *rsc,
224 const Allocation *dstAlloc,
225 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
226 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
227 const Allocation *srcAlloc,
228 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
229 RsAllocationCubemapFace srcFace);
230 void (*allocData3D)(const Context *rsc,
231 const Allocation *dstAlloc,
232 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700233 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700234 uint32_t w, uint32_t h, uint32_t d,
235 const Allocation *srcAlloc,
236 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700237 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700238
Jason Samseb4fe182011-05-26 16:33:01 -0700239 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800240 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700241 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800242 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700243
Jason Sams61a4bb72012-07-25 19:33:43 -0700244 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samsa36c50a2014-06-17 12:06:06 -0700245
246 void (*updateCachedObject)(const Context *rsc, const Allocation *alloc, rs_allocation *obj);
Jason Samsbc9dc272015-02-09 12:50:22 -0800247
248 void (*adapterOffset)(const Context *rsc, const Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700249 } allocation;
250
251 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700252 bool (*init)(const Context *rsc, const ProgramStore *ps);
253 void (*setActive)(const Context *rsc, const ProgramStore *ps);
254 void (*destroy)(const Context *rsc, const ProgramStore *ps);
255 } store;
256
Jason Sams721acc42011-04-06 11:23:54 -0700257 struct {
258 bool (*init)(const Context *rsc, const ProgramRaster *ps);
259 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
260 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
261 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700262
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700263 struct {
264 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800265 const char* shader, size_t shaderLen,
266 const char** textureNames, size_t textureNamesCount,
267 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700268 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
269 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
270 } vertex;
271
272 struct {
273 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800274 const char* shader, size_t shaderLen,
275 const char** textureNames, size_t textureNamesCount,
276 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700277 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
278 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
279 } fragment;
280
281 struct {
282 bool (*init)(const Context *rsc, const Mesh *m);
283 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
284 void (*destroy)(const Context *rsc, const Mesh *m);
285 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700286
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700287 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700288 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
289 bool (*initDynamic)(const Context *rsc, const Path *m);
290 void (*draw)(const Context *rsc, const Path *m);
291 void (*destroy)(const Context *rsc, const Path *m);
292 } path;
293
294 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700295 bool (*init)(const Context *rsc, const Sampler *m);
296 void (*destroy)(const Context *rsc, const Sampler *m);
Jason Samsa36c50a2014-06-17 12:06:06 -0700297 void (*updateCachedObject)(const Context *rsc, const Sampler *s, rs_sampler *obj);
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700298 } sampler;
299
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700300 struct {
301 bool (*init)(const Context *rsc, const FBOCache *fb);
302 void (*setActive)(const Context *rsc, const FBOCache *fb);
303 void (*destroy)(const Context *rsc, const FBOCache *fb);
304 } framebuffer;
305
Jason Samsdbe66d62012-09-17 13:54:41 -0700306 struct {
Yang Ni1ffd86b2015-01-07 09:16:40 -0800307 bool (*init)(const Context *rsc, ScriptGroupBase *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700308 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
309 const ScriptKernelID *kid, Allocation *);
310 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
311 const ScriptKernelID *kid, Allocation *);
Yang Ni1ffd86b2015-01-07 09:16:40 -0800312 void (*execute)(const Context *rsc, const ScriptGroupBase *sg);
313 void (*destroy)(const Context *rsc, const ScriptGroupBase *sg);
Jason Samsa36c50a2014-06-17 12:06:06 -0700314 void (*updateCachedObject)(const Context *rsc, const ScriptGroup *sg, rs_script_group *obj);
Jason Samsdbe66d62012-09-17 13:54:41 -0700315 } scriptgroup;
316
Jason Samsa36c50a2014-06-17 12:06:06 -0700317 struct {
318 bool (*init)(const Context *rsc, const Type *m);
319 void (*destroy)(const Context *rsc, const Type *m);
320 void (*updateCachedObject)(const Context *rsc, const Type *s, rs_type *obj);
321 } type;
322
323 struct {
324 bool (*init)(const Context *rsc, const Element *m);
325 void (*destroy)(const Context *rsc, const Element *m);
326 void (*updateCachedObject)(const Context *rsc, const Element *s, rs_element *obj);
327 } element;
328
Jason Sams9761c3f2013-11-26 18:10:59 -0800329 void (*finish)(const Context *rsc);
Jason Samsbad80742011-03-16 16:29:28 -0700330} RsdHalFunctions;
331
Jason Samsbad80742011-03-16 16:29:28 -0700332
333}
334}
335
Stephen Hines414a4612012-09-05 18:05:08 -0700336#ifdef __cplusplus
337extern "C" {
338#endif
Jason Samsbad80742011-03-16 16:29:28 -0700339
Stephen Hines414a4612012-09-05 18:05:08 -0700340bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
341
342#ifdef __cplusplus
343}
344#endif
Jason Samsbad80742011-03-16 16:29:28 -0700345
346#endif