@@ -2284,6 +2284,7 @@ impl<W: Write> Writer<W> {
22842284 // to signed.
22852285 self . put_bitcasted_expression (
22862286 context. resolve_type ( expr_handle) ,
2287+ expr_handle,
22872288 context,
22882289 & |writer, context, is_scoped| {
22892290 writer. put_binop (
@@ -2295,6 +2296,7 @@ impl<W: Write> Writer<W> {
22952296 & |writer, expr, context, _is_scoped| {
22962297 writer. put_bitcasted_expression (
22972298 & to_unsigned ( context. resolve_type ( expr) ) ?,
2299+ expr,
22982300 context,
22992301 & |writer, context, is_scoped| {
23002302 writer. put_expression ( expr, context, is_scoped)
@@ -3036,6 +3038,7 @@ impl<W: Write> Writer<W> {
30363038 fn put_bitcasted_expression < F > (
30373039 & mut self ,
30383040 cast_to : & crate :: TypeInner ,
3041+ inner_expr : Handle < crate :: Expression > ,
30393042 context : & ExpressionContext ,
30403043 put_expression : & F ,
30413044 ) -> BackendResult
@@ -3051,9 +3054,18 @@ impl<W: Write> Writer<W> {
30513054 _ => return Err ( Error :: UnsupportedBitCast ( cast_to. clone ( ) ) ) ,
30523055 } ;
30533056 write ! ( self . out, ">(" ) ?;
3054- put_expression ( self , context, true ) ?;
3055- write ! ( self . out, ")" ) ?;
30563057
3058+ // if it's packed, we must unpack it (e.g., float3(val)) before the bitcast.
3059+ if let Some ( scalar) = context. get_packed_vec_kind ( inner_expr) {
3060+ put_numeric_type ( & mut self . out , scalar, & [ crate :: VectorSize :: Tri ] ) ?;
3061+ write ! ( self . out, "(" ) ?;
3062+ put_expression ( self , context, true ) ?;
3063+ write ! ( self . out, ")" ) ?;
3064+ } else {
3065+ put_expression ( self , context, true ) ?;
3066+ }
3067+
3068+ write ! ( self . out, ")" ) ?;
30573069 Ok ( ( ) )
30583070 }
30593071
0 commit comments