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