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