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

Bytes per pixel should be multiplied by width before calling align_copy_bytes_per_row #17357

Open
allenqm opened this issue Jan 14, 2025 · 0 comments

Comments

@allenqm
Copy link

allenqm commented Jan 14, 2025

I was playing around with the headless_renderer.rs example. I observed that image_data received in the update system was 4x the size I was expecting. I set the dimensions to 64x64 in AppConfig; image_data.len was 65k bytes vs the expected 16k.

I think it's due how the cpu buffer is initialized in ImageCopier::new()

pub fn new(
        src_image: Handle<Image>,
        size: Extent3d,
        render_device: &RenderDevice,
    ) -> ImageCopier {
        let padded_bytes_per_row =
            RenderDevice::align_copy_bytes_per_row((size.width) as usize) * 4;  // HERE: shouldn't we multiply by 4 before calling align_copy_bytes_per_row?

        let cpu_buffer = render_device.create_buffer(&BufferDescriptor {
            label: None,
            size: padded_bytes_per_row as u64 * size.height as u64,
            usage: BufferUsages::MAP_READ | BufferUsages::COPY_DST,
            mapped_at_creation: false,
        });

        ImageCopier {
            buffer: cpu_buffer,
            src_image,
            enabled: Arc::new(AtomicBool::new(true)),
        }
    }

When I make the suggested change, I get the expected image_data length.

I'm relatively new to rendering code, so wanted to confirm this is an error first. If it is, I can submit a simple PR to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant