rsCpuScript.h revision 25e3af55a43faddced1a9931574dfdc3cc8ad8fd
1/*
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#ifndef RS_COMPATIBILITY_LIB
24#include <bcc/ExecutionEngine/CompilerRTSymbolResolver.h>
25#include <bcc/ExecutionEngine/SymbolResolverProxy.h>
26#endif
27
28#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);
47#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
53
54    bool init(char const *resName, char const *cacheDir,
55              uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
56              char const *bccPluginName = NULL);
57    virtual void populateScript(Script *);
58
59    virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
60    virtual int invokeRoot();
61    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);
67    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);
77    virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
78    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
100#ifndef FAKE_ARM64_BUILD
101#ifndef RS_COMPATIBILITY_LIB
102    virtual  void * getRSExecutable() { return mExecutable; }
103#endif
104#else
105    virtual void* getRSExecutable() { return NULL; }
106#endif
107
108protected:
109    RsdCpuReferenceImpl *mCtx;
110    const Script *mScript;
111
112#ifndef FAKE_ARM64_BUILD
113#ifndef RS_COMPATIBILITY_LIB
114    int (*mRoot)();
115    int (*mRootExpand)();
116    void (*mInit)();
117    void (*mFreeChildren)();
118
119    bcc::BCCContext *mCompilerContext;
120    bcc::RSCompilerDriver *mCompilerDriver;
121    bcc::CompilerRTSymbolResolver mCompilerRuntime;
122    bcc::LookupFunctionSymbolResolver<void *> mRSRuntime;
123    bcc::SymbolResolverProxy mResolver;
124    bcc::RSExecutable *mExecutable;
125#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
144#endif
145
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
164