Skip to content

Commit

Permalink
hal: rename bunnymark to halmark
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Jun 10, 2021
1 parent 782c72d commit 3172377
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ struct Locals {
_pad: u32,
}

#[allow(dead_code)]
struct Example<A: hal::Api> {
#[allow(dead_code)]
instance: A::Instance,
surface: A::Surface,
surface_format: wgt::TextureFormat,
Expand All @@ -39,6 +39,10 @@ struct Example<A: hal::Api> {
pipeline: A::RenderPipeline,
bunnies: Vec<Locals>,
local_buffer: A::Buffer,
global_buffer: A::Buffer,
sampler: A::Sampler,
texture: A::Texture,
view: A::TextureView,
extent: [u32; 2],
start: Instant,
}
Expand All @@ -62,7 +66,7 @@ impl<A: hal::Api> Example<A> {
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,
Expand All @@ -77,7 +81,7 @@ impl<A: hal::Api> Example<A> {
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();
Expand All @@ -91,7 +95,9 @@ impl<A: hal::Api> Example<A> {
};
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 {
Expand Down Expand Up @@ -185,7 +191,7 @@ impl<A: hal::Api> Example<A> {
};
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"),
Expand Down Expand Up @@ -398,6 +404,10 @@ impl<A: hal::Api> Example<A> {
local_group,
bunnies: Vec::new(),
local_buffer,
global_buffer,
sampler,
texture,
view,
extent: [window_size.0, window_size.1],
start: Instant::now(),
})
Expand All @@ -422,8 +432,8 @@ impl<A: hal::Api> Example<A> {
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)],
Expand Down Expand Up @@ -518,6 +528,7 @@ impl<A: hal::Api> Example<A> {
}

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();
Expand Down Expand Up @@ -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:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion wgpu-hal/src/metal/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl crate::CommandBuffer<super::Api> 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(),
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl crate::Surface<super::Api> 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;
Expand Down Expand Up @@ -205,7 +205,7 @@ impl crate::Surface<super::Api> 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);

Expand Down
2 changes: 1 addition & 1 deletion wgpu/examples/bunnymark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))),
});

Expand Down

0 comments on commit 3172377

Please sign in to comment.