@@ -5,20 +5,19 @@ which is then placed in bits 16 × i through 16 × i + 15 of the result.
5
5
` ;
6
6
7
7
import { makeTestGroup } from '../../../../../../common/framework/test_group.js' ;
8
- import { assert } from '../../../../../../common/util/util.js' ;
9
8
import { GPUTest } from '../../../../../gpu_test.js' ;
10
- import { anyOf , Comparator } from '../../../../../util/compare.js' ;
9
+ import { anyOf , skipUndefined } from '../../../../../util/compare.js' ;
11
10
import {
12
11
f32 ,
13
12
pack2x16float ,
14
- Scalar ,
15
13
TypeF32 ,
16
14
TypeU32 ,
17
15
TypeVec ,
18
16
u32 ,
19
17
vec2 ,
20
18
} from '../../../../../util/conversion.js' ;
21
19
import { cartesianProduct , fullF32Range , quantizeToF32 } from '../../../../../util/math.js' ;
20
+ import { makeCaseCache } from '../../case_cache.js' ;
22
21
import { allInputSources , Case , run } from '../../expression.js' ;
23
22
24
23
import { builtin } from './builtin.js' ;
@@ -28,29 +27,6 @@ export const g = makeTestGroup(GPUTest);
28
27
// pack2x16float has somewhat unusual behaviour, specifically around how it is
29
28
// supposed to behave when values go OOB and when they are considered to have
30
29
// gone OOB, so has its own bespoke implementation.
31
- //
32
- // The use of a custom Comparator prevents easy serialization in the case cache,
33
- // https://github.com/gpuweb/cts/issues/2077
34
-
35
- /**
36
- * @returns a custom comparator for a possible result from pack2x16float
37
- * @param expectation element of the array generated by pack2x16float
38
- */
39
- function cmp ( expectation : number | undefined ) : Comparator {
40
- return got => {
41
- assert ( got instanceof Scalar , `Received non-Scalar Value in pack2x16float comparator` ) ;
42
- let matched = true ;
43
- if ( expectation !== undefined ) {
44
- matched = ( got . value as number ) === expectation ;
45
- }
46
-
47
- return {
48
- matched,
49
- got : `${ got } ` ,
50
- expected : `${ expectation !== undefined ? u32 ( expectation ) : 'Any' } ` ,
51
- } ;
52
- } ;
53
- }
54
30
55
31
/**
56
32
* @returns a Case for `pack2x16float`
@@ -68,7 +44,12 @@ function makeCase(param0: number, param1: number, filter_undefined: boolean): Ca
68
44
return undefined ;
69
45
}
70
46
71
- return { input : [ vec2 ( f32 ( param0 ) , f32 ( param1 ) ) ] , expected : anyOf ( ...results . map ( cmp ) ) } ;
47
+ return {
48
+ input : [ vec2 ( f32 ( param0 ) , f32 ( param1 ) ) ] ,
49
+ expected : anyOf (
50
+ ...results . map ( r => ( r === undefined ? skipUndefined ( undefined ) : skipUndefined ( u32 ( r ) ) ) )
51
+ ) ,
52
+ } ;
72
53
}
73
54
74
55
/**
@@ -84,6 +65,15 @@ function generateCases(param0s: number[], param1s: number[], filter_undefined: b
84
65
. filter ( ( c ) : c is Case => c !== undefined ) ;
85
66
}
86
67
68
+ export const d = makeCaseCache ( 'pack2x16float' , {
69
+ f32_const : ( ) => {
70
+ return generateCases ( fullF32Range ( ) , fullF32Range ( ) , true ) ;
71
+ } ,
72
+ f32_non_const : ( ) => {
73
+ return generateCases ( fullF32Range ( ) , fullF32Range ( ) , false ) ;
74
+ } ,
75
+ } ) ;
76
+
87
77
g . test ( 'pack' )
88
78
. specURL ( 'https://www.w3.org/TR/WGSL/#pack-builtin-functions' )
89
79
. desc (
@@ -93,9 +83,6 @@ g.test('pack')
93
83
)
94
84
. params ( u => u . combine ( 'inputSource' , allInputSources ) )
95
85
. fn ( async t => {
96
- const cases =
97
- t . params . inputSource === 'const'
98
- ? generateCases ( fullF32Range ( ) , fullF32Range ( ) , true )
99
- : generateCases ( fullF32Range ( ) , fullF32Range ( ) , false ) ;
86
+ const cases = await d . get ( t . params . inputSource === 'const' ? 'f32_const' : 'f32_non_const' ) ;
100
87
await run ( t , builtin ( 'pack2x16float' ) , [ TypeVec ( 2 , TypeF32 ) ] , TypeU32 , t . params , cases ) ;
101
88
} ) ;
0 commit comments