More testing

This commit is contained in:
hodasemi 2023-01-13 15:00:01 +01:00
parent 3478425b71
commit 392c4164d6
6 changed files with 115 additions and 55 deletions

View file

@ -11,7 +11,8 @@ crate-type = ["cdylib"]
[dependencies] [dependencies]
# vulkan-rs = { git = "ssh://gitea@gavania.de:23/Gavania/Gavania.git", branch = "0.2.0_dev" } # vulkan-rs = { git = "ssh://gitea@gavania.de:23/Gavania/Gavania.git", branch = "0.2.0_dev" }
vulkan-rs = { path = "/home/michael/Dokumente/Workspace/Gavania/vulkan-rs" } vulkan-rs = { path = "/home/michael/Dokumente/Workspace/Gavania/vulkan-rs" }
rfactor_sm_reader = { git = "https://gavania.de/hodasemi/rfactor_sm_reader.git" }
anyhow = { version = "1.0.68", features = ["backtrace"] } anyhow = { version = "1.0.68", features = ["backtrace"] }
rfactor_sm_reader = { path = "../rfactor_sm_reader" }
cgmath = "0.18.0" cgmath = "0.18.0"
paste = "1.0.11" paste = "1.0.11"

View file

@ -67,4 +67,5 @@ create_functions_enum!(
[QueueSubmit, submit_queue], [QueueSubmit, submit_queue],
[GetDeviceQueue, get_device_queue], [GetDeviceQueue, get_device_queue],
[AcquireNextImageKHR, acquire_next_image], [AcquireNextImageKHR, acquire_next_image],
[QueuePresentKHR, present_queue],
); );

View file

