Browse Source

added local group size

master
Thomas Johnson 4 months ago
parent
commit
d89862fc2d
  1. 2
      src/julia_set.glsl
  2. 52
      src/main.rs

2
src/julia_set.glsl

@ -1,5 +1,7 @@
#version 450
layout (local_size_x = 32, local_size_y = 32) in;
layout (push_constant) uniform PushConstants {
// Origin and spacing of the grid of pixels
vec2 origin;

52
src/main.rs

@ -28,8 +28,8 @@ use vulkano::command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage};
use vulkano::pipeline::{ComputePipeline, ComputePipelineAbstract};
use vulkano_win::VkSurfaceBuild;
use winit::{
dpi::{PhysicalSize, Size},
event::{Event, WindowEvent, KeyboardInput, VirtualKeyCode, ElementState as KeyState},
dpi::{PhysicalSize, PhysicalPosition, Size},
event::{Event, WindowEvent, KeyboardInput, VirtualKeyCode, ElementState},
event_loop::{ControlFlow, EventLoop},
window::{Window, WindowBuilder},
};
@ -115,13 +115,14 @@ impl VulkanWindow {
let mut dir_keys = [false; 4];
let mut pot_adj_keys = [false; 4];
let mut rate_keys = [false; 2];
let mut cursor_pos = PhysicalPosition::new(0.0, 0.0);
let mut params: JuliaSetParams;
{
let (origin, spacing) = Self::compute_viewport(DEFAULT_DIMS);
params = JuliaSetParams {
origin,
spacing,
c: [0.2, 0.2],
c: [-0.75, 0.0],
potential_period: 10.0,
potential_offset: 0.0,
max_iters: 50,
@ -164,25 +165,25 @@ impl VulkanWindow {
};
match (key, key_state) {
(Some(VirtualKeyCode::Q), _) => { *elcf = ControlFlow::Exit; }
(Some(VirtualKeyCode::Minus | VirtualKeyCode::Underline), KeyState::Pressed) => {
(Some(VirtualKeyCode::Minus | VirtualKeyCode::Underline), ElementState::Pressed) => {
params.max_iters = params.max_iters.saturating_sub(max_iter_step);
println!("max iters: {}", params.max_iters);
sfc.window().request_redraw();
}
(Some(VirtualKeyCode::Equals | VirtualKeyCode::Plus), KeyState::Pressed) => {
(Some(VirtualKeyCode::Equals | VirtualKeyCode::Plus), ElementState::Pressed) => {
params.max_iters = params.max_iters.saturating_add(max_iter_step);
println!("max iters: {}", params.max_iters);
sfc.window().request_redraw();
}
(Some(k@VirtualKeyCode::Key1)
| Some(k@VirtualKeyCode::Key2)
| Some(k@VirtualKeyCode::Key3)
| Some(k@VirtualKeyCode::Key4)
| Some(k@VirtualKeyCode::Key5)
| Some(k@VirtualKeyCode::Key6)
| Some(k@VirtualKeyCode::Key7)
| Some(k@VirtualKeyCode::Key8)
| Some(k@VirtualKeyCode::Key9), KeyState::Pressed) => {
(Some(VirtualKeyCode::Key1)
| Some(VirtualKeyCode::Key2)
| Some(VirtualKeyCode::Key3)
| Some(VirtualKeyCode::Key4)
| Some(VirtualKeyCode::Key5)
| Some(VirtualKeyCode::Key6)
| Some(VirtualKeyCode::Key7)
| Some(VirtualKeyCode::Key8)
| Some(VirtualKeyCode::Key9), ElementState::Pressed) => {
let num = match key.unwrap() {
VirtualKeyCode::Key1 => 1,
VirtualKeyCode::Key2 => 2,
@ -210,8 +211,8 @@ impl VulkanWindow {
};
if let Some(idx) = key_dir_idx {
match key_state {
KeyState::Pressed => { dir_keys[idx] = true; },
KeyState::Released => { dir_keys[idx] = false; },
ElementState::Pressed => { dir_keys[idx] = true; },
ElementState::Released => { dir_keys[idx] = false; },
}
}
let pot_adj_key_idx = match key {
@ -223,8 +224,8 @@ impl VulkanWindow {
};
if let Some(idx) = pot_adj_key_idx {
match key_state {
KeyState::Pressed => { pot_adj_keys[idx] = true; },
KeyState::Released => { pot_adj_keys[idx] = false; },
ElementState::Pressed => { pot_adj_keys[idx] = true; },
ElementState::Released => { pot_adj_keys[idx] = false; },
}
}
}
@ -232,8 +233,17 @@ impl VulkanWindow {
event: WindowEvent::ModifiersChanged(mstate),
..
} => {
println!("new modifier set: {:?}", mstate);
rate_keys = [mstate.shift(), mstate.ctrl()];
println!("new modifier set: {:?}", mstate);
rate_keys = [mstate.shift(), mstate.ctrl()];
}
Event::WindowEvent {
event: WindowEvent::CursorMoved {
position: pos,
..
},
..
} => {
cursor_pos = pos;
}
Event::WindowEvent {
event: WindowEvent::CloseRequested,
@ -592,7 +602,7 @@ impl<W: 'static + Sync + Send> VulkanData<W> {
).expect("could not make command buffer builder!");
command_buffer_builder
.dispatch(
[dims[0], dims[1], 1],
[(dims[0] + 31) / 32, (dims[1] + 31) / 32, 1],
self.compute_pipeline.clone(),
self.desc_sets[image_idx].clone(),
params.clone(),

Loading…
Cancel
Save