blob: 666379d70fdbfd716c6c7e3e845dee273d8114ac [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)(
50 const RsForEachStubParamStruct *,
51 uint32_t x1, uint32_t x2,
52 uint32_t instep, uint32_t outstep);
Jason Sams110f1812013-03-14 16:02:18 -070053#ifdef RS_COMPATIBILITY_LIB
54 typedef void (* InvokeFunc_t)(void);
55 typedef void (* ForEachFunc_t)(void);
56 typedef int (* RootFunc_t)(void);
57 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
58#endif
Jason Sams709a0972012-11-15 18:18:04 -080059
60 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080061 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
62 char const *bccPluginName = NULL);
Jason Sams709a0972012-11-15 18:18:04 -080063 virtual void populateScript(Script *);
64
65 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
66 virtual int invokeRoot();
Jason Sams17e3cdc2013-09-09 17:32:16 -070067 virtual void preLaunch(uint32_t slot, const Allocation * ain,
68 Allocation * aout, const void * usr,
69 uint32_t usrLen, const RsScriptCall *sc);
70 virtual void postLaunch(uint32_t slot, const Allocation * ain,
71 Allocation * aout, const void * usr,
72 uint32_t usrLen, const RsScriptCall *sc);
Jason Sams709a0972012-11-15 18:18:04 -080073 virtual void invokeForEach(uint32_t slot,
74 const Allocation * ain,
75 Allocation * aout,
76 const void * usr,
77 uint32_t usrLen,
78 const RsScriptCall *sc);
79 virtual void invokeInit();
80 virtual void invokeFreeChildren();
81
82 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -070083 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
Jason Sams709a0972012-11-15 18:18:04 -080084 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070085 const Element *e, const uint32_t *dims, size_t dimLength);
Jason Sams709a0972012-11-15 18:18:04 -080086 virtual void setGlobalBind(uint32_t slot, Allocation *data);
87 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
88
89
90 virtual ~RsdCpuScriptImpl();
91 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
92
93 const Script * getScript() {return mScript;}
94
95 void forEachMtlsSetup(const Allocation * ain, Allocation * aout,
96 const void * usr, uint32_t usrLen,
97 const RsScriptCall *sc, MTLaunchStruct *mtls);
98 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
99
100
101 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
102 static void * lookupRuntimeStub(void* pContext, char const* name);
103
104 virtual Allocation * getAllocationForPointer(const void *ptr) const;
105
Jason Samscadfac42013-03-06 18:09:08 -0800106#ifndef RS_COMPATIBILITY_LIB
Stephen Hinesf218bf12013-02-12 19:32:38 -0800107 virtual void * getRSExecutable() { return mExecutable; }
Jason Samscadfac42013-03-06 18:09:08 -0800108#endif
Jason Sams709a0972012-11-15 18:18:04 -0800109
110protected:
111 RsdCpuReferenceImpl *mCtx;
112 const Script *mScript;
113
Jason Sams110f1812013-03-14 16:02:18 -0700114#ifndef RS_COMPATIBILITY_LIB
Jean-Luc Brouillet40e35cd2014-06-25 18:21:45 -0700115 // Returns the path to the core library we'll use.
116 const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -0700117 size_t bitcodeSize);
Jason Sams709a0972012-11-15 18:18:04 -0800118 int (*mRoot)();
119 int (*mRootExpand)();
120 void (*mInit)();
121 void (*mFreeChildren)();
122
Tim Murray29809d12014-05-28 12:04:19 -0700123 std::vector<std::pair<const char *, uint32_t> > mExportedForEachFuncList;
124
Jason Sams709a0972012-11-15 18:18:04 -0800125 bcc::BCCContext *mCompilerContext;
126 bcc::RSCompilerDriver *mCompilerDriver;
Stephen Hines25e3af52014-05-21 21:23:08 -0700127 bcc::CompilerRTSymbolResolver mCompilerRuntime;
128 bcc::LookupFunctionSymbolResolver<void *> mRSRuntime;
129 bcc::SymbolResolverProxy mResolver;
Jason Sams709a0972012-11-15 18:18:04 -0800130 bcc::RSExecutable *mExecutable;
Jason Sams110f1812013-03-14 16:02:18 -0700131#else
132 void *mScriptSO;
133 RootFunc_t mRoot;
134 RootFunc_t mRootExpand;
135 InvokeFunc_t mInit;
136 InvokeFunc_t mFreeChildren;
137 InvokeFunc_t *mInvokeFunctions;
138 ForEachFunc_t *mForEachFunctions;
139
140 void **mFieldAddress;
141 bool *mFieldIsObject;
142 uint32_t *mForEachSignatures;
143
144 // for populate script
145 //int mVersionMajor;
146 //int mVersionMinor;
147 size_t mExportedVariableCount;
148 size_t mExportedFunctionCount;
149#endif
Jason Sams709a0972012-11-15 18:18:04 -0800150
151 Allocation **mBoundAllocs;
152 void * mIntrinsicData;
153 bool mIsThreadable;
Jason Sams709a0972012-11-15 18:18:04 -0800154};
155
Jason Sams709a0972012-11-15 18:18:04 -0800156Allocation * rsdScriptGetAllocationForPointer(
157 const Context *dc,
158 const Script *script,
159 const void *);
160
161
162
163}
164}
165
166#endif