@@ -7,7 +7,7 @@ use wasm_bindgen_test::*;
7
7
8
8
#[ test]
9
9
#[ wasm_bindgen_test]
10
- fn write_texture_subset ( ) {
10
+ fn write_texture_subset_2d ( ) {
11
11
let size = 256 ;
12
12
let parameters = TestParameters :: default ( ) . backend_failure ( wgpu:: Backends :: DX12 ) ;
13
13
initialize_test ( parameters, |ctx| {
@@ -99,3 +99,99 @@ fn write_texture_subset() {
99
99
}
100
100
} ) ;
101
101
}
102
+
103
+ #[ test]
104
+ #[ wasm_bindgen_test]
105
+ fn write_texture_subset_3d ( ) {
106
+ let size = 256 ;
107
+ let depth = 4 ;
108
+ let parameters = TestParameters :: default ( ) ;
109
+ initialize_test ( parameters, |ctx| {
110
+ let tex = ctx. device . create_texture ( & wgpu:: TextureDescriptor {
111
+ label : None ,
112
+ dimension : wgpu:: TextureDimension :: D2 ,
113
+ size : wgpu:: Extent3d {
114
+ width : size,
115
+ height : size,
116
+ depth_or_array_layers : depth,
117
+ } ,
118
+ format : wgpu:: TextureFormat :: R8Uint ,
119
+ usage : wgpu:: TextureUsages :: COPY_DST
120
+ | wgpu:: TextureUsages :: COPY_SRC
121
+ | wgpu:: TextureUsages :: TEXTURE_BINDING ,
122
+ mip_level_count : 1 ,
123
+ sample_count : 1 ,
124
+ view_formats : & [ ] ,
125
+ } ) ;
126
+ let data = vec ! [ 1u8 ; ( size * size) as usize * 2 ] ;
127
+ // Write the first two slices
128
+ ctx. queue . write_texture (
129
+ wgpu:: ImageCopyTexture {
130
+ texture : & tex,
131
+ mip_level : 0 ,
132
+ origin : wgpu:: Origin3d :: ZERO ,
133
+ aspect : wgpu:: TextureAspect :: All ,
134
+ } ,
135
+ bytemuck:: cast_slice ( & data) ,
136
+ wgpu:: ImageDataLayout {
137
+ offset : 0 ,
138
+ bytes_per_row : std:: num:: NonZeroU32 :: new ( size) ,
139
+ rows_per_image : std:: num:: NonZeroU32 :: new ( size) ,
140
+ } ,
141
+ wgpu:: Extent3d {
142
+ width : size,
143
+ height : size,
144
+ depth_or_array_layers : 2 ,
145
+ } ,
146
+ ) ;
147
+
148
+ ctx. queue . submit ( None ) ;
149
+
150
+ let read_buffer = ctx. device . create_buffer ( & wgpu:: BufferDescriptor {
151
+ label : None ,
152
+ size : ( size * size * depth) as u64 ,
153
+ usage : wgpu:: BufferUsages :: MAP_READ | wgpu:: BufferUsages :: COPY_DST ,
154
+ mapped_at_creation : false ,
155
+ } ) ;
156
+
157
+ let mut encoder = ctx
158
+ . device
159
+ . create_command_encoder ( & wgpu:: CommandEncoderDescriptor { label : None } ) ;
160
+
161
+ encoder. copy_texture_to_buffer (
162
+ wgpu:: ImageCopyTexture {
163
+ texture : & tex,
164
+ mip_level : 0 ,
165
+ origin : wgpu:: Origin3d :: ZERO ,
166
+ aspect : wgpu:: TextureAspect :: All ,
167
+ } ,
168
+ wgpu:: ImageCopyBuffer {
169
+ buffer : & read_buffer,
170
+ layout : wgpu:: ImageDataLayout {
171
+ offset : 0 ,
172
+ bytes_per_row : NonZeroU32 :: new ( size) ,
173
+ rows_per_image : NonZeroU32 :: new ( size) ,
174
+ } ,
175
+ } ,
176
+ wgpu:: Extent3d {
177
+ width : size,
178
+ height : size,
179
+ depth_or_array_layers : depth,
180
+ } ,
181
+ ) ;
182
+
183
+ ctx. queue . submit ( Some ( encoder. finish ( ) ) ) ;
184
+
185
+ let slice = read_buffer. slice ( ..) ;
186
+ slice. map_async ( wgpu:: MapMode :: Read , |_| ( ) ) ;
187
+ ctx. device . poll ( wgpu:: Maintain :: Wait ) ;
188
+ let data: Vec < u8 > = slice. get_mapped_range ( ) . to_vec ( ) ;
189
+
190
+ for byte in & data[ ..( ( size * size) as usize * 2 ) ] {
191
+ assert_eq ! ( * byte, 1 ) ;
192
+ }
193
+ for byte in & data[ ( ( size * size) as usize * 2 ) ..] {
194
+ assert_eq ! ( * byte, 0 ) ;
195
+ }
196
+ } ) ;
197
+ }
0 commit comments