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

Frame capture testing tool #5550

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

DGriffin91
Copy link
Contributor

Objective

Solution

  • A plugin for copying images from vram back to an Image
  • A plugin for testing scenes.
  • An example test scene.

There would be a folder of test images,

Currently main.rs creates a new bevy app and tests with an example scene. The .run() returns after the test so there could be a set of scenes tested here (or elsewhere if appropriate)

@superdump
Copy link
Contributor

Cool! I'll give this a review another time, but just wanted to note an initial thought: it would probably be good to integrate into scene_viewer so we can load scenes and take screenshots of those, then compare against references or something for regressions testing. Maybe we'd need to add some kind of configuration file for scene_viewer to be able to set up some known configurations (camera, lighting, etc) for tests.

@alice-i-cecile alice-i-cecile added C-Enhancement A new feature A-Rendering Drawing game state to the screen labels Aug 2, 2022
@alice-i-cecile alice-i-cecile self-requested a review August 2, 2022 16:48
@alice-i-cecile alice-i-cecile added the A-Diagnostics Logging, crash handling, error reporting and performance analysis label Aug 2, 2022
@paulkre
Copy link

paulkre commented Sep 7, 2022

Very cool! This is a great resource. I used some of this code to build a plugin for exporting image sequences out of Bevy: https://github.com/paulkre/bevy_image_export

Unfortunately, it doesn't work with the 2D pipeline yet (2D shapes are invisible in the output image). Using a RenderTarget::Image for a 2D camera works fine though. It seems like the copy_texture_to_buffer method is being called too early in the pipeline. I can't figure out where to insert the custom "image copier" node in the render graph, so that it runs after 2D shapes have been rendered.

@paulkre
Copy link

paulkre commented Sep 10, 2022

Apparently, a 2D camera does not work properly if it is parented to another 2D camera. I could not find the source of the problem though.

@AlanRace
Copy link

I have been trying this out, and I think that as it is written it only works correctly for images which have a width of a multiple of 256.

It seems that two different padded_bytes_per_row are being used:

let padded_bytes_per_row =
RenderDevice::align_copy_bytes_per_row((size.width) as usize) * 4;

let padded_bytes_per_row = RenderDevice::align_copy_bytes_per_row(
(src_image.size.x as usize / format.block_dimensions.0 as usize)
* format.block_size as usize,
);

Changing the first one to:

 let padded_bytes_per_row =
            RenderDevice::align_copy_bytes_per_row((size.width) as usize * 4);

produces the same padded_bytes_per_row in both situations and produces the correct image regardless of width.

@DGriffin91
Copy link
Contributor Author

@AlanRace Good catch! I need to figure out how to make it not depend on there being 4 color channels though. Will probably reference https://github.com/gfx-rs/wgpu/blob/c434b94ca20e9ccab8b0afdd7406c595dd37e7c3/wgpu/src/util/device.rs#L112

@Youdiie
Copy link

Youdiie commented Aug 2, 2023

@DGriffin91 Hello, I want to use your tools, but I got this error. Is there something to need before cargo run?

thread 'Compute Task Pool (1)' panicked at 'called `Result::unwrap()` on an `Err` value: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })', tools/frame_capture/src/scene_tester.rs:177:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'task has failed', /Users/gim-yujin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.4.0/src/task.rs:452:45

@DGriffin91
Copy link
Contributor Author

@Youdiie I'm guessing that's because this test_images dir doesn't exist. https://github.com/bevyengine/bevy/pull/5550/files#diff-630fc550358d7e46d3891918b8dd2edb1a225c06337f82b07ce657ac9afadba8R165

Not sure if you are aware of the new screenshot feature that landed in bevy 0.11, if you can do what you need with it, it would be probably easier than trying to use this code: https://bevyengine.org/news/bevy-0-11/#screenshot-api

@Youdiie
Copy link

Youdiie commented Aug 3, 2023

@DGriffin91 Thanks for replying!
I wanted to save high quality frame capture and couldn't resize with screenshot feature in bevy 0.11.
Thanks for @paulkre, I could resize frame capture with bevy_image_export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Diagnostics Logging, crash handling, error reporting and performance analysis A-Rendering Drawing game state to the screen C-Enhancement A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants