mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Merge #501
501: Fighting back the bovine forces r=kvark a=Kimundi <img src="https://dcassetcdn.com/w1k/submissions/399000/399327_d0ba.jpg" width="300"> "Good work boys, we'll get 'em next time!" Co-authored-by: Marvin Löbel <loebel.marvin@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// 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;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
#[path = "../framework.rs"]
|
||||
@@ -61,7 +60,7 @@ impl framework::Example for Example {
|
||||
|
||||
let compute_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::COMPUTE,
|
||||
@@ -88,32 +87,32 @@ impl framework::Example for Example {
|
||||
readonly: false,
|
||||
},
|
||||
),
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
let compute_pipeline_layout =
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&compute_bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&compute_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
// create render pipeline with empty bind group layout
|
||||
|
||||
let render_pipeline_layout =
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
layout: Some(&render_pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -121,27 +120,27 @@ impl framework::Example for Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[
|
||||
vertex_buffers: &[
|
||||
wgpu::VertexBufferDescriptor {
|
||||
stride: 4 * 4,
|
||||
step_mode: wgpu::InputStepMode::Instance,
|
||||
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Float2, 1 => Float2]),
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float2, 1 => Float2],
|
||||
},
|
||||
wgpu::VertexBufferDescriptor {
|
||||
stride: 2 * 4,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(&wgpu::vertex_attr_array![2 => Float2]),
|
||||
attributes: &wgpu::vertex_attr_array![2 => Float2],
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -154,7 +153,7 @@ impl framework::Example for Example {
|
||||
layout: Some(&compute_pipeline_layout),
|
||||
compute_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &boids_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -201,7 +200,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: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(sim_param_buffer.slice(..)),
|
||||
@@ -216,7 +215,7 @@ impl framework::Example for Example {
|
||||
particle_buffers[(i + 1) % 2].slice(..), // bind to opposite buffer
|
||||
),
|
||||
},
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
}));
|
||||
}
|
||||
@@ -272,7 +271,7 @@ impl framework::Example for Example {
|
||||
},
|
||||
}];
|
||||
let render_pass_descriptor = wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&color_attachments),
|
||||
color_attachments: &color_attachments,
|
||||
depth_stencil_attachment: None,
|
||||
};
|
||||
|
||||
|
||||
@@ -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::{borrow::Cow::Borrowed, mem::size_of};
|
||||
use std::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: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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,
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
mod framework;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::borrow::Cow::Borrowed;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -140,7 +139,7 @@ impl framework::Example for Example {
|
||||
// Create pipeline layout
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::VERTEX,
|
||||
@@ -163,11 +162,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: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
// Create the texture
|
||||
@@ -224,7 +223,7 @@ impl framework::Example for Example {
|
||||
// Create bind group
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
||||
@@ -237,7 +236,7 @@ impl framework::Example for Example {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -249,11 +248,11 @@ impl framework::Example for Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -261,19 +260,19 @@ impl framework::Example for Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[wgpu::VertexBufferDescriptor {
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(&[
|
||||
attributes: &[
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
format: wgpu::VertexFormat::Float4,
|
||||
offset: 0,
|
||||
@@ -284,8 +283,8 @@ impl framework::Example for Example {
|
||||
offset: 4 * 4,
|
||||
shader_location: 1,
|
||||
},
|
||||
]),
|
||||
}]),
|
||||
],
|
||||
}],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -329,7 +328,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: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
@@ -341,7 +340,7 @@ impl framework::Example for Example {
|
||||
}),
|
||||
store: true,
|
||||
},
|
||||
}]),
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
rpass.push_debug_group("Prepare data for draw.");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow::Borrowed, convert::TryInto, str::FromStr};
|
||||
use std::{convert::TryInto, str::FromStr};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
async fn run() {
|
||||
@@ -63,7 +63,7 @@ async fn execute_gpu(numbers: Vec<u32>) -> Vec<u32> {
|
||||
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
label: None,
|
||||
entries: Borrowed(&[wgpu::BindGroupLayoutEntry::new(
|
||||
entries: &[wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::COMPUTE,
|
||||
wgpu::BindingType::StorageBuffer {
|
||||
@@ -71,28 +71,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: Borrowed(&[wgpu::BindGroupEntry {
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(storage_buffer.slice(..)),
|
||||
}]),
|
||||
}],
|
||||
});
|
||||
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
layout: Some(&pipeline_layout),
|
||||
compute_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &cs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::borrow::Cow::Borrowed;
|
||||
use winit::{
|
||||
event::{Event, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
@@ -36,33 +35,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: Borrowed(&[]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
// Use the default rasterizer state: no culling, no depth bias
|
||||
rasterization_state: None,
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[]),
|
||||
vertex_buffers: &[],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -111,14 +110,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: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
mod framework;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::{borrow::Cow::Borrowed, num::NonZeroU32};
|
||||
use std::num::NonZeroU32;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
const TEXTURE_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8UnormSrgb;
|
||||
@@ -83,7 +83,7 @@ impl Example {
|
||||
mip_count: u32,
|
||||
) {
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::FRAGMENT,
|
||||
@@ -98,12 +98,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: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let vs_module = device.create_shader_module(wgpu::include_spirv!("blit.vert.spv"));
|
||||
@@ -113,11 +113,11 @@ impl Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -125,16 +125,16 @@ impl Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleStrip,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[]),
|
||||
vertex_buffers: &[],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -142,7 +142,7 @@ impl Example {
|
||||
});
|
||||
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some(Borrowed("mip")),
|
||||
label: Some("mip"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
@@ -155,7 +155,7 @@ impl Example {
|
||||
let views = (0..mip_count)
|
||||
.map(|mip| {
|
||||
texture.create_view(&wgpu::TextureViewDescriptor {
|
||||
label: Some(Borrowed("mip")),
|
||||
label: Some("mip"),
|
||||
format: TEXTURE_FORMAT,
|
||||
dimension: wgpu::TextureViewDimension::D2,
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
@@ -170,7 +170,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: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureView(&views[target_mip - 1]),
|
||||
@@ -179,19 +179,19 @@ impl Example {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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);
|
||||
@@ -223,7 +223,7 @@ impl framework::Example for Example {
|
||||
|
||||
// Create pipeline layout
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::VERTEX,
|
||||
@@ -246,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: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
// Create the texture
|
||||
@@ -321,7 +321,7 @@ impl framework::Example for Example {
|
||||
// Create bind group
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
||||
@@ -334,7 +334,7 @@ impl framework::Example for Example {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -346,11 +346,11 @@ impl framework::Example for Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -358,20 +358,20 @@ impl framework::Example for Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleStrip,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[wgpu::VertexBufferDescriptor {
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Float4]),
|
||||
}]),
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float4],
|
||||
}],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -422,14 +422,14 @@ impl framework::Example for Example {
|
||||
a: 1.0,
|
||||
};
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#[path = "../framework.rs"]
|
||||
mod framework;
|
||||
|
||||
use std::{borrow::Cow::Borrowed, iter};
|
||||
use std::iter;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use wgpu::util::DeviceExt;
|
||||
@@ -54,11 +54,11 @@ impl Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -66,20 +66,20 @@ impl Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::LineList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[wgpu::VertexBufferDescriptor {
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Float2, 1 => Float4]),
|
||||
}]),
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float2, 1 => Float4],
|
||||
}],
|
||||
},
|
||||
sample_count,
|
||||
sample_mask: !0,
|
||||
@@ -88,7 +88,7 @@ impl Example {
|
||||
let mut encoder =
|
||||
device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor {
|
||||
label: None,
|
||||
color_formats: Borrowed(&[sc_desc.format]),
|
||||
color_formats: &[sc_desc.format],
|
||||
depth_stencil_format: None,
|
||||
sample_count,
|
||||
});
|
||||
@@ -96,7 +96,7 @@ impl Example {
|
||||
encoder.set_vertex_buffer(0, vertex_buffer.slice(..));
|
||||
encoder.draw(0..vertex_count, 0..1);
|
||||
encoder.finish(&wgpu::RenderBundleDescriptor {
|
||||
label: Some(Borrowed("main")),
|
||||
label: Some("main"),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -139,8 +139,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: Borrowed(&[]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let multisampled_framebuffer =
|
||||
@@ -276,7 +276,7 @@ impl framework::Example for Example {
|
||||
|
||||
encoder
|
||||
.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[rpass_color_attachment]),
|
||||
color_attachments: &[rpass_color_attachment],
|
||||
depth_stencil_attachment: None,
|
||||
})
|
||||
.execute_bundles(iter::once(&self.bundle));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{borrow::Cow::Borrowed, iter, mem, num::NonZeroU32, ops::Range, rc::Rc};
|
||||
use std::{iter, mem, num::NonZeroU32, ops::Range, rc::Rc};
|
||||
|
||||
#[path = "../framework.rs"]
|
||||
mod framework;
|
||||
@@ -255,7 +255,7 @@ impl framework::Example for Example {
|
||||
|
||||
let local_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[wgpu::BindGroupLayoutEntry::new(
|
||||
entries: &[wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
wgpu::BindingType::UniformBuffer {
|
||||
@@ -264,7 +264,7 @@ impl framework::Example for Example {
|
||||
mem::size_of::<EntityUniforms>() as _
|
||||
),
|
||||
},
|
||||
)]),
|
||||
)],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -273,10 +273,10 @@ impl framework::Example for Example {
|
||||
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &local_bind_group_layout,
|
||||
entries: Borrowed(&[wgpu::BindGroupEntry {
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(plane_uniform_buf.slice(..)),
|
||||
}]),
|
||||
}],
|
||||
label: None,
|
||||
});
|
||||
Entity {
|
||||
@@ -347,10 +347,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: Borrowed(&[wgpu::BindGroupEntry {
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
||||
}]),
|
||||
}],
|
||||
label: None,
|
||||
}),
|
||||
uniform_buf,
|
||||
@@ -359,7 +359,7 @@ impl framework::Example for Example {
|
||||
|
||||
// Create other resources
|
||||
let shadow_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some(Borrowed("shadow")),
|
||||
label: Some("shadow"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
@@ -384,7 +384,7 @@ impl framework::Example for Example {
|
||||
let mut shadow_target_views = (0..2)
|
||||
.map(|i| {
|
||||
Some(shadow_texture.create_view(&wgpu::TextureViewDescriptor {
|
||||
label: Some(Borrowed("shadow")),
|
||||
label: Some("shadow"),
|
||||
format: Self::SHADOW_FORMAT,
|
||||
dimension: wgpu::TextureViewDimension::D2,
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
@@ -436,7 +436,7 @@ impl framework::Example for Example {
|
||||
let vb_desc = wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(&vertex_attr),
|
||||
attributes: &vertex_attr,
|
||||
};
|
||||
|
||||
let shadow_pass = {
|
||||
@@ -444,19 +444,19 @@ impl framework::Example for Example {
|
||||
// Create pipeline layout
|
||||
let bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[wgpu::BindGroupLayoutEntry::new(
|
||||
entries: &[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: Borrowed(&[&bind_group_layout, &local_bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
@@ -469,10 +469,10 @@ impl framework::Example for Example {
|
||||
// Create bind group
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: Borrowed(&[wgpu::BindGroupEntry {
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
||||
}]),
|
||||
}],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -484,11 +484,11 @@ impl framework::Example for Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -499,7 +499,7 @@ impl framework::Example for Example {
|
||||
clamp_depth: device.features().contains(wgpu::Features::DEPTH_CLAMPING),
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[]),
|
||||
color_states: &[],
|
||||
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
|
||||
format: Self::SHADOW_FORMAT,
|
||||
depth_write_enabled: true,
|
||||
@@ -511,7 +511,7 @@ impl framework::Example for Example {
|
||||
}),
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: Borrowed(&[vb_desc.clone()]),
|
||||
vertex_buffers: &[vb_desc.clone()],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -529,7 +529,7 @@ impl framework::Example for Example {
|
||||
// Create pipeline layout
|
||||
let bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0, // global
|
||||
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
@@ -564,12 +564,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: Borrowed(&[&bind_group_layout, &local_bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
|
||||
@@ -586,7 +586,7 @@ impl framework::Example for Example {
|
||||
// Create bind group
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
||||
@@ -603,7 +603,7 @@ impl framework::Example for Example {
|
||||
binding: 3,
|
||||
resource: wgpu::BindingResource::Sampler(&shadow_sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -615,11 +615,11 @@ impl framework::Example for Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -627,12 +627,12 @@ impl framework::Example for Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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,
|
||||
@@ -644,7 +644,7 @@ impl framework::Example for Example {
|
||||
}),
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: Borrowed(&[vb_desc]),
|
||||
vertex_buffers: &[vb_desc],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -769,7 +769,7 @@ impl framework::Example for Example {
|
||||
);
|
||||
|
||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[]),
|
||||
color_attachments: &[],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &light.target_view,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
@@ -793,7 +793,7 @@ impl framework::Example for Example {
|
||||
// forward pass
|
||||
{
|
||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
@@ -805,7 +805,7 @@ impl framework::Example for Example {
|
||||
}),
|
||||
store: true,
|
||||
},
|
||||
}]),
|
||||
}],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &self.forward_depth,
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
mod framework;
|
||||
|
||||
use futures::task::{LocalSpawn, LocalSpawnExt};
|
||||
use std::borrow::Cow::Borrowed;
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
const IMAGE_SIZE: u32 = 512;
|
||||
@@ -50,7 +49,7 @@ impl framework::Example for Skybox {
|
||||
queue: &wgpu::Queue,
|
||||
) -> Self {
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
@@ -73,7 +72,7 @@ impl framework::Example for Skybox {
|
||||
wgpu::ShaderStage::FRAGMENT,
|
||||
wgpu::BindingType::Sampler { comparison: false },
|
||||
),
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -90,8 +89,8 @@ impl framework::Example for Skybox {
|
||||
});
|
||||
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
// Create the render pipeline
|
||||
@@ -99,11 +98,11 @@ impl framework::Example for Skybox {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Cw,
|
||||
@@ -111,15 +110,15 @@ impl framework::Example for Skybox {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[]),
|
||||
vertex_buffers: &[],
|
||||
},
|
||||
depth_stencil_state: None,
|
||||
sample_count: 1,
|
||||
@@ -260,7 +259,7 @@ impl framework::Example for Skybox {
|
||||
});
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(uniform_buf.slice(..)),
|
||||
@@ -273,7 +272,7 @@ impl framework::Example for Skybox {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
@@ -329,7 +328,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: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
@@ -341,7 +340,7 @@ impl framework::Example for Skybox {
|
||||
}),
|
||||
store: true,
|
||||
},
|
||||
}]),
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
mod framework;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use std::borrow::Cow::Borrowed;
|
||||
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -153,11 +153,11 @@ impl framework::Example for Example {
|
||||
label: None,
|
||||
};
|
||||
let red_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some(Borrowed("red")),
|
||||
label: Some("red"),
|
||||
..texture_descriptor
|
||||
});
|
||||
let green_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some(Borrowed("green")),
|
||||
label: Some("green"),
|
||||
..texture_descriptor
|
||||
});
|
||||
|
||||
@@ -204,8 +204,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(Borrowed("bind group layout")),
|
||||
entries: Borrowed(&[
|
||||
label: Some("bind group layout"),
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
count: Some(2),
|
||||
..wgpu::BindGroupLayoutEntry::new(
|
||||
@@ -223,11 +223,11 @@ impl framework::Example for Example {
|
||||
wgpu::ShaderStage::FRAGMENT,
|
||||
wgpu::BindingType::Sampler { comparison: false },
|
||||
),
|
||||
]),
|
||||
],
|
||||
});
|
||||
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::TextureViewArray(&[
|
||||
@@ -239,23 +239,23 @@ impl framework::Example for Example {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
],
|
||||
layout: &bind_group_layout,
|
||||
label: Some(Borrowed("bind group")),
|
||||
label: Some("bind group"),
|
||||
});
|
||||
|
||||
let pipeline_layout = if uniform_workaround {
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[wgpu::PushConstantRange {
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[wgpu::PushConstantRange {
|
||||
stages: wgpu::ShaderStage::FRAGMENT,
|
||||
range: 0..4,
|
||||
}]),
|
||||
}],
|
||||
})
|
||||
} else {
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
})
|
||||
};
|
||||
|
||||
@@ -263,11 +263,11 @@ impl framework::Example for Example {
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -275,22 +275,20 @@ impl framework::Example for Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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: Borrowed(&[wgpu::VertexBufferDescriptor {
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(
|
||||
&wgpu::vertex_attr_array![0 => Float2, 1 => Float2, 2 => Int],
|
||||
),
|
||||
}]),
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float2, 1 => Float2, 2 => Int],
|
||||
}],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -324,18 +322,18 @@ impl framework::Example for Example {
|
||||
_spawner: &impl futures::task::LocalSpawn,
|
||||
) {
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some(Borrowed("primary")),
|
||||
label: Some("primary"),
|
||||
});
|
||||
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
|
||||
store: true,
|
||||
},
|
||||
}]),
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ mod framework;
|
||||
mod point_gen;
|
||||
|
||||
use cgmath::Point3;
|
||||
use std::{borrow::Cow::Borrowed, iter, mem};
|
||||
use std::{iter, mem};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
///
|
||||
@@ -196,7 +196,7 @@ impl Example {
|
||||
};
|
||||
|
||||
let reflection_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some(Borrowed("Reflection Render Texture")),
|
||||
label: Some("Reflection Render Texture"),
|
||||
size: texture_extent,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
@@ -208,7 +208,7 @@ impl Example {
|
||||
});
|
||||
|
||||
let draw_depth_buffer = device.create_texture(&wgpu::TextureDescriptor {
|
||||
label: Some(Borrowed("Depth Buffer")),
|
||||
label: Some("Depth Buffer"),
|
||||
size: texture_extent,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
@@ -220,7 +220,7 @@ impl Example {
|
||||
});
|
||||
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some(Borrowed("Texture Sampler")),
|
||||
label: Some("Texture Sampler"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
@@ -234,7 +234,7 @@ impl Example {
|
||||
|
||||
let water_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: water_bind_group_layout,
|
||||
entries: Borrowed(&[
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(water_uniforms.slice(..)),
|
||||
@@ -253,8 +253,8 @@ impl Example {
|
||||
binding: 3,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
]),
|
||||
label: Some(Borrowed("Water Bind Group")),
|
||||
],
|
||||
label: Some("Water Bind Group"),
|
||||
});
|
||||
|
||||
(
|
||||
@@ -353,8 +353,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(Borrowed("Water Bind Group Layout")),
|
||||
entries: Borrowed(&[
|
||||
label: Some("Water Bind Group Layout"),
|
||||
entries: &[
|
||||
// Uniform variables such as projection/view.
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
@@ -392,13 +392,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(Borrowed("Terrain Bind Group Layout")),
|
||||
entries: Borrowed(&[
|
||||
label: Some("Terrain Bind Group Layout"),
|
||||
entries: &[
|
||||
// Regular uniform variables like view/projection.
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
0,
|
||||
@@ -410,38 +410,38 @@ impl framework::Example for Example {
|
||||
),
|
||||
},
|
||||
),
|
||||
]),
|
||||
],
|
||||
});
|
||||
|
||||
// Create our pipeline layouts.
|
||||
let water_pipeline_layout =
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&water_bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&water_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let terrain_pipeline_layout =
|
||||
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
bind_group_layouts: Borrowed(&[&terrain_bind_group_layout]),
|
||||
push_constant_ranges: Borrowed(&[]),
|
||||
bind_group_layouts: &[&terrain_bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let water_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some(Borrowed("Water Uniforms")),
|
||||
label: Some("Water Uniforms"),
|
||||
size: mem::size_of::<WaterUniforms>() as _,
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let terrain_normal_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some(Borrowed("Normal Terrain Uniforms")),
|
||||
label: Some("Normal Terrain Uniforms"),
|
||||
size: mem::size_of::<TerrainUniforms>() as _,
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let terrain_flipped_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some(Borrowed("Flipped Terrain Uniforms")),
|
||||
label: Some("Flipped Terrain Uniforms"),
|
||||
size: mem::size_of::<TerrainUniforms>() as _,
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
@@ -462,19 +462,19 @@ impl framework::Example for Example {
|
||||
|
||||
let terrain_normal_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &terrain_bind_group_layout,
|
||||
entries: Borrowed(&[wgpu::BindGroupEntry {
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(terrain_normal_uniform_buf.slice(..)),
|
||||
}]),
|
||||
label: Some(Borrowed("Terrain Normal Bind Group")),
|
||||
}],
|
||||
label: Some("Terrain Normal Bind Group"),
|
||||
});
|
||||
let terrain_flipped_bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &terrain_bind_group_layout,
|
||||
entries: Borrowed(&[wgpu::BindGroupEntry {
|
||||
entries: &[wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: wgpu::BindingResource::Buffer(terrain_flipped_uniform_buf.slice(..)),
|
||||
}]),
|
||||
label: Some(Borrowed("Terrain Flipped Bind Group")),
|
||||
}],
|
||||
label: Some("Terrain Flipped Bind Group"),
|
||||
});
|
||||
|
||||
// Upload/compile them to GPU code.
|
||||
@@ -495,11 +495,11 @@ impl framework::Example for Example {
|
||||
// Vertex & Fragment shaders
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &water_vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &water_fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
// How the triangles will be rasterized. This is more important
|
||||
// for the terrain because of the beneath-the water shot.
|
||||
@@ -513,7 +513,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: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: sc_desc.format,
|
||||
color_blend: wgpu::BlendDescriptor {
|
||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||
@@ -526,7 +526,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
|
||||
@@ -553,11 +553,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: Borrowed(&[wgpu::VertexBufferDescriptor {
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: water_vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(&wgpu::vertex_attr_array![0 => Short2, 1 => Char4]),
|
||||
}]),
|
||||
attributes: &wgpu::vertex_attr_array![0 => Short2, 1 => Char4],
|
||||
}],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -569,11 +569,11 @@ impl framework::Example for Example {
|
||||
layout: Some(&terrain_pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &terrain_vs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &terrain_fs_module,
|
||||
entry_point: Borrowed("main"),
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
@@ -581,12 +581,12 @@ impl framework::Example for Example {
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: Borrowed(&[wgpu::ColorStateDescriptor {
|
||||
color_states: &[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,
|
||||
@@ -598,13 +598,11 @@ impl framework::Example for Example {
|
||||
}),
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: Borrowed(&[wgpu::VertexBufferDescriptor {
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: terrain_vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: Borrowed(
|
||||
&wgpu::vertex_attr_array![0 => Float3, 1 => Float3, 2 => Uchar4Norm],
|
||||
),
|
||||
}]),
|
||||
attributes: &wgpu::vertex_attr_array![0 => Float3, 1 => Float3, 2 => Uchar4Norm],
|
||||
}],
|
||||
},
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
@@ -713,20 +711,20 @@ impl framework::Example for Example {
|
||||
// The encoder provides a way to turn our instructions here, into
|
||||
// a command buffer the GPU can understand.
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some(Borrowed("Main Command Encoder")),
|
||||
label: Some("Main Command Encoder"),
|
||||
});
|
||||
|
||||
// First pass: render the reflection.
|
||||
{
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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 {
|
||||
@@ -747,14 +745,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: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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 {
|
||||
@@ -773,14 +771,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: Borrowed(&[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
color_attachments: &[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,
|
||||
|
||||
@@ -1,21 +1,17 @@
|
||||
use crate::{
|
||||
backend::native_gpu_future, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
|
||||
CommandEncoderDescriptor, ComputePipelineDescriptor, Features, Limits, LoadOp, MapMode,
|
||||
Operations, PipelineLayoutDescriptor, RenderPipelineDescriptor, SamplerDescriptor,
|
||||
ShaderModuleSource, SwapChainStatus, TextureDescriptor, TextureViewDescriptor,
|
||||
Operations, PipelineLayoutDescriptor, RenderBundleEncoderDescriptor, RenderPipelineDescriptor,
|
||||
SamplerDescriptor, ShaderModuleSource, SwapChainStatus, TextureDescriptor,
|
||||
TextureViewDescriptor,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
use futures::future::{ready, Ready};
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
borrow::Cow::{self, Borrowed},
|
||||
error::Error,
|
||||
ffi::CString,
|
||||
fmt,
|
||||
marker::PhantomData,
|
||||
ops::Range,
|
||||
ptr, slice,
|
||||
borrow::Cow::Borrowed, error::Error, ffi::CString, fmt, marker::PhantomData, ops::Range, ptr,
|
||||
slice,
|
||||
};
|
||||
use typed_arena::Arena;
|
||||
|
||||
@@ -614,7 +610,10 @@ impl crate::Context for Context {
|
||||
) -> Self::BindGroupLayoutId {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(
|
||||
*device => global.device_create_bind_group_layout(*device, desc, PhantomData)
|
||||
*device => global.device_create_bind_group_layout(*device, &wgt::BindGroupLayoutDescriptor {
|
||||
label: desc.label.map(Borrowed),
|
||||
entries: Borrowed(desc.entries),
|
||||
}, PhantomData)
|
||||
)
|
||||
.unwrap_pretty()
|
||||
}
|
||||
@@ -723,9 +722,19 @@ impl crate::Context for Context {
|
||||
module: fs.module.id,
|
||||
entry_point: Borrowed(&fs.entry_point),
|
||||
});
|
||||
let vertex_buffers: ArrayVec<[_; wgc::device::MAX_VERTEX_BUFFERS]> = desc
|
||||
.vertex_state
|
||||
.vertex_buffers
|
||||
.iter()
|
||||
.map(|vertex_buffer| wgt::VertexBufferDescriptor {
|
||||
stride: vertex_buffer.stride,
|
||||
step_mode: vertex_buffer.step_mode,
|
||||
attributes: Borrowed(vertex_buffer.attributes),
|
||||
})
|
||||
.collect();
|
||||
let vertex_state = wgt::VertexStateDescriptor {
|
||||
index_format: desc.vertex_state.index_format,
|
||||
vertex_buffers: Borrowed(&desc.vertex_state.vertex_buffers),
|
||||
vertex_buffers: Borrowed(&vertex_buffers),
|
||||
};
|
||||
|
||||
let global = &self.0;
|
||||
@@ -778,14 +787,19 @@ impl crate::Context for Context {
|
||||
fn device_create_buffer(
|
||||
&self,
|
||||
device: &Self::DeviceId,
|
||||
desc: &wgt::BufferDescriptor<Option<Cow<'_, str>>>,
|
||||
desc: &crate::BufferDescriptor<'_>,
|
||||
) -> Self::BufferId {
|
||||
let owned_label = OwnedLabel::new(desc.label.as_deref());
|
||||
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(*device => global.device_create_buffer(
|
||||
*device,
|
||||
&desc.map_label(|_| owned_label.as_ptr()),
|
||||
&wgt::BufferDescriptor {
|
||||
label: owned_label.as_ptr(),
|
||||
mapped_at_creation: desc.mapped_at_creation,
|
||||
size: desc.size,
|
||||
usage: desc.usage,
|
||||
},
|
||||
PhantomData
|
||||
))
|
||||
.unwrap_pretty()
|
||||
@@ -801,7 +815,15 @@ impl crate::Context for Context {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(*device => global.device_create_texture(
|
||||
*device,
|
||||
&desc.map_label(|_| owned_label.as_ptr()),
|
||||
&wgt::TextureDescriptor {
|
||||
label: owned_label.as_ptr(),
|
||||
size: desc.size,
|
||||
mip_level_count: desc.mip_level_count,
|
||||
sample_count: desc.sample_count,
|
||||
dimension: desc.dimension,
|
||||
format:desc.format,
|
||||
usage:desc.usage,
|
||||
},
|
||||
PhantomData
|
||||
))
|
||||
.unwrap_pretty()
|
||||
@@ -817,7 +839,19 @@ impl crate::Context for Context {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(*device => global.device_create_sampler(
|
||||
*device,
|
||||
&desc.map_label(|_| owned_label.as_ptr()),
|
||||
&wgt::SamplerDescriptor {
|
||||
label: owned_label.as_ptr(),
|
||||
address_mode_u: desc.address_mode_u,
|
||||
address_mode_v: desc.address_mode_v,
|
||||
address_mode_w: desc.address_mode_w,
|
||||
mag_filter: desc.mag_filter,
|
||||
min_filter: desc.min_filter,
|
||||
mipmap_filter: desc.mipmap_filter,
|
||||
lod_min_clamp: desc.lod_min_clamp,
|
||||
lod_max_clamp: desc.lod_max_clamp,
|
||||
compare: desc.compare,
|
||||
anisotropy_clamp: desc.anisotropy_clamp.map(|v| v.get()),
|
||||
},
|
||||
PhantomData
|
||||
))
|
||||
.unwrap_pretty()
|
||||
@@ -844,9 +878,19 @@ impl crate::Context for Context {
|
||||
fn device_create_render_bundle_encoder(
|
||||
&self,
|
||||
device: &Self::DeviceId,
|
||||
desc: &wgt::RenderBundleEncoderDescriptor,
|
||||
desc: &RenderBundleEncoderDescriptor,
|
||||
) -> Self::RenderBundleEncoderId {
|
||||
wgc::command::RenderBundleEncoder::new(desc, *device, None).unwrap_pretty()
|
||||
wgc::command::RenderBundleEncoder::new(
|
||||
&wgt::RenderBundleEncoderDescriptor {
|
||||
label: desc.label.map(Borrowed),
|
||||
color_formats: Borrowed(desc.color_formats),
|
||||
depth_stencil_format: desc.depth_stencil_format,
|
||||
sample_count: desc.sample_count,
|
||||
},
|
||||
*device,
|
||||
None,
|
||||
)
|
||||
.unwrap_pretty()
|
||||
}
|
||||
|
||||
fn device_drop(&self, device: &Self::DeviceId) {
|
||||
@@ -985,7 +1029,16 @@ impl crate::Context for Context {
|
||||
desc: Option<&TextureViewDescriptor>,
|
||||
) -> Self::TextureViewId {
|
||||
let owned_label = OwnedLabel::new(desc.and_then(|d| d.label.as_deref()));
|
||||
let descriptor = desc.map(|d| d.map_label(|_| owned_label.as_ptr()));
|
||||
let descriptor = desc.map(|d| wgt::TextureViewDescriptor {
|
||||
label: owned_label.as_ptr(),
|
||||
format: d.format,
|
||||
dimension: d.dimension,
|
||||
aspect: d.aspect,
|
||||
base_mip_level: d.base_mip_level,
|
||||
level_count: d.level_count,
|
||||
base_array_layer: d.base_array_layer,
|
||||
array_layer_count: d.array_layer_count,
|
||||
});
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(
|
||||
*texture => global.texture_create_view(*texture, descriptor.as_ref(), PhantomData)
|
||||
@@ -1208,7 +1261,9 @@ impl crate::Context for Context {
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(encoder.parent() => global.render_bundle_encoder_finish(
|
||||
encoder,
|
||||
&desc.map_label(|_| owned_label.as_ptr()),
|
||||
&wgt::RenderBundleDescriptor {
|
||||
label: owned_label.as_ptr()
|
||||
},
|
||||
PhantomData
|
||||
))
|
||||
.unwrap_pretty()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::{
|
||||
BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BindingType,
|
||||
BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BindingType, BufferDescriptor,
|
||||
CommandEncoderDescriptor, ComputePipelineDescriptor, LoadOp, PipelineLayoutDescriptor,
|
||||
ProgrammableStageDescriptor, RenderPipelineDescriptor, SamplerDescriptor, ShaderModuleSource,
|
||||
SwapChainStatus, TextureDescriptor, TextureViewDescriptor, TextureViewDimension,
|
||||
ProgrammableStageDescriptor, RenderBundleEncoderDescriptor, RenderPipelineDescriptor,
|
||||
SamplerDescriptor, ShaderModuleSource, SwapChainStatus, TextureDescriptor,
|
||||
TextureViewDescriptor, TextureViewDimension,
|
||||
};
|
||||
|
||||
use futures::FutureExt;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fmt,
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
@@ -1052,7 +1052,7 @@ impl crate::Context for Context {
|
||||
fn device_create_buffer(
|
||||
&self,
|
||||
device: &Self::DeviceId,
|
||||
desc: &wgt::BufferDescriptor<Option<Cow<'_, str>>>,
|
||||
desc: &BufferDescriptor<'_>,
|
||||
) -> Self::BufferId {
|
||||
let mut mapped_desc =
|
||||
web_sys::GpuBufferDescriptor::new(desc.size as f64, desc.usage.bits());
|
||||
@@ -1119,7 +1119,7 @@ impl crate::Context for Context {
|
||||
fn device_create_render_bundle_encoder(
|
||||
&self,
|
||||
_device: &Self::DeviceId,
|
||||
_desc: &wgt::RenderBundleEncoderDescriptor,
|
||||
_desc: &RenderBundleEncoderDescriptor,
|
||||
) -> Self::RenderBundleEncoderId {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
286
wgpu/src/lib.rs
286
wgpu/src/lib.rs
@@ -16,6 +16,7 @@ use std::{
|
||||
fmt::{Debug, Display},
|
||||
future::Future,
|
||||
marker::PhantomData,
|
||||
num::{NonZeroU32, NonZeroU8},
|
||||
ops::{Bound, Range, RangeBounds},
|
||||
sync::Arc,
|
||||
thread,
|
||||
@@ -31,18 +32,17 @@ use serde::Serialize;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use wgc::instance::{AdapterInfo, DeviceType};
|
||||
pub use wgt::{
|
||||
AddressMode, Backend, BackendBit, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
|
||||
BlendDescriptor, BlendFactor, BlendOperation, BufferAddress, BufferSize, BufferUsage, Color,
|
||||
AddressMode, Backend, BackendBit, BindGroupLayoutEntry, BindingType, BlendDescriptor,
|
||||
BlendFactor, BlendOperation, BufferAddress, BufferSize, BufferUsage, Color,
|
||||
ColorStateDescriptor, ColorWrite, CommandBufferDescriptor, CompareFunction, CullMode,
|
||||
DepthStencilStateDescriptor, DeviceDescriptor, DynamicOffset, Extent3d, Features, FilterMode,
|
||||
FrontFace, IndexFormat, InputStepMode, Limits, Origin3d, PowerPreference, PresentMode,
|
||||
PrimitiveTopology, PushConstantRange, RasterizationStateDescriptor,
|
||||
RenderBundleEncoderDescriptor, ShaderLocation, ShaderStage, StencilOperation,
|
||||
StencilStateFaceDescriptor, SwapChainDescriptor, SwapChainStatus, TextureAspect,
|
||||
TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat, TextureUsage,
|
||||
TextureViewDimension, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat,
|
||||
VertexStateDescriptor, BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT,
|
||||
COPY_BYTES_PER_ROW_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT,
|
||||
PrimitiveTopology, PushConstantRange, RasterizationStateDescriptor, ShaderLocation,
|
||||
ShaderStage, StencilOperation, StencilStateFaceDescriptor, SwapChainDescriptor,
|
||||
SwapChainStatus, TextureAspect, TextureComponentType, TextureDataLayout, TextureDimension,
|
||||
TextureFormat, TextureUsage, TextureViewDimension, VertexAttributeDescriptor, VertexFormat,
|
||||
BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
|
||||
PUSH_CONSTANT_ALIGNMENT,
|
||||
};
|
||||
|
||||
use backend::Context as C;
|
||||
@@ -926,64 +926,218 @@ pub use wgt::RequestAdapterOptions as RequestAdapterOptionsBase;
|
||||
/// Additional information required when requesting an adapter.
|
||||
pub type RequestAdapterOptions<'a> = RequestAdapterOptionsBase<&'a Surface>;
|
||||
|
||||
pub use wgt::BufferDescriptor as BufferDescriptorBase;
|
||||
/// Describes a [`Buffer`].
|
||||
pub type BufferDescriptor<'a> = BufferDescriptorBase<Option<Cow<'a, str>>>;
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct BufferDescriptor<'a> {
|
||||
/// Debug label of a buffer. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
/// Size of a buffer.
|
||||
pub size: BufferAddress,
|
||||
/// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation
|
||||
/// will panic.
|
||||
pub usage: BufferUsage,
|
||||
/// Allows a buffer to be mapped immediately after they are made. It does not have to be [`BufferUsage::MAP_READ`] or
|
||||
/// [`BufferUsage::MAP_WRITE`], all buffers are allowed to be mapped at creation.
|
||||
pub mapped_at_creation: bool,
|
||||
}
|
||||
|
||||
pub use wgt::CommandEncoderDescriptor as CommandEncoderDescriptorBase;
|
||||
/// Describes a [`CommandEncoder`].
|
||||
pub type CommandEncoderDescriptor<'a> = CommandEncoderDescriptorBase<Option<Cow<'a, str>>>;
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
|
||||
pub struct CommandEncoderDescriptor<'a> {
|
||||
/// Debug label for the command encoder. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub use wgt::RenderBundleDescriptor as RenderBundleDescriptorBase;
|
||||
/// Describes a [`RenderBundle`].
|
||||
pub type RenderBundleDescriptor<'a> = RenderBundleDescriptorBase<Option<Cow<'a, str>>>;
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
|
||||
pub struct RenderBundleDescriptor<'a> {
|
||||
/// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
}
|
||||
|
||||
pub use wgt::TextureDescriptor as TextureDescriptorBase;
|
||||
/// Describes a [`Texture`].
|
||||
pub type TextureDescriptor<'a> = TextureDescriptorBase<Option<Cow<'a, str>>>;
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct TextureDescriptor<'a> {
|
||||
/// Debug label of the texture. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
/// Size of the texture. For a regular 1D/2D texture, the unused sizes will be 1. For 2DArray textures, Z is the
|
||||
/// number of 2D textures in that array.
|
||||
pub size: Extent3d,
|
||||
/// Mip count of texture. For a texture with no extra mips, this must be 1.
|
||||
pub mip_level_count: u32,
|
||||
/// Sample count of texture. If this is not 1, texture must have [`BindingType::SampledTexture::multisampled`] set to true.
|
||||
pub sample_count: u32,
|
||||
/// Dimensions of the texture.
|
||||
pub dimension: TextureDimension,
|
||||
/// Format of the texture.
|
||||
pub format: TextureFormat,
|
||||
/// Allowed usages of the texture. If used in other ways, the operation will panic.
|
||||
pub usage: TextureUsage,
|
||||
}
|
||||
|
||||
pub use wgt::TextureViewDescriptor as TextureViewDescriptorBase;
|
||||
/// Describes a [`TextureView`].
|
||||
pub type TextureViewDescriptor<'a> = TextureViewDescriptorBase<Option<Cow<'a, str>>>;
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct TextureViewDescriptor<'a> {
|
||||
/// Debug label of the texture view. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
/// Format of the texture view. At this time, it must be the same as the underlying format of the texture.
|
||||
pub format: TextureFormat,
|
||||
/// The dimension of the texture view. For 1D textures, this must be `1D`. For 2D textures it must be one of
|
||||
/// `D2`, `D2Array`, `Cube`, and `CubeArray`. For 3D textures it must be `3D`
|
||||
pub dimension: TextureViewDimension,
|
||||
/// Aspect of the texture. Color textures must be [`TextureAspect::All`].
|
||||
pub aspect: TextureAspect,
|
||||
/// Base mip level.
|
||||
pub base_mip_level: u32,
|
||||
/// Mip level count.
|
||||
/// If `Some(count)`, `base_mip_level + count` must be less or equal to underlying texture mip count.
|
||||
/// If `None`, considered to include the rest of the mipmap levels, but at least 1 in total.
|
||||
pub level_count: Option<NonZeroU32>,
|
||||
/// Base array layer.
|
||||
pub base_array_layer: u32,
|
||||
/// Layer count.
|
||||
/// If `Some(count)`, `base_array_layer + count` must be less or equal to the underlying array count.
|
||||
/// If `None`, considered to include the rest of the array layers, but at least 1 in total.
|
||||
pub array_layer_count: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
pub use wgt::PipelineLayoutDescriptor as PipelineLayoutDescriptorBase;
|
||||
/// Describes a [`PipelineLayout`].
|
||||
pub type PipelineLayoutDescriptor<'a> = PipelineLayoutDescriptorBase<'a, &'a BindGroupLayout>;
|
||||
/// Describes a pipeline layout.
|
||||
///
|
||||
/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct PipelineLayoutDescriptor<'a> {
|
||||
/// Bind groups that this pipeline uses. The first entry will provide all the bindings for
|
||||
/// "set = 0", second entry will provide all the bindings for "set = 1" etc.
|
||||
pub bind_group_layouts: &'a [&'a BindGroupLayout],
|
||||
/// Set of push constant ranges this pipeline uses. Each shader stage that uses push constants
|
||||
/// must define the range in push constant memory that corresponds to its single `layout(push_constant)`
|
||||
/// uniform block.
|
||||
///
|
||||
/// If this array is non-empty, the [`Features::PUSH_CONSTANTS`] must be enabled.
|
||||
pub push_constant_ranges: &'a [PushConstantRange],
|
||||
}
|
||||
|
||||
pub use wgt::SamplerDescriptor as SamplerDescriptorBase;
|
||||
/// Describes a [`Sampler`].
|
||||
pub type SamplerDescriptor<'a> = SamplerDescriptorBase<Option<Cow<'a, str>>>;
|
||||
/// Describes a [`Sampler`]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct SamplerDescriptor<'a> {
|
||||
/// Debug label of the sampler. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
/// How to deal with out of bounds accesses in the u (i.e. x) direction
|
||||
pub address_mode_u: AddressMode,
|
||||
/// How to deal with out of bounds accesses in the v (i.e. y) direction
|
||||
pub address_mode_v: AddressMode,
|
||||
/// How to deal with out of bounds accesses in the w (i.e. z) direction
|
||||
pub address_mode_w: AddressMode,
|
||||
/// How to filter the texture when it needs to be magnified (made larger)
|
||||
pub mag_filter: FilterMode,
|
||||
/// How to filter the texture when it needs to be minified (made smaller)
|
||||
pub min_filter: FilterMode,
|
||||
/// How to filter between mip map levels
|
||||
pub mipmap_filter: FilterMode,
|
||||
/// Minimum level of detail (i.e. mip level) to use
|
||||
pub lod_min_clamp: f32,
|
||||
/// Maximum level of detail (i.e. mip level) to use
|
||||
pub lod_max_clamp: f32,
|
||||
/// If this is enabled, this is a comparison sampler using the given comparison function.
|
||||
pub compare: Option<CompareFunction>,
|
||||
/// Valid values: 1, 2, 4, 8, and 16.
|
||||
pub anisotropy_clamp: Option<NonZeroU8>,
|
||||
}
|
||||
|
||||
impl Default for SamplerDescriptor<'_> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
label: Default::default(),
|
||||
address_mode_u: Default::default(),
|
||||
address_mode_v: Default::default(),
|
||||
address_mode_w: Default::default(),
|
||||
mag_filter: Default::default(),
|
||||
min_filter: Default::default(),
|
||||
mipmap_filter: Default::default(),
|
||||
lod_min_clamp: 0.0,
|
||||
lod_max_clamp: std::f32::MAX,
|
||||
compare: Default::default(),
|
||||
anisotropy_clamp: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub use wgt::BindGroupEntry as BindGroupEntryBase;
|
||||
/// Bindable resource and the slot to bind it to.
|
||||
pub type BindGroupEntry<'a> = BindGroupEntryBase<BindingResource<'a>>;
|
||||
|
||||
pub use wgt::BindGroupDescriptor as BindGroupDescriptorBase;
|
||||
/// Describes a group of bindings and the resources to be bound.
|
||||
pub type BindGroupDescriptor<'a> =
|
||||
BindGroupDescriptorBase<'a, &'a BindGroupLayout, BindGroupEntry<'a>>;
|
||||
#[derive(Clone)]
|
||||
pub struct BindGroupDescriptor<'a> {
|
||||
/// Debug label of the bind group. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
/// The [`BindGroupLayout`] that corresponds to this bind group.
|
||||
pub layout: &'a BindGroupLayout,
|
||||
/// The resources to bind to this bind group.
|
||||
pub entries: &'a [BindGroupEntry<'a>],
|
||||
}
|
||||
|
||||
pub use wgt::ProgrammableStageDescriptor as ProgrammableStageDescriptorBase;
|
||||
/// Describes a programmable pipeline stage.
|
||||
pub type ProgrammableStageDescriptor<'a> = wgt::ProgrammableStageDescriptor<'a, &'a ShaderModule>;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ProgrammableStageDescriptor<'a> {
|
||||
/// The compiled shader module for this stage.
|
||||
pub module: &'a ShaderModule,
|
||||
/// The name of the entry point in the compiled shader. There must be a function that returns
|
||||
/// void with this name in the shader.
|
||||
pub entry_point: &'a str,
|
||||
}
|
||||
|
||||
pub use wgt::RenderPassDescriptor as RenderPassDescriptorBase;
|
||||
/// Describes the attachments of a [`RenderPass`];
|
||||
pub type RenderPassDescriptor<'a, 'b> = RenderPassDescriptorBase<
|
||||
'b,
|
||||
RenderPassColorAttachmentDescriptor<'a>,
|
||||
RenderPassDepthStencilAttachmentDescriptor<'a>,
|
||||
>;
|
||||
/// Describes the attachments of a render pass.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct RenderPassDescriptor<'a, 'b> {
|
||||
/// The color attachments of the render pass.
|
||||
pub color_attachments: &'b [RenderPassColorAttachmentDescriptor<'a>],
|
||||
/// The depth and stencil attachment of the render pass, if any.
|
||||
pub depth_stencil_attachment: Option<RenderPassDepthStencilAttachmentDescriptor<'a>>,
|
||||
}
|
||||
|
||||
pub use wgt::RenderPipelineDescriptor as RenderPipelineDescriptorBase;
|
||||
/// Describes a render (graphics) pipeline.
|
||||
pub type RenderPipelineDescriptor<'a> =
|
||||
RenderPipelineDescriptorBase<'a, &'a PipelineLayout, ProgrammableStageDescriptor<'a>>;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RenderPipelineDescriptor<'a> {
|
||||
/// The layout of bind groups for this pipeline.
|
||||
pub layout: Option<&'a PipelineLayout>,
|
||||
/// The compiled vertex stage and its entry point.
|
||||
pub vertex_stage: ProgrammableStageDescriptor<'a>,
|
||||
/// The compiled fragment stage and its entry point, if any.
|
||||
pub fragment_stage: Option<ProgrammableStageDescriptor<'a>>,
|
||||
/// The rasterization process for this pipeline.
|
||||
pub rasterization_state: Option<RasterizationStateDescriptor>,
|
||||
/// The primitive topology used to interpret vertices.
|
||||
pub primitive_topology: PrimitiveTopology,
|
||||
/// The effect of draw calls on the color aspect of the output target.
|
||||
pub color_states: &'a [ColorStateDescriptor],
|
||||
/// The effect of draw calls on the depth and stencil aspects of the output target, if any.
|
||||
pub depth_stencil_state: Option<DepthStencilStateDescriptor>,
|
||||
/// The vertex input state for this pipeline.
|
||||
pub vertex_state: VertexStateDescriptor<'a>,
|
||||
/// The number of samples calculated per pixel (for MSAA). For non-multisampled textures,
|
||||
/// this should be `1`
|
||||
pub sample_count: u32,
|
||||
/// Bitmask that restricts the samples of a pixel modified by this pipeline. All samples
|
||||
/// can be enabled using the value `!0`
|
||||
pub sample_mask: u32,
|
||||
/// When enabled, produces another sample mask per pixel based on the alpha output value, that
|
||||
/// is ANDed with the sample_mask and the primitive coverage to restrict the set of samples
|
||||
/// affected by a primitive.
|
||||
///
|
||||
/// The implicit mask produced for alpha of zero is guaranteed to be zero, and for alpha of one
|
||||
/// is guaranteed to be all 1-s.
|
||||
pub alpha_to_coverage_enabled: bool,
|
||||
}
|
||||
|
||||
pub use ComputePipelineDescriptor as ComputePipelineDescriptorBase;
|
||||
/// Describes a compute pipeline.
|
||||
pub type ComputePipelineDescriptor<'a> =
|
||||
wgt::ComputePipelineDescriptor<&'a PipelineLayout, ProgrammableStageDescriptor<'a>>;
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ComputePipelineDescriptor<'a> {
|
||||
/// The layout of bind groups for this pipeline.
|
||||
pub layout: Option<&'a PipelineLayout>,
|
||||
/// The compiled compute stage and its entry point.
|
||||
pub compute_stage: ProgrammableStageDescriptor<'a>,
|
||||
}
|
||||
|
||||
pub use wgt::BufferCopyView as BufferCopyViewBase;
|
||||
/// View of a buffer which can be used to copy to/from a texture.
|
||||
@@ -993,6 +1147,52 @@ pub use wgt::TextureCopyView as TextureCopyViewBase;
|
||||
/// View of a texture which can be used to copy to/from a buffer/texture.
|
||||
pub type TextureCopyView<'a> = TextureCopyViewBase<&'a Texture>;
|
||||
|
||||
/// Describes a [`BindGroupLayout`].
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BindGroupLayoutDescriptor<'a> {
|
||||
/// Debug label of the bind group layout. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
|
||||
/// Array of entries in this BindGroupLayout
|
||||
pub entries: &'a [BindGroupLayoutEntry],
|
||||
}
|
||||
|
||||
/// Describes how the vertex buffer is interpreted.
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct VertexBufferDescriptor<'a> {
|
||||
/// The stride, in bytes, between elements of this buffer.
|
||||
pub stride: BufferAddress,
|
||||
/// How often this vertex buffer is "stepped" forward.
|
||||
pub step_mode: InputStepMode,
|
||||
/// The list of attributes which comprise a single vertex.
|
||||
pub attributes: &'a [VertexAttributeDescriptor],
|
||||
}
|
||||
|
||||
/// Describes vertex input state for a render pipeline.
|
||||
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub struct VertexStateDescriptor<'a> {
|
||||
/// The format of any index buffers used with this pipeline.
|
||||
pub index_format: IndexFormat,
|
||||
/// The format of any vertex buffers used with this pipeline.
|
||||
pub vertex_buffers: &'a [VertexBufferDescriptor<'a>],
|
||||
}
|
||||
|
||||
/// Describes a [`RenderBundleEncoder`].
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
|
||||
pub struct RenderBundleEncoderDescriptor<'a> {
|
||||
/// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification.
|
||||
pub label: Option<&'a str>,
|
||||
/// The formats of the color attachments that this render bundle is capable to rendering to. This
|
||||
/// must match the formats of the color attachments in the renderpass this render bundle is executed in.
|
||||
pub color_formats: &'a [TextureFormat],
|
||||
/// The formats of the depth attachment that this render bundle is capable to rendering to. This
|
||||
/// must match the formats of the depth attachments in the renderpass this render bundle is executed in.
|
||||
pub depth_stencil_format: Option<TextureFormat>,
|
||||
/// Sample count this render bundle is capable of rendering to. This must match the pipelines and
|
||||
/// the renderpasses it is used in.
|
||||
pub sample_count: u32,
|
||||
}
|
||||
|
||||
/// Swap chain image that can be rendered to.
|
||||
#[derive(Debug)]
|
||||
pub struct SwapChainTexture {
|
||||
|
||||
@@ -3,7 +3,7 @@ use crate::{
|
||||
CommandEncoder, CommandEncoderDescriptor, Device, MapMode,
|
||||
};
|
||||
use futures::{future::join_all, FutureExt};
|
||||
use std::{borrow::Cow::Borrowed, future::Future, mem, sync::mpsc};
|
||||
use std::{future::Future, mem, sync::mpsc};
|
||||
|
||||
struct Chunk {
|
||||
buffer: Buffer,
|
||||
@@ -77,7 +77,7 @@ impl StagingBelt {
|
||||
wgc::span!(_guard, INFO, "Creating chunk of size {}", size);
|
||||
Chunk {
|
||||
buffer: device.create_buffer(&BufferDescriptor {
|
||||
label: Some(Borrowed("staging")),
|
||||
label: Some("staging"),
|
||||
size,
|
||||
usage: BufferUsage::MAP_WRITE | BufferUsage::COPY_SRC,
|
||||
mapped_at_creation: true,
|
||||
|
||||
@@ -67,8 +67,8 @@ impl DeviceExt for crate::Device {
|
||||
let padding = crate::COPY_BUFFER_ALIGNMENT - unpadded_size % crate::COPY_BUFFER_ALIGNMENT;
|
||||
let padded_size = padding + unpadded_size;
|
||||
|
||||
let wgt_descriptor = wgt::BufferDescriptor {
|
||||
label: descriptor.label.as_ref().map(|x| Cow::Borrowed(&**x)),
|
||||
let wgt_descriptor = crate::BufferDescriptor {
|
||||
label: descriptor.label,
|
||||
size: padded_size,
|
||||
usage: descriptor.usage,
|
||||
mapped_at_creation: true,
|
||||
|
||||
Reference in New Issue
Block a user