blob: 5e8fee8f9046e4f85da648917dffe08b0c05ebf5 [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
Miao Wangcc8cea72015-02-19 18:14:46 -0800239 void (*elementData)(const Context *rsc, const Allocation *alloc,
240 uint32_t x, uint32_t y, uint32_t z,
241 const void *data, uint32_t elementOff, size_t sizeBytes);
242 void (*elementRead)(const Context *rsc, const Allocation *alloc,
243 uint32_t x, uint32_t y, uint32_t z,
244 void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700245
Jason Sams61a4bb72012-07-25 19:33:43 -0700246 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samsa36c50a2014-06-17 12:06:06 -0700247
248 void (*updateCachedObject)(const Context *rsc, const Allocation *alloc, rs_allocation *obj);
Jason Samsbc9dc272015-02-09 12:50:22 -0800249
250 void (*adapterOffset)(const Context *rsc, const Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700251 } allocation;
252
253 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700254 bool (*init)(const Context *rsc, const ProgramStore *ps);
255 void (*setActive)(const Context *rsc, const ProgramStore *ps);
256 void (*destroy)(const Context *rsc, const ProgramStore *ps);
257 } store;
258
Jason Sams721acc42011-04-06 11:23:54 -0700259 struct {
260 bool (*init)(const Context *rsc, const ProgramRaster *ps);
261 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
262 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
263 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700264
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700265 struct {
266 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800267 const char* shader, size_t shaderLen,
268 const char** textureNames, size_t textureNamesCount,
269 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700270 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
271 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
272 } vertex;
273
274 struct {
275 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800276 const char* shader, size_t shaderLen,
277 const char** textureNames, size_t textureNamesCount,
278 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700279 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
280 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
281 } fragment;
282
283 struct {
284 bool (*init)(const Context *rsc, const Mesh *m);
285 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
286 void (*destroy)(const Context *rsc, const Mesh *m);
287 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700288
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700289 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700290 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
291 bool (*initDynamic)(const Context *rsc, const Path *m);
292 void (*draw)(const Context *rsc, const Path *m);
293 void (*destroy)(const Context *rsc, const Path *m);
294 } path;
295
296 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700297 bool (*init)(const Context *rsc, const Sampler *m);
298 void (*destroy)(const Context *rsc, const Sampler *m);
Jason Samsa36c50a2014-06-17 12:06:06 -0700299 void (*updateCachedObject)(const Context *rsc, const Sampler *s, rs_sampler *obj);
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700300 } sampler;
301
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700302 struct {
303 bool (*init)(const Context *rsc, const FBOCache *fb);
304 void (*setActive)(const Context *rsc, const FBOCache *fb);
305 void (*destroy)(const Context *rsc, const FBOCache *fb);
306 } framebuffer;
307
Jason Samsdbe66d62012-09-17 13:54:41 -0700308 struct {
Yang Ni1ffd86b2015-01-07 09:16:40 -0800309 bool (*init)(const Context *rsc, ScriptGroupBase *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700310 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
311 const ScriptKernelID *kid, Allocation *);
312 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
313 const ScriptKernelID *kid, Allocation *);
Yang Ni1ffd86b2015-01-07 09:16:40 -0800314 void (*execute)(const Context *rsc, const ScriptGroupBase *sg);
315 void (*destroy)(const Context *rsc, const ScriptGroupBase *sg);
Jason Samsa36c50a2014-06-17 12:06:06 -0700316 void (*updateCachedObject)(const Context *rsc, const ScriptGroup *sg, rs_script_group *obj);
Jason Samsdbe66d62012-09-17 13:54:41 -0700317 } scriptgroup;
318
Jason Samsa36c50a2014-06-17 12:06:06 -0700319 struct {
320 bool (*init)(const Context *rsc, const Type *m);
321 void (*destroy)(const Context *rsc, const Type *m);
322 void (*updateCachedObject)(const Context *rsc, const Type *s, rs_type *obj);
323 } type;
324
325 struct {
326 bool (*init)(const Context *rsc, const Element *m);
327 void (*destroy)(const Context *rsc, const Element *m);
328 void (*updateCachedObject)(const Context *rsc, const Element *s, rs_element *obj);
329 } element;
330
Jason Sams9761c3f2013-11-26 18:10:59 -0800331 void (*finish)(const Context *rsc);
Jason Samsbad80742011-03-16 16:29:28 -0700332} RsdHalFunctions;
333
Jason Samsbad80742011-03-16 16:29:28 -0700334
335}
336}
337
Stephen Hines414a4612012-09-05 18:05:08 -0700338#ifdef __cplusplus
339extern "C" {
340#endif
Jason Samsbad80742011-03-16 16:29:28 -0700341
Stephen Hines414a4612012-09-05 18:05:08 -0700342bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
343
344#ifdef __cplusplus
345}
346#endif
Jason Samsbad80742011-03-16 16:29:28 -0700347
348#endif