rsdBcc.cpp revision 099bc262f862cdeb547cf8a78fe9e0e92560f437
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#include "../cpu_ref/rsd_cpu.h"
18
19#include "rsdCore.h"
20
21#include "rsdBcc.h"
22#include "rsdAllocation.h"
23
24#include "rsContext.h"
25#include "rsElement.h"
26#include "rsScriptC.h"
27
28#ifndef RS_SERVER
29#include "utils/Vector.h"
30#include "utils/Timers.h"
31#include "utils/StopWatch.h"
32#endif
33
34using namespace android;
35using namespace android::renderscript;
36
37
38bool rsdScriptInit(const Context *rsc,
39                     ScriptC *script,
40                     char const *resName,
41                     char const *cacheDir,
42                     uint8_t const *bitcode,
43                     size_t bitcodeSize,
44                     uint32_t flags) {
45    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
46    RsdCpuReference::CpuScript * cs = dc->mCpuRef->createScript(script, resName, cacheDir,
47                                                                bitcode, bitcodeSize, flags);
48    if (cs == NULL) {
49        return false;
50    }
51    script->mHal.drv = cs;
52    cs->populateScript(script);
53    return true;
54}
55
56bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) {
57    RsdHal *dc = (RsdHal *)rsc->mHal.drv;
58    RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e);
59    if (cs == NULL) {
60        return false;
61    }
62    s->mHal.drv = cs;
63    cs->populateScript(s);
64    return true;
65}
66
67void rsdScriptInvokeForEach(const Context *rsc,
68                            Script *s,
69                            uint32_t slot,
70                            const Allocation * ain,
71                            Allocation * aout,
72                            const void * usr,
73                            size_t usrLen,
74                            const RsScriptCall *sc) {
75
76    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
77    cs->invokeForEach(slot, ain, aout, usr, usrLen, sc);
78}
79
80
81int rsdScriptInvokeRoot(const Context *dc, Script *s) {
82    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
83    return cs->invokeRoot();
84}
85
86void rsdScriptInvokeInit(const Context *dc, Script *s) {
87    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
88    cs->invokeInit();
89}
90
91void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) {
92    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
93    cs->invokeFreeChildren();
94}
95
96void rsdScriptInvokeFunction(const Context *dc, Script *s,
97                            uint32_t slot,
98                            const void *params,
99                            size_t paramLength) {
100    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
101    cs->invokeFunction(slot, params, paramLength);
102}
103
104void rsdScriptSetGlobalVar(const Context *dc, const Script *s,
105                           uint32_t slot, void *data, size_t dataLength) {
106    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
107    cs->setGlobalVar(slot, data, dataLength);
108}
109
110void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s,
111                                       uint32_t slot, void *data, size_t dataLength,
112                                       const android::renderscript::Element *elem,
113                                       const size_t *dims, size_t dimLength) {
114    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
115    cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength);
116}
117
118void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) {
119    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
120    cs->setGlobalBind(slot, data);
121}
122
123void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) {
124    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
125    cs->setGlobalObj(slot, data);
126}
127
128void rsdScriptDestroy(const Context *dc, Script *s) {
129    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
130    delete cs;
131    s->mHal.drv = NULL;
132}
133
134
135Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
136                                              const android::renderscript::Script *sc,
137                                              const void *ptr) {
138    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
139    return cs->getAllocationForPointer(ptr);
140}
141
142