blob: b0e924e3ab708dcb32aaff7b7530f6e9d33a06f7 [file] [log] [blame]
Jason Sams709a0972012-11-15 18:18:04 -08001/*
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
Jason Sams110f1812013-03-14 16:02:18 -070022#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -080023namespace llvm {
24
25class Module;
26
27} // end namespace llvm
28
29namespace bcc {
30
Stephen Hinesb7d9c802013-04-29 19:13:09 -070031class RSCompilerDriver;
Stephen Hinesf218bf12013-02-12 19:32:38 -080032class RSScript;
Stephen Hinesb7d9c802013-04-29 19:13:09 -070033typedef llvm::Module* (*RSLinkRuntimeCallback)
34 (bcc::RSScript *, llvm::Module *, llvm::Module *);
Stephen Hinesf218bf12013-02-12 19:32:38 -080035
36} // end namespace bcc;
Stephen Hines1d476622013-03-29 22:08:49 -070037
38typedef const char* (*RSSelectRTCallback) (const char*, size_t);
Stephen Hinesb7d9c802013-04-29 19:13:09 -070039
40typedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *);
Jason Sams110f1812013-03-14 16:02:18 -070041#endif
Jason Sams709a0972012-11-15 18:18:04 -080042
43namespace android {
44namespace renderscript {
45
46class ScriptC;
47class Script;
48class ScriptGroup;
49class ScriptKernelID;
50
51
52class RsdCpuReference {
53public:
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;
Chris Wailesf3712132014-07-16 15:18:30 -070072
Jason Sams709a0972012-11-15 18:18:04 -080073 virtual void invokeForEach(uint32_t slot,
Chris Wailesf3712132014-07-16 15:18:30 -070074 const Allocation ** ains,
75 uint32_t inLen,
76 Allocation * aout,
77 const void * usr,
78 uint32_t usrLen,
79 const RsScriptCall *sc) = 0;
80
Jason Sams709a0972012-11-15 18:18:04 -080081 virtual void invokeInit() = 0;
82 virtual void invokeFreeChildren() = 0;
83
84 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
Tim Murray9c642392013-04-11 13:29:59 -070085 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080086 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070087 const Element *e, const uint32_t *dims, size_t dimLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080088 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0;
89 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0;
90
91 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
92 virtual ~CpuScript() {}
Stephen Hinesf218bf12013-02-12 19:32:38 -080093
Jason Samscadfac42013-03-06 18:09:08 -080094#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -080095 virtual void * getRSExecutable() = 0;
Jason Samscadfac42013-03-06 18:09:08 -080096#endif
Jason Sams709a0972012-11-15 18:18:04 -080097 };
98 typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
99
100 class CpuScriptGroup {
101 public:
102 virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0;
103 virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0;
104 virtual void execute() = 0;
105 virtual ~CpuScriptGroup() {};
106 };
107
108 static Context * getTlsContext();
109 static const Script * getTlsScript();
Stephen Hinesf218bf12013-02-12 19:32:38 -0800110 static pthread_key_t getThreadTLSKey();
Jason Sams709a0972012-11-15 18:18:04 -0800111
112 static RsdCpuReference * create(Context *c, uint32_t version_major,
Jason Samscadfac42013-03-06 18:09:08 -0800113 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
114#ifndef RS_COMPATIBILITY_LIB
Chris Wailes44bef6f2014-08-12 13:51:10 -0700115 , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr,
116 RSSelectRTCallback pSelectRTCallback = nullptr,
117 const char *pBccPluginName = nullptr
Jason Samscadfac42013-03-06 18:09:08 -0800118#endif
119 );
Jason Sams709a0972012-11-15 18:18:04 -0800120 virtual ~RsdCpuReference();
121 virtual void setPriority(int32_t priority) = 0;
122
123 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
124 uint8_t const *bitcode, size_t bitcodeSize,
125 uint32_t flags) = 0;
126 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0;
127 virtual CpuScriptGroup * createScriptGroup(const ScriptGroup *sg) = 0;
Stephen Hinesf218bf12013-02-12 19:32:38 -0800128 virtual bool getInForEach() = 0;
129
Stephen Hinesb7d9c802013-04-29 19:13:09 -0700130#ifndef RS_COMPATIBILITY_LIB
131 virtual void setSetupCompilerCallback(
132 RSSetupCompilerCallback pSetupCompilerCallback) = 0;
133 virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0;
134#endif
Jason Sams709a0972012-11-15 18:18:04 -0800135};
136
137
138}
139}
140
141#endif