Browse Source

Start working on swapchains

main
Jens Pitkänen 4 months ago
parent
commit
a5dd86a50a
1 changed files with 57 additions and 16 deletions
  1. +57
    -16
      src/xr_main.rs

+ 57
- 16
src/xr_main.rs View File

@ -211,6 +211,7 @@ fn xr_main(xr_instance: &Instance, vk_entry: &ash::Entry) -> Result<(), Error> {
let view_configuration_views = xr_instance
.enumerate_view_configuration_views(system, ViewConfigurationType::PRIMARY_STEREO)?;
// TODO: Create the actions?
// Actions (definitely needed, possibly after session creation):
// - xrCreateActionSet
// - xrCreateAction
@ -227,6 +228,12 @@ fn xr_main(xr_instance: &Instance, vk_entry: &ash::Entry) -> Result<(), Error> {
unsafe { xr_instance.create_session::<Vulkan>(system, &info) }?;
let _ = session.set_name("Viewless OpenXR Session");
struct ViewSwapchains {
color_swapchain: Swapchain<Vulkan>,
color_images: Vec<vk::Image>,
depth_swapchain: Swapchain<Vulkan>,
depth_images: Vec<vk::Image>,
}
let formats = session.enumerate_swapchain_formats()?;
let color_format = formats
.first()
@ -251,9 +258,9 @@ fn xr_main(xr_instance: &Instance, vk_entry: &ash::Entry) -> Result<(), Error> {
depth_format,
view
);
let swapchain_create_info = SwapchainCreateInfo {
let color_swapchain_create_info = SwapchainCreateInfo {
create_flags: SwapchainCreateFlags::EMPTY,
usage_flags: SwapchainUsageFlags::COLOR_ATTACHMENT,
usage_flags: SwapchainUsageFlags::COLOR_ATTACHMENT | SwapchainUsageFlags::TRANSFER_SRC,
format: color_format.as_raw() as u32,
sample_count: view.recommended_swapchain_sample_count,
width: view.recommended_image_rect_width,
@ -265,21 +272,35 @@ fn xr_main(xr_instance: &Instance, vk_entry: &ash::Entry) -> Result<(), Error> {
let depth_swapchain_create_info = SwapchainCreateInfo {
usage_flags: SwapchainUsageFlags::DEPTH_STENCIL_ATTACHMENT,
format: depth_format.as_raw() as u32,
..swapchain_create_info
..color_swapchain_create_info
};
log::trace!("Creating a swapchain for the color buffer.");
let mut swapchain = session.create_swapchain(&swapchain_create_info)?;
let _ = swapchain.set_name("Viewless/OpenXR Color Swapchain");
let mut color_swapchain = session.create_swapchain(&color_swapchain_create_info)?;
let _ = color_swapchain.set_name("Viewless/OpenXR Color Swapchain");
let color_images = color_swapchain
.enumerate_images()?
.into_iter()
.map(|image| vk::Image::from_raw(image))
.collect();
log::trace!("Creating a swapchain for the depth buffer.");
let mut depth_swapchain = session.create_swapchain(&depth_swapchain_create_info)?;
let _ = depth_swapchain.set_name("Viewless/OpenXR Depth Swapchain");
Ok((swapchain, depth_swapchain))
let depth_images = depth_swapchain
.enumerate_images()?
.into_iter()
.map(|image| vk::Image::from_raw(image))
.collect();
Ok(ViewSwapchains {
color_swapchain,
color_images,
depth_swapchain,
depth_images,
})
};
let _swapchains = view_configuration_views
let mut swapchains = view_configuration_views
.iter()
.map(create_swapchain)
.collect::<Result<Vec<_>, Error>>()?;
.collect::<Result<Vec<ViewSwapchains>, Error>>()?;
// Now the actual setup.
log::trace!("Setting up reference spaces and actions.");
@ -384,19 +405,39 @@ fn xr_main(xr_instance: &Instance, vk_entry: &ash::Entry) -> Result<(), Error> {
// TODO: User-initiated shutdown
// - xrRequestExitSession
}
let _ = session.request_exit(); // Just for testing
log::trace!("xrBeginFrame");
frame_stream.begin()?;
if frame_state.should_render {
// - xrAcquireSwapchainImage
// - xrWaitSwapchainImage
// TODO: game_render()
// - xrLocateViews
// - xrLocateSpace
// - vkSendStuffToBeRendered
// - xrReleaseSwapchainImage
for ViewSwapchains {
color_swapchain,
color_images,
depth_swapchain,
depth_images,
} in &mut swapchains
{
log::trace!("color: acquire");
let color_image_index = color_swapchain.acquire_image()? as usize;
color_swapchain.wait_image(openxr::Duration::INFINITE)?;
log::trace!("depth: acquire");
let depth_image_index = depth_swapchain.acquire_image()? as usize;
depth_swapchain.wait_image(openxr::Duration::INFINITE)?;
let _color_image = &color_images[color_image_index];
let _depth_image = &depth_images[depth_image_index];
// TODO: game_render()
// - xrLocateViews
// - xrLocateSpace
// - vkSendStuffToBeRendered
log::trace!("color: release");
color_swapchain.release_image()?;
log::trace!("depth: release");
depth_swapchain.release_image()?;
}
}
log::trace!("xrEndFrame");
frame_stream.end(
frame_state.predicted_display_time,
EnvironmentBlendMode::OPAQUE,


Loading…
Cancel
Save