1#ifndef CPU_REF_CPUSCRIPTGROUP2IMPL_H_ 2#define CPU_REF_CPUSCRIPTGROUP2IMPL_H_ 3 4#include "rsd_cpu.h" 5#include "rsList.h" 6 7struct RsExpandKernelDriverInfo; 8 9namespace android { 10namespace renderscript { 11 12class Closure; 13class RsdCpuScriptImpl; 14class RsdCpuReferenceImpl; 15class ScriptExecutable; 16class ScriptGroup2; 17 18typedef void (*ExpandFuncTy)(const RsExpandKernelDriverInfo*, 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 mClosure(closure), mSi(si), mFunc(func) {} 26 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 37class CpuScriptGroup2Impl; 38 39class Batch { 40public: 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 52 size_t size() const { return mClosures.size(); } 53 54 CpuScriptGroup2Impl* mGroup; 55 List<CPUClosure*> mClosures; 56 char* mName; 57 void* mFunc; 58}; 59 60class CpuScriptGroup2Impl : public RsdCpuReference::CpuScriptGroup2 { 61public: 62 CpuScriptGroup2Impl(RsdCpuReferenceImpl *cpuRefImpl, const ScriptGroupBase* group); 63 ~CpuScriptGroup2Impl() override; 64 65 bool init(); 66 void execute() override; 67 68 RsdCpuReferenceImpl* getCpuRefImpl() const { return mCpuRefImpl; } 69 ScriptExecutable* getExecutable() const { return mExecutable; } 70 71 void compile(const char* cacheDir); 72 73private: 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