Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 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 | |
| 20 | #include <RenderScriptDefines.h> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace renderscript { |
| 24 | |
| 25 | class Context; |
| 26 | class ObjectBase; |
| 27 | class Element; |
| 28 | class Type; |
| 29 | class Allocation; |
| 30 | class Script; |
| 31 | class ScriptC; |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 32 | class Program; |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 33 | class ProgramStore; |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 34 | class ProgramRaster; |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 35 | class ProgramVertex; |
| 36 | class ProgramFragment; |
| 37 | class Mesh; |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 38 | class Sampler; |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 39 | class FBOCache; |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 40 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 41 | typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); |
| 42 | |
Jason Sams | c1b4c1f | 2011-08-17 13:46:46 -0700 | [diff] [blame] | 43 | typedef struct { |
| 44 | const void *in; |
| 45 | void *out; |
| 46 | const void *usr; |
| 47 | size_t usr_len; |
| 48 | uint32_t x; |
| 49 | uint32_t y; |
| 50 | uint32_t z; |
| 51 | uint32_t lod; |
| 52 | RsAllocationCubemapFace face; |
| 53 | uint32_t ar[16]; |
| 54 | } RsForEachStubParamStruct; |
| 55 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 56 | /** |
| 57 | * Script management functions |
| 58 | */ |
| 59 | typedef struct { |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 60 | bool (*initGraphics)(const Context *); |
| 61 | void (*shutdownGraphics)(const Context *); |
Alex Sakhartchouk | 6c72eec | 2011-05-17 12:32:47 -0700 | [diff] [blame] | 62 | bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); |
Jason Sams | 803626f | 2011-04-06 17:52:23 -0700 | [diff] [blame] | 63 | void (*swap)(const Context *); |
| 64 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 65 | void (*shutdownDriver)(Context *); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 66 | void (*getVersion)(unsigned int *major, unsigned int *minor); |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 67 | void (*setPriority)(const Context *, int32_t priority); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 68 | |
| 69 | |
| 70 | |
| 71 | struct { |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 72 | bool (*init)(const Context *rsc, ScriptC *s, |
| 73 | char const *resName, |
| 74 | char const *cacheDir, |
| 75 | uint8_t const *bitcode, |
| 76 | size_t bitcodeSize, |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 77 | uint32_t flags); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 78 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 79 | void (*invokeFunction)(const Context *rsc, Script *s, |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 80 | uint32_t slot, |
| 81 | const void *params, |
| 82 | size_t paramLength); |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 83 | int (*invokeRoot)(const Context *rsc, Script *s); |
| 84 | void (*invokeForEach)(const Context *rsc, |
| 85 | Script *s, |
Jason Sams | 92b0eab | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 86 | uint32_t slot, |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 87 | const Allocation * ain, |
| 88 | Allocation * aout, |
| 89 | const void * usr, |
| 90 | uint32_t usrLen, |
| 91 | const RsScriptCall *sc); |
| 92 | void (*invokeInit)(const Context *rsc, Script *s); |
Stephen Hines | 514f979 | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 93 | void (*invokeFreeChildren)(const Context *rsc, Script *s); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 94 | |
| 95 | void (*setGlobalVar)(const Context *rsc, const Script *s, |
| 96 | uint32_t slot, |
| 97 | void *data, |
| 98 | size_t dataLength); |
| 99 | void (*setGlobalBind)(const Context *rsc, const Script *s, |
| 100 | uint32_t slot, |
| 101 | void *data); |
| 102 | void (*setGlobalObj)(const Context *rsc, const Script *s, |
| 103 | uint32_t slot, |
| 104 | ObjectBase *data); |
| 105 | |
| 106 | void (*destroy)(const Context *rsc, Script *s); |
| 107 | } script; |
| 108 | |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 109 | struct { |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 110 | bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero); |
| 111 | void (*destroy)(const Context *rsc, Allocation *alloc); |
| 112 | |
| 113 | void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType, |
| 114 | bool zeroNew); |
| 115 | void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); |
| 116 | void (*markDirty)(const Context *rsc, const Allocation *alloc); |
| 117 | |
| 118 | void (*data1D)(const Context *rsc, const Allocation *alloc, |
| 119 | uint32_t xoff, uint32_t lod, uint32_t count, |
| 120 | const void *data, uint32_t sizeBytes); |
| 121 | void (*data2D)(const Context *rsc, const Allocation *alloc, |
| 122 | uint32_t xoff, uint32_t yoff, uint32_t lod, |
| 123 | RsAllocationCubemapFace face, uint32_t w, uint32_t h, |
| 124 | const void *data, uint32_t sizeBytes); |
| 125 | void (*data3D)(const Context *rsc, const Allocation *alloc, |
| 126 | uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 127 | uint32_t lod, RsAllocationCubemapFace face, |
| 128 | uint32_t w, uint32_t h, uint32_t d, const void *data, uint32_t sizeBytes); |
| 129 | |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 130 | // Allocation to allocation copies |
| 131 | void (*allocData1D)(const Context *rsc, |
| 132 | const Allocation *dstAlloc, |
| 133 | uint32_t dstXoff, uint32_t dstLod, uint32_t count, |
| 134 | const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); |
| 135 | void (*allocData2D)(const Context *rsc, |
| 136 | const Allocation *dstAlloc, |
| 137 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, |
| 138 | RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, |
| 139 | const Allocation *srcAlloc, |
| 140 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, |
| 141 | RsAllocationCubemapFace srcFace); |
| 142 | void (*allocData3D)(const Context *rsc, |
| 143 | const Allocation *dstAlloc, |
| 144 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
| 145 | uint32_t dstLod, RsAllocationCubemapFace dstFace, |
| 146 | uint32_t w, uint32_t h, uint32_t d, |
| 147 | const Allocation *srcAlloc, |
| 148 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
| 149 | uint32_t srcLod, RsAllocationCubemapFace srcFace); |
| 150 | |
Jason Sams | 7e8aae7 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 151 | void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, |
| 152 | const void *data, uint32_t elementOff, uint32_t sizeBytes); |
| 153 | void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, |
| 154 | const void *data, uint32_t elementOff, uint32_t sizeBytes); |
| 155 | |
| 156 | |
| 157 | } allocation; |
| 158 | |
| 159 | struct { |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 160 | bool (*init)(const Context *rsc, const ProgramStore *ps); |
| 161 | void (*setActive)(const Context *rsc, const ProgramStore *ps); |
| 162 | void (*destroy)(const Context *rsc, const ProgramStore *ps); |
| 163 | } store; |
| 164 | |
Jason Sams | 331bf9b | 2011-04-06 11:23:54 -0700 | [diff] [blame] | 165 | struct { |
| 166 | bool (*init)(const Context *rsc, const ProgramRaster *ps); |
| 167 | void (*setActive)(const Context *rsc, const ProgramRaster *ps); |
| 168 | void (*destroy)(const Context *rsc, const ProgramRaster *ps); |
| 169 | } raster; |
Jason Sams | 48f5056 | 2011-03-18 15:03:25 -0700 | [diff] [blame] | 170 | |
Alex Sakhartchouk | 4a36b45 | 2011-04-29 16:49:08 -0700 | [diff] [blame] | 171 | struct { |
| 172 | bool (*init)(const Context *rsc, const ProgramVertex *pv, |
| 173 | const char* shader, uint32_t shaderLen); |
| 174 | void (*setActive)(const Context *rsc, const ProgramVertex *pv); |
| 175 | void (*destroy)(const Context *rsc, const ProgramVertex *pv); |
| 176 | } vertex; |
| 177 | |
| 178 | struct { |
| 179 | bool (*init)(const Context *rsc, const ProgramFragment *pf, |
| 180 | const char* shader, uint32_t shaderLen); |
| 181 | void (*setActive)(const Context *rsc, const ProgramFragment *pf); |
| 182 | void (*destroy)(const Context *rsc, const ProgramFragment *pf); |
| 183 | } fragment; |
| 184 | |
| 185 | struct { |
| 186 | bool (*init)(const Context *rsc, const Mesh *m); |
| 187 | void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); |
| 188 | void (*destroy)(const Context *rsc, const Mesh *m); |
| 189 | } mesh; |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 190 | |
Alex Sakhartchouk | 4385054 | 2011-05-05 16:56:27 -0700 | [diff] [blame] | 191 | struct { |
| 192 | bool (*init)(const Context *rsc, const Sampler *m); |
| 193 | void (*destroy)(const Context *rsc, const Sampler *m); |
| 194 | } sampler; |
| 195 | |
Alex Sakhartchouk | 2f6964f | 2011-05-13 14:53:34 -0700 | [diff] [blame] | 196 | struct { |
| 197 | bool (*init)(const Context *rsc, const FBOCache *fb); |
| 198 | void (*setActive)(const Context *rsc, const FBOCache *fb); |
| 199 | void (*destroy)(const Context *rsc, const FBOCache *fb); |
| 200 | } framebuffer; |
| 201 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 202 | } RsdHalFunctions; |
| 203 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 204 | |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | |
| 209 | bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor); |
| 210 | |
| 211 | #endif |
| 212 | |