Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 2 | * Copyright (C) 2011-2012 The Android Open Source Project |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 3 | * |
| 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 Sams | 3715b00 | 2012-02-16 16:07:49 -0800 | [diff] [blame] | 20 | #include <rsDefines.h> |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 21 | |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 22 | struct ANativeWindow; |
| 23 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | class Context; |
| 28 | class ObjectBase; |
| 29 | class Element; |
| 30 | class Type; |
| 31 | class Allocation; |
| 32 | class Script; |
| 33 | class ScriptC; |
Jason Sams | 9e0afb5 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 34 | class Path; |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 35 | class Program; |
Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 36 | class ProgramStore; |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 37 | class ProgramRaster; |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 38 | class ProgramVertex; |
| 39 | class ProgramFragment; |
| 40 | class Mesh; |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 41 | class Sampler; |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 42 | class FBOCache; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 43 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 44 | typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); |
| 45 | |
Jason Sams | 451cf2e | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 46 | typedef struct { |
| 47 | const void *in; |
| 48 | void *out; |
| 49 | const void *usr; |
Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 50 | size_t usrLen; |
Jason Sams | 451cf2e | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 51 | uint32_t x; |
| 52 | uint32_t y; |
| 53 | uint32_t z; |
| 54 | uint32_t lod; |
| 55 | RsAllocationCubemapFace face; |
| 56 | uint32_t ar[16]; |
Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 57 | |
| 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 Sams | 451cf2e | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 69 | } RsForEachStubParamStruct; |
| 70 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 71 | /** |
| 72 | * Script management functions |
| 73 | */ |
| 74 | typedef struct { |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 75 | bool (*initGraphics)(const Context *); |
| 76 | void (*shutdownGraphics)(const Context *); |
Alex Sakhartchouk | 7257c7e | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 77 | bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 78 | void (*swap)(const Context *); |
| 79 | |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 80 | void (*shutdownDriver)(Context *); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 81 | void (*getVersion)(unsigned int *major, unsigned int *minor); |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 82 | void (*setPriority)(const Context *, int32_t priority); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 83 | |
| 84 | |
| 85 | |
| 86 | struct { |
Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 87 | 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 Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 92 | uint32_t flags); |
Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 93 | bool (*initIntrinsic)(const Context *rsc, Script *s, |
Stephen Hines | 41d6c76 | 2012-08-21 17:07:38 -0700 | [diff] [blame] | 94 | RsScriptIntrinsicID iid, |
Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 95 | Element *e); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 96 | |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 97 | void (*invokeFunction)(const Context *rsc, Script *s, |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 98 | uint32_t slot, |
| 99 | const void *params, |
| 100 | size_t paramLength); |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 101 | int (*invokeRoot)(const Context *rsc, Script *s); |
| 102 | void (*invokeForEach)(const Context *rsc, |
| 103 | Script *s, |
Jason Sams | 35e429e | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 104 | uint32_t slot, |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 105 | 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 Hines | 4ee16ff | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 111 | void (*invokeFreeChildren)(const Context *rsc, Script *s); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 112 | |
| 113 | void (*setGlobalVar)(const Context *rsc, const Script *s, |
| 114 | uint32_t slot, |
| 115 | void *data, |
| 116 | size_t dataLength); |
Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 117 | 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 124 | void (*setGlobalBind)(const Context *rsc, const Script *s, |
| 125 | uint32_t slot, |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 126 | Allocation *data); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 127 | 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 Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 134 | struct { |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 135 | 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 Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 142 | |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 143 | int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc); |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 144 | 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 Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 147 | |
| 148 | void (*data1D)(const Context *rsc, const Allocation *alloc, |
| 149 | uint32_t xoff, uint32_t lod, uint32_t count, |
Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 150 | const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 151 | 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 Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 154 | const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 155 | 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 Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 158 | uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 159 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 160 | 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 Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 178 | // 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 Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 199 | void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, |
Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 200 | const void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 201 | void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, |
Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 202 | const void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 203 | |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 204 | void (*generateMipmaps)(const Context *rsc, const Allocation *alloc); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 205 | } allocation; |
| 206 | |
| 207 | struct { |
Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 208 | 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 Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 213 | 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 Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 218 | |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 219 | struct { |
| 220 | bool (*init)(const Context *rsc, const ProgramVertex *pv, |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 221 | const char* shader, size_t shaderLen, |
| 222 | const char** textureNames, size_t textureNamesCount, |
| 223 | const size_t *textureNamesLength); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 224 | 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 Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 230 | const char* shader, size_t shaderLen, |
| 231 | const char** textureNames, size_t textureNamesCount, |
| 232 | const size_t *textureNamesLength); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 233 | 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 242 | |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 243 | struct { |
Jason Sams | 9e0afb5 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 244 | 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 Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 251 | bool (*init)(const Context *rsc, const Sampler *m); |
| 252 | void (*destroy)(const Context *rsc, const Sampler *m); |
| 253 | } sampler; |
| 254 | |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 255 | 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 261 | } RsdHalFunctions; |
| 262 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 263 | |
| 264 | } |
| 265 | } |
| 266 | |
Stephen Hines | 414a461 | 2012-09-05 18:05:08 -0700 | [diff] [blame^] | 267 | #ifdef __cplusplus |
| 268 | extern "C" { |
| 269 | #endif |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 270 | |
Stephen Hines | 414a461 | 2012-09-05 18:05:08 -0700 | [diff] [blame^] | 271 | bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor); |
| 272 | |
| 273 | #ifdef __cplusplus |
| 274 | } |
| 275 | #endif |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 276 | |
| 277 | #endif |
| 278 | |