@@ -159,12 +159,8 @@ pub enum CopyError {
159
159
pub ( crate ) fn extract_texture_selector < A : hal:: Api > (
160
160
copy_texture : & ImageCopyTexture ,
161
161
copy_size : & Extent3d ,
162
- texture_guard : & Storage < Texture < A > , TextureId > ,
162
+ texture : & Texture < A > ,
163
163
) -> Result < ( TextureSelector , hal:: TextureCopyBase , wgt:: TextureFormat ) , TransferError > {
164
- let texture = texture_guard
165
- . get ( copy_texture. texture )
166
- . map_err ( |_| TransferError :: InvalidTexture ( copy_texture. texture ) ) ?;
167
-
168
164
let format = texture. desc . format ;
169
165
let copy_aspect =
170
166
hal:: FormatAspects :: from ( format) & hal:: FormatAspects :: from ( copy_texture. aspect ) ;
@@ -710,8 +706,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
710
706
return Ok ( ( ) ) ;
711
707
}
712
708
709
+ let dst_texture = texture_guard
710
+ . get ( destination. texture )
711
+ . map_err ( |_| TransferError :: InvalidTexture ( destination. texture ) ) ?;
712
+
713
+ let ( hal_copy_size, array_layer_count) = validate_texture_copy_range (
714
+ destination,
715
+ & dst_texture. desc ,
716
+ CopySide :: Destination ,
717
+ copy_size,
718
+ ) ?;
719
+
713
720
let ( dst_range, dst_base, _) =
714
- extract_texture_selector ( destination, copy_size, & * texture_guard ) ?;
721
+ extract_texture_selector ( destination, copy_size, dst_texture ) ?;
715
722
716
723
// Handle texture init *before* dealing with barrier transitions so we
717
724
// have an easier time inserting "immediate-inits" that may be required
@@ -732,11 +739,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
732
739
}
733
740
let src_barrier = src_pending. map ( |pending| pending. into_hal ( src_buffer) ) ;
734
741
735
- let ( dst_texture , dst_pending) = cmd_buf
742
+ let dst_pending = cmd_buf
736
743
. trackers
737
744
. textures
738
745
. set_single (
739
- & * texture_guard ,
746
+ dst_texture ,
740
747
destination. texture ,
741
748
dst_range,
742
749
hal:: TextureUses :: COPY_DST ,
@@ -754,12 +761,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
754
761
let dst_barrier = dst_pending. map ( |pending| pending. into_hal ( dst_texture) ) ;
755
762
756
763
let format_desc = dst_texture. desc . format . describe ( ) ;
757
- let ( hal_copy_size, array_layer_count) = validate_texture_copy_range (
758
- destination,
759
- & dst_texture. desc ,
760
- CopySide :: Destination ,
761
- copy_size,
762
- ) ?;
763
764
let ( required_buffer_bytes_in_copy, bytes_per_array_layer) = validate_linear_texture_data (
764
765
& source. layout ,
765
766
dst_texture. desc . format ,
@@ -839,19 +840,25 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
839
840
return Ok ( ( ) ) ;
840
841
}
841
842
842
- let ( src_range, src_base, _) =
843
- extract_texture_selector ( source, copy_size, & * texture_guard) ?;
843
+ let src_texture = texture_guard
844
+ . get ( source. texture )
845
+ . map_err ( |_| TransferError :: InvalidTexture ( source. texture ) ) ?;
846
+
847
+ let ( hal_copy_size, array_layer_count) =
848
+ validate_texture_copy_range ( source, & src_texture. desc , CopySide :: Source , copy_size) ?;
849
+
850
+ let ( src_range, src_base, _) = extract_texture_selector ( source, copy_size, src_texture) ?;
844
851
845
852
// Handle texture init *before* dealing with barrier transitions so we
846
853
// have an easier time inserting "immediate-inits" that may be required
847
854
// by prior discards in rare cases.
848
855
handle_src_texture_init ( cmd_buf, device, source, copy_size, & texture_guard) ?;
849
856
850
- let ( src_texture , src_pending) = cmd_buf
857
+ let src_pending = cmd_buf
851
858
. trackers
852
859
. textures
853
860
. set_single (
854
- & * texture_guard ,
861
+ src_texture ,
855
862
source. texture ,
856
863
src_range,
857
864
hal:: TextureUses :: COPY_SRC ,
@@ -900,8 +907,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
900
907
let dst_barrier = dst_pending. map ( |pending| pending. into_hal ( dst_buffer) ) ;
901
908
902
909
let format_desc = src_texture. desc . format . describe ( ) ;
903
- let ( hal_copy_size, array_layer_count) =
904
- validate_texture_copy_range ( source, & src_texture. desc , CopySide :: Source , copy_size) ?;
905
910
let ( required_buffer_bytes_in_copy, bytes_per_array_layer) = validate_linear_texture_data (
906
911
& destination. layout ,
907
912
src_texture. desc . format ,
@@ -998,10 +1003,37 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
998
1003
return Ok ( ( ) ) ;
999
1004
}
1000
1005
1006
+ let src_texture = texture_guard
1007
+ . get ( source. texture )
1008
+ . map_err ( |_| TransferError :: InvalidTexture ( source. texture ) ) ?;
1009
+ let dst_texture = texture_guard
1010
+ . get ( destination. texture )
1011
+ . map_err ( |_| TransferError :: InvalidTexture ( source. texture ) ) ?;
1012
+
1013
+ // src and dst texture format must be the same.
1014
+ let src_format = src_texture. desc . format ;
1015
+ let dst_format = dst_texture. desc . format ;
1016
+ if src_format != dst_format {
1017
+ return Err ( TransferError :: MismatchedTextureFormats {
1018
+ src_format,
1019
+ dst_format,
1020
+ }
1021
+ . into ( ) ) ;
1022
+ }
1023
+
1024
+ let ( src_copy_size, array_layer_count) =
1025
+ validate_texture_copy_range ( source, & src_texture. desc , CopySide :: Source , copy_size) ?;
1026
+ let ( dst_copy_size, _) = validate_texture_copy_range (
1027
+ destination,
1028
+ & dst_texture. desc ,
1029
+ CopySide :: Destination ,
1030
+ copy_size,
1031
+ ) ?;
1032
+
1001
1033
let ( src_range, src_tex_base, _) =
1002
- extract_texture_selector ( source, copy_size, & * texture_guard ) ?;
1034
+ extract_texture_selector ( source, copy_size, src_texture ) ?;
1003
1035
let ( dst_range, dst_tex_base, _) =
1004
- extract_texture_selector ( destination, copy_size, & * texture_guard ) ?;
1036
+ extract_texture_selector ( destination, copy_size, dst_texture ) ?;
1005
1037
if src_tex_base. aspect != dst_tex_base. aspect {
1006
1038
return Err ( TransferError :: MismatchedAspects . into ( ) ) ;
1007
1039
}
@@ -1012,11 +1044,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
1012
1044
handle_src_texture_init ( cmd_buf, device, source, copy_size, & texture_guard) ?;
1013
1045
handle_dst_texture_init ( cmd_buf, device, destination, copy_size, & texture_guard) ?;
1014
1046
1015
- let ( src_texture , src_pending) = cmd_buf
1047
+ let src_pending = cmd_buf
1016
1048
. trackers
1017
1049
. textures
1018
1050
. set_single (
1019
- & * texture_guard ,
1051
+ src_texture ,
1020
1052
source. texture ,
1021
1053
src_range,
1022
1054
hal:: TextureUses :: COPY_SRC ,
@@ -1037,11 +1069,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
1037
1069
. into_iter ( )
1038
1070
. collect ( ) ;
1039
1071
1040
- let ( dst_texture , dst_pending) = cmd_buf
1072
+ let dst_pending = cmd_buf
1041
1073
. trackers
1042
1074
. textures
1043
1075
. set_single (
1044
- & * texture_guard ,
1076
+ dst_texture ,
1045
1077
destination. texture ,
1046
1078
dst_range,
1047
1079
hal:: TextureUses :: COPY_DST ,
@@ -1057,29 +1089,8 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
1057
1089
) ;
1058
1090
}
1059
1091
1060
- // src and dst texture format must be the same.
1061
- let src_format = src_texture. desc . format ;
1062
- let dst_format = dst_texture. desc . format ;
1063
-
1064
- if src_format != dst_format {
1065
- return Err ( TransferError :: MismatchedTextureFormats {
1066
- src_format,
1067
- dst_format,
1068
- }
1069
- . into ( ) ) ;
1070
- }
1071
-
1072
1092
barriers. extend ( dst_pending. map ( |pending| pending. into_hal ( dst_texture) ) ) ;
1073
1093
1074
- let ( src_copy_size, array_layer_count) =
1075
- validate_texture_copy_range ( source, & src_texture. desc , CopySide :: Source , copy_size) ?;
1076
- let ( dst_copy_size, _) = validate_texture_copy_range (
1077
- destination,
1078
- & dst_texture. desc ,
1079
- CopySide :: Destination ,
1080
- copy_size,
1081
- ) ?;
1082
-
1083
1094
let hal_copy_size = hal:: CopyExtent {
1084
1095
width : src_copy_size. width . min ( dst_copy_size. width ) ,
1085
1096
height : src_copy_size. height . min ( dst_copy_size. height ) ,
0 commit comments