Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | ee7aa2e | 2012-01-12 18:56:23 -0800 | [diff] [blame] | 2 | * Copyright (C) 2011-2012 The Android Open Source Project |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 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 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 17 | #include "../cpu_ref/rsd_cpu.h" |
| 18 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 19 | #include "rsdCore.h" |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 20 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 21 | #include "rsdBcc.h" |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 22 | #include "rsdAllocation.h" |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 23 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 24 | #include "rsContext.h" |
Stephen Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 25 | #include "rsElement.h" |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 26 | #include "rsScriptC.h" |
| 27 | |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 28 | #ifndef RS_SERVER |
Shih-wei Liao | a3af2cd | 2012-04-25 04:18:31 -0700 | [diff] [blame] | 29 | #include "utils/Vector.h" |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 30 | #include "utils/Timers.h" |
| 31 | #include "utils/StopWatch.h" |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 32 | #endif |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 33 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 34 | using namespace android; |
| 35 | using namespace android::renderscript; |
| 36 | |
Jason Sams | 83c451a | 2011-04-21 11:46:50 -0700 | [diff] [blame] | 37 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 38 | bool 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 Sams | 87fe59a | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 44 | uint32_t flags) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 50 | } |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 51 | script->mHal.drv = cs; |
| 52 | cs->populateScript(script); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 53 | return true; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Stephen Hines | 41d6c76 | 2012-08-21 17:07:38 -0700 | [diff] [blame] | 56 | bool rsdInitIntrinsic(const Context *rsc, Script *s, RsScriptIntrinsicID iid, Element *e) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 57 | RsdHal *dc = (RsdHal *)rsc->mHal.drv; |
| 58 | RsdCpuReference::CpuScript * cs = dc->mCpuRef->createIntrinsic(s, iid, e); |
| 59 | if (cs == NULL) { |
| 60 | return false; |
Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 61 | } |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 62 | s->mHal.drv = cs; |
| 63 | cs->populateScript(s); |
Jason Sams | 8eaba4f | 2012-08-14 14:38:05 -0700 | [diff] [blame] | 64 | return true; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 67 | void rsdScriptInvokeForEach(const Context *rsc, |
| 68 | Script *s, |
Jason Sams | 35e429e | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 69 | uint32_t slot, |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 70 | const Allocation * ain, |
| 71 | Allocation * aout, |
| 72 | const void * usr, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 73 | size_t usrLen, |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 74 | const RsScriptCall *sc) { |
| 75 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 76 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 77 | cs->invokeForEach(slot, ain, aout, usr, usrLen, sc); |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 81 | int rsdScriptInvokeRoot(const Context *dc, Script *s) { |
| 82 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 83 | return cs->invokeRoot(); |
Jason Sams | cdfdb8f | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 86 | void rsdScriptInvokeInit(const Context *dc, Script *s) { |
| 87 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 88 | cs->invokeInit(); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 91 | void rsdScriptInvokeFreeChildren(const Context *dc, Script *s) { |
| 92 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 93 | cs->invokeFreeChildren(); |
Stephen Hines | 4ee16ff | 2011-08-31 17:41:39 -0700 | [diff] [blame] | 94 | } |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 95 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 96 | void rsdScriptInvokeFunction(const Context *dc, Script *s, |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 97 | uint32_t slot, |
| 98 | const void *params, |
| 99 | size_t paramLength) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 100 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 101 | cs->invokeFunction(slot, params, paramLength); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 104 | void rsdScriptSetGlobalVar(const Context *dc, const Script *s, |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 105 | uint32_t slot, void *data, size_t dataLength) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 106 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 107 | cs->setGlobalVar(slot, data, dataLength); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 110 | void 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 Hines | 2980f07 | 2012-04-09 18:26:29 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 118 | void 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 123 | void 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 Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 126 | } |
| 127 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 128 | void rsdScriptDestroy(const Context *dc, Script *s) { |
| 129 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)s->mHal.drv; |
| 130 | delete cs; |
| 131 | s->mHal.drv = NULL; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 132 | } |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 133 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 134 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 135 | Allocation * rsdScriptGetAllocationForPointer(const android::renderscript::Context *dc, |
| 136 | const android::renderscript::Script *sc, |
| 137 | const void *ptr) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 138 | RsdCpuReference::CpuScript *cs = (RsdCpuReference::CpuScript *)sc->mHal.drv; |
| 139 | return cs->getAllocationForPointer(ptr); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 140 | } |
| 141 | |