Debug why there is nothing rendered

This commit is contained in:
hodasemi 2023-01-13 09:27:58 +01:00
parent 0dfc8a9ff0
commit 2c8a979b1e
4 changed files with 79 additions and 48 deletions

View file

@ -14,3 +14,4 @@ vulkan-rs = { path = "/home/michael/Dokumente/Workspace/Gavania/vulkan-rs" }
anyhow = { version = "1.0.68", features = ["backtrace"] } anyhow = { version = "1.0.68", features = ["backtrace"] }
rfactor_sm_reader = { path = "../rfactor_sm_reader" } rfactor_sm_reader = { path = "../rfactor_sm_reader" }
cgmath = "0.18.0" cgmath = "0.18.0"
paste = "1.0.11"

View file

@ -3,6 +3,8 @@
use std::{mem, ptr}; use std::{mem, ptr};
use vulkan_rs::prelude::*; use vulkan_rs::prelude::*;
use crate::*;
pub use VkLayerFunction::*; pub use VkLayerFunction::*;
pub use VkNegotiateLayerStructType::*; pub use VkNegotiateLayerStructType::*;
@ -19,15 +21,14 @@ pub enum VkLayerFunction {
VK_LOADER_FEATURES = 3, VK_LOADER_FEATURES = 3,
} }
macro_rules! create_functions_enum {
($([$pfn:ident, $func:ident],)+) => {
paste::paste! {
pub enum Functions { pub enum Functions {
Null, Null,
CreateInstance(PFN_vkCreateInstance), $(
DestroyInstance(PFN_vkDestroyInstance), $pfn ( [<PFN_vk $pfn>] ),
CreateDevice(PFN_vkCreateDevice), )+
DestroyDevice(PFN_vkDestroyDevice),
CreateSwapchain(PFN_vkCreateSwapchainKHR),
QueueSubmit(PFN_vkQueueSubmit),
GetDeviceQueue(PFN_vkGetDeviceQueue),
} }
impl Functions { impl Functions {
@ -36,13 +37,34 @@ impl Functions {
Functions::Null => unsafe { Functions::Null => unsafe {
mem::transmute::<*const (), PFN_vkVoidFunction>(ptr::null()) mem::transmute::<*const (), PFN_vkVoidFunction>(ptr::null())
}, },
Functions::CreateInstance(func) => unsafe { mem::transmute(func) }, $(
Functions::DestroyInstance(func) => unsafe { mem::transmute(func) }, Functions::$pfn(foo) => unsafe { mem::transmute(foo) },
Functions::CreateDevice(func) => unsafe { mem::transmute(func) }, )+
Functions::DestroyDevice(func) => unsafe { mem::transmute(func) }, }
Functions::CreateSwapchain(func) => unsafe { mem::transmute(func) }, }
Functions::QueueSubmit(func) => unsafe { mem::transmute(func) },
Functions::GetDeviceQueue(func) => unsafe { mem::transmute(func) }, pub fn get_vk_func(s:&str) -> Option<Functions> {
match s {
$(
stringify!([<vk $pfn>]) => Some(Functions::$pfn($func)),
)+
_ => None
} }
} }
} }
}
};
}
create_functions_enum!(
[CreateInstance, create_instance],
[DestroyInstance, destroy_instance],
[CreateDevice, create_device],
[DestroyDevice, destroy_device],
[CreateSwapchainKHR, create_swapchain],
[QueueSubmit, submit_queue],
[GetDeviceQueue, get_device_queue],
[AcquireNextImageKHR, acquire_next_image],
);

View file

