blob: 419827b2f73577dfd67d5b892cf2b3834ba3db7b [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;
Jason Sams9e0afb52011-10-31 13:23:43 -070038class Path;
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070039class Program;
Jason Sams8feea4e2011-03-18 15:03:25 -070040class ProgramStore;
Jason Sams721acc42011-04-06 11:23:54 -070041class ProgramRaster;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070042class ProgramVertex;
43class ProgramFragment;
44class Mesh;
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070045class Sampler;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070046class FBOCache;
Jason Samsbad80742011-03-16 16:29:28 -070047
Jason Samsa36c50a2014-06-17 12:06:06 -070048/**
49 * Define the internal object types. This ia a mirror of the
50 * definition in rs_types.rsh except with the p value typed
51 * correctly.
52 *
53 * p = pointer to internal object implementation
54 * r = reserved by libRS runtime
55 * v1 = Mirror of p->mHal.drv
56 * v2 = reserved for use by vendor drivers
57 */
58
59#ifndef __LP64__
60#define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; } __attribute__((packed, aligned(4)))
61#else
62#define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; const void* r; const void* v1; const void* v2; }
63#endif
64
Jason Sams05ef73f2014-08-05 14:59:22 -070065RS_BASE_OBJ(ObjectBase) rs_object_base;
Jason Samsa36c50a2014-06-17 12:06:06 -070066RS_BASE_OBJ(Element) rs_element;
67RS_BASE_OBJ(Type) rs_type;
68RS_BASE_OBJ(Allocation) rs_allocation;
69RS_BASE_OBJ(Sampler) rs_sampler;
70RS_BASE_OBJ(Script) rs_script;
71RS_BASE_OBJ(ScriptGroup) rs_script_group;
72
73#ifndef __LP64__
74typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_mesh;
75typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_path;
76typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_fragment;
77typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_vertex;
78typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_raster;
79typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_store;
80typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_font;
81#endif // __LP64__
82
83
Jason Samsbad80742011-03-16 16:29:28 -070084typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
85
Jason Samsbad80742011-03-16 16:29:28 -070086/**
87 * Script management functions
88 */
89typedef struct {
Jason Sams4b3de472011-04-06 17:52:23 -070090 bool (*initGraphics)(const Context *);
91 void (*shutdownGraphics)(const Context *);
Alex Sakhartchouk7257c7e2011-05-17 12:32:47 -070092 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
Jason Sams4b3de472011-04-06 17:52:23 -070093 void (*swap)(const Context *);
94
Jason Samscdfdb8f2011-03-17 16:12:47 -070095 void (*shutdownDriver)(Context *);
Jason Samsbad80742011-03-16 16:29:28 -070096 void (*getVersion)(unsigned int *major, unsigned int *minor);
Jason Samscdfdb8f2011-03-17 16:12:47 -070097 void (*setPriority)(const Context *, int32_t priority);
Jason Samsbad80742011-03-16 16:29:28 -070098
Tim Murray34689382013-03-11 12:12:03 -070099 void* (*allocRuntimeMem)(size_t size, uint32_t flags);
100 void (*freeRuntimeMem)(void* ptr);
Jason Samsbad80742011-03-16 16:29:28 -0700101
102 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700103 bool (*init)(const Context *rsc, ScriptC *s,
104 char const *resName,
105 char const *cacheDir,
106 uint8_t const *bitcode,
107 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -0700108 uint32_t flags);
Jason Sams8eaba4f2012-08-14 14:38:05 -0700109 bool (*initIntrinsic)(const Context *rsc, Script *s,
Stephen Hines41d6c762012-08-21 17:07:38 -0700110 RsScriptIntrinsicID iid,
Jason Sams8eaba4f2012-08-14 14:38:05 -0700111 Element *e);
Jason Samsbad80742011-03-16 16:29:28 -0700112
Jason Samscdfdb8f2011-03-17 16:12:47 -0700113 void (*invokeFunction)(const Context *rsc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -0700114 uint32_t slot,
115 const void *params,
116 size_t paramLength);
Jason Samscdfdb8f2011-03-17 16:12:47 -0700117 int (*invokeRoot)(const Context *rsc, Script *s);
118 void (*invokeForEach)(const Context *rsc,
119 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -0700120 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700121 const Allocation * ain,
122 Allocation * aout,
123 const void * usr,
Tim Murray099bc262013-03-20 16:54:03 -0700124 size_t usrLen,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700125 const RsScriptCall *sc);
126 void (*invokeInit)(const Context *rsc, Script *s);
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700127 void (*invokeFreeChildren)(const Context *rsc, Script *s);
Jason Samsbad80742011-03-16 16:29:28 -0700128
129 void (*setGlobalVar)(const Context *rsc, const Script *s,
130 uint32_t slot,
131 void *data,
132 size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -0700133 void (*getGlobalVar)(const Context *rsc, const Script *s,
134 uint32_t slot,
135 void *data,
136 size_t dataLength);
Stephen Hines2980f072012-04-09 18:26:29 -0700137 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
138 uint32_t slot,
139 void *data,
140 size_t dataLength,
141 const Element *e,
Stephen Hinesac8d1462014-06-25 00:01:23 -0700142 const uint32_t *dims,
Stephen Hines2980f072012-04-09 18:26:29 -0700143 size_t dimLength);
Jason Samsbad80742011-03-16 16:29:28 -0700144 void (*setGlobalBind)(const Context *rsc, const Script *s,
145 uint32_t slot,
Jason Sams807fdc42012-07-25 17:55:39 -0700146 Allocation *data);
Jason Samsbad80742011-03-16 16:29:28 -0700147 void (*setGlobalObj)(const Context *rsc, const Script *s,
148 uint32_t slot,
149 ObjectBase *data);
150
151 void (*destroy)(const Context *rsc, Script *s);
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700152 void (*invokeForEachMulti)(const Context *rsc,
153 Script *s,
154 uint32_t slot,
155 const Allocation ** ains,
156 size_t inLen,
157 Allocation * aout,
158 const void * usr,
159 size_t usrLen,
160 const RsScriptCall *sc);
Jason Samsa36c50a2014-06-17 12:06:06 -0700161 void (*updateCachedObject)(const Context *rsc, const Script *, rs_script *obj);
Jason Samsbad80742011-03-16 16:29:28 -0700162 } script;
163
Jason Sams8feea4e2011-03-18 15:03:25 -0700164 struct {
Jason Samseb4fe182011-05-26 16:33:01 -0700165 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
166 void (*destroy)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700167 uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700168
169 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
170 bool zeroNew);
171 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
172 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800173
Jason Sams733396b2013-02-22 12:46:18 -0800174 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800175 void (*ioSend)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700176
177 /**
178 * A new gralloc buffer is in use. The pointers and strides in
179 * mHal.drvState.lod[0-2] will be updated with the new values.
180 *
181 * The new gralloc handle is provided in mHal.state.nativeBuffer
182 *
183 */
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800184 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700185
186 void (*data1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700187 uint32_t xoff, uint32_t lod, size_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800188 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700189 void (*data2D)(const Context *rsc, const Allocation *alloc,
190 uint32_t xoff, uint32_t yoff, uint32_t lod,
191 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800192 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700193 void (*data3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700194 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
195 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
196 size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700197
Jason Sams807fdc42012-07-25 17:55:39 -0700198 void (*read1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700199 uint32_t xoff, uint32_t lod, size_t count,
Jason Sams807fdc42012-07-25 17:55:39 -0700200 void *data, size_t sizeBytes);
201 void (*read2D)(const Context *rsc, const Allocation *alloc,
202 uint32_t xoff, uint32_t yoff, uint32_t lod,
203 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800204 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700205 void (*read3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700206 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
207 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
208 size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700209
210 // Lock and unlock make a 1D region of memory available to the CPU
211 // for direct access by pointer. Once unlock is called control is
212 // returned to the SOC driver.
213 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
214 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
215
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700216 // Allocation to allocation copies
217 void (*allocData1D)(const Context *rsc,
218 const Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700219 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700220 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
221 void (*allocData2D)(const Context *rsc,
222 const Allocation *dstAlloc,
223 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
224 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
225 const Allocation *srcAlloc,
226 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
227 RsAllocationCubemapFace srcFace);
228 void (*allocData3D)(const Context *rsc,
229 const Allocation *dstAlloc,
230 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700231 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700232 uint32_t w, uint32_t h, uint32_t d,
233 const Allocation *srcAlloc,
234 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700235 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700236
Jason Samseb4fe182011-05-26 16:33:01 -0700237 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800238 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700239 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
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
Jason Sams61a4bb72012-07-25 19:33:43 -0700242 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samsa36c50a2014-06-17 12:06:06 -0700243
244 void (*updateCachedObject)(const Context *rsc, const Allocation *alloc, rs_allocation *obj);
Jason Samseb4fe182011-05-26 16:33:01 -0700245 } allocation;
246
247 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700248 bool (*init)(const Context *rsc, const ProgramStore *ps);
249 void (*setActive)(const Context *rsc, const ProgramStore *ps);
250 void (*destroy)(const Context *rsc, const ProgramStore *ps);
251 } store;
252
Jason Sams721acc42011-04-06 11:23:54 -0700253 struct {
254 bool (*init)(const Context *rsc, const ProgramRaster *ps);
255 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
256 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
257 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700258
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700259 struct {
260 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800261 const char* shader, size_t shaderLen,
262 const char** textureNames, size_t textureNamesCount,
263 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700264 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
265 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
266 } vertex;
267
268 struct {
269 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800270 const char* shader, size_t shaderLen,
271 const char** textureNames, size_t textureNamesCount,
272 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700273 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
274 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
275 } fragment;
276
277 struct {
278 bool (*init)(const Context *rsc, const Mesh *m);
279 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
280 void (*destroy)(const Context *rsc, const Mesh *m);
281 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700282
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700283 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700284 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
285 bool (*initDynamic)(const Context *rsc, const Path *m);
286 void (*draw)(const Context *rsc, const Path *m);
287 void (*destroy)(const Context *rsc, const Path *m);
288 } path;
289
290 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700291 bool (*init)(const Context *rsc, const Sampler *m);
292 void (*destroy)(const Context *rsc, const Sampler *m);
Jason Samsa36c50a2014-06-17 12:06:06 -0700293 void (*updateCachedObject)(const Context *rsc, const Sampler *s, rs_sampler *obj);
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700294 } sampler;
295
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700296 struct {
297 bool (*init)(const Context *rsc, const FBOCache *fb);
298 void (*setActive)(const Context *rsc, const FBOCache *fb);
299 void (*destroy)(const Context *rsc, const FBOCache *fb);
300 } framebuffer;
301
Jason Samsdbe66d62012-09-17 13:54:41 -0700302 struct {
Jason Sams709a0972012-11-15 18:18:04 -0800303 bool (*init)(const Context *rsc, ScriptGroup *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700304 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
305 const ScriptKernelID *kid, Allocation *);
306 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
307 const ScriptKernelID *kid, Allocation *);
308 void (*execute)(const Context *rsc, const ScriptGroup *sg);
309 void (*destroy)(const Context *rsc, const ScriptGroup *sg);
Jason Samsa36c50a2014-06-17 12:06:06 -0700310 void (*updateCachedObject)(const Context *rsc, const ScriptGroup *sg, rs_script_group *obj);
Jason Samsdbe66d62012-09-17 13:54:41 -0700311 } scriptgroup;
312
Jason Samsa36c50a2014-06-17 12:06:06 -0700313 struct {
314 bool (*init)(const Context *rsc, const Type *m);
315 void (*destroy)(const Context *rsc, const Type *m);
316 void (*updateCachedObject)(const Context *rsc, const Type *s, rs_type *obj);
317 } type;
318
319 struct {
320 bool (*init)(const Context *rsc, const Element *m);
321 void (*destroy)(const Context *rsc, const Element *m);
322 void (*updateCachedObject)(const Context *rsc, const Element *s, rs_element *obj);
323 } element;
324
Jason Sams9761c3f2013-11-26 18:10:59 -0800325 void (*finish)(const Context *rsc);
Jason Samsbad80742011-03-16 16:29:28 -0700326} RsdHalFunctions;
327
Jason Samsbad80742011-03-16 16:29:28 -0700328
329}
330}
331
Stephen Hines414a4612012-09-05 18:05:08 -0700332#ifdef __cplusplus
333extern "C" {
334#endif
Jason Samsbad80742011-03-16 16:29:28 -0700335
Stephen Hines414a4612012-09-05 18:05:08 -0700336bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
337
338#ifdef __cplusplus
339}
340#endif
Jason Samsbad80742011-03-16 16:29:28 -0700341
342#endif