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

Instance without surface + small buffer errors #167

Closed
elbaro opened this issue Apr 30, 2022 · 1 comment
Closed

Instance without surface + small buffer errors #167

elbaro opened this issue Apr 30, 2022 · 1 comment

Comments

@elbaro
Copy link

elbaro commented Apr 30, 2022

use piet::RenderContext;

fn ctx_to_file(
    ctx: &mut piet_gpu::PietGpuRenderContext,
    width: usize,
    height: usize,
    path: &std::path::Path,
) {
    let mut img_data: Vec<u8> = Default::default();
    unsafe {
        // this part is copied from bin/cli.rs
        let (instance, _) = piet_gpu_hal::Instance::new(None, Default::default()).unwrap();
        let device = instance.device(None).unwrap();
        let session = piet_gpu_hal::Session::new(device);
        let mut renderer = piet_gpu::Renderer::new(&session, width, height, 1).unwrap();
        renderer.upload_render_ctx(ctx, 0).unwrap();

        let mut cmd_buf = session.cmd_buf().unwrap();
        let query_pool = session.create_query_pool(8).unwrap();
        let image_usage = piet_gpu_hal::BufferUsage::MAP_READ | piet_gpu_hal::BufferUsage::COPY_DST;
        let image_buf = session
            .create_buffer((width * height * 4) as u64, image_usage)
            .unwrap();
        cmd_buf.begin();
        renderer.record(&mut cmd_buf, &query_pool, 0);
        cmd_buf.copy_image_to_buffer(&renderer.image_dev, &image_buf);
        cmd_buf.finish_timestamps(&query_pool);
        cmd_buf.host_barrier();
        cmd_buf.finish();
        let submitted = session.run_cmd_buf(cmd_buf, &[], &[]).unwrap();
        submitted.wait().unwrap();
        session.fetch_query_pool(&query_pool).unwrap();
        image_buf.read(&mut img_data).unwrap();
    }

    // Write image as PNG file.
    let file = std::fs::File::create(path).unwrap();
    let ref mut w = std::io::BufWriter::new(file);
    let mut encoder = png::Encoder::new(w, width as u32, height as u32);
    encoder.set_color(png::ColorType::Rgba);
    encoder.set_depth(png::BitDepth::Eight);
    let mut writer = encoder.write_header().unwrap();
    writer.write_image_data(&img_data).unwrap();
}

fn main() {
    let mut ctx = piet_gpu::PietGpuRenderContext::new();
    let size = (200, 200);
    ctx.fill(
        piet::kurbo::Rect::new(0., 0., size.0 as f64, size.1 as f64),
        &piet::Color::WHITE,
    );
    ctx.stroke(
        piet::kurbo::Line::new((0., 50.0), (100.0, 50.0)),
        &piet::Color::rgb8(0, 255, 0),
        2.0,
    );
    ctx.finish().unwrap();
    ctx_to_file(&mut ctx, size.0, size.1, std::path::Path::new("gpu.png"));
}

gpu

Now increase (width, height) to (2048, 1600) and it produces the correct result (image is truncated):
image

This can be also reproduced in piet-gpu/bin/cli.rs. Reducing the size

const WIDTH: usize = 2048;
const HEIGHT: usize = 1536;

to a smaller size like (200,200) results in ERROR_DEVICE_LOST. I am on linux, nvidia 510.60.

@DJMcNab
Copy link
Member

DJMcNab commented Feb 24, 2024

Thanks for the report. However, I don't think this is still applicable to Vello (which has been renamed from piet-gpu, and moved to using wgpu).

'm going to close this issue now. If you do run into similar issues with the new version, we would need a new reproduction, so a new issue is probably most appropriate.

@DJMcNab DJMcNab closed this as completed Feb 24, 2024
@DJMcNab DJMcNab reopened this Feb 24, 2024
@DJMcNab DJMcNab closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2024
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

2 participants