Skip to content

Commit 7e18608

Browse files
authored
Merge pull request #89 from Cupnfish/wgpu-0.13
update `wgpu` to `0.13`
2 parents e24640d + ffb0d17 commit 7e18608

File tree

6 files changed

+47
-69
lines changed

6 files changed

+47
-69
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "wgpu_glyph"
33
version = "0.16.0"
44
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
5-
edition = "2018"
5+
edition = "2021"
66
description = "A fast text renderer for wgpu, powered by glyph_brush"
77
license = "MIT"
88
keywords = ["font", "ttf", "truetype", "wgpu", "text"]
@@ -12,12 +12,12 @@ readme = "README.md"
1212
resolver = "2"
1313

1414
[dependencies]
15-
wgpu = "0.12"
15+
wgpu = "0.13"
1616
glyph_brush = "0.7"
1717
log = "0.4"
1818

1919
[dependencies.bytemuck]
20-
version = "1.4"
20+
version = "1.9"
2121
features = ["derive"]
2222

2323
[dev-dependencies]

examples/clipping.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ fn main() -> Result<(), Box<dyn Error>> {
3232
.expect("Request device")
3333
});
3434

35-
// Create staging belt and a local pool
35+
// Create staging belt
3636
let mut staging_belt = wgpu::util::StagingBelt::new(1024);
37-
let mut local_pool = futures::executor::LocalPool::new();
38-
let local_spawner = local_pool.spawner();
3937

4038
// Prepare swap chain
4139
let render_format = wgpu::TextureFormat::Bgra8UnormSrgb;
@@ -48,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
4846
format: render_format,
4947
width: size.width,
5048
height: size.height,
51-
present_mode: wgpu::PresentMode::Mailbox,
49+
present_mode: wgpu::PresentMode::AutoVsync,
5250
},
5351
);
5452

@@ -82,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error>> {
8280
format: render_format,
8381
width: size.width,
8482
height: size.height,
85-
present_mode: wgpu::PresentMode::Mailbox,
83+
present_mode: wgpu::PresentMode::AutoVsync,
8684
},
8785
);
8886
}
@@ -106,7 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
106104
let _ = encoder.begin_render_pass(
107105
&wgpu::RenderPassDescriptor {
108106
label: Some("Render pass"),
109-
color_attachments: &[
107+
color_attachments: &[Some(
110108
wgpu::RenderPassColorAttachment {
111109
view,
112110
resolve_target: None,
@@ -122,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> {
122120
store: true,
123121
},
124122
},
125-
],
123+
)],
126124
depth_stencil_attachment: None,
127125
},
128126
);
@@ -183,13 +181,7 @@ fn main() -> Result<(), Box<dyn Error>> {
183181
queue.submit(Some(encoder.finish()));
184182
frame.present();
185183
// Recall unused staging buffers
186-
use futures::task::SpawnExt;
187-
188-
local_spawner
189-
.spawn(staging_belt.recall())
190-
.expect("Recall staging belt");
191-
192-
local_pool.run_until_stalled();
184+
staging_belt.recall();
193185
}
194186
_ => {
195187
*control_flow = winit::event_loop::ControlFlow::Wait;

examples/depth.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ fn main() -> Result<(), Box<dyn Error>> {
3434
.expect("Request device")
3535
});
3636

37-
// Create staging belt and a local pool
37+
// Create staging belt
3838
let mut staging_belt = wgpu::util::StagingBelt::new(1024);
39-
let mut local_pool = futures::executor::LocalPool::new();
40-
let local_spawner = local_pool.spawner();
4139

4240
// Prepare swap chain and depth buffer
4341
let mut size = window.inner_size();
@@ -101,7 +99,7 @@ fn main() -> Result<(), Box<dyn Error>> {
10199
let _ = encoder.begin_render_pass(
102100
&wgpu::RenderPassDescriptor {
103101
label: Some("Render pass"),
104-
color_attachments: &[
102+
color_attachments: &[Some(
105103
wgpu::RenderPassColorAttachment {
106104
view,
107105
resolve_target: None,
@@ -117,7 +115,7 @@ fn main() -> Result<(), Box<dyn Error>> {
117115
store: true,
118116
},
119117
},
120-
],
118+
)],
121119
depth_stencil_attachment: None,
122120
},
123121
);
@@ -180,13 +178,7 @@ fn main() -> Result<(), Box<dyn Error>> {
180178
queue.submit(Some(encoder.finish()));
181179
frame.present();
182180
// Recall unused staging buffers
183-
use futures::task::SpawnExt;
184-
185-
local_spawner
186-
.spawn(staging_belt.recall())
187-
.expect("Recall staging belt");
188-
189-
local_pool.run_until_stalled();
181+
staging_belt.recall();
190182
}
191183
_ => {
192184
*control_flow = winit::event_loop::ControlFlow::Wait;
@@ -209,7 +201,7 @@ fn create_frame_views(
209201
format: FORMAT,
210202
width,
211203
height,
212-
present_mode: wgpu::PresentMode::Mailbox,
204+
present_mode: wgpu::PresentMode::AutoVsync,
213205
},
214206
);
215207

examples/hello.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ fn main() -> Result<(), Box<dyn Error>> {
3232
.expect("Request device")
3333
});
3434

35-
// Create staging belt and a local pool
35+
// Create staging belt
3636
let mut staging_belt = wgpu::util::StagingBelt::new(1024);
37-
let mut local_pool = futures::executor::LocalPool::new();
38-
let local_spawner = local_pool.spawner();
3937

4038
// Prepare swap chain
4139
let render_format = wgpu::TextureFormat::Bgra8UnormSrgb;
@@ -48,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
4846
format: render_format,
4947
width: size.width,
5048
height: size.height,
51-
present_mode: wgpu::PresentMode::Mailbox,
49+
present_mode: wgpu::PresentMode::AutoVsync,
5250
},
5351
);
5452

@@ -82,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error>> {
8280
format: render_format,
8381
width: size.width,
8482
height: size.height,
85-
present_mode: wgpu::PresentMode::Mailbox,
83+
present_mode: wgpu::PresentMode::AutoVsync,
8684
},
8785
);
8886
}
@@ -106,7 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
106104
let _ = encoder.begin_render_pass(
107105
&wgpu::RenderPassDescriptor {
108106
label: Some("Render pass"),
109-
color_attachments: &[
107+
color_attachments: &[Some(
110108
wgpu::RenderPassColorAttachment {
111109
view,
112110
resolve_target: None,
@@ -122,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> {
122120
store: true,
123121
},
124122
},
125-
],
123+
)],
126124
depth_stencil_attachment: None,
127125
},
128126
);
@@ -163,13 +161,7 @@ fn main() -> Result<(), Box<dyn Error>> {
163161
queue.submit(Some(encoder.finish()));
164162
frame.present();
165163
// Recall unused staging buffers
166-
use futures::task::SpawnExt;
167-
168-
local_spawner
169-
.spawn(staging_belt.recall())
170-
.expect("Recall staging belt");
171-
172-
local_pool.run_until_stalled();
164+
staging_belt.recall();
173165
}
174166
_ => {
175167
*control_flow = winit::event_loop::ControlFlow::Wait;

src/pipeline.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ fn build<D>(
236236
wgpu::BindGroupLayoutEntry {
237237
binding: 1,
238238
visibility: wgpu::ShaderStages::FRAGMENT,
239-
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
239+
ty: wgpu::BindingType::Sampler(
240+
wgpu::SamplerBindingType::Filtering,
241+
),
240242
count: None,
241243
},
242244
wgpu::BindGroupLayoutEntry {
@@ -277,7 +279,7 @@ fn build<D>(
277279
bind_group_layouts: &[&uniform_layout],
278280
});
279281

280-
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
282+
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
281283
label: Some("Glyph Shader"),
282284
source: wgpu::ShaderSource::Wgsl(crate::Cow::Borrowed(include_str!(
283285
"shader/glyph.wgsl"
@@ -313,7 +315,7 @@ fn build<D>(
313315
fragment: Some(wgpu::FragmentState {
314316
module: &shader,
315317
entry_point: "fs_main",
316-
targets: &[wgpu::ColorTargetState {
318+
targets: &[Some(wgpu::ColorTargetState {
317319
format: render_format,
318320
blend: Some(wgpu::BlendState {
319321
color: wgpu::BlendComponent {
@@ -328,7 +330,7 @@ fn build<D>(
328330
},
329331
}),
330332
write_mask: wgpu::ColorWrites::ALL,
331-
}],
333+
})],
332334
}),
333335
multiview: None,
334336
});
@@ -375,14 +377,14 @@ fn draw<D>(
375377
let mut render_pass =
376378
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
377379
label: Some("wgpu_glyph::pipeline render pass"),
378-
color_attachments: &[wgpu::RenderPassColorAttachment {
380+
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
379381
view: target,
380382
resolve_target: None,
381383
ops: wgpu::Operations {
382384
load: wgpu::LoadOp::Load,
383385
store: true,
384386
},
385-
}],
387+
})],
386388
depth_stencil_attachment,
387389
});
388390

src/shader/glyph.wgsl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
struct Globals {
2-
transform: mat4x4<f32>;
3-
};
2+
transform: mat4x4<f32>,
3+
}
44

5-
[[group(0), binding(0)]] var<uniform> globals: Globals;
6-
[[group(0), binding(1)]] var font_sampler: sampler;
7-
[[group(0), binding(2)]] var font_tex: texture_2d<f32>;
5+
@group(0) @binding(0) var<uniform> globals: Globals;
6+
@group(0) @binding(1) var font_sampler: sampler;
7+
@group(0) @binding(2) var font_tex: texture_2d<f32>;
88

99
struct VertexInput {
10-
[[builtin(vertex_index)]] vertex_index: u32;
11-
[[location(0)]] left_top: vec3<f32>;
12-
[[location(1)]] right_bottom: vec2<f32>;
13-
[[location(2)]] tex_left_top: vec2<f32>;
14-
[[location(3)]] tex_right_bottom: vec2<f32>;
15-
[[location(4)]] color: vec4<f32>;
16-
};
10+
@builtin(vertex_index) vertex_index: u32,
11+
@location(0) left_top: vec3<f32>,
12+
@location(1) right_bottom: vec2<f32>,
13+
@location(2) tex_left_top: vec2<f32>,
14+
@location(3) tex_right_bottom: vec2<f32>,
15+
@location(4) color: vec4<f32>,
16+
}
1717

1818
struct VertexOutput {
19-
[[builtin(position)]] position: vec4<f32>;
20-
[[location(0)]] f_tex_pos: vec2<f32>;
21-
[[location(1)]] f_color: vec4<f32>;
22-
};
19+
@builtin(position) position: vec4<f32>,
20+
@location(0) f_tex_pos: vec2<f32>,
21+
@location(1) f_color: vec4<f32>,
22+
}
2323

24-
[[stage(vertex)]]
24+
@vertex
2525
fn vs_main(input: VertexInput) -> VertexOutput {
2626
var out: VertexOutput;
2727

@@ -57,8 +57,8 @@ fn vs_main(input: VertexInput) -> VertexOutput {
5757
return out;
5858
}
5959

60-
[[stage(fragment)]]
61-
fn fs_main(input: VertexOutput) -> [[location(0)]] vec4<f32> {
60+
@fragment
61+
fn fs_main(input: VertexOutput) -> @location(0) vec4<f32> {
6262
var alpha: f32 = textureSample(font_tex, font_sampler, input.f_tex_pos).r;
6363

6464
if (alpha <= 0.0) {

0 commit comments

Comments
 (0)