blob: 3074cc8af363c7bb515c4d860470c82ec63e938f [file] [log] [blame]
Yang Ni1ffd86b2015-01-07 09:16:40 -08001#ifndef CPU_REF_CPUSCRIPTGROUP2IMPL_H_
2#define CPU_REF_CPUSCRIPTGROUP2IMPL_H_
3
Yang Ni1ffd86b2015-01-07 09:16:40 -08004#include "rsd_cpu.h"
Yang Niff2bb542015-02-02 14:33:47 -08005#include "rsList.h"
Yang Ni1ffd86b2015-01-07 09:16:40 -08006
David Grossdced5c92015-03-11 16:12:42 -07007struct RsExpandKernelParams;
8
Yang Ni1ffd86b2015-01-07 09:16:40 -08009namespace android {
10namespace renderscript {
11
12class Closure;
13class RsdCpuScriptImpl;
14class RsdCpuReferenceImpl;
Yang Nida0f0692015-01-12 13:03:40 -080015class ScriptExecutable;
Yang Ni1ffd86b2015-01-07 09:16:40 -080016class ScriptGroup2;
17
David Grossdced5c92015-03-11 16:12:42 -070018typedef ::RsExpandKernelParams RsExpandKernelParams;
Yang Ni1ffd86b2015-01-07 09:16:40 -080019
20typedef void (*ExpandFuncTy)(const RsExpandKernelParams*, uint32_t, uint32_t,
21 uint32_t);
Yang Nieb9aa672015-01-27 14:32:25 -080022typedef void (*InvokeFuncTy)(const void*, uint32_t);
Yang Ni1ffd86b2015-01-07 09:16:40 -080023
24class CPUClosure {
Yang Nieb9aa672015-01-27 14:32:25 -080025public:
Yang Ni062c2872015-02-20 15:20:00 -080026 CPUClosure(const Closure* closure, RsdCpuScriptImpl* si, ExpandFuncTy func) :
27 mClosure(closure), mSi(si), mFunc(func) {}
Yang Ni1ffd86b2015-01-07 09:16:40 -080028
Yang Nieb9aa672015-01-27 14:32:25 -080029 CPUClosure(const Closure* closure, RsdCpuScriptImpl* si) :
Yang Ni062c2872015-02-20 15:20:00 -080030 mClosure(closure), mSi(si), mFunc(nullptr) {}
Yang Nieb9aa672015-01-27 14:32:25 -080031
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 Ni1ffd86b2015-01-07 09:16:40 -080037};
38
Yang Nida0f0692015-01-12 13:03:40 -080039class CpuScriptGroup2Impl;
40
41class Batch {
Yang Nieb9aa672015-01-27 14:32:25 -080042public:
Yang Ni062c2872015-02-20 15:20:00 -080043 Batch(CpuScriptGroup2Impl* group, const char* name);
Yang Nieb9aa672015-01-27 14:32:25 -080044 ~Batch();
Yang Nida0f0692015-01-12 13:03:40 -080045
Yang Nieb9aa672015-01-27 14:32:25 -080046 // Returns true if closure depends on any closure in this batch for a global
47 // variable
48 bool conflict(CPUClosure* closure) const;
Yang Nida0f0692015-01-12 13:03:40 -080049
Yang Ni062c2872015-02-20 15:20:00 -080050 void resolveFuncPtr(void* sharedObj);
Yang Nieb9aa672015-01-27 14:32:25 -080051 void setGlobalsForBatch();
52 void run();
Yang Nida0f0692015-01-12 13:03:40 -080053
Yang Ni062c2872015-02-20 15:20:00 -080054 size_t size() const { return mClosures.size(); }
55
Yang Nieb9aa672015-01-27 14:32:25 -080056 CpuScriptGroup2Impl* mGroup;
Yang Niff2bb542015-02-02 14:33:47 -080057 List<CPUClosure*> mClosures;
Yang Ni062c2872015-02-20 15:20:00 -080058 char* mName;
59 void* mFunc;
Yang Nida0f0692015-01-12 13:03:40 -080060};
61
Yang Ni1ffd86b2015-01-07 09:16:40 -080062class CpuScriptGroup2Impl : public RsdCpuReference::CpuScriptGroup2 {
Yang Nieb9aa672015-01-27 14:32:25 -080063public:
64 CpuScriptGroup2Impl(RsdCpuReferenceImpl *cpuRefImpl, const ScriptGroupBase* group);
65 virtual ~CpuScriptGroup2Impl();
Yang Ni1ffd86b2015-01-07 09:16:40 -080066
Yang Nieb9aa672015-01-27 14:32:25 -080067 bool init();
68 virtual void execute();
Yang Ni1ffd86b2015-01-07 09:16:40 -080069
Yang Nieb9aa672015-01-27 14:32:25 -080070 RsdCpuReferenceImpl* getCpuRefImpl() const { return mCpuRefImpl; }
Yang Ni062c2872015-02-20 15:20:00 -080071 ScriptExecutable* getExecutable() const { return mExecutable; }
72
73 void compile(const char* cacheDir);
Yang Ni1ffd86b2015-01-07 09:16:40 -080074
Yang Nieb9aa672015-01-27 14:32:25 -080075private:
76 RsdCpuReferenceImpl* mCpuRefImpl;
77 const ScriptGroup2* mGroup;
Yang Niff2bb542015-02-02 14:33:47 -080078 List<Batch*> mBatches;
Yang Ni062c2872015-02-20 15:20:00 -080079 ScriptExecutable* mExecutable;
80 void* mScriptObj;
Yang Ni1ffd86b2015-01-07 09:16:40 -080081};
82
83} // namespace renderscript
84} // namespace android
85
86#endif // CPU_REF_CPUSCRIPTGROUP2IMPL_H_