diff --git a/config/input.toml b/config/input.toml index 3d2112f..34b9065 100644 --- a/config/input.toml +++ b/config/input.toml @@ -29,8 +29,7 @@ scan_code = 32 [[button]] name = "test" -controller_button = "West" -ctrl = true +scan_code = 20 [[axis]] name = "move_forward" diff --git a/config/log.toml b/config/log.toml index 21f4239..4719d10 100644 --- a/config/log.toml +++ b/config/log.toml @@ -1,3 +1,3 @@ input_events = false -vulkan_validation_layers = true +vulkan_validation_layers = false mesh_load_info = true \ No newline at end of file diff --git a/shaders/triangle.vert b/shaders/triangle.vert index 91d68b8..0550ccd 100644 --- a/shaders/triangle.vert +++ b/shaders/triangle.vert @@ -6,11 +6,17 @@ layout(location = 1) in vec2 uv; layout(location = 0) out vec2 tex_coords; +//layout(binding = 0) uniform UniformBufferObject { +// mat4 view; +// mat4 projection; +// float time; +//} ubo; + layout(push_constant) uniform PushConstants { - float time; mat4 model; mat4 view; mat4 projection; + float time; } push; void main() { diff --git a/src/main.rs b/src/main.rs index 9d3634a..c4d9954 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,8 +45,8 @@ impl TestGame { self.input.frame_start(); let new_time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32; - let frame_time = new_time - renderer.game_data.push_constants.time; - renderer.game_data.push_constants.time = new_time; +// let frame_time = new_time - renderer.game_data.uniform_buffers.iter().map(|ubo| ubo.time).max_by(|a,b| if a > b {Ordering::Greater} else {Ordering::Less} ).unwrap(); +// renderer.game_data.uniform_buffers.iter_mut().for_each(|ubo| ubo.time = new_time); // User interaction if self.input.button_just_released("quit") { @@ -58,7 +58,7 @@ impl TestGame { } if self.input.button_down("print_framerate") { - println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time); +// println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time); } if self.input.button_just_pressed("test") { @@ -87,6 +87,8 @@ impl TestGame { renderer.game_data.push_constants.view = view.into(); renderer.game_data.push_constants.projection = proj.into(); +// renderer.game_data.uniform_buffers.iter_mut().for_each(|ubo| ubo.view = view.into()); +// renderer.game_data.uniform_buffers.iter_mut().for_each(|ubo| ubo.projection = proj.into()); renderer.game_data.line_push_constants.view = view.into(); renderer.game_data.line_push_constants.projection = proj.into(); @@ -100,7 +102,7 @@ fn main() { let mut game = TestGame { input: InputState::new("config/input.toml", log_config), cam_rotation: Quaternion::one(), - cam_position: Vector3::new(0.0, 0.0, -10.0), + cam_position: Vector3::new(0.0, 3.0, -10.0), test_meshes: vec![], cubes: vec![], log_config diff --git a/src/vulkan.rs b/src/vulkan.rs index 1700b2a..aa8646b 100644 --- a/src/vulkan.rs +++ b/src/vulkan.rs @@ -1,4 +1,4 @@ -use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; +use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, CpuBufferPool}; use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState}; use vulkano::device::{Device, DeviceExtensions, Queue}; use vulkano::framebuffer::{Framebuffer, FramebufferAbstract, Subpass, RenderPassAbstract}; @@ -14,7 +14,7 @@ use vulkano::sync; use vulkano::format::{Format, ClearValue}; use vulkano::instance::debug::{DebugCallback, MessageTypes}; use vulkano::memory::pool::{PotentialDedicatedAllocation, StdMemoryPoolAlloc}; -use vulkano::descriptor::descriptor_set::PersistentDescriptorSet; +use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, FixedSizeDescriptorSetsPool, FixedSizeDescriptorSet, PersistentDescriptorSetBuf, PersistentDescriptorSetSampler}; use vulkano::descriptor::DescriptorSet; use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode}; @@ -22,7 +22,7 @@ use vulkano_win::VkSurfaceBuild; use winit::{EventsLoop, Window, WindowBuilder, Event, WindowEvent}; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use std::time::SystemTime; use std::path::{PathBuf}; use std::ffi::{CStr}; @@ -78,6 +78,8 @@ pub struct GameObject { pub(crate) type GameObjectHandle = usize; pub(crate) type MeshHandle = usize; +//type FixedGraphicsDescriptorSet = std::sync::Arc, (((), PersistentDescriptorSetSampler), PersistentDescriptorSetBuf>>)>>; + pub struct GameData { pub start_time: SystemTime, pub line_vertices: Vec, @@ -109,6 +111,7 @@ pub struct VulkanRenderer { pub recreate_swapchain: bool, pub debug_callback: Option, pub previous_frame_end: Option>, +// pub uniform_buffers: CpuBufferPool, } pub enum RenderLoopResult { @@ -122,7 +125,6 @@ impl VulkanRenderer { let mut data = GameData { push_constants: PushConstants { time: 0.0, - _dummy0: [0; 12], model: Matrix4::identity().into(), view: Matrix4::identity().into(), projection: Matrix4::identity().into(), @@ -287,7 +289,6 @@ impl VulkanRenderer { let line_pipeline: Arc = create_pipeline::(device.clone(), render_pass.clone(), "shaders/line.vert", "shaders/line.frag", true).unwrap(); - let (default_tex, default_tex_future) = { let image = image::load_from_memory_with_format(include_bytes!("../models/missing-texture.jpg"), ImageFormat::JPEG).unwrap().to_rgba(); @@ -318,6 +319,8 @@ impl VulkanRenderer { // can draw we also need to create the actual framebuffers. let framebuffers = window_size_dependent_setup(device.clone(), &images, render_pass.clone(), &mut dynamic_state); +// let uniform_buffers = CpuBufferPool::::new(device.clone(), BufferUsage::all()); + // In the loop below we are going to submit commands to the GPU. Submitting a command produces // an object that implements the `GpuFuture` trait, which holds the resources for as long as // they are in use by the GPU. @@ -327,8 +330,7 @@ impl VulkanRenderer { let previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); VulkanRenderer { game_data: data, device, framebuffers, sampler, - default_descriptor_set: default_descriptor_set, - dynamic_state, pipeline, line_pipeline, + dynamic_state, pipeline, line_pipeline, default_descriptor_set, surface, swapchain, render_pass, queue, line_vertex_buffer, events_loop, recreate_swapchain: false, debug_callback, previous_frame_end } }