blob: 130e6ac2ebdc859b6d2478d25fdd6d4d459ba90a [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
Yang Nicf34bdc2016-11-29 09:21:36 -080020#include "rsInternalDefines.h"
Jason Sams709a0972012-11-15 18:18:04 -080021
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
Yang Nicf34bdc2016-11-29 09:21:36 -080027class Allocation;
28class Context;
29class Element;
30class ObjectBase;
Jason Sams709a0972012-11-15 18:18:04 -080031class ScriptC;
32class Script;
Yang Ni1ffd86b2015-01-07 09:16:40 -080033class ScriptGroupBase;
Jason Sams709a0972012-11-15 18:18:04 -080034class ScriptKernelID;
35
Jason Sams709a0972012-11-15 18:18:04 -080036class RsdCpuReference {
37public:
38 struct CpuSymbol {
39 const char * name;
40 void * fnPtr;
41 bool threadable;
42 };
43
44 typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name);
45
46 struct CpuTls {
47 Context *rsc;
48 const ScriptC * sc;
49 };
50
51 class CpuScript {
52 public:
53 virtual void populateScript(Script *) = 0;
54 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0;
55 virtual int invokeRoot() = 0;
Chris Wailesf3712132014-07-16 15:18:30 -070056
Jason Sams709a0972012-11-15 18:18:04 -080057 virtual void invokeForEach(uint32_t slot,
Chris Wailesf3712132014-07-16 15:18:30 -070058 const Allocation ** ains,
59 uint32_t inLen,
60 Allocation * aout,
61 const void * usr,
62 uint32_t usrLen,
63 const RsScriptCall *sc) = 0;
64
Matt Wala14ce0072015-07-30 17:30:25 -070065 virtual void invokeReduce(uint32_t slot,
David Grossae2ec3f2016-06-01 14:45:47 -070066 const Allocation ** ains, uint32_t inLen,
Matt Wala14ce0072015-07-30 17:30:25 -070067 Allocation *aout,
68 const RsScriptCall *sc) = 0;
69
Jason Sams709a0972012-11-15 18:18:04 -080070 virtual void invokeInit() = 0;
71 virtual void invokeFreeChildren() = 0;
72
73 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
Tim Murray9c642392013-04-11 13:29:59 -070074 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080075 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070076 const Element *e, const uint32_t *dims, size_t dimLength) = 0;
Jason Sams709a0972012-11-15 18:18:04 -080077 virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0;
78 virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0;
79
80 virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
Stephen Hines8409d642015-04-28 18:49:56 -070081
82 // Returns number of global variables in this Script (may be 0 if
83 // compiler is not configured to emit this information).
84 virtual int getGlobalEntries() const = 0;
85 // Returns the name of the global variable at index i.
86 virtual const char * getGlobalName(int i) const = 0;
87 // Returns the CPU address of the global variable at index i.
88 virtual const void * getGlobalAddress(int i) const = 0;
89 // Returns the size (in bytes) of the global variable at index i.
90 virtual size_t getGlobalSize(int i) const = 0;
Stephen Hines5aa018c2015-05-20 18:09:57 -070091 // Returns the properties of the global variable at index i.
92 virtual uint32_t getGlobalProperties(int i) const = 0;
Stephen Hines8409d642015-04-28 18:49:56 -070093
Jason Sams709a0972012-11-15 18:18:04 -080094 virtual ~CpuScript() {}
95 };
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;
Stephen Hinesc060f142015-05-13 19:26:09 -0700108 ~CpuScriptGroup() override {};
Jason Sams709a0972012-11-15 18:18:04 -0800109 };
110
Yang Ni1ffd86b2015-01-07 09:16:40 -0800111 class CpuScriptGroup2 : public CpuScriptGroupBase {
112 public:
Stephen Hinesc060f142015-05-13 19:26:09 -0700113 ~CpuScriptGroup2() override {}
Yang Ni1ffd86b2015-01-07 09:16:40 -0800114 };
115
Jason Sams709a0972012-11-15 18:18:04 -0800116 static Context * getTlsContext();
117 static const Script * getTlsScript();
Stephen Hinesf218bf12013-02-12 19:32:38 -0800118 static pthread_key_t getThreadTLSKey();
Jason Sams709a0972012-11-15 18:18:04 -0800119
120 static RsdCpuReference * create(Context *c, uint32_t version_major,
Jason Samscadfac42013-03-06 18:09:08 -0800121 uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
David Grossb043df02015-05-29 11:38:15 -0700122 , RSSelectRTCallback pSelectRTCallback = nullptr,
Chris Wailes44bef6f2014-08-12 13:51:10 -0700123 const char *pBccPluginName = nullptr
Jason Samscadfac42013-03-06 18:09:08 -0800124 );
Jason Sams709a0972012-11-15 18:18:04 -0800125 virtual ~RsdCpuReference();
126 virtual void setPriority(int32_t priority) = 0;
127
128 virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
129 uint8_t const *bitcode, size_t bitcodeSize,
130 uint32_t flags) = 0;
131 virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0;
Yang Ni1ffd86b2015-01-07 09:16:40 -0800132 virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0;
David Gross10adb0c2016-03-29 13:48:41 -0700133 virtual bool getInKernel() = 0; // Is a parallel kernel execution underway?
Stephen Hinesf218bf12013-02-12 19:32:38 -0800134
Pirama Arumuga Nainar5cb19fd2015-05-12 11:06:58 -0700135 // Set to true if we should embed global variable information in the code.
136 virtual void setEmbedGlobalInfo(bool v) = 0;
137
138 // Returns true if we should embed global variable information in the code.
139 virtual bool getEmbedGlobalInfo() const = 0;
140
141 // Set to true if we should skip constant (immutable) global variables when
142 // potentially embedding information about globals.
143 virtual void setEmbedGlobalInfoSkipConstant(bool v) = 0;
144
145 // Returns true if we should skip constant (immutable) global variables when
146 // potentially embedding information about globals.
147 virtual bool getEmbedGlobalInfoSkipConstant() const = 0;
Jason Sams709a0972012-11-15 18:18:04 -0800148};
149
150
Rahul Chaudhry7974fc02017-02-09 12:33:28 -0800151} // namespace renderscript
152} // namespace android
Jason Sams709a0972012-11-15 18:18:04 -0800153
154#endif