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

update wgpu to 0.13 #1378

Merged
merged 9 commits into from
Jul 3, 2022
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
18 changes: 7 additions & 11 deletions examples/integration_wgpu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use scene::Scene;
use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport};
use iced_winit::{conversion, futures, program, winit, Clipboard, Debug, Size};

use futures::task::SpawnExt;
use winit::{
dpi::PhysicalPosition,
event::{Event, ModifiersState, WindowEvent},
Expand Down Expand Up @@ -91,7 +90,9 @@ pub fn main() {

(
surface
.get_preferred_format(&adapter)
.get_supported_formats(&adapter)
.first()
.copied()
.expect("Get preferred format"),
adapter
.request_device(
Expand All @@ -114,15 +115,14 @@ pub fn main() {
format,
width: physical_size.width,
height: physical_size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);

let mut resized = false;

// Initialize staging belt and local pool
// Initialize staging belt
let mut staging_belt = wgpu::util::StagingBelt::new(5 * 1024);
let mut local_pool = futures::executor::LocalPool::new();

// Initialize scene and GUI controls
let scene = Scene::new(&mut device, format);
Expand Down Expand Up @@ -207,7 +207,7 @@ pub fn main() {
format: format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);

Expand Down Expand Up @@ -262,12 +262,8 @@ pub fn main() {
);

// And recall staging buffers
local_pool
.spawner()
.spawn(staging_belt.recall())
.expect("Recall staging buffers");
staging_belt.recall();

local_pool.run_until_stalled();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more local pool! That's great 😄

}
Err(error) => match error {
wgpu::SurfaceError::OutOfMemory => {
Expand Down
12 changes: 6 additions & 6 deletions examples/integration_wgpu/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Scene {
) -> wgpu::RenderPass<'a> {
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
Expand All @@ -39,7 +39,7 @@ impl Scene {
}),
store: true,
},
}],
})],
depth_stencil_attachment: None,
})
}
Expand All @@ -55,8 +55,8 @@ fn build_pipeline(
texture_format: wgpu::TextureFormat,
) -> wgpu::RenderPipeline {
let (vs_module, fs_module) = (
device.create_shader_module(&wgpu::include_wgsl!("shader/vert.wgsl")),
device.create_shader_module(&wgpu::include_wgsl!("shader/frag.wgsl")),
device.create_shader_module(wgpu::include_wgsl!("shader/vert.wgsl")),
device.create_shader_module(wgpu::include_wgsl!("shader/frag.wgsl")),
);

let pipeline_layout =
Expand All @@ -78,14 +78,14 @@ fn build_pipeline(
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: texture_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
Expand Down
4 changes: 2 additions & 2 deletions examples/integration_wgpu/src/shader/frag.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[stage(fragment)]]
fn main() -> [[location(0)]] vec4<f32> {
@fragment
fn main() -> @location(0) vec4<f32> {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
4 changes: 2 additions & 2 deletions examples/integration_wgpu/src/shader/vert.wgsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[[stage(vertex)]]
fn main([[builtin(vertex_index)]] in_vertex_index: u32) -> [[builtin(position)]] vec4<f32> {
@vertex
fn main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
let x = f32(1 - i32(in_vertex_index)) * 0.5;
let y = f32(1 - i32(in_vertex_index & 1u) * 2) * 0.5;
return vec4<f32>(x, y, 0.0, 1.0);
Expand Down
6 changes: 3 additions & 3 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ spirv = ["wgpu/spirv"]
webgl = ["wgpu/webgl"]

[dependencies]
wgpu = "0.12"
wgpu_glyph = "0.16"
wgpu = "0.13"
wgpu_glyph = "0.17"
glyph_brush = "0.7"
raw-window-handle = "0.4"
log = "0.4"
Expand All @@ -39,7 +39,7 @@ kamadak-exif = "0.5"
bitflags = "1.2"

[dependencies.bytemuck]
version = "1.4"
version = "1.9"
features = ["derive"]

[dependencies.iced_native]
Expand Down
22 changes: 12 additions & 10 deletions wgpu/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl Pipeline {
});

let shader =
device.create_shader_module(&wgpu::ShaderModuleDescriptor {
device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu::image::shader"),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
include_str!("shader/image.wgsl"),
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Pipeline {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent {
Expand All @@ -191,7 +191,7 @@ impl Pipeline {
},
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
Expand Down Expand Up @@ -406,14 +406,16 @@ impl Pipeline {
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::image render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
color_attachments: &[Some(
wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
},
}],
)],
depth_stencil_attachment: None,
});

Expand Down
22 changes: 12 additions & 10 deletions wgpu/src/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Pipeline {
});

let shader =
device.create_shader_module(&wgpu::ShaderModuleDescriptor {
device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("iced_wgpu::quad::shader"),
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(
include_str!("shader/quad.wgsl"),
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Pipeline {
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent {
Expand All @@ -115,7 +115,7 @@ impl Pipeline {
},
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
Expand Down Expand Up @@ -211,14 +211,16 @@ impl Pipeline {
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("iced_wgpu::quad render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
color_attachments: &[Some(
wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
},
}],
)],
depth_stencil_attachment: None,
});

Expand Down
2 changes: 1 addition & 1 deletion wgpu/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl Settings {
impl Default for Settings {
fn default() -> Settings {
Settings {
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
internal_backend: wgpu::Backends::all(),
default_font: None,
default_text_size: 20,
Expand Down
20 changes: 10 additions & 10 deletions wgpu/src/shader/blit.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ var<private> uvs: array<vec2<f32>, 6> = array<vec2<f32>, 6>(
vec2<f32>(1.0, 1.0)
);

[[group(0), binding(0)]] var u_sampler: sampler;
[[group(1), binding(0)]] var u_texture: texture_2d<f32>;
@group(0) @binding(0) var u_sampler: sampler;
@group(1) @binding(0) var u_texture: texture_2d<f32>;

struct VertexInput {
[[builtin(vertex_index)]] vertex_index: u32;
};
@builtin(vertex_index) vertex_index: u32,
}

struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] uv: vec2<f32>;
};
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
}

[[stage(vertex)]]
@vertex
fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput;
out.uv = uvs[input.vertex_index];
Expand All @@ -37,7 +37,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
return out;
}

[[stage(fragment)]]
fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(u_texture, u_sampler, input.uv);
}
38 changes: 19 additions & 19 deletions wgpu/src/shader/image.wgsl
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
struct Globals {
transform: mat4x4<f32>;
};
transform: mat4x4<f32>,
}

[[group(0), binding(0)]] var<uniform> globals: Globals;
[[group(0), binding(1)]] var u_sampler: sampler;
[[group(1), binding(0)]] var u_texture: texture_2d_array<f32>;
@group(0) @binding(0) var<uniform> globals: Globals;
@group(0) @binding(1) var u_sampler: sampler;
@group(1) @binding(0) var u_texture: texture_2d_array<f32>;

struct VertexInput {
[[location(0)]] v_pos: vec2<f32>;
[[location(1)]] pos: vec2<f32>;
[[location(2)]] scale: vec2<f32>;
[[location(3)]] atlas_pos: vec2<f32>;
[[location(4)]] atlas_scale: vec2<f32>;
[[location(5)]] layer: i32;
};
@location(0) v_pos: vec2<f32>,
@location(1) pos: vec2<f32>,
@location(2) scale: vec2<f32>,
@location(3) atlas_pos: vec2<f32>,
@location(4) atlas_scale: vec2<f32>,
@location(5) layer: i32,
}

struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
[[location(0)]] uv: vec2<f32>;
[[location(1)]] layer: f32; // this should be an i32, but naga currently reads that as requiring interpolation.
};
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
@location(1) layer: f32, // this should be an i32, but naga currently reads that as requiring interpolation.
}

[[stage(vertex)]]
@vertex
fn vs_main(input: VertexInput) -> VertexOutput {
var out: VertexOutput;

Expand All @@ -40,7 +40,7 @@ fn vs_main(input: VertexInput) -> VertexOutput {
return out;
}

[[stage(fragment)]]
fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
return textureSample(u_texture, u_sampler, input.uv, i32(input.layer));
}
Loading