blob: 4cc9d6df075e523336528dcaec84daf75beaf253 [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
23#include "rsCpuCore.h"
24
25namespace bcc {
26 class BCCContext;
27 class RSCompilerDriver;
28 class RSExecutable;
29}
30
31namespace android {
32namespace renderscript {
33
34
35
36class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
37public:
38 typedef void (*outer_foreach_t)(
39 const RsForEachStubParamStruct *,
40 uint32_t x1, uint32_t x2,
41 uint32_t instep, uint32_t outstep);
Jason Sams110f1812013-03-14 16:02:18 -070042#ifdef RS_COMPATIBILITY_LIB
43 typedef void (* InvokeFunc_t)(void);
44 typedef void (* ForEachFunc_t)(void);
45 typedef int (* RootFunc_t)(void);
46 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
47#endif
Jason Sams709a0972012-11-15 18:18:04 -080048
49 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080050 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
51 char const *bccPluginName = NULL);
Jason Sams709a0972012-11-15 18:18:04 -080052 virtual void populateScript(Script *);
53
54 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
55 virtual int invokeRoot();
Jason Sams17e3cdc2013-09-09 17:32:16 -070056 virtual void preLaunch(uint32_t slot, const Allocation * ain,
57 Allocation * aout, const void * usr,
58 uint32_t usrLen, const RsScriptCall *sc);
59 virtual void postLaunch(uint32_t slot, const Allocation * ain,
60 Allocation * aout, const void * usr,
61 uint32_t usrLen, const RsScriptCall *sc);
Jason Sams709a0972012-11-15 18:18:04 -080062 virtual void invokeForEach(uint32_t slot,
63 const Allocation * ain,
64 Allocation * aout,
65 const void * usr,
66 uint32_t usrLen,
67 const RsScriptCall *sc);
68 virtual void invokeInit();
69 virtual void invokeFreeChildren();
70
71 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -070072 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
Jason Sams709a0972012-11-15 18:18:04 -080073 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
74 const Element *e, const size_t *dims, size_t dimLength);
75 virtual void setGlobalBind(uint32_t slot, Allocation *data);
76 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
77
78
79 virtual ~RsdCpuScriptImpl();
80 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
81
82 const Script * getScript() {return mScript;}
83
84 void forEachMtlsSetup(const Allocation * ain, Allocation * aout,
85 const void * usr, uint32_t usrLen,
86 const RsScriptCall *sc, MTLaunchStruct *mtls);
87 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
88
89
90 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
91 static void * lookupRuntimeStub(void* pContext, char const* name);
92
93 virtual Allocation * getAllocationForPointer(const void *ptr) const;
94
Tim Murraye195a3f2014-03-13 15:04:58 -070095#ifndef FAKE_ARM64_BUILD
Jason Samscadfac42013-03-06 18:09:08 -080096#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -080097 virtual void * getRSExecutable() { return mExecutable; }
Jason Samscadfac42013-03-06 18:09:08 -080098#endif
Tim Murraye195a3f2014-03-13 15:04:58 -070099#else
100 virtual void* getRSExecutable() { return NULL; }
101#endif
Jason Sams709a0972012-11-15 18:18:04 -0800102
103protected:
104 RsdCpuReferenceImpl *mCtx;
105 const Script *mScript;
106
Tim Murraye195a3f2014-03-13 15:04:58 -0700107#ifndef FAKE_ARM64_BUILD
Jason Sams110f1812013-03-14 16:02:18 -0700108#ifndef RS_COMPATIBILITY_LIB
Jason Sams709a0972012-11-15 18:18:04 -0800109 int (*mRoot)();
110 int (*mRootExpand)();
111 void (*mInit)();
112 void (*mFreeChildren)();
113
114 bcc::BCCContext *mCompilerContext;
115 bcc::RSCompilerDriver *mCompilerDriver;
116 bcc::RSExecutable *mExecutable;
Jason Sams110f1812013-03-14 16:02:18 -0700117#else
118 void *mScriptSO;
119 RootFunc_t mRoot;
120 RootFunc_t mRootExpand;
121 InvokeFunc_t mInit;
122 InvokeFunc_t mFreeChildren;
123 InvokeFunc_t *mInvokeFunctions;
124 ForEachFunc_t *mForEachFunctions;
125
126 void **mFieldAddress;
127 bool *mFieldIsObject;
128 uint32_t *mForEachSignatures;
129
130 // for populate script
131 //int mVersionMajor;
132 //int mVersionMinor;
133 size_t mExportedVariableCount;
134 size_t mExportedFunctionCount;
135#endif
Tim Murraye195a3f2014-03-13 15:04:58 -0700136#endif
Jason Sams709a0972012-11-15 18:18:04 -0800137
138 Allocation **mBoundAllocs;
139 void * mIntrinsicData;
140 bool mIsThreadable;
141
142};
143
144
145Allocation * rsdScriptGetAllocationForPointer(
146 const Context *dc,
147 const Script *script,
148 const void *);
149
150
151
152}
153}
154
155#endif