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 | |
Stephen Hines | 25e3af5 | 2014-05-21 21:23:08 -0700 | [diff] [blame] | 23 | #ifndef RS_COMPATIBILITY_LIB |
| 24 | #include <bcc/ExecutionEngine/CompilerRTSymbolResolver.h> |
| 25 | #include <bcc/ExecutionEngine/SymbolResolverProxy.h> |
Tim Murray | 29809d1 | 2014-05-28 12:04:19 -0700 | [diff] [blame] | 26 | #include <vector> |
| 27 | #include <utility> |
Stephen Hines | 25e3af5 | 2014-05-21 21:23:08 -0700 | [diff] [blame] | 28 | #endif |
| 29 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 30 | #include "rsCpuCore.h" |
| 31 | |
| 32 | namespace bcc { |
| 33 | class BCCContext; |
| 34 | class RSCompilerDriver; |
| 35 | class RSExecutable; |
| 36 | } |
| 37 | |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 38 | namespace bcinfo { |
| 39 | class MetadataExtractor; |
| 40 | } |
| 41 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 42 | namespace android { |
| 43 | namespace renderscript { |
| 44 | |
| 45 | |
| 46 | |
| 47 | class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript { |
| 48 | public: |
| 49 | typedef void (*outer_foreach_t)( |
| 50 | const RsForEachStubParamStruct *, |
| 51 | uint32_t x1, uint32_t x2, |
| 52 | uint32_t instep, uint32_t outstep); |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 53 | #ifdef RS_COMPATIBILITY_LIB |
| 54 | typedef void (* InvokeFunc_t)(void); |
| 55 | typedef void (* ForEachFunc_t)(void); |
| 56 | typedef int (* RootFunc_t)(void); |
| 57 | typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); |
| 58 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 59 | |
| 60 | bool init(char const *resName, char const *cacheDir, |
Stephen Hines | 0051132 | 2014-01-31 11:20:23 -0800 | [diff] [blame] | 61 | uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags, |
| 62 | char const *bccPluginName = NULL); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 63 | virtual void populateScript(Script *); |
| 64 | |
| 65 | virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength); |
| 66 | virtual int invokeRoot(); |
Jason Sams | 17e3cdc | 2013-09-09 17:32:16 -0700 | [diff] [blame] | 67 | virtual void preLaunch(uint32_t slot, const Allocation * ain, |
| 68 | Allocation * aout, const void * usr, |
| 69 | uint32_t usrLen, const RsScriptCall *sc); |
| 70 | virtual void postLaunch(uint32_t slot, const Allocation * ain, |
| 71 | Allocation * aout, const void * usr, |
| 72 | uint32_t usrLen, const RsScriptCall *sc); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 73 | virtual void invokeForEach(uint32_t slot, |
| 74 | const Allocation * ain, |
| 75 | Allocation * aout, |
| 76 | const void * usr, |
| 77 | uint32_t usrLen, |
| 78 | const RsScriptCall *sc); |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame^] | 79 | |
| 80 | virtual void invokeForEachMulti(uint32_t slot, |
| 81 | const Allocation** ains, |
| 82 | uint32_t inLen, |
| 83 | Allocation* aout, |
| 84 | const void* usr, |
| 85 | uint32_t usrLen, |
| 86 | const RsScriptCall* sc); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 87 | virtual void invokeInit(); |
| 88 | virtual void invokeFreeChildren(); |
| 89 | |
| 90 | virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength); |
Tim Murray | 9c64239 | 2013-04-11 13:29:59 -0700 | [diff] [blame] | 91 | virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 92 | virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength, |
Stephen Hines | ac8d146 | 2014-06-25 00:01:23 -0700 | [diff] [blame] | 93 | const Element *e, const uint32_t *dims, size_t dimLength); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 94 | virtual void setGlobalBind(uint32_t slot, Allocation *data); |
| 95 | virtual void setGlobalObj(uint32_t slot, ObjectBase *data); |
| 96 | |
| 97 | |
| 98 | virtual ~RsdCpuScriptImpl(); |
| 99 | RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s); |
| 100 | |
| 101 | const Script * getScript() {return mScript;} |
| 102 | |
| 103 | void forEachMtlsSetup(const Allocation * ain, Allocation * aout, |
| 104 | const void * usr, uint32_t usrLen, |
| 105 | const RsScriptCall *sc, MTLaunchStruct *mtls); |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame^] | 106 | |
| 107 | void forEachMtlsSetup(const Allocation ** ains, uint32_t inLen, |
| 108 | Allocation * aout, const void * usr, uint32_t usrLen, |
| 109 | const RsScriptCall *sc, MTLaunchStruct *mtls); |
| 110 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 111 | virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls); |
| 112 | |
| 113 | |
| 114 | const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym); |
| 115 | static void * lookupRuntimeStub(void* pContext, char const* name); |
| 116 | |
| 117 | virtual Allocation * getAllocationForPointer(const void *ptr) const; |
| 118 | |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 119 | #ifndef RS_COMPATIBILITY_LIB |
Stephen Hines | f218bf1 | 2013-02-12 19:32:38 -0800 | [diff] [blame] | 120 | virtual void * getRSExecutable() { return mExecutable; } |
Jason Sams | cadfac4 | 2013-03-06 18:09:08 -0800 | [diff] [blame] | 121 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 122 | |
| 123 | protected: |
| 124 | RsdCpuReferenceImpl *mCtx; |
| 125 | const Script *mScript; |
| 126 | |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 127 | #ifndef RS_COMPATIBILITY_LIB |
Jean-Luc Brouillet | 40e35cd | 2014-06-25 18:21:45 -0700 | [diff] [blame] | 128 | // Returns the path to the core library we'll use. |
| 129 | const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode, |
Jean-Luc Brouillet | 9ab5094 | 2014-06-18 18:10:32 -0700 | [diff] [blame] | 130 | size_t bitcodeSize); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 131 | int (*mRoot)(); |
| 132 | int (*mRootExpand)(); |
| 133 | void (*mInit)(); |
| 134 | void (*mFreeChildren)(); |
| 135 | |
Tim Murray | 29809d1 | 2014-05-28 12:04:19 -0700 | [diff] [blame] | 136 | std::vector<std::pair<const char *, uint32_t> > mExportedForEachFuncList; |
| 137 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 138 | bcc::BCCContext *mCompilerContext; |
| 139 | bcc::RSCompilerDriver *mCompilerDriver; |
Stephen Hines | 25e3af5 | 2014-05-21 21:23:08 -0700 | [diff] [blame] | 140 | bcc::CompilerRTSymbolResolver mCompilerRuntime; |
| 141 | bcc::LookupFunctionSymbolResolver<void *> mRSRuntime; |
| 142 | bcc::SymbolResolverProxy mResolver; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 143 | bcc::RSExecutable *mExecutable; |
Jason Sams | 110f181 | 2013-03-14 16:02:18 -0700 | [diff] [blame] | 144 | #else |
| 145 | void *mScriptSO; |
| 146 | RootFunc_t mRoot; |
| 147 | RootFunc_t mRootExpand; |
| 148 | InvokeFunc_t mInit; |
| 149 | InvokeFunc_t mFreeChildren; |
| 150 | InvokeFunc_t *mInvokeFunctions; |
| 151 | ForEachFunc_t *mForEachFunctions; |
| 152 | |
| 153 | void **mFieldAddress; |
| 154 | bool *mFieldIsObject; |
| 155 | uint32_t *mForEachSignatures; |
| 156 | |
| 157 | // for populate script |
| 158 | //int mVersionMajor; |
| 159 | //int mVersionMinor; |
| 160 | size_t mExportedVariableCount; |
| 161 | size_t mExportedFunctionCount; |
| 162 | #endif |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 163 | |
| 164 | Allocation **mBoundAllocs; |
| 165 | void * mIntrinsicData; |
| 166 | bool mIsThreadable; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 167 | }; |
| 168 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 169 | Allocation * rsdScriptGetAllocationForPointer( |
| 170 | const Context *dc, |
| 171 | const Script *script, |
| 172 | const void *); |
| 173 | |
| 174 | |
| 175 | |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | #endif |