diff --git a/wgpu-hal/examples/bunnymark/main.rs b/wgpu-hal/examples/halmark/main.rs similarity index 96% rename from wgpu-hal/examples/bunnymark/main.rs rename to wgpu-hal/examples/halmark/main.rs index 65fc10223..def4fc5a9 100644 --- a/wgpu-hal/examples/bunnymark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -26,8 +26,8 @@ struct Locals { _pad: u32, } +#[allow(dead_code)] struct Example { - #[allow(dead_code)] instance: A::Instance, surface: A::Surface, surface_format: wgt::TextureFormat, @@ -39,6 +39,10 @@ struct Example { pipeline: A::RenderPipeline, bunnies: Vec, local_buffer: A::Buffer, + global_buffer: A::Buffer, + sampler: A::Sampler, + texture: A::Texture, + view: A::TextureView, extent: [u32; 2], start: Instant, } @@ -62,7 +66,7 @@ impl Example { swap_chain_size: 2, present_mode: wgt::PresentMode::Fifo, composite_alpha_mode: hal::CompositeAlphaMode::Opaque, - format: wgt::TextureFormat::Rgba8UnormSrgb, + format: wgt::TextureFormat::Bgra8UnormSrgb, extent: wgt::Extent3d { width: window_size.0, height: window_size.1, @@ -77,7 +81,7 @@ impl Example { let naga_shader = { let shader_file = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("examples") - .join("bunnymark") + .join("halmark") .join("shader.wgsl"); let source = std::fs::read_to_string(shader_file).unwrap(); let module = naga::front::wgsl::Parser::new().parse(&source).unwrap(); @@ -91,7 +95,9 @@ impl Example { }; let shader_desc = hal::ShaderModuleDescriptor { label: None }; let shader = unsafe { - device.create_shader_module(&shader_desc, naga_shader).unwrap() + device + .create_shader_module(&shader_desc, naga_shader) + .unwrap() }; let global_bgl_desc = hal::BindGroupLayoutDescriptor { @@ -185,7 +191,7 @@ impl Example { }; let pipeline = unsafe { device.create_render_pipeline(&pipeline_desc).unwrap() }; - let texture_data = vec![0xFFu8; 3]; + let texture_data = vec![0xFFu8; 4]; let staging_buffer_desc = hal::BufferDescriptor { label: Some("stage"), @@ -398,6 +404,10 @@ impl Example { local_group, bunnies: Vec::new(), local_buffer, + global_buffer, + sampler, + texture, + view, extent: [window_size.0, window_size.1], start: Instant::now(), }) @@ -422,8 +432,8 @@ impl Example { spawn_count, self.bunnies.len() + spawn_count ); - for _ in 0..spawn_count { - let random = (elapsed.as_nanos() & 0xFF) as f32 / 255.0; + for i in 0..spawn_count { + let random = ((elapsed.as_nanos() * (i + 1) as u128) & 0xFF) as f32 / 255.0; let speed = random * MAX_VELOCITY - (MAX_VELOCITY * 0.5); self.bunnies.push(Locals { position: [0.0, 0.5 * (self.extent[1] as f32)], @@ -518,6 +528,7 @@ impl Example { } unsafe { + cmd_buf.end_render_pass(); cmd_buf.finish(); self.queue.submit(iter::once(cmd_buf), None).unwrap(); self.queue.present(&mut self.surface, surface_tex).unwrap(); @@ -545,6 +556,9 @@ fn main() { let _ = &window; // force ownership by the closure *control_flow = winit::event_loop::ControlFlow::Poll; match event { + winit::event::Event::RedrawEventsCleared => { + window.request_redraw(); + } winit::event::Event::WindowEvent { event, .. } => match event { winit::event::WindowEvent::KeyboardInput { input: diff --git a/wgpu-hal/examples/bunnymark/shader.wgsl b/wgpu-hal/examples/halmark/shader.wgsl similarity index 100% rename from wgpu-hal/examples/bunnymark/shader.wgsl rename to wgpu-hal/examples/halmark/shader.wgsl diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index 3dd7c98d3..72b8c0a4e 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -132,7 +132,7 @@ impl crate::CommandBuffer for super::CommandBuffer { bytes_per_image, extent, &dst.raw, - dst_slice + slice_count, + dst_slice + slice, copy.texture_base.mip_level as u64, dst_origin, mtl::MTLBlitOption::empty(), diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index 1f2e18ac5..e030760e6 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -177,7 +177,7 @@ impl crate::Surface for super::Surface { log::info!("build swapchain {:?}", config); let caps = &device.shared.private_caps; - let mtl_format = caps.map_format(config.format); + self.raw_swapchain_format = caps.map_format(config.format); let render_layer = self.render_layer.lock(); let framebuffer_only = config.usage == crate::TextureUse::COLOR_TARGET; @@ -205,7 +205,7 @@ impl crate::Surface for super::Surface { } } render_layer.set_device(&*device_raw); - render_layer.set_pixel_format(mtl_format); + render_layer.set_pixel_format(self.raw_swapchain_format); render_layer.set_framebuffer_only(framebuffer_only); render_layer.set_presents_with_transaction(self.present_with_transaction); diff --git a/wgpu/examples/bunnymark/main.rs b/wgpu/examples/bunnymark/main.rs index b98611962..cec3e5fe6 100644 --- a/wgpu/examples/bunnymark/main.rs +++ b/wgpu/examples/bunnymark/main.rs @@ -47,7 +47,7 @@ impl framework::Example for Example { let shader = device.create_shader_module(&wgpu::ShaderModuleDescriptor { label: None, source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!( - "../../../wgpu-hal/examples/bunnymark/shader.wgsl" + "../../../wgpu-hal/examples/halmark/shader.wgsl" ))), });