blob: 7f7750f546ff8fbf8b48c1316a8feb73541cea9f [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
Tim Murray29809d12014-05-28 12:04:19 -070024#include <vector>
25#include <utility>
Stephen Hines25e3af52014-05-21 21:23:08 -070026#endif
27
Jason Sams709a0972012-11-15 18:18:04 -080028#include "rsCpuCore.h"
29
30namespace bcc {
31 class BCCContext;
32 class RSCompilerDriver;
Jason Sams709a0972012-11-15 18:18:04 -080033}
34
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -070035namespace bcinfo {
36 class MetadataExtractor;
37}
38
Jason Sams709a0972012-11-15 18:18:04 -080039namespace android {
40namespace renderscript {
41
42
43
44class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
45public:
46 typedef void (*outer_foreach_t)(
Chris Wailes80ef6932014-07-08 11:22:18 -070047 const RsExpandKernelParams *,
Jason Sams709a0972012-11-15 18:18:04 -080048 uint32_t x1, uint32_t x2,
Chris Wailes9ed79102014-07-25 15:53:28 -070049 uint32_t outstep);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080050
Jason Sams110f1812013-03-14 16:02:18 -070051 typedef void (* InvokeFunc_t)(void);
52 typedef void (* ForEachFunc_t)(void);
53 typedef int (* RootFunc_t)(void);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080054#ifdef RS_COMPATIBILITY_LIB
Jason Sams110f1812013-03-14 16:02:18 -070055 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
56#endif
Jason Sams709a0972012-11-15 18:18:04 -080057
58 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080059 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
Chris Wailes44bef6f2014-08-12 13:51:10 -070060 char const *bccPluginName = nullptr);
Jason Sams709a0972012-11-15 18:18:04 -080061 virtual void populateScript(Script *);
62
63 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
64 virtual int invokeRoot();
Chris Wailesf3712132014-07-16 15:18:30 -070065 virtual void preLaunch(uint32_t slot, const Allocation ** ains,
66 uint32_t inLen, Allocation * aout, const void * usr,
Jason Sams17e3cdc2013-09-09 17:32:16 -070067 uint32_t usrLen, const RsScriptCall *sc);
Chris Wailesf3712132014-07-16 15:18:30 -070068 virtual void postLaunch(uint32_t slot, const Allocation ** ains,
69 uint32_t inLen, Allocation * aout,
70 const void * usr, uint32_t usrLen,
71 const RsScriptCall *sc);
Chris Wailes818cfa02014-07-16 15:18:30 -070072
Chris Wailesf3712132014-07-16 15:18:30 -070073 virtual void invokeForEach(uint32_t slot,
74 const Allocation ** ains,
75 uint32_t inLen,
76 Allocation* aout,
77 const void* usr,
78 uint32_t usrLen,
79 const RsScriptCall* sc);
80
Jason Sams709a0972012-11-15 18:18:04 -080081 virtual void invokeInit();
82 virtual void invokeFreeChildren();
83
84 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -070085 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
Jason Sams709a0972012-11-15 18:18:04 -080086 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070087 const Element *e, const uint32_t *dims, size_t dimLength);
Jason Sams709a0972012-11-15 18:18:04 -080088 virtual void setGlobalBind(uint32_t slot, Allocation *data);
89 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
90
91
92 virtual ~RsdCpuScriptImpl();
93 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
94
95 const Script * getScript() {return mScript;}
96
Chris Wailes4b3c34e2014-06-11 12:00:29 -070097 void forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
98 Allocation * aout, const void * usr, uint32_t usrLen,
99 const RsScriptCall *sc, MTLaunchStruct *mtls);
100
Jason Sams709a0972012-11-15 18:18:04 -0800101 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
102
103
104 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
105 static void * lookupRuntimeStub(void* pContext, char const* name);
106
107 virtual Allocation * getAllocationForPointer(const void *ptr) const;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800108 bool storeRSInfoFromSO();
Jason Sams709a0972012-11-15 18:18:04 -0800109
Jason Sams709a0972012-11-15 18:18:04 -0800110protected:
111 RsdCpuReferenceImpl *mCtx;
112 const Script *mScript;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800113 void *mScriptSO;
Jason Sams709a0972012-11-15 18:18:04 -0800114
Jason Sams110f1812013-03-14 16:02:18 -0700115#ifndef RS_COMPATIBILITY_LIB
Jean-Luc Brouillet40e35cd2014-06-25 18:21:45 -0700116 // Returns the path to the core library we'll use.
117 const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -0700118 size_t bitcodeSize);
Tim Murray29809d12014-05-28 12:04:19 -0700119
Jason Sams709a0972012-11-15 18:18:04 -0800120 bcc::RSCompilerDriver *mCompilerDriver;
Stephen Hines45e753a2015-01-19 20:58:44 -0800121#endif
122
Jason Sams110f1812013-03-14 16:02:18 -0700123 RootFunc_t mRoot;
124 RootFunc_t mRootExpand;
125 InvokeFunc_t mInit;
126 InvokeFunc_t mFreeChildren;
127 InvokeFunc_t *mInvokeFunctions;
128 ForEachFunc_t *mForEachFunctions;
129
130 void **mFieldAddress;
131 bool *mFieldIsObject;
132 uint32_t *mForEachSignatures;
133
Jason Sams110f1812013-03-14 16:02:18 -0700134 size_t mExportedVariableCount;
135 size_t mExportedFunctionCount;
Jason Sams709a0972012-11-15 18:18:04 -0800136
137 Allocation **mBoundAllocs;
138 void * mIntrinsicData;
139 bool mIsThreadable;
Jason Sams709a0972012-11-15 18:18:04 -0800140};
141
Jason Sams709a0972012-11-15 18:18:04 -0800142Allocation * rsdScriptGetAllocationForPointer(
143 const Context *dc,
144 const Script *script,
145 const void *);
146
147
148
149}
150}
151
152#endif