blob: b3c2e39e59c5334c226fa98248494b975cfa3fb3 [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);
167 void (*destroy)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700168 uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700169
170 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
171 bool zeroNew);
172 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
173 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800174
Jason Sams733396b2013-02-22 12:46:18 -0800175 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800176 void (*ioSend)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700177
178 /**
179 * A new gralloc buffer is in use. The pointers and strides in
180 * mHal.drvState.lod[0-2] will be updated with the new values.
181 *
182 * The new gralloc handle is provided in mHal.state.nativeBuffer
183 *
184 */
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800185 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700186
187 void (*data1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700188 uint32_t xoff, uint32_t lod, size_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800189 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700190 void (*data2D)(const Context *rsc, const Allocation *alloc,
191 uint32_t xoff, uint32_t yoff, uint32_t lod,
192 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800193 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700194 void (*data3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700195 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
196 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
197 size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700198
Jason Sams807fdc42012-07-25 17:55:39 -0700199 void (*read1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700200 uint32_t xoff, uint32_t lod, size_t count,
Jason Sams807fdc42012-07-25 17:55:39 -0700201 void *data, size_t sizeBytes);
202 void (*read2D)(const Context *rsc, const Allocation *alloc,
203 uint32_t xoff, uint32_t yoff, uint32_t lod,
204 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800205 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700206 void (*read3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700207 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
208 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
209 size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700210
211 // Lock and unlock make a 1D region of memory available to the CPU
212 // for direct access by pointer. Once unlock is called control is
213 // returned to the SOC driver.
214 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
215 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
216
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700217 // Allocation to allocation copies
218 void (*allocData1D)(const Context *rsc,
219 const Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700220 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700221 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
222 void (*allocData2D)(const Context *rsc,
223 const Allocation *dstAlloc,
224 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
225 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
226 const Allocation *srcAlloc,
227 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
228 RsAllocationCubemapFace srcFace);
229 void (*allocData3D)(const Context *rsc,
230 const Allocation *dstAlloc,
231 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700232 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700233 uint32_t w, uint32_t h, uint32_t d,
234 const Allocation *srcAlloc,
235 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700236 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700237
Jason Samseb4fe182011-05-26 16:33:01 -0700238 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800239 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700240 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800241 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700242
Jason Sams61a4bb72012-07-25 19:33:43 -0700243 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samsa36c50a2014-06-17 12:06:06 -0700244
245 void (*updateCachedObject)(const Context *rsc, const Allocation *alloc, rs_allocation *obj);
Jason Samseb4fe182011-05-26 16:33:01 -0700246 } allocation;
247
248 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700249 bool (*init)(const Context *rsc, const ProgramStore *ps);
250 void (*setActive)(const Context *rsc, const ProgramStore *ps);
251 void (*destroy)(const Context *rsc, const ProgramStore *ps);
252 } store;
253
Jason Sams721acc42011-04-06 11:23:54 -0700254 struct {
255 bool (*init)(const Context *rsc, const ProgramRaster *ps);
256 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
257 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
258 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700259
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700260 struct {
261 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800262 const char* shader, size_t shaderLen,
263 const char** textureNames, size_t textureNamesCount,
264 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700265 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
266 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
267 } vertex;
268
269 struct {
270 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800271 const char* shader, size_t shaderLen,
272 const char** textureNames, size_t textureNamesCount,
273 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700274 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
275 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
276 } fragment;
277
278 struct {
279 bool (*init)(const Context *rsc, const Mesh *m);
280 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
281 void (*destroy)(const Context *rsc, const Mesh *m);
282 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700283
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700284 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700285 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
286 bool (*initDynamic)(const Context *rsc, const Path *m);
287 void (*draw)(const Context *rsc, const Path *m);
288 void (*destroy)(const Context *rsc, const Path *m);
289 } path;
290
291 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700292 bool (*init)(const Context *rsc, const Sampler *m);
293 void (*destroy)(const Context *rsc, const Sampler *m);
Jason Samsa36c50a2014-06-17 12:06:06 -0700294 void (*updateCachedObject)(const Context *rsc, const Sampler *s, rs_sampler *obj);
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700295 } sampler;
296
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700297 struct {
298 bool (*init)(const Context *rsc, const FBOCache *fb);
299 void (*setActive)(const Context *rsc, const FBOCache *fb);
300 void (*destroy)(const Context *rsc, const FBOCache *fb);
301 } framebuffer;
302
Jason Samsdbe66d62012-09-17 13:54:41 -0700303 struct {
Yang Ni1ffd86b2015-01-07 09:16:40 -0800304 bool (*init)(const Context *rsc, ScriptGroupBase *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700305 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
306 const ScriptKernelID *kid, Allocation *);
307 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
308 const ScriptKernelID *kid, Allocation *);
Yang Ni1ffd86b2015-01-07 09:16:40 -0800309 void (*execute)(const Context *rsc, const ScriptGroupBase *sg);
310 void (*destroy)(const Context *rsc, const ScriptGroupBase *sg);
Jason Samsa36c50a2014-06-17 12:06:06 -0700311 void (*updateCachedObject)(const Context *rsc, const ScriptGroup *sg, rs_script_group *obj);
Jason Samsdbe66d62012-09-17 13:54:41 -0700312 } scriptgroup;
313
Jason Samsa36c50a2014-06-17 12:06:06 -0700314 struct {
315 bool (*init)(const Context *rsc, const Type *m);
316 void (*destroy)(const Context *rsc, const Type *m);
317 void (*updateCachedObject)(const Context *rsc, const Type *s, rs_type *obj);
318 } type;
319
320 struct {
321 bool (*init)(const Context *rsc, const Element *m);
322 void (*destroy)(const Context *rsc, const Element *m);
323 void (*updateCachedObject)(const Context *rsc, const Element *s, rs_element *obj);
324 } element;
325
Jason Sams9761c3f2013-11-26 18:10:59 -0800326 void (*finish)(const Context *rsc);
Jason Samsbad80742011-03-16 16:29:28 -0700327} RsdHalFunctions;
328
Jason Samsbad80742011-03-16 16:29:28 -0700329
330}
331}
332
Stephen Hines414a4612012-09-05 18:05:08 -0700333#ifdef __cplusplus
334extern "C" {
335#endif
Jason Samsbad80742011-03-16 16:29:28 -0700336
Stephen Hines414a4612012-09-05 18:05:08 -0700337bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
338
339#ifdef __cplusplus
340}
341#endif
Jason Samsbad80742011-03-16 16:29:28 -0700342
343#endif