rsCpuScript.h revision 110f181b7966212a36ef18016f9b81c7322d0a2f
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 RSD_BCC_H 18#define RSD_BCC_H 19 20#include <rs_hal.h> 21#include <rsRuntime.h> 22 23#include "rsCpuCore.h" 24 25namespace bcc { 26 class BCCContext; 27 class RSCompilerDriver; 28 class RSExecutable; 29} 30 31namespace android { 32namespace renderscript { 33 34 35 36class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { 37public: 38 typedef void (*outer_foreach_t)( 39 const RsForEachStubParamStruct *, 40 uint32_t x1, uint32_t x2, 41 uint32_t instep, uint32_t outstep); 42#ifdef RS_COMPATIBILITY_LIB 43 typedef void (* InvokeFunc_t)(void); 44 typedef void (* ForEachFunc_t)(void); 45 typedef int (* RootFunc_t)(void); 46 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); 47#endif 48 49 bool init(char const *resName, char const *cacheDir, 50 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags); 51 virtual void populateScript(Script *); 52 53 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength); 54 virtual int invokeRoot(); 55 virtual void invokeForEach(uint32_t slot, 56 const Allocation * ain, 57 Allocation * aout, 58 const void * usr, 59 uint32_t usrLen, 60 const RsScriptCall *sc); 61 virtual void invokeInit(); 62 virtual void invokeFreeChildren(); 63 64 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength); 65 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, 66 const Element *e, const size_t *dims, size_t dimLength); 67 virtual void setGlobalBind(uint32_t slot, Allocation *data); 68 virtual void setGlobalObj(uint32_t slot, ObjectBase *data); 69 70 71 virtual ~RsdCpuScriptImpl(); 72 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); 73 74 const Script * getScript() {return mScript;} 75 76 void forEachMtlsSetup(const Allocation * ain, Allocation * aout, 77 const void * usr, uint32_t usrLen, 78 const RsScriptCall *sc, MTLaunchStruct *mtls); 79 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls); 80 81 82 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); 83 static void * lookupRuntimeStub(void* pContext, char const* name); 84 85 virtual Allocation * getAllocationForPointer(const void *ptr) const; 86 87#ifndef RS_COMPATIBILITY_LIB 88 virtual void * getRSExecutable() { return mExecutable; } 89#endif 90 91protected: 92 RsdCpuReferenceImpl *mCtx; 93 const Script *mScript; 94 95#ifndef RS_COMPATIBILITY_LIB 96 int (*mRoot)(); 97 int (*mRootExpand)(); 98 void (*mInit)(); 99 void (*mFreeChildren)(); 100 101 bcc::BCCContext *mCompilerContext; 102 bcc::RSCompilerDriver *mCompilerDriver; 103 bcc::RSExecutable *mExecutable; 104#else 105 void *mScriptSO; 106 RootFunc_t mRoot; 107 RootFunc_t mRootExpand; 108 InvokeFunc_t mInit; 109 InvokeFunc_t mFreeChildren; 110 InvokeFunc_t *mInvokeFunctions; 111 ForEachFunc_t *mForEachFunctions; 112 113 void **mFieldAddress; 114 bool *mFieldIsObject; 115 uint32_t *mForEachSignatures; 116 117 // for populate script 118 //int mVersionMajor; 119 //int mVersionMinor; 120 size_t mExportedVariableCount; 121 size_t mExportedFunctionCount; 122#endif 123 124 Allocation **mBoundAllocs; 125 void * mIntrinsicData; 126 bool mIsThreadable; 127 128}; 129 130 131Allocation * rsdScriptGetAllocationForPointer( 132 const Context *dc, 133 const Script *script, 134 const void *); 135 136 137 138} 139} 140 141#endif 142