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

Skewed output when changing resolution of new headless_renderer example #13384

Closed
cxreiff opened this issue May 16, 2024 · 4 comments · Fixed by #13388
Closed

Skewed output when changing resolution of new headless_renderer example #13384

cxreiff opened this issue May 16, 2024 · 4 comments · Fixed by #13388
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled

Comments

@cxreiff
Copy link

cxreiff commented May 16, 2024

Bevy version

main
v0.14.0-dev
f91fd32

Relevant system information

rustc/cargo 1.78.0

`SystemInfo { os: "MacOS 14.4.1 ", kernel: "23.4.0", cpu: "Apple M2 Max", core_count: "12", memory: "96.0 GiB" }`
`AdapterInfo { name: "Apple M2 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }`

What you did

Hello all - I am taking a look at the new headless_renderer example in the repo: https://github.com/bevyengine/bevy/blob/main/examples/app/headless_renderer.rs
#13006

I have a use case where I would need to set the dimensions of the output image based on something outside of bevy. So I ran the example after changing the configured dimensions (on line 69 in the AppConfig struct).

What went wrong

I expected the output image to be properly formatted at the indicated resolution. However, just changing the width by 1 or a few results in output that is skewed/misaligned (examples attached).

I sort of suspected that this had to do with bevy's default output, which doesn't match the resolution in the example but does have the same aspect ratio. So I changed the primary_window in WindowPlugin from None to a window with the config-defined dimensions:

primary_window: Some(Window {
  resolution: WindowResolution::new(config.width as f32, config.height as f32),
  ..default()
}),

...but it didn't change the output at all (and in fact no window appears, I assume because the camera's target is still set to a texture).

Additional information

I assume its most likely some kind of bit alignment issue where the resolution needs to be a certain aspect ratio or along certain increments, but I tried changing the width by increments of 4, 8, etc, and had no luck.

Thank you.

001
000

@cxreiff cxreiff added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 16, 2024
@cxreiff
Copy link
Author

cxreiff commented May 16, 2024

The AppConfig struct is where I started, I just decreased the width by one, e.g. on line 68-72:

let config = AppConfig {
        width: 1919,
        height: 1080,
        single_image: true,
};

...which results in the 45° skewed image (second screenshot). I also tried adding 4, 8, 16, and 32 to the width to see if that worked, and it didn't- but just now I tried adding 64 (1952x1080) and it worked! So it seems that the width has to be multiples of 64. It wouldn't be a problem for most fixed resolutions but for my use case a user might resize it to anything.

@bugsweeper
Copy link
Contributor

If found the root of problem. That is in copying from image to buffer, because copy_texture_to_buffer can copy image only by rows aligned wgpu::COPY_BYTES_PER_ROW_ALIGNMENT. That is why image in buffer can be little bit wider. I will fix copying from buffer to resulting image.

@cxreiff
Copy link
Author

cxreiff commented May 16, 2024

Oh great! I tried digging but wgpu calls are a bit beyond me at the moment. Thanks for your help!

@bugsweeper
Copy link
Contributor

@cxreiff Done

github-merge-queue bot pushed a commit that referenced this issue May 19, 2024
…ensions (#13388)

# Objective

- Fixes #13384 .

## Solution

- If the image became wider when copying from the texture to the buffer,
then the data is reduced to its original size when copying from the
buffer to the image.

## Testing

- Ran example with 1919x1080 resolution

![000](https://github.com/bevyengine/bevy/assets/17225606/47d95ed7-1c8c-4be4-a45a-1f485a3d6aa7)

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: François Mockers <francois.mockers@vleue.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants