Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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_CPU_CORE_H |
| 18 | #define RSD_CPU_CORE_H |
| 19 | |
| 20 | #include "rsd_cpu.h" |
| 21 | #include "rsSignal.h" |
| 22 | #include "rsContext.h" |
| 23 | #include "rsElement.h" |
| 24 | #include "rsScriptC.h" |
| 25 | |
| 26 | namespace bcc { |
| 27 | class BCCContext; |
| 28 | class RSCompilerDriver; |
| 29 | class RSExecutable; |
| 30 | } |
| 31 | |
| 32 | namespace android { |
| 33 | namespace renderscript { |
| 34 | |
| 35 | |
| 36 | typedef void (* InvokeFunc_t)(void); |
| 37 | typedef void (* ForEachFunc_t)(void); |
| 38 | typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); |
| 39 | |
| 40 | class RsdCpuScriptImpl; |
| 41 | class RsdCpuReferenceImpl; |
| 42 | |
| 43 | typedef struct ScriptTLSStructRec { |
| 44 | android::renderscript::Context * mContext; |
| 45 | const android::renderscript::Script * mScript; |
| 46 | RsdCpuScriptImpl *mImpl; |
| 47 | } ScriptTLSStruct; |
| 48 | |
| 49 | typedef struct { |
| 50 | RsForEachStubParamStruct fep; |
| 51 | |
| 52 | RsdCpuReferenceImpl *rsc; |
| 53 | RsdCpuScriptImpl *script; |
| 54 | |
| 55 | ForEachFunc_t kernel; |
| 56 | uint32_t sig; |
| 57 | const Allocation * ain; |
| 58 | Allocation * aout; |
| 59 | |
| 60 | uint32_t mSliceSize; |
| 61 | volatile int mSliceNum; |
| 62 | bool isThreadable; |
| 63 | |
| 64 | uint32_t xStart; |
| 65 | uint32_t xEnd; |
| 66 | uint32_t yStart; |
| 67 | uint32_t yEnd; |
| 68 | uint32_t zStart; |
| 69 | uint32_t zEnd; |
| 70 | uint32_t arrayStart; |
| 71 | uint32_t arrayEnd; |
| 72 | } MTLaunchStruct; |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | class RsdCpuReferenceImpl : public RsdCpuReference { |
| 78 | public: |
| 79 | virtual ~RsdCpuReferenceImpl(); |
| 80 | RsdCpuReferenceImpl(Context *); |
| 81 | |
| 82 | void lockMutex(); |
| 83 | void unlockMutex(); |
| 84 | |
| 85 | bool init(uint32_t version_major, uint32_t version_minor, sym_lookup_t, script_lookup_t); |
| 86 | virtual void setPriority(int32_t priority); |
| 87 | virtual void launchThreads(WorkerCallback_t cbk, void *data); |
| 88 | static void * helperThreadProc(void *vrsc); |
| 89 | RsdCpuScriptImpl * setTLS(RsdCpuScriptImpl *sc); |
| 90 | |
| 91 | Context * getContext() {return mRSC;} |
Jason Sams | c44d670 | 2012-11-28 18:37:52 -0800 | [diff] [blame^] | 92 | uint32_t getThreadCount() const { |
| 93 | return mWorkers.mCount + 1; |
| 94 | } |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 95 | |
| 96 | void launchThreads(const Allocation * ain, Allocation * aout, |
| 97 | const RsScriptCall *sc, MTLaunchStruct *mtls); |
| 98 | |
| 99 | virtual CpuScript * createScript(const ScriptC *s, |
| 100 | char const *resName, char const *cacheDir, |
| 101 | uint8_t const *bitcode, size_t bitcodeSize, |
| 102 | uint32_t flags); |
| 103 | virtual CpuScript * createIntrinsic(const Script *s, |
| 104 | RsScriptIntrinsicID iid, Element *e); |
| 105 | virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg); |
| 106 | |
| 107 | const RsdCpuReference::CpuSymbol *symLookup(const char *); |
| 108 | |
| 109 | RsdCpuReference::CpuScript * lookupScript(const Script *s) { |
| 110 | return mScriptLookupFn(mRSC, s); |
| 111 | } |
| 112 | |
| 113 | |
| 114 | protected: |
| 115 | Context *mRSC; |
| 116 | uint32_t version_major; |
| 117 | uint32_t version_minor; |
| 118 | //bool mHasGraphics; |
| 119 | bool mInForEach; |
| 120 | |
| 121 | struct Workers { |
| 122 | volatile int mRunningCount; |
| 123 | volatile int mLaunchCount; |
| 124 | uint32_t mCount; |
| 125 | pthread_t *mThreadId; |
| 126 | pid_t *mNativeThreadId; |
| 127 | Signal mCompleteSignal; |
| 128 | Signal *mLaunchSignals; |
| 129 | WorkerCallback_t mLaunchCallback; |
| 130 | void *mLaunchData; |
| 131 | }; |
| 132 | Workers mWorkers; |
| 133 | bool mExit; |
| 134 | sym_lookup_t mSymLookupFn; |
| 135 | script_lookup_t mScriptLookupFn; |
| 136 | |
| 137 | ScriptTLSStruct mTlsStruct; |
| 138 | }; |
| 139 | |
| 140 | |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | #endif |