More testing
This commit is contained in:
parent
2c8a979b1e
commit
9fd1275ce3
6 changed files with 115 additions and 55 deletions
|
@ -11,7 +11,8 @@ crate-type = ["cdylib"]
|
|||
[dependencies]
|
||||
# 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" }
|
||||
rfactor_sm_reader = { git = "https://gavania.de/hodasemi/rfactor_sm_reader.git" }
|
||||
|
||||
anyhow = { version = "1.0.68", features = ["backtrace"] }
|
||||
rfactor_sm_reader = { path = "../rfactor_sm_reader" }
|
||||
cgmath = "0.18.0"
|
||||
paste = "1.0.11"
|
||||
|
|
|
@ -67,4 +67,5 @@ create_functions_enum!(
|
|||
[QueueSubmit, submit_queue],
|
||||
[GetDeviceQueue, get_device_queue],
|
||||
[AcquireNextImageKHR, acquire_next_image],
|
||||
[QueuePresentKHR, present_queue],
|
||||
);
|
||||
|
|
97
src/lib.rs
97
src/lib.rs
|
@ -24,6 +24,8 @@ const LOG_FILE: &'static str = "/home/michael/rf2_vk_hud.log";
|
|||
static mut OVERLAY: Overlay = Overlay::new();
|
||||
static mut QUEUE_SUBMIT: PFN_vkQueueSubmit =
|
||||
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]
|
||||
#[allow(non_snake_case)]
|
||||
|
@ -237,7 +239,15 @@ pub extern "system" fn create_device(
|
|||
write_log("failed querying vkQueueSubmit");
|
||||
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) {
|
||||
|
@ -328,24 +338,30 @@ pub extern "system" fn submit_queue(
|
|||
submits: *const VkSubmitInfo,
|
||||
fence: VkFence,
|
||||
) -> VkResult {
|
||||
write_log(" ================== vulkan layer submit queue ==================");
|
||||
|
||||
unsafe {
|
||||
let input_submit_info = slice::from_raw_parts(submits, submit_count as usize);
|
||||
let overlay_submit = match OVERLAY.render() {
|
||||
Ok(submit) => submit,
|
||||
let command_buffers = slice::from_raw_parts(
|
||||
(*submits).pCommandBuffers,
|
||||
(*submits).commandBufferCount as usize,
|
||||
);
|
||||
|
||||
let cb = match OVERLAY.render() {
|
||||
Ok(cb) => cb,
|
||||
Err(err) => {
|
||||
write_log(format!("overlay rendering failed: {:?}", err));
|
||||
return VK_ERROR_DEVICE_LOST;
|
||||
}
|
||||
};
|
||||
|
||||
let complete_submits = [input_submit_info, &[overlay_submit]].concat();
|
||||
let cb = [command_buffers, &[cb]].concat();
|
||||
|
||||
QUEUE_SUBMIT(
|
||||
queue,
|
||||
complete_submits.len() as u32,
|
||||
complete_submits.as_ptr(),
|
||||
fence,
|
||||
)
|
||||
let mut_ptr = submits as *mut VkSubmitInfo;
|
||||
|
||||
(*mut_ptr).commandBufferCount = cb.len() as u32;
|
||||
(*mut_ptr).pCommandBuffers = cb.as_ptr();
|
||||
|
||||
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);
|
||||
write_log(format!("new queue: {:?}", unsafe { *p_queue }));
|
||||
|
||||
unsafe {
|
||||
if !OVERLAY.has_queue() {
|
||||
|
@ -386,9 +403,63 @@ pub extern "system" fn acquire_next_image(
|
|||
timeout: u64,
|
||||
semaphore: VkSemaphore,
|
||||
fence: VkFence,
|
||||
pImageIndex: *mut u32,
|
||||
image_index: *mut u32,
|
||||
) -> 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) {
|
||||
|
|
|
@ -59,8 +59,14 @@ impl Overlay {
|
|||
self.queue.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
pub fn swapchain(&self) -> &Arc<Swapchain> {
|
||||
self.rendering.as_ref().unwrap().swapchain()
|
||||
pub fn swapchain(&self, swapchain: VkSwapchainKHR) -> Option<&Arc<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<()> {
|
||||
|
@ -79,17 +85,17 @@ impl Overlay {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render(&mut self) -> Result<VkSubmitInfo> {
|
||||
pub fn render(&mut self) -> Result<VkCommandBuffer> {
|
||||
if self.rfactor_data.is_none() {
|
||||
self.rfactor_data = RFactorData::new(
|
||||
self.device(),
|
||||
self.rendering
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.single_color_pipeline()
|
||||
.descriptor_layout(),
|
||||
)
|
||||
.ok();
|
||||
// self.rfactor_data = RFactorData::new(
|
||||
// self.device(),
|
||||
// self.rendering
|
||||
// .as_mut()
|
||||
// .unwrap()
|
||||
// .single_color_pipeline()
|
||||
// .descriptor_layout(),
|
||||
// )
|
||||
// .ok();
|
||||
}
|
||||
|
||||
// check twice for rfactor data, because of borrowing rules
|
||||
|
@ -102,13 +108,8 @@ impl Overlay {
|
|||
None => Vec::new(),
|
||||
};
|
||||
|
||||
let device = self.device();
|
||||
let queue = self.queue();
|
||||
let swapchain = self.swapchain().clone();
|
||||
let swapchain = self.rendering.as_ref().unwrap().swapchain().clone();
|
||||
|
||||
self.rendering
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.render(device, queue, swapchain, &objects)
|
||||
self.rendering.as_mut().unwrap().render(swapchain, &objects)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,11 +7,7 @@ use super::rendering::PositionOnlyVertex;
|
|||
|
||||
pub struct SingleColorPipeline {
|
||||
pipeline: Arc<Pipeline>,
|
||||
pipeline_layout: Arc<PipelineLayout>,
|
||||
descriptor_layout: Arc<DescriptorSetLayout>,
|
||||
|
||||
vertex_shader: Arc<ShaderModule>,
|
||||
fragment_shader: Arc<ShaderModule>,
|
||||
}
|
||||
|
||||
impl SingleColorPipeline {
|
||||
|
@ -67,11 +63,8 @@ impl SingleColorPipeline {
|
|||
.build(device, &pipeline_layout, &renderpass, 0)?;
|
||||
|
||||
Ok(Self {
|
||||
vertex_shader,
|
||||
fragment_shader,
|
||||
descriptor_layout,
|
||||
pipeline,
|
||||
pipeline_layout,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ pub struct Rendering {
|
|||
swapchain: Arc<Swapchain>,
|
||||
pipeline: SingleColorPipeline,
|
||||
render_target: RenderTarget,
|
||||
submit_info: SubmitInfo,
|
||||
command_buffer: Arc<CommandBuffer>,
|
||||
}
|
||||
|
||||
impl Rendering {
|
||||
|
@ -89,9 +89,9 @@ impl Rendering {
|
|||
|
||||
Ok(Self {
|
||||
swapchain,
|
||||
pipeline: SingleColorPipeline::new(device, render_target.render_pass())?,
|
||||
pipeline: SingleColorPipeline::new(device.clone(), render_target.render_pass())?,
|
||||
render_target,
|
||||
submit_info: SubmitInfo::default(),
|
||||
command_buffer: CommandBuffer::new_primary().build(device, queue)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -105,11 +105,9 @@ impl Rendering {
|
|||
|
||||
pub fn render(
|
||||
&mut self,
|
||||
device: Arc<Device>,
|
||||
queue: Arc<Mutex<Queue>>,
|
||||
swapchain: Arc<Swapchain>,
|
||||
objects: &[&dyn RenderObject],
|
||||
) -> Result<VkSubmitInfo> {
|
||||
) -> Result<VkCommandBuffer> {
|
||||
let image_index = self.swapchain.current_index();
|
||||
|
||||
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(
|
||||
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
|
||||
let mut recorder = self.command_buffer.begin(VkCommandBufferBeginInfo::new(
|
||||
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT
|
||||
| VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
|
||||
))?;
|
||||
|
||||
self.render_target
|
||||
|
@ -156,10 +153,6 @@ impl Rendering {
|
|||
self.render_target.end(&recorder);
|
||||
}
|
||||
|
||||
self.submit_info = SubmitInfo::default()
|
||||
.add_wait_stage(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT)
|
||||
.add_command_buffer(command_buffer);
|
||||
|
||||
Ok(self.submit_info.as_vk_submit())
|
||||
Ok(self.command_buffer.vk_handle())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue