Debug why there is nothing rendered
This commit is contained in:
parent
ecfaa18614
commit
3478425b71
4 changed files with 79 additions and 48 deletions
|
@ -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"
|
||||||
|
|
72
src/enums.rs
72
src/enums.rs
|
@ -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,30 +21,50 @@ pub enum VkLayerFunction {
|
||||||
VK_LOADER_FEATURES = 3,
|
VK_LOADER_FEATURES = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Functions {
|
macro_rules! create_functions_enum {
|
||||||
Null,
|
($([$pfn:ident, $func:ident],)+) => {
|
||||||
CreateInstance(PFN_vkCreateInstance),
|
paste::paste! {
|
||||||
DestroyInstance(PFN_vkDestroyInstance),
|
pub enum Functions {
|
||||||
CreateDevice(PFN_vkCreateDevice),
|
Null,
|
||||||
DestroyDevice(PFN_vkDestroyDevice),
|
$(
|
||||||
CreateSwapchain(PFN_vkCreateSwapchainKHR),
|
$pfn ( [<PFN_vk $pfn>] ),
|
||||||
QueueSubmit(PFN_vkQueueSubmit),
|
)+
|
||||||
GetDeviceQueue(PFN_vkGetDeviceQueue),
|
}
|
||||||
|
|
||||||
|
impl Functions {
|
||||||
|
pub fn convert(self) -> PFN_vkVoidFunction {
|
||||||
|
match self {
|
||||||
|
Functions::Null => unsafe {
|
||||||
|
mem::transmute::<*const (), PFN_vkVoidFunction>(ptr::null())
|
||||||
|
},
|
||||||
|
$(
|
||||||
|
Functions::$pfn(foo) => unsafe { mem::transmute(foo) },
|
||||||
|
)+
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_vk_func(s:&str) -> Option<Functions> {
|
||||||
|
match s {
|
||||||
|
$(
|
||||||
|
stringify!([<vk $pfn>]) => Some(Functions::$pfn($func)),
|
||||||
|
)+
|
||||||
|
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Functions {
|
create_functions_enum!(
|
||||||
pub fn convert(self) -> PFN_vkVoidFunction {
|
[CreateInstance, create_instance],
|
||||||
match self {
|
[DestroyInstance, destroy_instance],
|
||||||
Functions::Null => unsafe {
|
[CreateDevice, create_device],
|
||||||
mem::transmute::<*const (), PFN_vkVoidFunction>(ptr::null())
|
[DestroyDevice, destroy_device],
|
||||||
},
|
[CreateSwapchainKHR, create_swapchain],
|
||||||
Functions::CreateInstance(func) => unsafe { mem::transmute(func) },
|
[QueueSubmit, submit_queue],
|
||||||
Functions::DestroyInstance(func) => unsafe { mem::transmute(func) },
|
[GetDeviceQueue, get_device_queue],
|
||||||
Functions::CreateDevice(func) => unsafe { mem::transmute(func) },
|
[AcquireNextImageKHR, acquire_next_image],
|
||||||
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) },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
46
src/lib.rs
46
src/lib.rs
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue