blob: f2c7f19a0519fda39f7ed9115383ccd23c0e0457 [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 Hines1d476622013-03-29 22:08:49 -070022typedef const char* (*RSSelectRTCallback) (const char*, size_t);
Stephen Hinesb7d9c802013-04-29 19:13:09 -070023
Jason Sams709a0972012-11-15 18:18:04 -080024namespace android {
25namespace renderscript {
26
27class ScriptC;
28class Script;
Yang Ni1ffd86b2015-01-07 09:16:40 -080029class ScriptGroupBase;
Jason Sams709a0972012-11-15 18:18:04 -080030class ScriptKernelID;
31
Jason Sams709a0972012-11-15 18:18:04 -080032class RsdCpuReference {
33public:
34 struct CpuSymbol {
35 const char * name;
36 void * fnPtr;
37 bool threadable;
38 };
39
40 typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name);
41
42 struct CpuTls {
43 Context *rsc;
44 const ScriptC * sc;
45 };
46
47 class CpuScript {
48 public:
49 virtual void populateScript(Script *) = 0;
50 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0;
51 virtual int invokeRoot() = 0;
Chris Wailesf3712132014-07-16 15:18:30 -070052
Jason Sams709a0972012-11-15 18:18:04 -080053 virtual void invokeForEach(uint32_t slot,
Chris Wailesf3712132014-07-16 15:18:30 -070054 const Allocation ** ains,
55 uint32_t inLen,
56 Allocation * aout,
57 const void * usr,
58 uint32_t usrLen,
59 const RsScriptCall *sc) = 0;
60
Matt Wala14ce0072015-07-30 17:30:25 -070061 virtual void invokeReduce(uint32_t slot,
62 const Allocation *ain,
63 Allocation *aout,
64 const RsScriptCall *sc) = 0;
65
Jason Sams709a0972012-11-15 18:18:04 -080066 virtual void invokeInit() = 0;
67 virtual void invokeFreeChildren() = 0;
68
69 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
Tim Murray9c642392013-04-11 13:29:59 -070070 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080071 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070072 const Element *e, const uint32_t *dims, size_t dimLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080073 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0;
74 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0;
75
76 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
Stephen Hines8409d642015-04-28 18:49:56 -070077
78 // Returns number of global variables in this Script (may be 0 if
79 // compiler is not configured to emit this information).
80 virtual int getGlobalEntries() const = 0;
81 // Returns the name of the global variable at index i.
82 virtual const char * getGlobalName(int i) const = 0;
83 // Returns the CPU address of the global variable at index i.
84 virtual const void * getGlobalAddress(int i) const = 0;
85 // Returns the size (in bytes) of the global variable at index i.
86 virtual size_t getGlobalSize(int i) const = 0;
Stephen Hines5aa018c2015-05-20 18:09:57 -070087 // Returns the properties of the global variable at index i.
88 virtual uint32_t getGlobalProperties(int i) const = 0;
Stephen Hines8409d642015-04-28 18:49:56 -070089
Jason Sams709a0972012-11-15 18:18:04 -080090 virtual ~CpuScript() {}
91 };
92 typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
93
Yang Ni1ffd86b2015-01-07 09:16:40 -080094 class CpuScriptGroupBase {
95 public:
96 virtual void execute() = 0;
97 virtual ~CpuScriptGroupBase() {}
98 };
99
100 class CpuScriptGroup : public CpuScriptGroupBase {
Jason Sams709a0972012-11-15 18:18:04 -0800101 public:
102 virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0;
103 virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0;
Stephen Hinesc060f142015-05-13 19:26:09 -0700104 ~CpuScriptGroup() override {};
Jason Sams709a0972012-11-15 18:18:04 -0800105 };
106
Yang Ni1ffd86b2015-01-07 09:16:40 -0800107 class CpuScriptGroup2 : public CpuScriptGroupBase {
108 public:
Stephen Hinesc060f142015-05-13 19:26:09 -0700109 ~CpuScriptGroup2() override {}
Yang Ni1ffd86b2015-01-07 09:16:40 -0800110 };
111
Jason Sams709a0972012-11-15 18:18:04 -0800112 static Context * getTlsContext();
113 static const Script * getTlsScript();
Stephen Hinesf218bf12013-02-12 19:32:38 -0800114 static pthread_key_t getThreadTLSKey();
Jason Sams709a0972012-11-15 18:18:04 -0800115
116 static RsdCpuReference * create(Context *c, uint32_t version_major,
Jason Samscadfac42013-03-06 18:09:08 -0800117 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
David Grossb043df02015-05-29 11:38:15 -0700118 , RSSelectRTCallback pSelectRTCallback = nullptr,
Chris Wailes44bef6f2014-08-12 13:51:10 -0700119 const char *pBccPluginName = nullptr
Jason Samscadfac42013-03-06 18:09:08 -0800120 );
Jason Sams709a0972012-11-15 18:18:04 -0800121 virtual ~RsdCpuReference();
122 virtual void setPriority(int32_t priority) = 0;
123
124 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
125 uint8_t const *bitcode, size_t bitcodeSize,
126 uint32_t flags) = 0;
127 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0;
Yang Ni1ffd86b2015-01-07 09:16:40 -0800128 virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0;
Stephen Hinesf218bf12013-02-12 19:32:38 -0800129 virtual bool getInForEach() = 0;
130
Pirama Arumuga Nainar5cb19fd2015-05-12 11:06:58 -0700131 // Set to true if we should embed global variable information in the code.
132 virtual void setEmbedGlobalInfo(bool v) = 0;
133
134 // Returns true if we should embed global variable information in the code.
135 virtual bool getEmbedGlobalInfo() const = 0;
136
137 // Set to true if we should skip constant (immutable) global variables when
138 // potentially embedding information about globals.
139 virtual void setEmbedGlobalInfoSkipConstant(bool v) = 0;
140
141 // Returns true if we should skip constant (immutable) global variables when
142 // potentially embedding information about globals.
143 virtual bool getEmbedGlobalInfoSkipConstant() const = 0;
Jason Sams709a0972012-11-15 18:18:04 -0800144};
145
146
147}
148}
149
150#endif