Fix dead lock
This commit is contained in:
parent
bd8d255492
commit
edc60dd757
3 changed files with 72 additions and 15 deletions
|
@ -9,7 +9,7 @@ mod elements;
|
||||||
mod rendering;
|
mod rendering;
|
||||||
mod rfactor_data;
|
mod rfactor_data;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::{bail, Result};
|
||||||
use assetpath::AssetPath;
|
use assetpath::AssetPath;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
@ -366,7 +366,11 @@ impl Overlay {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&mut self, wait_semaphores: &[VkSemaphore]) -> Result<&Arc<Semaphore>> {
|
pub fn render(
|
||||||
|
&mut self,
|
||||||
|
wait_semaphores: &[VkSemaphore],
|
||||||
|
swapchain: &Arc<Swapchain>,
|
||||||
|
) -> Result<&Arc<Semaphore>> {
|
||||||
if self.rfactor_data.is_none() {
|
if self.rfactor_data.is_none() {
|
||||||
self.rfactor_data = RFactorData::new().ok();
|
self.rfactor_data = RFactorData::new().ok();
|
||||||
|
|
||||||
|
@ -383,7 +387,13 @@ impl Overlay {
|
||||||
rfactor.update()?;
|
rfactor.update()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.rendering.as_ref().unwrap().render(wait_semaphores)
|
let rendering = self.rendering.as_ref().unwrap();
|
||||||
|
|
||||||
|
if swapchain.vk_handle() != rendering.swapchain().vk_handle() {
|
||||||
|
bail!("swapchains did not match");
|
||||||
|
} else {
|
||||||
|
rendering.render(wait_semaphores)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,8 @@ impl Rendering {
|
||||||
}
|
}
|
||||||
|
|
||||||
for wait_semaphore in wait_semaphores {
|
for wait_semaphore in wait_semaphores {
|
||||||
submit = submit.add_wait_semaphore_vk(*wait_semaphore);
|
submit = submit
|
||||||
|
.add_wait_semaphore_vk(*wait_semaphore, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
write_log!(format!(
|
write_log!(format!(
|
||||||
|
|
|
@ -467,7 +467,6 @@ pub(crate) extern "system" fn present_queue(
|
||||||
|
|
||||||
let mut overlay = overlay();
|
let mut overlay = overlay();
|
||||||
let wait_semaphores = unsafe { (*present_info).wait_semaphores() };
|
let wait_semaphores = unsafe { (*present_info).wait_semaphores() };
|
||||||
let mut res = VK_SUCCESS;
|
|
||||||
|
|
||||||
let pfn: PFN_vkQueuePresentKHR = match vk_handles().handle("vkQueuePresentKHR") {
|
let pfn: PFN_vkQueuePresentKHR = match vk_handles().handle("vkQueuePresentKHR") {
|
||||||
Some(pfn) => unsafe { mem::transmute(pfn) },
|
Some(pfn) => unsafe { mem::transmute(pfn) },
|
||||||
|
@ -477,21 +476,60 @@ pub(crate) extern "system" fn present_queue(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for swapchain_info in unsafe { (*present_info).swapchain_info() } {
|
for (index, swapchain_info) in unsafe { (*present_info).swapchain_info() }
|
||||||
if let Some(swapchain) = overlay.swapchain(swapchain_info.swapchain) {
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
|
if let Some(swapchain) = overlay.swapchain(swapchain_info.swapchain).cloned() {
|
||||||
unsafe { swapchain.set_image_index(swapchain_info.index) };
|
unsafe { swapchain.set_image_index(swapchain_info.index) };
|
||||||
|
let swapchain_handle = swapchain.vk_handle();
|
||||||
|
|
||||||
match overlay.render(wait_semaphores) {
|
match overlay.render(wait_semaphores, &swapchain) {
|
||||||
Ok(signal_semaphore) => {
|
Ok(signal_semaphore) => {
|
||||||
let new_present_info = present_info as *mut VkPresentInfoKHR;
|
let wait_semaphores = &[signal_semaphore.vk_handle()];
|
||||||
|
let swapchain_handles = &[swapchain_handle];
|
||||||
|
let indices = &[swapchain_info.index];
|
||||||
|
|
||||||
unsafe {
|
let mut new_present_info =
|
||||||
(*new_present_info).waitSemaphoreCount = 1;
|
VkPresentInfoKHR::new(wait_semaphores, swapchain_handles, indices, &mut []);
|
||||||
(*new_present_info).pWaitSemaphores =
|
new_present_info.pNext = unsafe { (*present_info).pNext };
|
||||||
[signal_semaphore.vk_handle()].as_ptr();
|
|
||||||
|
if signal_semaphore.vk_handle() != new_present_info.wait_semaphores()[0] {
|
||||||
|
write_log!(format!(
|
||||||
|
"wait_semaphore: expected ({:?}) - found ({:?})",
|
||||||
|
signal_semaphore.vk_handle(),
|
||||||
|
new_present_info.wait_semaphores()[0],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
res = pfn(queue, new_present_info);
|
if swapchain_handle != new_present_info.swapchain_info()[0].swapchain {
|
||||||
|
write_log!(format!(
|
||||||
|
"swapchain: expected ({:?}) - found ({:?})",
|
||||||
|
swapchain_handle,
|
||||||
|
new_present_info.swapchain_info()[0].swapchain,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if swapchain_info.index != new_present_info.swapchain_info()[0].index {
|
||||||
|
write_log!(format!(
|
||||||
|
"index: expected ({:?}) - found ({:?})",
|
||||||
|
swapchain_info.index,
|
||||||
|
new_present_info.swapchain_info()[0].index,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
write_log!(format!("present_info: {new_present_info:#?}"));
|
||||||
|
unsafe {
|
||||||
|
write_log!(format!("present_info: {:#?}", *present_info));
|
||||||
|
}
|
||||||
|
|
||||||
|
let res = pfn(queue, &new_present_info);
|
||||||
|
|
||||||
|
let results = unsafe { (*present_info).results() };
|
||||||
|
|
||||||
|
if results.len() > index {
|
||||||
|
results[index] = res;
|
||||||
|
}
|
||||||
|
|
||||||
if res != VK_SUCCESS {
|
if res != VK_SUCCESS {
|
||||||
write_log!(format!("queue present failed: {:?}", res));
|
write_log!(format!("queue present failed: {:?}", res));
|
||||||
|
@ -505,5 +543,13 @@ pub(crate) extern "system" fn present_queue(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
write_log!("finish present queue");
|
||||||
|
|
||||||
|
match unsafe { (*present_info).results() }
|
||||||
|
.iter()
|
||||||
|
.find(|&&result| result != VK_SUCCESS)
|
||||||
|
{
|
||||||
|
Some(&error) => error,
|
||||||
|
None => VK_SUCCESS,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue