1
1
#![ no_std]
2
2
3
+ use difftest:: round6;
3
4
use spirv_std:: glam:: { Mat2 , Mat3 , Mat4 , UVec3 , Vec2 , Vec3 , Vec4 } ;
4
5
#[ allow( unused_imports) ]
5
6
use spirv_std:: num_traits:: Float ;
@@ -35,10 +36,10 @@ pub fn main_cs(
35
36
36
37
// Mat2 multiplication
37
38
let m2_mul = m2a * m2b;
38
- output[ base_offset + 0 ] = m2_mul. col ( 0 ) . x ;
39
- output[ base_offset + 1 ] = m2_mul. col ( 0 ) . y ;
40
- output[ base_offset + 2 ] = m2_mul. col ( 1 ) . x ;
41
- output[ base_offset + 3 ] = m2_mul. col ( 1 ) . y ;
39
+ output[ base_offset + 0 ] = round6 ! ( m2_mul. col( 0 ) . x) ;
40
+ output[ base_offset + 1 ] = round6 ! ( m2_mul. col( 0 ) . y) ;
41
+ output[ base_offset + 2 ] = round6 ! ( m2_mul. col( 1 ) . x) ;
42
+ output[ base_offset + 3 ] = round6 ! ( m2_mul. col( 1 ) . y) ;
42
43
43
44
// Mat2 transpose
44
45
let m2_transpose = m2a. transpose ( ) ;
@@ -48,29 +49,29 @@ pub fn main_cs(
48
49
output[ base_offset + 7 ] = m2_transpose. col ( 1 ) . y ;
49
50
50
51
// Mat2 determinant (with rounding for consistency)
51
- output[ base_offset + 8 ] = ( m2a. determinant ( ) * 1000.0 ) . round ( ) / 1000.0 ;
52
+ output[ base_offset + 8 ] = round6 ! ( m2a. determinant( ) ) ;
52
53
53
54
// Mat2 * Vec2
54
55
let v2 = Vec2 :: new ( 1.0 , 2.0 ) ;
55
56
let m2_v2 = m2a * v2;
56
- output[ base_offset + 9 ] = m2_v2. x ;
57
- output[ base_offset + 10 ] = m2_v2. y ;
57
+ output[ base_offset + 9 ] = round6 ! ( m2_v2. x) ;
58
+ output[ base_offset + 10 ] = round6 ! ( m2_v2. y) ;
58
59
59
60
// Mat3 operations
60
61
let m3a = Mat3 :: from_cols ( Vec3 :: new ( a, b, c) , Vec3 :: new ( b, c, d) , Vec3 :: new ( c, d, a) ) ;
61
62
let m3b = Mat3 :: from_cols ( Vec3 :: new ( d, c, b) , Vec3 :: new ( c, b, a) , Vec3 :: new ( b, a, d) ) ;
62
63
63
64
// Mat3 multiplication
64
65
let m3_mul = m3a * m3b;
65
- output[ base_offset + 11 ] = m3_mul. col ( 0 ) . x ;
66
- output[ base_offset + 12 ] = m3_mul. col ( 0 ) . y ;
67
- output[ base_offset + 13 ] = m3_mul. col ( 0 ) . z ;
68
- output[ base_offset + 14 ] = m3_mul. col ( 1 ) . x ;
69
- output[ base_offset + 15 ] = m3_mul. col ( 1 ) . y ;
70
- output[ base_offset + 16 ] = m3_mul. col ( 1 ) . z ;
71
- output[ base_offset + 17 ] = m3_mul. col ( 2 ) . x ;
72
- output[ base_offset + 18 ] = m3_mul. col ( 2 ) . y ;
73
- output[ base_offset + 19 ] = m3_mul. col ( 2 ) . z ;
66
+ output[ base_offset + 11 ] = round6 ! ( m3_mul. col( 0 ) . x) ;
67
+ output[ base_offset + 12 ] = round6 ! ( m3_mul. col( 0 ) . y) ;
68
+ output[ base_offset + 13 ] = round6 ! ( m3_mul. col( 0 ) . z) ;
69
+ output[ base_offset + 14 ] = round6 ! ( m3_mul. col( 1 ) . x) ;
70
+ output[ base_offset + 15 ] = round6 ! ( m3_mul. col( 1 ) . y) ;
71
+ output[ base_offset + 16 ] = round6 ! ( m3_mul. col( 1 ) . z) ;
72
+ output[ base_offset + 17 ] = round6 ! ( m3_mul. col( 2 ) . x) ;
73
+ output[ base_offset + 18 ] = round6 ! ( m3_mul. col( 2 ) . y) ;
74
+ output[ base_offset + 19 ] = round6 ! ( m3_mul. col( 2 ) . z) ;
74
75
75
76
// Mat3 transpose - store just diagonal elements
76
77
let m3_transpose = m3a. transpose ( ) ;
@@ -79,14 +80,14 @@ pub fn main_cs(
79
80
output[ base_offset + 22 ] = m3_transpose. col ( 2 ) . z ;
80
81
81
82
// Mat3 determinant (with rounding for consistency)
82
- output[ base_offset + 23 ] = ( m3a. determinant ( ) * 1000.0 ) . round ( ) / 1000.0 ;
83
+ output[ base_offset + 23 ] = round6 ! ( m3a. determinant( ) ) ;
83
84
84
85
// Mat3 * Vec3 (with rounding for consistency)
85
86
let v3 = Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ;
86
87
let m3_v3 = m3a * v3;
87
- output[ base_offset + 24 ] = ( m3_v3. x * 10000.0 ) . round ( ) / 10000.0 ;
88
- output[ base_offset + 25 ] = ( m3_v3. y * 10000.0 ) . round ( ) / 10000.0 ;
89
- output[ base_offset + 26 ] = ( m3_v3. z * 10000.0 ) . round ( ) / 10000.0 ;
88
+ output[ base_offset + 24 ] = round6 ! ( m3_v3. x) ;
89
+ output[ base_offset + 25 ] = round6 ! ( m3_v3. y) ;
90
+ output[ base_offset + 26 ] = round6 ! ( m3_v3. z) ;
90
91
91
92
// Mat4 operations
92
93
let m4a = Mat4 :: from_cols (
@@ -104,10 +105,10 @@ pub fn main_cs(
104
105
105
106
// Mat4 multiplication (just store diagonal for brevity)
106
107
let m4_mul = m4a * m4b;
107
- output[ base_offset + 27 ] = m4_mul. col ( 0 ) . x ;
108
- output[ base_offset + 28 ] = m4_mul. col ( 1 ) . y ;
109
- output[ base_offset + 29 ] = m4_mul. col ( 2 ) . z ;
110
- output[ base_offset + 30 ] = m4_mul. col ( 3 ) . w ;
108
+ output[ base_offset + 27 ] = round6 ! ( m4_mul. col( 0 ) . x) ;
109
+ output[ base_offset + 28 ] = round6 ! ( m4_mul. col( 1 ) . y) ;
110
+ output[ base_offset + 29 ] = round6 ! ( m4_mul. col( 2 ) . z) ;
111
+ output[ base_offset + 30 ] = round6 ! ( m4_mul. col( 3 ) . w) ;
111
112
112
113
// Mat4 transpose (just store diagonal)
113
114
let m4_transpose = m4a. transpose ( ) ;
@@ -117,15 +118,15 @@ pub fn main_cs(
117
118
output[ base_offset + 34 ] = m4_transpose. col ( 3 ) . w ;
118
119
119
120
// Mat4 determinant (with rounding for consistency)
120
- output[ base_offset + 35 ] = ( m4a. determinant ( ) * 1000.0 ) . round ( ) / 1000.0 ;
121
+ output[ base_offset + 35 ] = round6 ! ( m4a. determinant( ) ) ;
121
122
122
123
// Mat4 * Vec4 (with rounding for consistency)
123
124
let v4 = Vec4 :: new ( 1.0 , 2.0 , 3.0 , 4.0 ) ;
124
125
let m4_v4 = m4a * v4;
125
- output[ base_offset + 36 ] = ( m4_v4. x * 10000.0 ) . round ( ) / 10000.0 ;
126
- output[ base_offset + 37 ] = ( m4_v4. y * 10000.0 ) . round ( ) / 10000.0 ;
127
- output[ base_offset + 38 ] = ( m4_v4. z * 10000.0 ) . round ( ) / 10000.0 ;
128
- output[ base_offset + 39 ] = ( m4_v4. w * 10000.0 ) . round ( ) / 10000.0 ;
126
+ output[ base_offset + 36 ] = round6 ! ( m4_v4. x) ;
127
+ output[ base_offset + 37 ] = round6 ! ( m4_v4. y) ;
128
+ output[ base_offset + 38 ] = round6 ! ( m4_v4. z) ;
129
+ output[ base_offset + 39 ] = round6 ! ( m4_v4. w) ;
129
130
130
131
// Identity matrices
131
132
output[ base_offset + 40 ] = Mat2 :: IDENTITY . col ( 0 ) . x ;
@@ -135,8 +136,8 @@ pub fn main_cs(
135
136
// Matrix inverse
136
137
if m2a. determinant ( ) . abs ( ) > 0.0001 {
137
138
let m2_inv = m2a. inverse ( ) ;
138
- output[ base_offset + 43 ] = m2_inv. col ( 0 ) . x ;
139
- output[ base_offset + 44 ] = m2_inv. col ( 1 ) . y ;
139
+ output[ base_offset + 43 ] = round6 ! ( m2_inv. col( 0 ) . x) ;
140
+ output[ base_offset + 44 ] = round6 ! ( m2_inv. col( 1 ) . y) ;
140
141
} else {
141
142
output[ base_offset + 43 ] = 0.0 ;
142
143
output[ base_offset + 44 ] = 0.0 ;
0 commit comments