@ -24,6 +24,8 @@ const LOG_FILE: &'static str = "/home/michael/rf2_vk_hud.log";
static mut OVERLAY: Overlay = Overlay::new(); static mut OVERLAY: Overlay = Overlay::new();
static mut QUEUE_SUBMIT: PFN_vkQueueSubmit = static mut QUEUE_SUBMIT: PFN_vkQueueSubmit =
unsafe { mem::transmute(vkVoidFunction as *const c_void) }; unsafe { mem::transmute(vkVoidFunction as *const c_void) };
static mut ACQUIRE_NEXT_IMAGE: PFN_vkAcquireNextImageKHR =
unsafe { mem::transmute(vkVoidFunction as *const c_void) };
#[no_mangle] #[no_mangle]
#[allow(non_snake_case)] #[allow(non_snake_case)]
@ -237,7 +239,15 @@ pub extern "system" fn create_device(
write_log("failed querying vkQueueSubmit"); write_log("failed querying vkQueueSubmit");
return VK_ERROR_INITIALIZATION_FAILED; return VK_ERROR_INITIALIZATION_FAILED;
} }
} };
ACQUIRE_NEXT_IMAGE = match vk_handles().handle("vkAcquireNextImageKHR") {
Some(acquire_next_image) => mem::transmute(acquire_next_image),
None => {
write_log("failed querying vkAcquireNextImageKHR");
return VK_ERROR_INITIALIZATION_FAILED;
}
};
}; };
let pdev = match PhysicalDevice::from_raw(unsafe { OVERLAY.instance() }, physical_device) { let pdev = match PhysicalDevice::from_raw(unsafe { OVERLAY.instance() }, physical_device) {
@ -328,24 +338,30 @@ pub extern "system" fn submit_queue(
submits: *const VkSubmitInfo, submits: *const VkSubmitInfo,
fence: VkFence, fence: VkFence,
) -> VkResult { ) -> VkResult {
write_log(" ================== vulkan layer submit queue ==================");
unsafe { unsafe {
let input_submit_info = slice::from_raw_parts(submits, submit_count as usize); let command_buffers = slice::from_raw_parts(
let overlay_submit = match OVERLAY.render() { (*submits).pCommandBuffers,
Ok(submit) => submit, (*submits).commandBufferCount as usize,
);
let cb = match OVERLAY.render() {
Ok(cb) => cb,
Err(err) => { Err(err) => {
write_log(format!("overlay rendering failed: {:?}", err)); write_log(format!("overlay rendering failed: {:?}", err));
return VK_ERROR_DEVICE_LOST; return VK_ERROR_DEVICE_LOST;
} }
}; };
let complete_submits = [input_submit_info, &[overlay_submit]].concat(); let cb = [command_buffers, &[cb]].concat();
QUEUE_SUBMIT( let mut_ptr = submits as *mut VkSubmitInfo;
queue,
complete_submits.len() as u32, (*mut_ptr).commandBufferCount = cb.len() as u32;
complete_submits.as_ptr(), (*mut_ptr).pCommandBuffers = cb.as_ptr();
fence,
) QUEUE_SUBMIT(queue, submit_count, mut_ptr, fence)
} }
} }
@ -366,6 +382,7 @@ pub extern "system" fn get_device_queue(
}; };
get_device_queue(device, queue_family_index, queue_index, p_queue); get_device_queue(device, queue_family_index, queue_index, p_queue);
write_log(format!("new queue: {:?}", unsafe { *p_queue }));
unsafe { unsafe {
if !OVERLAY.has_queue() { if !OVERLAY.has_queue() {
@ -386,9 +403,63 @@ pub extern "system" fn acquire_next_image(
timeout: u64, timeout: u64,
semaphore: VkSemaphore, semaphore: VkSemaphore,
fence: VkFence, fence: VkFence,
pImageIndex: *mut u32, image_index: *mut u32,
) -> VkResult { ) -> VkResult {
VK_SUCCESS unsafe {
match OVERLAY.swapchain(swapchain) {
Some(sc) => {
let device = OVERLAY.device();
let res = device.acquire_next_image(
sc.vk_handle(),
timeout,
Some(semaphore),
Some(fence),
);
write_log(format!("acquire res: {:?}", res));
match res {
Ok(res) => match res {
OutOfDate::Ok(index) => {
sc.set_image_index(index);
VK_SUCCESS
}
OutOfDate::OutOfDate => VK_ERROR_OUT_OF_DATE_KHR,
OutOfDate::TimeOut => VK_TIMEOUT,
},
Err(err) => {
write_log(format!("failed acquiring next image {:?}", err));
VK_ERROR_DEVICE_LOST
}
}
}
None => {
write_log("acquired other swapchain image");
ACQUIRE_NEXT_IMAGE(device, swapchain, timeout, semaphore, fence, image_index)
}
}
}
}
pub extern "system" fn present_queue(
queue: VkQueue,
present_info: *const VkPresentInfoKHR,
) -> VkResult {
write_log(" ================== vulkan layer queue present ==================");
write_log(format!("iq: {:?}, cq: {:?}", queue, unsafe {
OVERLAY.queue().lock().unwrap().vk_handle()
}));
let pfn: PFN_vkQueuePresentKHR = match vk_handles().handle("vkQueuePresentKHR") {
Some(pfn) => unsafe { mem::transmute(pfn) },
None => {
write_log("failed querying vkQueuePresentKHR");
return VK_ERROR_DEVICE_LOST;
}
};
pfn(queue, present_info)
} }
pub fn write_log(msg: impl ToString) { pub fn write_log(msg: impl ToString) {

View file

@ -59,8 +59,14 @@ impl Overlay {
self.queue.as_ref().unwrap().clone() self.queue.as_ref().unwrap().clone()
} }
pub fn swapchain(&self) -> &Arc<Swapchain> { pub fn swapchain(&self, swapchain: VkSwapchainKHR) -> Option<&Arc<Swapchain>> {
self.rendering.as_ref().unwrap().swapchain() let sc = self.rendering.as_ref().unwrap().swapchain();
if sc.vk_handle() == swapchain {
Some(sc)
} else {
None
}
} }
pub fn create_rendering(&mut self, swapchain: Arc<Swapchain>) -> Result<()> { pub fn create_rendering(&mut self, swapchain: Arc<Swapchain>) -> Result<()> {
@ -79,17 +85,17 @@ impl Overlay {
Ok(()) Ok(())
} }
pub fn render(&mut self) -> Result<VkSubmitInfo> { pub fn render(&mut self) -> Result<VkCommandBuffer> {
if self.rfactor_data.is_none() { if self.rfactor_data.is_none() {
self.rfactor_data = RFactorData::new( // self.rfactor_data = RFactorData::new(
self.device(), // self.device(),
self.rendering // self.rendering
.as_mut() // .as_mut()
.unwrap() // .unwrap()
.single_color_pipeline() // .single_color_pipeline()
.descriptor_layout(), // .descriptor_layout(),
) // )
.ok(); // .ok();
} }
// check twice for rfactor data, because of borrowing rules // check twice for rfactor data, because of borrowing rules
@ -102,13 +108,8 @@ impl Overlay {
None => Vec::new(), None => Vec::new(),
}; };
let device = self.device(); let swapchain = self.rendering.as_ref().unwrap().swapchain().clone();
let queue = self.queue();
let swapchain = self.swapchain().clone();
self.rendering self.rendering.as_mut().unwrap().render(swapchain, &objects)
.as_mut()
.unwrap()
.render(device, queue, swapchain, &objects)
} }
} }

View file

@ -7,11 +7,7 @@ use super::rendering::PositionOnlyVertex;
pub struct SingleColorPipeline { pub struct SingleColorPipeline {
pipeline: Arc<Pipeline>, pipeline: Arc<Pipeline>,
pipeline_layout: Arc<PipelineLayout>,
descriptor_layout: Arc<DescriptorSetLayout>, descriptor_layout: Arc<DescriptorSetLayout>,
vertex_shader: Arc<ShaderModule>,
fragment_shader: Arc<ShaderModule>,
} }
impl SingleColorPipeline { impl SingleColorPipeline {
@ -67,11 +63,8 @@ impl SingleColorPipeline {
.build(device, &pipeline_layout, &renderpass, 0)?; .build(device, &pipeline_layout, &renderpass, 0)?;
Ok(Self { Ok(Self {
vertex_shader,
fragment_shader,
descriptor_layout, descriptor_layout,
pipeline, pipeline,
pipeline_layout,
}) })
} }

View file

@ -47,7 +47,7 @@ pub struct Rendering {
swapchain: Arc<Swapchain>, swapchain: Arc<Swapchain>,
pipeline: SingleColorPipeline, pipeline: SingleColorPipeline,
render_target: RenderTarget, render_target: RenderTarget,
submit_info: SubmitInfo, command_buffer: Arc<CommandBuffer>,
} }
impl Rendering { impl Rendering {
@ -89,9 +89,9 @@ impl Rendering {
Ok(Self { Ok(Self {
swapchain, swapchain,
pipeline: SingleColorPipeline::new(device, render_target.render_pass())?, pipeline: SingleColorPipeline::new(device.clone(), render_target.render_pass())?,
render_target, render_target,
submit_info: SubmitInfo::default(), command_buffer: CommandBuffer::new_primary().build(device, queue)?,
}) })
} }
@ -105,11 +105,9 @@ impl Rendering {
pub fn render( pub fn render(
&mut self, &mut self,
device: Arc<Device>,
queue: Arc<Mutex<Queue>>,
swapchain: Arc<Swapchain>, swapchain: Arc<Swapchain>,
objects: &[&dyn RenderObject], objects: &[&dyn RenderObject],
) -> Result<VkSubmitInfo> { ) -> Result<VkCommandBuffer> {
let image_index = self.swapchain.current_index(); let image_index = self.swapchain.current_index();
let viewport = [VkViewport { let viewport = [VkViewport {
@ -129,11 +127,10 @@ impl Rendering {
}, },
}]; }];
let command_buffer = CommandBuffer::new_primary().build(device, queue)?;
{ {
let mut recorder = command_buffer.begin(VkCommandBufferBeginInfo::new( let mut recorder = self.command_buffer.begin(VkCommandBufferBeginInfo::new(
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
| VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
))?; ))?;
self.render_target self.render_target
@ -156,10 +153,6 @@ impl Rendering {
self.render_target.end(&recorder); self.render_target.end(&recorder);
} }
self.submit_info = SubmitInfo::default() Ok(self.command_buffer.vk_handle())
.add_wait_stage(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)
.add_command_buffer(command_buffer);
Ok(self.submit_info.as_vk_submit())
} }
} }