• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef RSD_CPU_H
18 #define RSD_CPU_H
19 
20 #include "rsAllocation.h"
21 
22 #ifndef RS_COMPATIBILITY_LIB
23 namespace llvm {
24 
25 class Module;
26 
27 }  // end namespace llvm
28 
29 namespace bcc {
30 
31 class RSCompilerDriver;
32 class RSScript;
33 typedef llvm::Module* (*RSLinkRuntimeCallback)
34         (bcc::RSScript *, llvm::Module *, llvm::Module *);
35 
36 }  // end namespace bcc;
37 
38 typedef const char* (*RSSelectRTCallback) (const char*, size_t);
39 
40 typedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *);
41 #endif
42 
43 namespace android {
44 namespace renderscript {
45 
46 class ScriptC;
47 class Script;
48 class ScriptGroup;
49 class ScriptKernelID;
50 
51 
52 class RsdCpuReference {
53 public:
54     struct CpuSymbol {
55         const char * name;
56         void * fnPtr;
57         bool threadable;
58     };
59 
60     typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name);
61 
62     struct CpuTls {
63         Context *rsc;
64         const ScriptC * sc;
65     };
66 
67     class CpuScript {
68     public:
69         virtual void populateScript(Script *) = 0;
70         virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0;
71         virtual int invokeRoot() = 0;
72         virtual void invokeForEach(uint32_t slot,
73                            const Allocation * ain,
74                            Allocation * aout,
75                            const void * usr,
76                            uint32_t usrLen,
77                            const RsScriptCall *sc) = 0;
78 
79         virtual void invokeForEachMulti(uint32_t slot,
80                                          const Allocation** ains,
81                                          uint32_t inLen,
82                                          Allocation * aout,
83                                          const void * usr,
84                                          uint32_t usrLen,
85                                          const RsScriptCall *sc) = 0;
86 
87         virtual void invokeInit() = 0;
88         virtual void invokeFreeChildren() = 0;
89 
90         virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
91         virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
92         virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
93                                       const Element *e, const uint32_t *dims, size_t dimLength) = 0;
94         virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0;
95         virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0;
96 
97         virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
~CpuScript()98         virtual ~CpuScript() {}
99 
100 #ifndef RS_COMPATIBILITY_LIB
101         virtual  void * getRSExecutable()  = 0;
102 #endif
103     };
104     typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
105 
106     class CpuScriptGroup {
107     public:
108         virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0;
109         virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0;
110         virtual void execute() = 0;
~CpuScriptGroup()111         virtual ~CpuScriptGroup() {};
112     };
113 
114     static Context * getTlsContext();
115     static const Script * getTlsScript();
116     static pthread_key_t getThreadTLSKey();
117 
118     static RsdCpuReference * create(Context *c, uint32_t version_major,
119                                     uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
120 #ifndef RS_COMPATIBILITY_LIB
121                                     , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = NULL,
122                                     RSSelectRTCallback pSelectRTCallback = NULL,
123                                     const char *pBccPluginName = NULL
124 #endif
125                                     );
126     virtual ~RsdCpuReference();
127     virtual void setPriority(int32_t priority) = 0;
128 
129     virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
130                                      uint8_t const *bitcode, size_t bitcodeSize,
131                                      uint32_t flags) = 0;
132     virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0;
133     virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg) = 0;
134     virtual bool getInForEach() = 0;
135 
136 #ifndef RS_COMPATIBILITY_LIB
137     virtual void setSetupCompilerCallback(
138             RSSetupCompilerCallback pSetupCompilerCallback) = 0;
139     virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0;
140 #endif
141 };
142 
143 
144 }
145 }
146 
147 #endif
148