Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
KeKsBoTer opened this issue Feb 15, 2022 · 6 comments
Closed

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

KeKsBoTer opened this issue Feb 15, 2022 · 6 comments
Labels
api: vulkan Issues with Vulkan external: driver-bug A driver is causing the bug, though we may still want to work around it

Comments

@KeKsBoTer
Copy link

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)

@kvark
Copy link
Member

kvark commented Feb 15, 2022

Thank you for filing! Would you be able to modify one of our examples to reproduce the issue? Alternatively, attaching a zipped trace would help - https://github.com/gfx-rs/wgpu/wiki/Debugging-wgpu-Applications#tracing-infrastructure.

@kvark kvark added the type: bug Something isn't working label Feb 15, 2022
@KeKsBoTer
Copy link
Author

Update:

I just realized this issue is only present if I use my integrated GPU (Intel(R) HD Graphics 4600 (HSW GT2) (Vulkan)).
When running on my dedicated GPU (AMD RADV TONGA (Vulkan)) the issue does not occur.

The issue does also occur with the cube example!
image

I created a trace for the cube example: trace.zip

@kvark
Copy link
Member

kvark commented Feb 15, 2022

Wow that's unexpected. I can't reproduce this on my Intel Xe GPU on Linux, from either the example itself or from the trace :(
Looks like we may be dealing with a driver bug here. Would you be able to record the first frame in RenderDoc and shader that capture?

@KeKsBoTer
Copy link
Author

I tried to record a Frame with RenderDoc.
Turns out Wayland is not supported yet (Issue).

When I run the example with X11 (and not Wayland, as before) the issue is not present.

Seems like it is a problem with Wayland.
Any Idea what could cause this and If its wgpus's fault?

@kvark
Copy link
Member

kvark commented Feb 24, 2022

When I run the example with X11 (and not Wayland, as before) the issue is not present.

That's kind of puzzling. Texture data uploads should have nothing to do with Wayland and whatnot.

@teoxoy teoxoy added the api: vulkan Issues with Vulkan label Feb 24, 2023
@cwfitzgerald
Copy link
Member

This seems like a driver bug, so closing as out of scope.

@cwfitzgerald cwfitzgerald closed this as not planned Won't fix, can't repro, duplicate, stale Oct 14, 2023
@teoxoy teoxoy added the external: driver-bug A driver is causing the bug, though we may still want to work around it label Oct 16, 2023
@teoxoy teoxoy removed the type: bug Something isn't working label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: vulkan Issues with Vulkan external: driver-bug A driver is causing the bug, though we may still want to work around it
Projects
None yet
Development

No branches or pull requests

4 participants