@@ -41,15 +41,6 @@ export enum BinaryOpType {
41
41
SUB
42
42
}
43
43
44
- const CHECK_NAN_SNIPPET = `
45
- resultTemp = select(resultTemp, valueForNaN, isNaN | isnan(a) | isnan(b));` ;
46
-
47
- const CHECK_NAN_SNIPPET_VEC4 = `
48
- resultTemp = select(
49
- resultTemp, vec4<f32>(valueForNaN),
50
- vec4<bool>(isNaN) | isnanVec4(a) | isnanVec4(b));
51
- ` ;
52
-
53
44
const ADD = 'return a + b;' ;
54
45
const ATAN2 = 'var resultTemp = atan2(a, b);' ;
55
46
// (Ar + Ai)(Br + Bi) =
@@ -183,9 +174,10 @@ const SUB = 'return a - b;';
183
174
184
175
export function getBinaryOpString (
185
176
type : BinaryOpType , useVec4 ?: boolean ) : string {
177
+ let doOpSnippet : string ;
178
+
186
179
// Ops with NaN check
187
180
do {
188
- let doOpSnippet : string ;
189
181
switch ( type ) {
190
182
case BinaryOpType . ATAN2 :
191
183
doOpSnippet = ATAN2 ;
@@ -208,13 +200,34 @@ export function getBinaryOpString(
208
200
default :
209
201
continue ;
210
202
}
203
+
204
+ let isNaN : string ;
205
+ let dTypeN : string ;
206
+ let boolN : string ;
207
+ if ( useVec4 ) {
208
+ isNaN = 'isnanVec4' ;
209
+ dTypeN = 'vec4<f32>' ;
210
+ boolN = 'vec4<bool>' ;
211
+ } else {
212
+ isNaN = 'isnan' ;
213
+ dTypeN = 'f32' ;
214
+ boolN = 'bool' ;
215
+ }
216
+
211
217
return `
218
+ let aIsNaN = ${ isNaN } (a);
219
+ let aPostLegalization = select(a, ${ dTypeN } (42), aIsNaN);
220
+ let bIsNaN = ${ isNaN } (b);
221
+ let bPostLegalization = select(b, ${ dTypeN } (42), bIsNaN);
212
222
let isNaN = false;
213
223
let valueForNaN = uniforms.NAN;
214
224
{
225
+ let a = aPostLegalization;
226
+ let b = bPostLegalization;
215
227
${ doOpSnippet }
216
- ${ useVec4 ? CHECK_NAN_SNIPPET_VEC4 : CHECK_NAN_SNIPPET }
217
- return resultTemp;
228
+ return select(
229
+ resultTemp, ${ dTypeN } (valueForNaN),
230
+ ${ boolN } (isNaN) | aIsNaN | bIsNaN);
218
231
}
219
232
` ;
220
233
} while ( false ) ;
@@ -256,6 +269,10 @@ export function getBinaryOpString(
256
269
case BinaryOpType . SUB :
257
270
return SUB ;
258
271
default :
259
- throw new Error ( `BinaryType ${ type } is not implemented!` ) ;
272
+ // throw new Error(`BinaryType ${type} is not implemented!`);
260
273
}
274
+ return `
275
+ ${ doOpSnippet }
276
+ return resultTemp;
277
+ ` ;
261
278
}
0 commit comments