blob: d00425c617b04ceb3b865376fcd4ebb04001a845 [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
Stephen Hinesf218bf12013-02-12 19:32:38 -080022namespace llvm {
23
24class Module;
25
26} // end namespace llvm
27
28namespace bcc {
29
Stephen Hinesb7d9c802013-04-29 19:13:09 -070030class RSCompilerDriver;
Stephen Hinesf218bf12013-02-12 19:32:38 -080031class RSScript;
Stephen Hinesb7d9c802013-04-29 19:13:09 -070032typedef llvm::Module* (*RSLinkRuntimeCallback)
33 (bcc::RSScript *, llvm::Module *, llvm::Module *);
Stephen Hinesf218bf12013-02-12 19:32:38 -080034
35} // end namespace bcc;
Stephen Hines1d476622013-03-29 22:08:49 -070036
37typedef const char* (*RSSelectRTCallback) (const char*, size_t);
Stephen Hinesb7d9c802013-04-29 19:13:09 -070038
39typedef void (*RSSetupCompilerCallback) (bcc::RSCompilerDriver *);
Jason Sams709a0972012-11-15 18:18:04 -080040
41namespace android {
42namespace renderscript {
43
44class ScriptC;
45class Script;
Yang Ni1ffd86b2015-01-07 09:16:40 -080046class ScriptGroupBase;
Jason Sams709a0972012-11-15 18:18:04 -080047class ScriptKernelID;
48
49
50class RsdCpuReference {
51public:
52 struct CpuSymbol {
53 const char * name;
54 void * fnPtr;
55 bool threadable;
56 };
57
58 typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name);
59
60 struct CpuTls {
61 Context *rsc;
62 const ScriptC * sc;
63 };
64
65 class CpuScript {
66 public:
67 virtual void populateScript(Script *) = 0;
68 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0;
69 virtual int invokeRoot() = 0;
Chris Wailesf3712132014-07-16 15:18:30 -070070
Jason Sams709a0972012-11-15 18:18:04 -080071 virtual void invokeForEach(uint32_t slot,
Chris Wailesf3712132014-07-16 15:18:30 -070072 const Allocation ** ains,
73 uint32_t inLen,
74 Allocation * aout,
75 const void * usr,
76 uint32_t usrLen,
77 const RsScriptCall *sc) = 0;
78
Jason Sams709a0972012-11-15 18:18:04 -080079 virtual void invokeInit() = 0;
80 virtual void invokeFreeChildren() = 0;
81
82 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
Tim Murray9c642392013-04-11 13:29:59 -070083 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080084 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070085 const Element *e, const uint32_t *dims, size_t dimLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080086 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0;
87 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0;
88
89 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
90 virtual ~CpuScript() {}
Stephen Hinesf218bf12013-02-12 19:32:38 -080091
Jason Samscadfac42013-03-06 18:09:08 -080092#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -080093 virtual void * getRSExecutable() = 0;
Jason Samscadfac42013-03-06 18:09:08 -080094#endif
Jason Sams709a0972012-11-15 18:18:04 -080095 };
96 typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
97
Yang Ni1ffd86b2015-01-07 09:16:40 -080098 class CpuScriptGroupBase {
99 public:
100 virtual void execute() = 0;
101 virtual ~CpuScriptGroupBase() {}
102 };
103
104 class CpuScriptGroup : public CpuScriptGroupBase {
Jason Sams709a0972012-11-15 18:18:04 -0800105 public:
106 virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0;
107 virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0;
108 virtual void execute() = 0;
109 virtual ~CpuScriptGroup() {};
110 };
111
Yang Ni1ffd86b2015-01-07 09:16:40 -0800112 class CpuScriptGroup2 : public CpuScriptGroupBase {
113 public:
114 virtual void execute() = 0;
115 virtual ~CpuScriptGroup2() {}
116 };
117
Jason Sams709a0972012-11-15 18:18:04 -0800118 static Context * getTlsContext();
119 static const Script * getTlsScript();
Stephen Hinesf218bf12013-02-12 19:32:38 -0800120 static pthread_key_t getThreadTLSKey();
Jason Sams709a0972012-11-15 18:18:04 -0800121
122 static RsdCpuReference * create(Context *c, uint32_t version_major,
Jason Samscadfac42013-03-06 18:09:08 -0800123 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
Chris Wailes44bef6f2014-08-12 13:51:10 -0700124 , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = nullptr,
125 RSSelectRTCallback pSelectRTCallback = nullptr,
126 const char *pBccPluginName = nullptr
Jason Samscadfac42013-03-06 18:09:08 -0800127 );
Jason Sams709a0972012-11-15 18:18:04 -0800128 virtual ~RsdCpuReference();
129 virtual void setPriority(int32_t priority) = 0;
130
131 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
132 uint8_t const *bitcode, size_t bitcodeSize,
133 uint32_t flags) = 0;
134 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0;
Yang Ni1ffd86b2015-01-07 09:16:40 -0800135 virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0;
Stephen Hinesf218bf12013-02-12 19:32:38 -0800136 virtual bool getInForEach() = 0;
137
Stephen Hinesb7d9c802013-04-29 19:13:09 -0700138#ifndef RS_COMPATIBILITY_LIB
139 virtual void setSetupCompilerCallback(
140 RSSetupCompilerCallback pSetupCompilerCallback) = 0;
141 virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0;
142#endif
Jason Sams709a0972012-11-15 18:18:04 -0800143};
144
145
146}
147}
148
149#endif