blob: 03aabf4cc65771eedbdcf71664716c7e14722cd1 [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 <utility>
Stephen Hines25e3af52014-05-21 21:23:08 -070025#endif
26
Jason Sams709a0972012-11-15 18:18:04 -080027#include "rsCpuCore.h"
28
29namespace bcc {
30 class BCCContext;
31 class RSCompilerDriver;
Jason Sams709a0972012-11-15 18:18:04 -080032}
33
Jean-Luc Brouillet9ab50942014-06-18 18:10:32 -070034namespace bcinfo {
35 class MetadataExtractor;
36}
37
Jason Sams709a0972012-11-15 18:18:04 -080038namespace android {
39namespace renderscript {
40
Yang Ni2abfcc62015-02-17 16:05:19 -080041class ScriptExecutable;
Jason Sams709a0972012-11-15 18:18:04 -080042
43class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
44public:
45 typedef void (*outer_foreach_t)(
Chris Wailes80ef6932014-07-08 11:22:18 -070046 const RsExpandKernelParams *,
Jason Sams709a0972012-11-15 18:18:04 -080047 uint32_t x1, uint32_t x2,
Chris Wailes9ed79102014-07-25 15:53:28 -070048 uint32_t outstep);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080049
Jason Sams110f1812013-03-14 16:02:18 -070050 typedef void (* InvokeFunc_t)(void);
51 typedef void (* ForEachFunc_t)(void);
52 typedef int (* RootFunc_t)(void);
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -080053#ifdef RS_COMPATIBILITY_LIB
Jason Sams110f1812013-03-14 16:02:18 -070054 typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
55#endif
Jason Sams709a0972012-11-15 18:18:04 -080056
57 bool init(char const *resName, char const *cacheDir,
Stephen Hines00511322014-01-31 11:20:23 -080058 uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
Chris Wailes44bef6f2014-08-12 13:51:10 -070059 char const *bccPluginName = nullptr);
Jason Sams709a0972012-11-15 18:18:04 -080060 virtual void populateScript(Script *);
61
62 virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
63 virtual int invokeRoot();
Chris Wailesf3712132014-07-16 15:18:30 -070064 virtual void preLaunch(uint32_t slot, const Allocation ** ains,
65 uint32_t inLen, Allocation * aout, const void * usr,
Jason Sams17e3cdc2013-09-09 17:32:16 -070066 uint32_t usrLen, const RsScriptCall *sc);
Chris Wailesf3712132014-07-16 15:18:30 -070067 virtual void postLaunch(uint32_t slot, const Allocation ** ains,
68 uint32_t inLen, Allocation * aout,
69 const void * usr, uint32_t usrLen,
70 const RsScriptCall *sc);
Chris Wailes818cfa02014-07-16 15:18:30 -070071
Chris Wailesf3712132014-07-16 15:18:30 -070072 virtual void invokeForEach(uint32_t slot,
73 const Allocation ** ains,
74 uint32_t inLen,
75 Allocation* aout,
76 const void* usr,
77 uint32_t usrLen,
78 const RsScriptCall* sc);
79
Jason Sams709a0972012-11-15 18:18:04 -080080 virtual void invokeInit();
81 virtual void invokeFreeChildren();
82
83 virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
Tim Murray9c642392013-04-11 13:29:59 -070084 virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
Jason Sams709a0972012-11-15 18:18:04 -080085 virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
Stephen Hinesac8d1462014-06-25 00:01:23 -070086 const Element *e, const uint32_t *dims, size_t dimLength);
Jason Sams709a0972012-11-15 18:18:04 -080087 virtual void setGlobalBind(uint32_t slot, Allocation *data);
88 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
89
90
91 virtual ~RsdCpuScriptImpl();
92 RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
93
94 const Script * getScript() {return mScript;}
95
Jason Samsbf2111d2015-01-26 18:13:41 -080096 bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
Chris Wailes4b3c34e2014-06-11 12:00:29 -070097 Allocation * aout, const void * usr, uint32_t usrLen,
98 const RsScriptCall *sc, MTLaunchStruct *mtls);
99
Jason Sams709a0972012-11-15 18:18:04 -0800100 virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
101
102
103 const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
104 static void * lookupRuntimeStub(void* pContext, char const* name);
105
106 virtual Allocation * getAllocationForPointer(const void *ptr) const;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800107 bool storeRSInfoFromSO();
Jason Sams709a0972012-11-15 18:18:04 -0800108
Jason Sams709a0972012-11-15 18:18:04 -0800109protected:
110 RsdCpuReferenceImpl *mCtx;
111 const Script *mScript;
Pirama Arumuga Nainardc0d8f72014-12-02 15:23:38 -0800112 void *mScriptSO;
Jason Sams709a0972012-11-15 18:18:04 -0800113
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);
Tim Murray29809d12014-05-28 12:04:19 -0700118
Jason Sams709a0972012-11-15 18:18:04 -0800119 bcc::RSCompilerDriver *mCompilerDriver;
Stephen Hines45e753a2015-01-19 20:58:44 -0800120#endif
121
Jason Sams110f1812013-03-14 16:02:18 -0700122 RootFunc_t mRoot;
123 RootFunc_t mRootExpand;
124 InvokeFunc_t mInit;
125 InvokeFunc_t mFreeChildren;
Yang Nid9bae682015-01-20 15:31:15 -0800126 ScriptExecutable* mScriptExec;
Jason Sams709a0972012-11-15 18:18:04 -0800127
128 Allocation **mBoundAllocs;
129 void * mIntrinsicData;
130 bool mIsThreadable;
Yang Nida0f0692015-01-12 13:03:40 -0800131
Yang Ni2abfcc62015-02-17 16:05:19 -0800132public:
133 static const char* BCC_EXE_PATH;
134 const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); }
Yang Nida0f0692015-01-12 13:03:40 -0800135
Yang Ni2abfcc62015-02-17 16:05:19 -0800136private:
137 String8 mBitcodeFilePath;
Jason Sams709a0972012-11-15 18:18:04 -0800138};
139
Jason Sams709a0972012-11-15 18:18:04 -0800140Allocation * rsdScriptGetAllocationForPointer(
141 const Context *dc,
142 const Script *script,
143 const void *);
144
Jason Sams709a0972012-11-15 18:18:04 -0800145}
Yang Nid9bae682015-01-20 15:31:15 -0800146
Yang Nida0f0692015-01-12 13:03:40 -0800147#ifdef __LP64__
148#define SYSLIBPATH "/system/lib64"
149#else
150#define SYSLIBPATH "/system/lib"
151#endif
152
Jason Sams709a0972012-11-15 18:18:04 -0800153}
154
155#endif