[rs] Update wgpu-rs for the Cow changes in wgpu

This commit is contained in:
Marvin Löbel
2020-07-20 19:57:45 +02:00
parent 3e8ab741fd
commit 50935bf1d3
15 changed files with 243 additions and 225 deletions

View File

@@ -27,14 +27,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan"]
package = "wgpu-core"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "3c6ee8766ae8df8fc5c2b70f7c37d634ff3b79aa"
rev = "4ed2c0a313deb48a99f15e8fe0558ad3d095ca01"
features = ["raw-window-handle"]
[dependencies.wgt]
package = "wgpu-types"
version = "0.5"
git = "https://github.com/gfx-rs/wgpu"
rev = "3c6ee8766ae8df8fc5c2b70f7c37d634ff3b79aa"
rev = "4ed2c0a313deb48a99f15e8fe0558ad3d095ca01"
[dependencies]
arrayvec = "0.5"

View File

@@ -1,6 +1,8 @@
// Flocking boids example with gpu compute update pass
// adapted from https://github.com/austinEng/webgpu-samples/blob/master/src/examples/computeBoids.ts
use std::borrow::Cow::Borrowed;
#[path = "../framework.rs"]
mod framework;
@@ -57,7 +59,7 @@ impl framework::Example for Example {
let compute_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::COMPUTE,
@@ -84,32 +86,32 @@ impl framework::Example for Example {
readonly: false,
},
),
],
]),
label: None,
});
let compute_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&compute_bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&compute_bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
// create render pipeline with empty bind group layout
let render_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[]),
push_constant_ranges: Borrowed(&[]),
});
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &render_pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -119,27 +121,27 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[
vertex_buffers: Borrowed(&[
wgpu::VertexBufferDescriptor {
stride: 4 * 4,
step_mode: wgpu::InputStepMode::Instance,
attributes: &wgpu::vertex_attr_array![0 => Float2, 1 => Float2],
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Float2, 1 => Float2]),
},
wgpu::VertexBufferDescriptor {
stride: 2 * 4,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![2 => Float2],
attributes: Borrowed(&wgpu::vertex_attr_array![2 => Float2]),
},
],
]),
},
sample_count: 1,
sample_mask: !0,
@@ -152,7 +154,7 @@ impl framework::Example for Example {
layout: &compute_pipeline_layout,
compute_stage: wgpu::ProgrammableStageDescriptor {
module: &boids_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
});
@@ -195,7 +197,7 @@ impl framework::Example for Example {
for i in 0..2 {
particle_bind_groups.push(device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &compute_bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(sim_param_buffer.slice(..)),
@@ -210,7 +212,7 @@ impl framework::Example for Example {
particle_buffers[(i + 1) % 2].slice(..), // bind to opposite buffer
),
},
],
]),
label: None,
}));
}
@@ -256,16 +258,17 @@ impl framework::Example for Example {
queue: &wgpu::Queue,
_spawner: &impl futures::task::LocalSpawn,
) {
// create render pass descriptor
// create render pass descriptor and its color attachments
let color_attachments = [wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: true,
},
}];
let render_pass_descriptor = wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: true,
},
}],
color_attachments: Borrowed(&color_attachments),
depth_stencil_attachment: None,
};

View File

@@ -4,7 +4,7 @@ use std::env;
/// the added benefit that this method doesn't require a window to be created.
use std::fs::File;
use std::io::Write;
use std::mem::size_of;
use std::{borrow::Cow::Borrowed, mem::size_of};
use wgpu::{Buffer, Device};
async fn run(png_output_path: &str) {
@@ -83,14 +83,14 @@ async fn create_red_image_with_dimensions(
let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &texture.create_default_view(),
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::RED),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});

View File

@@ -2,6 +2,7 @@
mod framework;
use bytemuck::{Pod, Zeroable};
use std::borrow::Cow::Borrowed;
#[repr(C)]
#[derive(Clone, Copy)]
@@ -134,7 +135,7 @@ impl framework::Example for Example {
// Create pipeline layout
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::VERTEX,
@@ -157,11 +158,11 @@ impl framework::Example for Example {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: false },
),
],
]),
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
// Create the texture
@@ -217,7 +218,7 @@ impl framework::Example for Example {
// Create bind group
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
@@ -230,7 +231,7 @@ impl framework::Example for Example {
binding: 2,
resource: wgpu::BindingResource::Sampler(&sampler),
},
],
]),
label: None,
});
@@ -242,11 +243,11 @@ impl framework::Example for Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -256,19 +257,19 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
vertex_buffers: Borrowed(&[wgpu::VertexBufferDescriptor {
stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &[
attributes: Borrowed(&[
wgpu::VertexAttributeDescriptor {
format: wgpu::VertexFormat::Float4,
offset: 0,
@@ -279,8 +280,8 @@ impl framework::Example for Example {
offset: 4 * 4,
shader_location: 1,
},
],
}],
]),
}]),
},
sample_count: 1,
sample_mask: !0,
@@ -324,7 +325,7 @@ impl framework::Example for Example {
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
@@ -336,7 +337,7 @@ impl framework::Example for Example {
}),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});
rpass.push_debug_group("Prepare data for draw.");

View File

@@ -1,4 +1,4 @@
use std::{convert::TryInto, str::FromStr};
use std::{borrow::Cow::Borrowed, convert::TryInto, str::FromStr};
async fn run() {
let numbers = if std::env::args().len() <= 1 {
@@ -59,7 +59,7 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[wgpu::BindGroupLayoutEntry::new(
entries: Borrowed(&[wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::COMPUTE,
wgpu::BindingType::StorageBuffer {
@@ -67,28 +67,28 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
readonly: false,
min_binding_size: wgpu::BufferSize::new(4),
},
)],
)]),
});
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: None,
layout: &bind_group_layout,
entries: &[wgpu::BindGroupEntry {
entries: Borrowed(&[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(storage_buffer.slice(..)),
}],
}]),
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
layout: &pipeline_layout,
compute_stage: wgpu::ProgrammableStageDescriptor {
module: &cs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
});

View File

@@ -1,3 +1,4 @@
use std::borrow::Cow::Borrowed;
use winit::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
@@ -35,33 +36,33 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::
let fs_module = device.create_shader_module(wgpu::include_spirv!("shader.frag.spv"));
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[]),
push_constant_ranges: Borrowed(&[]),
});
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
// Use the default rasterizer state: no culling, no depth bias
rasterization_state: None,
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: swapchain_format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
vertex_buffers: Borrowed(&[]),
},
sample_count: 1,
sample_mask: !0,
@@ -110,14 +111,14 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});
rpass.set_pipeline(&render_pipeline);

View File

@@ -2,6 +2,7 @@
mod framework;
use bytemuck::{Pod, Zeroable};
use std::borrow::Cow::Borrowed;
const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
@@ -81,7 +82,7 @@ impl Example {
mip_count: u32,
) {
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::FRAGMENT,
@@ -96,12 +97,12 @@ impl Example {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: false },
),
],
]),
label: None,
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
let vs_module = device.create_shader_module(wgpu::include_spirv!("blit.vert.spv"));
@@ -111,11 +112,11 @@ impl Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -125,16 +126,16 @@ impl Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleStrip,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: TEXTURE_FORMAT,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
vertex_buffers: Borrowed(&[]),
},
sample_count: 1,
sample_mask: !0,
@@ -170,7 +171,7 @@ impl Example {
for target_mip in 1..mip_count as usize {
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureView(&views[target_mip - 1]),
@@ -179,19 +180,19 @@ impl Example {
binding: 1,
resource: wgpu::BindingResource::Sampler(&sampler),
},
],
]),
label: None,
});
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &views[target_mip],
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});
rpass.set_pipeline(&pipeline);
@@ -222,7 +223,7 @@ impl framework::Example for Example {
// Create pipeline layout
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::VERTEX,
@@ -245,12 +246,12 @@ impl framework::Example for Example {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: false },
),
],
]),
label: None,
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
// Create the texture
@@ -316,7 +317,7 @@ impl framework::Example for Example {
// Create bind group
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
@@ -329,7 +330,7 @@ impl framework::Example for Example {
binding: 2,
resource: wgpu::BindingResource::Sampler(&sampler),
},
],
]),
label: None,
});
@@ -341,11 +342,11 @@ impl framework::Example for Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -355,20 +356,20 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleStrip,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
vertex_buffers: Borrowed(&[wgpu::VertexBufferDescriptor {
stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float4],
}],
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Float4]),
}]),
},
sample_count: 1,
sample_mask: !0,
@@ -419,14 +420,14 @@ impl framework::Example for Example {
a: 1.0,
};
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(clear_color),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});
rpass.set_pipeline(&self.draw_pipeline);

View File

@@ -10,7 +10,7 @@
#[path = "../framework.rs"]
mod framework;
use std::iter;
use std::{borrow::Cow, iter};
use bytemuck::{Pod, Zeroable};
@@ -53,11 +53,11 @@ impl Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: vs_module,
entry_point: "main",
entry_point: Cow::Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: fs_module,
entry_point: "main",
entry_point: Cow::Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -67,20 +67,20 @@ impl Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::LineList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Cow::Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
vertex_buffers: Cow::Borrowed(&[wgpu::VertexBufferDescriptor {
stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float2, 1 => Float4],
}],
attributes: Cow::Borrowed(&wgpu::vertex_attr_array![0 => Float2, 1 => Float4]),
}]),
},
sample_count,
sample_mask: !0,
@@ -89,7 +89,7 @@ impl Example {
let mut encoder =
device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor {
label: None,
color_formats: &[sc_desc.format],
color_formats: Cow::Borrowed(&[sc_desc.format]),
depth_stencil_format: None,
sample_count,
});
@@ -140,8 +140,8 @@ impl framework::Example for Example {
let fs_module = device.create_shader_module(wgpu::include_spirv!("shader.frag.spv"));
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[],
push_constant_ranges: &[],
bind_group_layouts: Cow::Borrowed(&[]),
push_constant_ranges: Cow::Borrowed(&[]),
});
let multisampled_framebuffer =
@@ -276,7 +276,7 @@ impl framework::Example for Example {
encoder
.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[rpass_color_attachment],
color_attachments: Cow::Borrowed(&[rpass_color_attachment]),
depth_stencil_attachment: None,
})
.execute_bundles(iter::once(&self.bundle));

View File

@@ -1,4 +1,4 @@
use std::{iter, mem, ops::Range, rc::Rc};
use std::{borrow::Cow::Borrowed, iter, mem, ops::Range, rc::Rc};
#[path = "../framework.rs"]
mod framework;
@@ -242,7 +242,7 @@ impl framework::Example for Example {
let local_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[wgpu::BindGroupLayoutEntry::new(
entries: Borrowed(&[wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::UniformBuffer {
@@ -251,7 +251,7 @@ impl framework::Example for Example {
mem::size_of::<EntityUniforms>() as _
),
},
)],
)]),
label: None,
});
@@ -260,10 +260,10 @@ impl framework::Example for Example {
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &local_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
entries: Borrowed(&[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(plane_uniform_buf.slice(..)),
}],
}]),
label: None,
});
Entity {
@@ -334,10 +334,10 @@ impl framework::Example for Example {
index_count: cube_index_data.len(),
bind_group: device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &local_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
entries: Borrowed(&[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
}],
}]),
label: None,
}),
uniform_buf,
@@ -419,10 +419,11 @@ impl framework::Example for Example {
mapped_at_creation: false,
});
let vertex_attr = wgpu::vertex_attr_array![0 => Char4, 1 => Char4];
let vb_desc = wgpu::VertexBufferDescriptor {
stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Char4, 1 => Char4],
attributes: Borrowed(&vertex_attr),
};
let shadow_pass = {
@@ -430,19 +431,19 @@ impl framework::Example for Example {
// Create pipeline layout
let bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[wgpu::BindGroupLayoutEntry::new(
entries: Borrowed(&[wgpu::BindGroupLayoutEntry::new(
0, // global
wgpu::ShaderStage::VERTEX,
wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: wgpu::BufferSize::new(uniform_size),
},
)],
)]),
label: None,
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout, &local_bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
@@ -455,10 +456,10 @@ impl framework::Example for Example {
// Create bind group
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
entries: &[wgpu::BindGroupEntry {
entries: Borrowed(&[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
}],
}]),
label: None,
});
@@ -470,11 +471,11 @@ impl framework::Example for Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -484,7 +485,7 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[],
color_states: Borrowed(&[]),
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
format: Self::SHADOW_FORMAT,
depth_write_enabled: true,
@@ -496,7 +497,7 @@ impl framework::Example for Example {
}),
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[vb_desc.clone()],
vertex_buffers: Borrowed(&[vb_desc.clone()]),
},
sample_count: 1,
sample_mask: !0,
@@ -514,7 +515,7 @@ impl framework::Example for Example {
// Create pipeline layout
let bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry::new(
0, // global
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
@@ -549,12 +550,12 @@ impl framework::Example for Example {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: true },
),
],
]),
label: None,
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout, &local_bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
@@ -570,7 +571,7 @@ impl framework::Example for Example {
// Create bind group
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
@@ -587,7 +588,7 @@ impl framework::Example for Example {
binding: 3,
resource: wgpu::BindingResource::Sampler(&shadow_sampler),
},
],
]),
label: None,
});
@@ -599,11 +600,11 @@ impl framework::Example for Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -613,12 +614,12 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
format: Self::DEPTH_FORMAT,
depth_write_enabled: true,
@@ -630,7 +631,7 @@ impl framework::Example for Example {
}),
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[vb_desc],
vertex_buffers: Borrowed(&[vb_desc]),
},
sample_count: 1,
sample_mask: !0,
@@ -755,7 +756,7 @@ impl framework::Example for Example {
);
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[],
color_attachments: Borrowed(&[]),
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
attachment: &light.target_view,
depth_ops: Some(wgpu::Operations {
@@ -779,7 +780,7 @@ impl framework::Example for Example {
// forward pass
{
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
@@ -791,7 +792,7 @@ impl framework::Example for Example {
}),
store: true,
},
}],
}]),
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
attachment: &self.forward_depth,
depth_ops: Some(wgpu::Operations {

View File

@@ -2,6 +2,7 @@
mod framework;
use futures::task::{LocalSpawn, LocalSpawnExt};
use std::borrow::Cow::Borrowed;
const SKYBOX_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
@@ -44,7 +45,7 @@ impl framework::Example for Skybox {
queue: &wgpu::Queue,
) -> Self {
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
entries: &[
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry::new(
0,
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
@@ -67,7 +68,7 @@ impl framework::Example for Skybox {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: false },
),
],
]),
label: None,
});
@@ -83,8 +84,8 @@ impl framework::Example for Skybox {
);
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
// Create the render pipeline
@@ -92,11 +93,11 @@ impl framework::Example for Skybox {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Cw,
@@ -106,15 +107,15 @@ impl framework::Example for Skybox {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
vertex_buffers: Borrowed(&[]),
},
depth_stencil_state: None,
sample_count: 1,
@@ -215,7 +216,7 @@ impl framework::Example for Skybox {
});
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
@@ -228,7 +229,7 @@ impl framework::Example for Skybox {
binding: 2,
resource: wgpu::BindingResource::Sampler(&sampler),
},
],
]),
label: None,
});
@@ -284,7 +285,7 @@ impl framework::Example for Skybox {
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
@@ -296,7 +297,7 @@ impl framework::Example for Skybox {
}),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});

View File

@@ -2,6 +2,7 @@
mod framework;
use bytemuck::{Pod, Zeroable};
use std::borrow::Cow::Borrowed;
#[repr(C)]
#[derive(Clone, Copy)]
@@ -200,8 +201,8 @@ impl framework::Example for Example {
let sampler = device.create_sampler(&wgpu::SamplerDescriptor::default());
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("bind group layout"),
entries: &[
label: Some(Borrowed("bind group layout")),
entries: Borrowed(&[
wgpu::BindGroupLayoutEntry {
count: Some(2),
..wgpu::BindGroupLayoutEntry::new(
@@ -219,11 +220,11 @@ impl framework::Example for Example {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: false },
),
],
]),
});
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::TextureViewArray(&[
@@ -235,23 +236,23 @@ impl framework::Example for Example {
binding: 1,
resource: wgpu::BindingResource::Sampler(&sampler),
},
],
]),
layout: &bind_group_layout,
label: Some("bind group"),
label: Some(Borrowed("bind group")),
});
let pipeline_layout = if uniform_workaround {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[wgpu::PushConstantRange {
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[wgpu::PushConstantRange {
stages: wgpu::ShaderStage::FRAGMENT,
range: 0..4,
}],
}]),
})
} else {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
})
};
@@ -259,11 +260,11 @@ impl framework::Example for Example {
layout: &pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -273,20 +274,22 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: None,
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
vertex_buffers: Borrowed(&[wgpu::VertexBufferDescriptor {
stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float2, 1 => Float2, 2 => Int],
}],
attributes: Borrowed(
&wgpu::vertex_attr_array![0 => Float2, 1 => Float2, 2 => Int],
),
}]),
},
sample_count: 1,
sample_mask: !0,
@@ -324,14 +327,14 @@ impl framework::Example for Example {
});
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: true,
},
}],
}]),
depth_stencil_attachment: None,
});

View File

@@ -4,7 +4,7 @@ mod framework;
mod point_gen;
use cgmath::Point3;
use std::{iter, mem};
use std::{borrow::Cow::Borrowed, iter, mem};
///
/// Radius of the terrain.
@@ -231,7 +231,7 @@ impl Example {
let water_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: water_bind_group_layout,
entries: &[
entries: Borrowed(&[
wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(water_uniforms.slice(..)),
@@ -252,8 +252,8 @@ impl Example {
binding: 3,
resource: wgpu::BindingResource::Sampler(&sampler),
},
],
label: Some("Water Bind Group"),
]),
label: Some(Borrowed("Water Bind Group")),
});
(
@@ -350,8 +350,8 @@ impl framework::Example for Example {
// Create the bind group layout. This is what our uniforms will look like.
let water_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Water Bind Group Layout"),
entries: &[
label: Some(Borrowed("Water Bind Group Layout")),
entries: Borrowed(&[
// Uniform variables such as projection/view.
wgpu::BindGroupLayoutEntry::new(
0,
@@ -389,13 +389,13 @@ impl framework::Example for Example {
wgpu::ShaderStage::FRAGMENT,
wgpu::BindingType::Sampler { comparison: false },
),
],
]),
});
let terrain_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Terrain Bind Group Layout"),
entries: &[
label: Some(Borrowed("Terrain Bind Group Layout")),
entries: Borrowed(&[
// Regular uniform variables like view/projection.
wgpu::BindGroupLayoutEntry::new(
0,
@@ -407,20 +407,20 @@ impl framework::Example for Example {
),
},
),
],
]),
});
// Create our pipeline layouts.
let water_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&water_bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&water_bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
let terrain_pipeline_layout =
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
bind_group_layouts: &[&terrain_bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: Borrowed(&[&terrain_bind_group_layout]),
push_constant_ranges: Borrowed(&[]),
});
let water_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
@@ -459,19 +459,19 @@ impl framework::Example for Example {
let terrain_normal_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &terrain_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
entries: Borrowed(&[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(terrain_normal_uniform_buf.slice(..)),
}],
label: Some("Terrain Normal Bind Group"),
}]),
label: Some(Borrowed("Terrain Normal Bind Group")),
});
let terrain_flipped_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
layout: &terrain_bind_group_layout,
entries: &[wgpu::BindGroupEntry {
entries: Borrowed(&[wgpu::BindGroupEntry {
binding: 0,
resource: wgpu::BindingResource::Buffer(terrain_flipped_uniform_buf.slice(..)),
}],
label: Some("Terrain Flipped Bind Group"),
}]),
label: Some(Borrowed("Terrain Flipped Bind Group")),
});
// Upload/compile them to GPU code.
@@ -492,11 +492,11 @@ impl framework::Example for Example {
// Vertex & Fragment shaders
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &water_vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &water_fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
// How the triangles will be rasterized. This is more important
// for the terrain because of the beneath-the water shot.
@@ -512,7 +512,7 @@ impl framework::Example for Example {
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
// Describes how the colour will be interpolated
// and assigned to the output attachment.
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor {
src_factor: wgpu::BlendFactor::SrcAlpha,
@@ -525,7 +525,7 @@ impl framework::Example for Example {
operation: wgpu::BlendOperation::Max,
},
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
// Describes how us writing to the depth/stencil buffer
// will work. Since this is water, we need to read from the
// depth buffer both as a texture in the shader, and as an
@@ -552,11 +552,11 @@ impl framework::Example for Example {
// because we duplicate all the data anyway. This is
// necessary to achieve the low-poly effect.
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
vertex_buffers: Borrowed(&[wgpu::VertexBufferDescriptor {
stride: water_vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Short2, 1 => Char4],
}],
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Short2, 1 => Char4]),
}]),
},
sample_count: 1,
sample_mask: !0,
@@ -568,11 +568,11 @@ impl framework::Example for Example {
layout: &terrain_pipeline_layout,
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &terrain_vs_module,
entry_point: "main",
entry_point: Borrowed("main"),
},
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &terrain_fs_module,
entry_point: "main",
entry_point: Borrowed("main"),
}),
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
@@ -582,12 +582,12 @@ impl framework::Example for Example {
depth_bias_clamp: 0.0,
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
}]),
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
format: wgpu::TextureFormat::Depth32Float,
depth_write_enabled: true,
@@ -599,11 +599,13 @@ impl framework::Example for Example {
}),
vertex_state: wgpu::VertexStateDescriptor {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
vertex_buffers: Borrowed(&[wgpu::VertexBufferDescriptor {
stride: terrain_vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &wgpu::vertex_attr_array![0 => Float3, 1 => Float3, 2 => Uchar4Norm],
}],
attributes: Borrowed(
&wgpu::vertex_attr_array![0 => Float3, 1 => Float3, 2 => Uchar4Norm],
),
}]),
},
sample_count: 1,
sample_mask: !0,
@@ -718,14 +720,14 @@ impl framework::Example for Example {
// First pass: render the reflection.
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &self.reflect_view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(back_color),
store: true,
},
}],
}]),
// We still need to use the depth buffer here
// since the pipeline requires it.
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
@@ -746,14 +748,14 @@ impl framework::Example for Example {
// depth values, so we must use StoreOp::Store.
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(back_color),
store: true,
},
}],
}]),
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
attachment: &self.depth_buffer,
depth_ops: Some(wgpu::Operations {
@@ -772,14 +774,14 @@ impl framework::Example for Example {
// to it, so it cannot be in the same render pass.
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
}],
}]),
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
attachment: &self.depth_buffer,
depth_ops: None,

