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