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

wgpu: Update to 0.10 #1000

Merged
merged 6 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ documentation = "https://docs.rs/iced"
readme = "README.md"
keywords = ["gui", "ui", "graphics", "interface", "widgets"]
categories = ["gui"]
resolver = "2"

[features]
default = ["wgpu", "default_system_font"]
Expand Down
2 changes: 1 addition & 1 deletion examples/integration_wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ publish = false

[dependencies]
iced_winit = { path = "../../winit" }
iced_wgpu = { path = "../../wgpu" }
iced_wgpu = { path = "../../wgpu", features = ["spirv"] }
env_logger = "0.8"
34 changes: 18 additions & 16 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn main() {
let mut clipboard = Clipboard::connect(&window);

// Initialize wgpu
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY);
let surface = unsafe { instance.create_surface(&window) };

let (format, (mut device, queue)) = futures::executor::block_on(async {
Expand All @@ -44,8 +44,8 @@ pub fn main() {
.expect("Request adapter");

(
adapter
.get_swap_chain_preferred_format(&surface)
surface
.get_preferred_format(&adapter)
.expect("Get preferred format"),
adapter
.request_device(
Expand All @@ -61,13 +61,13 @@ pub fn main() {
)
});

let mut swap_chain = {
{
let size = window.inner_size();

device.create_swap_chain(
&surface,
&wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
surface.configure(
&device,
&wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format,
width: size.width,
height: size.height,
Expand Down Expand Up @@ -158,10 +158,10 @@ pub fn main() {
if resized {
let size = window.inner_size();

swap_chain = device.create_swap_chain(
&surface,
&wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
surface.configure(
&device,
&wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
format: format,
width: size.width,
height: size.height,
Expand All @@ -172,18 +172,20 @@ pub fn main() {
resized = false;
}

match swap_chain.get_current_frame() {
match surface.get_current_frame() {
Ok(frame) => {
let mut encoder = device.create_command_encoder(
&wgpu::CommandEncoderDescriptor { label: None },
);

let program = state.program();

let view = frame.output.texture.create_view(&wgpu::TextureViewDescriptor::default());

{
// We clear the frame
let mut render_pass = scene.clear(
&frame.output.view,
&view,
&mut encoder,
program.background_color(),
);
Expand All @@ -197,7 +199,7 @@ pub fn main() {
&mut device,
&mut staging_belt,
&mut encoder,
&frame.output.view,
&view,
&viewport,
state.primitive(),
&debug.overlay(),
Expand All @@ -223,7 +225,7 @@ pub fn main() {
local_pool.run_until_stalled();
}
Err(error) => match error {
wgpu::SwapChainError::OutOfMemory => {
wgpu::SurfaceError::OutOfMemory => {
panic!("Swapchain error: {}. Rendering cannot continue.", error)
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion examples/integration_wgpu/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn build_pipeline(device: &wgpu::Device) -> wgpu::RenderPipeline {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrite::ALL,
write_mask: wgpu::ColorWrites::ALL,
}],
}),
primitive: wgpu::PrimitiveState {
Expand Down
2 changes: 1 addition & 1 deletion graphics/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod compositor;
#[cfg(feature = "opengl")]
mod gl_compositor;

pub use compositor::{Compositor, SwapChainError};
pub use compositor::{Compositor, SurfaceError};

#[cfg(feature = "opengl")]
pub use gl_compositor::GLCompositor;
15 changes: 6 additions & 9 deletions graphics/src/window/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ pub trait Compositor: Sized {
/// The surface of the backend.
type Surface;

/// The swap chain of the backend.
type SwapChain;

/// Creates a new [`Compositor`].
fn new<W: HasRawWindowHandle>(
settings: Self::Settings,
Expand All @@ -37,30 +34,30 @@ pub trait Compositor: Sized {
///
/// [`SwapChain`]: Self::SwapChain
/// [`Surface`]: Self::Surface
fn create_swap_chain(
fn configure_surface(
&mut self,
surface: &Self::Surface,
surface: &mut Self::Surface,
width: u32,
height: u32,
) -> Self::SwapChain;
);

/// Draws the output primitives to the next frame of the given [`SwapChain`].
///
/// [`SwapChain`]: Self::SwapChain
fn draw<T: AsRef<str>>(
&mut self,
renderer: &mut Self::Renderer,
swap_chain: &mut Self::SwapChain,
surface: &mut Self::Surface,
viewport: &Viewport,
background_color: Color,
output: &<Self::Renderer as iced_native::Renderer>::Output,
overlay: &[T],
) -> Result<mouse::Interaction, SwapChainError>;
) -> Result<mouse::Interaction, SurfaceError>;
}

/// Result of an unsuccessful call to [`Compositor::draw`].
#[derive(Clone, PartialEq, Eq, Debug, Error)]
pub enum SwapChainError {
pub enum SurfaceError {
/// A timeout was encountered while trying to acquire the next frame.
#[error(
"A timeout was encountered while trying to acquire the next frame"
Expand Down
5 changes: 3 additions & 2 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ farbfeld = ["image_rs/farbfeld"]
canvas = ["iced_graphics/canvas"]
qr_code = ["iced_graphics/qr_code"]
default_system_font = ["iced_graphics/font-source"]
spirv = ["wgpu/spirv"]

[dependencies]
wgpu = "0.9"
wgpu_glyph = "0.13"
wgpu = "0.10"
wgpu_glyph = "0.14"
glyph_brush = "0.7"
raw-window-handle = "0.3"
log = "0.4"
Expand Down
21 changes: 10 additions & 11 deletions wgpu/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Pipeline {
entries: &[
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX,
visibility: wgpu::ShaderStages::VERTEX,
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: false,
Expand All @@ -73,7 +73,7 @@ impl Pipeline {
},
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler {
comparison: false,
filtering: true,
Expand All @@ -86,7 +86,7 @@ impl Pipeline {
let uniforms_buffer = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("iced_wgpu::image uniforms buffer"),
size: mem::size_of::<Uniforms>() as u64,
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});

Expand Down Expand Up @@ -117,7 +117,7 @@ impl Pipeline {
label: Some("iced_wgpu::image texture atlas layout"),
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::FRAGMENT,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float {
filterable: true,
Expand All @@ -142,7 +142,6 @@ impl Pipeline {
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
include_str!("shader/image.wgsl"),
)),
flags: wgpu::ShaderFlags::all(),
});

let pipeline =
Expand All @@ -155,7 +154,7 @@ impl Pipeline {
buffers: &[
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Vertex>() as u64,
step_mode: wgpu::InputStepMode::Vertex,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[wgpu::VertexAttribute {
shader_location: 0,
format: wgpu::VertexFormat::Float32x2,
Expand All @@ -164,7 +163,7 @@ impl Pipeline {
},
wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Instance>() as u64,
step_mode: wgpu::InputStepMode::Instance,
step_mode: wgpu::VertexStepMode::Instance,
attributes: &wgpu::vertex_attr_array!(
1 => Float32x2,
2 => Float32x2,
Expand Down Expand Up @@ -192,7 +191,7 @@ impl Pipeline {
operation: wgpu::BlendOperation::Add,
},
}),
write_mask: wgpu::ColorWrite::ALL,
write_mask: wgpu::ColorWrites::ALL,
}],
}),
primitive: wgpu::PrimitiveState {
Expand All @@ -212,20 +211,20 @@ impl Pipeline {
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("iced_wgpu::image vertex buffer"),
contents: bytemuck::cast_slice(&QUAD_VERTS),
usage: wgpu::BufferUsage::VERTEX,
usage: wgpu::BufferUsages::VERTEX,
});

let indices =
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("iced_wgpu::image index buffer"),
contents: bytemuck::cast_slice(&QUAD_INDICES),
usage: wgpu::BufferUsage::INDEX,
usage: wgpu::BufferUsages::INDEX,
});

let instances = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("iced_wgpu::image instance buffer"),
size: mem::size_of::<Instance>() as u64 * Instance::MAX as u64,
usage: wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST,
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});

Expand Down
17 changes: 10 additions & 7 deletions wgpu/src/image/atlas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ impl Atlas {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Bgra8UnormSrgb,
usage: wgpu::TextureUsage::COPY_DST
| wgpu::TextureUsage::COPY_SRC
| wgpu::TextureUsage::SAMPLED,
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
});

let texture_view = texture.create_view(&wgpu::TextureViewDescriptor {
Expand Down Expand Up @@ -107,7 +107,7 @@ impl Atlas {
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("iced_wgpu::image staging buffer"),
contents: &padded_data,
usage: wgpu::BufferUsage::COPY_SRC,
usage: wgpu::BufferUsages::COPY_SRC,
});

match &entry {
Expand Down Expand Up @@ -316,6 +316,7 @@ impl Atlas {
y,
z: layer as u32,
},
aspect: wgpu::TextureAspect::default(),
},
extent,
);
Expand All @@ -342,9 +343,9 @@ impl Atlas {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Bgra8UnormSrgb,
usage: wgpu::TextureUsage::COPY_DST
| wgpu::TextureUsage::COPY_SRC
| wgpu::TextureUsage::SAMPLED,
usage: wgpu::TextureUsages::COPY_DST
| wgpu::TextureUsages::COPY_SRC
| wgpu::TextureUsages::TEXTURE_BINDING,
});

let amount_to_copy = self.layers.len() - amount;
Expand All @@ -365,6 +366,7 @@ impl Atlas {
y: 0,
z: i as u32,
},
aspect: wgpu::TextureAspect::default(),
},
wgpu::ImageCopyTexture {
texture: &new_texture,
Expand All @@ -374,6 +376,7 @@ impl Atlas {
y: 0,
z: i as u32,
},
aspect: wgpu::TextureAspect::default(),
},
wgpu::Extent3d {
width: SIZE,
Expand Down
Loading