rsCpuCore.h revision cb51798a0379409c0f9927c44bbcdd772ed7ec18
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#include <string> 27 28namespace bcc { 29 class BCCContext; 30 class RSCompilerDriver; 31 class RSExecutable; 32} 33 34namespace android { 35namespace renderscript { 36 37typedef struct { 38 const void *in; 39 void *out; 40 const void *usr; 41 uint32_t usrLen; 42 uint32_t x; 43 uint32_t y; 44 uint32_t z; 45 uint32_t lod; 46 RsAllocationCubemapFace face; 47 uint32_t ar[16]; 48 uint32_t lid; 49 50 uint32_t dimX; 51 uint32_t dimY; 52 uint32_t dimZ; 53 uint32_t dimArray; 54 55 const uint8_t *ptrIn; 56 uint8_t *ptrOut; 57 uint32_t eStrideIn; 58 uint32_t eStrideOut; 59 uint32_t yStrideIn; 60 uint32_t yStrideOut; 61 uint32_t slot; 62} RsForEachStubParamStruct; 63 64extern bool gArchUseSIMD; 65 66typedef void (* InvokeFunc_t)(void); 67typedef void (* ForEachFunc_t)(void); 68typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); 69 70class RsdCpuScriptImpl; 71class RsdCpuReferenceImpl; 72 73typedef struct ScriptTLSStructRec { 74 android::renderscript::Context * mContext; 75 const android::renderscript::Script * mScript; 76 RsdCpuScriptImpl *mImpl; 77} ScriptTLSStruct; 78 79typedef struct { 80 RsForEachStubParamStruct fep; 81 82 RsdCpuReferenceImpl *rsc; 83 RsdCpuScriptImpl *script; 84 85 ForEachFunc_t kernel; 86 uint32_t sig; 87 const Allocation * ain; 88 Allocation * aout; 89 90 uint32_t mSliceSize; 91 volatile int mSliceNum; 92 bool isThreadable; 93 94 uint32_t xStart; 95 uint32_t xEnd; 96 uint32_t yStart; 97 uint32_t yEnd; 98 uint32_t zStart; 99 uint32_t zEnd; 100 uint32_t arrayStart; 101 uint32_t arrayEnd; 102} MTLaunchStruct; 103 104 105 106 107class RsdCpuReferenceImpl : public RsdCpuReference { 108public: 109 virtual ~RsdCpuReferenceImpl(); 110 RsdCpuReferenceImpl(Context *); 111 112 void lockMutex(); 113 void unlockMutex(); 114 115 bool init(uint32_t version_major, uint32_t version_minor, sym_lookup_t, script_lookup_t); 116 virtual void setPriority(int32_t priority); 117 virtual void launchThreads(WorkerCallback_t cbk, void *data); 118 static void * helperThreadProc(void *vrsc); 119 RsdCpuScriptImpl * setTLS(RsdCpuScriptImpl *sc); 120 121 Context * getContext() {return mRSC;} 122 uint32_t getThreadCount() const { 123 return mWorkers.mCount + 1; 124 } 125 126 void launchThreads(const Allocation * ain, Allocation * aout, 127 const RsScriptCall *sc, MTLaunchStruct *mtls); 128 129 virtual CpuScript * createScript(const ScriptC *s, 130 char const *resName, char const *cacheDir, 131 uint8_t const *bitcode, size_t bitcodeSize, 132 uint32_t flags); 133 virtual CpuScript * createIntrinsic(const Script *s, 134 RsScriptIntrinsicID iid, Element *e); 135 virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg); 136 137 const RsdCpuReference::CpuSymbol *symLookup(const char *); 138 139 RsdCpuReference::CpuScript * lookupScript(const Script *s) { 140 return mScriptLookupFn(mRSC, s); 141 } 142 143#ifndef RS_COMPATIBILITY_LIB 144 void setLinkRuntimeCallback( 145 bcc::RSLinkRuntimeCallback pLinkRuntimeCallback) { 146 mLinkRuntimeCallback = pLinkRuntimeCallback; 147 } 148 bcc::RSLinkRuntimeCallback getLinkRuntimeCallback() { 149 return mLinkRuntimeCallback; 150 } 151 152 void setSelectRTCallback(RSSelectRTCallback pSelectRTCallback) { 153 mSelectRTCallback = pSelectRTCallback; 154 } 155 RSSelectRTCallback getSelectRTCallback() { 156 return mSelectRTCallback; 157 } 158 159 virtual void setSetupCompilerCallback( 160 RSSetupCompilerCallback pSetupCompilerCallback) { 161 mSetupCompilerCallback = pSetupCompilerCallback; 162 } 163 virtual RSSetupCompilerCallback getSetupCompilerCallback() const { 164 return mSetupCompilerCallback; 165 } 166 167 virtual void setBccPluginName(const char *name) { 168 mBccPluginName.assign(name); 169 } 170 virtual const char *getBccPluginName() const { 171 return mBccPluginName.c_str(); 172 } 173#endif 174 virtual bool getInForEach() { return mInForEach; } 175 176protected: 177 Context *mRSC; 178 uint32_t version_major; 179 uint32_t version_minor; 180 //bool mHasGraphics; 181 bool mInForEach; 182 183 struct Workers { 184 volatile int mRunningCount; 185 volatile int mLaunchCount; 186 uint32_t mCount; 187 pthread_t *mThreadId; 188 pid_t *mNativeThreadId; 189 Signal mCompleteSignal; 190 Signal *mLaunchSignals; 191 WorkerCallback_t mLaunchCallback; 192 void *mLaunchData; 193 }; 194 Workers mWorkers; 195 bool mExit; 196 sym_lookup_t mSymLookupFn; 197 script_lookup_t mScriptLookupFn; 198 199 ScriptTLSStruct mTlsStruct; 200 201#ifndef RS_COMPATIBILITY_LIB 202 bcc::RSLinkRuntimeCallback mLinkRuntimeCallback; 203 RSSelectRTCallback mSelectRTCallback; 204 RSSetupCompilerCallback mSetupCompilerCallback; 205 std::string mBccPluginName; 206#endif 207}; 208 209 210} 211} 212 213#endif 214