rsCpuCore.h revision c31585b8ca865bf2b35abc79c8a8ee42de27bee8
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 "rsCppUtils.h" 24#include "rsElement.h" 25#include "rsScriptC.h" 26 27 28#define RS_KERNEL_INPUT_LIMIT 8 29 30namespace bcc { 31 class BCCContext; 32 class RSCompilerDriver; 33 class RSExecutable; 34} 35 36namespace android { 37namespace renderscript { 38 39struct StridePair { 40 uint32_t eStride; 41 uint32_t yStride; 42}; 43 44struct RsLaunchDimensions { 45 uint32_t x; 46 uint32_t y; 47 uint32_t z; 48 uint32_t lod; 49 uint32_t face; 50 uint32_t array[4 /*make a define*/]; 51}; 52 53struct RsExpandKernelDriverInfo { 54 // Warning: This structure is shared with the compiler 55 // Any change to the fields here requires a matching compiler change 56 57 const uint8_t *inPtr[RS_KERNEL_INPUT_LIMIT]; 58 uint32_t inStride[RS_KERNEL_INPUT_LIMIT]; 59 uint32_t inLen; 60 61 uint8_t *outPtr[RS_KERNEL_INPUT_LIMIT]; 62 uint32_t outStride[RS_KERNEL_INPUT_LIMIT]; 63 uint32_t outLen; 64 65 // Dimension of the launch 66 RsLaunchDimensions dim; 67 68 // The walking itterator of the launch 69 RsLaunchDimensions current; 70 71 const void *usr; 72 uint32_t usrLen; 73 74 75 76 // Items below this line are not used by the compiler and can be change in the driver 77 uint32_t lid; 78 uint32_t slot; 79 80}; 81 82struct RsExpandKernelParams { 83 84 // Used by kernels 85 const void **ins; 86 uint32_t *inEStrides; 87 void *out; 88 uint32_t y; 89 uint32_t z; 90 uint32_t lid; 91 92 // Used by ScriptGroup and user kernels. 93 const void *usr; 94 95 // Used by intrinsics 96 uint32_t dimX; 97 uint32_t dimY; 98 uint32_t dimZ; 99 100 /* 101 * FIXME: This is only used by the blend intrinsic. If possible, we should 102 * modify blur to not need it. 103 */ 104 uint32_t slot; 105}; 106 107extern bool gArchUseSIMD; 108 109typedef void (* InvokeFunc_t)(void); 110typedef void (* ForEachFunc_t)(void); 111typedef void (*WorkerCallback_t)(void *usr, uint32_t idx); 112 113class RsdCpuScriptImpl; 114class RsdCpuReferenceImpl; 115 116struct ScriptTLSStruct { 117 android::renderscript::Context * mContext; 118 const android::renderscript::Script * mScript; 119 RsdCpuScriptImpl *mImpl; 120}; 121 122struct MTLaunchStruct { 123 RsExpandKernelDriverInfo fep; 124 125 RsdCpuReferenceImpl *rsc; 126 RsdCpuScriptImpl *script; 127 128 ForEachFunc_t kernel; 129 uint32_t sig; 130 const Allocation * ains[RS_KERNEL_INPUT_LIMIT]; 131 Allocation * aout[RS_KERNEL_INPUT_LIMIT]; 132 133 uint32_t mSliceSize; 134 volatile int mSliceNum; 135 bool isThreadable; 136 137 RsLaunchDimensions start; 138 RsLaunchDimensions end; 139}; 140 141class RsdCpuReferenceImpl : public RsdCpuReference { 142public: 143 virtual ~RsdCpuReferenceImpl(); 144 RsdCpuReferenceImpl(Context *); 145 146 void lockMutex(); 147 void unlockMutex(); 148 149 bool init(uint32_t version_major, uint32_t version_minor, sym_lookup_t, script_lookup_t); 150 virtual void setPriority(int32_t priority); 151 virtual void launchThreads(WorkerCallback_t cbk, void *data); 152 static void * helperThreadProc(void *vrsc); 153 RsdCpuScriptImpl * setTLS(RsdCpuScriptImpl *sc); 154 155 Context * getContext() {return mRSC;} 156 uint32_t getThreadCount() const { 157 return mWorkers.mCount + 1; 158 } 159 160 void launchThreads(const Allocation** ains, uint32_t inLen, Allocation* aout, 161 const RsScriptCall* sc, MTLaunchStruct* mtls); 162 163 virtual CpuScript * createScript(const ScriptC *s, 164 char const *resName, char const *cacheDir, 165 uint8_t const *bitcode, size_t bitcodeSize, 166 uint32_t flags); 167 virtual CpuScript * createIntrinsic(const Script *s, 168 RsScriptIntrinsicID iid, Element *e); 169 virtual void* createScriptGroup(const ScriptGroupBase *sg); 170 171 const RsdCpuReference::CpuSymbol *symLookup(const char *); 172 173 RsdCpuReference::CpuScript * lookupScript(const Script *s) { 174 return mScriptLookupFn(mRSC, s); 175 } 176 177 void setLinkRuntimeCallback( 178 bcc::RSLinkRuntimeCallback pLinkRuntimeCallback) { 179 mLinkRuntimeCallback = pLinkRuntimeCallback; 180 } 181 bcc::RSLinkRuntimeCallback getLinkRuntimeCallback() { 182 return mLinkRuntimeCallback; 183 } 184 185 void setSelectRTCallback(RSSelectRTCallback pSelectRTCallback) { 186 mSelectRTCallback = pSelectRTCallback; 187 } 188 RSSelectRTCallback getSelectRTCallback() { 189 return mSelectRTCallback; 190 } 191 192 virtual void setSetupCompilerCallback( 193 RSSetupCompilerCallback pSetupCompilerCallback) { 194 mSetupCompilerCallback = pSetupCompilerCallback; 195 } 196 virtual RSSetupCompilerCallback getSetupCompilerCallback() const { 197 return mSetupCompilerCallback; 198 } 199 200 virtual void setBccPluginName(const char *name) { 201 mBccPluginName.setTo(name); 202 } 203 virtual const char *getBccPluginName() const { 204 return mBccPluginName.string(); 205 } 206 virtual bool getInForEach() { return mInForEach; } 207 208protected: 209 Context *mRSC; 210 uint32_t version_major; 211 uint32_t version_minor; 212 //bool mHasGraphics; 213 bool mInForEach; 214 215 struct Workers { 216 volatile int mRunningCount; 217 volatile int mLaunchCount; 218 uint32_t mCount; 219 pthread_t *mThreadId; 220 pid_t *mNativeThreadId; 221 Signal mCompleteSignal; 222 Signal *mLaunchSignals; 223 WorkerCallback_t mLaunchCallback; 224 void *mLaunchData; 225 }; 226 Workers mWorkers; 227 bool mExit; 228 sym_lookup_t mSymLookupFn; 229 script_lookup_t mScriptLookupFn; 230 231 ScriptTLSStruct mTlsStruct; 232 233 bcc::RSLinkRuntimeCallback mLinkRuntimeCallback; 234 RSSelectRTCallback mSelectRTCallback; 235 RSSetupCompilerCallback mSetupCompilerCallback; 236 String8 mBccPluginName; 237}; 238 239 240} 241} 242 243#endif 244