Skip to content

Copying CPU buffer to GPU buffer bug on Linux/Vulkan #2480

@KeKsBoTer

Description

@KeKsBoTer

Description
Copying an image buffer from CPU to GPU texture with write_texture gives unexpected result on linux.

Repro steps

  1. Create texture
  let frame_buffer = device.create_texture(&wgpu::TextureDescriptor {
            label: None,
            size: Extent3d {
                width: 100,
                height: 100,
                depth_or_array_layers: 1,
            },
            mip_level_count: 1,
            sample_count: 1,
            dimension: wgpu::TextureDimension::D2,
            format: wgpu::TextureFormat::Rgba8Unorm,
            usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
        });
  1. Create CPU buffer and write some data into it
let mut cpu_buffer = vec![0u8;100*100*4];
for i in 0..100{
    for i in 0..100{
         let index = (i*100+j)*4;
         // write some data here
         cpu_buffer[index] = i as u8;
         cpu_buffer[index+1] = 0;
         cpu_buffer[index+2] = 0;
         cpu_buffer[index+3] = 255;
    }
}
  1. copy data to GPU buffer with write_texture
queue.write_texture(
   frame_buffer.as_image_copy(),
   &cpu_buffer,
   wgpu::ImageDataLayout {
       offset: 0,
       bytes_per_row: Some(std::num::NonZeroU32::new(100 * 4).unwrap()),
       rows_per_image: None,
   },
   wgpu::Extent3d {
       width: 100,
       height: 100,
       depth_or_array_layers: 1,
   },
);
  1. Render texture to screen

Expected vs observed behavior

Image on linux looks like on macOS.
But image on linux is distorted.

Screenshot macOS
Screenshot Linux

Extra materials

I used only the column number as red value:

100x100 image where red equals column

I used only the row number as red value:

100x100 image where red equals row

Platform
Linux (Ubuntu 21.10)
macOS (12.2.1)

wgpu (0.12.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend: vulkanIssues with Vulkanexternal: driver-bugA driver is causing the bug, though we may still want to work around it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions