From d842432d175e87d8c29a5e1914ed58b99a4bdef2 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 13 Mar 2020 15:14:02 -0400 Subject: [PATCH] Update for the latest spec changes --- Cargo.toml | 11 ++- examples/boids/main.rs | 22 ++--- examples/capture/main.rs | 4 +- examples/cube/main.rs | 24 ++--- examples/framework.rs | 2 +- examples/hello-compute/main.rs | 4 +- examples/hello-triangle/main.rs | 2 +- examples/mipmap/main.rs | 30 +++--- examples/msaa-line/main.rs | 2 +- examples/shadow/main.rs | 24 ++--- examples/skybox/main.rs | 20 ++-- src/lib.rs | 166 ++++++++++++++------------------ 12 files changed, 143 insertions(+), 168 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a527604fe..1a85d9d97c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,16 +27,23 @@ vulkan = ["wgn/vulkan-portability"] package = "wgpu-native" version = "0.4" git = "https://github.com/gfx-rs/wgpu" -rev = "429ca1d4460becd20d771f67024878948b60454b" +rev = "39f17e50754aba6beeeabdd868ddfd700f9710c5" #path = "../wgpu/wgpu-native" [dependencies.wgc] package = "wgpu-core" version = "0.1" git = "https://github.com/gfx-rs/wgpu" -rev = "429ca1d4460becd20d771f67024878948b60454b" +rev = "39f17e50754aba6beeeabdd868ddfd700f9710c5" #path = "../wgpu/wgpu-core" +[dependencies.wgt] +package = "wgpu-types" +version = "0.1" +git = "https://github.com/gfx-rs/wgpu" +rev = "39f17e50754aba6beeeabdd868ddfd700f9710c5" +#path = "../wgpu/wgpu-types" + [dependencies] arrayvec = "0.5" smallvec = "1" diff --git a/examples/boids/main.rs b/examples/boids/main.rs index eacd7a9765..41ceb228d8 100644 --- a/examples/boids/main.rs +++ b/examples/boids/main.rs @@ -67,17 +67,17 @@ impl framework::Example for Example { let compute_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[ - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::COMPUTE, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::COMPUTE, ty: wgpu::BindingType::StorageBuffer { dynamic: false, readonly: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 2, visibility: wgpu::ShaderStage::COMPUTE, ty: wgpu::BindingType::StorageBuffer { dynamic: false, readonly: false }, @@ -149,11 +149,11 @@ impl framework::Example for Example { }, }); - + // buffer for the three 2d triangle vertices of each instance let vertex_buffer_data = [-0.01f32, -0.02, 0.01, -0.02, 0.00, 0.02]; - let vertices_buffer = device.create_buffer_with_data(vertex_buffer_data.as_bytes(), + let vertices_buffer = device.create_buffer_with_data(vertex_buffer_data.as_bytes(), wgpu::BufferUsage::VERTEX | wgpu::BufferUsage::COPY_DST); @@ -168,7 +168,7 @@ impl framework::Example for Example { 0.05, // rule2Scale 0.005 // rule3Scale ].to_vec(); - let sim_param_buffer = device.create_buffer_with_data(sim_param_data.as_bytes(), + let sim_param_buffer = device.create_buffer_with_data(sim_param_data.as_bytes(), wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST); @@ -288,7 +288,7 @@ impl framework::Example for Example { // get command encoder let mut command_encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 }); - + { // compute pass let mut cpass = command_encoder.begin_compute_pass(); @@ -301,10 +301,10 @@ impl framework::Example for Example { // render pass let mut rpass = command_encoder.begin_render_pass(&render_pass_descriptor); rpass.set_pipeline(&self.render_pipeline); - rpass.set_vertex_buffers(0, &[ - (&self.particle_buffers[(self.frame_num + 1) % 2], 0), // render dst particles - (&self.vertices_buffer, 0), // the three instance-local vertices - ]); + // render dst particles + rpass.set_vertex_buffer(0, &self.particle_buffers[(self.frame_num + 1) % 2], 0, 0); + // the three instance-local vertices + rpass.set_vertex_buffer(1, &self.vertices_buffer, 0, 0); rpass.draw(0..3, 0..NUM_PARTICLES); } diff --git a/examples/capture/main.rs b/examples/capture/main.rs index a4cecb74e6..50b7bf4d5b 100644 --- a/examples/capture/main.rs +++ b/examples/capture/main.rs @@ -74,8 +74,8 @@ async fn run() { wgpu::BufferCopyView { buffer: &output_buffer, offset: 0, - row_pitch: size_of::() as u32 * size, - image_height: size, + bytes_per_row: size_of::() as u32 * size, + rows_per_image: size, }, texture_extent, ); diff --git a/examples/cube/main.rs b/examples/cube/main.rs index 8eef61ebc7..4080243f81 100644 --- a/examples/cube/main.rs +++ b/examples/cube/main.rs @@ -131,12 +131,12 @@ impl framework::Example for Example { // Create pipeline layout let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[ - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::SampledTexture { @@ -144,10 +144,10 @@ impl framework::Example for Example { dimension: wgpu::TextureViewDimension::D2, }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 2, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler, + ty: wgpu::BindingType::Sampler { comparison: false }, }, ], }); @@ -179,18 +179,14 @@ impl framework::Example for Example { wgpu::BufferCopyView { buffer: &temp_buf, offset: 0, - row_pitch: 4 * size, - image_height: size, + bytes_per_row: 4 * size, + rows_per_image: size, }, wgpu::TextureCopyView { texture: &texture, mip_level: 0, array_layer: 0, - origin: wgpu::Origin3d { - x: 0, - y: 0, - z: 0, - }, + origin: wgpu::Origin3d::ZERO, }, texture_extent, ); @@ -205,7 +201,7 @@ impl framework::Example for Example { mipmap_filter: wgpu::FilterMode::Nearest, lod_min_clamp: -100.0, lod_max_clamp: 100.0, - compare_function: wgpu::CompareFunction::Always, + compare: None, }); 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(); @@ -351,8 +347,8 @@ 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(0, &[(&self.vertex_buf, 0)]); + rpass.set_index_buffer(&self.index_buf, 0,0 ); + rpass.set_vertex_buffer(0, &self.vertex_buf, 0, 0); rpass.draw_indexed(0 .. self.index_count as u32, 0, 0 .. 1); } diff --git a/examples/framework.rs b/examples/framework.rs index 1030262403..c5d2045e2c 100644 --- a/examples/framework.rs +++ b/examples/framework.rs @@ -119,7 +119,7 @@ pub fn run(title: &str) { format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Vsync, + present_mode: wgpu::PresentMode::Mailbox, }; let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); diff --git a/examples/hello-compute/main.rs b/examples/hello-compute/main.rs index 266eabad92..655c3119ad 100644 --- a/examples/hello-compute/main.rs +++ b/examples/hello-compute/main.rs @@ -52,7 +52,7 @@ async fn execute_gpu(numbers: Vec) -> Vec { }); let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - bindings: &[wgpu::BindGroupLayoutBinding { + bindings: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::COMPUTE, ty: wgpu::BindingType::StorageBuffer { @@ -130,4 +130,4 @@ mod tests { async fn assert_execute_gpu(input: Vec, expected: Vec){ assert_eq!(execute_gpu(input).await, expected); } -} \ No newline at end of file +} diff --git a/examples/hello-triangle/main.rs b/examples/hello-triangle/main.rs index 6907902a11..a2050decf7 100644 --- a/examples/hello-triangle/main.rs +++ b/examples/hello-triangle/main.rs @@ -105,7 +105,7 @@ fn main() { format: wgpu::TextureFormat::Bgra8UnormSrgb, width: size.width, height: size.height, - present_mode: wgpu::PresentMode::Vsync, + present_mode: wgpu::PresentMode::Mailbox, }; let mut swap_chain = device.create_swap_chain(&surface, &sc_desc); diff --git a/examples/mipmap/main.rs b/examples/mipmap/main.rs index 35022867d0..a690658856 100644 --- a/examples/mipmap/main.rs +++ b/examples/mipmap/main.rs @@ -81,7 +81,7 @@ impl Example { ) { let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[ - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::SampledTexture { @@ -89,10 +89,10 @@ impl Example { dimension: wgpu::TextureViewDimension::D2, }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler, + ty: wgpu::BindingType::Sampler { comparison: false }, }, ], }); @@ -148,7 +148,7 @@ impl Example { mipmap_filter: wgpu::FilterMode::Nearest, lod_min_clamp: -100.0, lod_max_clamp: 100.0, - compare_function: wgpu::CompareFunction::Always, + compare: None, }); let views = (0 .. mip_count) @@ -216,12 +216,12 @@ impl framework::Example for Example { // Create pipeline layout let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[ - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::SampledTexture { @@ -229,10 +229,10 @@ impl framework::Example for Example { dimension: wgpu::TextureViewDimension::D2, }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 2, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler, + ty: wgpu::BindingType::Sampler { comparison: false }, }, ], }); @@ -267,18 +267,14 @@ impl framework::Example for Example { wgpu::BufferCopyView { buffer: &temp_buf, offset: 0, - row_pitch: 4 * size, - image_height: size, + bytes_per_row: 4 * size, + rows_per_image: size, }, wgpu::TextureCopyView { texture: &texture, mip_level: 0, array_layer: 0, - origin: wgpu::Origin3d { - x: 0, - y: 0, - z: 0, - }, + origin: wgpu::Origin3d::ZERO, }, texture_extent, ); @@ -293,7 +289,7 @@ impl framework::Example for Example { mipmap_filter: wgpu::FilterMode::Linear, lod_min_clamp: -100.0, lod_max_clamp: 100.0, - compare_function: wgpu::CompareFunction::Always, + compare: None, }); 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(); @@ -426,7 +422,7 @@ impl framework::Example for Example { }); rpass.set_pipeline(&self.draw_pipeline); rpass.set_bind_group(0, &self.bind_group, &[]); - rpass.set_vertex_buffers(0, &[(&self.vertex_buf, 0)]); + rpass.set_vertex_buffer(0, &self.vertex_buf, 0, 0); rpass.draw(0 .. 4, 0 .. 1); } diff --git a/examples/msaa-line/main.rs b/examples/msaa-line/main.rs index faccfb9790..3859d6dfeb 100644 --- a/examples/msaa-line/main.rs +++ b/examples/msaa-line/main.rs @@ -255,7 +255,7 @@ impl framework::Example for Example { depth_stencil_attachment: None, }); rpass.set_pipeline(&self.pipeline); - rpass.set_vertex_buffers(0, &[(&self.vertex_buffer, 0)]); + rpass.set_vertex_buffer(0, &self.vertex_buffer, 0, 0); rpass.draw(0 .. self.vertex_count, 0 .. 1); } diff --git a/examples/shadow/main.rs b/examples/shadow/main.rs index 4978365b95..05f0272d80 100644 --- a/examples/shadow/main.rs +++ b/examples/shadow/main.rs @@ -223,7 +223,7 @@ impl framework::Example for Example { let local_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - bindings: &[wgpu::BindGroupLayoutBinding { + bindings: &[wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, @@ -331,7 +331,7 @@ impl framework::Example for Example { mipmap_filter: wgpu::FilterMode::Nearest, lod_min_clamp: -100.0, lod_max_clamp: 100.0, - compare_function: wgpu::CompareFunction::LessEqual, + compare: Some(&wgpu::CompareFunction::LessEqual), }); let shadow_texture = device.create_texture(&wgpu::TextureDescriptor { @@ -403,7 +403,7 @@ impl framework::Example for Example { // Create pipeline layout let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - bindings: &[wgpu::BindGroupLayoutBinding { + bindings: &[wgpu::BindGroupLayoutEntry { binding: 0, // global visibility: wgpu::ShaderStage::VERTEX, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, @@ -486,17 +486,17 @@ impl framework::Example for Example { let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[ - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 0, // global visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 1, // lights visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 2, visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::SampledTexture { @@ -504,10 +504,10 @@ impl framework::Example for Example { dimension: wgpu::TextureViewDimension::D2Array, }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 3, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler, + ty: wgpu::BindingType::Sampler { comparison: true }, }, ], }); @@ -779,8 +779,8 @@ impl framework::Example for Example { for entity in &self.entities { pass.set_bind_group(1, &entity.bind_group, &[]); - pass.set_index_buffer(&entity.index_buf, 0); - pass.set_vertex_buffers(0, &[(&entity.vertex_buf, 0)]); + pass.set_index_buffer(&entity.index_buf, 0, 0); + pass.set_vertex_buffer(0, &entity.vertex_buf, 0, 0); pass.draw_indexed(0 .. entity.index_count as u32, 0, 0 .. 1); } } @@ -815,8 +815,8 @@ impl framework::Example for Example { for entity in &self.entities { pass.set_bind_group(1, &entity.bind_group, &[]); - pass.set_index_buffer(&entity.index_buf, 0); - pass.set_vertex_buffers(0, &[(&entity.vertex_buf, 0)]); + pass.set_index_buffer(&entity.index_buf, 0, 0); + pass.set_vertex_buffer(0, &entity.vertex_buf, 0, 0); pass.draw_indexed(0 .. entity.index_count as u32, 0, 0 .. 1); } } diff --git a/examples/skybox/main.rs b/examples/skybox/main.rs index e83ff2cc89..9a2fae457b 100644 --- a/examples/skybox/main.rs +++ b/examples/skybox/main.rs @@ -56,12 +56,12 @@ impl framework::Example for Skybox { let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { bindings: &[ - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::UniformBuffer { dynamic: false }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStage::FRAGMENT, ty: wgpu::BindingType::SampledTexture { @@ -69,10 +69,10 @@ impl framework::Example for Skybox { dimension: wgpu::TextureViewDimension::Cube, }, }, - wgpu::BindGroupLayoutBinding { + wgpu::BindGroupLayoutEntry { binding: 2, visibility: wgpu::ShaderStage::FRAGMENT, - ty: wgpu::BindingType::Sampler, + ty: wgpu::BindingType::Sampler { comparison: false }, }, ], }); @@ -144,7 +144,7 @@ impl framework::Example for Skybox { mipmap_filter: wgpu::FilterMode::Nearest, lod_min_clamp: -100.0, lod_max_clamp: 100.0, - compare_function: wgpu::CompareFunction::Always, + compare: None, }); let paths: [&'static [u8]; 6] = [ @@ -201,18 +201,14 @@ impl framework::Example for Skybox { wgpu::BufferCopyView { buffer: &image_buf, offset: 0, - row_pitch: 4 * image_width, - image_height, + bytes_per_row: 4 * image_width, + rows_per_image: 0, }, wgpu::TextureCopyView { texture: &texture, mip_level: 0, array_layer: i as u32, - origin: wgpu::Origin3d { - x: 0, - y: 0, - z: 0, - }, + origin: wgpu::Origin3d::ZERO, }, texture_extent, ); diff --git a/src/lib.rs b/src/lib.rs index 4ab1603330..4a36783a47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,77 +10,37 @@ mod macros; use arrayvec::ArrayVec; use smallvec::SmallVec; -use std::ffi::CString; -use std::ops::Range; -use std::ptr; -use std::slice; -use std::thread; +use std::{ + ffi::CString, + ops::Range, + ptr, + slice, + thread, +}; +pub use wgt::*; pub use wgc::{ - Backend, - binding_model::ShaderStage, + Extent3d, + Origin3d, command::{ CommandBufferDescriptor, - CommandEncoderDescriptor, - LoadOp, - StoreOp, }, device::{ BIND_BUFFER_ALIGNMENT, }, instance::{ AdapterInfo, - BackendBit, - DeviceDescriptor, DeviceType, - Extensions, - Limits, - PowerPreference, - RequestAdapterOptions, }, - pipeline::{ - BlendDescriptor, - BlendFactor, - BlendOperation, - ColorStateDescriptor, - ColorWrite, - CullMode, - DepthStencilStateDescriptor, - FrontFace, - IndexFormat, - InputStepMode, - PrimitiveTopology, - RasterizationStateDescriptor, - ShaderLocation, - ShaderModuleDescriptor, - StencilOperation, - StencilStateFaceDescriptor, - VertexAttributeDescriptor, - VertexFormat, - }, - read_spirv, resource::{ AddressMode, - BufferDescriptor, - BufferMapAsyncStatus, - BufferUsage, - CompareFunction, FilterMode, SamplerDescriptor, TextureAspect, TextureDescriptor, TextureDimension, - TextureFormat, - TextureUsage, TextureViewDescriptor, - TextureViewDimension, }, - swap_chain::{PresentMode, SwapChainDescriptor}, - BufferAddress, - Color, - DynamicOffset, - Extent3d, - Origin3d, }; //TODO: avoid heap allocating vectors during resource creation. @@ -297,19 +257,23 @@ pub enum BindingType { dynamic: bool, readonly: bool, }, - Sampler, + Sampler { + comparison: bool, + }, SampledTexture { - multisampled: bool, dimension: TextureViewDimension, + multisampled: bool, }, StorageTexture { dimension: TextureViewDimension, + format: TextureFormat, + readonly: bool, }, } /// A description of a single binding inside a bind group. #[derive(Clone, Debug, Hash)] -pub struct BindGroupLayoutBinding { +pub struct BindGroupLayoutEntry { pub binding: u32, pub visibility: ShaderStage, pub ty: BindingType, @@ -317,7 +281,7 @@ pub struct BindGroupLayoutBinding { #[derive(Clone, Debug)] pub struct BindGroupLayoutDescriptor<'a> { - pub bindings: &'a [BindGroupLayoutBinding], + pub bindings: &'a [BindGroupLayoutEntry], } /// A description of a group of bindings and the resources to be bound. @@ -416,9 +380,9 @@ pub struct ComputePipelineDescriptor<'a> { } pub type RenderPassColorAttachmentDescriptor<'a> = - wgc::command::RenderPassColorAttachmentDescriptorBase<&'a TextureView, Option<&'a TextureView>>; + wgt::RenderPassColorAttachmentDescriptorBase<&'a TextureView, Option<&'a TextureView>>; pub type RenderPassDepthStencilAttachmentDescriptor<'a> = - wgc::command::RenderPassDepthStencilAttachmentDescriptorBase<&'a TextureView>; + wgt::RenderPassDepthStencilAttachmentDescriptorBase<&'a TextureView>; /// A description of all the attachments of a render pass. #[derive(Debug)] @@ -448,19 +412,19 @@ pub struct BufferCopyView<'a> { pub offset: BufferAddress, /// The size in bytes of a single row of the texture. This must be a multiple of 256 bytes. - pub row_pitch: u32, + pub bytes_per_row: u32, /// The height in texels of the imaginary texture view overlaid on the buffer. - pub image_height: u32, + pub rows_per_image: u32, } -impl<'a> BufferCopyView<'a> { +impl BufferCopyView<'_> { fn into_native(self) -> wgc::command::BufferCopyView { wgc::command::BufferCopyView { buffer: self.buffer.id, offset: self.offset, - row_pitch: self.row_pitch, - image_height: self.image_height, + bytes_per_row: self.bytes_per_row, + rows_per_image: self.rows_per_image, } } } @@ -569,7 +533,7 @@ impl Adapter { temp: Temp::default(), }; let queue = Queue { - id: wgn::wgpu_device_get_queue(device.id), + id: wgn::wgpu_device_get_default_queue(device.id), }; (device, queue) } @@ -613,7 +577,7 @@ impl Device { let bindings = desc .bindings .iter() - .map(|binding| bm::BindGroupBinding { + .map(|binding| bm::BindGroupEntry { binding: binding.binding, resource: match binding.resource { BindingResource::Buffer { @@ -653,7 +617,7 @@ impl Device { let temp_layouts = desc .bindings .iter() - .map(|bind| bm::BindGroupLayoutBinding { + .map(|bind| bm::BindGroupLayoutEntry { binding: bind.binding, visibility: bind.visibility, ty: match bind.ty { @@ -664,24 +628,34 @@ impl Device { BindingType::StorageBuffer { readonly: true, .. } => { bm::BindingType::ReadonlyStorageBuffer } - BindingType::Sampler => bm::BindingType::Sampler, + BindingType::Sampler { comparison: false } => bm::BindingType::Sampler, + BindingType::Sampler { .. } => bm::BindingType::ComparisonSampler, BindingType::SampledTexture { .. } => bm::BindingType::SampledTexture, - BindingType::StorageTexture { .. } => bm::BindingType::StorageTexture, + BindingType::StorageTexture { readonly: true, .. } => { + bm::BindingType::ReadonlyStorageTexture + } + BindingType::StorageTexture { .. } => { + bm::BindingType::WriteonlyStorageTexture + } }, - dynamic: match bind.ty { - BindingType::UniformBuffer { dynamic } - | BindingType::StorageBuffer { dynamic, .. } => dynamic, + has_dynamic_offset: match bind.ty { + BindingType::UniformBuffer { dynamic } | + BindingType::StorageBuffer { dynamic, .. } => dynamic, _ => false, }, multisampled: match bind.ty { BindingType::SampledTexture { multisampled, .. } => multisampled, _ => false, }, - texture_dimension: match bind.ty { - BindingType::SampledTexture { dimension, .. } - | BindingType::StorageTexture { dimension } => dimension, + view_dimension: match bind.ty { + BindingType::SampledTexture { dimension, .. } | + BindingType::StorageTexture { dimension, .. } => dimension, _ => TextureViewDimension::D2, }, + storage_texture_format: match bind.ty { + BindingType::StorageTexture { format, .. } => format, + _ => TextureFormat::Rgb10a2Unorm, // doesn't matter + }, }) .collect::>(); BindGroupLayout { @@ -739,8 +713,8 @@ impl Device { let temp_vertex_buffers = desc .vertex_buffers .iter() - .map(|vbuf| pipe::VertexBufferDescriptor { - stride: vbuf.stride, + .map(|vbuf| pipe::VertexBufferLayoutDescriptor { + array_stride: vbuf.stride, step_mode: vbuf.step_mode, attributes: vbuf.attributes.as_ptr(), attributes_length: vbuf.attributes.len(), @@ -767,7 +741,7 @@ impl Device { .depth_stencil_state .as_ref() .map_or(ptr::null(), |p| p as *const _), - vertex_input: pipe::VertexInputDescriptor { + vertex_state: pipe::VertexStateDescriptor { index_format: desc.index_format, vertex_buffers: temp_vertex_buffers.as_ptr(), vertex_buffers_length: temp_vertex_buffers.len(), @@ -1249,38 +1223,44 @@ impl<'a> RenderPass<'a> { /// /// Subsequent calls to [`draw_indexed`](RenderPass::draw_indexed) on this [`RenderPass`] will /// use `buffer` as the source index buffer. - pub fn set_index_buffer(&mut self, buffer: &'a Buffer, offset: BufferAddress) { + /// + /// If `size == 0`, the remaining part of the buffer is considered. + pub fn set_index_buffer( + &mut self, + buffer: &'a Buffer, + offset: BufferAddress, + size: BufferAddress, + ) { unsafe { wgn::wgpu_render_pass_set_index_buffer( self.id.as_mut().unwrap(), buffer.id, offset, + size, ); } } - /// Sets the active vertex buffers, starting from `start_slot`. + /// Assign a vertex buffer to a slot. /// - /// Each element of `buffer_pairs` describes a vertex buffer and an offset in bytes into that - /// buffer. The offset must be aligned to a multiple of 4 bytes. - pub fn set_vertex_buffers( + /// Subsequent calls to [`draw`](RenderPass::draw) and [`draw_indexed`](RenderPass::draw_indexed) + /// on this [`RenderPass`] will use `buffer` as one of the source vertex buffers. + /// + /// If `size == 0`, the remaining part of the buffer is considered. + pub fn set_vertex_buffer( &mut self, - start_slot: u32, - buffer_pairs: &[(&'a Buffer, BufferAddress)], + slot: u32, + buffer: &'a Buffer, + offset: BufferAddress, + size: BufferAddress, ) { - let mut buffers = Vec::new(); - let mut offsets = Vec::new(); - for &(buffer, offset) in buffer_pairs { - buffers.push(buffer.id); - offsets.push(offset); - } unsafe { - wgn::wgpu_render_pass_set_vertex_buffers( + wgn::wgpu_render_pass_set_vertex_buffer( self.id.as_mut().unwrap(), - start_slot, - buffers.as_ptr(), - offsets.as_ptr(), - buffer_pairs.len(), + slot, + buffer.id, + offset, + size, ) }; }