blob: a140e224a3f946a381b71b21aaba405b8abb2c8f [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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 Samsbe36bf32010-05-11 14:03:58 -070020#include "../../../external/llvm/libbcc/include/bcc/bcc.h"
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070021#include "utils/Timers.h"
Jack Palevich1ef8b802009-05-28 15:53:04 -070022
Jason Sams1aa5a4e2009-06-22 17:15:15 -070023#include <GLES/gl.h>
24#include <GLES/glext.h>
25
Jason Sams326e0dd2009-05-22 14:03:28 -070026using namespace android;
27using namespace android::renderscript;
28
Jason Samse5769102009-06-19 16:03:18 -070029#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 Sams326e0dd2009-05-22 14:03:28 -070034
Jason Samse514b452009-09-25 14:51:22 -070035ScriptC::ScriptC(Context *rsc) : Script(rsc)
Jason Sams326e0dd2009-05-22 14:03:28 -070036{
Jason Samsf2649a92009-09-25 16:37:33 -070037 mAllocFile = __FILE__;
38 mAllocLine = __LINE__;
Jason Samsbe36bf32010-05-11 14:03:58 -070039 mBccScript = NULL;
Jason Samsefb8de12009-06-08 15:20:31 -070040 memset(&mProgram, 0, sizeof(mProgram));
Jason Sams326e0dd2009-05-22 14:03:28 -070041}
42
43ScriptC::~ScriptC()
44{
Jason Samsbe36bf32010-05-11 14:03:58 -070045 if (mBccScript) {
46 bccDeleteScript(mBccScript);
Jack Palevich1ef8b802009-05-28 15:53:04 -070047 }
Jason Samse402ed32009-11-03 11:25:42 -080048 free(mEnviroment.mScriptText);
49 mEnviroment.mScriptText = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -070050}
51
Jason Samsc61346b2010-05-28 18:23:22 -070052void ScriptC::setupScript(Context *rsc)
Jason Samsada7f272009-09-24 14:55:38 -070053{
Jason Samsc61346b2010-05-28 18:23:22 -070054 setupGLState(rsc);
55 mEnviroment.mStartTimeMillis
56 = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
57
Jason Samsbe36bf32010-05-11 14:03:58 -070058 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 Samsada7f272009-09-24 14:55:38 -070074 }
75 }
76}
77
Jason Samsce92d4b2010-05-17 14:55:34 -070078const 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 Samsc61346b2010-05-28 18:23:22 -070094Script * ScriptC::setTLS(Script *sc)
Jason Sams22fa3712010-05-19 17:22:57 -070095{
96 Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *)
97 pthread_getspecific(Context::gThreadTLSKey);
98 rsAssert(tls);
Jason Samsc61346b2010-05-28 18:23:22 -070099 Script *old = tls->mScript;
100 tls->mScript = sc;
101 return old;
Jason Sams22fa3712010-05-19 17:22:57 -0700102}
103
Jason Sams326e0dd2009-05-22 14:03:28 -0700104
Jason Samsc61346b2010-05-28 18:23:22 -0700105void ScriptC::setupGLState(Context *rsc)
Jason Sams326e0dd2009-05-22 14:03:28 -0700106{
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700107 if (mEnviroment.mFragmentStore.get()) {
108 rsc->setFragmentStore(mEnviroment.mFragmentStore.get());
109 }
110 if (mEnviroment.mFragment.get()) {
111 rsc->setFragment(mEnviroment.mFragment.get());
112 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700113 if (mEnviroment.mVertex.get()) {
114 rsc->setVertex(mEnviroment.mVertex.get());
115 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700116 if (mEnviroment.mRaster.get()) {
117 rsc->setRaster(mEnviroment.mRaster.get());
118 }
Jason Samsc61346b2010-05-28 18:23:22 -0700119}
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700120
Jason Samsc61346b2010-05-28 18:23:22 -0700121uint32_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 Onorato9c4e4ca2009-08-09 11:39:02 -0700126 }
Jason Samsc61346b2010-05-28 18:23:22 -0700127
128 setupScript(rsc);
Jason Sams1d54f102009-09-03 15:43:13 -0700129
Jason Sams2dca84d2009-12-09 11:05:45 -0800130 uint32_t ret = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700131 Script * oldTLS = setTLS(this);
Jason Samsbe36bf32010-05-11 14:03:58 -0700132 //LOGE("ScriptC::run %p", mProgram.mRoot);
133 ret = mProgram.mRoot();
Jason Samsc61346b2010-05-28 18:23:22 -0700134 setTLS(oldTLS);
Jason Samsbe36bf32010-05-11 14:03:58 -0700135 //LOGE("ScriptC::run ret %i", ret);
Jason Samse45ac6e2009-07-20 14:31:06 -0700136 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700137}
138
Jason Samsc61346b2010-05-28 18:23:22 -0700139
Jason Sams7bf29dd2010-07-19 15:38:19 -0700140typedef struct {
141 Context *rsc;
142 ScriptC *script;
143 const Allocation * ain;
144 Allocation * aout;
145 const void * usr;
146
147 uint32_t mSliceSize;
148 volatile int mSliceNum;
149
150 const uint8_t *ptrIn;
151 uint32_t eStrideIn;
152 uint8_t *ptrOut;
153 uint32_t eStrideOut;
154
155 uint32_t xStart;
156 uint32_t xEnd;
157 uint32_t yStart;
158 uint32_t yEnd;
159 uint32_t zStart;
160 uint32_t zEnd;
161 uint32_t arrayStart;
162 uint32_t arrayEnd;
163
164 uint32_t dimX;
165 uint32_t dimY;
166 uint32_t dimZ;
167 uint32_t dimArray;
168} MTLaunchStruct;
169typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t);
170
171static void wc_xy(void *usr, uint32_t idx)
172{
173 MTLaunchStruct *mtls = (MTLaunchStruct *)usr;
Jason Sams7bf29dd2010-07-19 15:38:19 -0700174
175 while (1) {
176 uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
177 uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize;
178 uint32_t yEnd = yStart + mtls->mSliceSize;
179 yEnd = rsMin(yEnd, mtls->yEnd);
180 if (yEnd <= yStart) {
181 return;
182 }
183
184 //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd);
185
186 for (uint32_t y = yStart; y < yEnd; y++) {
187 uint32_t offset = mtls->dimX * y;
188 uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset);
189 const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset);
190
191 for (uint32_t x = mtls->xStart; x < mtls->xEnd; x++) {
192 ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0);
193 xPtrIn += mtls->eStrideIn;
194 xPtrOut += mtls->eStrideOut;
195 }
196 }
197 }
198
199}
200
Jason Samsace3e012010-07-15 17:11:13 -0700201void ScriptC::runForEach(Context *rsc,
202 const Allocation * ain,
203 Allocation * aout,
204 const void * usr,
205 const RsScriptCall *sc)
Jason Samsc61346b2010-05-28 18:23:22 -0700206{
Jason Sams7bf29dd2010-07-19 15:38:19 -0700207 MTLaunchStruct mtls;
208 memset(&mtls, 0, sizeof(mtls));
Jason Samsc61346b2010-05-28 18:23:22 -0700209
Jason Sams7bf29dd2010-07-19 15:38:19 -0700210 if (ain) {
211 mtls.dimX = ain->getType()->getDimX();
212 mtls.dimY = ain->getType()->getDimY();
213 mtls.dimZ = ain->getType()->getDimZ();
214 //mtls.dimArray = ain->getType()->getDimArray();
215 } else if (aout) {
216 mtls.dimX = aout->getType()->getDimX();
217 mtls.dimY = aout->getType()->getDimY();
218 mtls.dimZ = aout->getType()->getDimZ();
219 //mtls.dimArray = aout->getType()->getDimArray();
220 } else {
221 rsc->setError(RS_ERROR_BAD_SCRIPT, "rsForEach called with null allocations");
222 return;
223 }
Jason Samsace3e012010-07-15 17:11:13 -0700224
225 if (!sc || (sc->xEnd == 0)) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700226 mtls.xEnd = mtls.dimX;
Jason Samsace3e012010-07-15 17:11:13 -0700227 } else {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700228 rsAssert(sc->xStart < mtls.dimX);
229 rsAssert(sc->xEnd <= mtls.dimX);
Jason Samsace3e012010-07-15 17:11:13 -0700230 rsAssert(sc->xStart < sc->xEnd);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700231 mtls.xStart = rsMin(mtls.dimX, sc->xStart);
232 mtls.xEnd = rsMin(mtls.dimX, sc->xEnd);
233 if (mtls.xStart >= mtls.xEnd) return;
Jason Samsace3e012010-07-15 17:11:13 -0700234 }
235
236 if (!sc || (sc->yEnd == 0)) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700237 mtls.yEnd = mtls.dimY;
Jason Samsace3e012010-07-15 17:11:13 -0700238 } else {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700239 rsAssert(sc->yStart < mtls.dimY);
240 rsAssert(sc->yEnd <= mtls.dimY);
Jason Samsace3e012010-07-15 17:11:13 -0700241 rsAssert(sc->yStart < sc->yEnd);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700242 mtls.yStart = rsMin(mtls.dimY, sc->yStart);
243 mtls.yEnd = rsMin(mtls.dimY, sc->yEnd);
244 if (mtls.yStart >= mtls.yEnd) return;
Jason Samsace3e012010-07-15 17:11:13 -0700245 }
246
Jason Sams7bf29dd2010-07-19 15:38:19 -0700247 mtls.xEnd = rsMax((uint32_t)1, mtls.xEnd);
248 mtls.yEnd = rsMax((uint32_t)1, mtls.yEnd);
249 mtls.zEnd = rsMax((uint32_t)1, mtls.zEnd);
250 mtls.arrayEnd = rsMax((uint32_t)1, mtls.arrayEnd);
Jason Samsace3e012010-07-15 17:11:13 -0700251
252 rsAssert(ain->getType()->getDimZ() == 0);
Jason Samsc61346b2010-05-28 18:23:22 -0700253
254 setupScript(rsc);
255 Script * oldTLS = setTLS(this);
256
Jason Samsace3e012010-07-15 17:11:13 -0700257
Jason Sams7bf29dd2010-07-19 15:38:19 -0700258 mtls.rsc = rsc;
259 mtls.ain = ain;
260 mtls.aout = aout;
261 mtls.script = this;
262 mtls.usr = usr;
263 mtls.mSliceSize = 10;
264 mtls.mSliceNum = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700265
Jason Sams7bf29dd2010-07-19 15:38:19 -0700266 mtls.ptrIn = NULL;
267 mtls.eStrideIn = 0;
268 if (ain) {
269 mtls.ptrIn = (const uint8_t *)ain->getPtr();
270 mtls.eStrideIn = ain->getType()->getElementSizeBytes();
Jason Samsc61346b2010-05-28 18:23:22 -0700271 }
272
Jason Sams7bf29dd2010-07-19 15:38:19 -0700273 mtls.ptrOut = NULL;
274 mtls.eStrideOut = 0;
275 if (aout) {
276 mtls.ptrOut = (uint8_t *)aout->getPtr();
277 mtls.eStrideOut = aout->getType()->getElementSizeBytes();
278 }
279
280
Jason Samsdd663fa2010-08-11 13:26:28 -0700281 if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable &&
Jason Sams18133402010-07-20 15:09:00 -0700282 ((mtls.dimY * mtls.dimZ * mtls.dimArray) > 1)) {
283
284 //LOGE("launch 1");
Jason Sams7bf29dd2010-07-19 15:38:19 -0700285 rsc->launchThreads(wc_xy, &mtls);
Jason Sams18133402010-07-20 15:09:00 -0700286 //LOGE("launch 2");
287 } else {
288 for (uint32_t ar = mtls.arrayStart; ar < mtls.arrayEnd; ar++) {
289 for (uint32_t z = mtls.zStart; z < mtls.zEnd; z++) {
290 for (uint32_t y = mtls.yStart; y < mtls.yEnd; y++) {
291 uint32_t offset = mtls.dimX * mtls.dimY * mtls.dimZ * ar +
292 mtls.dimX * mtls.dimY * z +
293 mtls.dimX * y;
294 uint8_t *xPtrOut = mtls.ptrOut + (mtls.eStrideOut * offset);
295 const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700296
Jason Sams18133402010-07-20 15:09:00 -0700297 for (uint32_t x = mtls.xStart; x < mtls.xEnd; x++) {
298 ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar);
299 xPtrIn += mtls.eStrideIn;
300 xPtrOut += mtls.eStrideOut;
301 }
Jason Samsace3e012010-07-15 17:11:13 -0700302 }
303 }
304 }
Jason Samsc61346b2010-05-28 18:23:22 -0700305 }
Jason Sams18133402010-07-20 15:09:00 -0700306
Jason Samsc61346b2010-05-28 18:23:22 -0700307 setTLS(oldTLS);
308}
309
Jason Sams22fa3712010-05-19 17:22:57 -0700310void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len)
311{
312 //LOGE("rsi_ScriptInvoke %i", slot);
313 if ((slot >= mEnviroment.mInvokeFunctionCount) ||
314 (mEnviroment.mInvokeFunctions[slot] == NULL)) {
315 rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
316 return;
317 }
Jason Samsc61346b2010-05-28 18:23:22 -0700318 setupScript(rsc);
319 Script * oldTLS = setTLS(this);
Jason Sams22fa3712010-05-19 17:22:57 -0700320
Jason Sams2a63bf62010-06-08 15:40:48 -0700321 ((void (*)(const void *, uint32_t))
322 mEnviroment.mInvokeFunctions[slot])(data, len);
323
Jason Samsc61346b2010-05-28 18:23:22 -0700324 setTLS(oldTLS);
Jason Sams22fa3712010-05-19 17:22:57 -0700325}
326
Jason Sams326e0dd2009-05-22 14:03:28 -0700327ScriptCState::ScriptCState()
328{
Jason Sams8c6bc692009-09-16 15:04:38 -0700329 mScript = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -0700330 clear();
331}
332
333ScriptCState::~ScriptCState()
334{
Jason Sams8c6bc692009-09-16 15:04:38 -0700335 delete mScript;
336 mScript = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -0700337}
338
339void ScriptCState::clear()
340{
Jason Sams8b2c0652009-08-12 17:54:11 -0700341 for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
342 mConstantBufferTypes[ct].clear();
Jason Sams90b36a82009-08-17 13:56:09 -0700343 mSlotWritable[ct] = false;
Jason Sams8b2c0652009-08-12 17:54:11 -0700344 }
Jason Samsefb8de12009-06-08 15:20:31 -0700345
Jason Sams8c6bc692009-09-16 15:04:38 -0700346 delete mScript;
Jason Samse514b452009-09-25 14:51:22 -0700347 mScript = new ScriptC(NULL);
Jason Sams1f526332009-06-05 17:35:09 -0700348}
349
Jason Samsbe36bf32010-05-11 14:03:58 -0700350static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name)
Jason Sams29df66f2009-07-16 15:08:06 -0700351{
Jason Samsaeb094b2010-05-18 13:35:45 -0700352 const ScriptCState::SymbolTable_t *sym;
Jason Samsdd663fa2010-08-11 13:26:28 -0700353 ScriptC *s = (ScriptC *)pContext;
Jason Samsaeb094b2010-05-18 13:35:45 -0700354 sym = ScriptCState::lookupSymbol(name);
355 if (sym) {
356 return sym->mPtr;
357 }
Jason Samsdd663fa2010-08-11 13:26:28 -0700358 s->mEnviroment.mIsThreadable = false;
Jason Samsaeb094b2010-05-18 13:35:45 -0700359 sym = ScriptCState::lookupSymbolCL(name);
360 if (sym) {
361 return sym->mPtr;
362 }
363 sym = ScriptCState::lookupSymbolGL(name);
Jason Sams29df66f2009-07-16 15:08:06 -0700364 if (sym) {
365 return sym->mPtr;
366 }
Jason Sams29df66f2009-07-16 15:08:06 -0700367 LOGE("ScriptC sym lookup failed for %s", name);
Jason Sams29df66f2009-07-16 15:08:06 -0700368 return NULL;
369}
Jason Samsa4a54e42009-06-10 18:39:40 -0700370
Jason Sams8c6bc692009-09-16 15:04:38 -0700371void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
Jason Sams1f526332009-06-05 17:35:09 -0700372{
Jason Samsace3e012010-07-15 17:11:13 -0700373 LOGV("ScriptCState::runCompiler ");
Jason Sams1f526332009-06-05 17:35:09 -0700374
Jason Samsbe36bf32010-05-11 14:03:58 -0700375 s->mBccScript = bccCreateScript();
Jason Samsdd663fa2010-08-11 13:26:28 -0700376 s->mEnviroment.mIsThreadable = true;
Jason Samsbe36bf32010-05-11 14:03:58 -0700377 bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength);
Jason Samsdd663fa2010-08-11 13:26:28 -0700378 bccRegisterSymbolCallback(s->mBccScript, symbolLookup, s);
Jason Samsbe36bf32010-05-11 14:03:58 -0700379 bccCompileScript(s->mBccScript);
Jason Samsbe36bf32010-05-11 14:03:58 -0700380 bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot);
381 bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit);
Jason Samsace3e012010-07-15 17:11:13 -0700382 LOGV("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit);
Jason Samsf1685042009-07-16 17:47:40 -0700383
Jason Sams8c6bc692009-09-16 15:04:38 -0700384 if (s->mProgram.mInit) {
385 s->mProgram.mInit();
Jason Sams1d54f102009-09-03 15:43:13 -0700386 }
387
Jason Sams8c880902010-06-15 12:15:57 -0700388 bccGetExportFuncs(s->mBccScript, (BCCsizei*) &s->mEnviroment.mInvokeFunctionCount, 0, NULL);
389 if(s->mEnviroment.mInvokeFunctionCount <= 0)
390 s->mEnviroment.mInvokeFunctions = NULL;
391 else {
392 s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t));
393 bccGetExportFuncs(s->mBccScript, NULL, s->mEnviroment.mInvokeFunctionCount, (BCCvoid **) s->mEnviroment.mInvokeFunctions);
Jason Sams1d54f102009-09-03 15:43:13 -0700394 }
395
Shih-wei Liaoa226b162010-07-20 16:43:25 -0700396 bccGetExportVars(s->mBccScript, (BCCsizei*) &s->mEnviroment.mFieldCount, 0, NULL);
397 if(s->mEnviroment.mFieldCount <= 0)
398 s->mEnviroment.mFieldAddress = NULL;
399 else {
400 s->mEnviroment.mFieldAddress = (void **) calloc(s->mEnviroment.mFieldCount, sizeof(void *));
401 bccGetExportVars(s->mBccScript, NULL, s->mEnviroment.mFieldCount, (BCCvoid **) s->mEnviroment.mFieldAddress);
402 }
Jason Sams18133402010-07-20 15:09:00 -0700403 //for (int ct2=0; ct2 < s->mEnviroment.mFieldCount; ct2++ ) {
404 //LOGE("Script field %i = %p", ct2, s->mEnviroment.mFieldAddress[ct2]);
405 //}
Jason Samsa4a54e42009-06-10 18:39:40 -0700406
Jason Sams8c6bc692009-09-16 15:04:38 -0700407 s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
408 s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
Jason Samsccc010b2010-05-13 18:30:11 -0700409 s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
Jason Samsb681c8a2009-09-28 18:12:56 -0700410 s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams8c6bc692009-09-16 15:04:38 -0700411
Jason Samsbe36bf32010-05-11 14:03:58 -0700412 if (s->mProgram.mRoot) {
Jason Sams10308932009-06-09 12:15:30 -0700413 const static int pragmaMax = 16;
Jason Samsbe36bf32010-05-11 14:03:58 -0700414 BCCsizei pragmaCount;
415 BCCchar * str[pragmaMax];
416 bccGetPragmas(s->mBccScript, &pragmaCount, pragmaMax, &str[0]);
Jason Sams10308932009-06-09 12:15:30 -0700417
Jason Sams10308932009-06-09 12:15:30 -0700418 for (int ct=0; ct < pragmaCount; ct+=2) {
Jason Samsaeb094b2010-05-18 13:35:45 -0700419 //LOGE("pragme %s %s", str[ct], str[ct+1]);
Jason Sams10308932009-06-09 12:15:30 -0700420 if (!strcmp(str[ct], "version")) {
421 continue;
Jason Sams10308932009-06-09 12:15:30 -0700422 }
423
Jason Sams10308932009-06-09 12:15:30 -0700424 if (!strcmp(str[ct], "stateVertex")) {
Jason Sams8ce125b2009-06-17 16:52:59 -0700425 if (!strcmp(str[ct+1], "default")) {
426 continue;
427 }
428 if (!strcmp(str[ct+1], "parent")) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700429 s->mEnviroment.mVertex.clear();
Jason Sams8ce125b2009-06-17 16:52:59 -0700430 continue;
431 }
Jason Sams10308932009-06-09 12:15:30 -0700432 LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
433 }
434
435 if (!strcmp(str[ct], "stateRaster")) {
Jason Samsb681c8a2009-09-28 18:12:56 -0700436 if (!strcmp(str[ct+1], "default")) {
437 continue;
438 }
439 if (!strcmp(str[ct+1], "parent")) {
440 s->mEnviroment.mRaster.clear();
441 continue;
442 }
Jason Sams10308932009-06-09 12:15:30 -0700443 LOGE("Unreconized value %s passed to stateRaster", str[ct+1]);
444 }
445
446 if (!strcmp(str[ct], "stateFragment")) {
Jason Sams8ce125b2009-06-17 16:52:59 -0700447 if (!strcmp(str[ct+1], "default")) {
448 continue;
449 }
450 if (!strcmp(str[ct+1], "parent")) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700451 s->mEnviroment.mFragment.clear();
Jason Sams8ce125b2009-06-17 16:52:59 -0700452 continue;
453 }
Jason Sams10308932009-06-09 12:15:30 -0700454 LOGE("Unreconized value %s passed to stateFragment", str[ct+1]);
455 }
456
Jason Samsb681c8a2009-09-28 18:12:56 -0700457 if (!strcmp(str[ct], "stateStore")) {
Jason Sams8ce125b2009-06-17 16:52:59 -0700458 if (!strcmp(str[ct+1], "default")) {
459 continue;
460 }
461 if (!strcmp(str[ct+1], "parent")) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700462 s->mEnviroment.mFragmentStore.clear();
Jason Sams8ce125b2009-06-17 16:52:59 -0700463 continue;
464 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700465 LOGE("Unreconized value %s passed to stateStore", str[ct+1]);
Jason Sams10308932009-06-09 12:15:30 -0700466 }
467
468 }
469
Jason Samsd34b7252009-08-04 16:58:20 -0700470
Jason Sams10308932009-06-09 12:15:30 -0700471 } else {
472 // Deal with an error.
473 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700474}
475
Jason Sams8b2c0652009-08-12 17:54:11 -0700476
Joe Onorato57b79ce2009-08-09 22:57:44 -0700477
Jason Sams326e0dd2009-05-22 14:03:28 -0700478namespace android {
479namespace renderscript {
480
481void rsi_ScriptCBegin(Context * rsc)
482{
483 ScriptCState *ss = &rsc->mScriptC;
484 ss->clear();
485}
486
Jason Samsefb8de12009-06-08 15:20:31 -0700487void rsi_ScriptCSetScript(Context * rsc, void *vp)
Jason Sams326e0dd2009-05-22 14:03:28 -0700488{
Jason Sams8c6bc692009-09-16 15:04:38 -0700489 rsAssert(0);
490 //ScriptCState *ss = &rsc->mScriptC;
491 //ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp);
Jason Sams326e0dd2009-05-22 14:03:28 -0700492}
493
Jason Sams1f526332009-06-05 17:35:09 -0700494void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len)
495{
496 ScriptCState *ss = &rsc->mScriptC;
Jason Samse402ed32009-11-03 11:25:42 -0800497
498 char *t = (char *)malloc(len + 1);
499 memcpy(t, text, len);
500 t[len] = 0;
501 ss->mScript->mEnviroment.mScriptText = t;
Jason Sams8c6bc692009-09-16 15:04:38 -0700502 ss->mScript->mEnviroment.mScriptTextLength = len;
Jason Sams1f526332009-06-05 17:35:09 -0700503}
504
505
Jason Sams326e0dd2009-05-22 14:03:28 -0700506RsScript rsi_ScriptCCreate(Context * rsc)
507{
508 ScriptCState *ss = &rsc->mScriptC;
509
Jason Sams8c6bc692009-09-16 15:04:38 -0700510 ScriptC *s = ss->mScript;
511 ss->mScript = NULL;
Jason Sams1f526332009-06-05 17:35:09 -0700512
Jason Sams8c6bc692009-09-16 15:04:38 -0700513 ss->runCompiler(rsc, s);
Jason Sams9397e302009-08-27 20:23:34 -0700514 s->incUserRef();
Jason Samse514b452009-09-25 14:51:22 -0700515 s->setContext(rsc);
Jason Samsfa517192009-08-13 12:59:04 -0700516 for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
517 s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
Jason Sams90b36a82009-08-17 13:56:09 -0700518 s->mSlotWritable[ct] = ss->mSlotWritable[ct];
Jason Samsfa517192009-08-13 12:59:04 -0700519 }
Jason Sams10308932009-06-09 12:15:30 -0700520
Jason Samsfa517192009-08-13 12:59:04 -0700521 ss->clear();
Jason Sams326e0dd2009-05-22 14:03:28 -0700522 return s;
523}
524
Jason Sams326e0dd2009-05-22 14:03:28 -0700525}
526}
527
528