| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 1 | #ifndef CPU_REF_CPUSCRIPTGROUP2IMPL_H_ |
| 2 | #define CPU_REF_CPUSCRIPTGROUP2IMPL_H_ |
| 3 | |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 4 | #include "rsd_cpu.h" |
| Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 5 | #include "rsList.h" |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 6 | |
| David Gross | dced5c9 | 2015-03-11 16:12:42 -0700 | [diff] [blame] | 7 | struct RsExpandKernelParams; |
| 8 | |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 9 | namespace android { |
| 10 | namespace renderscript { |
| 11 | |
| 12 | class Closure; |
| 13 | class RsdCpuScriptImpl; |
| 14 | class RsdCpuReferenceImpl; |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 15 | class ScriptExecutable; |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 16 | class ScriptGroup2; |
| 17 | |
| David Gross | dced5c9 | 2015-03-11 16:12:42 -0700 | [diff] [blame] | 18 | typedef ::RsExpandKernelParams RsExpandKernelParams; |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 19 | |
| 20 | typedef void (*ExpandFuncTy)(const RsExpandKernelParams*, uint32_t, uint32_t, |
| 21 | uint32_t); |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 22 | typedef void (*InvokeFuncTy)(const void*, uint32_t); |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 23 | |
| 24 | class CPUClosure { |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 25 | public: |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 26 | CPUClosure(const Closure* closure, RsdCpuScriptImpl* si, ExpandFuncTy func) : |
| 27 | mClosure(closure), mSi(si), mFunc(func) {} |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 28 | |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 29 | CPUClosure(const Closure* closure, RsdCpuScriptImpl* si) : |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 30 | mClosure(closure), mSi(si), mFunc(nullptr) {} |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 31 | |
| 32 | // It's important to do forwarding here than inheritance for unbound value |
| 33 | // binding to work. |
| 34 | const Closure* mClosure; |
| 35 | RsdCpuScriptImpl* mSi; |
| 36 | const ExpandFuncTy mFunc; |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 37 | }; |
| 38 | |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 39 | class CpuScriptGroup2Impl; |
| 40 | |
| 41 | class Batch { |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 42 | public: |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 43 | Batch(CpuScriptGroup2Impl* group, const char* name); |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 44 | ~Batch(); |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 45 | |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 46 | // Returns true if closure depends on any closure in this batch for a global |
| 47 | // variable |
| 48 | bool conflict(CPUClosure* closure) const; |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 49 | |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 50 | void resolveFuncPtr(void* sharedObj); |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 51 | void setGlobalsForBatch(); |
| 52 | void run(); |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 53 | |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 54 | size_t size() const { return mClosures.size(); } |
| 55 | |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 56 | CpuScriptGroup2Impl* mGroup; |
| Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 57 | List<CPUClosure*> mClosures; |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 58 | char* mName; |
| 59 | void* mFunc; |
| Yang Ni | da0f069 | 2015-01-12 13:03:40 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 62 | class CpuScriptGroup2Impl : public RsdCpuReference::CpuScriptGroup2 { |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 63 | public: |
| 64 | CpuScriptGroup2Impl(RsdCpuReferenceImpl *cpuRefImpl, const ScriptGroupBase* group); |
| 65 | virtual ~CpuScriptGroup2Impl(); |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 66 | |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 67 | bool init(); |
| 68 | virtual void execute(); |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 69 | |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 70 | RsdCpuReferenceImpl* getCpuRefImpl() const { return mCpuRefImpl; } |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 71 | ScriptExecutable* getExecutable() const { return mExecutable; } |
| 72 | |
| 73 | void compile(const char* cacheDir); |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 74 | |
| Yang Ni | eb9aa67 | 2015-01-27 14:32:25 -0800 | [diff] [blame] | 75 | private: |
| 76 | RsdCpuReferenceImpl* mCpuRefImpl; |
| 77 | const ScriptGroup2* mGroup; |
| Yang Ni | ff2bb54 | 2015-02-02 14:33:47 -0800 | [diff] [blame] | 78 | List<Batch*> mBatches; |
| Yang Ni | 062c287 | 2015-02-20 15:20:00 -0800 | [diff] [blame] | 79 | ScriptExecutable* mExecutable; |
| 80 | void* mScriptObj; |
| Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | } // namespace renderscript |
| 84 | } // namespace android |
| 85 | |
| 86 | #endif // CPU_REF_CPUSCRIPTGROUP2IMPL_H_ |