blob: 324ee14f4e4d76d74edd7cc5b96ffb7f03b5b89e [file] [log] [blame]
Jason Sams709a0972012-11-15 18:18:04 -08001/*
2 * Copyright (C) 2011-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_BCC_H
18#define RSD_BCC_H
19
20#include <rs_hal.h>
21#include <rsRuntime.h>
22
Stephen Hines25e3af52014-05-21 21:23:08 -070023#ifndef RS_COMPATIBILITY_LIB
24#include <bcc/ExecutionEngine/CompilerRTSymbolResolver.h>
25#include <bcc/ExecutionEngine/SymbolResolverProxy.h>
Tim Murray29809d12014-05-28 12:04:19 -070026#include <vector>
27#include <utility>
Stephen Hines25e3af52014-05-21 21:23:08 -070028#endif
29
Jason Sams709a0972012-11-15 18:18:04 -080030#include "rsCpuCore.h"
31
32namespace bcc {
33 class BCCContext;
34 class RSCompilerDriver;
35 class RSExecutable;
36}
37
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -070038namespace bcinfo {
39 class MetadataExtractor;
40}
41
Jason Sams709a0972012-11-15 18:18:04 -080042namespace android {
43namespace renderscript {
44
45
46
47class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
48public:
49 typedef void (*outer_foreach_t)(
Chris Wailes80ef6932014-07-08 11:22:18 -070050 const RsExpandKernelParams *,
Jason Sams709a0972012-11-15 18:18:04 -080051 uint32_t x1, uint32_t x2,
Chris Wailes9ed79102014-07-25 15:53:28 -070052 uint32_t outstep);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080053
Jason Sams110f1812013-03-14 16:02:18 -070054 typedef void (* InvokeFunc_t)(void);
55 typedef void (* ForEachFunc_t)(void);
56 typedef int (* RootFunc_t)(void);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080057#ifdef RS_COMPATIBILITY_LIB
Jason Sams110f1812013-03-14 16:02:18 -070058 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
59#endif
Jason Sams709a0972012-11-15 18:18:04 -080060
61 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080062 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
Chris Wailes44bef6f2014-08-12 13:51:10 -070063 char const *bccPluginName = nullptr);
Jason Sams709a0972012-11-15 18:18:04 -080064 virtual void populateScript(Script *);
65
66 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
67 virtual int invokeRoot();
Chris Wailesf3712132014-07-16 15:18:30 -070068 virtual void preLaunch(uint32_t slot, const Allocation ** ains,
69 uint32_t inLen, Allocation * aout, const void * usr,
Jason Sams17e3cdc2013-09-09 17:32:16 -070070 uint32_t usrLen, const RsScriptCall *sc);
Chris Wailesf3712132014-07-16 15:18:30 -070071 virtual void postLaunch(uint32_t slot, const Allocation ** ains,
72 uint32_t inLen, Allocation * aout,
73 const void * usr, uint32_t usrLen,
74 const RsScriptCall *sc);
Chris Wailes818cfa02014-07-16 15:18:30 -070075
Chris Wailesf3712132014-07-16 15:18:30 -070076 virtual void invokeForEach(uint32_t slot,
77 const Allocation ** ains,
78 uint32_t inLen,
79 Allocation* aout,
80 const void* usr,
81 uint32_t usrLen,
82 const RsScriptCall* sc);
83
Jason Sams709a0972012-11-15 18:18:04 -080084 virtual void invokeInit();
85 virtual void invokeFreeChildren();
86
87 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -070088 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
Jason Sams709a0972012-11-15 18:18:04 -080089 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070090 const Element *e, const uint32_t *dims, size_t dimLength);
Jason Sams709a0972012-11-15 18:18:04 -080091 virtual void setGlobalBind(uint32_t slot, Allocation *data);
92 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
93
94
95 virtual ~RsdCpuScriptImpl();
96 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
97
98 const Script * getScript() {return mScript;}
99
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700100 void forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
101 Allocation * aout, const void * usr, uint32_t usrLen,
102 const RsScriptCall *sc, MTLaunchStruct *mtls);
103
Jason Sams709a0972012-11-15 18:18:04 -0800104 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
105
106
107 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
108 static void * lookupRuntimeStub(void* pContext, char const* name);
109
110 virtual Allocation * getAllocationForPointer(const void *ptr) const;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800111 bool storeRSInfoFromSO();
Jason Sams709a0972012-11-15 18:18:04 -0800112
Jason Samscadfac42013-03-06 18:09:08 -0800113#ifndef RS_COMPATIBILITY_LIB
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800114 bool storeRSInfoFromObj(bcinfo::MetadataExtractor &bitcodeMetadata);
Stephen Hinesf218bf12013-02-12 19:32:38 -0800115 virtual void * getRSExecutable() { return mExecutable; }
Jason Samscadfac42013-03-06 18:09:08 -0800116#endif
Jason Sams709a0972012-11-15 18:18:04 -0800117
118protected:
119 RsdCpuReferenceImpl *mCtx;
120 const Script *mScript;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800121 void *mScriptSO;
Jason Sams709a0972012-11-15 18:18:04 -0800122
Jason Sams110f1812013-03-14 16:02:18 -0700123#ifndef RS_COMPATIBILITY_LIB
Jean-Luc Brouillet40e35cd2014-06-25 18:21:45 -0700124 // Returns the path to the core library we'll use.
125 const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -0700126 size_t bitcodeSize);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800127 RootFunc_t mRoot;
128 RootFunc_t mRootExpand;
129 InvokeFunc_t mInit;
130 InvokeFunc_t mFreeChildren;
131
132 InvokeFunc_t *mInvokeFunctions;
133 ForEachFunc_t *mForEachFunctions;
134 void **mFieldAddress;
135 bool *mFieldIsObject;
136 uint32_t *mForEachSignatures;
137 size_t mExportedVariableCount;
138 size_t mExportedFunctionCount;
Jason Sams709a0972012-11-15 18:18:04 -0800139
Tim Murray29809d12014-05-28 12:04:19 -0700140 std::vector<std::pair<const char *, uint32_t> > mExportedForEachFuncList;
141
Jason Sams709a0972012-11-15 18:18:04 -0800142 bcc::RSCompilerDriver *mCompilerDriver;
Stephen Hines25e3af52014-05-21 21:23:08 -0700143 bcc::CompilerRTSymbolResolver mCompilerRuntime;
144 bcc::LookupFunctionSymbolResolver<void *> mRSRuntime;
145 bcc::SymbolResolverProxy mResolver;
Jason Sams709a0972012-11-15 18:18:04 -0800146 bcc::RSExecutable *mExecutable;
Jason Sams110f1812013-03-14 16:02:18 -0700147#else
Jason Sams110f1812013-03-14 16:02:18 -0700148 RootFunc_t mRoot;
149 RootFunc_t mRootExpand;
150 InvokeFunc_t mInit;
151 InvokeFunc_t mFreeChildren;
152 InvokeFunc_t *mInvokeFunctions;
153 ForEachFunc_t *mForEachFunctions;
154
155 void **mFieldAddress;
156 bool *mFieldIsObject;
157 uint32_t *mForEachSignatures;
158
159 // for populate script
160 //int mVersionMajor;
161 //int mVersionMinor;
162 size_t mExportedVariableCount;
163 size_t mExportedFunctionCount;
164#endif
Jason Sams709a0972012-11-15 18:18:04 -0800165
166 Allocation **mBoundAllocs;
167 void * mIntrinsicData;
168 bool mIsThreadable;
Jason Sams709a0972012-11-15 18:18:04 -0800169};
170
Jason Sams709a0972012-11-15 18:18:04 -0800171Allocation * rsdScriptGetAllocationForPointer(
172 const Context *dc,
173 const Script *script,
174 const void *);
175
176
177
178}
179}
180
181#endif