blob: 1ed26dc23d64d923d08959c75bf3d5374054962b [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);
148
149 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType,
150 bool zeroNew);
151 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src);
152 void (*markDirty)(const Context *rsc, const Allocation *alloc);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800153
Jason Sams733396b2013-02-22 12:46:18 -0800154 void * (*getSurface)(const Context *rsc, const Allocation *alloc);
155 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800156 void (*ioSend)(const Context *rsc, Allocation *alloc);
157 void (*ioReceive)(const Context *rsc, Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700158
159 void (*data1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700160 uint32_t xoff, uint32_t lod, size_t count,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800161 const void *data, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700162 void (*data2D)(const Context *rsc, const Allocation *alloc,
163 uint32_t xoff, uint32_t yoff, uint32_t lod,
164 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800165 const void *data, size_t sizeBytes, size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700166 void (*data3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700167 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
168 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes,
169 size_t stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700170
Jason Sams807fdc42012-07-25 17:55:39 -0700171 void (*read1D)(const Context *rsc, const Allocation *alloc,
Tim Murray099bc262013-03-20 16:54:03 -0700172 uint32_t xoff, uint32_t lod, size_t count,
Jason Sams807fdc42012-07-25 17:55:39 -0700173 void *data, size_t sizeBytes);
174 void (*read2D)(const Context *rsc, const Allocation *alloc,
175 uint32_t xoff, uint32_t yoff, uint32_t lod,
176 RsAllocationCubemapFace face, uint32_t w, uint32_t h,
Tim Murray358747a2012-11-26 13:52:04 -0800177 void *data, size_t sizeBytes, size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700178 void (*read3D)(const Context *rsc, const Allocation *alloc,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700179 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
180 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes,
181 size_t stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700182
183 // Lock and unlock make a 1D region of memory available to the CPU
184 // for direct access by pointer. Once unlock is called control is
185 // returned to the SOC driver.
186 void * (*lock1D)(const Context *rsc, const Allocation *alloc);
187 void (*unlock1D)(const Context *rsc, const Allocation *alloc);
188
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700189 // Allocation to allocation copies
190 void (*allocData1D)(const Context *rsc,
191 const Allocation *dstAlloc,
Tim Murray099bc262013-03-20 16:54:03 -0700192 uint32_t dstXoff, uint32_t dstLod, size_t count,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700193 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod);
194 void (*allocData2D)(const Context *rsc,
195 const Allocation *dstAlloc,
196 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod,
197 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h,
198 const Allocation *srcAlloc,
199 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod,
200 RsAllocationCubemapFace srcFace);
201 void (*allocData3D)(const Context *rsc,
202 const Allocation *dstAlloc,
203 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700204 uint32_t dstLod,
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700205 uint32_t w, uint32_t h, uint32_t d,
206 const Allocation *srcAlloc,
207 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700208 uint32_t srcLod);
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700209
Jason Samseb4fe182011-05-26 16:33:01 -0700210 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800211 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700212 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y,
Alex Sakhartchoukc794cd52012-02-13 11:57:32 -0800213 const void *data, uint32_t elementOff, size_t sizeBytes);
Jason Samseb4fe182011-05-26 16:33:01 -0700214
Jason Sams61a4bb72012-07-25 19:33:43 -0700215 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc);
Jason Samseb4fe182011-05-26 16:33:01 -0700216 } allocation;
217
218 struct {
Jason Sams8feea4e2011-03-18 15:03:25 -0700219 bool (*init)(const Context *rsc, const ProgramStore *ps);
220 void (*setActive)(const Context *rsc, const ProgramStore *ps);
221 void (*destroy)(const Context *rsc, const ProgramStore *ps);
222 } store;
223
Jason Sams721acc42011-04-06 11:23:54 -0700224 struct {
225 bool (*init)(const Context *rsc, const ProgramRaster *ps);
226 void (*setActive)(const Context *rsc, const ProgramRaster *ps);
227 void (*destroy)(const Context *rsc, const ProgramRaster *ps);
228 } raster;
Jason Sams8feea4e2011-03-18 15:03:25 -0700229
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700230 struct {
231 bool (*init)(const Context *rsc, const ProgramVertex *pv,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800232 const char* shader, size_t shaderLen,
233 const char** textureNames, size_t textureNamesCount,
234 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700235 void (*setActive)(const Context *rsc, const ProgramVertex *pv);
236 void (*destroy)(const Context *rsc, const ProgramVertex *pv);
237 } vertex;
238
239 struct {
240 bool (*init)(const Context *rsc, const ProgramFragment *pf,
Alex Sakhartchouk748eb072012-02-15 16:21:46 -0800241 const char* shader, size_t shaderLen,
242 const char** textureNames, size_t textureNamesCount,
243 const size_t *textureNamesLength);
Alex Sakhartchouka04e30d2011-04-29 16:49:08 -0700244 void (*setActive)(const Context *rsc, const ProgramFragment *pf);
245 void (*destroy)(const Context *rsc, const ProgramFragment *pf);
246 } fragment;
247
248 struct {
249 bool (*init)(const Context *rsc, const Mesh *m);
250 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len);
251 void (*destroy)(const Context *rsc, const Mesh *m);
252 } mesh;
Jason Samsbad80742011-03-16 16:29:28 -0700253
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700254 struct {
Jason Sams9e0afb52011-10-31 13:23:43 -0700255 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops);
256 bool (*initDynamic)(const Context *rsc, const Path *m);
257 void (*draw)(const Context *rsc, const Path *m);
258 void (*destroy)(const Context *rsc, const Path *m);
259 } path;
260
261 struct {
Alex Sakhartchouk7f126c72011-05-05 16:56:27 -0700262 bool (*init)(const Context *rsc, const Sampler *m);
263 void (*destroy)(const Context *rsc, const Sampler *m);
264 } sampler;
265
Alex Sakhartchoukda6d34a2011-05-13 14:53:34 -0700266 struct {
267 bool (*init)(const Context *rsc, const FBOCache *fb);
268 void (*setActive)(const Context *rsc, const FBOCache *fb);
269 void (*destroy)(const Context *rsc, const FBOCache *fb);
270 } framebuffer;
271
Jason Samsdbe66d62012-09-17 13:54:41 -0700272 struct {
Jason Sams709a0972012-11-15 18:18:04 -0800273 bool (*init)(const Context *rsc, ScriptGroup *sg);
Jason Samsdbe66d62012-09-17 13:54:41 -0700274 void (*setInput)(const Context *rsc, const ScriptGroup *sg,
275 const ScriptKernelID *kid, Allocation *);
276 void (*setOutput)(const Context *rsc, const ScriptGroup *sg,
277 const ScriptKernelID *kid, Allocation *);
278 void (*execute)(const Context *rsc, const ScriptGroup *sg);
279 void (*destroy)(const Context *rsc, const ScriptGroup *sg);
280 } scriptgroup;
281
Jason Samsbad80742011-03-16 16:29:28 -0700282} RsdHalFunctions;
283
Jason Samsbad80742011-03-16 16:29:28 -0700284
285}
286}
287
Stephen Hines414a4612012-09-05 18:05:08 -0700288#ifdef __cplusplus
289extern "C" {
290#endif
Jason Samsbad80742011-03-16 16:29:28 -0700291
Stephen Hines414a4612012-09-05 18:05:08 -0700292bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor);
293
294#ifdef __cplusplus
295}
296#endif
Jason Samsbad80742011-03-16 16:29:28 -0700297
298#endif
299