From 8626d23f886015172127f483249b2c9e6790849a Mon Sep 17 00:00:00 2001 From: hodasemi Date: Mon, 20 Feb 2023 10:21:33 +0100 Subject: [PATCH 1/9] Add more logging --- src/vk_layer/vk_handles.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/vk_layer/vk_handles.rs b/src/vk_layer/vk_handles.rs index b157f3b..122c48c 100644 --- a/src/vk_layer/vk_handles.rs +++ b/src/vk_layer/vk_handles.rs @@ -2,6 +2,8 @@ use anyhow::Result; use std::{collections::HashMap, ffi::c_void, mem, ptr}; use vulkan_rs::prelude::*; +use crate::write_log; + static mut FN_HANDLES: Option = None; pub fn vk_handles() -> &'static VkTypedefHandles { @@ -44,6 +46,8 @@ impl VkTypedefHandles { if mem::transmute::(function) != ptr::null() { self.functions.insert(symbol.clone(), function); + } else { + write_log!(format!("layer (instance): failed reading {}", symbol)); } } } @@ -57,6 +61,8 @@ impl VkTypedefHandles { if mem::transmute::(function) != ptr::null() { self.functions.insert(symbol.clone(), function); + } else { + write_log!(format!("layer (device): failed reading {}", symbol)); } } } -- 2.47.0 From 8e09841daddd315e84b40f78cd4c7316e84f25f0 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Tue, 21 Feb 2023 18:45:43 +0100 Subject: [PATCH 2/9] More logging for instance creation --- src/vk_layer/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vk_layer/mod.rs b/src/vk_layer/mod.rs index 3338c50..6092360 100644 --- a/src/vk_layer/mod.rs +++ b/src/vk_layer/mod.rs @@ -144,6 +144,8 @@ pub(crate) extern "system" fn create_instance( // DXVK workaround, it creates the instance twice with different properties if ext_names.contains(&VkString::new("VK_KHR_surface")) { + write_log!("found VK_KHR_surface"); + unsafe { let panic_result = match std::panic::catch_unwind(|| -> anyhow::Result> { @@ -178,6 +180,8 @@ pub(crate) extern "system" fn create_instance( write_log!("-> created local instance handle"); } + write_log!("returning from create_instance"); + VK_SUCCESS } -- 2.47.0 From 8b3186094d4ee7c9f7a6bf24f1822f585d5f011e Mon Sep 17 00:00:00 2001 From: hodasemi Date: Tue, 21 Feb 2023 19:23:10 +0100 Subject: [PATCH 3/9] Add application info workaround --- resources/pkgbuild/PKGBUILD | 2 +- src/vk_layer/mod.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/pkgbuild/PKGBUILD b/resources/pkgbuild/PKGBUILD index d9bcde2..cdf4b02 100644 --- a/resources/pkgbuild/PKGBUILD +++ b/resources/pkgbuild/PKGBUILD @@ -7,7 +7,7 @@ pkgdesc="Vulkan overlay layer for rFactor 2" arch=('x86_64') url="https://gavania.de/hodasemi/${_pkgbase}" license=('GPL-3.0') -makedepends=('rust' 'ctags' 'glslang') +makedepends=('rust' 'ctags' 'glslang' 'vulkan-headers') depends=() conflicts=("${_pkgbase}") source=("git+${url}") diff --git a/src/vk_layer/mod.rs b/src/vk_layer/mod.rs index 6092360..212a369 100644 --- a/src/vk_layer/mod.rs +++ b/src/vk_layer/mod.rs @@ -153,7 +153,11 @@ pub(crate) extern "system" fn create_instance( *instance, proc_addr, &ext_names, - (*(*create_info).pApplicationInfo).apiVersion, + if (*create_info).pApplicationInfo == ptr::null() { + VK_MAKE_VERSION(1, 3, 0) + } else { + (*(*create_info).pApplicationInfo).apiVersion + }, ) }) { Ok(panic_ok) => panic_ok, -- 2.47.0 From 7cc1eb54e20bf6470290bfd80fba0ccfa2b512c5 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Tue, 21 Feb 2023 19:31:04 +0100 Subject: [PATCH 4/9] Add vk_handle debug infos --- src/vk_layer/vk_handles.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vk_layer/vk_handles.rs b/src/vk_layer/vk_handles.rs index 122c48c..e7a44f6 100644 --- a/src/vk_layer/vk_handles.rs +++ b/src/vk_layer/vk_handles.rs @@ -45,6 +45,7 @@ impl VkTypedefHandles { let function = proc_addr(instance, name.as_ptr()); if mem::transmute::(function) != ptr::null() { + write_log!(format!("layer (instance): successfully read: {}", symbol)); self.functions.insert(symbol.clone(), function); } else { write_log!(format!("layer (instance): failed reading {}", symbol)); @@ -60,6 +61,7 @@ impl VkTypedefHandles { let function = proc_addr(device, name.as_ptr()); if mem::transmute::(function) != ptr::null() { + write_log!(format!("layer (device): successfully read: {}", symbol)); self.functions.insert(symbol.clone(), function); } else { write_log!(format!("layer (device): failed reading {}", symbol)); -- 2.47.0 From eaff64a9d60a62bf77fbe7484bad8c69c8bae09f Mon Sep 17 00:00:00 2001 From: hodasemi Date: Wed, 22 Feb 2023 09:24:28 +0100 Subject: [PATCH 5/9] Add logging to get_proc_addrs --- src/vk_layer/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vk_layer/mod.rs b/src/vk_layer/mod.rs index 212a369..c094240 100644 --- a/src/vk_layer/mod.rs +++ b/src/vk_layer/mod.rs @@ -55,6 +55,8 @@ extern "system" fn get_device_proc_addr( _device: VkDevice, function_name: *const c_char, ) -> PFN_vkVoidFunction { + write_log!("get_device_proc_addr"); + let func_string = match VkString::try_from(function_name) { Ok(func) => func, Err(_) => { @@ -65,6 +67,8 @@ extern "system" fn get_device_proc_addr( let s = func_string.as_str(); + write_log!(format!("\t{}", s)); + if let Some(func) = Functions::get_vk_func(s) { return func.convert(); } @@ -73,6 +77,8 @@ extern "system" fn get_device_proc_addr( return func; } + write_log!("\t-> returning null"); + Functions::Null.convert() } @@ -81,6 +87,8 @@ extern "system" fn get_instance_proc_addr( _instance: VkInstance, function_name: *const c_char, ) -> PFN_vkVoidFunction { + write_log!("get_instance_proc_addr"); + let func_string = match VkString::try_from(function_name) { Ok(func) => func, Err(_) => { @@ -91,6 +99,8 @@ extern "system" fn get_instance_proc_addr( let s = func_string.as_str(); + write_log!(format!("\t{}", s)); + if let Some(func) = Functions::get_vk_func(s) { return func.convert(); } @@ -99,6 +109,8 @@ extern "system" fn get_instance_proc_addr( return func; } + write_log!("\t-> returning null"); + Functions::Null.convert() } -- 2.47.0 From 790595783538b3237903b7a0641c9a9872675c54 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Wed, 22 Feb 2023 09:38:25 +0100 Subject: [PATCH 6/9] Use Option for api version --- src/vk_layer/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vk_layer/mod.rs b/src/vk_layer/mod.rs index c094240..27ad675 100644 --- a/src/vk_layer/mod.rs +++ b/src/vk_layer/mod.rs @@ -166,9 +166,9 @@ pub(crate) extern "system" fn create_instance( proc_addr, &ext_names, if (*create_info).pApplicationInfo == ptr::null() { - VK_MAKE_VERSION(1, 3, 0) + None } else { - (*(*create_info).pApplicationInfo).apiVersion + Some((*(*create_info).pApplicationInfo).apiVersion) }, ) }) { -- 2.47.0 From a5a370215387f66ba937df048037c7365124f72b Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sat, 15 Apr 2023 07:54:01 +0200 Subject: [PATCH 7/9] Attempt to fix layer for mesa (intel) --- src/overlay/elements/pedals/mod.rs | 41 ++++++++++++++++--------- src/overlay/elements/pedals/pipeline.rs | 1 + src/overlay/elements/radar/mod.rs | 30 +++++++++--------- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/overlay/elements/pedals/mod.rs b/src/overlay/elements/pedals/mod.rs index e5916dc..a54be7f 100644 --- a/src/overlay/elements/pedals/mod.rs +++ b/src/overlay/elements/pedals/mod.rs @@ -94,7 +94,6 @@ impl Pedals { let descriptor_pool = DescriptorPool::builder() .set_layout(pipeline.descriptor_layout().clone()) - .set_descriptor_set_count(2) .build(device.clone())?; let brake_color_buffer = Buffer::builder() @@ -116,7 +115,16 @@ impl Pedals { write_log!("allocate throttle descriptor"); - let throttle_descriptor = descriptor_pool.prepare_set().allocate()?; + let throttle_descriptor = match descriptor_pool.prepare_set().allocate() { + Ok(d) => d, + Err(err) => { + write_log!(format!("desc alloc {:?}, {}", err, err.backtrace())); + return Err(err); + } + }; + + write_log!("update throttle descriptor"); + throttle_descriptor.update(&[DescriptorWrite::uniform_buffers( 0, &[&throttle_color_buffer], @@ -130,6 +138,8 @@ impl Pedals { brake_samples.push_overwrite(0.0); } + write_log!(format!("create vertex buffers ({icon_width})")); + let brake_vertex_buffer = Self::create_vertex_buffer(&device, icon_width as VkDeviceSize)?; let throttle_vertex_buffer = Self::create_vertex_buffer(&device, icon_width as VkDeviceSize)?; @@ -160,6 +170,8 @@ impl Pedals { throttle_vertex_buffer, }; + write_log!("update vertex buffers"); + me.update_vertex_buffers()?; Ok(me) @@ -207,26 +219,27 @@ impl Pedals { let command_buffer = CommandBuffer::new_primary().build(self.device.clone(), self.queue.clone())?; - if self.enable { + { let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new( VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, ))?; + if self.enable { + self.render_target + .begin(&mut recorder, VK_SUBPASS_CONTENTS_INLINE, 0); - self.render_target - .begin(&mut recorder, VK_SUBPASS_CONTENTS_INLINE, 0); + recorder.bind_pipeline(self.pipeline.pipeline())?; - recorder.bind_pipeline(self.pipeline.pipeline())?; + recorder.bind_descriptor_sets_minimal(&[&self.throttle_descriptor]); + recorder.bind_vertex_buffer(&self.throttle_vertex_buffer); + recorder.draw_complete_single_instance(self.throttle_vertex_buffer.size() as u32); - recorder.bind_descriptor_sets_minimal(&[&self.throttle_descriptor]); - recorder.bind_vertex_buffer(&self.throttle_vertex_buffer); - recorder.draw_complete_single_instance(self.throttle_vertex_buffer.size() as u32); + recorder.bind_descriptor_sets_minimal(&[&self.brake_descriptor]); + recorder.bind_vertex_buffer(&self.brake_vertex_buffer); + recorder.draw_complete_single_instance(self.brake_vertex_buffer.size() as u32); - recorder.bind_descriptor_sets_minimal(&[&self.brake_descriptor]); - recorder.bind_vertex_buffer(&self.brake_vertex_buffer); - recorder.draw_complete_single_instance(self.brake_vertex_buffer.size() as u32); - - self.render_target.end(&mut recorder); + self.render_target.end(&mut recorder); + } } Ok(command_buffer) diff --git a/src/overlay/elements/pedals/pipeline.rs b/src/overlay/elements/pedals/pipeline.rs index ac511b6..4a98d2a 100644 --- a/src/overlay/elements/pedals/pipeline.rs +++ b/src/overlay/elements/pedals/pipeline.rs @@ -29,6 +29,7 @@ impl HistoryPipeline { VK_SHADER_STAGE_FRAGMENT_BIT, 0, ) + .change_descriptor_count(2) .build(device.clone())?; let pipeline_layout = PipelineLayout::builder() diff --git a/src/overlay/elements/radar/mod.rs b/src/overlay/elements/radar/mod.rs index 9a2b3b2..8e78697 100644 --- a/src/overlay/elements/radar/mod.rs +++ b/src/overlay/elements/radar/mod.rs @@ -222,29 +222,31 @@ impl Radar { let command_buffer = CommandBuffer::new_primary().build(self.device.clone(), self.queue.clone())?; - if self.enable { + { let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new( VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT | VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT, ))?; - self.render_target.begin( - &mut recorder, - VK_SUBPASS_CONTENTS_INLINE, - image_index as usize, - ); + if self.enable { + self.render_target.begin( + &mut recorder, + VK_SUBPASS_CONTENTS_INLINE, + image_index as usize, + ); - recorder.bind_pipeline(self.pipeline.pipeline())?; + recorder.bind_pipeline(self.pipeline.pipeline())?; - for object in self.objects() { - let buffer = &object.position_buffer; + for object in self.objects() { + let buffer = &object.position_buffer; - recorder.bind_descriptor_sets_minimal(&[&object.descriptor_set]); - recorder.bind_vertex_buffer(buffer); - recorder.draw_complete_single_instance(buffer.size() as u32); + recorder.bind_descriptor_sets_minimal(&[&object.descriptor_set]); + recorder.bind_vertex_buffer(buffer); + recorder.draw_complete_single_instance(buffer.size() as u32); + } + + self.render_target.end(&mut recorder); } - - self.render_target.end(&mut recorder); } Ok(command_buffer) -- 2.47.0 From d87ed8c0c9f38a555f6f7f5df2f48a9dd138cdfe Mon Sep 17 00:00:00 2001 From: hodasemi Date: Sun, 16 Apr 2023 08:51:05 +0200 Subject: [PATCH 8/9] Fix pedal overlay --- src/overlay/elements/pedals/mod.rs | 1 + src/overlay/elements/pedals/pipeline.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlay/elements/pedals/mod.rs b/src/overlay/elements/pedals/mod.rs index a54be7f..b66d3a7 100644 --- a/src/overlay/elements/pedals/mod.rs +++ b/src/overlay/elements/pedals/mod.rs @@ -94,6 +94,7 @@ impl Pedals { let descriptor_pool = DescriptorPool::builder() .set_layout(pipeline.descriptor_layout().clone()) + .set_descriptor_set_count(2) .build(device.clone())?; let brake_color_buffer = Buffer::builder() diff --git a/src/overlay/elements/pedals/pipeline.rs b/src/overlay/elements/pedals/pipeline.rs index 4a98d2a..ac511b6 100644 --- a/src/overlay/elements/pedals/pipeline.rs +++ b/src/overlay/elements/pedals/pipeline.rs @@ -29,7 +29,6 @@ impl HistoryPipeline { VK_SHADER_STAGE_FRAGMENT_BIT, 0, ) - .change_descriptor_count(2) .build(device.clone())?; let pipeline_layout = PipelineLayout::builder() -- 2.47.0 From 889b2f212c157fb875475e28be65bba7ea8a7964 Mon Sep 17 00:00:00 2001 From: hodasemi Date: Thu, 20 Apr 2023 09:10:29 +0200 Subject: [PATCH 9/9] Fix leaderboard formatting --- src/overlay/elements/leaderboard/leaderboard_entry.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/overlay/elements/leaderboard/leaderboard_entry.rs b/src/overlay/elements/leaderboard/leaderboard_entry.rs index e8fec60..656e90f 100644 --- a/src/overlay/elements/leaderboard/leaderboard_entry.rs +++ b/src/overlay/elements/leaderboard/leaderboard_entry.rs @@ -218,7 +218,7 @@ impl LeaderBoardEntry { if best_lap > 60.0 { let (full_minutes, remainder) = Self::split_minute(best_lap); - format!("{:.0}:{:.3}", full_minutes, remainder) + format!("{:.0}:{:06.3}", full_minutes, remainder) } else { format!("{:.3}", best_lap) } @@ -307,5 +307,7 @@ mod test { let behind_leader = LeaderBoardEntry::calculate_behind_leader(BehindLeader::Time(85.42)); let behind_next = LeaderBoardEntry::calculate_behind_next(150.213423); let best_lap = LeaderBoardEntry::calculuate_best_lap(97.23436); + + let t = LeaderBoardEntry::calculuate_best_lap(65.23436); } } -- 2.47.0