View File

@@ -9,7 +9,7 @@ use crate::{
use arrayvec::ArrayVec;
use futures::future::{ready, Ready};
use smallvec::SmallVec;
use std::{ffi::CString, fmt, marker::PhantomData, ops::Range, ptr, slice};
use std::{borrow::Cow::Borrowed, ffi::CString, fmt, marker::PhantomData, ops::Range, ptr, slice};
use typed_arena::Arena;
pub struct Context(wgc::hub::Global<wgc::hub::IdentityManagerFactory>);
@@ -636,10 +636,10 @@ impl crate::Context for Context {
bm::BindingResource::TextureView(texture_view.id)
}
BindingResource::TextureViewArray(texture_view_array) => {
bm::BindingResource::TextureViewArray(
bm::BindingResource::TextureViewArray(Borrowed(
texture_view_arena
.alloc_extend(texture_view_array.iter().map(|view| view.id)),
)
))
}
},
})
@@ -649,9 +649,9 @@ impl crate::Context for Context {
wgc::gfx_select!(*device => global.device_create_bind_group(
*device,
&bm::BindGroupDescriptor {
label: desc.label,
label: desc.label.as_ref().map(|label| Borrowed(&label[..])),
layout: desc.layout.id,
entries: &entries,
entries: Borrowed(&entries),
},
PhantomData
))
@@ -684,8 +684,8 @@ impl crate::Context for Context {
wgc::gfx_select!(*device => global.device_create_pipeline_layout(
*device,
&wgt::PipelineLayoutDescriptor {
bind_group_layouts: &temp_layouts,
push_constant_ranges: &desc.push_constant_ranges,
bind_group_layouts: Borrowed(&temp_layouts),
push_constant_ranges: Borrowed(&desc.push_constant_ranges),
},
PhantomData
))
@@ -702,15 +702,19 @@ impl crate::Context for Context {
let vertex_stage = pipe::ProgrammableStageDescriptor {
module: desc.vertex_stage.module.id,
entry_point: desc.vertex_stage.entry_point,
entry_point: Borrowed(&desc.vertex_stage.entry_point),
};
let fragment_stage =
desc.fragment_stage
.as_ref()
.map(|fs| pipe::ProgrammableStageDescriptor {
module: fs.module.id,
entry_point: fs.entry_point,
entry_point: Borrowed(&fs.entry_point),
});
let vertex_state = wgt::VertexStateDescriptor {
index_format: desc.vertex_state.index_format,
vertex_buffers: Borrowed(&desc.vertex_state.vertex_buffers),
};
let global = &self.0;
wgc::gfx_select!(*device => global.device_create_render_pipeline(
@@ -721,9 +725,9 @@ impl crate::Context for Context {
fragment_stage,
rasterization_state: desc.rasterization_state.clone(),
primitive_topology: desc.primitive_topology,
color_states: desc.color_states,
color_states: Borrowed(&desc.color_states),
depth_stencil_state: desc.depth_stencil_state.clone(),
vertex_state: desc.vertex_state,
vertex_state: vertex_state,
sample_count: desc.sample_count,
sample_mask: desc.sample_mask,
alpha_to_coverage_enabled: desc.alpha_to_coverage_enabled,
@@ -747,7 +751,7 @@ impl crate::Context for Context {
layout: desc.layout.id,
compute_stage: pipe::ProgrammableStageDescriptor {
module: desc.compute_stage.module.id,
entry_point: desc.compute_stage.entry_point,
entry_point: Borrowed(&desc.compute_stage.entry_point),
},
},
PhantomData
@@ -1130,7 +1134,7 @@ impl crate::Context for Context {
wgc::command::RenderPass::new(
*encoder,
wgc::command::RenderPassDescriptor {
color_attachments: &colors,
color_attachments: Borrowed(&colors),
depth_stencil_attachment: depth_stencil.as_ref(),
},
)

View File

@@ -322,7 +322,7 @@ fn map_texture_component_type(
fn map_stage_descriptor(
desc: &ProgrammableStageDescriptor,
) -> web_sys::GpuProgrammableStageDescriptor {
web_sys::GpuProgrammableStageDescriptor::new(desc.entry_point, &desc.module.id.0)
web_sys::GpuProgrammableStageDescriptor::new(&desc.entry_point, &desc.module.id.0)
}
fn map_cull_mode(cull_mode: wgt::CullMode) -> web_sys::GpuCullMode {
@@ -910,7 +910,7 @@ impl crate::Context for Context {
.collect::<js_sys::Array>();
let mut mapped_desc = web_sys::GpuBindGroupLayoutDescriptor::new(&mapped_bindings);
if let Some(label) = desc.label {
if let Some(ref label) = desc.label {
mapped_desc.label(label);
}
Sendable(device.0.create_bind_group_layout(&mapped_desc))
@@ -950,7 +950,7 @@ impl crate::Context for Context {
let mut mapped_desc =
web_sys::GpuBindGroupDescriptor::new(&mapped_entries, &desc.layout.id.0);
if let Some(label) = desc.label {
if let Some(ref label) = desc.label {
mapped_desc.label(label);
}
Sendable(device.0.create_bind_group(&mapped_desc))

View File

@@ -798,6 +798,7 @@ pub struct Queue {
/// Resource that can be bound to a pipeline.
#[non_exhaustive]
#[derive(Clone)]
pub enum BindingResource<'a> {
/// Binding is backed by a buffer.
///