rsdBcc.cpp revision 9c64239ebbfa4170190ede812e69150035e008e0
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 rsdScriptGetGlobalVar(const Context *dc, const Script *s,
111                           uint32_t slot, void *data, size_t dataLength) {
112    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
113    cs->getGlobalVar(slot, data, dataLength);
114}
115
116
117void rsdScriptSetGlobalVarWithElemDims(const Context *dc, const Script *s,
118                                       uint32_t slot, void *data, size_t dataLength,
119                                       const android::renderscript::Element *elem,
120                                       const size_t *dims, size_t dimLength) {
121    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
122    cs->setGlobalVarWithElemDims(slot, data, dataLength, elem, dims, dimLength);
123}
124
125void rsdScriptSetGlobalBind(const Context *dc, const Script *s, uint32_t slot, Allocation *data) {
126    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
127    cs->setGlobalBind(slot, data);
128}
129
130void rsdScriptSetGlobalObj(const Context *dc, const Script *s, uint32_t slot, ObjectBase *data) {
131    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
132    cs->setGlobalObj(slot, data);
133}
134
135void rsdScriptDestroy(const Context *dc, Script *s) {
136    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
137    delete cs;
138    s->mHal.drv = NULL;
139}
140
141
142Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
143                                              const android::renderscript::Script *sc,
144                                              const void *ptr) {
145    RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
146    return cs->getAllocationForPointer(ptr);
147}
148
149