rs_hal.h revision a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12
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 ScriptKernelID; 34class ScriptFieldID; 35class ScriptMethodID; 36class ScriptC; 37class ScriptGroup; 38class Path; 39class Program; 40class ProgramStore; 41class ProgramRaster; 42class ProgramVertex; 43class ProgramFragment; 44class Mesh; 45class Sampler; 46class FBOCache; 47 48/** 49 * Define the internal object types. This ia a mirror of the 50 * definition in rs_types.rsh except with the p value typed 51 * correctly. 52 * 53 * p = pointer to internal object implementation 54 * r = reserved by libRS runtime 55 * v1 = Mirror of p->mHal.drv 56 * v2 = reserved for use by vendor drivers 57 */ 58 59#ifndef __LP64__ 60#define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; } __attribute__((packed, aligned(4))) 61#else 62#define RS_BASE_OBJ(_t_) typedef struct { const _t_* p; const void* r; const void* v1; const void* v2; } 63#endif 64 65RS_BASE_OBJ(Element) rs_element; 66RS_BASE_OBJ(Type) rs_type; 67RS_BASE_OBJ(Allocation) rs_allocation; 68RS_BASE_OBJ(Sampler) rs_sampler; 69RS_BASE_OBJ(Script) rs_script; 70RS_BASE_OBJ(ScriptGroup) rs_script_group; 71 72#ifndef __LP64__ 73typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_mesh; 74typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_path; 75typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_fragment; 76typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_vertex; 77typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_raster; 78typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_program_store; 79typedef struct { const int* p; } __attribute__((packed, aligned(4))) rs_font; 80#endif // __LP64__ 81 82 83typedef void *(*RsHalSymbolLookupFunc)(void *usrptr, char const *symbolName); 84 85/** 86 * Script management functions 87 */ 88typedef struct { 89 bool (*initGraphics)(const Context *); 90 void (*shutdownGraphics)(const Context *); 91 bool (*setSurface)(const Context *, uint32_t w, uint32_t h, RsNativeWindow); 92 void (*swap)(const Context *); 93 94 void (*shutdownDriver)(Context *); 95 void (*getVersion)(unsigned int *major, unsigned int *minor); 96 void (*setPriority)(const Context *, int32_t priority); 97 98 void* (*allocRuntimeMem)(size_t size, uint32_t flags); 99 void (*freeRuntimeMem)(void* ptr); 100 101 struct { 102 bool (*init)(const Context *rsc, ScriptC *s, 103 char const *resName, 104 char const *cacheDir, 105 uint8_t const *bitcode, 106 size_t bitcodeSize, 107 uint32_t flags); 108 bool (*initIntrinsic)(const Context *rsc, Script *s, 109 RsScriptIntrinsicID iid, 110 Element *e); 111 112 void (*invokeFunction)(const Context *rsc, Script *s, 113 uint32_t slot, 114 const void *params, 115 size_t paramLength); 116 int (*invokeRoot)(const Context *rsc, Script *s); 117 void (*invokeForEach)(const Context *rsc, 118 Script *s, 119 uint32_t slot, 120 const Allocation * ain, 121 Allocation * aout, 122 const void * usr, 123 size_t usrLen, 124 const RsScriptCall *sc); 125 void (*invokeInit)(const Context *rsc, Script *s); 126 void (*invokeFreeChildren)(const Context *rsc, Script *s); 127 128 void (*setGlobalVar)(const Context *rsc, const Script *s, 129 uint32_t slot, 130 void *data, 131 size_t dataLength); 132 void (*getGlobalVar)(const Context *rsc, const Script *s, 133 uint32_t slot, 134 void *data, 135 size_t dataLength); 136 void (*setGlobalVarWithElemDims)(const Context *rsc, const Script *s, 137 uint32_t slot, 138 void *data, 139 size_t dataLength, 140 const Element *e, 141 const uint32_t *dims, 142 size_t dimLength); 143 void (*setGlobalBind)(const Context *rsc, const Script *s, 144 uint32_t slot, 145 Allocation *data); 146 void (*setGlobalObj)(const Context *rsc, const Script *s, 147 uint32_t slot, 148 ObjectBase *data); 149 150 void (*destroy)(const Context *rsc, Script *s); 151 void (*invokeForEachMulti)(const Context *rsc, 152 Script *s, 153 uint32_t slot, 154 const Allocation ** ains, 155 size_t inLen, 156 Allocation * aout, 157 const void * usr, 158 size_t usrLen, 159 const RsScriptCall *sc); 160 void (*updateCachedObject)(const Context *rsc, const Script *, rs_script *obj); 161 } script; 162 163 struct { 164 bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero); 165 void (*destroy)(const Context *rsc, Allocation *alloc); 166 uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc); 167 168 void (*resize)(const Context *rsc, const Allocation *alloc, const Type *newType, 169 bool zeroNew); 170 void (*syncAll)(const Context *rsc, const Allocation *alloc, RsAllocationUsageType src); 171 void (*markDirty)(const Context *rsc, const Allocation *alloc); 172 173 void (*setSurface)(const Context *rsc, Allocation *alloc, ANativeWindow *sur); 174 void (*ioSend)(const Context *rsc, Allocation *alloc); 175 176 /** 177 * A new gralloc buffer is in use. The pointers and strides in 178 * mHal.drvState.lod[0-2] will be updated with the new values. 179 * 180 * The new gralloc handle is provided in mHal.state.nativeBuffer 181 * 182 */ 183 void (*ioReceive)(const Context *rsc, Allocation *alloc); 184 185 void (*data1D)(const Context *rsc, const Allocation *alloc, 186 uint32_t xoff, uint32_t lod, size_t count, 187 const void *data, size_t sizeBytes); 188 void (*data2D)(const Context *rsc, const Allocation *alloc, 189 uint32_t xoff, uint32_t yoff, uint32_t lod, 190 RsAllocationCubemapFace face, uint32_t w, uint32_t h, 191 const void *data, size_t sizeBytes, size_t stride); 192 void (*data3D)(const Context *rsc, const Allocation *alloc, 193 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, 194 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, 195 size_t stride); 196 197 void (*read1D)(const Context *rsc, const Allocation *alloc, 198 uint32_t xoff, uint32_t lod, size_t count, 199 void *data, size_t sizeBytes); 200 void (*read2D)(const Context *rsc, const Allocation *alloc, 201 uint32_t xoff, uint32_t yoff, uint32_t lod, 202 RsAllocationCubemapFace face, uint32_t w, uint32_t h, 203 void *data, size_t sizeBytes, size_t stride); 204 void (*read3D)(const Context *rsc, const Allocation *alloc, 205 uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, 206 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, 207 size_t stride); 208 209 // Lock and unlock make a 1D region of memory available to the CPU 210 // for direct access by pointer. Once unlock is called control is 211 // returned to the SOC driver. 212 void * (*lock1D)(const Context *rsc, const Allocation *alloc); 213 void (*unlock1D)(const Context *rsc, const Allocation *alloc); 214 215 // Allocation to allocation copies 216 void (*allocData1D)(const Context *rsc, 217 const Allocation *dstAlloc, 218 uint32_t dstXoff, uint32_t dstLod, size_t count, 219 const Allocation *srcAlloc, uint32_t srcXoff, uint32_t srcLod); 220 void (*allocData2D)(const Context *rsc, 221 const Allocation *dstAlloc, 222 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstLod, 223 RsAllocationCubemapFace dstFace, uint32_t w, uint32_t h, 224 const Allocation *srcAlloc, 225 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcLod, 226 RsAllocationCubemapFace srcFace); 227 void (*allocData3D)(const Context *rsc, 228 const Allocation *dstAlloc, 229 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, 230 uint32_t dstLod, 231 uint32_t w, uint32_t h, uint32_t d, 232 const Allocation *srcAlloc, 233 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, 234 uint32_t srcLod); 235 236 void (*elementData1D)(const Context *rsc, const Allocation *alloc, uint32_t x, 237 const void *data, uint32_t elementOff, size_t sizeBytes); 238 void (*elementData2D)(const Context *rsc, const Allocation *alloc, uint32_t x, uint32_t y, 239 const void *data, uint32_t elementOff, size_t sizeBytes); 240 241 void (*generateMipmaps)(const Context *rsc, const Allocation *alloc); 242 243 void (*updateCachedObject)(const Context *rsc, const Allocation *alloc, rs_allocation *obj); 244 } allocation; 245 246 struct { 247 bool (*init)(const Context *rsc, const ProgramStore *ps); 248 void (*setActive)(const Context *rsc, const ProgramStore *ps); 249 void (*destroy)(const Context *rsc, const ProgramStore *ps); 250 } store; 251 252 struct { 253 bool (*init)(const Context *rsc, const ProgramRaster *ps); 254 void (*setActive)(const Context *rsc, const ProgramRaster *ps); 255 void (*destroy)(const Context *rsc, const ProgramRaster *ps); 256 } raster; 257 258 struct { 259 bool (*init)(const Context *rsc, const ProgramVertex *pv, 260 const char* shader, size_t shaderLen, 261 const char** textureNames, size_t textureNamesCount, 262 const size_t *textureNamesLength); 263 void (*setActive)(const Context *rsc, const ProgramVertex *pv); 264 void (*destroy)(const Context *rsc, const ProgramVertex *pv); 265 } vertex; 266 267 struct { 268 bool (*init)(const Context *rsc, const ProgramFragment *pf, 269 const char* shader, size_t shaderLen, 270 const char** textureNames, size_t textureNamesCount, 271 const size_t *textureNamesLength); 272 void (*setActive)(const Context *rsc, const ProgramFragment *pf); 273 void (*destroy)(const Context *rsc, const ProgramFragment *pf); 274 } fragment; 275 276 struct { 277 bool (*init)(const Context *rsc, const Mesh *m); 278 void (*draw)(const Context *rsc, const Mesh *m, uint32_t primIndex, uint32_t start, uint32_t len); 279 void (*destroy)(const Context *rsc, const Mesh *m); 280 } mesh; 281 282 struct { 283 bool (*initStatic)(const Context *rsc, const Path *m, const Allocation *vtx, const Allocation *loops); 284 bool (*initDynamic)(const Context *rsc, const Path *m); 285 void (*draw)(const Context *rsc, const Path *m); 286 void (*destroy)(const Context *rsc, const Path *m); 287 } path; 288 289 struct { 290 bool (*init)(const Context *rsc, const Sampler *m); 291 void (*destroy)(const Context *rsc, const Sampler *m); 292 void (*updateCachedObject)(const Context *rsc, const Sampler *s, rs_sampler *obj); 293 } sampler; 294 295 struct { 296 bool (*init)(const Context *rsc, const FBOCache *fb); 297 void (*setActive)(const Context *rsc, const FBOCache *fb); 298 void (*destroy)(const Context *rsc, const FBOCache *fb); 299 } framebuffer; 300 301 struct { 302 bool (*init)(const Context *rsc, ScriptGroup *sg); 303 void (*setInput)(const Context *rsc, const ScriptGroup *sg, 304 const ScriptKernelID *kid, Allocation *); 305 void (*setOutput)(const Context *rsc, const ScriptGroup *sg, 306 const ScriptKernelID *kid, Allocation *); 307 void (*execute)(const Context *rsc, const ScriptGroup *sg); 308 void (*destroy)(const Context *rsc, const ScriptGroup *sg); 309 void (*updateCachedObject)(const Context *rsc, const ScriptGroup *sg, rs_script_group *obj); 310 } scriptgroup; 311 312 struct { 313 bool (*init)(const Context *rsc, const Type *m); 314 void (*destroy)(const Context *rsc, const Type *m); 315 void (*updateCachedObject)(const Context *rsc, const Type *s, rs_type *obj); 316 } type; 317 318 struct { 319 bool (*init)(const Context *rsc, const Element *m); 320 void (*destroy)(const Context *rsc, const Element *m); 321 void (*updateCachedObject)(const Context *rsc, const Element *s, rs_element *obj); 322 } element; 323 324 void (*finish)(const Context *rsc); 325} RsdHalFunctions; 326 327 328} 329} 330 331#ifdef __cplusplus 332extern "C" { 333#endif 334 335bool rsdHalInit(RsContext, uint32_t version_major, uint32_t version_minor); 336 337#ifdef __cplusplus 338} 339#endif 340 341#endif 342