rsCpuScript.h revision b043df0676fef226336deb3a00ead2f31e02343f
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 <utility>
25#endif
26
27#include "rsCpuCore.h"
28
29namespace bcinfo {
30    class MetadataExtractor;
31}
32
33namespace android {
34namespace renderscript {
35
36class ScriptExecutable;
37
38class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
39public:
40    typedef void (*outer_foreach_t)(
41        const RsExpandKernelDriverInfo *,
42        uint32_t x1, uint32_t x2,
43        uint32_t outstep);
44
45    typedef void (* InvokeFunc_t)(void);
46    typedef void (* ForEachFunc_t)(void);
47    typedef int (* RootFunc_t)(void);
48#ifdef RS_COMPATIBILITY_LIB
49    typedef void (*WorkerCallback_t)(void *usr, uint32_t idx);
50#endif
51
52    bool init(char const *resName, char const *cacheDir,
53              uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags,
54              char const *bccPluginName = nullptr);
55    void populateScript(Script *) override;
56
57    void invokeFunction(uint32_t slot, const void *params, size_t paramLength) override;
58    int invokeRoot() override;
59    virtual void preLaunch(uint32_t slot, const Allocation ** ains,
60                           uint32_t inLen, Allocation * aout, const void * usr,
61                           uint32_t usrLen, const RsScriptCall *sc);
62    virtual void postLaunch(uint32_t slot, const Allocation ** ains,
63                            uint32_t inLen, Allocation * aout,
64                            const void * usr, uint32_t usrLen,
65                            const RsScriptCall *sc);
66
67    void invokeForEach(uint32_t slot,
68                       const Allocation ** ains,
69                       uint32_t inLen,
70                       Allocation* aout,
71                       const void* usr,
72                       uint32_t usrLen,
73                       const RsScriptCall* sc) override;
74
75    void invokeInit() override;
76    void invokeFreeChildren() override;
77
78    void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) override;
79    void getGlobalVar(uint32_t slot, void *data, size_t dataLength) override;
80    void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
81                                  const Element *e, const uint32_t *dims,
82                                  size_t dimLength) override;
83    void setGlobalBind(uint32_t slot, Allocation *data) override;
84    void setGlobalObj(uint32_t slot, ObjectBase *data) override;
85
86    const char* getFieldName(uint32_t slot) const;
87
88    ~RsdCpuScriptImpl() override;
89    RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
90
91    const Script * getScript() {return mScript;}
92
93    bool forEachMtlsSetup(const Allocation ** ains, uint32_t inLen,
94                          Allocation * aout, const void * usr, uint32_t usrLen,
95                          const RsScriptCall *sc, MTLaunchStruct *mtls);
96
97    virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
98
99
100    const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
101    static void * lookupRuntimeStub(void* pContext, char const* name);
102
103    Allocation * getAllocationForPointer(const void *ptr) const override;
104    bool storeRSInfoFromSO();
105
106    int getGlobalEntries() const override;
107    const char * getGlobalName(int i) const override;
108    const void * getGlobalAddress(int i) const override;
109    size_t getGlobalSize(int i) const override;
110    uint32_t getGlobalProperties(int i) const override;
111
112protected:
113    RsdCpuReferenceImpl *mCtx;
114    const Script *mScript;
115    void *mScriptSO;
116
117#ifndef RS_COMPATIBILITY_LIB
118    // Returns the path to the core library we'll use.
119    const char* findCoreLib(const bcinfo::MetadataExtractor& bitCodeMetaData, const char* bitcode,
120                            size_t bitcodeSize);
121#endif
122
123    RootFunc_t mRoot;
124    RootFunc_t mRootExpand;
125    InvokeFunc_t mInit;
126    InvokeFunc_t mFreeChildren;
127    ScriptExecutable* mScriptExec;
128
129    Allocation **mBoundAllocs;
130    void * mIntrinsicData;
131    bool mIsThreadable;
132
133public:
134    static const char* BCC_EXE_PATH;
135    const char* getBitcodeFilePath() const { return mBitcodeFilePath.string(); }
136
137private:
138    String8 mBitcodeFilePath;
139    uint32_t mBuildChecksum;
140    bool mChecksumNeeded;
141};
142
143Allocation * rsdScriptGetAllocationForPointer(
144                        const Context *dc,
145                        const Script *script,
146                        const void *);
147
148uint32_t constructBuildChecksum(uint8_t const *bitcode, size_t bitcodeSize,
149                                const char *commandLine,
150                                const char ** bccFiles, size_t numFiles);
151
152}
153
154#ifdef __LP64__
155#define SYSLIBPATH "/system/lib64"
156#define SYSLIBPATH_VENDOR "/system/vendor/lib64"
157#else
158#define SYSLIBPATH "/system/lib"
159#define SYSLIBPATH_VENDOR "/system/vendor/lib"
160#endif
161
162}
163
164#endif
165