rs_hal.h revision 41d6c769f5fa21da3cbc116af95d88949a4a5c76
1/* 2 * Copyright (C) 2011-2012 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 <rsDefines.h> 21 22struct ANativeWindow; 23 24namespace android { 25namespace renderscript { 26 27class Context; 28class ObjectBase; 29class Element; 30class Type; 31class Allocation; 32class Script; 33class ScriptC; 34class Path; 35class Program; 36class ProgramStore; 37class ProgramRaster; 38class ProgramVertex; 39class ProgramFragment; 40class Mesh; 41class Sampler; 42class FBOCache; 43 44typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); 45 46typedef struct { 47 const void *in; 48 void *out; 49 const void *usr; 50 size_t usrLen; 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 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; 69} RsForEachStubParamStruct; 70 71/** 72 * Script management functions 73 */ 74typedef struct { 75 bool (*initGraphics)(const Context *); 76 void (*shutdownGraphics)(const Context *); 77 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); 78 void (*swap)(const Context *); 79 80 void (*shutdownDriver)(Context *); 81 void (*getVersion)(unsigned int *major, unsigned int *minor); 82 void (*setPriority)(const Context *, int32_t priority); 83 84 85 86 struct { 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, 92 uint32_t flags); 93 bool (*initIntrinsic)(const Context *rsc, Script *s, 94 RsScriptIntrinsicID iid, 95 Element *e); 96 97 void (*invokeFunction)(const Context *rsc, Script *s, 98 uint32_t slot, 99 const void *params, 100 size_t paramLength); 101 int (*invokeRoot)(const Context *rsc, Script *s); 102 void (*invokeForEach)(const Context *rsc, 103 Script *s, 104 uint32_t slot, 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); 111 void (*invokeFreeChildren)(const Context *rsc, Script *s); 112 113 void (*setGlobalVar)(const Context *rsc, const Script *s, 114 uint32_t slot, 115 void *data, 116 size_t dataLength); 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); 124 void (*setGlobalBind)(const Context *rsc, const Script *s, 125 uint32_t slot, 126 Allocation *data); 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 134 struct { 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); 142 143 int32_t (*initSurfaceTexture)(const Context *rsc, const Allocation *alloc); 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); 147 148 void (*data1D)(const Context *rsc, const Allocation *alloc, 149 uint32_t xoff, uint32_t lod, uint32_t count, 150 const void *data, size_t sizeBytes); 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, 154 const void *data, size_t sizeBytes); 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, 158 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes); 159 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 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 199 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, 200 const void *data, uint32_t elementOff, size_t sizeBytes); 201 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, 202 const void *data, uint32_t elementOff, size_t sizeBytes); 203 204 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc); 205 } allocation; 206 207 struct { 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 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; 218 219 struct { 220 bool (*init)(const Context *rsc, const ProgramVertex *pv, 221 const char* shader, size_t shaderLen, 222 const char** textureNames, size_t textureNamesCount, 223 const size_t *textureNamesLength); 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, 230 const char* shader, size_t shaderLen, 231 const char** textureNames, size_t textureNamesCount, 232 const size_t *textureNamesLength); 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; 242 243 struct { 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 { 251 bool (*init)(const Context *rsc, const Sampler *m); 252 void (*destroy)(const Context *rsc, const Sampler *m); 253 } sampler; 254 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 261} RsdHalFunctions; 262 263 264} 265} 266 267 268bool rsdHalInit(android::renderscript::Context *, uint32_t version_major, uint32_t version_minor); 269 270#endif 271 272