rsCpuScriptGroup2.h 2.1 KB

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