Update bytemuck and remove zerocopy in iced_wgpu
This commit is contained in:
parent
b86accfe1c
commit
9d4f664c94
5 changed files with 28 additions and 28 deletions
|
|
@ -16,13 +16,15 @@ default_system_font = ["iced_graphics/font-source"]
|
||||||
wgpu = "0.6"
|
wgpu = "0.6"
|
||||||
wgpu_glyph = "0.10"
|
wgpu_glyph = "0.10"
|
||||||
glyph_brush = "0.7"
|
glyph_brush = "0.7"
|
||||||
zerocopy = "0.3"
|
|
||||||
bytemuck = "1.2"
|
|
||||||
raw-window-handle = "0.3"
|
raw-window-handle = "0.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
guillotiere = "0.6"
|
guillotiere = "0.6"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
|
|
||||||
|
[dependencies.bytemuck]
|
||||||
|
version = "1.4"
|
||||||
|
features = ["derive"]
|
||||||
|
|
||||||
[dependencies.iced_native]
|
[dependencies.iced_native]
|
||||||
version = "0.2"
|
version = "0.2"
|
||||||
path = "../native"
|
path = "../native"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ use iced_graphics::layer;
|
||||||
use iced_native::Rectangle;
|
use iced_native::Rectangle;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use zerocopy::AsBytes;
|
|
||||||
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
use iced_native::image;
|
use iced_native::image;
|
||||||
|
|
@ -219,14 +220,14 @@ impl Pipeline {
|
||||||
let vertices =
|
let vertices =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::image vertex buffer"),
|
label: Some("iced_wgpu::image vertex buffer"),
|
||||||
contents: QUAD_VERTS.as_bytes(),
|
contents: bytemuck::cast_slice(&QUAD_VERTS),
|
||||||
usage: wgpu::BufferUsage::VERTEX,
|
usage: wgpu::BufferUsage::VERTEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
let indices =
|
let indices =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::image index buffer"),
|
label: Some("iced_wgpu::image index buffer"),
|
||||||
contents: QUAD_INDICES.as_bytes(),
|
contents: bytemuck::cast_slice(&QUAD_INDICES),
|
||||||
usage: wgpu::BufferUsage::INDEX,
|
usage: wgpu::BufferUsage::INDEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -385,12 +386,9 @@ impl Pipeline {
|
||||||
device,
|
device,
|
||||||
);
|
);
|
||||||
|
|
||||||
uniforms_buffer.copy_from_slice(
|
uniforms_buffer.copy_from_slice(bytemuck::bytes_of(&Uniforms {
|
||||||
Uniforms {
|
transform: transformation.into(),
|
||||||
transform: transformation.into(),
|
}));
|
||||||
}
|
|
||||||
.as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
@ -411,8 +409,9 @@ impl Pipeline {
|
||||||
device,
|
device,
|
||||||
);
|
);
|
||||||
|
|
||||||
instances_buffer
|
instances_buffer.copy_from_slice(bytemuck::cast_slice(
|
||||||
.copy_from_slice(instances[i..i + amount].as_bytes());
|
&instances[i..i + amount],
|
||||||
|
));
|
||||||
|
|
||||||
let mut render_pass =
|
let mut render_pass =
|
||||||
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||||
|
|
@ -463,7 +462,7 @@ impl Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, AsBytes)]
|
#[derive(Clone, Copy, Zeroable, Pod)]
|
||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
_position: [f32; 2],
|
_position: [f32; 2],
|
||||||
}
|
}
|
||||||
|
|
@ -486,7 +485,7 @@ const QUAD_VERTS: [Vertex; 4] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone, Copy, AsBytes)]
|
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
|
||||||
struct Instance {
|
struct Instance {
|
||||||
_position: [f32; 2],
|
_position: [f32; 2],
|
||||||
_size: [f32; 2],
|
_size: [f32; 2],
|
||||||
|
|
@ -500,7 +499,7 @@ impl Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone, Copy, AsBytes)]
|
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
|
||||||
struct Uniforms {
|
struct Uniforms {
|
||||||
transform: [f32; 16],
|
transform: [f32; 16],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ use crate::image::atlas::{self, Atlas};
|
||||||
use iced_native::svg;
|
use iced_native::svg;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
use zerocopy::AsBytes;
|
|
||||||
|
|
||||||
pub enum Svg {
|
pub enum Svg {
|
||||||
Loaded(resvg::usvg::Tree),
|
Loaded(resvg::usvg::Tree),
|
||||||
NotFound,
|
NotFound,
|
||||||
|
|
@ -119,7 +117,7 @@ impl Cache {
|
||||||
let allocation = texture_atlas.upload(
|
let allocation = texture_atlas.upload(
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
canvas.get_data().as_bytes(),
|
bytemuck::cast_slice(canvas.get_data()),
|
||||||
device,
|
device,
|
||||||
encoder,
|
encoder,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ use crate::Transformation;
|
||||||
use iced_graphics::layer;
|
use iced_graphics::layer;
|
||||||
use iced_native::Rectangle;
|
use iced_native::Rectangle;
|
||||||
|
|
||||||
|
use bytemuck::{Pod, Zeroable};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use wgpu::util::DeviceExt;
|
use wgpu::util::DeviceExt;
|
||||||
use zerocopy::AsBytes;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Pipeline {
|
pub struct Pipeline {
|
||||||
|
|
@ -156,14 +156,14 @@ impl Pipeline {
|
||||||
let vertices =
|
let vertices =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::quad vertex buffer"),
|
label: Some("iced_wgpu::quad vertex buffer"),
|
||||||
contents: QUAD_VERTS.as_bytes(),
|
contents: bytemuck::cast_slice(&QUAD_VERTS),
|
||||||
usage: wgpu::BufferUsage::VERTEX,
|
usage: wgpu::BufferUsage::VERTEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
let indices =
|
let indices =
|
||||||
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
|
||||||
label: Some("iced_wgpu::quad index buffer"),
|
label: Some("iced_wgpu::quad index buffer"),
|
||||||
contents: QUAD_INDICES.as_bytes(),
|
contents: bytemuck::cast_slice(&QUAD_INDICES),
|
||||||
usage: wgpu::BufferUsage::INDEX,
|
usage: wgpu::BufferUsage::INDEX,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -207,7 +207,7 @@ impl Pipeline {
|
||||||
device,
|
device,
|
||||||
);
|
);
|
||||||
|
|
||||||
constants_buffer.copy_from_slice(uniforms.as_bytes());
|
constants_buffer.copy_from_slice(bytemuck::bytes_of(&uniforms));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
|
@ -271,7 +271,7 @@ impl Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Clone, Copy, AsBytes)]
|
#[derive(Clone, Copy, Zeroable, Pod)]
|
||||||
pub struct Vertex {
|
pub struct Vertex {
|
||||||
_position: [f32; 2],
|
_position: [f32; 2],
|
||||||
}
|
}
|
||||||
|
|
@ -296,7 +296,7 @@ const QUAD_VERTS: [Vertex; 4] = [
|
||||||
const MAX_INSTANCES: usize = 100_000;
|
const MAX_INSTANCES: usize = 100_000;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone, Copy, AsBytes)]
|
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
|
||||||
struct Uniforms {
|
struct Uniforms {
|
||||||
transform: [f32; 16],
|
transform: [f32; 16],
|
||||||
scale: f32,
|
scale: f32,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
//! Draw meshes of triangles.
|
//! Draw meshes of triangles.
|
||||||
use crate::{settings, Transformation};
|
use crate::{settings, Transformation};
|
||||||
use iced_graphics::layer;
|
use iced_graphics::layer;
|
||||||
|
|
||||||
|
use bytemuck::{Pod, Zeroable};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use zerocopy::AsBytes;
|
|
||||||
|
|
||||||
pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
|
pub use iced_graphics::triangle::{Mesh2D, Vertex2D};
|
||||||
|
|
||||||
|
|
@ -322,7 +323,7 @@ impl Pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let uniforms = uniforms.as_bytes();
|
let uniforms = bytemuck::cast_slice(&uniforms);
|
||||||
|
|
||||||
if let Some(uniforms_size) =
|
if let Some(uniforms_size) =
|
||||||
wgpu::BufferSize::new(uniforms.len() as u64)
|
wgpu::BufferSize::new(uniforms.len() as u64)
|
||||||
|
|
@ -409,7 +410,7 @@ impl Pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Clone, Copy, AsBytes)]
|
#[derive(Debug, Clone, Copy, Zeroable, Pod)]
|
||||||
struct Uniforms {
|
struct Uniforms {
|
||||||
transform: [f32; 16],
|
transform: [f32; 16],
|
||||||
// We need to align this to 256 bytes to please `wgpu`...
|
// We need to align this to 256 bytes to please `wgpu`...
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue