blob: 709d1818732e65b24f39d6dab753613b68ddb62d [file] [log] [blame]
Jason Samsbad80742011-03-16 16:29:28 -07001/*
Stephen Hinesee7aa2e2012-01-12 18:56:23 -08002 * Copyright (C) 2011-2012 The Android Open Source Project
Jason Samsbad80742011-03-16 16:29:28 -07003 *
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
Jason Sams709a0972012-11-15 18:18:04 -080017#include "../cpu_ref/rsd_cpu.h"
18
Jason Samsbad80742011-03-16 16:29:28 -070019#include "rsdCore.h"
Jason Samsbad80742011-03-16 16:29:28 -070020
Jason Samsdbe66d62012-09-17 13:54:41 -070021#include "rsdBcc.h"
Jason Samsdbe66d62012-09-17 13:54:41 -070022#include "rsdAllocation.h"
Jason Samsdbe66d62012-09-17 13:54:41 -070023
Jason Samsbad80742011-03-16 16:29:28 -070024#include "rsContext.h"
Stephen Hines2980f072012-04-09 18:26:29 -070025#include "rsElement.h"
Jason Samsbad80742011-03-16 16:29:28 -070026#include "rsScriptC.h"
27
Tim Murray0b575de2013-03-15 15:56:43 -070028#ifndef RS_SERVER
Shih-wei Liaoa3af2cd2012-04-25 04:18:31 -070029#include "utils/Vector.h"
Jason Samsbad80742011-03-16 16:29:28 -070030#include "utils/Timers.h"
31#include "utils/StopWatch.h"
Tim Murray0b575de2013-03-15 15:56:43 -070032#endif
Jason Samsbad80742011-03-16 16:29:28 -070033
Jason Samsbad80742011-03-16 16:29:28 -070034using namespace android;
35using namespace android::renderscript;
36
Jason Sams83c451a2011-04-21 11:46:50 -070037
Jason Samsbad80742011-03-16 16:29:28 -070038bool rsdScriptInit(const Context *rsc,
39 ScriptC *script,
40 char const *resName,
41 char const *cacheDir,
42 uint8_t const *bitcode,
43 size_t bitcodeSize,
Jason Sams87fe59a2011-04-20 15:09:01 -070044 uint32_t flags) {
Jason Sams709a0972012-11-15 18:18:04 -080045 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;
Jason Samsbad80742011-03-16 16:29:28 -070050 }
Jason Sams709a0972012-11-15 18:18:04 -080051 script->mHal.drv = cs;
52 cs->populateScript(script);
Jason Samsbad80742011-03-16 16:29:28 -070053 return true;
Jason Samsbad80742011-03-16 16:29:28 -070054}
55
Stephen Hines41d6c762012-08-21 17:07:38 -070056bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) {
Jason Sams709a0972012-11-15 18:18:04 -080057 RsdHal *dc = (RsdHal *)rsc->mHal.drv;
58 RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e);
59 if (cs == NULL) {
60 return false;
Jason Sams8eaba4f2012-08-14 14:38:05 -070061 }
Jason Sams709a0972012-11-15 18:18:04 -080062 s->mHal.drv = cs;
63 cs->populateScript(s);
Jason Sams8eaba4f2012-08-14 14:38:05 -070064 return true;
Jason Samsdbe66d62012-09-17 13:54:41 -070065}
66
Jason Samscdfdb8f2011-03-17 16:12:47 -070067void rsdScriptInvokeForEach(const Context *rsc,
68 Script *s,
Jason Sams35e429e2011-07-13 11:26:26 -070069 uint32_t slot,
Jason Samscdfdb8f2011-03-17 16:12:47 -070070 const Allocation * ain,
71 Allocation * aout,
72 const void * usr,
Tim Murray099bc262013-03-20 16:54:03 -070073 size_t usrLen,
Jason Samscdfdb8f2011-03-17 16:12:47 -070074 const RsScriptCall *sc) {
75
Jason Sams709a0972012-11-15 18:18:04 -080076 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
77 cs->invokeForEach(slot, ain, aout, usr, usrLen, sc);
Jason Samscdfdb8f2011-03-17 16:12:47 -070078}
79
80
Jason Sams709a0972012-11-15 18:18:04 -080081int rsdScriptInvokeRoot(const Context *dc, Script *s) {
82 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
83 return cs->invokeRoot();
Jason Samscdfdb8f2011-03-17 16:12:47 -070084}
85
Jason Sams709a0972012-11-15 18:18:04 -080086void rsdScriptInvokeInit(const Context *dc, Script *s) {
87 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
88 cs->invokeInit();
Jason Samsbad80742011-03-16 16:29:28 -070089}
90
Jason Sams709a0972012-11-15 18:18:04 -080091void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) {
92 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
93 cs->invokeFreeChildren();
Stephen Hines4ee16ff2011-08-31 17:41:39 -070094}
Jason Samsbad80742011-03-16 16:29:28 -070095
Jason Sams709a0972012-11-15 18:18:04 -080096void rsdScriptInvokeFunction(const Context *dc, Script *s,
Jason Samsbad80742011-03-16 16:29:28 -070097 uint32_t slot,
98 const void *params,
99 size_t paramLength) {
Jason Sams709a0972012-11-15 18:18:04 -0800100 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
101 cs->invokeFunction(slot, params, paramLength);
Jason Samsbad80742011-03-16 16:29:28 -0700102}
103
Jason Sams709a0972012-11-15 18:18:04 -0800104void rsdScriptSetGlobalVar(const Context *dc, const Script *s,
Jason Samsbad80742011-03-16 16:29:28 -0700105 uint32_t slot, void *data, size_t dataLength) {
Jason Sams709a0972012-11-15 18:18:04 -0800106 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
107 cs->setGlobalVar(slot, data, dataLength);
Jason Samsbad80742011-03-16 16:29:28 -0700108}
109
Jason Sams709a0972012-11-15 18:18:04 -0800110void 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);
Stephen Hines2980f072012-04-09 18:26:29 -0700116}
117
Jason Sams709a0972012-11-15 18:18:04 -0800118void 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);
Jason Samsbad80742011-03-16 16:29:28 -0700121}
122
Jason Sams709a0972012-11-15 18:18:04 -0800123void 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);
Jason Samsbad80742011-03-16 16:29:28 -0700126}
127
Jason Sams709a0972012-11-15 18:18:04 -0800128void rsdScriptDestroy(const Context *dc, Script *s) {
129 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv;
130 delete cs;
131 s->mHal.drv = NULL;
Jason Samsbad80742011-03-16 16:29:28 -0700132}
Jason Sams807fdc42012-07-25 17:55:39 -0700133
Jason Sams709a0972012-11-15 18:18:04 -0800134
Jason Sams807fdc42012-07-25 17:55:39 -0700135Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc,
136 const android::renderscript::Script *sc,
137 const void *ptr) {
Jason Sams709a0972012-11-15 18:18:04 -0800138 RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv;
139 return cs->getAllocationForPointer(ptr);
Jason Sams807fdc42012-07-25 17:55:39 -0700140}
141