blob: 16bd890fb1d4dda40daa9c406c5a54a4f224f567 [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 Sams3715b002012-02-16 16:07:49 -080020#include <rsDefines.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 Samsbad80742011-03-16 16:29:28 -070048typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
49
Jason Sams451cf2e2011-08-17 13:46:46 -070050typedef struct {
51 const void *in;
52 void *out;
53 const void *usr;
Jason Sams8eaba4f2012-08-14 14:38:05 -070054 size_t usrLen;
Jason Sams451cf2e2011-08-17 13:46:46 -070055 uint32_t x;
56 uint32_t y;
57 uint32_t z;
58 uint32_t lod;
59 RsAllocationCubemapFace face;
60 uint32_t ar[16];
Jason Samsbee28c62012-10-25 18:15:54 -070061 uint32_t lid;
Jason Sams8eaba4f2012-08-14 14:38:05 -070062
63 uint32_t dimX;
64 uint32_t dimY;
65 uint32_t dimZ;
66 uint32_t dimArray;
67
68 const uint8_t *ptrIn;
69 uint8_t *ptrOut;
70 uint32_t eStrideIn;
71 uint32_t eStrideOut;
72 uint32_t yStrideIn;
73 uint32_t yStrideOut;
Jason Samscf9ea9f2012-09-23 17:00:54 -070074 uint32_t slot;
Jason Sams451cf2e2011-08-17 13:46:46 -070075} RsForEachStubParamStruct;
76
Jason Samsbad80742011-03-16 16:29:28 -070077/**
78 * Script management functions
79 */
80typedef struct {
Jason Sams4b3de472011-04-06 17:52:23 -070081 bool (*initGraphics)(const Context *);
82 void (*shutdownGraphics)(const Context *);
Alex Sakhartchouk7257c7e2011-05-17 12:32:47 -070083 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
Jason Sams4b3de472011-04-06 17:52:23 -070084 void (*swap)(const Context *);
85
Jason Samscdfdb8f2011-03-17 16:12:47 -070086 void (*shutdownDriver)(Context *);
Jason Samsbad80742011-03-16 16:29:28 -070087 void (*getVersion)(unsigned int *major, unsigned int *minor);
Jason Samscdfdb8f2011-03-17 16:12:47 -070088 void (*setPriority)(const Context *, int32_t priority);
Jason Samsbad80742011-03-16 16:29:28 -070089
Tim Murray34689382013-03-11 12:12:03 -070090 void* (*allocRuntimeMem)(size_t size, uint32_t flags);
91 void (*freeRuntimeMem)(void* ptr);
Jason Samsbad80742011-03-16 16:29:28 -070092
93 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -070094 bool (*init)(const Context *rsc, ScriptC *s,
95 char const *resName,
96 char const *cacheDir,
97 uint8_t const *bitcode,
98 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -070099 uint32_t flags);
Jason Sams8eaba4f2012-08-14 14:38:05 -0700100 bool (*initIntrinsic)(const Context *rsc, Script *s,
Stephen Hines41d6c762012-08-21 17:07:38 -0700101 RsScriptIntrinsicID iid,
Jason Sams8eaba4f2012-08-14 14:38:05 -0700102 Element *e);
Jason Samsbad80742011-03-16 16:29:28 -0700103
Jason Samscdfdb8f2011-03-17 16:12:47 -0700104 void (*invokeFunction)(const Context *rsc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -0700105 uint32_t slot,
106 const void *params,
107 size_t paramLength);
Jason Samscdfdb8f2011-03-17 16:12:47 -0700108 int (*invokeRoot)(const Context *rsc, Script *s);
109 void (*invokeForEach)(const Context *rsc,
110 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -0700111 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700112 const Allocation * ain,
113 Allocation * aout,
114 const void * usr,
Tim Murray099bc262013-03-20 16:54:03 -0700115 size_t usrLen,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700116 const RsScriptCall *sc);
117 void (*invokeInit)(const Context *rsc, Script *s);
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700118 void (*invokeFreeChildren)(const Context *rsc, Script *s);
Jason Samsbad80742011-03-16 16:29:28 -0700119
120 void (*setGlobalVar)(const Context *rsc, const Script *s,
121 uint32_t slot,
122 void *data,
123 size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -0700124 void (*getGlobalVar)(const Context *rsc, const Script *s,
125 uint32_t slot,
126 void *data,
127 size_t dataLength);
Stephen Hines2980f072012-04-09 18:26:29 -0700128 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
129 uint32_t slot,
130 void *data,
131 size_t dataLength,
132 const Element *e,
133 const size_t *dims,
134 size_t dimLength);
Jason Samsbad80742011-03-16 16:29:28 -0700135 void (*setGlobalBind)(const Context *rsc, const Script *s,
136 uint32_t slot,
Jason Sams807fdc42012-07-25 17:55:39 -0700137 Allocation *data);
Jason Samsbad80742011-03-16 16:29:28 -0700138 void (*setGlobalObj)(const Context *rsc, const Script *s,
139 uint32_t slot,
140 ObjectBase *data);
141
142 void (*destroy)(const Context *rsc, Script *s);
143 } script;
144
Jason Sams8feea4e2011-03-18 15:03:25 -0700145 struct {
Jason Samseb4fe182011-05-26 16:33:01 -0700146 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
147 void (*destroy)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700148 uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700149
150 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
151 bool zeroNew);
152 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
153 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800154
Jason Sams733396b2013-02-22 12:46:18 -0800155 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800156 void (*ioSend)(const Context *rsc, Allocation *alloc);
Jason Samsddceab92013-08-07 13:02:32 -0700157
158 /**
159 * A new gralloc buffer is in use. The pointers and strides in
160 * mHal.drvState.lod[0-2] will be updated with the new values.
161 *
162 * The new gralloc handle is provided in mHal.state.nativeBuffer
163 *
164 */
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800165 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700166
167 void (*data1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700168 uint32_t xoff, uint32_t lod, size_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800169 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700170 void (*data2D)(const Context *rsc, const Allocation *alloc,
171 uint32_t xoff, uint32_t yoff, uint32_t lod,
172 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800173 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700174 void (*data3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700175 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
176 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
177 size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700178
Jason Sams807fdc42012-07-25 17:55:39 -0700179 void (*read1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700180 uint32_t xoff, uint32_t lod, size_t count,
Jason Sams807fdc42012-07-25 17:55:39 -0700181 void *data, size_t sizeBytes);
182 void (*read2D)(const Context *rsc, const Allocation *alloc,
183 uint32_t xoff, uint32_t yoff, uint32_t lod,
184 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800185 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700186 void (*read3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700187 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
188 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
189 size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700190
191 // Lock and unlock make a 1D region of memory available to the CPU
192 // for direct access by pointer. Once unlock is called control is
193 // returned to the SOC driver.
194 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
195 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
196
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700197 // Allocation to allocation copies
198 void (*allocData1D)(const Context *rsc,
199 const Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700200 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700201 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
202 void (*allocData2D)(const Context *rsc,
203 const Allocation *dstAlloc,
204 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
205 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
206 const Allocation *srcAlloc,
207 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
208 RsAllocationCubemapFace srcFace);
209 void (*allocData3D)(const Context *rsc,
210 const Allocation *dstAlloc,
211 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700212 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700213 uint32_t w, uint32_t h, uint32_t d,
214 const Allocation *srcAlloc,
215 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700216 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700217
Jason Samseb4fe182011-05-26 16:33:01 -0700218 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800219 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700220 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800221 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700222
Jason Sams61a4bb72012-07-25 19:33:43 -0700223 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700224 } allocation;
225
226 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700227 bool (*init)(const Context *rsc, const ProgramStore *ps);
228 void (*setActive)(const Context *rsc, const ProgramStore *ps);
229 void (*destroy)(const Context *rsc, const ProgramStore *ps);
230 } store;
231
Jason Sams721acc42011-04-06 11:23:54 -0700232 struct {
233 bool (*init)(const Context *rsc, const ProgramRaster *ps);
234 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
235 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
236 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700237
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700238 struct {
239 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800240 const char* shader, size_t shaderLen,
241 const char** textureNames, size_t textureNamesCount,
242 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700243 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
244 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
245 } vertex;
246
247 struct {
248 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800249 const char* shader, size_t shaderLen,
250 const char** textureNames, size_t textureNamesCount,
251 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700252 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
253 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
254 } fragment;
255
256 struct {
257 bool (*init)(const Context *rsc, const Mesh *m);
258 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
259 void (*destroy)(const Context *rsc, const Mesh *m);
260 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700261
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700262 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700263 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
264 bool (*initDynamic)(const Context *rsc, const Path *m);
265 void (*draw)(const Context *rsc, const Path *m);
266 void (*destroy)(const Context *rsc, const Path *m);
267 } path;
268
269 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700270 bool (*init)(const Context *rsc, const Sampler *m);
271 void (*destroy)(const Context *rsc, const Sampler *m);
272 } sampler;
273
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700274 struct {
275 bool (*init)(const Context *rsc, const FBOCache *fb);
276 void (*setActive)(const Context *rsc, const FBOCache *fb);
277 void (*destroy)(const Context *rsc, const FBOCache *fb);
278 } framebuffer;
279
Jason Samsdbe66d62012-09-17 13:54:41 -0700280 struct {
Jason Sams709a0972012-11-15 18:18:04 -0800281 bool (*init)(const Context *rsc, ScriptGroup *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700282 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
283 const ScriptKernelID *kid, Allocation *);
284 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
285 const ScriptKernelID *kid, Allocation *);
286 void (*execute)(const Context *rsc, const ScriptGroup *sg);
287 void (*destroy)(const Context *rsc, const ScriptGroup *sg);
288 } scriptgroup;
289
Jason Samsbad80742011-03-16 16:29:28 -0700290} RsdHalFunctions;
291
Jason Samsbad80742011-03-16 16:29:28 -0700292
293}
294}
295
Stephen Hines414a4612012-09-05 18:05:08 -0700296#ifdef __cplusplus
297extern "C" {
298#endif
Jason Samsbad80742011-03-16 16:29:28 -0700299
Stephen Hines414a4612012-09-05 18:05:08 -0700300bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
301
302#ifdef __cplusplus
303}
304#endif
Jason Samsbad80742011-03-16 16:29:28 -0700305
306#endif
307