| 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; |
| Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 33 | class ScriptKernelID; |
| 34 | class ScriptFieldID; |
| 35 | class ScriptMethodID; |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 36 | class ScriptC; |
| Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 37 | class ScriptGroup; |
| Jason Sams | 9e0afb5 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 38 | class Path; |
| Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 39 | class Program; |
| Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 40 | class ProgramStore; |
| Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 41 | class ProgramRaster; |
| Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 42 | class ProgramVertex; |
| 43 | class ProgramFragment; |
| 44 | class Mesh; |
| Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 45 | class Sampler; |
| Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 46 | class FBOCache; |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 47 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 48 | typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); |
| 49 | |
| Jason Sams | 451cf2e | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 50 | typedef struct { |
| 51 | const void *in; |
| 52 | void *out; |
| 53 | const void *usr; |
| Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 54 | size_t usrLen; |
| Jason Sams | 451cf2e | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 55 | uint32_t x; |
| 56 | uint32_t y; |
| 57 | uint32_t z; |
| 58 | uint32_t lod; |
| 59 | RsAllocationCubemapFace face; |
| 60 | uint32_t ar[16]; |
| Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 61 | |
| 62 | uint32_t dimX; |
| 63 | uint32_t dimY; |
| 64 | uint32_t dimZ; |
| 65 | uint32_t dimArray; |
| 66 | |
| 67 | const uint8_t *ptrIn; |
| 68 | uint8_t *ptrOut; |
| 69 | uint32_t eStrideIn; |
| 70 | uint32_t eStrideOut; |
| 71 | uint32_t yStrideIn; |
| 72 | uint32_t yStrideOut; |
| Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 73 | uint32_t slot; |
| Jason Sams | 451cf2e | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 74 | } RsForEachStubParamStruct; |
| 75 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 76 | /** |
| 77 | * Script management functions |
| 78 | */ |
| 79 | typedef struct { |
| Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 80 | bool (*initGraphics)(const Context *); |
| 81 | void (*shutdownGraphics)(const Context *); |
| Alex Sakhartchouk | 7257c7e | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 82 | bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); |
| Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 83 | void (*swap)(const Context *); |
| 84 | |
| Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 85 | void (*shutdownDriver)(Context *); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 86 | void (*getVersion)(unsigned int *major, unsigned int *minor); |
| Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 87 | void (*setPriority)(const Context *, int32_t priority); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 88 | |
| 89 | |
| 90 | |
| 91 | struct { |
| Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 92 | bool (*init)(const Context *rsc, ScriptC *s, |
| 93 | char const *resName, |
| 94 | char const *cacheDir, |
| 95 | uint8_t const *bitcode, |
| 96 | size_t bitcodeSize, |
| Jason Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 97 | uint32_t flags); |
| Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 98 | bool (*initIntrinsic)(const Context *rsc, Script *s, |
| Stephen Hines | 41d6c76 | 2012-08-21 17:07:38 -0700 | [diff] [blame] | 99 | RsScriptIntrinsicID iid, |
| Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 100 | Element *e); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 101 | |
| Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 102 | void (*invokeFunction)(const Context *rsc, Script *s, |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 103 | uint32_t slot, |
| 104 | const void *params, |
| 105 | size_t paramLength); |
| Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 106 | int (*invokeRoot)(const Context *rsc, Script *s); |
| 107 | void (*invokeForEach)(const Context *rsc, |
| 108 | Script *s, |
| Jason Sams | 35e429e | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 109 | uint32_t slot, |
| Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 110 | const Allocation * ain, |
| 111 | Allocation * aout, |
| 112 | const void * usr, |
| 113 | uint32_t usrLen, |
| 114 | const RsScriptCall *sc); |
| 115 | void (*invokeInit)(const Context *rsc, Script *s); |
| Stephen Hines | 4ee16ff | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 116 | void (*invokeFreeChildren)(const Context *rsc, Script *s); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 117 | |
| 118 | void (*setGlobalVar)(const Context *rsc, const Script *s, |
| 119 | uint32_t slot, |
| 120 | void *data, |
| 121 | size_t dataLength); |
| Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 122 | void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s, |
| 123 | uint32_t slot, |
| 124 | void *data, |
| 125 | size_t dataLength, |
| 126 | const Element *e, |
| 127 | const size_t *dims, |
| 128 | size_t dimLength); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 129 | void (*setGlobalBind)(const Context *rsc, const Script *s, |
| 130 | uint32_t slot, |
| Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 131 | Allocation *data); |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 132 | void (*setGlobalObj)(const Context *rsc, const Script *s, |
| 133 | uint32_t slot, |
| 134 | ObjectBase *data); |
| 135 | |
| 136 | void (*destroy)(const Context *rsc, Script *s); |
| 137 | } script; |
| 138 | |
| Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 139 | struct { |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 140 | bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero); |
| 141 | void (*destroy)(const Context *rsc, Allocation *alloc); |
| 142 | |
| 143 | void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType, |
| 144 | bool zeroNew); |
| 145 | void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); |
| 146 | void (*markDirty)(const Context *rsc, const Allocation *alloc); |
| Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 147 | |
| Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 148 | int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc); |
| Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 149 | void (*setSurfaceTexture)(const Context *rsc, Allocation *alloc, ANativeWindow *sur); |
| 150 | void (*ioSend)(const Context *rsc, Allocation *alloc); |
| 151 | void (*ioReceive)(const Context *rsc, Allocation *alloc); |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 152 | |
| 153 | void (*data1D)(const Context *rsc, const Allocation *alloc, |
| 154 | uint32_t xoff, uint32_t lod, uint32_t count, |
| Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 155 | const void *data, size_t sizeBytes); |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 156 | void (*data2D)(const Context *rsc, const Allocation *alloc, |
| 157 | uint32_t xoff, uint32_t yoff, uint32_t lod, |
| 158 | RsAllocationCubemapFace face, uint32_t w, uint32_t h, |
| Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 159 | const void *data, size_t sizeBytes); |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 160 | void (*data3D)(const Context *rsc, const Allocation *alloc, |
| 161 | uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 162 | uint32_t lod, RsAllocationCubemapFace face, |
| Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 163 | 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] | 164 | |
| Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 165 | void (*read1D)(const Context *rsc, const Allocation *alloc, |
| 166 | uint32_t xoff, uint32_t lod, uint32_t count, |
| 167 | void *data, size_t sizeBytes); |
| 168 | void (*read2D)(const Context *rsc, const Allocation *alloc, |
| 169 | uint32_t xoff, uint32_t yoff, uint32_t lod, |
| 170 | RsAllocationCubemapFace face, uint32_t w, uint32_t h, |
| 171 | void *data, size_t sizeBytes); |
| 172 | void (*read3D)(const Context *rsc, const Allocation *alloc, |
| 173 | uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 174 | uint32_t lod, RsAllocationCubemapFace face, |
| 175 | uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes); |
| 176 | |
| 177 | // Lock and unlock make a 1D region of memory available to the CPU |
| 178 | // for direct access by pointer. Once unlock is called control is |
| 179 | // returned to the SOC driver. |
| 180 | void * (*lock1D)(const Context *rsc, const Allocation *alloc); |
| 181 | void (*unlock1D)(const Context *rsc, const Allocation *alloc); |
| 182 | |
| Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 183 | // Allocation to allocation copies |
| 184 | void (*allocData1D)(const Context *rsc, |
| 185 | const Allocation *dstAlloc, |
| 186 | uint32_t dstXoff, uint32_t dstLod, uint32_t count, |
| 187 | const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); |
| 188 | void (*allocData2D)(const Context *rsc, |
| 189 | const Allocation *dstAlloc, |
| 190 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, |
| 191 | RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, |
| 192 | const Allocation *srcAlloc, |
| 193 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, |
| 194 | RsAllocationCubemapFace srcFace); |
| 195 | void (*allocData3D)(const Context *rsc, |
| 196 | const Allocation *dstAlloc, |
| 197 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
| 198 | uint32_t dstLod, RsAllocationCubemapFace dstFace, |
| 199 | uint32_t w, uint32_t h, uint32_t d, |
| 200 | const Allocation *srcAlloc, |
| 201 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
| 202 | uint32_t srcLod, RsAllocationCubemapFace srcFace); |
| 203 | |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 204 | void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, |
| Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 205 | const void *data, uint32_t elementOff, size_t sizeBytes); |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 206 | 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] | 207 | const void *data, uint32_t elementOff, size_t sizeBytes); |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 208 | |
| Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 209 | void (*generateMipmaps)(const Context *rsc, const Allocation *alloc); |
| Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 210 | } allocation; |
| 211 | |
| 212 | struct { |
| Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 213 | bool (*init)(const Context *rsc, const ProgramStore *ps); |
| 214 | void (*setActive)(const Context *rsc, const ProgramStore *ps); |
| 215 | void (*destroy)(const Context *rsc, const ProgramStore *ps); |
| 216 | } store; |
| 217 | |
| Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 218 | struct { |
| 219 | bool (*init)(const Context *rsc, const ProgramRaster *ps); |
| 220 | void (*setActive)(const Context *rsc, const ProgramRaster *ps); |
| 221 | void (*destroy)(const Context *rsc, const ProgramRaster *ps); |
| 222 | } raster; |
| Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 223 | |
| Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 224 | struct { |
| 225 | bool (*init)(const Context *rsc, const ProgramVertex *pv, |
| Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 226 | const char* shader, size_t shaderLen, |
| 227 | const char** textureNames, size_t textureNamesCount, |
| 228 | const size_t *textureNamesLength); |
| Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 229 | void (*setActive)(const Context *rsc, const ProgramVertex *pv); |
| 230 | void (*destroy)(const Context *rsc, const ProgramVertex *pv); |
| 231 | } vertex; |
| 232 | |
| 233 | struct { |
| 234 | bool (*init)(const Context *rsc, const ProgramFragment *pf, |
| Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 235 | const char* shader, size_t shaderLen, |
| 236 | const char** textureNames, size_t textureNamesCount, |
| 237 | const size_t *textureNamesLength); |
| Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 238 | void (*setActive)(const Context *rsc, const ProgramFragment *pf); |
| 239 | void (*destroy)(const Context *rsc, const ProgramFragment *pf); |
| 240 | } fragment; |
| 241 | |
| 242 | struct { |
| 243 | bool (*init)(const Context *rsc, const Mesh *m); |
| 244 | void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); |
| 245 | void (*destroy)(const Context *rsc, const Mesh *m); |
| 246 | } mesh; |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 247 | |
| Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 248 | struct { |
| Jason Sams | 9e0afb5 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 249 | bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops); |
| 250 | bool (*initDynamic)(const Context *rsc, const Path *m); |
| 251 | void (*draw)(const Context *rsc, const Path *m); |
| 252 | void (*destroy)(const Context *rsc, const Path *m); |
| 253 | } path; |
| 254 | |
| 255 | struct { |
| Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 256 | bool (*init)(const Context *rsc, const Sampler *m); |
| 257 | void (*destroy)(const Context *rsc, const Sampler *m); |
| 258 | } sampler; |
| 259 | |
| Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 260 | struct { |
| 261 | bool (*init)(const Context *rsc, const FBOCache *fb); |
| 262 | void (*setActive)(const Context *rsc, const FBOCache *fb); |
| 263 | void (*destroy)(const Context *rsc, const FBOCache *fb); |
| 264 | } framebuffer; |
| 265 | |
| Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 266 | struct { |
| 267 | bool (*init)(const Context *rsc, const ScriptGroup *sg); |
| 268 | void (*setInput)(const Context *rsc, const ScriptGroup *sg, |
| 269 | const ScriptKernelID *kid, Allocation *); |
| 270 | void (*setOutput)(const Context *rsc, const ScriptGroup *sg, |
| 271 | const ScriptKernelID *kid, Allocation *); |
| 272 | void (*execute)(const Context *rsc, const ScriptGroup *sg); |
| 273 | void (*destroy)(const Context *rsc, const ScriptGroup *sg); |
| 274 | } scriptgroup; |
| 275 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 276 | } RsdHalFunctions; |
| 277 | |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 278 | |
| 279 | } |
| 280 | } |
| 281 | |
| Stephen Hines | 414a461 | 2012-09-05 18:05:08 -0700 | [diff] [blame] | 282 | #ifdef __cplusplus |
| 283 | extern "C" { |
| 284 | #endif |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 285 | |
| Stephen Hines | 414a461 | 2012-09-05 18:05:08 -0700 | [diff] [blame] | 286 | bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor); |
| 287 | |
| 288 | #ifdef __cplusplus |
| 289 | } |
| 290 | #endif |
| Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 291 | |
| 292 | #endif |
| 293 | |