Merge pull request #37 from linebender/update_deps

Update dependencies
This commit is contained in:
Raph Levien 2020-11-17 14:18:14 -08:00 committed by GitHub
commit c939448348
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 639 additions and 386 deletions

750
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ license = "MIT/Apache-2.0"
edition = "2018"
[dependencies]
ash = "0.30"
ash = "0.31"
once_cell = "1.3.1"
ash-window = { git = "https://github.com/norse-rs/ash-window.git", branch = "dyn_trait" }
ash-window = "0.5"
raw-window-handle = "0.3"

View file

@ -5,6 +5,7 @@ fn main() {
let (instance, _) = VkInstance::new(None).unwrap();
unsafe {
let device = instance.device(None).unwrap();
let fence = device.create_fence(false).unwrap();
let mem_flags = MemFlags::host_coherent();
let src = (0..256).map(|x| x + 1).collect::<Vec<u32>>();
let buffer = device
@ -12,8 +13,10 @@ fn main() {
.unwrap();
device.write_buffer(&buffer, &src).unwrap();
let code = include_bytes!("./shader/collatz.spv");
let pipeline = device.create_simple_compute_pipeline(code, 1).unwrap();
let descriptor_set = device.create_descriptor_set(&pipeline, &[&buffer]).unwrap();
let pipeline = device.create_simple_compute_pipeline(code, 1, 0).unwrap();
let descriptor_set = device
.create_descriptor_set(&pipeline, &[&buffer], &[])
.unwrap();
let query_pool = device.create_query_pool(2).unwrap();
let mut cmd_buf = device.create_cmd_buf().unwrap();
cmd_buf.begin();
@ -22,8 +25,11 @@ fn main() {
cmd_buf.dispatch(&pipeline, &descriptor_set, (256, 1, 1));
cmd_buf.write_timestamp(&query_pool, 1);
cmd_buf.finish();
device.run_cmd_buf(&cmd_buf).unwrap();
let timestamps = device.reap_query_pool(query_pool);
device
.run_cmd_buf(&cmd_buf, &[], &[], Some(&fence))
.unwrap();
device.wait_and_reset(&[fence]).unwrap();
let timestamps = device.reap_query_pool(&query_pool);
let mut dst: Vec<u32> = Default::default();
device.read_buffer(&buffer, &mut dst).unwrap();
for (i, val) in dst.iter().enumerate().take(16) {

View file

@ -21,9 +21,9 @@ path = "../piet-gpu-hal"
path = "../piet-gpu-types"
[dependencies]
piet = "0.0.13"
piet = "0.2.0"
png = "0.16.2"
rand = "0.7.3"
roxmltree = "0.11"
winit = "0.22"
roxmltree = "0.13"
winit = "0.23"
clap = "2.33"

View file

@ -2,7 +2,7 @@ use std::fs::File;
use std::io::BufWriter;
use std::path::Path;
use clap::{Arg, App};
use clap::{App, Arg};
use piet_gpu_hal::vulkan::VkInstance;
use piet_gpu_hal::{CmdBuf, Device, Error, MemFlags};
@ -22,18 +22,30 @@ fn dump_scene(buf: &[u8]) {
fn dump_state(buf: &[u8]) {
for i in 0..(buf.len() / 48) {
let j = i * 48;
let floats = (0..11).map(|k| {
let mut buf_f32 = [0u8; 4];
buf_f32.copy_from_slice(&buf[j + k * 4..j + k * 4 + 4]);
f32::from_le_bytes(buf_f32)
}).collect::<Vec<_>>();
println!("{}: [{} {} {} {} {} {}] ({}, {})-({} {}) {} {}",
let floats = (0..11)
.map(|k| {
let mut buf_f32 = [0u8; 4];
buf_f32.copy_from_slice(&buf[j + k * 4..j + k * 4 + 4]);
f32::from_le_bytes(buf_f32)
})
.collect::<Vec<_>>();
println!(
"{}: [{} {} {} {} {} {}] ({}, {})-({} {}) {} {}",
i,
floats[0], floats[1], floats[2], floats[3], floats[4], floats[5],
floats[6], floats[7], floats[8], floats[9],
floats[10], buf[j + 44]);
floats[0],
floats[1],
floats[2],
floats[3],
floats[4],
floats[5],
floats[6],
floats[7],
floats[8],
floats[9],
floats[10],
buf[j + 44]
);
}
}
/// Interpret the output of the binning stage, for diagnostic purposes.
@ -41,22 +53,31 @@ fn dump_state(buf: &[u8]) {
fn trace_merge(buf: &[u32]) {
for bin in 0..256 {
println!("bin {}:", bin);
let mut starts = (0..16).map(|i| Some((bin * 16 + i) * 64)).collect::<Vec<Option<usize>>>();
let mut starts = (0..16)
.map(|i| Some((bin * 16 + i) * 64))
.collect::<Vec<Option<usize>>>();
loop {
let min_start = starts.iter().map(|st|
st.map(|st|
if buf[st / 4] == 0 {
!0
} else {
buf[st / 4 + 2]
}).unwrap_or(!0)).min().unwrap();
let min_start = starts
.iter()
.map(|st| {
st.map(|st| {
if buf[st / 4] == 0 {
!0
} else {
buf[st / 4 + 2]
}
})
.unwrap_or(!0)
})
.min()
.unwrap();
if min_start == !0 {
break;
}
let mut selected = !0;
for i in 0..16 {
if let Some(st) = starts[i] {
if buf[st/4] != 0 && buf[st/4 + 2] == min_start {
if buf[st / 4] != 0 && buf[st / 4 + 2] == min_start {
selected = i;
break;
}
@ -64,16 +85,15 @@ fn trace_merge(buf: &[u32]) {
}
let st = starts[selected].unwrap();
println!("selected {}, start {:x}", selected, st);
for j in 0..buf[st/4] {
println!("{:x}", buf[st/4 + 2 + j as usize])
for j in 0..buf[st / 4] {
println!("{:x}", buf[st / 4 + 2 + j as usize])
}
if buf[st/4 + 1] == 0 {
if buf[st / 4 + 1] == 0 {
starts[selected] = None;
} else {
starts[selected] = Some(buf[st/4 + 1] as usize);
starts[selected] = Some(buf[st / 4 + 1] as usize);
}
}
}
}
@ -103,7 +123,10 @@ fn trace_ptcl(buf: &[u32]) {
let x1 = f32::from_bits(buf[segs / 4 + i * 5 + 2]);
let y1 = f32::from_bits(buf[segs / 4 + i * 5 + 3]);
let y_edge = f32::from_bits(buf[segs / 4 + i * 5 + 4]);
println!(" ({:.3}, {:.3}) - ({:.3}, {:.3}) | {:.3}", x0, y0, x1, y1, y_edge);
println!(
" ({:.3}, {:.3}) - ({:.3}, {:.3}) | {:.3}",
x0, y0, x1, y1, y_edge
);
}
loop {
seg_chunk = buf[seg_chunk / 4 + 1] as usize;
@ -115,7 +138,10 @@ fn trace_ptcl(buf: &[u32]) {
4 => {
let line_width = f32::from_bits(buf[tile_offset / 4 + 2]);
let rgba_color = buf[tile_offset / 4 + 3];
println!(" {:x}: stroke {:x} {}", tile_offset, rgba_color, line_width);
println!(
" {:x}: stroke {:x} {}",
tile_offset, rgba_color, line_width
);
let mut seg_chunk = buf[tile_offset / 4 + 1] as usize;
let n = buf[seg_chunk / 4] as usize;
let segs = buf[seg_chunk / 4 + 2] as usize;
@ -126,7 +152,10 @@ fn trace_ptcl(buf: &[u32]) {
let x1 = f32::from_bits(buf[segs / 4 + i * 5 + 2]);
let y1 = f32::from_bits(buf[segs / 4 + i * 5 + 3]);
let y_edge = f32::from_bits(buf[segs / 4 + i * 5 + 4]);
println!(" ({:.3}, {:.3}) - ({:.3}, {:.3}) | {:.3}", x0, y0, x1, y1, y_edge);
println!(
" ({:.3}, {:.3}) - ({:.3}, {:.3}) | {:.3}",
x0, y0, x1, y1, y_edge
);
}
loop {
seg_chunk = buf[seg_chunk / 4 + 1] as usize;
@ -152,18 +181,16 @@ fn trace_ptcl(buf: &[u32]) {
}
}
fn main() -> Result<(), Error> {
let matches = App::new("piet-gpu test")
.arg(Arg::with_name("INPUT")
.index(1))
.arg(Arg::with_name("flip")
.short("f")
.long("flip"))
.arg(Arg::with_name("scale")
.short("s")
.long("scale")
.takes_value(true))
.arg(Arg::with_name("INPUT").index(1))
.arg(Arg::with_name("flip").short("f").long("flip"))
.arg(
Arg::with_name("scale")
.short("s")
.long("scale")
.takes_value(true),
)
.get_matches();
let (instance, _) = VkInstance::new(None)?;
unsafe {
@ -175,7 +202,8 @@ fn main() -> Result<(), Error> {
let mut ctx = PietGpuRenderContext::new();
if let Some(input) = matches.value_of("INPUT") {
let mut scale = matches.value_of("scale")
let mut scale = matches
.value_of("scale")
.map(|scale| scale.parse().unwrap())
.unwrap_or(8.0);
if matches.is_present("flip") {
@ -198,11 +226,16 @@ fn main() -> Result<(), Error> {
renderer.record(&mut cmd_buf, &query_pool);
cmd_buf.copy_image_to_buffer(&renderer.image_dev, &image_buf);
cmd_buf.finish();
let start = std::time::Instant::now();
device.run_cmd_buf(&cmd_buf, &[], &[], Some(&fence))?;
device.wait_and_reset(&[fence])?;
println!("elapsed = {:?}", start.elapsed());
let ts = device.reap_query_pool(&query_pool).unwrap();
println!("Element kernel time: {:.3}ms", ts[0] * 1e3);
println!("Tile allocation kernel time: {:.3}ms", (ts[1] - ts[0]) * 1e3);
println!(
"Tile allocation kernel time: {:.3}ms",
(ts[1] - ts[0]) * 1e3
);
println!("Coarse path kernel time: {:.3}ms", (ts[2] - ts[1]) * 1e3);
println!("Backdrop kernel time: {:.3}ms", (ts[3] - ts[2]) * 1e3);
println!("Binning kernel time: {:.3}ms", (ts[4] - ts[3]) * 1e3);

View file

@ -162,12 +162,20 @@ pub struct Renderer<D: Device> {
}
impl<D: Device> Renderer<D> {
pub unsafe fn new(device: &D, scene: &[u8], n_paths: usize, n_pathseg: usize) -> Result<Self, Error> {
pub unsafe fn new(
device: &D,
scene: &[u8],
n_paths: usize,
n_pathseg: usize,
) -> Result<Self, Error> {
let host = MemFlags::host_coherent();
let dev = MemFlags::device_local();
let n_elements = scene.len() / piet_gpu_types::scene::Element::fixed_size();
println!("scene: {} elements, {} paths, {} path_segments", n_elements, n_paths, n_pathseg);
println!(
"scene: {} elements, {} paths, {} path_segments",
n_elements, n_paths, n_pathseg
);
let scene_buf = device
.create_buffer(std::mem::size_of_val(&scene[..]) as u64, host)
@ -256,17 +264,20 @@ impl<D: Device> Renderer<D> {
let coarse_pipeline = device.create_simple_compute_pipeline(coarse_code, 5, 0)?;
let coarse_ds = device.create_descriptor_set(
&coarse_pipeline,
&[&anno_buf, &bin_buf, &tile_buf, &coarse_alloc_buf_dev, &ptcl_buf],
&[
&anno_buf,
&bin_buf,
&tile_buf,
&coarse_alloc_buf_dev,
&ptcl_buf,
],
&[],
)?;
let k4_code = include_bytes!("../shader/kernel4.spv");
let k4_pipeline = device.create_simple_compute_pipeline(k4_code, 2, 1)?;
let k4_ds = device.create_descriptor_set(
&k4_pipeline,
&[&ptcl_buf, &tile_buf],
&[&image_dev]
)?;
let k4_ds =
device.create_descriptor_set(&k4_pipeline, &[&ptcl_buf, &tile_buf], &[&image_dev])?;
Ok(Renderer {
scene_buf,

View file

@ -1,28 +1,28 @@
use std::borrow::Cow;
use std::{borrow::Cow, ops::RangeBounds};
use piet_gpu_types::encoder::{Encode, Encoder};
use piet_gpu_types::scene::{CubicSeg, Element, Fill, LineSeg, QuadSeg, SetLineWidth, Stroke};
use piet::kurbo::{Affine, PathEl, Point, Rect, Shape};
use piet::{
kurbo::Size,
kurbo::{Affine, PathEl, Point, Rect, Shape},
HitTestPosition, TextAttribute, TextStorage,
};
use piet::{
Color, Error, FixedGradient, Font, FontBuilder, HitTestPoint, HitTestTextPosition, ImageFormat,
InterpolationMode, IntoBrush, LineMetric, RenderContext, StrokeStyle, Text, TextLayout,
TextLayoutBuilder,
Color, Error, FixedGradient, FontFamily, HitTestPoint, ImageFormat, InterpolationMode,
IntoBrush, LineMetric, RenderContext, StrokeStyle, Text, TextLayout, TextLayoutBuilder,
};
pub struct PietGpuImage;
pub struct PietGpuFont;
pub struct PietGpuFontBuilder;
#[derive(Clone)]
pub struct PietGpuTextLayout;
pub struct PietGpuTextLayoutBuilder;
#[derive(Clone)]
pub struct PietGpuText;
pub struct PietGpuRenderContext {
@ -103,7 +103,7 @@ impl RenderContext for PietGpuRenderContext {
self.stroke_width = width;
}
let brush = brush.make_brush(self, || shape.bounding_box()).into_owned();
let path = shape.to_bez_path(TOLERANCE);
let path = shape.path_elements(TOLERANCE);
self.encode_path(path, false);
match brush {
PietGpuBrush::Solid(rgba_color) => {
@ -126,7 +126,7 @@ impl RenderContext for PietGpuRenderContext {
fn fill(&mut self, shape: impl Shape, brush: &impl IntoBrush<Self>) {
let brush = brush.make_brush(self, || shape.bounding_box()).into_owned();
let path = shape.to_bez_path(TOLERANCE);
let path = shape.path_elements(TOLERANCE);
self.encode_path(path, true);
match brush {
PietGpuBrush::Solid(rgba_color) => {
@ -146,23 +146,7 @@ impl RenderContext for PietGpuRenderContext {
&mut self.inner_text
}
fn draw_text(
&mut self,
_layout: &Self::TextLayout,
pos: impl Into<Point>,
brush: &impl IntoBrush<Self>,
) {
let _pos = pos.into();
let brush: PietGpuBrush = brush.make_brush(self, || Rect::ZERO).into_owned();
match brush {
PietGpuBrush::Solid(_rgba) => {
// TODO: draw text
}
_ => {}
}
}
fn draw_text(&mut self, _layout: &Self::TextLayout, _pos: impl Into<Point>) {}
fn save(&mut self) -> Result<(), Error> {
Ok(())
@ -335,70 +319,81 @@ impl PietGpuRenderContext {
}
impl Text for PietGpuText {
type Font = PietGpuFont;
type FontBuilder = PietGpuFontBuilder;
type TextLayout = PietGpuTextLayout;
type TextLayoutBuilder = PietGpuTextLayoutBuilder;
fn new_font_by_name(&mut self, _name: &str, _size: f64) -> Self::FontBuilder {
unimplemented!();
fn load_font(&mut self, _data: &[u8]) -> Result<FontFamily, Error> {
Ok(FontFamily::default())
}
fn new_text_layout(
&mut self,
_font: &Self::Font,
_text: &str,
_width: impl Into<Option<f64>>,
) -> Self::TextLayoutBuilder {
unimplemented!();
fn new_text_layout(&mut self, _text: impl TextStorage) -> Self::TextLayoutBuilder {
PietGpuTextLayoutBuilder
}
}
impl Font for PietGpuFont {}
impl FontBuilder for PietGpuFontBuilder {
type Out = PietGpuFont;
fn build(self) -> Result<Self::Out, Error> {
unimplemented!();
fn font_family(&mut self, _family_name: &str) -> Option<FontFamily> {
Some(FontFamily::default())
}
}
impl TextLayoutBuilder for PietGpuTextLayoutBuilder {
type Out = PietGpuTextLayout;
fn max_width(self, _width: f64) -> Self {
self
}
fn alignment(self, _alignment: piet::TextAlignment) -> Self {
self
}
fn default_attribute(self, _attribute: impl Into<TextAttribute>) -> Self {
self
}
fn range_attribute(
self,
_range: impl RangeBounds<usize>,
_attribute: impl Into<TextAttribute>,
) -> Self {
self
}
fn build(self) -> Result<Self::Out, Error> {
unimplemented!()
Ok(PietGpuTextLayout)
}
}
impl TextLayout for PietGpuTextLayout {
fn width(&self) -> f64 {
0.0
fn size(&self) -> Size {
Size::ZERO
}
fn update_width(&mut self, _new_width: impl Into<Option<f64>>) -> Result<(), Error> {
unimplemented!()
fn image_bounds(&self) -> Rect {
Rect::ZERO
}
fn line_text(&self, _line_number: usize) -> Option<&str> {
unimplemented!()
None
}
fn line_metric(&self, _line_number: usize) -> Option<LineMetric> {
unimplemented!()
None
}
fn line_count(&self) -> usize {
unimplemented!()
0
}
fn hit_test_point(&self, _point: Point) -> HitTestPoint {
unimplemented!()
HitTestPoint::default()
}
fn hit_test_text_position(&self, _text_position: usize) -> Option<HitTestTextPosition> {
unimplemented!()
fn hit_test_text_position(&self, _text_position: usize) -> HitTestPosition {
HitTestPosition::default()
}
fn text(&self) -> &str {
""
}
}