blob: 4f562d565f79702fcd1a8df820005041798a1297 [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
90
91
92 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -070093 bool (*init)(const Context *rsc, ScriptC *s,
94 char const *resName,
95 char const *cacheDir,
96 uint8_t const *bitcode,
97 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -070098 uint32_t flags);
Jason Sams8eaba4f2012-08-14 14:38:05 -070099 bool (*initIntrinsic)(const Context *rsc, Script *s,
Stephen Hines41d6c762012-08-21 17:07:38 -0700100 RsScriptIntrinsicID iid,
Jason Sams8eaba4f2012-08-14 14:38:05 -0700101 Element *e);
Jason Samsbad80742011-03-16 16:29:28 -0700102
Jason Samscdfdb8f2011-03-17 16:12:47 -0700103 void (*invokeFunction)(const Context *rsc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -0700104 uint32_t slot,
105 const void *params,
106 size_t paramLength);
Jason Samscdfdb8f2011-03-17 16:12:47 -0700107 int (*invokeRoot)(const Context *rsc, Script *s);
108 void (*invokeForEach)(const Context *rsc,
109 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -0700110 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700111 const Allocation * ain,
112 Allocation * aout,
113 const void * usr,
114 uint32_t usrLen,
115 const RsScriptCall *sc);
116 void (*invokeInit)(const Context *rsc, Script *s);
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700117 void (*invokeFreeChildren)(const Context *rsc, Script *s);
Jason Samsbad80742011-03-16 16:29:28 -0700118
119 void (*setGlobalVar)(const Context *rsc, const Script *s,
120 uint32_t slot,
121 void *data,
122 size_t dataLength);
Stephen Hines2980f072012-04-09 18:26:29 -0700123 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
124 uint32_t slot,
125 void *data,
126 size_t dataLength,
127 const Element *e,
128 const size_t *dims,
129 size_t dimLength);
Jason Samsbad80742011-03-16 16:29:28 -0700130 void (*setGlobalBind)(const Context *rsc, const Script *s,
131 uint32_t slot,
Jason Sams807fdc42012-07-25 17:55:39 -0700132 Allocation *data);
Jason Samsbad80742011-03-16 16:29:28 -0700133 void (*setGlobalObj)(const Context *rsc, const Script *s,
134 uint32_t slot,
135 ObjectBase *data);
136
137 void (*destroy)(const Context *rsc, Script *s);
138 } script;
139
Jason Sams8feea4e2011-03-18 15:03:25 -0700140 struct {
Jason Samseb4fe182011-05-26 16:33:01 -0700141 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
142 void (*destroy)(const Context *rsc, Allocation *alloc);
143
144 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
145 bool zeroNew);
146 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
147 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800148
Jason Sams41e373d2012-01-13 14:01:20 -0800149 int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800150 void (*setSurfaceTexture)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
151 void (*ioSend)(const Context *rsc, Allocation *alloc);
152 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700153
154 void (*data1D)(const Context *rsc, const Allocation *alloc,
155 uint32_t xoff, uint32_t lod, uint32_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800156 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700157 void (*data2D)(const Context *rsc, const Allocation *alloc,
158 uint32_t xoff, uint32_t yoff, uint32_t lod,
159 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800160 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700161 void (*data3D)(const Context *rsc, const Allocation *alloc,
162 uint32_t xoff, uint32_t yoff, uint32_t zoff,
163 uint32_t lod, RsAllocationCubemapFace face,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800164 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700165
Jason Sams807fdc42012-07-25 17:55:39 -0700166 void (*read1D)(const Context *rsc, const Allocation *alloc,
167 uint32_t xoff, uint32_t lod, uint32_t count,
168 void *data, size_t sizeBytes);
169 void (*read2D)(const Context *rsc, const Allocation *alloc,
170 uint32_t xoff, uint32_t yoff, uint32_t lod,
171 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800172 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700173 void (*read3D)(const Context *rsc, const Allocation *alloc,
174 uint32_t xoff, uint32_t yoff, uint32_t zoff,
175 uint32_t lod, RsAllocationCubemapFace face,
176 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes);
177
178 // Lock and unlock make a 1D region of memory available to the CPU
179 // for direct access by pointer. Once unlock is called control is
180 // returned to the SOC driver.
181 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
182 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
183
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700184 // Allocation to allocation copies
185 void (*allocData1D)(const Context *rsc,
186 const Allocation *dstAlloc,
187 uint32_t dstXoff, uint32_t dstLod, uint32_t count,
188 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
189 void (*allocData2D)(const Context *rsc,
190 const Allocation *dstAlloc,
191 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
192 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
193 const Allocation *srcAlloc,
194 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
195 RsAllocationCubemapFace srcFace);
196 void (*allocData3D)(const Context *rsc,
197 const Allocation *dstAlloc,
198 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
199 uint32_t dstLod, RsAllocationCubemapFace dstFace,
200 uint32_t w, uint32_t h, uint32_t d,
201 const Allocation *srcAlloc,
202 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
203 uint32_t srcLod, RsAllocationCubemapFace srcFace);
204
Jason Samseb4fe182011-05-26 16:33:01 -0700205 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800206 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700207 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800208 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700209
Jason Sams61a4bb72012-07-25 19:33:43 -0700210 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700211 } allocation;
212
213 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700214 bool (*init)(const Context *rsc, const ProgramStore *ps);
215 void (*setActive)(const Context *rsc, const ProgramStore *ps);
216 void (*destroy)(const Context *rsc, const ProgramStore *ps);
217 } store;
218
Jason Sams721acc42011-04-06 11:23:54 -0700219 struct {
220 bool (*init)(const Context *rsc, const ProgramRaster *ps);
221 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
222 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
223 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700224
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700225 struct {
226 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800227 const char* shader, size_t shaderLen,
228 const char** textureNames, size_t textureNamesCount,
229 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700230 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
231 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
232 } vertex;
233
234 struct {
235 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800236 const char* shader, size_t shaderLen,
237 const char** textureNames, size_t textureNamesCount,
238 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700239 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
240 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
241 } fragment;
242
243 struct {
244 bool (*init)(const Context *rsc, const Mesh *m);
245 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
246 void (*destroy)(const Context *rsc, const Mesh *m);
247 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700248
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700249 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700250 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
251 bool (*initDynamic)(const Context *rsc, const Path *m);
252 void (*draw)(const Context *rsc, const Path *m);
253 void (*destroy)(const Context *rsc, const Path *m);
254 } path;
255
256 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700257 bool (*init)(const Context *rsc, const Sampler *m);
258 void (*destroy)(const Context *rsc, const Sampler *m);
259 } sampler;
260
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700261 struct {
262 bool (*init)(const Context *rsc, const FBOCache *fb);
263 void (*setActive)(const Context *rsc, const FBOCache *fb);
264 void (*destroy)(const Context *rsc, const FBOCache *fb);
265 } framebuffer;
266
Jason Samsdbe66d62012-09-17 13:54:41 -0700267 struct {
Jason Sams709a0972012-11-15 18:18:04 -0800268 bool (*init)(const Context *rsc, ScriptGroup *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700269 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
270 const ScriptKernelID *kid, Allocation *);
271 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
272 const ScriptKernelID *kid, Allocation *);
273 void (*execute)(const Context *rsc, const ScriptGroup *sg);
274 void (*destroy)(const Context *rsc, const ScriptGroup *sg);
275 } scriptgroup;
276
Jason Samsbad80742011-03-16 16:29:28 -0700277} RsdHalFunctions;
278
Jason Samsbad80742011-03-16 16:29:28 -0700279
280}
281}
282
Stephen Hines414a4612012-09-05 18:05:08 -0700283#ifdef __cplusplus
284extern "C" {
285#endif
Jason Samsbad80742011-03-16 16:29:28 -0700286
Stephen Hines414a4612012-09-05 18:05:08 -0700287bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
288
289#ifdef __cplusplus
290}
291#endif
Jason Samsbad80742011-03-16 16:29:28 -0700292
293#endif
294