blob: 9693b16e4ac05360fcaee41ba2f7caef56175530 [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;
174 LOGE("usr %p, idx %i", usr, idx);
175
176 while (1) {
177 uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum);
178 uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize;
179 uint32_t yEnd = yStart + mtls->mSliceSize;
180 yEnd = rsMin(yEnd, mtls->yEnd);
181 if (yEnd <= yStart) {
182 return;
183 }
184
185 //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd);
186
187 for (uint32_t y = yStart; y < yEnd; y++) {
188 uint32_t offset = mtls->dimX * y;
189 uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset);
190 const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset);
191
192 for (uint32_t x = mtls->xStart; x < mtls->xEnd; x++) {
193 ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0);
194 xPtrIn += mtls->eStrideIn;
195 xPtrOut += mtls->eStrideOut;
196 }
197 }
198 }
199
200}
201
Jason Samsace3e012010-07-15 17:11:13 -0700202void ScriptC::runForEach(Context *rsc,
203 const Allocation * ain,
204 Allocation * aout,
205 const void * usr,
206 const RsScriptCall *sc)
Jason Samsc61346b2010-05-28 18:23:22 -0700207{
Jason Sams7bf29dd2010-07-19 15:38:19 -0700208 MTLaunchStruct mtls;
209 memset(&mtls, 0, sizeof(mtls));
Jason Samsc61346b2010-05-28 18:23:22 -0700210
Jason Sams7bf29dd2010-07-19 15:38:19 -0700211 if (ain) {
212 mtls.dimX = ain->getType()->getDimX();
213 mtls.dimY = ain->getType()->getDimY();
214 mtls.dimZ = ain->getType()->getDimZ();
215 //mtls.dimArray = ain->getType()->getDimArray();
216 } else if (aout) {
217 mtls.dimX = aout->getType()->getDimX();
218 mtls.dimY = aout->getType()->getDimY();
219 mtls.dimZ = aout->getType()->getDimZ();
220 //mtls.dimArray = aout->getType()->getDimArray();
221 } else {
222 rsc->setError(RS_ERROR_BAD_SCRIPT, "rsForEach called with null allocations");
223 return;
224 }
Jason Samsace3e012010-07-15 17:11:13 -0700225
226 if (!sc || (sc->xEnd == 0)) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700227 mtls.xEnd = mtls.dimX;
Jason Samsace3e012010-07-15 17:11:13 -0700228 } else {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700229 rsAssert(sc->xStart < mtls.dimX);
230 rsAssert(sc->xEnd <= mtls.dimX);
Jason Samsace3e012010-07-15 17:11:13 -0700231 rsAssert(sc->xStart < sc->xEnd);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700232 mtls.xStart = rsMin(mtls.dimX, sc->xStart);
233 mtls.xEnd = rsMin(mtls.dimX, sc->xEnd);
234 if (mtls.xStart >= mtls.xEnd) return;
Jason Samsace3e012010-07-15 17:11:13 -0700235 }
236
237 if (!sc || (sc->yEnd == 0)) {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700238 mtls.yEnd = mtls.dimY;
Jason Samsace3e012010-07-15 17:11:13 -0700239 } else {
Jason Sams7bf29dd2010-07-19 15:38:19 -0700240 rsAssert(sc->yStart < mtls.dimY);
241 rsAssert(sc->yEnd <= mtls.dimY);
Jason Samsace3e012010-07-15 17:11:13 -0700242 rsAssert(sc->yStart < sc->yEnd);
Jason Sams7bf29dd2010-07-19 15:38:19 -0700243 mtls.yStart = rsMin(mtls.dimY, sc->yStart);
244 mtls.yEnd = rsMin(mtls.dimY, sc->yEnd);
245 if (mtls.yStart >= mtls.yEnd) return;
Jason Samsace3e012010-07-15 17:11:13 -0700246 }
247
Jason Sams7bf29dd2010-07-19 15:38:19 -0700248 mtls.xEnd = rsMax((uint32_t)1, mtls.xEnd);
249 mtls.yEnd = rsMax((uint32_t)1, mtls.yEnd);
250 mtls.zEnd = rsMax((uint32_t)1, mtls.zEnd);
251 mtls.arrayEnd = rsMax((uint32_t)1, mtls.arrayEnd);
Jason Samsace3e012010-07-15 17:11:13 -0700252
253 rsAssert(ain->getType()->getDimZ() == 0);
Jason Samsc61346b2010-05-28 18:23:22 -0700254
255 setupScript(rsc);
256 Script * oldTLS = setTLS(this);
257
Jason Samsace3e012010-07-15 17:11:13 -0700258
Jason Sams7bf29dd2010-07-19 15:38:19 -0700259 mtls.rsc = rsc;
260 mtls.ain = ain;
261 mtls.aout = aout;
262 mtls.script = this;
263 mtls.usr = usr;
264 mtls.mSliceSize = 10;
265 mtls.mSliceNum = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700266
Jason Sams7bf29dd2010-07-19 15:38:19 -0700267 mtls.ptrIn = NULL;
268 mtls.eStrideIn = 0;
269 if (ain) {
270 mtls.ptrIn = (const uint8_t *)ain->getPtr();
271 mtls.eStrideIn = ain->getType()->getElementSizeBytes();
Jason Samsc61346b2010-05-28 18:23:22 -0700272 }
273
Jason Sams7bf29dd2010-07-19 15:38:19 -0700274 mtls.ptrOut = NULL;
275 mtls.eStrideOut = 0;
276 if (aout) {
277 mtls.ptrOut = (uint8_t *)aout->getPtr();
278 mtls.eStrideOut = aout->getType()->getElementSizeBytes();
279 }
280
281
282 {
283 LOGE("launch 1");
284 rsc->launchThreads(wc_xy, &mtls);
285 LOGE("launch 2");
286 }
287
288/*
Jason Samsace3e012010-07-15 17:11:13 -0700289 for (uint32_t ar = arrayStart; ar < arrayEnd; ar++) {
290 for (uint32_t z = zStart; z < zEnd; z++) {
291 for (uint32_t y = yStart; y < yEnd; y++) {
292 uint32_t offset = dimX * dimY * dimZ * ar +
293 dimX * dimY * z +
294 dimX * y;
295 uint8_t *xPtrOut = ptrOut + (eStrideOut * offset);
296 const uint8_t *xPtrIn = ptrIn + (eStrideIn * offset);
297
298 for (uint32_t x = xStart; x < xEnd; x++) {
299 ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar);
300 xPtrIn += eStrideIn;
301 xPtrOut += eStrideOut;
302 }
303 }
304 }
305
Jason Samsc61346b2010-05-28 18:23:22 -0700306 }
Jason Sams7bf29dd2010-07-19 15:38:19 -0700307*/
Jason Samsc61346b2010-05-28 18:23:22 -0700308 setTLS(oldTLS);
309}
310
Jason Sams22fa3712010-05-19 17:22:57 -0700311void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len)
312{
313 //LOGE("rsi_ScriptInvoke %i", slot);
314 if ((slot >= mEnviroment.mInvokeFunctionCount) ||
315 (mEnviroment.mInvokeFunctions[slot] == NULL)) {
316 rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
317 return;
318 }
Jason Samsc61346b2010-05-28 18:23:22 -0700319 setupScript(rsc);
320 Script * oldTLS = setTLS(this);
Jason Sams22fa3712010-05-19 17:22:57 -0700321
Jason Sams2a63bf62010-06-08 15:40:48 -0700322 ((void (*)(const void *, uint32_t))
323 mEnviroment.mInvokeFunctions[slot])(data, len);
324
Jason Samsc61346b2010-05-28 18:23:22 -0700325 setTLS(oldTLS);
Jason Sams22fa3712010-05-19 17:22:57 -0700326}
327
Jason Sams326e0dd2009-05-22 14:03:28 -0700328ScriptCState::ScriptCState()
329{
Jason Sams8c6bc692009-09-16 15:04:38 -0700330 mScript = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -0700331 clear();
332}
333
334ScriptCState::~ScriptCState()
335{
Jason Sams8c6bc692009-09-16 15:04:38 -0700336 delete mScript;
337 mScript = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -0700338}
339
340void ScriptCState::clear()
341{
Jason Sams8b2c0652009-08-12 17:54:11 -0700342 for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
343 mConstantBufferTypes[ct].clear();
Jason Sams90b36a82009-08-17 13:56:09 -0700344 mSlotWritable[ct] = false;
Jason Sams8b2c0652009-08-12 17:54:11 -0700345 }
Jason Samsefb8de12009-06-08 15:20:31 -0700346
Jason Sams8c6bc692009-09-16 15:04:38 -0700347 delete mScript;
Jason Samse514b452009-09-25 14:51:22 -0700348 mScript = new ScriptC(NULL);
Jason Sams1f526332009-06-05 17:35:09 -0700349}
350
Jason Samsbe36bf32010-05-11 14:03:58 -0700351static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name)
Jason Sams29df66f2009-07-16 15:08:06 -0700352{
Jason Samsaeb094b2010-05-18 13:35:45 -0700353 const ScriptCState::SymbolTable_t *sym;
354 sym = ScriptCState::lookupSymbol(name);
355 if (sym) {
356 return sym->mPtr;
357 }
358 sym = ScriptCState::lookupSymbolCL(name);
359 if (sym) {
360 return sym->mPtr;
361 }
362 sym = ScriptCState::lookupSymbolGL(name);
Jason Sams29df66f2009-07-16 15:08:06 -0700363 if (sym) {
364 return sym->mPtr;
365 }
Jason Sams29df66f2009-07-16 15:08:06 -0700366 LOGE("ScriptC sym lookup failed for %s", name);
Jason Sams29df66f2009-07-16 15:08:06 -0700367 return NULL;
368}
Jason Samsa4a54e42009-06-10 18:39:40 -0700369
Jason Sams8c6bc692009-09-16 15:04:38 -0700370void ScriptCState::runCompiler(Context *rsc, ScriptC *s)
Jason Sams1f526332009-06-05 17:35:09 -0700371{
Jason Samsace3e012010-07-15 17:11:13 -0700372 LOGV("ScriptCState::runCompiler ");
Jason Sams1f526332009-06-05 17:35:09 -0700373
Jason Samsbe36bf32010-05-11 14:03:58 -0700374 s->mBccScript = bccCreateScript();
375 bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength);
376 bccRegisterSymbolCallback(s->mBccScript, symbolLookup, NULL);
Jason Samsbe36bf32010-05-11 14:03:58 -0700377 bccCompileScript(s->mBccScript);
Jason Samsbe36bf32010-05-11 14:03:58 -0700378 bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot);
379 bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit);
Jason Samsace3e012010-07-15 17:11:13 -0700380 LOGV("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit);
Jason Samsf1685042009-07-16 17:47:40 -0700381
Jason Sams8c6bc692009-09-16 15:04:38 -0700382 if (s->mProgram.mInit) {
383 s->mProgram.mInit();
Jason Sams1d54f102009-09-03 15:43:13 -0700384 }
385
Jason Sams8c880902010-06-15 12:15:57 -0700386 bccGetExportFuncs(s->mBccScript, (BCCsizei*) &s->mEnviroment.mInvokeFunctionCount, 0, NULL);
387 if(s->mEnviroment.mInvokeFunctionCount <= 0)
388 s->mEnviroment.mInvokeFunctions = NULL;
389 else {
390 s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t));
391 bccGetExportFuncs(s->mBccScript, NULL, s->mEnviroment.mInvokeFunctionCount, (BCCvoid **) s->mEnviroment.mInvokeFunctions);
Jason Sams1d54f102009-09-03 15:43:13 -0700392 }
393
Jason Samsbe36bf32010-05-11 14:03:58 -0700394 s->mEnviroment.mFieldAddress = (void **)calloc(100, sizeof(void *));
395 bccGetExportVars(s->mBccScript, (BCCsizei *)&s->mEnviroment.mFieldCount,
396 100, s->mEnviroment.mFieldAddress);
Jason Samsa4a54e42009-06-10 18:39:40 -0700397
Jason Sams8c6bc692009-09-16 15:04:38 -0700398 s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
399 s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
Jason Samsccc010b2010-05-13 18:30:11 -0700400 s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
Jason Samsb681c8a2009-09-28 18:12:56 -0700401 s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams8c6bc692009-09-16 15:04:38 -0700402
Jason Samsbe36bf32010-05-11 14:03:58 -0700403 if (s->mProgram.mRoot) {
Jason Sams10308932009-06-09 12:15:30 -0700404 const static int pragmaMax = 16;
Jason Samsbe36bf32010-05-11 14:03:58 -0700405 BCCsizei pragmaCount;
406 BCCchar * str[pragmaMax];
407 bccGetPragmas(s->mBccScript, &pragmaCount, pragmaMax, &str[0]);
Jason Sams10308932009-06-09 12:15:30 -0700408
Jason Sams10308932009-06-09 12:15:30 -0700409 for (int ct=0; ct < pragmaCount; ct+=2) {
Jason Samsaeb094b2010-05-18 13:35:45 -0700410 //LOGE("pragme %s %s", str[ct], str[ct+1]);
Jason Sams10308932009-06-09 12:15:30 -0700411 if (!strcmp(str[ct], "version")) {
412 continue;
Jason Sams10308932009-06-09 12:15:30 -0700413 }
414
Jason Sams10308932009-06-09 12:15:30 -0700415 if (!strcmp(str[ct], "stateVertex")) {
Jason Sams8ce125b2009-06-17 16:52:59 -0700416 if (!strcmp(str[ct+1], "default")) {
417 continue;
418 }
419 if (!strcmp(str[ct+1], "parent")) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700420 s->mEnviroment.mVertex.clear();
Jason Sams8ce125b2009-06-17 16:52:59 -0700421 continue;
422 }
Jason Sams10308932009-06-09 12:15:30 -0700423 LOGE("Unreconized value %s passed to stateVertex", str[ct+1]);
424 }
425
426 if (!strcmp(str[ct], "stateRaster")) {
Jason Samsb681c8a2009-09-28 18:12:56 -0700427 if (!strcmp(str[ct+1], "default")) {
428 continue;
429 }
430 if (!strcmp(str[ct+1], "parent")) {
431 s->mEnviroment.mRaster.clear();
432 continue;
433 }
Jason Sams10308932009-06-09 12:15:30 -0700434 LOGE("Unreconized value %s passed to stateRaster", str[ct+1]);
435 }
436
437 if (!strcmp(str[ct], "stateFragment")) {
Jason Sams8ce125b2009-06-17 16:52:59 -0700438 if (!strcmp(str[ct+1], "default")) {
439 continue;
440 }
441 if (!strcmp(str[ct+1], "parent")) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700442 s->mEnviroment.mFragment.clear();
Jason Sams8ce125b2009-06-17 16:52:59 -0700443 continue;
444 }
Jason Sams10308932009-06-09 12:15:30 -0700445 LOGE("Unreconized value %s passed to stateFragment", str[ct+1]);
446 }
447
Jason Samsb681c8a2009-09-28 18:12:56 -0700448 if (!strcmp(str[ct], "stateStore")) {
Jason Sams8ce125b2009-06-17 16:52:59 -0700449 if (!strcmp(str[ct+1], "default")) {
450 continue;
451 }
452 if (!strcmp(str[ct+1], "parent")) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700453 s->mEnviroment.mFragmentStore.clear();
Jason Sams8ce125b2009-06-17 16:52:59 -0700454 continue;
455 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700456 LOGE("Unreconized value %s passed to stateStore", str[ct+1]);
Jason Sams10308932009-06-09 12:15:30 -0700457 }
458
459 }
460
Jason Samsd34b7252009-08-04 16:58:20 -0700461
Jason Sams10308932009-06-09 12:15:30 -0700462 } else {
463 // Deal with an error.
464 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700465}
466
Jason Sams8b2c0652009-08-12 17:54:11 -0700467
Joe Onorato57b79ce2009-08-09 22:57:44 -0700468
Jason Sams326e0dd2009-05-22 14:03:28 -0700469namespace android {
470namespace renderscript {
471
472void rsi_ScriptCBegin(Context * rsc)
473{
474 ScriptCState *ss = &rsc->mScriptC;
475 ss->clear();
476}
477
Jason Samsefb8de12009-06-08 15:20:31 -0700478void rsi_ScriptCSetScript(Context * rsc, void *vp)
Jason Sams326e0dd2009-05-22 14:03:28 -0700479{
Jason Sams8c6bc692009-09-16 15:04:38 -0700480 rsAssert(0);
481 //ScriptCState *ss = &rsc->mScriptC;
482 //ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp);
Jason Sams326e0dd2009-05-22 14:03:28 -0700483}
484
Jason Sams1f526332009-06-05 17:35:09 -0700485void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len)
486{
487 ScriptCState *ss = &rsc->mScriptC;
Jason Samse402ed32009-11-03 11:25:42 -0800488
489 char *t = (char *)malloc(len + 1);
490 memcpy(t, text, len);
491 t[len] = 0;
492 ss->mScript->mEnviroment.mScriptText = t;
Jason Sams8c6bc692009-09-16 15:04:38 -0700493 ss->mScript->mEnviroment.mScriptTextLength = len;
Jason Sams1f526332009-06-05 17:35:09 -0700494}
495
496
Jason Sams326e0dd2009-05-22 14:03:28 -0700497RsScript rsi_ScriptCCreate(Context * rsc)
498{
499 ScriptCState *ss = &rsc->mScriptC;
500
Jason Sams8c6bc692009-09-16 15:04:38 -0700501 ScriptC *s = ss->mScript;
502 ss->mScript = NULL;
Jason Sams1f526332009-06-05 17:35:09 -0700503
Jason Sams8c6bc692009-09-16 15:04:38 -0700504 ss->runCompiler(rsc, s);
Jason Sams9397e302009-08-27 20:23:34 -0700505 s->incUserRef();
Jason Samse514b452009-09-25 14:51:22 -0700506 s->setContext(rsc);
Jason Samsfa517192009-08-13 12:59:04 -0700507 for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
508 s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get());
Jason Sams90b36a82009-08-17 13:56:09 -0700509 s->mSlotWritable[ct] = ss->mSlotWritable[ct];
Jason Samsfa517192009-08-13 12:59:04 -0700510 }
Jason Sams10308932009-06-09 12:15:30 -0700511
Jason Samsfa517192009-08-13 12:59:04 -0700512 ss->clear();
Jason Sams326e0dd2009-05-22 14:03:28 -0700513 return s;
514}
515
Jason Sams326e0dd2009-05-22 14:03:28 -0700516}
517}
518
519