OLD | NEW |
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 *result = RET (*src); | 71 *result = RET (*src); |
72 if (Result.has_derivs()) | 72 if (Result.has_derivs()) |
73 exec->zero_derivs (Result); | 73 exec->zero_derivs (Result); |
74 } else { | 74 } else { |
75 // Potentially varying case | 75 // Potentially varying case |
76 if (!std::numeric_limits<RET>::is_integer && | 76 if (!std::numeric_limits<RET>::is_integer && |
77 !std::numeric_limits<SRC>::is_integer && | 77 !std::numeric_limits<SRC>::is_integer && |
78 Result.has_derivs() && Src.has_derivs()) { | 78 Result.has_derivs() && Src.has_derivs()) { |
79 VaryingRef<Dual2<RET> > result ((Dual2<RET> *)Result.data(), Result.
step()); | 79 VaryingRef<Dual2<RET> > result ((Dual2<RET> *)Result.data(), Result.
step()); |
80 VaryingRef<Dual2<SRC> > src ((Dual2<SRC> *)Src.data(), Src.step()); | 80 VaryingRef<Dual2<SRC> > src ((Dual2<SRC> *)Src.data(), Src.step()); |
81 for (int i = beginpoint; i < endpoint; ++i) | 81 SHADE_LOOP ( |
82 if (runflags[i]) | 82 result[i] = Dual2<RET> (src[i]); |
83 result[i] = Dual2<RET> (src[i]); | 83 ) |
84 } else { | 84 } else { |
85 for (int i = beginpoint; i < endpoint; ++i) | 85 SHADE_LOOP ( |
86 if (runflags[i]) | 86 result[i] = RET (src[i]); |
87 result[i] = RET (src[i]); | 87 ) |
88 if (Result.has_derivs()) | 88 if (Result.has_derivs()) |
89 exec->zero_derivs (Result); | 89 exec->zero_derivs (Result); |
90 } | 90 } |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 | 95 |
96 // Special version of assign for when the source and result are the same | 96 // Special version of assign for when the source and result are the same |
97 // exact type, so we can just memcpy. | 97 // exact type, so we can just memcpy. |
(...skipping 12 matching lines...) Expand all Loading... |
110 if (Src.has_derivs()) // Both have derivs... | 110 if (Src.has_derivs()) // Both have derivs... |
111 size *= 3; // memcpy the derivs too | 111 size *= 3; // memcpy the derivs too |
112 else // Result needs derivs but | 112 else // Result needs derivs but |
113 exec->zero_derivs (Result); // src doesn't have -> zero | 113 exec->zero_derivs (Result); // src doesn't have -> zero |
114 } | 114 } |
115 | 115 |
116 // Loop over points, do the assignment. | 116 // Loop over points, do the assignment. |
117 if (Result.is_uniform()) { | 117 if (Result.is_uniform()) { |
118 // Uniform case | 118 // Uniform case |
119 memcpy (Result.data(), Src.data(), size); | 119 memcpy (Result.data(), Src.data(), size); |
| 120 #if 0 |
120 } else if (exec->all_points_on() && Src.is_varying() && | 121 } else if (exec->all_points_on() && Src.is_varying() && |
121 Result.has_derivs() == Src.has_derivs()) { | 122 Result.has_derivs() == Src.has_derivs()) { |
122 // Simple case where a single memcpy will do | 123 // Simple case where a single memcpy will do |
123 memcpy (Result.data(), Src.data(), Src.step() * exec->npoints()); | 124 memcpy (Result.data(), Src.data(), Src.step() * exec->npoints()); |
| 125 #endif |
124 } else { | 126 } else { |
125 // Potentially varying case | 127 // Potentially varying case |
126 VaryingRef<char> result ((char *)Result.data(), Result.step()); | 128 VaryingRef<char> result ((char *)Result.data(), Result.step()); |
127 VaryingRef<char> src ((char *)Src.data(), Src.step()); | 129 VaryingRef<char> src ((char *)Src.data(), Src.step()); |
128 for (int i = beginpoint; i < endpoint; ++i) | 130 SHADE_LOOP_BEGIN |
129 if (runflags[i]) | 131 memcpy (&result[i], &src[i], size); |
130 memcpy (&result[i], &src[i], size); | 132 SHADE_LOOP_END |
131 } | 133 } |
132 } | 134 } |
133 | 135 |
134 | 136 |
135 | 137 |
136 static void | 138 static void |
137 assign_closure (ShadingExecution *exec, int nargs, const int *args, | 139 assign_closure (ShadingExecution *exec, int nargs, const int *args) |
138 Runflag *runflags, int beginpoint, int endpoint) | |
139 { | 140 { |
140 // Get references to the symbols this op accesses | 141 // Get references to the symbols this op accesses |
141 Symbol &Result (exec->sym (args[0])); | 142 Symbol &Result (exec->sym (args[0])); |
142 Symbol &Src (exec->sym (args[1])); | 143 Symbol &Src (exec->sym (args[1])); |
143 | 144 |
144 // closures are always varying | 145 // closures are always varying |
145 DASSERT(Result.typespec().is_closure() && Result.is_varying()); | 146 DASSERT(Result.typespec().is_closure() && Result.is_varying()); |
146 DASSERT(Src.typespec().is_closure() && Src.is_varying()); | 147 DASSERT(Src.typespec().is_closure() && Src.is_varying()); |
147 | 148 |
148 // Loop over points, do the assignment. | 149 // Loop over points, do the assignment. |
149 VaryingRef<ClosureColor *> result ((ClosureColor **)Result.data(), Result.st
ep()); | 150 VaryingRef<ClosureColor *> result ((ClosureColor **)Result.data(), Result.st
ep()); |
150 VaryingRef<ClosureColor *> src ((ClosureColor **)Src.data(), Src.step()); | 151 VaryingRef<ClosureColor *> src ((ClosureColor **)Src.data(), Src.step()); |
151 for (int i = beginpoint; i < endpoint; ++i) | 152 SHADE_LOOP_BEGIN |
152 if (runflags[i]) | 153 *(result[i]) = *(src[i]); |
153 *(result[i]) = *(src[i]); | 154 SHADE_LOOP_END |
154 // N.B. You can't take a derivative of a closure | 155 // N.B. You can't take a derivative of a closure |
155 } | 156 } |
156 | 157 |
157 | 158 |
158 | 159 |
159 static void | 160 static void |
160 clear_closure (ShadingExecution *exec, int nargs, const int *args, | 161 clear_closure (ShadingExecution *exec, int nargs, const int *args) |
161 Runflag *runflags, int beginpoint, int endpoint) | |
162 { | 162 { |
163 // Get references to the symbols this op accesses | 163 // Get references to the symbols this op accesses |
164 Symbol &Result (exec->sym (args[0])); | 164 Symbol &Result (exec->sym (args[0])); |
165 | 165 |
166 // closures are always varying | 166 // closures are always varying |
167 DASSERT(Result.typespec().is_closure() && Result.is_varying()); | 167 DASSERT(Result.typespec().is_closure() && Result.is_varying()); |
168 | 168 |
169 // Loop over points, do the assignment. | 169 // Loop over points, do the assignment. |
170 VaryingRef<ClosureColor *> result ((ClosureColor **)Result.data(), Result.st
ep()); | 170 VaryingRef<ClosureColor *> result ((ClosureColor **)Result.data(), Result.st
ep()); |
171 for (int i = beginpoint; i < endpoint; ++i) | 171 SHADE_LOOP_BEGIN |
172 if (runflags[i]) | 172 result[i]->clear (); |
173 result[i]->clear (); | 173 SHADE_LOOP_END |
174 | 174 |
175 // N.B. You can't take a derivative of a closure | 175 // N.B. You can't take a derivative of a closure |
176 } | 176 } |
177 | 177 |
178 | 178 |
179 | 179 |
180 DECLOP (OP_assign) | 180 DECLOP (OP_assign) |
181 { | 181 { |
182 ASSERT (nargs == 2); | 182 ASSERT (nargs == 2); |
183 Symbol &Result (exec->sym (args[0])); | 183 Symbol &Result (exec->sym (args[0])); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 impl = specialized_assign<Vec3,float>; | 216 impl = specialized_assign<Vec3,float>; |
217 else if (Src.typespec().is_int()) | 217 else if (Src.typespec().is_int()) |
218 impl = specialized_assign<Vec3,int>; | 218 impl = specialized_assign<Vec3,int>; |
219 } else if (Result.typespec().is_matrix()) { | 219 } else if (Result.typespec().is_matrix()) { |
220 if (Src.typespec().is_float()) | 220 if (Src.typespec().is_float()) |
221 impl = specialized_assign<MatrixProxy,float>; | 221 impl = specialized_assign<MatrixProxy,float>; |
222 else if (Src.typespec().is_int()) | 222 else if (Src.typespec().is_int()) |
223 impl = specialized_assign<MatrixProxy,int>; | 223 impl = specialized_assign<MatrixProxy,int>; |
224 } | 224 } |
225 if (impl) { | 225 if (impl) { |
226 impl (exec, nargs, args, runflags, beginpoint, endpoint); | 226 impl (exec, nargs, args); |
227 // Use the specialized one for next time! Never have to check the | 227 // Use the specialized one for next time! Never have to check the |
228 // types or do the other sanity checks again. | 228 // types or do the other sanity checks again. |
229 // FIXME -- is this thread-safe? | 229 // FIXME -- is this thread-safe? |
230 exec->op().implementation (impl); | 230 exec->op().implementation (impl); |
231 return; | 231 return; |
232 } else { | 232 } else { |
233 exec->error ("Don't know how to assign %s = %s", | 233 exec->error ("Don't know how to assign %s = %s", |
234 Result.typespec().c_str(), Src.typespec().c_str()); | 234 Result.typespec().c_str(), Src.typespec().c_str()); |
235 ASSERT (0 && "Assignment types can't be handled"); | 235 ASSERT (0 && "Assignment types can't be handled"); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 | 240 |
241 }; // namespace pvt | 241 }; // namespace pvt |
242 }; // namespace OSL | 242 }; // namespace OSL |
243 #ifdef OSL_NAMESPACE | 243 #ifdef OSL_NAMESPACE |
244 }; // end namespace OSL_NAMESPACE | 244 }; // end namespace OSL_NAMESPACE |
245 #endif | 245 #endif |
OLD | NEW |