@@ -2891,37 +2891,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
2891
2891
//
2892
2892
// Note that this only works for `Load`s and we handle
2893
2893
// `Store`s differently in `Statement::Store`.
2894
- let cx2_columns;
2895
2894
if let Some ( MatrixType {
2896
2895
columns,
2897
2896
rows : crate :: VectorSize :: Bi ,
2898
2897
width : 4 ,
2899
2898
} ) = get_inner_matrix_of_struct_array_member ( module, base, func_ctx, true )
2899
+ . or_else ( || get_global_uniform_matrix ( module, base, func_ctx) )
2900
2900
{
2901
- cx2_columns = Some ( columns) ;
2902
- } else {
2903
- let base_tr = func_ctx
2904
- . resolve_type ( base, & module. types )
2905
- . pointer_base_type ( ) ;
2906
- let base_ty = base_tr. as_ref ( ) . map ( |tr| tr. inner_with ( & module. types ) ) ;
2907
- match ( & func_ctx. expressions [ base] , base_ty) {
2908
- (
2909
- & Expression :: GlobalVariable ( handle) ,
2910
- Some ( & TypeInner :: Matrix {
2911
- columns,
2912
- rows : crate :: VectorSize :: Bi ,
2913
- ..
2914
- } ) ,
2915
- ) if module. global_variables [ handle] . space
2916
- == crate :: AddressSpace :: Uniform =>
2917
- {
2918
- cx2_columns = Some ( columns) ;
2919
- }
2920
- _ => cx2_columns = None ,
2921
- }
2922
- }
2923
-
2924
- if let Some ( columns) = cx2_columns {
2925
2901
write ! ( self . out, "__get_col_of_mat{}x2(" , columns as u8 ) ?;
2926
2902
self . write_expr ( module, base, func_ctx) ?;
2927
2903
write ! ( self . out, ", " ) ?;
@@ -3033,38 +3009,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
3033
3009
{
3034
3010
// do nothing, the chain is written on `Load`/`Store`
3035
3011
} else {
3036
- // We write the matrix column access in a special way since
3037
- // the type of `base` is our special __matCx2 struct.
3038
- let is_cx2 ;
3012
+ // See if we need to write the matrix column access in a
3013
+ // special way since the type of `base` is our special
3014
+ // __matCx2 struct.
3039
3015
if let Some ( MatrixType {
3040
3016
rows : crate :: VectorSize :: Bi ,
3041
3017
width : 4 ,
3042
3018
..
3043
3019
} ) = get_inner_matrix_of_struct_array_member ( module, base, func_ctx, true )
3020
+ . or_else ( || get_global_uniform_matrix ( module, base, func_ctx) )
3044
3021
{
3045
- is_cx2 = true ;
3046
- } else {
3047
- let base_tr = func_ctx
3048
- . resolve_type ( base, & module. types )
3049
- . pointer_base_type ( ) ;
3050
- let base_ty = base_tr. as_ref ( ) . map ( |tr| tr. inner_with ( & module. types ) ) ;
3051
- match ( & func_ctx. expressions [ base] , base_ty) {
3052
- (
3053
- & Expression :: GlobalVariable ( handle) ,
3054
- Some ( & TypeInner :: Matrix {
3055
- rows : crate :: VectorSize :: Bi ,
3056
- ..
3057
- } ) ,
3058
- ) if module. global_variables [ handle] . space
3059
- == crate :: AddressSpace :: Uniform =>
3060
- {
3061
- is_cx2 = true ;
3062
- }
3063
- _ => is_cx2 = false ,
3064
- }
3065
- }
3066
-
3067
- if is_cx2 {
3068
3022
self . write_expr ( module, base, func_ctx) ?;
3069
3023
write ! ( self . out, "._{index}" ) ?;
3070
3024
return Ok ( ( ) ) ;
@@ -4497,6 +4451,36 @@ pub(super) fn get_inner_matrix_of_struct_array_member(
4497
4451
None
4498
4452
}
4499
4453
4454
+ /// Simpler version of get_inner_matrix_of_global_uniform that only looks at the
4455
+ /// immediate expression, rather than traversing an access chain.
4456
+ fn get_global_uniform_matrix (
4457
+ module : & Module ,
4458
+ base : Handle < crate :: Expression > ,
4459
+ func_ctx : & back:: FunctionCtx < ' _ > ,
4460
+ ) -> Option < MatrixType > {
4461
+ let base_tr = func_ctx
4462
+ . resolve_type ( base, & module. types )
4463
+ . pointer_base_type ( ) ;
4464
+ let base_ty = base_tr. as_ref ( ) . map ( |tr| tr. inner_with ( & module. types ) ) ;
4465
+ match ( & func_ctx. expressions [ base] , base_ty) {
4466
+ (
4467
+ & crate :: Expression :: GlobalVariable ( handle) ,
4468
+ Some ( & TypeInner :: Matrix {
4469
+ columns,
4470
+ rows,
4471
+ scalar,
4472
+ } ) ,
4473
+ ) if module. global_variables [ handle] . space == crate :: AddressSpace :: Uniform => {
4474
+ Some ( MatrixType {
4475
+ columns,
4476
+ rows,
4477
+ width : scalar. width ,
4478
+ } )
4479
+ }
4480
+ _ => None ,
4481
+ }
4482
+ }
4483
+
4500
4484
/// Returns the matrix data if the access chain starting at `base`:
4501
4485
/// - starts with an expression with resolved type of [`TypeInner::Matrix`]
4502
4486
/// - contains zero or more expressions with resolved type of [`TypeInner::Array`] of [`TypeInner::Matrix`]
0 commit comments