blob: 0076cb981f826347bbe3605604dda96140b6e9d5 [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;
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;
Chris Wailes4b3c34e2014-06-11 12:00:29 -070078
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
Jason Sams709a0972012-11-15 18:18:04 -080087 virtual void invokeInit() = 0;
88 virtual void invokeFreeChildren() = 0;
89
90 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
Tim Murray9c642392013-04-11 13:29:59 -070091 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080092 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070093 const Element *e, const uint32_t *dims, size_t dimLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080094 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;
98 virtual ~CpuScript() {}
Stephen Hinesf218bf12013-02-12 19:32:38 -080099
Jason Samscadfac42013-03-06 18:09:08 -0800100#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -0800101 virtual void * getRSExecutable() = 0;
Jason Samscadfac42013-03-06 18:09:08 -0800102#endif
Jason Sams709a0972012-11-15 18:18:04 -0800103 };
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;
111 virtual ~CpuScriptGroup() {};
112 };
113
114 static Context * getTlsContext();
115 static const Script * getTlsScript();
Stephen Hinesf218bf12013-02-12 19:32:38 -0800116 static pthread_key_t getThreadTLSKey();
Jason Sams709a0972012-11-15 18:18:04 -0800117
118 static RsdCpuReference * create(Context *c, uint32_t version_major,
Jason Samscadfac42013-03-06 18:09:08 -0800119 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
120#ifndef RS_COMPATIBILITY_LIB
Stephen Hines1d476622013-03-29 22:08:49 -0700121 , bcc::RSLinkRuntimeCallback pLinkRuntimeCallback = NULL,
Stephen Hines00511322014-01-31 11:20:23 -0800122 RSSelectRTCallback pSelectRTCallback = NULL,
123 const char *pBccPluginName = NULL
Jason Samscadfac42013-03-06 18:09:08 -0800124#endif
125 );
Jason Sams709a0972012-11-15 18:18:04 -0800126 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;
Stephen Hinesf218bf12013-02-12 19:32:38 -0800134 virtual bool getInForEach() = 0;
135
Stephen Hinesb7d9c802013-04-29 19:13:09 -0700136#ifndef RS_COMPATIBILITY_LIB
137 virtual void setSetupCompilerCallback(
138 RSSetupCompilerCallback pSetupCompilerCallback) = 0;
139 virtual RSSetupCompilerCallback getSetupCompilerCallback() const = 0;
140#endif
Jason Sams709a0972012-11-15 18:18:04 -0800141};
142
143
144}
145}
146
147#endif