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" |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 20 | #include "../../../external/llvm/libbcc/include/bcc/bcc.h" |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 21 | #include "utils/Timers.h" |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 22 | |
Jason Sams | 4b962e5 | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 23 | #include <GLES/gl.h> |
| 24 | #include <GLES/glext.h> |
| 25 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
Jason Sams | 462d11b | 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 | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 35 | ScriptC::ScriptC(Context *rsc) : Script(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 36 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 37 | mAllocFile = __FILE__; |
| 38 | mAllocLine = __LINE__; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 39 | mBccScript = NULL; |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 40 | memset(&mProgram, 0, sizeof(mProgram)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | ScriptC::~ScriptC() |
| 44 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 45 | if (mBccScript) { |
| 46 | bccDeleteScript(mBccScript); |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 47 | } |
Jason Sams | 9d5e03d | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 48 | free(mEnviroment.mScriptText); |
| 49 | mEnviroment.mScriptText = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Jason Sams | e60446b | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 52 | void ScriptC::setupScript() |
| 53 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 54 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
| 55 | if (!mSlots[ct].get()) |
| 56 | continue; |
| 57 | void *ptr = mSlots[ct]->getPtr(); |
| 58 | void **dest = ((void ***)mEnviroment.mFieldAddress)[ct]; |
| 59 | //LOGE("setupScript %i %p = %p %p %i", ct, dest, ptr, mSlots[ct]->getType(), mSlots[ct]->getType()->getDimX()); |
| 60 | |
| 61 | //const uint32_t *p32 = (const uint32_t *)ptr; |
| 62 | //for (uint32_t ct2=0; ct2 < mSlots[ct]->getType()->getDimX(); ct2++) { |
| 63 | //LOGE(" %i = 0x%08x ", ct2, p32[ct2]); |
| 64 | //} |
| 65 | |
| 66 | if (dest) { |
| 67 | *dest = ptr; |
| 68 | } else { |
| 69 | LOGE("ScriptC::setupScript, NULL var binding address."); |
Jason Sams | e60446b | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 74 | const Allocation *ScriptC::ptrToAllocation(const void *ptr) const |
| 75 | { |
| 76 | if (!ptr) { |
| 77 | return NULL; |
| 78 | } |
| 79 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
| 80 | if (!mSlots[ct].get()) |
| 81 | continue; |
| 82 | if (mSlots[ct]->getPtr() == ptr) { |
| 83 | return mSlots[ct].get(); |
| 84 | } |
| 85 | } |
| 86 | LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr); |
| 87 | return NULL; |
| 88 | } |
| 89 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 90 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 91 | uint32_t ScriptC::run(Context *rsc, uint32_t launchIndex) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 92 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 93 | if (mProgram.mRoot == NULL) { |
Jason Sams | 156cce6 | 2010-03-03 13:03:18 -0800 | [diff] [blame] | 94 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); |
| 95 | return 0; |
| 96 | } |
| 97 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 98 | Context::ScriptTLSStruct * tls = |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 99 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); |
Jason Sams | 996db8d | 2009-10-06 17:16:55 -0700 | [diff] [blame] | 100 | rsAssert(tls); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 101 | |
| 102 | if (mEnviroment.mFragmentStore.get()) { |
| 103 | rsc->setFragmentStore(mEnviroment.mFragmentStore.get()); |
| 104 | } |
| 105 | if (mEnviroment.mFragment.get()) { |
| 106 | rsc->setFragment(mEnviroment.mFragment.get()); |
| 107 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 108 | if (mEnviroment.mVertex.get()) { |
| 109 | rsc->setVertex(mEnviroment.mVertex.get()); |
| 110 | } |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 111 | if (mEnviroment.mRaster.get()) { |
| 112 | rsc->setRaster(mEnviroment.mRaster.get()); |
| 113 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 114 | |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 115 | if (launchIndex == 0) { |
| 116 | mEnviroment.mStartTimeMillis |
| 117 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 118 | } |
Jason Sams | e60446b | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 119 | setupScript(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 120 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 121 | uint32_t ret = 0; |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 122 | tls->mScript = this; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 123 | //LOGE("ScriptC::run %p", mProgram.mRoot); |
| 124 | ret = mProgram.mRoot(); |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 125 | tls->mScript = NULL; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 126 | //LOGE("ScriptC::run ret %i", ret); |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 127 | return ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | ScriptCState::ScriptCState() |
| 131 | { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 132 | mScript = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 133 | clear(); |
| 134 | } |
| 135 | |
| 136 | ScriptCState::~ScriptCState() |
| 137 | { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 138 | delete mScript; |
| 139 | mScript = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | void ScriptCState::clear() |
| 143 | { |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 144 | for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
| 145 | mConstantBufferTypes[ct].clear(); |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 146 | mSlotWritable[ct] = false; |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 147 | } |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 148 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 149 | delete mScript; |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 150 | mScript = new ScriptC(NULL); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 153 | static BCCvoid* symbolLookup(BCCvoid* pContext, const BCCchar* name) |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 154 | { |
| 155 | const ScriptCState::SymbolTable_t *sym = ScriptCState::lookupSymbol(name); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 156 | if (sym) { |
| 157 | return sym->mPtr; |
| 158 | } |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 159 | LOGE("ScriptC sym lookup failed for %s", name); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 160 | return NULL; |
| 161 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 162 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 163 | void ScriptCState::runCompiler(Context *rsc, ScriptC *s) |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 164 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 165 | LOGE("ScriptCState::runCompiler "); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 166 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 167 | s->mBccScript = bccCreateScript(); |
| 168 | bccScriptBitcode(s->mBccScript, s->mEnviroment.mScriptText, s->mEnviroment.mScriptTextLength); |
| 169 | bccRegisterSymbolCallback(s->mBccScript, symbolLookup, NULL); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 170 | bccCompileScript(s->mBccScript); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 171 | bccGetScriptLabel(s->mBccScript, "root", (BCCvoid**) &s->mProgram.mRoot); |
| 172 | bccGetScriptLabel(s->mBccScript, "init", (BCCvoid**) &s->mProgram.mInit); |
| 173 | LOGE("root %p, init %p", s->mProgram.mRoot, s->mProgram.mInit); |
Jason Sams | 764205c | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 174 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 175 | if (s->mProgram.mInit) { |
| 176 | s->mProgram.mInit(); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 179 | s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t *)calloc(100, sizeof(void *)); |
| 180 | BCCchar **labels = new char*[100]; |
| 181 | bccGetFunctions(s->mBccScript, (BCCsizei *)&s->mEnviroment.mInvokeFunctionCount, |
| 182 | 100, (BCCchar **)labels); |
| 183 | //LOGE("func count %i", s->mEnviroment.mInvokeFunctionCount); |
| 184 | for (uint32_t i=0; i < s->mEnviroment.mInvokeFunctionCount; i++) { |
| 185 | BCCsizei length; |
| 186 | bccGetFunctionBinary(s->mBccScript, labels[i], (BCCvoid **)&(s->mEnviroment.mInvokeFunctions[i]), &length); |
| 187 | //LOGE("func %i %p", i, s->mEnviroment.mInvokeFunctions[i]); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 190 | s->mEnviroment.mFieldAddress = (void **)calloc(100, sizeof(void *)); |
| 191 | bccGetExportVars(s->mBccScript, (BCCsizei *)&s->mEnviroment.mFieldCount, |
| 192 | 100, s->mEnviroment.mFieldAddress); |
| 193 | //LOGE("var count %i", s->mEnviroment.mFieldCount); |
| 194 | for (uint32_t i=0; i < s->mEnviroment.mFieldCount; i++) { |
| 195 | //LOGE("var %i %p", i, s->mEnviroment.mFieldAddress[i]); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 196 | } |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 197 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 198 | s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 199 | s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
Jason Sams | 54db59c | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 200 | s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 201 | s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 202 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 203 | if (s->mProgram.mRoot) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 204 | const static int pragmaMax = 16; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 205 | BCCsizei pragmaCount; |
| 206 | BCCchar * str[pragmaMax]; |
| 207 | bccGetPragmas(s->mBccScript, &pragmaCount, pragmaMax, &str[0]); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 208 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 209 | for (int ct=0; ct < pragmaCount; ct+=2) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 210 | if (!strcmp(str[ct], "version")) { |
| 211 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 214 | if (!strcmp(str[ct], "stateVertex")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 215 | if (!strcmp(str[ct+1], "default")) { |
| 216 | continue; |
| 217 | } |
| 218 | if (!strcmp(str[ct+1], "parent")) { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 219 | s->mEnviroment.mVertex.clear(); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 220 | continue; |
| 221 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 222 | LOGE("Unreconized value %s passed to stateVertex", str[ct+1]); |
| 223 | } |
| 224 | |
| 225 | if (!strcmp(str[ct], "stateRaster")) { |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 226 | if (!strcmp(str[ct+1], "default")) { |
| 227 | continue; |
| 228 | } |
| 229 | if (!strcmp(str[ct+1], "parent")) { |
| 230 | s->mEnviroment.mRaster.clear(); |
| 231 | continue; |
| 232 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 233 | LOGE("Unreconized value %s passed to stateRaster", str[ct+1]); |
| 234 | } |
| 235 | |
| 236 | if (!strcmp(str[ct], "stateFragment")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 237 | if (!strcmp(str[ct+1], "default")) { |
| 238 | continue; |
| 239 | } |
| 240 | if (!strcmp(str[ct+1], "parent")) { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 241 | s->mEnviroment.mFragment.clear(); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 242 | continue; |
| 243 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 244 | LOGE("Unreconized value %s passed to stateFragment", str[ct+1]); |
| 245 | } |
| 246 | |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 247 | if (!strcmp(str[ct], "stateStore")) { |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 248 | if (!strcmp(str[ct+1], "default")) { |
| 249 | continue; |
| 250 | } |
| 251 | if (!strcmp(str[ct+1], "parent")) { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 252 | s->mEnviroment.mFragmentStore.clear(); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 253 | continue; |
| 254 | } |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 255 | LOGE("Unreconized value %s passed to stateStore", str[ct+1]); |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | } |
| 259 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 260 | |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 261 | } else { |
| 262 | // Deal with an error. |
| 263 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 266 | |
Joe Onorato | d7b3774 | 2009-08-09 22:57:44 -0700 | [diff] [blame] | 267 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 268 | namespace android { |
| 269 | namespace renderscript { |
| 270 | |
| 271 | void rsi_ScriptCBegin(Context * rsc) |
| 272 | { |
| 273 | ScriptCState *ss = &rsc->mScriptC; |
| 274 | ss->clear(); |
| 275 | } |
| 276 | |
Jason Sams | 3a833d8 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 277 | void rsi_ScriptCSetScript(Context * rsc, void *vp) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 278 | { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 279 | rsAssert(0); |
| 280 | //ScriptCState *ss = &rsc->mScriptC; |
| 281 | //ss->mProgram.mScript = reinterpret_cast<ScriptC::RunScript_t>(vp); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 284 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) |
| 285 | { |
| 286 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | 9d5e03d | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 287 | |
| 288 | char *t = (char *)malloc(len + 1); |
| 289 | memcpy(t, text, len); |
| 290 | t[len] = 0; |
| 291 | ss->mScript->mEnviroment.mScriptText = t; |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 292 | ss->mScript->mEnviroment.mScriptTextLength = len; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 296 | RsScript rsi_ScriptCCreate(Context * rsc) |
| 297 | { |
| 298 | ScriptCState *ss = &rsc->mScriptC; |
| 299 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 300 | ScriptC *s = ss->mScript; |
| 301 | ss->mScript = NULL; |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 302 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 303 | ss->runCompiler(rsc, s); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 304 | s->incUserRef(); |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 305 | s->setContext(rsc); |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 306 | for (int ct=0; ct < MAX_SCRIPT_BANKS; ct++) { |
| 307 | s->mTypes[ct].set(ss->mConstantBufferTypes[ct].get()); |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 308 | s->mSlotWritable[ct] = ss->mSlotWritable[ct]; |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 309 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 310 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 311 | ss->clear(); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 312 | return s; |
| 313 | } |
| 314 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | |