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