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; |
| 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Script management functions |
| 61 | */ |
| 62 | typedef struct { |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 63 | bool (*initGraphics)(const Context *); |
| 64 | void (*shutdownGraphics)(const Context *); |
Alex Sakhartchouk | 7257c7e | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 65 | bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); |
Jason Sams | 4b3de47 | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 66 | void (*swap)(const Context *); |
| 67 | |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 68 | void (*shutdownDriver)(Context *); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 69 | void (*getVersion)(unsigned int *major, unsigned int *minor); |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 70 | void (*setPriority)(const Context *, int32_t priority); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 71 | |
| 72 | |
| 73 | |
| 74 | struct { |
Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 75 | 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 Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 80 | uint32_t flags); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 81 | |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 82 | void (*invokeFunction)(const Context *rsc, Script *s, |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 83 | uint32_t slot, |
| 84 | const void *params, |
| 85 | size_t paramLength); |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 86 | int (*invokeRoot)(const Context *rsc, Script *s); |
| 87 | void (*invokeForEach)(const Context *rsc, |
| 88 | Script *s, |
Jason Sams | 35e429e | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 89 | uint32_t slot, |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 90 | 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 Hines | 4ee16ff | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 96 | void (*invokeFreeChildren)(const Context *rsc, Script *s); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 97 | |
| 98 | void (*setGlobalVar)(const Context *rsc, const Script *s, |
| 99 | uint32_t slot, |
| 100 | void *data, |
| 101 | size_t dataLength); |
Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 102 | 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 109 | void (*setGlobalBind)(const Context *rsc, const Script *s, |
| 110 | uint32_t slot, |
| 111 | void *data); |
| 112 | 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 Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 119 | struct { |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 120 | 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 Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 127 | |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 128 | int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc); |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 129 | 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 Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 132 | |
| 133 | void (*data1D)(const Context *rsc, const Allocation *alloc, |
| 134 | uint32_t xoff, uint32_t lod, uint32_t count, |
Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 135 | const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 136 | 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 Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 139 | const void *data, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 140 | 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 Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 143 | 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] | 144 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 145 | // Allocation to allocation copies |
| 146 | void (*allocData1D)(const Context *rsc, |
| 147 | const Allocation *dstAlloc, |
| 148 | uint32_t dstXoff, uint32_t dstLod, uint32_t count, |
| 149 | const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); |
| 150 | void (*allocData2D)(const Context *rsc, |
| 151 | const Allocation *dstAlloc, |
| 152 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, |
| 153 | RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, |
| 154 | const Allocation *srcAlloc, |
| 155 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, |
| 156 | RsAllocationCubemapFace srcFace); |
| 157 | void (*allocData3D)(const Context *rsc, |
| 158 | const Allocation *dstAlloc, |
| 159 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
| 160 | uint32_t dstLod, RsAllocationCubemapFace dstFace, |
| 161 | uint32_t w, uint32_t h, uint32_t d, |
| 162 | const Allocation *srcAlloc, |
| 163 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
| 164 | uint32_t srcLod, RsAllocationCubemapFace srcFace); |
| 165 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 166 | void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, |
Alex Sakhartchouk | c794cd5 | 2012-02-13 11:57:32 -0800 | [diff] [blame] | 167 | const void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 168 | 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] | 169 | const void *data, uint32_t elementOff, size_t sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 170 | |
| 171 | |
| 172 | } allocation; |
| 173 | |
| 174 | struct { |
Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 175 | bool (*init)(const Context *rsc, const ProgramStore *ps); |
| 176 | void (*setActive)(const Context *rsc, const ProgramStore *ps); |
| 177 | void (*destroy)(const Context *rsc, const ProgramStore *ps); |
| 178 | } store; |
| 179 | |
Jason Sams | 721acc4 | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 180 | struct { |
| 181 | bool (*init)(const Context *rsc, const ProgramRaster *ps); |
| 182 | void (*setActive)(const Context *rsc, const ProgramRaster *ps); |
| 183 | void (*destroy)(const Context *rsc, const ProgramRaster *ps); |
| 184 | } raster; |
Jason Sams | 8feea4e | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 185 | |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 186 | struct { |
| 187 | bool (*init)(const Context *rsc, const ProgramVertex *pv, |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 188 | const char* shader, size_t shaderLen, |
| 189 | const char** textureNames, size_t textureNamesCount, |
| 190 | const size_t *textureNamesLength); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 191 | void (*setActive)(const Context *rsc, const ProgramVertex *pv); |
| 192 | void (*destroy)(const Context *rsc, const ProgramVertex *pv); |
| 193 | } vertex; |
| 194 | |
| 195 | struct { |
| 196 | bool (*init)(const Context *rsc, const ProgramFragment *pf, |
Alex Sakhartchouk | 748eb07 | 2012-02-15 16:21:46 -0800 | [diff] [blame] | 197 | const char* shader, size_t shaderLen, |
| 198 | const char** textureNames, size_t textureNamesCount, |
| 199 | const size_t *textureNamesLength); |
Alex Sakhartchouk | a04e30d | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 200 | void (*setActive)(const Context *rsc, const ProgramFragment *pf); |
| 201 | void (*destroy)(const Context *rsc, const ProgramFragment *pf); |
| 202 | } fragment; |
| 203 | |
| 204 | struct { |
| 205 | bool (*init)(const Context *rsc, const Mesh *m); |
| 206 | void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); |
| 207 | void (*destroy)(const Context *rsc, const Mesh *m); |
| 208 | } mesh; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 209 | |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 210 | struct { |
Jason Sams | 9e0afb5 | 2011-10-31 13:23:43 -0700 | [diff] [blame] | 211 | bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops); |
| 212 | bool (*initDynamic)(const Context *rsc, const Path *m); |
| 213 | void (*draw)(const Context *rsc, const Path *m); |
| 214 | void (*destroy)(const Context *rsc, const Path *m); |
| 215 | } path; |
| 216 | |
| 217 | struct { |
Alex Sakhartchouk | 7f126c7 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 218 | bool (*init)(const Context *rsc, const Sampler *m); |
| 219 | void (*destroy)(const Context *rsc, const Sampler *m); |
| 220 | } sampler; |
| 221 | |
Alex Sakhartchouk | da6d34a | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 222 | struct { |
| 223 | bool (*init)(const Context *rsc, const FBOCache *fb); |
| 224 | void (*setActive)(const Context *rsc, const FBOCache *fb); |
| 225 | void (*destroy)(const Context *rsc, const FBOCache *fb); |
| 226 | } framebuffer; |
| 227 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 228 | } RsdHalFunctions; |
| 229 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 230 | |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | |
| 235 | bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor); |
| 236 | |
| 237 | #endif |
| 238 | |