Skip to content

Commit

Permalink
Upgrade to latest for wgpu (#62)
Browse files Browse the repository at this point in the history
* Move to latest for wgsl

* Some Cleanup

* Update wgpu-rs for stagingbelt fix crashing iced

* update back to base

* Update wgpu to 0.8

* Fix formatting with `cargo fmt`

Co-authored-by: Héctor Ramón <[email protected]>
  • Loading branch information
Dispersia and hecrj authored May 19, 2021
1 parent fb9a170 commit 2bf6d31
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 125 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ documentation = "https://docs.rs/wgpu_glyph"
readme = "README.md"

[dependencies]
wgpu = "0.7"
wgpu = "0.8"
glyph_brush = "0.7"
log = "0.4"

Expand Down
4 changes: 2 additions & 2 deletions examples/clipping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ fn main() -> Result<(), Box<dyn Error>> {
&wgpu::RenderPassDescriptor {
label: Some("Render pass"),
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
wgpu::RenderPassColorAttachment {
view: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(
Expand Down
11 changes: 5 additions & 6 deletions examples/depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ fn main() -> Result<(), Box<dyn Error>> {
depth_compare: wgpu::CompareFunction::Greater,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
clamp_depth: false,
})
.build(&device, FORMAT);

Expand Down Expand Up @@ -105,8 +104,8 @@ fn main() -> Result<(), Box<dyn Error>> {
&wgpu::RenderPassDescriptor {
label: Some("Render pass"),
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
wgpu::RenderPassColorAttachment {
view: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(
Expand Down Expand Up @@ -162,8 +161,8 @@ fn main() -> Result<(), Box<dyn Error>> {
&mut staging_belt,
&mut encoder,
&frame.view,
wgpu::RenderPassDepthStencilAttachmentDescriptor {
attachment: &depth_view,
wgpu::RenderPassDepthStencilAttachment {
view: &depth_view,
depth_ops: Some(wgpu::Operations {
load: wgpu::LoadOp::Clear(-1.0),
store: true,
Expand Down Expand Up @@ -221,7 +220,7 @@ fn create_frame_views(
size: wgpu::Extent3d {
width,
height,
depth: 1,
depth_or_array_layers: 1,
},
mip_level_count: 1,
sample_count: 1,
Expand Down
4 changes: 2 additions & 2 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ fn main() -> Result<(), Box<dyn Error>> {
&wgpu::RenderPassDescriptor {
label: Some("Render pass"),
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
wgpu::RenderPassColorAttachment {
view: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl<F: Font + Sync, H: BuildHasher> GlyphBrush<wgpu::DepthStencilState, F, H> {
staging_belt: &mut wgpu::util::StagingBelt,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachmentDescriptor,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachment,
target_width: u32,
target_height: u32,
) -> Result<(), String> {
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<F: Font + Sync, H: BuildHasher> GlyphBrush<wgpu::DepthStencilState, F, H> {
staging_belt: &mut wgpu::util::StagingBelt,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachmentDescriptor,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachment,
transform: [f32; 16],
) -> Result<(), String> {
self.process_queued(device, staging_belt, encoder);
Expand Down Expand Up @@ -433,7 +433,7 @@ impl<F: Font + Sync, H: BuildHasher> GlyphBrush<wgpu::DepthStencilState, F, H> {
staging_belt: &mut wgpu::util::StagingBelt,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachmentDescriptor,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachment,
transform: [f32; 16],
region: Region,
) -> Result<(), String> {
Expand Down
72 changes: 36 additions & 36 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Pipeline<wgpu::DepthStencilState> {
staging_belt: &mut wgpu::util::StagingBelt,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachmentDescriptor,
depth_stencil_attachment: wgpu::RenderPassDepthStencilAttachment,
transform: [f32; 16],
region: Option<Region>,
) {
Expand Down Expand Up @@ -236,7 +236,7 @@ fn build<D>(
binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler {
filtering: false,
filtering: true,
comparison: false,
},
count: None,
Expand Down Expand Up @@ -279,74 +279,76 @@ fn build<D>(
bind_group_layouts: &[&uniform_layout],
});

let vs_module =
device.create_shader_module(&wgpu::include_spirv!("shader/vertex.spv"));

let fs_module = device
.create_shader_module(&wgpu::include_spirv!("shader/fragment.spv"));
let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
label: Some("Glyph Shader"),
source: wgpu::ShaderSource::Wgsl(crate::Cow::Borrowed(include_str!(
"shader/glyph.wgsl"
))),
flags: wgpu::ShaderFlags::all(),
});

let raw = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(&layout),
vertex: wgpu::VertexState {
module: &vs_module,
entry_point: "main",
module: &shader,
entry_point: "vs_main",
buffers: &[wgpu::VertexBufferLayout {
array_stride: mem::size_of::<Instance>() as u64,
step_mode: wgpu::InputStepMode::Instance,
attributes: &[
wgpu::VertexAttribute {
shader_location: 0,
format: wgpu::VertexFormat::Float3,
format: wgpu::VertexFormat::Float32x3,
offset: 0,
},
wgpu::VertexAttribute {
shader_location: 1,
format: wgpu::VertexFormat::Float2,
format: wgpu::VertexFormat::Float32x2,
offset: 4 * 3,
},
wgpu::VertexAttribute {
shader_location: 2,
format: wgpu::VertexFormat::Float2,
format: wgpu::VertexFormat::Float32x2,
offset: 4 * (3 + 2),
},
wgpu::VertexAttribute {
shader_location: 3,
format: wgpu::VertexFormat::Float2,
format: wgpu::VertexFormat::Float32x2,
offset: 4 * (3 + 2 + 2),
},
wgpu::VertexAttribute {
shader_location: 4,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
offset: 4 * (3 + 2 + 2 + 2),
},
],
}],
},
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleStrip,
strip_index_format: None,
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::None,
polygon_mode: wgpu::PolygonMode::Fill,
..Default::default()
},
depth_stencil,
multisample: wgpu::MultisampleState::default(),
fragment: Some(wgpu::FragmentState {
module: &fs_module,
entry_point: "main",
module: &shader,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
format: render_format,
color_blend: wgpu::BlendState {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
alpha_blend: wgpu::BlendState {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent {
src_factor: wgpu::BlendFactor::SrcAlpha,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
alpha: wgpu::BlendComponent {
src_factor: wgpu::BlendFactor::One,
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
operation: wgpu::BlendOperation::Add,
},
}),
write_mask: wgpu::ColorWrite::ALL,
}],
}),
Expand All @@ -373,9 +375,7 @@ fn draw<D>(
staging_belt: &mut wgpu::util::StagingBelt,
encoder: &mut wgpu::CommandEncoder,
target: &wgpu::TextureView,
depth_stencil_attachment: Option<
wgpu::RenderPassDepthStencilAttachmentDescriptor,
>,
depth_stencil_attachment: Option<wgpu::RenderPassDepthStencilAttachment>,
transform: [f32; 16],
region: Option<Region>,
) {
Expand All @@ -396,8 +396,8 @@ fn draw<D>(
let mut render_pass =
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("wgpu_glyph::pipeline render pass"),
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: target,
color_attachments: &[wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
Expand Down Expand Up @@ -436,11 +436,11 @@ fn create_uniforms(
entries: &[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer {
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
buffer: transform,
offset: 0,
size: None,
},
}),
},
wgpu::BindGroupEntry {
binding: 1,
Expand Down
19 changes: 11 additions & 8 deletions src/pipeline/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use core::num::NonZeroU64;
use std::num::NonZeroU32;

pub struct Cache {
texture: wgpu::Texture,
Expand All @@ -17,7 +18,7 @@ impl Cache {
size: wgpu::Extent3d {
width,
height,
depth: 1,
depth_or_array_layers: 1,
},
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::R8Unorm,
Expand Down Expand Up @@ -70,7 +71,8 @@ impl Cache {
device.create_buffer(&wgpu::BufferDescriptor {
label: Some("wgpu_glyph::Cache upload buffer"),
size: padded_data_size,
usage: wgpu::BufferUsage::COPY_DST | wgpu::BufferUsage::COPY_SRC,
usage: wgpu::BufferUsage::COPY_DST
| wgpu::BufferUsage::COPY_SRC,
mapped_at_creation: false,
});

Expand All @@ -90,16 +92,17 @@ impl Cache {
.copy_from_slice(&data[row * width..(row + 1) * width])
}

// TODO: Move to use Queue for less buffer usage
encoder.copy_buffer_to_texture(
wgpu::BufferCopyView {
wgpu::ImageCopyBuffer {
buffer: &self.upload_buffer,
layout: wgpu::TextureDataLayout {
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: padded_width as u32,
rows_per_image: height as u32,
bytes_per_row: NonZeroU32::new(padded_width as u32),
rows_per_image: NonZeroU32::new(height as u32),
},
},
wgpu::TextureCopyView {
wgpu::ImageCopyTexture {
texture: &self.texture,
mip_level: 0,
origin: wgpu::Origin3d {
Expand All @@ -111,7 +114,7 @@ impl Cache {
wgpu::Extent3d {
width: size[0] as u32,
height: size[1] as u32,
depth: 1,
depth_or_array_layers: 1,
},
);
}
Expand Down
19 changes: 0 additions & 19 deletions src/shader/fragment.frag

This file was deleted.

Binary file removed src/shader/fragment.spv
Binary file not shown.
Loading

0 comments on commit 2bf6d31

Please sign in to comment.