@@ -3213,57 +3213,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
32133213 array_index,
32143214 sample,
32153215 level,
3216- } => {
3217- let mut wrapping_type = None ;
3218- match * func_ctx. resolve_type ( image, & module. types ) {
3219- TypeInner :: Image {
3220- class : crate :: ImageClass :: Storage { format, .. } ,
3221- ..
3222- } => {
3223- if format. single_component ( ) {
3224- wrapping_type = Some ( Scalar :: from ( format) ) ;
3225- }
3226- }
3227- _ => { }
3228- }
3229- if let Some ( scalar) = wrapping_type {
3230- write ! (
3231- self . out,
3232- "{}{}(" ,
3233- help:: IMAGE_STORAGE_LOAD_SCALAR_WRAPPER ,
3234- scalar. to_hlsl_str( ) ?
3235- ) ?;
3236- }
3237- // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-load
3238- self . write_expr ( module, image, func_ctx) ?;
3239- write ! ( self . out, ".Load(" ) ?;
3240-
3241- self . write_texture_coordinates (
3242- "int" ,
3243- coordinate,
3244- array_index,
3245- level,
3246- module,
3247- func_ctx,
3248- ) ?;
3249-
3250- if let Some ( sample) = sample {
3251- write ! ( self . out, ", " ) ?;
3252- self . write_expr ( module, sample, func_ctx) ?;
3253- }
3254-
3255- // close bracket for Load function
3256- write ! ( self . out, ")" ) ?;
3257-
3258- if wrapping_type. is_some ( ) {
3259- write ! ( self . out, ")" ) ?;
3260- }
3261-
3262- // return x component if return type is scalar
3263- if let TypeInner :: Scalar ( _) = * func_ctx. resolve_type ( expr, & module. types ) {
3264- write ! ( self . out, ".x" ) ?;
3265- }
3266- }
3216+ } => self . write_image_load (
3217+ & module,
3218+ expr,
3219+ func_ctx,
3220+ image,
3221+ coordinate,
3222+ array_index,
3223+ sample,
3224+ level,
3225+ ) ?,
32673226 Expression :: GlobalVariable ( handle) => {
32683227 let global_variable = & module. global_variables [ handle] ;
32693228 let ty = & module. types [ global_variable. ty ] . inner ;
@@ -4003,6 +3962,63 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
40033962 Ok ( ( ) )
40043963 }
40053964
3965+ #[ allow( clippy:: too_many_arguments) ]
3966+ fn write_image_load (
3967+ & mut self ,
3968+ module : & & Module ,
3969+ expr : Handle < crate :: Expression > ,
3970+ func_ctx : & back:: FunctionCtx ,
3971+ image : Handle < crate :: Expression > ,
3972+ coordinate : Handle < crate :: Expression > ,
3973+ array_index : Option < Handle < crate :: Expression > > ,
3974+ sample : Option < Handle < crate :: Expression > > ,
3975+ level : Option < Handle < crate :: Expression > > ,
3976+ ) -> Result < ( ) , Error > {
3977+ let mut wrapping_type = None ;
3978+ match * func_ctx. resolve_type ( image, & module. types ) {
3979+ TypeInner :: Image {
3980+ class : crate :: ImageClass :: Storage { format, .. } ,
3981+ ..
3982+ } => {
3983+ if format. single_component ( ) {
3984+ wrapping_type = Some ( Scalar :: from ( format) ) ;
3985+ }
3986+ }
3987+ _ => { }
3988+ }
3989+ if let Some ( scalar) = wrapping_type {
3990+ write ! (
3991+ self . out,
3992+ "{}{}(" ,
3993+ help:: IMAGE_STORAGE_LOAD_SCALAR_WRAPPER ,
3994+ scalar. to_hlsl_str( ) ?
3995+ ) ?;
3996+ }
3997+ // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-load
3998+ self . write_expr ( module, image, func_ctx) ?;
3999+ write ! ( self . out, ".Load(" ) ?;
4000+
4001+ self . write_texture_coordinates ( "int" , coordinate, array_index, level, module, func_ctx) ?;
4002+
4003+ if let Some ( sample) = sample {
4004+ write ! ( self . out, ", " ) ?;
4005+ self . write_expr ( module, sample, func_ctx) ?;
4006+ }
4007+
4008+ // close bracket for Load function
4009+ write ! ( self . out, ")" ) ?;
4010+
4011+ if wrapping_type. is_some ( ) {
4012+ write ! ( self . out, ")" ) ?;
4013+ }
4014+
4015+ // return x component if return type is scalar
4016+ if let TypeInner :: Scalar ( _) = * func_ctx. resolve_type ( expr, & module. types ) {
4017+ write ! ( self . out, ".x" ) ?;
4018+ }
4019+ Ok ( ( ) )
4020+ }
4021+
40064022 /// Find the [`BindingArraySamplerInfo`] from an expression so that such an access
40074023 /// can be generated later.
40084024 fn sampler_binding_array_info_from_expression (
0 commit comments