rsCpuScript.h revision f4d216ee0f0ef18edbde208a61dc4e2fe4c8f050
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#include <vector>
27#include <utility>
28#endif
29
30#include "rsCpuCore.h"
31
32namespace bcc {
33    class BCCContext;
34    class RSCompilerDriver;
35    class RSExecutable;
36}
37
38namespace android {
39namespace renderscript {
40
41
42
43class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
44public:
45    typedef void (*outer_foreach_t)(
46        const RsForEachStubParamStruct *,
47        uint32_t x1, uint32_t x2,
48        uint32_t instep, uint32_t outstep);
49#ifdef RS_COMPATIBILITY_LIB
50    typedef void (* InvokeFunc_t)(void);
51    typedef void (* ForEachFunc_t)(void);
52    typedef int (* RootFunc_t)(void);
53    typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
54#endif
55
56    bool init(char const *resName, char const *cacheDir,
57              uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
58              char const *bccPluginName = NULL);
59    virtual void populateScript(Script *);
60
61    virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
62    virtual int invokeRoot();
63    virtual void preLaunch(uint32_t slot, const Allocation * ain,
64                           Allocation * aout, const void * usr,
65                           uint32_t usrLen, const RsScriptCall *sc);
66    virtual void postLaunch(uint32_t slot, const Allocation * ain,
67                            Allocation * aout, const void * usr,
68                            uint32_t usrLen, const RsScriptCall *sc);
69    virtual void invokeForEach(uint32_t slot,
70                       const Allocation * ain,
71                       Allocation * aout,
72                       const void * usr,
73                       uint32_t usrLen,
74                       const RsScriptCall *sc);
75    virtual void invokeInit();
76    virtual void invokeFreeChildren();
77
78    virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
79    virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength);
80    virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
81                                  const Element *e, const size_t *dims, size_t dimLength);
82    virtual void setGlobalBind(uint32_t slot, Allocation *data);
83    virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
84
85
86    virtual ~RsdCpuScriptImpl();
87    RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
88
89    const Script * getScript() {return mScript;}
90
91    void forEachMtlsSetup(const Allocation * ain, Allocation * aout,
92                          const void * usr, uint32_t usrLen,
93                          const RsScriptCall *sc, MTLaunchStruct *mtls);
94    virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
95
96
97    const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
98    static void * lookupRuntimeStub(void* pContext, char const* name);
99
100    virtual Allocation * getAllocationForPointer(const void *ptr) const;
101
102#ifndef RS_COMPATIBILITY_LIB
103    virtual  void * getRSExecutable() { return mExecutable; }
104#endif
105
106protected:
107    RsdCpuReferenceImpl *mCtx;
108    const Script *mScript;
109
110#ifndef RS_COMPATIBILITY_LIB
111    int (*mRoot)();
112    int (*mRootExpand)();
113    void (*mInit)();
114    void (*mFreeChildren)();
115
116    std::vector<std::pair<const char *, uint32_t> > mExportedForEachFuncList;
117
118    bcc::BCCContext *mCompilerContext;
119    bcc::RSCompilerDriver *mCompilerDriver;
120    bcc::CompilerRTSymbolResolver mCompilerRuntime;
121    bcc::LookupFunctionSymbolResolver<void *> mRSRuntime;
122    bcc::SymbolResolverProxy mResolver;
123    bcc::RSExecutable *mExecutable;
124#else
125    void *mScriptSO;
126    RootFunc_t mRoot;
127    RootFunc_t mRootExpand;
128    InvokeFunc_t mInit;
129    InvokeFunc_t mFreeChildren;
130    InvokeFunc_t *mInvokeFunctions;
131    ForEachFunc_t *mForEachFunctions;
132
133    void **mFieldAddress;
134    bool *mFieldIsObject;
135    uint32_t *mForEachSignatures;
136
137    // for populate script
138    //int mVersionMajor;
139    //int mVersionMinor;
140    size_t mExportedVariableCount;
141    size_t mExportedFunctionCount;
142#endif
143
144    Allocation **mBoundAllocs;
145    void * mIntrinsicData;
146    bool mIsThreadable;
147
148};
149
150
151Allocation * rsdScriptGetAllocationForPointer(
152                        const Context *dc,
153                        const Script *script,
154                        const void *);
155
156
157
158}
159}
160
161#endif
162