Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Update to latest wgpu-native commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Aug 17, 2019
1 parent 79b5342 commit 66c4d67
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ gl = ["wgn/gfx-backend-gl"]

[dependencies]
#TODO: only depend on the published version
wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "cf1bee30d6406d6393220736efdf91b5e429e0ca"}
wgn = { package = "wgpu-native", version = "0.2.6", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "38743c6ba37c7fe1b72e5c20a08befd800db3ae5"}
arrayvec = "0.4"
zerocopy = "0.2"

Expand Down
16 changes: 8 additions & 8 deletions examples/capture/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ fn main() {

let instance = wgpu::Instance::new();

let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
let adapter = instance.get_adapter(Some(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::LowPower,
});
}));

let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
let mut device = adapter.request_device(Some(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});
}));

// Rendered image is 256×256 with 32-bit RGBA color
let size = 256u32;

// The output buffer lets us retrieve the data as an array
let output_buffer = device.create_buffer(&wgpu::BufferDescriptor {
size: (size * size) as u64 * size_of::<u32>() as u64,
usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::TRANSFER_DST,
usage: wgpu::BufferUsage::MAP_READ | wgpu::BufferUsage::COPY_DST,
});

let texture_extent = wgpu::Extent3d {
Expand All @@ -43,7 +43,7 @@ fn main() {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT | wgpu::TextureUsage::TRANSFER_SRC,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT | wgpu::TextureUsage::COPY_SRC,
});

// Set the background to be red
Expand All @@ -52,7 +52,7 @@ fn main() {
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &texture.create_default_view(),
attachment: &texture.create_view(None),
resolve_target: None,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
Expand All @@ -78,7 +78,7 @@ fn main() {
texture_extent,
);

encoder.finish()
encoder.finish(None)
};

device.get_queue().submit(&[command_buffer]);
Expand Down
37 changes: 24 additions & 13 deletions examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,25 @@ impl framework::Example for Example {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::UniformBuffer,
dynamic: false,
multisampled: false,
texture_dimension: wgn::TextureViewDimension::D2,
},
wgpu::BindGroupLayoutBinding {
binding: 1,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture,
dynamic: false,
multisampled: false,
texture_dimension: wgn::TextureViewDimension::D2,
},
wgpu::BindGroupLayoutBinding {
binding: 2,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler,
dynamic: false,
multisampled: false,
texture_dimension: wgn::TextureViewDimension::D2,
},
],
});
Expand All @@ -162,11 +171,11 @@ impl framework::Example for Example {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::TRANSFER_DST,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::COPY_DST,
});
let texture_view = texture.create_default_view();
let texture_view = texture.create_view(None);
let temp_buf = device
.create_buffer_mapped(texels.len(), wgpu::BufferUsage::TRANSFER_SRC)
.create_buffer_mapped(texels.len(), wgpu::BufferUsage::COPY_SRC)
.fill_from_slice(&texels);
init_encoder.copy_buffer_to_texture(
wgpu::BufferCopyView {
Expand Down Expand Up @@ -205,7 +214,7 @@ impl framework::Example for Example {
let uniform_buf = device
.create_buffer_mapped(
16,
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
)
.fill_from_slice(mx_ref);

Expand Down Expand Up @@ -243,21 +252,21 @@ impl framework::Example for Example {

let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
vertex_stage: wgpu::PipelineStageDescriptor {
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
},
fragment_stage: Some(wgpu::PipelineStageDescriptor {
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
}),
rasterization_state: wgpu::RasterizationStateDescriptor {
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::Back,
depth_bias: 0,
depth_bias_slope_scale: 0.0,
depth_bias_clamp: 0.0,
},
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format: sc_desc.format,
Expand All @@ -284,10 +293,12 @@ impl framework::Example for Example {
],
}],
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
});

// Done
let init_command_buf = init_encoder.finish();
let init_command_buf = init_encoder.finish(None);
device.get_queue().submit(&[init_command_buf]);
Example {
vertex_buf,
Expand All @@ -308,13 +319,13 @@ impl framework::Example for Example {
let mx_ref: &[f32; 16] = mx_total.as_ref();

let temp_buf = device
.create_buffer_mapped(16, wgpu::BufferUsage::TRANSFER_SRC)
.create_buffer_mapped(16, wgpu::BufferUsage::COPY_SRC)
.fill_from_slice(mx_ref);

let mut encoder =
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
encoder.copy_buffer_to_buffer(&temp_buf, 0, &self.uniform_buf, 0, 64);
device.get_queue().submit(&[encoder.finish()]);
device.get_queue().submit(&[encoder.finish(None)]);
}

fn render(&mut self, frame: &wgpu::SwapChainOutput, device: &mut wgpu::Device) {
Expand All @@ -339,11 +350,11 @@ impl framework::Example for Example {
rpass.set_pipeline(&self.pipeline);
rpass.set_bind_group(0, &self.bind_group, &[]);
rpass.set_index_buffer(&self.index_buf, 0);
rpass.set_vertex_buffers(&[(&self.vertex_buf, 0)]);
rpass.set_vertex_buffers(0, &[(&self.vertex_buf, 0)]);
rpass.draw_indexed(0 .. self.index_count as u32, 0, 0 .. 1);
}

device.get_queue().submit(&[encoder.finish()]);
device.get_queue().submit(&[encoder.finish(None)]);
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,16 @@ pub fn run<E: Example>(title: &str) {
(window, instance, hidpi_factor, size, surface)
};

let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
let adapter = instance.get_adapter(Some(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::LowPower,
});
}));

