Jason Sams | d19f10d | 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" |
| 20 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 21 | #include "acc/acc.h" |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 22 | #include "utils/Timers.h" |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 23 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 24 | #include <GLES/gl.h> |
| 25 | #include <GLES/glext.h> |
| 26 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | using namespace android; |
| 28 | using namespace android::renderscript; |
| 29 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 30 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 31 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 32 | Context * rsc = tls->mContext; \ |
| 33 | ScriptC * sc = (ScriptC *) tls->mScript |
| 34 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 35 | |
| 36 | ScriptC::ScriptC() |
| 37 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 38 | mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 39 | memset(&mProgram, 0, sizeof(mProgram)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | ScriptC::~ScriptC() |
| 43 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 44 | if (mAccScript) { |
| 45 | accDeleteScript(mAccScript); |
| 46 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 50 | bool ScriptC::run(Context *rsc, uint32_t launchIndex) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 51 | { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 52 | Context::ScriptTLSStruct * tls = |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 53 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 54 | |
| 55 | if (mEnviroment.mFragmentStore.get()) { |
| 56 | rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); |
| 57 | } |
| 58 | if (mEnviroment.mFragment.get()) { |
| 59 | rsc->setFragment(mEnviroment.mFragment.get()); |
| 60 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 61 | if (mEnviroment.mVertex.get()) { |
| 62 | rsc->setVertex(mEnviroment.mVertex.get()); |
| 63 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 64 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 65 | if (launchIndex == 0) { |
| 66 | mEnviroment.mStartTimeMillis |
| 67 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 68 | } |
| 69 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 70 | bool ret = false; |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 71 | tls->mScript = this; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 72 | ret = mProgram.mScript(launchIndex) != 0; |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 73 | tls->mScript = NULL; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 74 | return ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | ScriptCState::ScriptCState() |
| 78 | { |
| 79 | clear(); |
| 80 | } |
| 81 | |
| 82 | ScriptCState::~ScriptCState() |
| 83 | { |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 84 | if (mAccScript) { |
| 85 | accDeleteScript(mAccScript); |
| 86 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void ScriptCState::clear() |
| 90 | { |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 91 | memset(&mProgram, 0, sizeof(mProgram)); |
| 92 | |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 93 | for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
| 94 | mConstantBufferTypes[ct].clear(); |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 95 | mSlotNames[ct].setTo(""); |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 96 | } |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 97 | |
| 98 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
| 99 | mEnviroment.mClearColor[0] = 0; |
| 100 | mEnviroment.mClearColor[1] = 0; |
| 101 | mEnviroment.mClearColor[2] = 0; |
| 102 | mEnviroment.mClearColor[3] = 1; |
| 103 | mEnviroment.mClearDepth = 1; |
| 104 | mEnviroment.mClearStencil = 0; |
| 105 | mEnviroment.mIsRoot = false; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 106 | |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 107 | mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 108 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 109 | mInt32Defines.clear(); |
| 110 | mFloatDefines.clear(); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 113 | static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name) |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 114 | { |
| 115 | const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 116 | if (sym) { |
| 117 | return sym->mPtr; |
| 118 | } |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 119 | LOGE("ScriptC sym lookup failed for %s", name); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 120 | return NULL; |
| 121 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 122 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 123 | void ScriptCState::runCompiler(Context *rsc) |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 124 | { |
| 125 | mAccScript = accCreateScript(); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 126 | String8 tmp; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 127 | |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 128 | rsc->appendNameDefines(&tmp); |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 129 | appendDecls(&tmp); |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 130 | rsc->appendVarDefines(&tmp); |
| 131 | appendVarDefines(&tmp); |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 132 | appendTypes(&tmp); |
Jason Sams | ee41112 | 2009-07-21 12:20:54 -0700 | [diff] [blame] | 133 | tmp.append("#line 1\n"); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 134 | |
| 135 | const char* scriptSource[] = {tmp.string(), mProgram.mScriptText}; |
| 136 | int scriptLength[] = {tmp.length(), mProgram.mScriptTextLength} ; |
| 137 | accScriptSource(mAccScript, sizeof(scriptLength) / sizeof(int), scriptSource, scriptLength); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 138 | accRegisterSymbolCallback(mAccScript, symbolLookup, NULL); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 139 | accCompileScript(mAccScript); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 140 | accGetScriptLabel(mAccScript, "main", (ACCvoid**) &mProgram.mScript); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 141 | rsAssert(mProgram.mScript); |
| 142 | |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 143 | if (!mProgram.mScript) { |
| 144 | ACCchar buf[4096]; |
| 145 | ACCsizei len; |
| 146 | accGetScriptInfoLog(mAccScript, sizeof(buf), &len, buf); |
| 147 | LOGE(buf); |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 150 | mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 151 | mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
| 152 | mEnviroment.mFragmentStore.set(rsc->getDefaultProgramFragmentStore()); |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 153 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 154 | if (mProgram.mScript) { |
| 155 | const static int pragmaMax = 16; |
| 156 | ACCsizei pragmaCount; |
| 157 | ACCchar * str[pragmaMax]; |
| 158 | accGetPragmas(mAccScript, &pragmaCount, pragmaMax, &str[0]); |
| 159 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 160 | for (int ct=0; ct < pragmaCount; ct+=2) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 161 | if (!strcmp(str[ct], "version")) { |
| 162 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 165 | if (!strcmp(str[ct], "stateVertex")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 166 | if (!strcmp(str[ct+1], "default")) { |
| 167 | continue; |
| 168 | } |
| 169 | if (!strcmp(str[ct+1], "parent")) { |
| 170 | mEnviroment.mVertex.clear(); |
| 171 | continue; |
| 172 | } |
| 173 | ProgramVertex * pv = (ProgramVertex *)rsc->lookupName(str[ct+1]); |
| 174 | if (pv != NULL) { |
| 175 | mEnviroment.mVertex.set(pv); |
| 176 | continue; |
| 177 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 178 | LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); |
| 179 | } |
| 180 | |
| 181 | if (!strcmp(str[ct], "stateRaster")) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 182 | LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); |
| 183 | } |
| 184 | |
| 185 | if (!strcmp(str[ct], "stateFragment")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 186 | if (!strcmp(str[ct+1], "default")) { |
| 187 | continue; |
| 188 | } |
| 189 | if (!strcmp(str[ct+1], "parent")) { |
| 190 | mEnviroment.mFragment.clear(); |
| 191 | continue; |
| 192 | } |
| 193 | ProgramFragment * pf = (ProgramFragment *)rsc->lookupName(str[ct+1]); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 194 | if (pf != NULL) { |
| 195 | mEnviroment.mFragment.set(pf); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 196 | continue; |
| 197 | } |
| 198 | LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); |
| 199 | } |
| 200 | |
| 201 | if (!strcmp(str[ct], "stateFragmentStore")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 202 | if (!strcmp(str[ct+1], "default")) { |
| 203 | continue; |
| 204 | } |
| 205 | if (!strcmp(str[ct+1], "parent")) { |
| 206 | mEnviroment.mFragmentStore.clear(); |
| 207 | continue; |
| 208 | } |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 209 | ProgramFragmentStore * pfs = |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 210 | (ProgramFragmentStore *)rsc->lookupName(str[ct+1]); |
| 211 | if (pfs != NULL) { |
| 212 | mEnviroment.mFragmentStore.set(pfs); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 213 | continue; |
| 214 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 215 | LOGE("Unreconized value %s passed to stateFragmentStore", str[ct+1]); |
| 216 | } |
| 217 | |
| 218 | } |
| 219 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 220 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 221 | } else { |
| 222 | // Deal with an error. |
| 223 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 226 | |
| 227 | void ScriptCState::appendVarDefines(String8 *str) |
| 228 | { |
| 229 | char buf[256]; |
| 230 | LOGD("appendVarDefines mInt32Defines.size()=%d mFloatDefines.size()=%d\n", |
| 231 | mInt32Defines.size(), mFloatDefines.size()); |
| 232 | for (size_t ct=0; ct < mInt32Defines.size(); ct++) { |
| 233 | str->append("#define "); |
| 234 | str->append(mInt32Defines.keyAt(ct)); |
| 235 | str->append(" "); |
| 236 | sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct)); |
| 237 | str->append(buf); |
| 238 | } |
| 239 | for (size_t ct=0; ct < mFloatDefines.size(); ct++) { |
| 240 | str->append("#define "); |
| 241 | str->append(mFloatDefines.keyAt(ct)); |
| 242 | str->append(" "); |
| 243 | sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct)); |
| 244 | str->append(buf); |
| 245 | } |
| 246 | } |
| 247 | |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 248 | void ScriptCState::appendTypes(String8 *str) |
| 249 | { |
| 250 | char buf[256]; |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 251 | String8 tmp; |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 252 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 253 | for (size_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 254 | const Type *t = mConstantBufferTypes[ct].get(); |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 255 | if (!t) { |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 256 | continue; |
| 257 | } |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 258 | const Element *e = t->getElement(); |
| 259 | |
| 260 | if (t->getName()) { |
| 261 | for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) { |
| 262 | const Component *c = e->getComponent(ct2); |
| 263 | tmp.setTo("#define OFFSETOF_"); |
| 264 | tmp.append(t->getName()); |
| 265 | tmp.append("_"); |
| 266 | tmp.append(c->getComponentName()); |
| 267 | sprintf(buf, " %i\n", ct2); |
| 268 | tmp.append(buf); |
| 269 | LOGD(tmp); |
| 270 | str->append(tmp); |
| 271 | } |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 274 | if (mSlotNames[ct].length() > 0) { |
| 275 | for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) { |
| 276 | const Component *c = e->getComponent(ct2); |
| 277 | tmp.setTo("#define "); |
| 278 | tmp.append(mSlotNames[ct]); |
| 279 | tmp.append("_"); |
| 280 | tmp.append(c->getComponentName()); |
| 281 | switch (c->getType()) { |
| 282 | case Component::FLOAT: |
| 283 | tmp.append(" loadF("); |
| 284 | break; |
| 285 | case Component::SIGNED: |
| 286 | sprintf(buf, " loadI%i(", c->getBits()); |
| 287 | tmp.append(buf); |
| 288 | break; |
| 289 | case Component::UNSIGNED: |
| 290 | sprintf(buf, " loadU%i(", c->getBits()); |
| 291 | tmp.append(buf); |
| 292 | break; |
| 293 | } |
| 294 | sprintf(buf, "%i, %i)\n", ct, ct2); |
| 295 | tmp.append(buf); |
| 296 | |
| 297 | LOGD(tmp); |
| 298 | str->append(tmp); |
| 299 | } |
| 300 | } |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | } |
| 304 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 305 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 306 | namespace android { |
| 307 | namespace renderscript { |
| 308 | |
| 309 | void rsi_ScriptCBegin(Context * rsc) |
| 310 | { |
| 311 | ScriptCState *ss = &rsc->mScriptC; |
| 312 | ss->clear(); |
| 313 | } |
| 314 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 315 | void rsi_ScriptCSetScript(Context * rsc, void *vp) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 316 | { |
| 317 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 318 | ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 321 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) |
| 322 | { |
| 323 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 324 | ss->mProgram.mScriptText = text; |
| 325 | ss->mProgram.mScriptTextLength = len; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 329 | RsScript rsi_ScriptCCreate(Context * rsc) |
| 330 | { |
| 331 | ScriptCState *ss = &rsc->mScriptC; |
| 332 | |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 333 | ss->runCompiler(rsc); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 334 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 335 | ScriptC *s = new ScriptC(); |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 336 | s->incRef(); |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 337 | s->mAccScript = ss->mAccScript; |
| 338 | ss->mAccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 339 | s->mEnviroment = ss->mEnviroment; |
| 340 | s->mProgram = ss->mProgram; |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 341 | for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
| 342 | s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get()); |
| 343 | s->mSlotNames[ct] = ss->mSlotNames[ct]; |
| 344 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 345 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 346 | ss->clear(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 347 | return s; |
| 348 | } |
| 349 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 350 | void rsi_ScriptCSetDefineF(Context *rsc, const char* name, float value) |
| 351 | { |
| 352 | ScriptCState *ss = &rsc->mScriptC; |
| 353 | ss->mFloatDefines.add(String8(name), value); |
| 354 | } |
| 355 | |
| 356 | void rsi_ScriptCSetDefineI32(Context *rsc, const char* name, int32_t value) |
| 357 | { |
| 358 | ScriptCState *ss = &rsc->mScriptC; |
| 359 | ss->mInt32Defines.add(String8(name), value); |
| 360 | } |
| 361 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | |