Skip to content

Commit

Permalink
Merge pull request #89 from Cupnfish/wgpu-0.13
Browse files Browse the repository at this point in the history
update `wgpu` to `0.13`
  • Loading branch information
hecrj authored Jul 3, 2022
2 parents e24640d + ffb0d17 commit 7e18608
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 69 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "wgpu_glyph"
version = "0.16.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2018"
edition = "2021"
description = "A fast text renderer for wgpu, powered by glyph_brush"
license = "MIT"
keywords = ["font", "ttf", "truetype", "wgpu", "text"]
Expand All @@ -12,12 +12,12 @@ readme = "README.md"
resolver = "2"

[dependencies]
wgpu = "0.12"
wgpu = "0.13"
glyph_brush = "0.7"
log = "0.4"

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

[dev-dependencies]
Expand Down
20 changes: 6 additions & 14 deletions examples/clipping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ fn main() -> Result<(), Box<dyn Error>> {
.expect("Request device")
});

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

// Prepare swap chain
let render_format = wgpu::TextureFormat::Bgra8UnormSrgb;
Expand All @@ -48,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
format: render_format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);

Expand Down Expand Up @@ -82,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error>> {
format: render_format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);
}
Expand All @@ -106,7 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = encoder.begin_render_pass(
&wgpu::RenderPassDescriptor {
label: Some("Render pass"),
color_attachments: &[
color_attachments: &[Some(
wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
Expand All @@ -122,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> {
store: true,
},
},
],
)],
depth_stencil_attachment: None,
},
);
Expand Down Expand Up @@ -183,13 +181,7 @@ fn main() -> Result<(), Box<dyn Error>> {
queue.submit(Some(encoder.finish()));
frame.present();
// Recall unused staging buffers
use futures::task::SpawnExt;

local_spawner
.spawn(staging_belt.recall())
.expect("Recall staging belt");

local_pool.run_until_stalled();
staging_belt.recall();
}
_ => {
*control_flow = winit::event_loop::ControlFlow::Wait;
Expand Down
18 changes: 5 additions & 13 deletions examples/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ fn main() -> Result<(), Box<dyn Error>> {
.expect("Request device")
});

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

// Prepare swap chain and depth buffer
let mut size = window.inner_size();
Expand Down Expand Up @@ -101,7 +99,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = encoder.begin_render_pass(
&wgpu::RenderPassDescriptor {
label: Some("Render pass"),
color_attachments: &[
color_attachments: &[Some(
wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
Expand All @@ -117,7 +115,7 @@ fn main() -> Result<(), Box<dyn Error>> {
store: true,
},
},
],
)],
depth_stencil_attachment: None,
},
);
Expand Down Expand Up @@ -180,13 +178,7 @@ fn main() -> Result<(), Box<dyn Error>> {
queue.submit(Some(encoder.finish()));
frame.present();
// Recall unused staging buffers
use futures::task::SpawnExt;

local_spawner
.spawn(staging_belt.recall())
.expect("Recall staging belt");

local_pool.run_until_stalled();
staging_belt.recall();
}
_ => {
*control_flow = winit::event_loop::ControlFlow::Wait;
Expand All @@ -209,7 +201,7 @@ fn create_frame_views(
format: FORMAT,
width,
height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);

Expand Down
20 changes: 6 additions & 14 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ fn main() -> Result<(), Box<dyn Error>> {
.expect("Request device")
});

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

// Prepare swap chain
let render_format = wgpu::TextureFormat::Bgra8UnormSrgb;
Expand All @@ -48,7 +46,7 @@ fn main() -> Result<(), Box<dyn Error>> {
format: render_format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);

Expand Down Expand Up @@ -82,7 +80,7 @@ fn main() -> Result<(), Box<dyn Error>> {
format: render_format,
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Mailbox,
present_mode: wgpu::PresentMode::AutoVsync,
},
);
}
Expand All @@ -106,7 +104,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let _ = encoder.begin_render_pass(
&wgpu::RenderPassDescriptor {
label: Some("Render pass"),
color_attachments: &[
color_attachments: &[Some(
wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
Expand All @@ -122,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> {
store: true,
},
},
],
)],
depth_stencil_attachment: None,
},
);
Expand Down Expand Up @@ -163,13 +161,7 @@ fn main() -> Result<(), Box<dyn Error>> {
queue.submit(Some(encoder.finish()));
frame.present();
// Recall unused staging buffers
use futures::task::SpawnExt;

local_spawner
.spawn(staging_belt.recall())
.expect("Recall staging belt");

local_pool.run_until_stalled();
staging_belt.recall();
}
_ => {
*control_flow = winit::event_loop::ControlFlow::Wait;
Expand Down
14 changes: 8 additions & 6 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ fn build<D>(
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
ty: wgpu::BindingType::Sampler(
wgpu::SamplerBindingType::Filtering,
),
count: None,
},
wgpu::BindGroupLayoutEntry {
Expand Down Expand Up @@ -277,7 +279,7 @@ fn build<D>(
bind_group_layouts: &[&uniform_layout],
});

let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("Glyph Shader"),
source: wgpu::ShaderSource::Wgsl(crate::Cow::Borrowed(include_str!(
"shader/glyph.wgsl"
Expand Down Expand Up @@ -313,7 +315,7 @@ fn build<D>(
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: render_format,
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent {
Expand All @@ -328,7 +330,7 @@ fn build<D>(
},
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
multiview: None,
});
Expand Down Expand Up @@ -375,14 +377,14 @@ fn draw<D>(
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("wgpu_glyph::pipeline render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
}],
})],
depth_stencil_attachment,
});

Expand Down
38 changes: 19 additions & 19 deletions src/shader/glyph.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 font_sampler: sampler;
[[group(0), binding(2)]] var font_tex: texture_2d<f32>;
@group(0) @binding(0) var<uniform> globals: Globals;
@group(0) @binding(1) var font_sampler: sampler;
@group(0) @binding(2) var font_tex: texture_2d<f32>;

struct VertexInput {
[[builtin(vertex_index)]] vertex_index: u32;
[[location(0)]] left_top: vec3<f32>;
[[location(1)]] right_bottom: vec2<f32>;
[[location(2)]] tex_left_top: vec2<f32>;
[[location(3)]] tex_right_bottom: vec2<f32>;
[[location(4)]] color: vec4<f32>;
};
@builtin(vertex_index) vertex_index: u32,
@location(0) left_top: vec3<f32>,
@location(1) right_bottom: vec2<f32>,
@location(2) tex_left_top: vec2<f32>,
@location(3) tex_right_bottom: vec2<f32>,
@location(4) color: vec4<f32>,
}

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

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

Expand Down Expand Up @@ -57,8 +57,8 @@ 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> {
var alpha: f32 = textureSample(font_tex, font_sampler, input.f_tex_pos).r;

if (alpha <= 0.0) {
Expand Down

0 comments on commit 7e18608

Please sign in to comment.