Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. | 2 Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. |
3 All Rights Reserved. | 3 All Rights Reserved. |
4 | 4 |
5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are | 6 modification, are permitted provided that the following conditions are |
7 met: | 7 met: |
8 * Redistributions of source code must retain the above copyright | 8 * Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 * Redistributions in binary form must reproduce the above copyright | 10 * Redistributions in binary form must reproduce the above copyright |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 // FIXME: bind the symbols -- get the syms ready and pointing to the | 181 // FIXME: bind the symbols -- get the syms ready and pointing to the |
182 // right place in the heap,, interpolate primitive variables, handle | 182 // right place in the heap,, interpolate primitive variables, handle |
183 // connections, initialize all parameters | 183 // connections, initialize all parameters |
184 BOOST_FOREACH (Symbol &sym, m_symbols) { | 184 BOOST_FOREACH (Symbol &sym, m_symbols) { |
185 if (m_debug) | 185 if (m_debug) |
186 m_shadingsys->info (" bind %s, offset %d", | 186 m_shadingsys->info (" bind %s, offset %d", |
187 sym.mangled().c_str(), sym.dataoffset()); | 187 sym.mangled().c_str(), sym.dataoffset()); |
188 if (sym.symtype() == SymTypeGlobal) { | 188 if (sym.symtype() == SymTypeGlobal) { |
189 // FIXME -- reset sym's data pointer? | 189 // FIXME -- reset sym's data pointer? |
190 | 190 |
191 // Instead of duplicating the logic for each possible global | |
192 // variable, we just decode the name and store pointers to | |
193 // the VaringRef's (for value, and for some cases, | |
194 // derivatives) into valref, dxref, and dyref, then handle | |
195 // them with a single logic block below. Note that rather | |
196 // than worry about the float and triple cases separately, | |
197 // we just cast them all to VR<float> for now, since it's | |
198 // just a pointer underneath anyway. | |
191 VaryingRef<float> * valref = NULL, *dxref = NULL, *dyref = NULL; | 199 VaryingRef<float> * valref = NULL, *dxref = NULL, *dyref = NULL; |
ckulla
2010/01/26 19:57:25
This is a big confusing - they all get turned into
larrygritz
2010/01/26 22:27:08
The idea is that the VaryingRef is really just a p
| |
192 if (sym.name() == Strings::P) { | 200 if (sym.name() == Strings::P) { |
193 valref = (VaryingRef<float>*) &globals->P; | 201 valref = (VaryingRef<float>*) &globals->P; |
194 dxref = (VaryingRef<float>*) &globals->dPdx; | 202 dxref = (VaryingRef<float>*) &globals->dPdx; |
195 dyref = (VaryingRef<float>*) &globals->dPdy; | 203 dyref = (VaryingRef<float>*) &globals->dPdy; |
196 } else if (sym.name() == Strings::I) { | 204 } else if (sym.name() == Strings::I) { |
197 valref = (VaryingRef<float>*) &globals->I; | 205 valref = (VaryingRef<float>*) &globals->I; |
198 dxref = (VaryingRef<float>*) &globals->dIdx; | 206 dxref = (VaryingRef<float>*) &globals->dIdx; |
199 dyref = (VaryingRef<float>*) &globals->dIdy; | 207 dyref = (VaryingRef<float>*) &globals->dIdy; |
200 } else if (sym.name() == Strings::N) { | 208 } else if (sym.name() == Strings::N) { |
201 valref = (VaryingRef<float>*) &globals->N; | 209 valref = (VaryingRef<float>*) &globals->N; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 if (dxref && dxref->ptr() && dyref && dyref->ptr()) { | 241 if (dxref && dxref->ptr() && dyref && dyref->ptr()) { |
234 // Derivs supplied | 242 // Derivs supplied |
235 sym.has_derivs (true); | 243 sym.has_derivs (true); |
236 if (rebind) { | 244 if (rebind) { |
237 // Rebinding -- addr is ok, just reset the step | 245 // Rebinding -- addr is ok, just reset the step |
238 sym.step (sym.derivsize()); | 246 sym.step (sym.derivsize()); |
239 } else { | 247 } else { |
240 m_context->heap_allot (sym, true); | 248 m_context->heap_allot (sym, true); |
241 } | 249 } |
242 if (sym.typespec().is_float()) { | 250 if (sym.typespec().is_float()) { |
251 // It's a float -- use the valref,dxref,dyref | |
252 // directly. | |
243 VaryingRef<Dual2<float> > P ((Dual2<Vec3> *)sym.data(), sym.step()); | 253 VaryingRef<Dual2<float> > P ((Dual2<Vec3> *)sym.data(), sym.step()); |
244 for (int i = 0; i < npoints(); ++i) | 254 for (int i = 0; i < npoints(); ++i) |
245 P[i].set ((*valref)[i], (*dxref)[i], (*dyref)[i]); | 255 P[i].set ((*valref)[i], (*dxref)[i], (*dyref)[i]); |
246 } else { | 256 } else { |
247 DASSERT (sym.typespec().is_triple()); | 257 DASSERT (sym.typespec().is_triple()); |
258 // It's a triple, so cast our | |
259 // VaryingRef<float>'s back to Vec3's. | |
248 VaryingRef<Dual2<Vec3> > P ((Dual2<Vec3> *)sym.data(), s ym.step()); | 260 VaryingRef<Dual2<Vec3> > P ((Dual2<Vec3> *)sym.data(), s ym.step()); |
249 for (int i = 0; i < npoints(); ++i) | 261 for (int i = 0; i < npoints(); ++i) |
250 P[i].set (*(Vec3 *)&((*valref)[i]), | 262 P[i].set (*(Vec3 *)&((*valref)[i]), |
251 *(Vec3 *)&((*dxref)[i]), | 263 *(Vec3 *)&((*dxref)[i]), |
252 *(Vec3 *)&((*dyref)[i])); | 264 *(Vec3 *)&((*dyref)[i])); |
253 } | 265 } |
254 // FIXME -- what if the user has already passed valref, | 266 // FIXME -- what if the user has already passed valref, |
255 // dxref, and dyref with just the right layout that it | 267 // dxref, and dyref with just the right layout that it |
256 // could be a Dual<Vec3>? Should we just point to it, | 268 // could be a Dual<Vec3>? Should we just point to it, |
257 // and avoid the data copy? | 269 // and avoid the data copy? |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 if (sym.typespec().is_closure()) { | 312 if (sym.typespec().is_closure()) { |
301 // Special case -- closures store pointers in the heap, and | 313 // Special case -- closures store pointers in the heap, and |
302 // they are always varying. | 314 // they are always varying. |
303 sym.dataoffset (m_context->closure_allot (m_npoints)); | 315 sym.dataoffset (m_context->closure_allot (m_npoints)); |
304 sym.data (m_context->heapaddr (sym.dataoffset())); | 316 sym.data (m_context->heapaddr (sym.dataoffset())); |
305 sym.step (sizeof (ClosureColor *)); | 317 sym.step (sizeof (ClosureColor *)); |
306 } else { | 318 } else { |
307 m_context->heap_allot (sym); | 319 m_context->heap_allot (sym); |
308 } | 320 } |
309 if (sym.typespec().simpletype() == TypeDesc::TypeString) { | 321 if (sym.typespec().simpletype() == TypeDesc::TypeString) { |
310 // Uninitialized strings in the heap can really screw | 322 // Uninitialized strings in the heap can really screw |
ckulla
2010/01/26 19:57:25
Could we mark this as temporary? I really think it
larrygritz
2010/01/26 22:27:08
I'm not sure I agree. Why clutter up the instruct
| |
311 // things up, since they are a pointer underneath. | 323 // things up, since they are a pointer underneath. |
312 // Clear and uniformize just in case. | 324 // Clear and uniformize just in case. Another stretegy |
325 // here might be to have the compiler generate | |
326 // initializations for all string vars that aren't | |
327 // unconditionally assigned by the user, but for now | |
328 // we're just taking care of it here. | |
313 sym.step (0); | 329 sym.step (0); |
314 ((ustring *)sym.data())->clear (); | 330 ((ustring *)sym.data())->clear (); |
315 } | 331 } |
316 } else if (sym.symtype() == SymTypeConst) { | 332 } else if (sym.symtype() == SymTypeConst) { |
317 ASSERT (sym.data() != NULL && | 333 ASSERT (sym.data() != NULL && |
318 "Const symbol should already have valid data address"); | 334 "Const symbol should already have valid data address"); |
319 } else { | 335 } else { |
320 ASSERT (0 && "Should never get here"); | 336 ASSERT (0 && "Should never get here"); |
321 } | 337 } |
322 if (m_debug) | 338 if (m_debug) |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
898 get_matrix (Mfrom, from, whichpoint); | 914 get_matrix (Mfrom, from, whichpoint); |
899 get_inverse_matrix (Mto, to, whichpoint); | 915 get_inverse_matrix (Mto, to, whichpoint); |
900 result = Mfrom * Mto; | 916 result = Mfrom * Mto; |
901 } | 917 } |
902 | 918 |
903 | 919 |
904 | 920 |
905 | 921 |
906 }; // namespace pvt | 922 }; // namespace pvt |
907 }; // namespace OSL | 923 }; // namespace OSL |
LEFT | RIGHT |