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