blob: fded347e7dd44158f85bccc16ec3c18a4c7af157 [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>
26#endif
27
Jason Sams709a0972012-11-15 18:18:04 -080028#include "rsCpuCore.h"
29
30namespace bcc {
31 class BCCContext;
32 class RSCompilerDriver;
33 class RSExecutable;
34}
35
36namespace android {
37namespace renderscript {
38
39
40
41class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
42public:
43 typedef void (*outer_foreach_t)(
44 const RsForEachStubParamStruct *,
45 uint32_t x1, uint32_t x2,
46 uint32_t instep, uint32_t outstep);
Jason Sams110f1812013-03-14 16:02:18 -070047#ifdef RS_COMPATIBILITY_LIB
48 typedef void (* InvokeFunc_t)(void);
49 typedef void (* ForEachFunc_t)(void);
50 typedef int (* RootFunc_t)(void);
51 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
52#endif
Jason Sams709a0972012-11-15 18:18:04 -080053
54 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080055 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
56 char const *bccPluginName = NULL);
Jason Sams709a0972012-11-15 18:18:04 -080057 virtual void populateScript(Script *);
58
59 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
60 virtual int invokeRoot();
Jason Sams17e3cdc2013-09-09 17:32:16 -070061 virtual void preLaunch(uint32_t slot, const Allocation * ain,
62 Allocation * aout, const void * usr,
63 uint32_t usrLen, const RsScriptCall *sc);
64 virtual void postLaunch(uint32_t slot, const Allocation * ain,
65 Allocation * aout, const void * usr,
66 uint32_t usrLen, const RsScriptCall *sc);
Jason Sams709a0972012-11-15 18:18:04 -080067 virtual void invokeForEach(uint32_t slot,
68 const Allocation * ain,
69 Allocation * aout,
70 const void * usr,
71 uint32_t usrLen,
72 const RsScriptCall *sc);
73 virtual void invokeInit();
74 virtual void invokeFreeChildren();
75
76 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -070077 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
Jason Sams709a0972012-11-15 18:18:04 -080078 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
79 const Element *e, const size_t *dims, size_t dimLength);
80 virtual void setGlobalBind(uint32_t slot, Allocation *data);
81 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
82
83
84 virtual ~RsdCpuScriptImpl();
85 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
86
87 const Script * getScript() {return mScript;}
88
89 void forEachMtlsSetup(const Allocation * ain, Allocation * aout,
90 const void * usr, uint32_t usrLen,
91 const RsScriptCall *sc, MTLaunchStruct *mtls);
92 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
93
94
95 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
96 static void * lookupRuntimeStub(void* pContext, char const* name);
97
98 virtual Allocation * getAllocationForPointer(const void *ptr) const;
99
Tim Murraye195a3f2014-03-13 15:04:58 -0700100#ifndef FAKE_ARM64_BUILD
Jason Samscadfac42013-03-06 18:09:08 -0800101#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -0800102 virtual void * getRSExecutable() { return mExecutable; }
Jason Samscadfac42013-03-06 18:09:08 -0800103#endif
Tim Murraye195a3f2014-03-13 15:04:58 -0700104#else
105 virtual void* getRSExecutable() { return NULL; }
106#endif
Jason Sams709a0972012-11-15 18:18:04 -0800107
108protected:
109 RsdCpuReferenceImpl *mCtx;
110 const Script *mScript;
111
Tim Murraye195a3f2014-03-13 15:04:58 -0700112#ifndef FAKE_ARM64_BUILD
Jason Sams110f1812013-03-14 16:02:18 -0700113#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -0800114 int (*mRoot)();
115 int (*mRootExpand)();
116 void (*mInit)();
117 void (*mFreeChildren)();
118
119 bcc::BCCContext *mCompilerContext;
120 bcc::RSCompilerDriver *mCompilerDriver;
Stephen Hines25e3af52014-05-21 21:23:08 -0700121 bcc::CompilerRTSymbolResolver mCompilerRuntime;
122 bcc::LookupFunctionSymbolResolver<void *> mRSRuntime;
123 bcc::SymbolResolverProxy mResolver;
Jason Sams709a0972012-11-15 18:18:04 -0800124 bcc::RSExecutable *mExecutable;
Jason Sams110f1812013-03-14 16:02:18 -0700125#else
126 void *mScriptSO;
127 RootFunc_t mRoot;
128 RootFunc_t mRootExpand;
129 InvokeFunc_t mInit;
130 InvokeFunc_t mFreeChildren;
131 InvokeFunc_t *mInvokeFunctions;
132 ForEachFunc_t *mForEachFunctions;
133
134 void **mFieldAddress;
135 bool *mFieldIsObject;
136 uint32_t *mForEachSignatures;
137
138 // for populate script
139 //int mVersionMajor;
140 //int mVersionMinor;
141 size_t mExportedVariableCount;
142 size_t mExportedFunctionCount;
143#endif
Tim Murraye195a3f2014-03-13 15:04:58 -0700144#endif
Jason Sams709a0972012-11-15 18:18:04 -0800145
146 Allocation **mBoundAllocs;
147 void * mIntrinsicData;
148 bool mIsThreadable;
149
150};
151
152
153Allocation * rsdScriptGetAllocationForPointer(
154 const Context *dc,
155 const Script *script,
156 const void *);
157
158
159
160}
161}
162
163#endif