Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 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 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 17 | #include "rsScriptGroup.h" |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 18 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 19 | #include "rsContext.h" |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 20 | // TODO: Is this header needed here? |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 21 | #include "rsScriptGroup2.h" |
| 22 | |
| 23 | #include <algorithm> |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 24 | #include <time.h> |
| 25 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 26 | namespace android { |
| 27 | namespace renderscript { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 28 | |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 29 | ScriptGroup::ScriptGroup(Context *rsc) : ScriptGroupBase(rsc) { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | ScriptGroup::~ScriptGroup() { |
| 33 | if (mRSC->mHal.funcs.scriptgroup.destroy) { |
| 34 | mRSC->mHal.funcs.scriptgroup.destroy(mRSC, this); |
| 35 | } |
| 36 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 37 | for (size_t ct=0; ct < mLinks.size(); ct++) { |
| 38 | delete mLinks[ct]; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 39 | } |
Yong Chen | 61d5ed5 | 2015-01-16 09:05:18 +0800 | [diff] [blame] | 40 | |
| 41 | for (auto input : mInputs) { |
| 42 | input->mAlloc.clear(); |
| 43 | } |
| 44 | |
| 45 | for (auto output : mOutputs) { |
| 46 | output->mAlloc.clear(); |
| 47 | } |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | ScriptGroup::IO::IO(const ScriptKernelID *kid) { |
| 51 | mKernel = kid; |
| 52 | } |
| 53 | |
| 54 | ScriptGroup::Node::Node(Script *s) { |
| 55 | mScript = s; |
| 56 | mSeen = false; |
| 57 | mOrder = 0; |
| 58 | } |
| 59 | |
| 60 | ScriptGroup::Node * ScriptGroup::findNode(Script *s) const { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 61 | //ALOGE("find %p %i", s, (int)mNodes.size()); |
| 62 | for (size_t ct=0; ct < mNodes.size(); ct++) { |
| 63 | Node *n = mNodes[ct]; |
| 64 | for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) { |
| 65 | if (n->mKernels[ct2]->mScript == s) { |
| 66 | return n; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | } |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 70 | |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 71 | return nullptr; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 74 | bool ScriptGroup::calcOrderRecurse(Node *n, int depth) { |
| 75 | n->mSeen = true; |
| 76 | if (n->mOrder < depth) { |
| 77 | n->mOrder = depth; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 78 | } |
| 79 | bool ret = true; |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 80 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 81 | for (size_t ct=0; ct < n->mOutputs.size(); ct++) { |
| 82 | const Link *l = n->mOutputs[ct]; |
| 83 | Node *nt = NULL; |
| 84 | if (l->mDstField.get()) { |
| 85 | nt = findNode(l->mDstField->mScript); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 86 | } else { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 87 | nt = findNode(l->mDstKernel->mScript); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 88 | } |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 89 | if (nt->mSeen) { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 90 | return false; |
| 91 | } |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 92 | ret &= calcOrderRecurse(nt, n->mOrder + 1); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 93 | } |
| 94 | return ret; |
| 95 | } |
| 96 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 97 | class NodeCompare { |
| 98 | public: |
| 99 | bool operator() (const ScriptGroup::Node* lhs, |
| 100 | const ScriptGroup::Node* rhs) { |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 101 | return (lhs->mOrder < rhs->mOrder); |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 102 | } |
| 103 | }; |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 104 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 105 | bool ScriptGroup::calcOrder() { |
| 106 | // Make nodes |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 107 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 108 | for (size_t ct=0; ct < mKernels.size(); ct++) { |
| 109 | const ScriptKernelID *k = mKernels[ct].get(); |
| 110 | //ALOGE(" kernel %i, %p s=%p", (int)ct, k, mKernels[ct]->mScript); |
| 111 | Node *n = findNode(k->mScript); |
| 112 | //ALOGE(" n = %p", n); |
| 113 | if (n == NULL) { |
| 114 | n = new Node(k->mScript); |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 115 | mNodes.push_back(n); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 116 | } |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 117 | n->mKernels.push_back(k); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | // add links |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 121 | //ALOGE("link count %i", (int)mLinks.size()); |
| 122 | for (size_t ct=0; ct < mLinks.size(); ct++) { |
| 123 | Link *l = mLinks[ct]; |
| 124 | //ALOGE("link %i %p", (int)ct, l); |
| 125 | Node *n = findNode(l->mSource->mScript); |
| 126 | //ALOGE("link n %p", n); |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 127 | n->mOutputs.push_back(l); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 128 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 129 | if (l->mDstKernel.get()) { |
| 130 | //ALOGE("l->mDstKernel.get() %p", l->mDstKernel.get()); |
| 131 | n = findNode(l->mDstKernel->mScript); |
| 132 | //ALOGE(" n1 %p", n); |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 133 | n->mInputs.push_back(l); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 134 | } else { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 135 | n = findNode(l->mDstField->mScript); |
| 136 | //ALOGE(" n2 %p", n); |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 137 | n->mInputs.push_back(l); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 141 | //ALOGE("node count %i", (int)mNodes.size()); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 142 | // Order nodes |
| 143 | bool ret = true; |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 144 | for (size_t ct=0; ct < mNodes.size(); ct++) { |
| 145 | Node *n = mNodes[ct]; |
| 146 | if (n->mInputs.size() == 0) { |
| 147 | for (size_t ct2=0; ct2 < mNodes.size(); ct2++) { |
| 148 | mNodes[ct2]->mSeen = false; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 149 | } |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 150 | ret &= calcOrderRecurse(n, 0); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 154 | for (size_t ct=0; ct < mKernels.size(); ct++) { |
| 155 | const ScriptKernelID *k = mKernels[ct].get(); |
| 156 | const Node *n = findNode(k->mScript); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 157 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 158 | if (k->mHasKernelOutput) { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 159 | bool found = false; |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 160 | for (size_t ct2=0; ct2 < n->mOutputs.size(); ct2++) { |
| 161 | if (n->mOutputs[ct2]->mSource.get() == k) { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 162 | found = true; |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | if (!found) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 167 | //ALOGE("add io out %p", k); |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 168 | mOutputs.push_back(new IO(k)); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 172 | if (k->mHasKernelInput) { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 173 | bool found = false; |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 174 | for (size_t ct2=0; ct2 < n->mInputs.size(); ct2++) { |
| 175 | if (n->mInputs[ct2]->mDstKernel.get() == k) { |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 176 | found = true; |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | if (!found) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 181 | //ALOGE("add io in %p", k); |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 182 | mInputs.push_back(new IO(k)); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 187 | // Sort mNodes in the increasing order. |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 188 | std::sort(mNodes.begin(), mNodes.end(), NodeCompare()); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | ScriptGroup * ScriptGroup::create(Context *rsc, |
| 193 | ScriptKernelID ** kernels, size_t kernelsSize, |
| 194 | ScriptKernelID ** src, size_t srcSize, |
| 195 | ScriptKernelID ** dstK, size_t dstKSize, |
| 196 | ScriptFieldID ** dstF, size_t dstFSize, |
| 197 | const Type ** type, size_t typeSize) { |
| 198 | |
| 199 | size_t kernelCount = kernelsSize / sizeof(ScriptKernelID *); |
| 200 | size_t linkCount = typeSize / sizeof(Type *); |
| 201 | |
| 202 | //ALOGE("ScriptGroup::create kernels=%i links=%i", (int)kernelCount, (int)linkCount); |
| 203 | |
| 204 | |
| 205 | // Start by counting unique kernel sources |
| 206 | |
| 207 | ScriptGroup *sg = new ScriptGroup(rsc); |
| 208 | |
| 209 | sg->mKernels.reserve(kernelCount); |
| 210 | for (size_t ct=0; ct < kernelCount; ct++) { |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 211 | sg->mKernels.push_back(kernels[ct]); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | sg->mLinks.reserve(linkCount); |
| 215 | for (size_t ct=0; ct < linkCount; ct++) { |
| 216 | Link *l = new Link(); |
| 217 | l->mType = type[ct]; |
| 218 | l->mSource = src[ct]; |
| 219 | l->mDstField = dstF[ct]; |
| 220 | l->mDstKernel = dstK[ct]; |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 221 | sg->mLinks.push_back(l); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | sg->calcOrder(); |
| 225 | |
| 226 | // allocate links |
| 227 | for (size_t ct=0; ct < sg->mNodes.size(); ct++) { |
| 228 | const Node *n = sg->mNodes[ct]; |
| 229 | for (size_t ct2=0; ct2 < n->mOutputs.size(); ct2++) { |
| 230 | Link *l = n->mOutputs[ct2]; |
| 231 | if (l->mAlloc.get()) { |
| 232 | continue; |
| 233 | } |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 234 | Allocation * alloc = Allocation::createAllocation(rsc, |
| 235 | l->mType.get(), RS_ALLOCATION_USAGE_SCRIPT); |
| 236 | l->mAlloc = alloc; |
| 237 | |
| 238 | for (size_t ct3=ct2+1; ct3 < n->mOutputs.size(); ct3++) { |
| 239 | if (n->mOutputs[ct3]->mSource.get() == l->mSource.get()) { |
| 240 | n->mOutputs[ct3]->mAlloc = alloc; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | if (rsc->mHal.funcs.scriptgroup.init) { |
| 247 | rsc->mHal.funcs.scriptgroup.init(rsc, sg); |
| 248 | } |
Stephen Hines | 61c8695 | 2013-04-09 17:34:43 -0700 | [diff] [blame] | 249 | sg->incUserRef(); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 250 | return sg; |
| 251 | } |
| 252 | |
| 253 | void ScriptGroup::setInput(Context *rsc, ScriptKernelID *kid, Allocation *a) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 254 | for (size_t ct=0; ct < mInputs.size(); ct++) { |
| 255 | if (mInputs[ct]->mKernel == kid) { |
| 256 | mInputs[ct]->mAlloc = a; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 257 | |
| 258 | if (rsc->mHal.funcs.scriptgroup.setInput) { |
| 259 | rsc->mHal.funcs.scriptgroup.setInput(rsc, this, kid, a); |
| 260 | } |
| 261 | return; |
| 262 | } |
| 263 | } |
| 264 | rsAssert(!"ScriptGroup:setInput kid not found"); |
| 265 | } |
| 266 | |
| 267 | void ScriptGroup::setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 268 | for (size_t ct=0; ct < mOutputs.size(); ct++) { |
| 269 | if (mOutputs[ct]->mKernel == kid) { |
| 270 | mOutputs[ct]->mAlloc = a; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 271 | |
| 272 | if (rsc->mHal.funcs.scriptgroup.setOutput) { |
| 273 | rsc->mHal.funcs.scriptgroup.setOutput(rsc, this, kid, a); |
| 274 | } |
| 275 | return; |
| 276 | } |
| 277 | } |
| 278 | rsAssert(!"ScriptGroup:setOutput kid not found"); |
| 279 | } |
| 280 | |
Yang Ni | 5f6f16f | 2014-07-25 13:51:09 -0700 | [diff] [blame] | 281 | bool ScriptGroup::validateInputAndOutput(Context *rsc) { |
| 282 | for(size_t i = 0; i < mInputs.size(); i++) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 283 | if (mInputs[i]->mAlloc.get() == nullptr) { |
Yang Ni | 5f6f16f | 2014-07-25 13:51:09 -0700 | [diff] [blame] | 284 | rsc->setError(RS_ERROR_BAD_VALUE, "ScriptGroup missing input."); |
| 285 | return false; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | for(size_t i = 0; i < mOutputs.size(); i++) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 290 | if (mOutputs[i]->mAlloc.get() == nullptr) { |
Yang Ni | 5f6f16f | 2014-07-25 13:51:09 -0700 | [diff] [blame] | 291 | rsc->setError(RS_ERROR_BAD_VALUE, "ScriptGroup missing output."); |
| 292 | return false; |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | return true; |
| 297 | } |
| 298 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 299 | void ScriptGroup::execute(Context *rsc) { |
Yang Ni | 5f6f16f | 2014-07-25 13:51:09 -0700 | [diff] [blame] | 300 | if (!validateInputAndOutput(rsc)) { |
| 301 | return; |
| 302 | } |
| 303 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 304 | if (rsc->mHal.funcs.scriptgroup.execute) { |
| 305 | rsc->mHal.funcs.scriptgroup.execute(rsc, this); |
| 306 | return; |
| 307 | } |
| 308 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 309 | for (size_t ct=0; ct < mNodes.size(); ct++) { |
| 310 | Node *n = mNodes[ct]; |
| 311 | //ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size()); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 312 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 313 | for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) { |
| 314 | const ScriptKernelID *k = n->mKernels[ct2]; |
| 315 | Allocation *ain = NULL; |
| 316 | Allocation *aout = NULL; |
| 317 | |
| 318 | for (size_t ct3=0; ct3 < n->mInputs.size(); ct3++) { |
| 319 | if (n->mInputs[ct3]->mDstKernel.get() == k) { |
| 320 | ain = n->mInputs[ct3]->mAlloc.get(); |
| 321 | //ALOGE(" link in %p", ain); |
| 322 | } |
| 323 | } |
| 324 | for (size_t ct3=0; ct3 < mInputs.size(); ct3++) { |
| 325 | if (mInputs[ct3]->mKernel == k) { |
| 326 | ain = mInputs[ct3]->mAlloc.get(); |
| 327 | //ALOGE(" io in %p", ain); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 331 | for (size_t ct3=0; ct3 < n->mOutputs.size(); ct3++) { |
| 332 | if (n->mOutputs[ct3]->mSource.get() == k) { |
| 333 | aout = n->mOutputs[ct3]->mAlloc.get(); |
| 334 | //ALOGE(" link out %p", aout); |
| 335 | } |
| 336 | } |
| 337 | for (size_t ct3=0; ct3 < mOutputs.size(); ct3++) { |
| 338 | if (mOutputs[ct3]->mKernel == k) { |
| 339 | aout = mOutputs[ct3]->mAlloc.get(); |
| 340 | //ALOGE(" io out %p", aout); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 343 | |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 344 | if (ain == NULL) { |
| 345 | n->mScript->runForEach(rsc, k->mSlot, NULL, 0, aout, NULL, 0); |
Chris Wailes | 93d6bc8 | 2014-07-28 16:54:38 -0700 | [diff] [blame] | 346 | |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 347 | } else { |
| 348 | const Allocation *ains[1] = {ain}; |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 349 | n->mScript->runForEach(rsc, k->mSlot, ains, |
| 350 | sizeof(ains) / sizeof(RsAllocation), |
| 351 | aout, NULL, 0); |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 352 | } |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 353 | } |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 354 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | } |
| 358 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 359 | ScriptGroup::Link::Link() { |
| 360 | } |
| 361 | |
| 362 | ScriptGroup::Link::~Link() { |
| 363 | } |
| 364 | |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 365 | |
| 366 | RsScriptGroup rsi_ScriptGroupCreate(Context *rsc, |
| 367 | RsScriptKernelID * kernels, size_t kernelsSize, |
| 368 | RsScriptKernelID * src, size_t srcSize, |
| 369 | RsScriptKernelID * dstK, size_t dstKSize, |
| 370 | RsScriptFieldID * dstF, size_t dstFSize, |
| 371 | const RsType * type, size_t typeSize) { |
| 372 | |
| 373 | |
| 374 | return ScriptGroup::create(rsc, |
| 375 | (ScriptKernelID **) kernels, kernelsSize, |
| 376 | (ScriptKernelID **) src, srcSize, |
| 377 | (ScriptKernelID **) dstK, dstKSize, |
| 378 | (ScriptFieldID **) dstF, dstFSize, |
| 379 | (const Type **) type, typeSize); |
| 380 | } |
| 381 | |
| 382 | |
| 383 | void rsi_ScriptGroupSetInput(Context *rsc, RsScriptGroup sg, RsScriptKernelID kid, |
| 384 | RsAllocation alloc) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 385 | //ALOGE("rsi_ScriptGroupSetInput"); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 386 | ScriptGroup *s = (ScriptGroup *)sg; |
| 387 | s->setInput(rsc, (ScriptKernelID *)kid, (Allocation *)alloc); |
| 388 | } |
| 389 | |
| 390 | void rsi_ScriptGroupSetOutput(Context *rsc, RsScriptGroup sg, RsScriptKernelID kid, |
| 391 | RsAllocation alloc) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 392 | //ALOGE("rsi_ScriptGroupSetOutput"); |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 393 | ScriptGroup *s = (ScriptGroup *)sg; |
| 394 | s->setOutput(rsc, (ScriptKernelID *)kid, (Allocation *)alloc); |
| 395 | } |
| 396 | |
| 397 | void rsi_ScriptGroupExecute(Context *rsc, RsScriptGroup sg) { |
Yang Ni | 1ffd86b | 2015-01-07 09:16:40 -0800 | [diff] [blame] | 398 | ScriptGroupBase *s = (ScriptGroupBase *)sg; |
Jason Sams | dbe66d6 | 2012-09-17 13:54:41 -0700 | [diff] [blame] | 399 | s->execute(rsc); |
| 400 | } |
| 401 | |
Chih-Hung Hsieh | 11496ac | 2016-11-15 15:14:05 -0800 | [diff] [blame] | 402 | } // namespace renderscript |
| 403 | } // namespace android |