Skip to content

Commit

Permalink
[rs] Merge gfx-rs#4
Browse files Browse the repository at this point in the history
4: Update wgpu-rs to reflect latest wgpu API r=kvark a=kyren

Not sure if everything here is correct, especially `RenderPassColorAttachmentDescriptor` and the `resolve_target` field.

Co-authored-by: kyren <kerriganw@gmail.com>
  • Loading branch information
bors[bot] and kyren committed May 16, 2019
2 parents fdef638 + 2910030 commit 5d6aa77
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 138 deletions.
2 changes: 1 addition & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vulkan = ["wgn/gfx-backend-vulkan"]

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

[dev-dependencies]
Expand Down
51 changes: 26 additions & 25 deletions wgpu/examples/cube/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,29 @@ impl framework::Example for Example {
let vertex_size = mem::size_of::<Vertex>();
let (vertex_data, index_data) = create_vertices();
let vertex_buf = device
.create_buffer_mapped(vertex_data.len(), wgpu::BufferUsageFlags::VERTEX)
.create_buffer_mapped(vertex_data.len(), wgpu::BufferUsage::VERTEX)
.fill_from_slice(&vertex_data);

let index_buf = device
.create_buffer_mapped(index_data.len(), wgpu::BufferUsageFlags::INDEX)
.create_buffer_mapped(index_data.len(), wgpu::BufferUsage::INDEX)
.fill_from_slice(&index_data);

// Create pipeline layout
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
bindings: &[
wgpu::BindGroupLayoutBinding {
binding: 0,
visibility: wgpu::ShaderStageFlags::VERTEX,
visibility: wgpu::ShaderStage::VERTEX,
ty: wgpu::BindingType::UniformBuffer,
},
wgpu::BindGroupLayoutBinding {
binding: 1,
visibility: wgpu::ShaderStageFlags::FRAGMENT,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture,
},
wgpu::BindGroupLayoutBinding {
binding: 2,
visibility: wgpu::ShaderStageFlags::FRAGMENT,
visibility: wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler,
},
],
Expand All @@ -156,14 +156,16 @@ impl framework::Example for Example {
};
let texture = device.create_texture(&wgpu::TextureDescriptor {
size: texture_extent,
array_size: 1,
array_layer_count: 1,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsageFlags::SAMPLED | wgpu::TextureUsageFlags::TRANSFER_DST,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::TRANSFER_DST,
});
let texture_view = texture.create_default_view();
let temp_buf = device
.create_buffer_mapped(texels.len(), wgpu::BufferUsageFlags::TRANSFER_SRC)
.create_buffer_mapped(texels.len(), wgpu::BufferUsage::TRANSFER_SRC)
.fill_from_slice(&texels);
init_encoder.copy_buffer_to_texture(
wgpu::BufferCopyView {
Expand All @@ -174,8 +176,8 @@ impl framework::Example for Example {
},
wgpu::TextureCopyView {
texture: &texture,
level: 0,
slice: 0,
mip_level: 0,
array_layer: 0,
origin: wgpu::Origin3d {
x: 0.0,
y: 0.0,
Expand All @@ -187,24 +189,22 @@ impl framework::Example for Example {

// Create other resources
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
r_address_mode: wgpu::AddressMode::ClampToEdge,
s_address_mode: wgpu::AddressMode::ClampToEdge,
t_address_mode: wgpu::AddressMode::ClampToEdge,
address_mode_u: wgpu::AddressMode::ClampToEdge,
address_mode_v: wgpu::AddressMode::ClampToEdge,
address_mode_w: wgpu::AddressMode::ClampToEdge,
mag_filter: wgpu::FilterMode::Nearest,
min_filter: wgpu::FilterMode::Linear,
mipmap_filter: wgpu::FilterMode::Nearest,
lod_min_clamp: -100.0,
lod_max_clamp: 100.0,
max_anisotropy: 0,
compare_function: wgpu::CompareFunction::Always,
border_color: wgpu::BorderColor::TransparentBlack,
});
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
let mx_ref: &[f32; 16] = mx_total.as_ref();
let uniform_buf = device
.create_buffer_mapped(
16,
wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
)
.fill_from_slice(mx_ref);

Expand Down Expand Up @@ -242,10 +242,10 @@ impl framework::Example for Example {
module: &vs_module,
entry_point: "main",
},
fragment_stage: wgpu::PipelineStageDescriptor {
fragment_stage: Some(wgpu::PipelineStageDescriptor {
module: &fs_module,
entry_point: "main",
},
}),
rasterization_state: wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Cw,
cull_mode: wgpu::CullMode::Back,
Expand All @@ -256,25 +256,25 @@ impl framework::Example for Example {
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format: sc_desc.format,
color: wgpu::BlendDescriptor::REPLACE,
alpha: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWriteFlags::ALL,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
index_format: wgpu::IndexFormat::Uint16,
vertex_buffers: &[wgpu::VertexBufferDescriptor {
stride: vertex_size as u32,
stride: vertex_size as wgpu::BufferAddress,
step_mode: wgpu::InputStepMode::Vertex,
attributes: &[
wgpu::VertexAttributeDescriptor {
attribute_index: 0,
format: wgpu::VertexFormat::Float4,
offset: 0,
shader_location: 0,
},
wgpu::VertexAttributeDescriptor {
attribute_index: 1,
format: wgpu::VertexFormat::Float2,
offset: 4 * 4,
shader_location: 1,
},
],
}],
Expand Down Expand Up @@ -303,7 +303,7 @@ impl framework::Example for Example {
let mx_ref: &[f32; 16] = mx_total.as_ref();

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

let mut encoder =
Expand All @@ -319,6 +319,7 @@ impl framework::Example for Example {
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color {
Expand Down
5 changes: 3 additions & 2 deletions wgpu/examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ pub fn run<E: Example>(title: &str) {
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
power_preference: wgpu::PowerPreference::LowPower,
});
let mut device = adapter.create_device(&wgpu::DeviceDescriptor {
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});

info!("Initializing the window...");
Expand All @@ -71,7 +72,7 @@ pub fn run<E: Example>(title: &str) {

let surface = instance.create_surface(&window);
let mut sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
format: wgpu::TextureFormat::Bgra8Unorm,
width: size.width.round() as u32,
height: size.height.round() as u32,
Expand Down
19 changes: 10 additions & 9 deletions wgpu/examples/hello-compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ fn main() {
.map(|s| u32::from_str(&s).expect("You must pass a list of positive integers!"))
.collect();

let size = (numbers.len() * std::mem::size_of::<u32>()) as u32;
let size = (numbers.len() * std::mem::size_of::<u32>()) as wgpu::BufferAddress;

let instance = wgpu::Instance::new();
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
power_preference: wgpu::PowerPreference::Default,
});
let mut device = adapter.create_device(&wgpu::DeviceDescriptor {
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});

let cs_bytes = include_bytes!("shader.comp.spv");
Expand All @@ -30,23 +31,23 @@ fn main() {
let staging_buffer = device
.create_buffer_mapped(
numbers.len(),
wgpu::BufferUsageFlags::MAP_READ
| wgpu::BufferUsageFlags::TRANSFER_DST
| wgpu::BufferUsageFlags::TRANSFER_SRC,
wgpu::BufferUsage::MAP_READ
| wgpu::BufferUsage::TRANSFER_DST
| wgpu::BufferUsage::TRANSFER_SRC,
)
.fill_from_slice(&numbers);

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

let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
bindings: &[wgpu::BindGroupLayoutBinding {
binding: 0,
visibility: wgpu::ShaderStageFlags::COMPUTE,
visibility: wgpu::ShaderStage::COMPUTE,
ty: wgpu::BindingType::StorageBuffer,
}],
});
Expand Down
16 changes: 9 additions & 7 deletions wgpu/examples/hello-triangle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ fn main() {
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
power_preference: wgpu::PowerPreference::LowPower,
});
let mut device = adapter.create_device(&wgpu::DeviceDescriptor {
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
extensions: wgpu::Extensions {
anisotropic_filtering: false,
},
limits: wgpu::Limits::default(),
});

let vs_bytes = include_bytes!("shader.vert.spv");
Expand All @@ -32,10 +33,10 @@ fn main() {
module: &vs_module,
entry_point: "main",
},
fragment_stage: wgpu::PipelineStageDescriptor {
fragment_stage: Some(wgpu::PipelineStageDescriptor {
module: &fs_module,
entry_point: "main",
},
}),
rasterization_state: wgpu::RasterizationStateDescriptor {
front_face: wgpu::FrontFace::Ccw,
cull_mode: wgpu::CullMode::None,
Expand All @@ -46,9 +47,9 @@ fn main() {
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
color_states: &[wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::Bgra8Unorm,
color: wgpu::BlendDescriptor::REPLACE,
alpha: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWriteFlags::ALL,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
}],
depth_stencil_state: None,
index_format: wgpu::IndexFormat::Uint16,
Expand Down Expand Up @@ -77,7 +78,7 @@ fn main() {
let mut swap_chain = device.create_swap_chain(
&surface,
&wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
format: wgpu::TextureFormat::Bgra8Unorm,
width: size.width.round() as u32,
height: size.height.round() as u32,
Expand Down Expand Up @@ -112,6 +113,7 @@ fn main() {
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
load_op: wgpu::LoadOp::Clear,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color::GREEN,
Expand Down
Loading

0 comments on commit 5d6aa77

Please sign in to comment.