blob: 5903805bb0dc2a2fd441e04cb4f1e1261b172cf9 [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;
50 size_t usr_len;
51 uint32_t x;
52 uint32_t y;
53 uint32_t z;
54 uint32_t lod;
55 RsAllocationCubemapFace face;
56 uint32_t ar[16];
57} RsForEachStubParamStruct;
58
Jason Samsbad80742011-03-16 16:29:28 -070059/**
60 * Script management functions
61 */
62typedef struct {
Jason Sams4b3de472011-04-06 17:52:23 -070063 bool (*initGraphics)(const Context *);
64 void (*shutdownGraphics)(const Context *);
Alex Sakhartchouk7257c7e2011-05-17 12:32:47 -070065 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow);
Jason Sams4b3de472011-04-06 17:52:23 -070066 void (*swap)(const Context *);
67
Jason Samscdfdb8f2011-03-17 16:12:47 -070068 void (*shutdownDriver)(Context *);
Jason Samsbad80742011-03-16 16:29:28 -070069 void (*getVersion)(unsigned int *major, unsigned int *minor);
Jason Samscdfdb8f2011-03-17 16:12:47 -070070 void (*setPriority)(const Context *, int32_t priority);
Jason Samsbad80742011-03-16 16:29:28 -070071
72
73
74 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -070075 bool (*init)(const Context *rsc, ScriptC *s,
76 char const *resName,
77 char const *cacheDir,
78 uint8_t const *bitcode,
79 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -070080 uint32_t flags);
Jason Samsbad80742011-03-16 16:29:28 -070081
Jason Samscdfdb8f2011-03-17 16:12:47 -070082 void (*invokeFunction)(const Context *rsc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -070083 uint32_t slot,
84 const void *params,
85 size_t paramLength);
Jason Samscdfdb8f2011-03-17 16:12:47 -070086 int (*invokeRoot)(const Context *rsc, Script *s);
87 void (*invokeForEach)(const Context *rsc,
88 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -070089 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -070090 const Allocation * ain,
91 Allocation * aout,
92 const void * usr,
93 uint32_t usrLen,
94 const RsScriptCall *sc);
95 void (*invokeInit)(const Context *rsc, Script *s);
Stephen Hines4ee16ff2011-08-31 17:41:39 -070096 void (*invokeFreeChildren)(const Context *rsc, Script *s);
Jason Samsbad80742011-03-16 16:29:28 -070097
98 void (*setGlobalVar)(const Context *rsc, const Script *s,
99 uint32_t slot,
100 void *data,
101 size_t dataLength);
Stephen Hines2980f072012-04-09 18:26:29 -0700102 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s,
103 uint32_t slot,
104 void *data,
105 size_t dataLength,
106 const Element *e,
107 const size_t *dims,
108 size_t dimLength);
Jason Samsbad80742011-03-16 16:29:28 -0700109 void (*setGlobalBind)(const Context *rsc, const Script *s,
110 uint32_t slot,
Jason Sams807fdc42012-07-25 17:55:39 -0700111 Allocation *data);
Jason Samsbad80742011-03-16 16:29:28 -0700112 void (*setGlobalObj)(const Context *rsc, const Script *s,
113 uint32_t slot,
114 ObjectBase *data);
115
116 void (*destroy)(const Context *rsc, Script *s);
117 } script;
118
Jason Sams8feea4e2011-03-18 15:03:25 -0700119 struct {
Jason Samseb4fe182011-05-26 16:33:01 -0700120 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
121 void (*destroy)(const Context *rsc, Allocation *alloc);
122
123 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
124 bool zeroNew);
125 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
126 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800127
Jason Sams41e373d2012-01-13 14:01:20 -0800128 int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800129 void (*setSurfaceTexture)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
130 void (*ioSend)(const Context *rsc, Allocation *alloc);
131 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700132
133 void (*data1D)(const Context *rsc, const Allocation *alloc,
134 uint32_t xoff, uint32_t lod, uint32_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800135 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700136 void (*data2D)(const Context *rsc, const Allocation *alloc,
137 uint32_t xoff, uint32_t yoff, uint32_t lod,
138 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800139 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700140 void (*data3D)(const Context *rsc, const Allocation *alloc,
141 uint32_t xoff, uint32_t yoff, uint32_t zoff,
142 uint32_t lod, RsAllocationCubemapFace face,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800143 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700144
Jason Sams807fdc42012-07-25 17:55:39 -0700145 void (*read1D)(const Context *rsc, const Allocation *alloc,
146 uint32_t xoff, uint32_t lod, uint32_t count,
147 void *data, size_t sizeBytes);
148 void (*read2D)(const Context *rsc, const Allocation *alloc,
149 uint32_t xoff, uint32_t yoff, uint32_t lod,
150 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
151 void *data, size_t sizeBytes);
152 void (*read3D)(const Context *rsc, const Allocation *alloc,
153 uint32_t xoff, uint32_t yoff, uint32_t zoff,
154 uint32_t lod, RsAllocationCubemapFace face,
155 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes);
156
157 // Lock and unlock make a 1D region of memory available to the CPU
158 // for direct access by pointer. Once unlock is called control is
159 // returned to the SOC driver.
160 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
161 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
162
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700163 // Allocation to allocation copies
164 void (*allocData1D)(const Context *rsc,
165 const Allocation *dstAlloc,
166 uint32_t dstXoff, uint32_t dstLod, uint32_t count,
167 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
168 void (*allocData2D)(const Context *rsc,
169 const Allocation *dstAlloc,
170 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
171 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
172 const Allocation *srcAlloc,
173 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
174 RsAllocationCubemapFace srcFace);
175 void (*allocData3D)(const Context *rsc,
176 const Allocation *dstAlloc,
177 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
178 uint32_t dstLod, RsAllocationCubemapFace dstFace,
179 uint32_t w, uint32_t h, uint32_t d,
180 const Allocation *srcAlloc,
181 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
182 uint32_t srcLod, RsAllocationCubemapFace srcFace);
183
Jason Samseb4fe182011-05-26 16:33:01 -0700184 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800185 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700186 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800187 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700188
189
190 } allocation;
191
192 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700193 bool (*init)(const Context *rsc, const ProgramStore *ps);
194 void (*setActive)(const Context *rsc, const ProgramStore *ps);
195 void (*destroy)(const Context *rsc, const ProgramStore *ps);
196 } store;
197
Jason Sams721acc42011-04-06 11:23:54 -0700198 struct {
199 bool (*init)(const Context *rsc, const ProgramRaster *ps);
200 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
201 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
202 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700203
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700204 struct {
205 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800206 const char* shader, size_t shaderLen,
207 const char** textureNames, size_t textureNamesCount,
208 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700209 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
210 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
211 } vertex;
212
213 struct {
214 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800215 const char* shader, size_t shaderLen,
216 const char** textureNames, size_t textureNamesCount,
217 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700218 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
219 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
220 } fragment;
221
222 struct {
223 bool (*init)(const Context *rsc, const Mesh *m);
224 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
225 void (*destroy)(const Context *rsc, const Mesh *m);
226 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700227
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700228 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700229 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
230 bool (*initDynamic)(const Context *rsc, const Path *m);
231 void (*draw)(const Context *rsc, const Path *m);
232 void (*destroy)(const Context *rsc, const Path *m);
233 } path;
234
235 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700236 bool (*init)(const Context *rsc, const Sampler *m);
237 void (*destroy)(const Context *rsc, const Sampler *m);
238 } sampler;
239
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700240 struct {
241 bool (*init)(const Context *rsc, const FBOCache *fb);
242 void (*setActive)(const Context *rsc, const FBOCache *fb);
243 void (*destroy)(const Context *rsc, const FBOCache *fb);
244 } framebuffer;
245
Jason Samsbad80742011-03-16 16:29:28 -0700246} RsdHalFunctions;
247
Jason Samsbad80742011-03-16 16:29:28 -0700248
249}
250}
251
252
253bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor);
254
255#endif
256