let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
let mut device = adapter.request_device(Some(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});
}));

let mut sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
Expand Down
24 changes: 14 additions & 10 deletions examples/hello-compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ fn main() {
let size = (numbers.len() * std::mem::size_of::<u32>()) as wgpu::BufferAddress;

let instance = wgpu::Instance::new();
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
let adapter = instance.get_adapter(Some(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::Default,
});
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
}));

let mut device = adapter.request_device(Some(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});
}));

let cs = include_bytes!("shader.comp.spv");
let cs_module = device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&cs[..])).unwrap());
Expand All @@ -32,23 +33,26 @@ fn main() {
.create_buffer_mapped(
numbers.len(),
wgpu::BufferUsage::MAP_READ
| wgpu::BufferUsage::TRANSFER_DST
| wgpu::BufferUsage::TRANSFER_SRC,
| wgpu::BufferUsage::COPY_DST
| wgpu::BufferUsage::COPY_SRC,
)
.fill_from_slice(&numbers);

let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
size,
usage: wgpu::BufferUsage::STORAGE
| wgpu::BufferUsage::TRANSFER_DST
| wgpu::BufferUsage::TRANSFER_SRC,
| wgpu::BufferUsage::COPY_DST
| wgpu::BufferUsage::COPY_SRC,
});

let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
bindings: &[wgpu::BindGroupLayoutBinding {
binding: 0,
visibility: wgpu::ShaderStage::COMPUTE,
ty: wgpu::BindingType::StorageBuffer,
dynamic: false,
multisampled: false,
texture_dimension: wgn::TextureViewDimension::D2,
}],
});

Expand All @@ -69,7 +73,7 @@ fn main() {

let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
layout: &pipeline_layout,
compute_stage: wgpu::PipelineStageDescriptor {
compute_stage: wgpu::ProgrammableStageDescriptor {
module: &cs_module,
entry_point: "main",
},
Expand All @@ -85,7 +89,7 @@ fn main() {
}
encoder.copy_buffer_to_buffer(&storage_buffer, 0, &staging_buffer, 0, size);

device.get_queue().submit(&[encoder.finish()]);
device.get_queue().submit(&[encoder.finish(None)]);

staging_buffer.map_read_async(0, size, |result: wgpu::BufferMapAsyncResult<&[u32]>| {
if let Ok(mapping) = result {
Expand Down
20 changes: 11 additions & 9 deletions examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ fn main() {
(window, instance, size, surface)
};

let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
let adapter = instance.get_adapter(Some(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::LowPower,
});
}));

let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
let mut device = adapter.request_device(Some(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});
}));

let vs = include_bytes!("shader.vert.spv");
let vs_module = device.create_shader_module(&wgpu::read_spirv(std::io::Cursor::new(&vs[..])).unwrap());
Expand All @@ -78,21 +78,21 @@ fn main() {

let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: &pipeline_layout,
vertex_stage: wgpu::PipelineStageDescriptor {
vertex_stage: wgpu::ProgrammableStageDescriptor {
module: &vs_module,
entry_point: "main",
},
fragment_stage: Some(wgpu::PipelineStageDescriptor {
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
module: &fs_module,
entry_point: "main",
}),
rasterization_state: wgpu::RasterizationStateDescriptor {
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::None,
depth_bias: 0,
depth_bias_slope_scale: 0.0,
depth_bias_clamp: 0.0,
},
}),
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::Bgra8UnormSrgb,
Expand All @@ -104,6 +104,8 @@ fn main() {
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[],
sample_count: 1,
sample_mask: !0,
alpha_to_coverage_enabled: false,
});

let mut swap_chain = device.create_swap_chain(
Expand Down Expand Up @@ -157,6 +159,6 @@ fn main() {
rpass.draw(0 .. 3, 0 .. 1);
}

device.get_queue().submit(&[encoder.finish()]);
device.get_queue().submit(&[encoder.finish(None)]);
}
}
Loading

0 comments on commit 66c4d67

Please sign in to comment.