This commit is contained in:
2019-08-13 11:36:40 +02:00
parent 35bb18ace9
commit 1a9e37df79
5 changed files with 24 additions and 15 deletions

View File

@@ -29,8 +29,7 @@ scan_code = 32
[[button]] [[button]]
name = "test" name = "test"
controller_button = "West" scan_code = 20
ctrl = true
[[axis]] [[axis]]
name = "move_forward" name = "move_forward"

View File

@@ -1,3 +1,3 @@
input_events = false input_events = false
vulkan_validation_layers = true vulkan_validation_layers = false
mesh_load_info = true mesh_load_info = true

View File

@@ -6,11 +6,17 @@ layout(location = 1) in vec2 uv;
layout(location = 0) out vec2 tex_coords; layout(location = 0) out vec2 tex_coords;
//layout(binding = 0) uniform UniformBufferObject {
// mat4 view;
// mat4 projection;
// float time;
//} ubo;
layout(push_constant) uniform PushConstants { layout(push_constant) uniform PushConstants {
float time;
mat4 model; mat4 model;
mat4 view; mat4 view;
mat4 projection; mat4 projection;
float time;
} push; } push;
void main() { void main() {

View File

@@ -45,8 +45,8 @@ impl TestGame {
self.input.frame_start(); self.input.frame_start();
let new_time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32; 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; // 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.push_constants.time = new_time; // renderer.game_data.uniform_buffers.iter_mut().for_each(|ubo| ubo.time = new_time);
// User interaction // User interaction
if self.input.button_just_released("quit") { if self.input.button_just_released("quit") {
@@ -58,7 +58,7 @@ impl TestGame {
} }
if self.input.button_down("print_framerate") { 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") { 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.view = view.into();
renderer.game_data.push_constants.projection = proj.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.view = view.into();
renderer.game_data.line_push_constants.projection = proj.into(); renderer.game_data.line_push_constants.projection = proj.into();
@@ -100,7 +102,7 @@ fn main() {
let mut game = TestGame { let mut game = TestGame {
input: InputState::new("config/input.toml", log_config), input: InputState::new("config/input.toml", log_config),
cam_rotation: Quaternion::one(), 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![], test_meshes: vec![],
cubes: vec![], cubes: vec![],
log_config log_config

View File

@@ -1,4 +1,4 @@
use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer}; use vulkano::buffer::{BufferUsage, CpuAccessibleBuffer, CpuBufferPool};
use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState}; use vulkano::command_buffer::{AutoCommandBufferBuilder, DynamicState};
use vulkano::device::{Device, DeviceExtensions, Queue}; use vulkano::device::{Device, DeviceExtensions, Queue};
use vulkano::framebuffer::{Framebuffer, FramebufferAbstract, Subpass, RenderPassAbstract}; use vulkano::framebuffer::{Framebuffer, FramebufferAbstract, Subpass, RenderPassAbstract};
@@ -14,7 +14,7 @@ use vulkano::sync;
use vulkano::format::{Format, ClearValue}; use vulkano::format::{Format, ClearValue};
use vulkano::instance::debug::{DebugCallback, MessageTypes}; use vulkano::instance::debug::{DebugCallback, MessageTypes};
use vulkano::memory::pool::{PotentialDedicatedAllocation, StdMemoryPoolAlloc}; 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::descriptor::DescriptorSet;
use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode}; use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode};
@@ -22,7 +22,7 @@ use vulkano_win::VkSurfaceBuild;
use winit::{EventsLoop, Window, WindowBuilder, Event, WindowEvent}; use winit::{EventsLoop, Window, WindowBuilder, Event, WindowEvent};
use std::sync::Arc; use std::sync::{Arc, Mutex};
use std::time::SystemTime; use std::time::SystemTime;
use std::path::{PathBuf}; use std::path::{PathBuf};
use std::ffi::{CStr}; use std::ffi::{CStr};
@@ -78,6 +78,8 @@ pub struct GameObject {
pub(crate) type GameObjectHandle = usize; pub(crate) type GameObjectHandle = usize;
pub(crate) type MeshHandle = usize; pub(crate) type MeshHandle = usize;
//type FixedGraphicsDescriptorSet = std::sync::Arc<FixedSizeDescriptorSet<std::sync::Arc<dyn GraphicsPipelineAbstract + std::marker::Send + std::marker::Sync>, (((), PersistentDescriptorSetSampler), PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::cpu_access::CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>)>>;
pub struct GameData { pub struct GameData {
pub start_time: SystemTime, pub start_time: SystemTime,
pub line_vertices: Vec<LinePoint>, pub line_vertices: Vec<LinePoint>,
@@ -109,6 +111,7 @@ pub struct VulkanRenderer {
pub recreate_swapchain: bool, pub recreate_swapchain: bool,
pub debug_callback: Option<DebugCallback>, pub debug_callback: Option<DebugCallback>,
pub previous_frame_end: Option<Box<GpuFuture>>, pub previous_frame_end: Option<Box<GpuFuture>>,
// pub uniform_buffers: CpuBufferPool<vs::ty::UniformBufferObject>,
} }
pub enum RenderLoopResult { pub enum RenderLoopResult {
@@ -122,7 +125,6 @@ impl VulkanRenderer {
let mut data = GameData { let mut data = GameData {
push_constants: PushConstants { push_constants: PushConstants {
time: 0.0, time: 0.0,
_dummy0: [0; 12],
model: Matrix4::identity().into(), model: Matrix4::identity().into(),
view: Matrix4::identity().into(), view: Matrix4::identity().into(),
projection: Matrix4::identity().into(), projection: Matrix4::identity().into(),
@@ -287,7 +289,6 @@ impl VulkanRenderer {
let line_pipeline: Arc<GraphicsPipelineAbstract + Send + Sync> = let line_pipeline: Arc<GraphicsPipelineAbstract + Send + Sync> =
create_pipeline::<LinePoint>(device.clone(), render_pass.clone(), "shaders/line.vert", "shaders/line.frag", true).unwrap(); create_pipeline::<LinePoint>(device.clone(), render_pass.clone(), "shaders/line.vert", "shaders/line.frag", true).unwrap();
let (default_tex, default_tex_future) = { let (default_tex, default_tex_future) = {
let image = image::load_from_memory_with_format(include_bytes!("../models/missing-texture.jpg"), let image = image::load_from_memory_with_format(include_bytes!("../models/missing-texture.jpg"),
ImageFormat::JPEG).unwrap().to_rgba(); ImageFormat::JPEG).unwrap().to_rgba();
@@ -318,6 +319,8 @@ impl VulkanRenderer {
// can draw we also need to create the actual framebuffers. // 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 framebuffers = window_size_dependent_setup(device.clone(), &images, render_pass.clone(), &mut dynamic_state);
// let uniform_buffers = CpuBufferPool::<vs::ty::UniformBufferObject>::new(device.clone(), BufferUsage::all());
// In the loop below we are going to submit commands to the GPU. Submitting a command produces // 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 // an object that implements the `GpuFuture` trait, which holds the resources for as long as
// they are in use by the GPU. // 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<dyn GpuFuture>); let previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<dyn GpuFuture>);
VulkanRenderer { game_data: data, device, framebuffers, sampler, VulkanRenderer { game_data: data, device, framebuffers, sampler,
default_descriptor_set: default_descriptor_set, dynamic_state, pipeline, line_pipeline, default_descriptor_set,
dynamic_state, pipeline, line_pipeline,
surface, swapchain, render_pass, queue, line_vertex_buffer, events_loop, surface, swapchain, render_pass, queue, line_vertex_buffer, events_loop,
recreate_swapchain: false, debug_callback, previous_frame_end } recreate_swapchain: false, debug_callback, previous_frame_end }
} }