@@ -91,9 +91,51 @@ void kore_webgpu_command_list_copy_buffer_to_texture(kore_gpu_command_list *list
9191 const kore_gpu_image_copy_texture * destination , uint32_t width , uint32_t height ,
9292 uint32_t depth_or_array_layers ) {}
9393
94+ static WGPUTextureAspect convert_texture_aspect (kore_gpu_texture_aspect aspect ) {
95+ switch (aspect ) {
96+ case KORE_GPU_IMAGE_COPY_ASPECT_ALL :
97+ return WGPUTextureAspect_All ;
98+ case KORE_GPU_IMAGE_COPY_ASPECT_DEPTH_ONLY :
99+ return WGPUTextureAspect_DepthOnly ;
100+ case KORE_GPU_IMAGE_COPY_ASPECT_STENCIL_ONLY :
101+ return WGPUTextureAspect_StencilOnly ;
102+ }
103+
104+ assert (false);
105+ return WGPUTextureAspect_All ;
106+ }
107+
94108void kore_webgpu_command_list_copy_texture_to_buffer (kore_gpu_command_list * list , const kore_gpu_image_copy_texture * source ,
95109 const kore_gpu_image_copy_buffer * destination , uint32_t width , uint32_t height ,
96- uint32_t depth_or_array_layers ) {}
110+ uint32_t depth_or_array_layers ) {
111+ WGPUImageCopyTexture copy_texture = {
112+ .texture = source -> texture -> webgpu .texture ,
113+ .mipLevel = source -> mip_level ,
114+ .origin = {
115+ .x = source -> origin_x ,
116+ .y = source -> origin_y ,
117+ .z = source -> origin_z ,
118+ },
119+ .aspect = convert_texture_aspect (source -> aspect ),
120+ };
121+
122+ WGPUImageCopyBuffer copy_buffer = {
123+ .layout = {
124+ .offset = destination -> offset ,
125+ .bytesPerRow = destination -> bytes_per_row ,
126+ .rowsPerImage = destination -> rows_per_image ,
127+ },
128+ .buffer = destination -> buffer -> webgpu .buffer ,
129+ };
130+
131+ WGPUExtent3D size = {
132+ .width = width ,
133+ .height = height ,
134+ .depthOrArrayLayers = depth_or_array_layers ,
135+ };
136+
137+ wgpuCommandEncoderCopyTextureToBuffer (list -> webgpu .command_encoder , & copy_texture , & copy_buffer , & size );
138+ }
97139
98140void kore_webgpu_command_list_copy_texture_to_texture (kore_gpu_command_list * list , const kore_gpu_image_copy_texture * source ,
99141 const kore_gpu_image_copy_texture * destination , uint32_t width , uint32_t height ,
0 commit comments