rsCpuScript.h revision 709a0978ae141198018ca9769f8d96292a8928e6
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
82protected:
83    RsdCpuReferenceImpl *mCtx;
84    const Script *mScript;
85
86    int (*mRoot)();
87    int (*mRootExpand)();
88    void (*mInit)();
89    void (*mFreeChildren)();
90
91    bcc::BCCContext *mCompilerContext;
92    bcc::RSCompilerDriver *mCompilerDriver;
93    bcc::RSExecutable *mExecutable;
94
95    Allocation **mBoundAllocs;
96    void * mIntrinsicData;
97    bool mIsThreadable;
98
99};
100
101
102Allocation * rsdScriptGetAllocationForPointer(
103                        const Context *dc,
104                        const Script *script,
105                        const void *);
106
107
108
109}
110}
111
112#endif
113