@ -73,7 +73,7 @@ extern "system" fn get_device_proc_addr(
let s = func_string.as_str(); let s = func_string.as_str();
if let Some(func) = get_vk_func(s) { if let Some(func) = Functions::get_vk_func(s) {
return func.convert(); return func.convert();
} }
@ -99,7 +99,7 @@ extern "system" fn get_instance_proc_addr(
let s = func_string.as_str(); let s = func_string.as_str();
if let Some(func) = get_vk_func(s) { if let Some(func) = Functions::get_vk_func(s) {
return func.convert(); return func.convert();
} }
@ -110,7 +110,7 @@ extern "system" fn get_instance_proc_addr(
Functions::Null.convert() Functions::Null.convert()
} }
extern "system" fn create_instance( pub extern "system" fn create_instance(
create_info: *const VkInstanceCreateInfo, create_info: *const VkInstanceCreateInfo,
allocator: *const VkAllocationCallbacks, allocator: *const VkAllocationCallbacks,
instance: *mut VkInstance, instance: *mut VkInstance,
@ -175,7 +175,10 @@ extern "system" fn create_instance(
VK_SUCCESS VK_SUCCESS
} }
extern "system" fn destroy_instance(instance: VkInstance, allocator: *const VkAllocationCallbacks) { pub extern "system" fn destroy_instance(
instance: VkInstance,
allocator: *const VkAllocationCallbacks,
) {
write_log(" ================== vulkan layer destroy instance =================="); write_log(" ================== vulkan layer destroy instance ==================");
unsafe { unsafe {
@ -187,7 +190,7 @@ extern "system" fn destroy_instance(instance: VkInstance, allocator: *const VkAl
} }
} }
extern "system" fn create_device( pub extern "system" fn create_device(
physical_device: VkPhysicalDevice, physical_device: VkPhysicalDevice,
create_info: *const VkDeviceCreateInfo<'_>, create_info: *const VkDeviceCreateInfo<'_>,
allocator: *const VkAllocationCallbacks, allocator: *const VkAllocationCallbacks,
@ -263,7 +266,7 @@ extern "system" fn create_device(
VK_SUCCESS VK_SUCCESS
} }
extern "system" fn destroy_device(device: VkDevice, allocator: *const VkAllocationCallbacks) { pub extern "system" fn destroy_device(device: VkDevice, allocator: *const VkAllocationCallbacks) {
write_log(" ================== vulkan layer destroy device =================="); write_log(" ================== vulkan layer destroy device ==================");
unsafe { unsafe {
@ -275,7 +278,7 @@ extern "system" fn destroy_device(device: VkDevice, allocator: *const VkAllocati
} }
} }
extern "system" fn create_swapchain( pub extern "system" fn create_swapchain(
_device: VkDevice, _device: VkDevice,
create_info: *const VkSwapchainCreateInfoKHR, create_info: *const VkSwapchainCreateInfoKHR,
_allocator: *const VkAllocationCallbacks, _allocator: *const VkAllocationCallbacks,
@ -319,7 +322,7 @@ extern "system" fn create_swapchain(
VK_SUCCESS VK_SUCCESS
} }
extern "system" fn submit_queue( pub extern "system" fn submit_queue(
queue: VkQueue, queue: VkQueue,
submit_count: u32, submit_count: u32,
submits: *const VkSubmitInfo, submits: *const VkSubmitInfo,
@ -346,7 +349,7 @@ extern "system" fn submit_queue(
} }
} }
extern "system" fn get_device_queue( pub extern "system" fn get_device_queue(
device: VkDevice, device: VkDevice,
queue_family_index: u32, queue_family_index: u32,
queue_index: u32, queue_index: u32,
@ -377,22 +380,19 @@ extern "system" fn get_device_queue(
} }
} }
pub extern "system" fn acquire_next_image(
device: VkDevice,
swapchain: VkSwapchainKHR,
timeout: u64,
semaphore: VkSemaphore,
fence: VkFence,
pImageIndex: *mut u32,
) -> VkResult {
VK_SUCCESS
}
pub fn write_log(msg: impl ToString) { pub fn write_log(msg: impl ToString) {
if let Ok(mut file) = OpenOptions::new().append(true).create(true).open(LOG_FILE) { if let Ok(mut file) = OpenOptions::new().append(true).create(true).open(LOG_FILE) {
if let Err(_) = file.write_all(format!("{}\n", msg.to_string()).as_bytes()) {} if let Err(_) = file.write_all(format!("{}\n", msg.to_string()).as_bytes()) {}
} }
} }
pub fn get_vk_func(s: &str) -> Option<Functions> {
match s {
"vkCreateDevice" => Some(Functions::CreateDevice(create_device)),
"vkDestroyDevice" => Some(Functions::DestroyDevice(destroy_device)),
"vkCreateInstance" => Some(Functions::CreateInstance(create_instance)),
"vkDestroyInstance" => Some(Functions::DestroyInstance(destroy_instance)),
"vkCreateSwapchainKHR" => Some(Functions::CreateSwapchain(create_swapchain)),
"vkQueueSubmit" => Some(Functions::QueueSubmit(submit_queue)),
"vkGetDeviceQueue" => Some(Functions::GetDeviceQueue(get_device_queue)),
_ => None,
}
}

View file

@ -81,6 +81,12 @@ impl Rendering {
write_log("-> Rendering ctor: created render_target"); write_log("-> Rendering ctor: created render_target");
write_log(format!(
"-> Rendering swapchain extents ({}, {})",
swapchain.width(),
swapchain.height(),
));
Ok(Self { Ok(Self {
swapchain, swapchain,
pipeline: SingleColorPipeline::new(device, render_target.render_pass())?, pipeline: SingleColorPipeline::new(device, render_target.render_pass())?,
@ -137,6 +143,8 @@ impl Rendering {
recorder.set_scissor(&scissor); recorder.set_scissor(&scissor);
recorder.set_viewport(&viewport); recorder.set_viewport(&viewport);
write_log(format!("-> Rendering {} objects", objects.len()));
for object in objects { for object in objects {
let buffer = object.buffer(); let buffer = object.buffer();