blob: c521ef56a1c830fb971445e2a0e5fa8ab7c21b2d [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;
33class ScriptC;
Jason Sams9e0afb52011-10-31 13:23:43 -070034class Path;
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070035class Program;
Jason Sams8feea4e2011-03-18 15:03:25 -070036class ProgramStore;
Jason Sams721acc42011-04-06 11:23:54 -070037class ProgramRaster;
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -070038class ProgramVertex;
39class ProgramFragment;
40class Mesh;
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -070041class Sampler;
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -070042class FBOCache;
Jason Samsbad80742011-03-16 16:29:28 -070043
Jason Samsbad80742011-03-16 16:29:28 -070044typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName);
45
Jason Sams451cf2e2011-08-17 13:46:46 -070046typedef struct {
47 const void *in;
48 void *out;
49 const void *usr;
Jason Sams8eaba4f2012-08-14 14:38:05 -070050 size_t usrLen;
Jason Sams451cf2e2011-08-17 13:46:46 -070051 uint32_t x;
52 uint32_t y;
53 uint32_t z;
54 uint32_t lod;
55 RsAllocationCubemapFace face;
56 uint32_t ar[16];
Jason Sams8eaba4f2012-08-14 14:38:05 -070057
58 uint32_t dimX;
59 uint32_t dimY;
60 uint32_t dimZ;
61 uint32_t dimArray;
62
63 const uint8_t *ptrIn;
64 uint8_t *ptrOut;
65 uint32_t eStrideIn;
66 uint32_t eStrideOut;
67 uint32_t yStrideIn;
68 uint32_t yStrideOut;
Jason Sams451cf2e2011-08-17 13:46:46 -070069} RsForEachStubParamStruct;
70
Jason Samsbad80742011-03-16 16:29:28 -070071/**
72 * Script management functions
73 */
74typedef struct {
Jason Sams4b3de472011-04-06 17:52:23 -070075 bool (*initGraphics)(const Context *);
76 void (*shutdownGraphics)(const Context *);
Alex Sakhartchouk7257c7e2011-05-17 12:32:47 -070077 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
Jason Sams4b3de472011-04-06 17:52:23 -070078 void (*swap)(const Context *);
79
Jason Samscdfdb8f2011-03-17 16:12:47 -070080 void (*shutdownDriver)(Context *);
Jason Samsbad80742011-03-16 16:29:28 -070081 void (*getVersion)(unsigned int *major, unsigned int *minor);
Jason Samscdfdb8f2011-03-17 16:12:47 -070082 void (*setPriority)(const Context *, int32_t priority);
Jason Samsbad80742011-03-16 16:29:28 -070083
84
85
86 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -070087 bool (*init)(const Context *rsc, ScriptC *s,
88 char const *resName,
89 char const *cacheDir,
90 uint8_t const *bitcode,
91 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -070092 uint32_t flags);
Jason Sams8eaba4f2012-08-14 14:38:05 -070093 bool (*initIntrinsic)(const Context *rsc, Script *s,
Stephen Hines41d6c762012-08-21 17:07:38 -070094 RsScriptIntrinsicID iid,
Jason Sams8eaba4f2012-08-14 14:38:05 -070095 Element *e);
Jason Samsbad80742011-03-16 16:29:28 -070096
Jason Samscdfdb8f2011-03-17 16:12:47 -070097 void (*invokeFunction)(const Context *rsc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -070098 uint32_t slot,
99 const void *params,
100 size_t paramLength);
Jason Samscdfdb8f2011-03-17 16:12:47 -0700101 int (*invokeRoot)(const Context *rsc, Script *s);
102 void (*invokeForEach)(const Context *rsc,
103 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -0700104 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -0700105 const Allocation * ain,
106 Allocation * aout,
107 const void * usr,
108 uint32_t usrLen,
109 const RsScriptCall *sc);
110 void (*invokeInit)(const Context *rsc, Script *s);
Stephen Hines4ee16ff2011-08-31 17:41:39 -0700111 void (*invokeFreeChildren)(const Context *rsc, Script *s);
Jason Samsbad80742011-03-16 16:29:28 -0700112
113 void (*setGlobalVar)(const Context *rsc, const Script *s,
114 uint32_t slot,
115 void *data,
116 size_t dataLength);
Stephen Hines2980f072012-04-09 18:26:29 -0700117 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
118 uint32_t slot,
119 void *data,
120 size_t dataLength,
121 const Element *e,
122 const size_t *dims,
123 size_t dimLength);
Jason Samsbad80742011-03-16 16:29:28 -0700124 void (*setGlobalBind)(const Context *rsc, const Script *s,
125 uint32_t slot,
Jason Sams807fdc42012-07-25 17:55:39 -0700126 Allocation *data);
Jason Samsbad80742011-03-16 16:29:28 -0700127 void (*setGlobalObj)(const Context *rsc, const Script *s,
128 uint32_t slot,
129 ObjectBase *data);
130
131 void (*destroy)(const Context *rsc, Script *s);
132 } script;
133
Jason Sams8feea4e2011-03-18 15:03:25 -0700134 struct {
Jason Samseb4fe182011-05-26 16:33:01 -0700135 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
136 void (*destroy)(const Context *rsc, Allocation *alloc);
137
138 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
139 bool zeroNew);
140 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
141 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800142
Jason Sams41e373d2012-01-13 14:01:20 -0800143 int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800144 void (*setSurfaceTexture)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
145 void (*ioSend)(const Context *rsc, Allocation *alloc);
146 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700147
148 void (*data1D)(const Context *rsc, const Allocation *alloc,
149 uint32_t xoff, uint32_t lod, uint32_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800150 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700151 void (*data2D)(const Context *rsc, const Allocation *alloc,
152 uint32_t xoff, uint32_t yoff, uint32_t lod,
153 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800154 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700155 void (*data3D)(const Context *rsc, const Allocation *alloc,
156 uint32_t xoff, uint32_t yoff, uint32_t zoff,
157 uint32_t lod, RsAllocationCubemapFace face,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800158 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700159
Jason Sams807fdc42012-07-25 17:55:39 -0700160 void (*read1D)(const Context *rsc, const Allocation *alloc,
161 uint32_t xoff, uint32_t lod, uint32_t count,
162 void *data, size_t sizeBytes);
163 void (*read2D)(const Context *rsc, const Allocation *alloc,
164 uint32_t xoff, uint32_t yoff, uint32_t lod,
165 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
166 void *data, size_t sizeBytes);
167 void (*read3D)(const Context *rsc, const Allocation *alloc,
168 uint32_t xoff, uint32_t yoff, uint32_t zoff,
169 uint32_t lod, RsAllocationCubemapFace face,
170 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes);
171
172 // Lock and unlock make a 1D region of memory available to the CPU
173 // for direct access by pointer. Once unlock is called control is
174 // returned to the SOC driver.
175 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
176 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
177
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700178 // Allocation to allocation copies
179 void (*allocData1D)(const Context *rsc,
180 const Allocation *dstAlloc,
181 uint32_t dstXoff, uint32_t dstLod, uint32_t count,
182 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
183 void (*allocData2D)(const Context *rsc,
184 const Allocation *dstAlloc,
185 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
186 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
187 const Allocation *srcAlloc,
188 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
189 RsAllocationCubemapFace srcFace);
190 void (*allocData3D)(const Context *rsc,
191 const Allocation *dstAlloc,
192 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
193 uint32_t dstLod, RsAllocationCubemapFace dstFace,
194 uint32_t w, uint32_t h, uint32_t d,
195 const Allocation *srcAlloc,
196 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
197 uint32_t srcLod, RsAllocationCubemapFace srcFace);
198
Jason Samseb4fe182011-05-26 16:33:01 -0700199 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800200 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700201 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800202 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700203
Jason Sams61a4bb72012-07-25 19:33:43 -0700204 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700205 } allocation;
206
207 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700208 bool (*init)(const Context *rsc, const ProgramStore *ps);
209 void (*setActive)(const Context *rsc, const ProgramStore *ps);
210 void (*destroy)(const Context *rsc, const ProgramStore *ps);
211 } store;
212
Jason Sams721acc42011-04-06 11:23:54 -0700213 struct {
214 bool (*init)(const Context *rsc, const ProgramRaster *ps);
215 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
216 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
217 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700218
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700219 struct {
220 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800221 const char* shader, size_t shaderLen,
222 const char** textureNames, size_t textureNamesCount,
223 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700224 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
225 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
226 } vertex;
227
228 struct {
229 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800230 const char* shader, size_t shaderLen,
231 const char** textureNames, size_t textureNamesCount,
232 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700233 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
234 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
235 } fragment;
236
237 struct {
238 bool (*init)(const Context *rsc, const Mesh *m);
239 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
240 void (*destroy)(const Context *rsc, const Mesh *m);
241 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700242
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700243 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700244 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
245 bool (*initDynamic)(const Context *rsc, const Path *m);
246 void (*draw)(const Context *rsc, const Path *m);
247 void (*destroy)(const Context *rsc, const Path *m);
248 } path;
249
250 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700251 bool (*init)(const Context *rsc, const Sampler *m);
252 void (*destroy)(const Context *rsc, const Sampler *m);
253 } sampler;
254
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700255 struct {
256 bool (*init)(const Context *rsc, const FBOCache *fb);
257 void (*setActive)(const Context *rsc, const FBOCache *fb);
258 void (*destroy)(const Context *rsc, const FBOCache *fb);
259 } framebuffer;
260
Jason Samsbad80742011-03-16 16:29:28 -0700261} RsdHalFunctions;
262
Jason Samsbad80742011-03-16 16:29:28 -0700263
264}
265}
266
267
268bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor);
269
270#endif
271