rsCpuScript.h revision cadfac411e6690e39de36c4f9e94deb9b7d2d08e
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#include "rsCpuCore.h"
24
25namespace bcc {
26    class BCCContext;
27    class RSCompilerDriver;
28    class RSExecutable;
29}
30
31namespace android {
32namespace renderscript {
33
34
35
36class RsdCpuScriptImpl : public RsdCpuReferenceImpl::CpuScript {
37public:
38    typedef void (*outer_foreach_t)(
39        const RsForEachStubParamStruct *,
40        uint32_t x1, uint32_t x2,
41        uint32_t instep, uint32_t outstep);
42
43    bool init(char const *resName, char const *cacheDir,
44              uint8_t const *bitcode, size_t bitcodeSize, uint32_t flags);
45    virtual void populateScript(Script *);
46
47    virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength);
48    virtual int invokeRoot();
49    virtual void invokeForEach(uint32_t slot,
50                       const Allocation * ain,
51                       Allocation * aout,
52                       const void * usr,
53                       uint32_t usrLen,
54                       const RsScriptCall *sc);
55    virtual void invokeInit();
56    virtual void invokeFreeChildren();
57
58    virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength);
59    virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
60                                  const Element *e, const size_t *dims, size_t dimLength);
61    virtual void setGlobalBind(uint32_t slot, Allocation *data);
62    virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
63
64
65    virtual ~RsdCpuScriptImpl();
66    RsdCpuScriptImpl(RsdCpuReferenceImpl *ctx, const Script *s);
67
68    const Script * getScript() {return mScript;}
69
70    void forEachMtlsSetup(const Allocation * ain, Allocation * aout,
71                          const void * usr, uint32_t usrLen,
72                          const RsScriptCall *sc, MTLaunchStruct *mtls);
73    virtual void forEachKernelSetup(uint32_t slot, MTLaunchStruct *mtls);
74
75
76    const RsdCpuReference::CpuSymbol * lookupSymbolMath(const char *sym);
77    static void * lookupRuntimeStub(void* pContext, char const* name);
78
79    virtual Allocation * getAllocationForPointer(const void *ptr) const;
80
81#ifndef RS_COMPATIBILITY_LIB
82    virtual  void * getRSExecutable() { return mExecutable; }
83#endif
84
85protected:
86    RsdCpuReferenceImpl *mCtx;
87    const Script *mScript;
88
89    int (*mRoot)();
90    int (*mRootExpand)();
91    void (*mInit)();
92    void (*mFreeChildren)();
93
94    bcc::BCCContext *mCompilerContext;
95    bcc::RSCompilerDriver *mCompilerDriver;
96    bcc::RSExecutable *mExecutable;
97
98    Allocation **mBoundAllocs;
99    void * mIntrinsicData;
100    bool mIsThreadable;
101
102};
103
104
105Allocation * rsdScriptGetAllocationForPointer(
106                        const Context *dc,
107                        const Script *script,
108                        const void *);
109
110
111
112}
113}
114
115#endif
116