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

Error printed every frame in some GPUs #9

Open
Zheoni opened this issue Nov 8, 2023 · 2 comments
Open

Error printed every frame in some GPUs #9

Zheoni opened this issue Nov 8, 2023 · 2 comments
Labels
bug Something isn't working upstream

Comments

@Zheoni
Copy link
Owner

Zheoni commented Nov 8, 2023

image

Maybe something with resize and or texture size? It happens in in (at least some) AMD GPUs

@Zheoni Zheoni added the bug Something isn't working label Nov 8, 2023
@crillon
Copy link
Contributor

crillon commented Nov 8, 2023

bevyengine/bevy#9975 looks relevant.
Idk if it will work, but here resize.rs with the suggested fix

use bevy::prelude::*;
use bevy::render::settings::Backends;
use bevy::render::settings::RenderCreation;
use bevy::render::settings::WgpuSettings;
use bevy::render::RenderPlugin;
use bevy_pixel_buffer::prelude::*;

#[derive(Deref, DerefMut, Resource)]
struct ResizeTimer(Timer);

fn main() {
    let size = PixelBufferSize {
        size: UVec2::new(32, 32),
        pixel_size: UVec2::new(16, 16),
    };

    App::new()
        .add_plugins((
            DefaultPlugins.set(RenderPlugin {
                render_creation: RenderCreation::Automatic(WgpuSettings {
                    backends: Some(Backends::VULKAN),
                    ..default()
                }),
            }),
            PixelBufferPlugin,
        ))
        .add_systems(Startup, PixelBufferBuilder::new().with_size(size).setup())
        // Resize applies at the beginning of next frame, update the image and
        // prepare the resize for the next frame
        .add_systems(Update, (update, resize).chain())
        .insert_resource(ResizeTimer(Timer::from_seconds(2.0, TimerMode::Repeating)))
        .run()
}

// update pixels when pixel buffer changes
fn update(image: Query<&Handle<Image>, Changed<PixelBuffer>>, mut images: ResMut<Assets<Image>>) {
    if let Ok(image) = image.get_single() {
        Frame::extract(&mut images, image).per_pixel(|_, _| Pixel::random());
    }
}

fn resize(
    time: Res<Time>,
    mut timer: ResMut<ResizeTimer>,
    mut pb: Query<&mut PixelBuffer>,
    mut toggle: Local<bool>,
) {
    timer.tick(time.delta());

    if timer.finished() {
        let mut pb = pb.single_mut();
        pb.size = if *toggle {
            PixelBufferSize {
                size: UVec2::new(32, 32),
                pixel_size: UVec2::new(16, 16),
            }
        } else {
            PixelBufferSize {
                size: UVec2::new(16, 16),
                pixel_size: UVec2::new(32, 32),
            }
        };
        *toggle = !*toggle;
    }
}

@Zheoni
Copy link
Owner Author

Zheoni commented Nov 8, 2023

Yep, it's that wgpu issue and that fixes it. Thanks again 😊

@Zheoni Zheoni added the upstream label Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working upstream
Projects
None yet
Development

No branches or pull requests

2 participants