11#![ no_std]
22
3+ use difftest:: round6;
34use spirv_std:: glam:: { Mat2 , Mat3 , Mat4 , UVec3 , Vec2 , Vec3 , Vec4 } ;
45#[ allow( unused_imports) ]
56use spirv_std:: num_traits:: Float ;
@@ -35,10 +36,10 @@ pub fn main_cs(
3536
3637 // Mat2 multiplication
3738 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) ;
4243
4344 // Mat2 transpose
4445 let m2_transpose = m2a. transpose ( ) ;
@@ -48,29 +49,29 @@ pub fn main_cs(
4849 output[ base_offset + 7 ] = m2_transpose. col ( 1 ) . y ;
4950
5051 // 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( ) ) ;
5253
5354 // Mat2 * Vec2
5455 let v2 = Vec2 :: new ( 1.0 , 2.0 ) ;
5556 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) ;
5859
5960 // Mat3 operations
6061 let m3a = Mat3 :: from_cols ( Vec3 :: new ( a, b, c) , Vec3 :: new ( b, c, d) , Vec3 :: new ( c, d, a) ) ;
6162 let m3b = Mat3 :: from_cols ( Vec3 :: new ( d, c, b) , Vec3 :: new ( c, b, a) , Vec3 :: new ( b, a, d) ) ;
6263
6364 // Mat3 multiplication
6465 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) ;
7475
7576 // Mat3 transpose - store just diagonal elements
7677 let m3_transpose = m3a. transpose ( ) ;
@@ -79,14 +80,14 @@ pub fn main_cs(
7980 output[ base_offset + 22 ] = m3_transpose. col ( 2 ) . z ;
8081
8182 // 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( ) ) ;
8384
8485 // Mat3 * Vec3 (with rounding for consistency)
8586 let v3 = Vec3 :: new ( 1.0 , 2.0 , 3.0 ) ;
8687 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) ;
9091
9192 // Mat4 operations
9293 let m4a = Mat4 :: from_cols (
@@ -104,10 +105,10 @@ pub fn main_cs(
104105
105106 // Mat4 multiplication (just store diagonal for brevity)
106107 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) ;
111112
112113 // Mat4 transpose (just store diagonal)
113114 let m4_transpose = m4a. transpose ( ) ;
@@ -117,15 +118,15 @@ pub fn main_cs(
117118 output[ base_offset + 34 ] = m4_transpose. col ( 3 ) . w ;
118119
119120 // 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( ) ) ;
121122
122123 // Mat4 * Vec4 (with rounding for consistency)
123124 let v4 = Vec4 :: new ( 1.0 , 2.0 , 3.0 , 4.0 ) ;
124125 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) ;
129130
130131 // Identity matrices
131132 output[ base_offset + 40 ] = Mat2 :: IDENTITY . col ( 0 ) . x ;
@@ -135,8 +136,8 @@ pub fn main_cs(
135136 // Matrix inverse
136137 if m2a. determinant ( ) . abs ( ) > 0.0001 {
137138 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) ;
140141 } else {
141142 output[ base_offset + 43 ] = 0.0 ;
142143 output[ base_offset + 44 ] = 0.0 ;
0 commit comments