Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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 | |
| 25 | namespace bcc { |
| 26 | class BCCContext; |
| 27 | class RSCompilerDriver; |
| 28 | class RSExecutable; |
| 29 | } |
| 30 | |
| 31 | namespace android { |
| 32 | namespace renderscript { |
| 33 | |
| 34 | |
| 35 | |
| 36 | class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { |
| 37 | public: |
| 38 | typedef void (*outer_foreach_t)( |
| 39 | const RsForEachStubParamStruct *, |
| 40 | uint32_t x1, uint32_t x2, |
| 41 | uint32_t instep, uint32_t outstep); |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 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 |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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(); |
Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 55 | virtual void preLaunch(uint32_t slot, const Allocation * ain, |
| 56 | Allocation * aout, const void * usr, |
| 57 | uint32_t usrLen, const RsScriptCall *sc); |
| 58 | virtual void postLaunch(uint32_t slot, const Allocation * ain, |
| 59 | Allocation * aout, const void * usr, |
| 60 | uint32_t usrLen, const RsScriptCall *sc); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 61 | virtual void invokeForEach(uint32_t slot, |
| 62 | const Allocation * ain, |
| 63 | Allocation * aout, |
| 64 | const void * usr, |
| 65 | uint32_t usrLen, |
| 66 | const RsScriptCall *sc); |
| 67 | virtual void invokeInit(); |
| 68 | virtual void invokeFreeChildren(); |
| 69 | |
| 70 | virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength); |
Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 71 | virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 72 | virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
| 73 | const Element *e, const size_t *dims, size_t dimLength); |
| 74 | virtual void setGlobalBind(uint32_t slot, Allocation *data); |
| 75 | virtual void setGlobalObj(uint32_t slot, ObjectBase *data); |
| 76 | |
| 77 | |
| 78 | virtual ~RsdCpuScriptImpl(); |
| 79 | RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); |
| 80 | |
| 81 | const Script * getScript() {return mScript;} |
| 82 | |
| 83 | void forEachMtlsSetup(const Allocation * ain, Allocation * aout, |
| 84 | const void * usr, uint32_t usrLen, |
| 85 | const RsScriptCall *sc, MTLaunchStruct *mtls); |
| 86 | virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls); |
| 87 | |
| 88 | |
| 89 | const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); |
| 90 | static void * lookupRuntimeStub(void* pContext, char const* name); |
| 91 | |
| 92 | virtual Allocation * getAllocationForPointer(const void *ptr) const; |
| 93 | |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 94 | #ifndef RS_COMPATIBILITY_LIB |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 95 | virtual void * getRSExecutable() { return mExecutable; } |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 96 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 97 | |
| 98 | protected: |
| 99 | RsdCpuReferenceImpl *mCtx; |
| 100 | const Script *mScript; |
| 101 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 102 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 103 | int (*mRoot)(); |
| 104 | int (*mRootExpand)(); |
| 105 | void (*mInit)(); |
| 106 | void (*mFreeChildren)(); |
| 107 | |
| 108 | bcc::BCCContext *mCompilerContext; |
| 109 | bcc::RSCompilerDriver *mCompilerDriver; |
| 110 | bcc::RSExecutable *mExecutable; |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 111 | #else |
| 112 | void *mScriptSO; |
| 113 | RootFunc_t mRoot; |
| 114 | RootFunc_t mRootExpand; |
| 115 | InvokeFunc_t mInit; |
| 116 | InvokeFunc_t mFreeChildren; |
| 117 | InvokeFunc_t *mInvokeFunctions; |
| 118 | ForEachFunc_t *mForEachFunctions; |
| 119 | |
| 120 | void **mFieldAddress; |
| 121 | bool *mFieldIsObject; |
| 122 | uint32_t *mForEachSignatures; |
| 123 | |
| 124 | // for populate script |
| 125 | //int mVersionMajor; |
| 126 | //int mVersionMinor; |
| 127 | size_t mExportedVariableCount; |
| 128 | size_t mExportedFunctionCount; |
| 129 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 130 | |
| 131 | Allocation **mBoundAllocs; |
| 132 | void * mIntrinsicData; |
| 133 | bool mIsThreadable; |
| 134 | |
| 135 | }; |
| 136 | |
| 137 | |
| 138 | Allocation * rsdScriptGetAllocationForPointer( |
| 139 | const Context *dc, |
| 140 | const Script *script, |
| 141 | const void *); |
| 142 | |
| 143 | |
| 144 | |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | #endif |