Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 "rsContext.h" |
| 18 | #include "rsScriptC.h" |
| 19 | #include "rsMatrix.h" |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 20 | #include "../../../external/llvm/libbcc/include/bcc/bcc.h" |
Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 21 | #include "utils/Timers.h" |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 22 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 23 | #include <GLES/gl.h> |
| 24 | #include <GLES/glext.h> |
| 25 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 29 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 30 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 31 | Context * rsc = tls->mContext; \ |
| 32 | ScriptC * sc = (ScriptC *) tls->mScript |
| 33 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 35 | ScriptC::ScriptC(Context *rsc) : Script(rsc) |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 36 | { |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 37 | mAllocFile = __FILE__; |
| 38 | mAllocLine = __LINE__; |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 39 | mBccScript = NULL; |
Jason Sams | efb8de1 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 40 | memset(&mProgram, 0, sizeof(mProgram)); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | ScriptC::~ScriptC() |
| 44 | { |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 45 | if (mBccScript) { |
| 46 | bccDeleteScript(mBccScript); |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 47 | } |
Jason Sams | e402ed3 | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 48 | free(mEnviroment.mScriptText); |
| 49 | mEnviroment.mScriptText = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 52 | void ScriptC::setupScript(Context *rsc) |
Jason Sams | ada7f27 | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 53 | { |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 54 | setupGLState(rsc); |
| 55 | mEnviroment.mStartTimeMillis |
| 56 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 57 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 58 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
| 59 | if (!mSlots[ct].get()) |
| 60 | continue; |
| 61 | void *ptr = mSlots[ct]->getPtr(); |
| 62 | void **dest = ((void ***)mEnviroment.mFieldAddress)[ct]; |
| 63 | //LOGE("setupScript %i %p = %p %p %i", ct, dest, ptr, mSlots[ct]->getType(), mSlots[ct]->getType()->getDimX()); |
| 64 | |
| 65 | //const uint32_t *p32 = (const uint32_t *)ptr; |
| 66 | //for (uint32_t ct2=0; ct2 < mSlots[ct]->getType()->getDimX(); ct2++) { |
| 67 | //LOGE(" %i = 0x%08x ", ct2, p32[ct2]); |
| 68 | //} |
| 69 | |
| 70 | if (dest) { |
| 71 | *dest = ptr; |
| 72 | } else { |
| 73 | LOGE("ScriptC::setupScript, NULL var binding address."); |
Jason Sams | ada7f27 | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
Jason Sams | ce92d4b | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 78 | const Allocation *ScriptC::ptrToAllocation(const void *ptr) const |
| 79 | { |
| 80 | if (!ptr) { |
| 81 | return NULL; |
| 82 | } |
| 83 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
| 84 | if (!mSlots[ct].get()) |
| 85 | continue; |
| 86 | if (mSlots[ct]->getPtr() == ptr) { |
| 87 | return mSlots[ct].get(); |
| 88 | } |
| 89 | } |
| 90 | LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr); |
| 91 | return NULL; |
| 92 | } |
| 93 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 94 | Script * ScriptC::setTLS(Script *sc) |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 95 | { |
| 96 | Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *) |
| 97 | pthread_getspecific(Context::gThreadTLSKey); |
| 98 | rsAssert(tls); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 99 | Script *old = tls->mScript; |
| 100 | tls->mScript = sc; |
| 101 | return old; |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 104 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 105 | void ScriptC::setupGLState(Context *rsc) |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 106 | { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 107 | if (mEnviroment.mFragmentStore.get()) { |
| 108 | rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); |
| 109 | } |
| 110 | if (mEnviroment.mFragment.get()) { |
| 111 | rsc->setFragment(mEnviroment.mFragment.get()); |
| 112 | } |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 113 | if (mEnviroment.mVertex.get()) { |
| 114 | rsc->setVertex(mEnviroment.mVertex.get()); |
| 115 | } |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 116 | if (mEnviroment.mRaster.get()) { |
| 117 | rsc->setRaster(mEnviroment.mRaster.get()); |
| 118 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 119 | } |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 120 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 121 | uint32_t ScriptC::run(Context *rsc) |
| 122 | { |
| 123 | if (mProgram.mRoot == NULL) { |
| 124 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); |
| 125 | return 0; |
Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 126 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 127 | |
| 128 | setupScript(rsc); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 129 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 130 | uint32_t ret = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 131 | Script * oldTLS = setTLS(this); |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 132 | //LOGE("ScriptC::run %p", mProgram.mRoot); |
| 133 | ret = mProgram.mRoot(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 134 | setTLS(oldTLS); |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 135 | //LOGE("ScriptC::run ret %i", ret); |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 136 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 139 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 140 | void ScriptC::runForEach(Context *rsc, |
| 141 | const Allocation * ain, |
| 142 | Allocation * aout, |
| 143 | const void * usr, |
| 144 | const RsScriptCall *sc) |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 145 | { |
| 146 | uint32_t dimX = ain->getType()->getDimX(); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 147 | uint32_t dimY = ain->getType()->getDimY(); |
| 148 | uint32_t dimZ = ain->getType()->getDimZ(); |
| 149 | uint32_t dimA = 0;//ain->getType()->getDimArray(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 150 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 151 | uint32_t xStart = 0; |
| 152 | uint32_t xEnd = 0; |
| 153 | uint32_t yStart = 0; |
| 154 | uint32_t yEnd = 0; |
| 155 | uint32_t zStart = 0; |
| 156 | uint32_t zEnd = 0; |
| 157 | uint32_t arrayStart = 0; |
| 158 | uint32_t arrayEnd = 0; |
| 159 | |
| 160 | if (!sc || (sc->xEnd == 0)) { |
| 161 | xStart = 0; |
| 162 | xEnd = ain->getType()->getDimX(); |
| 163 | } else { |
| 164 | rsAssert(xStart < dimX); |
| 165 | rsAssert(xEnd <= dimX); |
| 166 | rsAssert(sc->xStart < sc->xEnd); |
| 167 | xStart = rsMin(dimX, sc->xStart); |
| 168 | xEnd = rsMin(dimX, sc->xEnd); |
| 169 | if (xStart >= xEnd) return; |
| 170 | } |
| 171 | |
| 172 | if (!sc || (sc->yEnd == 0)) { |
| 173 | yStart = 0; |
| 174 | yEnd = ain->getType()->getDimY(); |
| 175 | } else { |
| 176 | rsAssert(yStart < dimY); |
| 177 | rsAssert(yEnd <= dimY); |
| 178 | rsAssert(sc->yStart < sc->yEnd); |
| 179 | yStart = rsMin(dimY, sc->yStart); |
| 180 | yEnd = rsMin(dimY, sc->yEnd); |
| 181 | if (yStart >= yEnd) return; |
| 182 | } |
| 183 | |
| 184 | xEnd = rsMax((uint32_t)1, xEnd); |
| 185 | yEnd = rsMax((uint32_t)1, yEnd); |
| 186 | zEnd = rsMax((uint32_t)1, zEnd); |
| 187 | arrayEnd = rsMax((uint32_t)1, arrayEnd); |
| 188 | |
| 189 | rsAssert(ain->getType()->getDimZ() == 0); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 190 | |
| 191 | setupScript(rsc); |
| 192 | Script * oldTLS = setTLS(this); |
| 193 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 194 | typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t); |
| 195 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 196 | const uint8_t *ptrIn = (const uint8_t *)ain->getPtr(); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 197 | uint32_t eStrideIn = ain->getType()->getElementSizeBytes(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 198 | |
| 199 | uint8_t *ptrOut = NULL; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 200 | uint32_t eStrideOut = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 201 | if (aout) { |
| 202 | ptrOut = (uint8_t *)aout->getPtr(); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 203 | eStrideOut = aout->getType()->getElementSizeBytes(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 206 | for (uint32_t ar = arrayStart; ar < arrayEnd; ar++) { |
| 207 | for (uint32_t z = zStart; z < zEnd; z++) { |
| 208 | for (uint32_t y = yStart; y < yEnd; y++) { |
| 209 | uint32_t offset = dimX * dimY * dimZ * ar + |
| 210 | dimX * dimY * z + |
| 211 | dimX * y; |
| 212 | uint8_t *xPtrOut = ptrOut + (eStrideOut * offset); |
| 213 | const uint8_t *xPtrIn = ptrIn + (eStrideIn * offset); |
| 214 | |
| 215 | for (uint32_t x = xStart; x < xEnd; x++) { |
| 216 | ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar); |
| 217 | xPtrIn += eStrideIn; |
| 218 | xPtrOut += eStrideOut; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | setTLS(oldTLS); |
| 226 | } |
| 227 | |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 228 | void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) |
| 229 | { |
| 230 | //LOGE("rsi_ScriptInvoke %i", slot); |
| 231 | if ((slot >= mEnviroment.mInvokeFunctionCount) || |
| 232 | (mEnviroment.mInvokeFunctions[slot] == NULL)) { |
| 233 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); |
| 234 | return; |
| 235 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 236 | setupScript(rsc); |
| 237 | Script * oldTLS = setTLS(this); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 238 | |
Jason Sams | 2a63bf6 | 2010-06-08 15:40:48 -0700 | [diff] [blame] | 239 | ((void (*)(const void *, uint32_t)) |
| 240 | mEnviroment.mInvokeFunctions[slot])(data, len); |
| 241 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 242 | setTLS(oldTLS); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 245 | ScriptCState::ScriptCState() |
| 246 | { |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 247 | mScript = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 248 | clear(); |
| 249 | } |
| 250 | |
| 251 | ScriptCState::~ScriptCState() |
| 252 | { |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 253 | delete mScript; |
| 254 | mScript = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | void ScriptCState::clear() |
| 258 | { |
Jason Sams | 8b2c065 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 259 | for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
| 260 | mConstantBufferTypes[ct].clear(); |
Jason Sams | 90b36a8 | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 261 | mSlotWritable[ct] = false; |
Jason Sams | 8b2c065 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 262 | } |
Jason Sams | efb8de1 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 263 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 264 | delete mScript; |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 265 | mScript = new ScriptC(NULL); |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 268 | static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name) |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 269 | { |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 270 | const ScriptCState::SymbolTable_t *sym; |
| 271 | sym = ScriptCState::lookupSymbol(name); |
| 272 | if (sym) { |
| 273 | return sym->mPtr; |
| 274 | } |
| 275 | sym = ScriptCState::lookupSymbolCL(name); |
| 276 | if (sym) { |
| 277 | return sym->mPtr; |
| 278 | } |
| 279 | sym = ScriptCState::lookupSymbolGL(name); |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 280 | if (sym) { |
| 281 | return sym->mPtr; |
| 282 | } |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 283 | LOGE("ScriptC sym lookup failed for %s", name); |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 284 | return NULL; |
| 285 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 286 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 287 | void ScriptCState::runCompiler(Context *rsc, ScriptC *s) |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 288 | { |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 289 | LOGV("ScriptCState::runCompiler "); |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 290 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 291 | s->mBccScript = bccCreateScript(); |
| 292 | bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength); |
| 293 | bccRegisterSymbolCallback(s->mBccScript, symbolLookup, NULL); |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 294 | bccCompileScript(s->mBccScript); |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 295 | bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot); |
| 296 | bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame^] | 297 | LOGV("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit); |
Jason Sams | f168504 | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 298 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 299 | if (s->mProgram.mInit) { |
| 300 | s->mProgram.mInit(); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jason Sams | 8c88090 | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 303 | bccGetExportFuncs(s->mBccScript, (BCCsizei*) &s->mEnviroment.mInvokeFunctionCount, 0, NULL); |
| 304 | if(s->mEnviroment.mInvokeFunctionCount <= 0) |
| 305 | s->mEnviroment.mInvokeFunctions = NULL; |
| 306 | else { |
| 307 | s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t)); |
| 308 | bccGetExportFuncs(s->mBccScript, NULL, s->mEnviroment.mInvokeFunctionCount, (BCCvoid **) s->mEnviroment.mInvokeFunctions); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 311 | s->mEnviroment.mFieldAddress = (void **)calloc(100, sizeof(void *)); |
| 312 | bccGetExportVars(s->mBccScript, (BCCsizei *)&s->mEnviroment.mFieldCount, |
| 313 | 100, s->mEnviroment.mFieldAddress); |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 314 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 315 | s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 316 | s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 317 | s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 318 | s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 319 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 320 | if (s->mProgram.mRoot) { |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 321 | const static int pragmaMax = 16; |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 322 | BCCsizei pragmaCount; |
| 323 | BCCchar * str[pragmaMax]; |
| 324 | bccGetPragmas(s->mBccScript, &pragmaCount, pragmaMax, &str[0]); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 325 | |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 326 | for (int ct=0; ct < pragmaCount; ct+=2) { |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 327 | //LOGE("pragme %s %s", str[ct], str[ct+1]); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 328 | if (!strcmp(str[ct], "version")) { |
| 329 | continue; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 332 | if (!strcmp(str[ct], "stateVertex")) { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 333 | if (!strcmp(str[ct+1], "default")) { |
| 334 | continue; |
| 335 | } |
| 336 | if (!strcmp(str[ct+1], "parent")) { |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 337 | s->mEnviroment.mVertex.clear(); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 338 | continue; |
| 339 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 340 | LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); |
| 341 | } |
| 342 | |
| 343 | if (!strcmp(str[ct], "stateRaster")) { |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 344 | if (!strcmp(str[ct+1], "default")) { |
| 345 | continue; |
| 346 | } |
| 347 | if (!strcmp(str[ct+1], "parent")) { |
| 348 | s->mEnviroment.mRaster.clear(); |
| 349 | continue; |
| 350 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 351 | LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); |
| 352 | } |
| 353 | |
| 354 | if (!strcmp(str[ct], "stateFragment")) { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 355 | if (!strcmp(str[ct+1], "default")) { |
| 356 | continue; |
| 357 | } |
| 358 | if (!strcmp(str[ct+1], "parent")) { |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 359 | s->mEnviroment.mFragment.clear(); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 360 | continue; |
| 361 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 362 | LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); |
| 363 | } |
| 364 | |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 365 | if (!strcmp(str[ct], "stateStore")) { |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 366 | if (!strcmp(str[ct+1], "default")) { |
| 367 | continue; |
| 368 | } |
| 369 | if (!strcmp(str[ct+1], "parent")) { |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 370 | s->mEnviroment.mFragmentStore.clear(); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 371 | continue; |
| 372 | } |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 373 | LOGE("Unreconized value %s passed to stateStore", str[ct+1]); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | } |
| 377 | |
Jason Sams | d34b725 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 378 | |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 379 | } else { |
| 380 | // Deal with an error. |
| 381 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Jason Sams | 8b2c065 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 384 | |
Joe Onorato | 57b79ce | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 385 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 386 | namespace android { |
| 387 | namespace renderscript { |
| 388 | |
| 389 | void rsi_ScriptCBegin(Context * rsc) |
| 390 | { |
| 391 | ScriptCState *ss = &rsc->mScriptC; |
| 392 | ss->clear(); |
| 393 | } |
| 394 | |
Jason Sams | efb8de1 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 395 | void rsi_ScriptCSetScript(Context * rsc, void *vp) |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 396 | { |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 397 | rsAssert(0); |
| 398 | //ScriptCState *ss = &rsc->mScriptC; |
| 399 | //ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 402 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) |
| 403 | { |
| 404 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | e402ed3 | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 405 | |
| 406 | char *t = (char *)malloc(len + 1); |
| 407 | memcpy(t, text, len); |
| 408 | t[len] = 0; |
| 409 | ss->mScript->mEnviroment.mScriptText = t; |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 410 | ss->mScript->mEnviroment.mScriptTextLength = len; |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 414 | RsScript rsi_ScriptCCreate(Context * rsc) |
| 415 | { |
| 416 | ScriptCState *ss = &rsc->mScriptC; |
| 417 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 418 | ScriptC *s = ss->mScript; |
| 419 | ss->mScript = NULL; |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 420 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 421 | ss->runCompiler(rsc, s); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 422 | s->incUserRef(); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 423 | s->setContext(rsc); |
Jason Sams | fa51719 | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 424 | for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
| 425 | s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get()); |
Jason Sams | 90b36a8 | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 426 | s->mSlotWritable[ct] = ss->mSlotWritable[ct]; |
Jason Sams | fa51719 | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 427 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 428 | |
Jason Sams | fa51719 | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 429 | ss->clear(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 430 | return s; |
| 431 | } |
| 432 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
| 436 | |