rsd_cpu.h revision 6c1876bbef1b2c89975dce91230a168bd2d2ce4c
1/*
2 * Copyright (C) 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_CPU_H
18#define RSD_CPU_H
19
20#include "rsAllocation.h"
21
22typedef const char* (*RSSelectRTCallback) (const char*, size_t);
23
24namespace android {
25namespace renderscript {
26
27class ScriptC;
28class Script;
29class ScriptGroupBase;
30class ScriptKernelID;
31
32class RsdCpuReference {
33public:
34    struct CpuSymbol {
35        const char * name;
36        void * fnPtr;
37        bool threadable;
38    };
39
40    typedef const CpuSymbol * (* sym_lookup_t)(Context *, const char *name);
41
42    struct CpuTls {
43        Context *rsc;
44        const ScriptC * sc;
45    };
46
47    class CpuScript {
48    public:
49        virtual void populateScript(Script *) = 0;
50        virtual void invokeFunction(uint32_t slot, const void *params, size_t paramLength) = 0;
51        virtual int invokeRoot() = 0;
52
53        virtual void invokeForEach(uint32_t slot,
54                                   const Allocation ** ains,
55                                   uint32_t inLen,
56                                   Allocation * aout,
57                                   const void * usr,
58                                   uint32_t usrLen,
59                                   const RsScriptCall *sc) = 0;
60
61        virtual void invokeReduce(uint32_t slot,
62                                  const Allocation *ain,
63                                  Allocation *aout,
64                                  const RsScriptCall *sc) = 0;
65
66        virtual void invokeReduceNew(uint32_t slot,
67                                     const Allocation ** ains, uint32_t inLen,
68                                     Allocation *aout,
69                                     const RsScriptCall *sc) = 0;
70
71        virtual void invokeInit() = 0;
72        virtual void invokeFreeChildren() = 0;
73
74        virtual void setGlobalVar(uint32_t slot, const void *data, size_t dataLength) = 0;
75        virtual void getGlobalVar(uint32_t slot, void *data, size_t dataLength) = 0;
76        virtual void setGlobalVarWithElemDims(uint32_t slot, const void *data, size_t dataLength,
77                                      const Element *e, const uint32_t *dims, size_t dimLength) = 0;
78        virtual void setGlobalBind(uint32_t slot, Allocation *data) = 0;
79        virtual void setGlobalObj(uint32_t slot, ObjectBase *obj) = 0;
80
81        virtual Allocation * getAllocationForPointer(const void *ptr) const = 0;
82
83        // Returns number of global variables in this Script (may be 0 if
84        // compiler is not configured to emit this information).
85        virtual int getGlobalEntries() const = 0;
86        // Returns the name of the global variable at index i.
87        virtual const char * getGlobalName(int i) const = 0;
88        // Returns the CPU address of the global variable at index i.
89        virtual const void * getGlobalAddress(int i) const = 0;
90        // Returns the size (in bytes) of the global variable at index i.
91        virtual size_t getGlobalSize(int i) const = 0;
92        // Returns the properties of the global variable at index i.
93        virtual uint32_t getGlobalProperties(int i) const = 0;
94
95        virtual ~CpuScript() {}
96    };
97    typedef CpuScript * (* script_lookup_t)(Context *, const Script *s);
98
99    class CpuScriptGroupBase {
100     public:
101      virtual void execute() = 0;
102      virtual ~CpuScriptGroupBase() {}
103    };
104
105    class CpuScriptGroup : public CpuScriptGroupBase {
106    public:
107        virtual void setInput(const ScriptKernelID *kid, Allocation *) = 0;
108        virtual void setOutput(const ScriptKernelID *kid, Allocation *) = 0;
109        ~CpuScriptGroup() override {};
110    };
111
112    class CpuScriptGroup2 : public CpuScriptGroupBase {
113     public:
114      ~CpuScriptGroup2() override {}
115    };
116
117    static Context * getTlsContext();
118    static const Script * getTlsScript();
119    static pthread_key_t getThreadTLSKey();
120
121    static RsdCpuReference * create(Context *c, uint32_t version_major,
122                                    uint32_t version_minor, sym_lookup_t lfn, script_lookup_t slfn
123                                    , RSSelectRTCallback pSelectRTCallback = nullptr,
124                                    const char *pBccPluginName = nullptr
125                                    );
126    virtual ~RsdCpuReference();
127    virtual void setPriority(int32_t priority) = 0;
128
129    virtual CpuScript * createScript(const ScriptC *s, char const *resName, char const *cacheDir,
130                                     uint8_t const *bitcode, size_t bitcodeSize,
131                                     uint32_t flags) = 0;
132    virtual CpuScript * createIntrinsic(const Script *s, RsScriptIntrinsicID iid, Element *e) = 0;
133    virtual void* createScriptGroup(const ScriptGroupBase *sg) = 0;
134    virtual bool getInForEach() = 0;
135
136    // Set to true if we should embed global variable information in the code.
137    virtual void setEmbedGlobalInfo(bool v) = 0;
138
139    // Returns true if we should embed global variable information in the code.
140    virtual bool getEmbedGlobalInfo() const = 0;
141
142    // Set to true if we should skip constant (immutable) global variables when
143    // potentially embedding information about globals.
144    virtual void setEmbedGlobalInfoSkipConstant(bool v) = 0;
145
146    // Returns true if we should skip constant (immutable) global variables when
147    // potentially embedding information about globals.
148    virtual bool getEmbedGlobalInfoSkipConstant() const = 0;
149};
150
151
152}
153}
154
155#endif
156