Add support for fragment density map
This commit is contained in:
@@ -761,6 +761,7 @@ void application::initialize_vulkan()
|
||||
vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME);
|
||||
@@ -1215,6 +1216,10 @@ void application::initialize()
|
||||
opt_extensions.push_back(XR_EXT_USER_PRESENCE_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_SWAPCHAIN_UPDATE_STATE_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_FOVEATION_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_FOVEATION_CONFIGURATION_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_FOVEATION_VULKAN_EXTENSION_NAME);
|
||||
|
||||
for (const auto & i: interaction_profiles)
|
||||
opt_extensions.insert(opt_extensions.end(), i.required_extensions.begin(), i.required_extensions.end());
|
||||
|
||||
+1
-1
@@ -277,7 +277,7 @@ xr::swapchain & scene::get_swapchain(vk::Format format, int32_t width, int32_t h
|
||||
.sample_count = sample_count,
|
||||
.array_size = array_size,
|
||||
.used = true,
|
||||
.swapchain = xr::swapchain(session, device, format, width, height, sample_count, array_size),
|
||||
.swapchain = xr::swapchain(instance, session, device, format, width, height, sample_count, array_size),
|
||||
};
|
||||
spdlog::info("Created swapchain");
|
||||
|
||||
|
||||
@@ -906,7 +906,7 @@ void scenes::lobby::on_focused()
|
||||
.z_index = constants::lobby::zindex_recenter_tip,
|
||||
}};
|
||||
|
||||
xr::swapchain swapchain_imgui(session, device, swapchain_format, 3000, 1300);
|
||||
xr::swapchain swapchain_imgui(instance, session, device, swapchain_format, 3000, 1300);
|
||||
|
||||
imgui_ctx.emplace(
|
||||
physical_device,
|
||||
|
||||
@@ -447,6 +447,7 @@ void scenes::stream::on_focused()
|
||||
};
|
||||
|
||||
xr::swapchain swapchain_imgui(
|
||||
instance,
|
||||
session,
|
||||
device,
|
||||
swapchain_format,
|
||||
@@ -1146,7 +1147,7 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
|
||||
swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
swapchain = xr::swapchain(instance, session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
spdlog::info("Created stream swapchain: {}x{}", swapchain.width(), swapchain.height());
|
||||
for (auto view: views)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "foveation_profile.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
|
||||
xr::foveation_profile::foveation_profile(instance & inst, session & s, XrFoveationLevelFB level, float verticalOffsetDegrees, bool dynamic) :
|
||||
handle(inst.get_proc<PFN_xrDestroyFoveationProfileFB>("xrDestroyFoveationProfileFB"))
|
||||
{
|
||||
auto create = inst.get_proc<PFN_xrCreateFoveationProfileFB>("xrCreateFoveationProfileFB");
|
||||
XrFoveationLevelProfileCreateInfoFB level_info{
|
||||
.type = XR_TYPE_FOVEATION_LEVEL_PROFILE_CREATE_INFO_FB,
|
||||
.level = level,
|
||||
.verticalOffset = verticalOffsetDegrees,
|
||||
.dynamic = dynamic ? XR_FOVEATION_DYNAMIC_LEVEL_ENABLED_FB : XR_FOVEATION_DYNAMIC_DISABLED_FB,
|
||||
};
|
||||
XrFoveationProfileCreateInfoFB info{
|
||||
.type = XR_TYPE_FOVEATION_PROFILE_CREATE_INFO_FB,
|
||||
.next = &level_info,
|
||||
};
|
||||
create(s, &info, &id);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/handle.h"
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
class session;
|
||||
class foveation_profile : public utils::handle<XrFoveationProfileFB>
|
||||
{
|
||||
public:
|
||||
foveation_profile(instance & inst, session & s, XrFoveationLevelFB, float verticalOffsetDegrees, bool dynamic);
|
||||
};
|
||||
} // namespace xr
|
||||
+53
-11
@@ -22,9 +22,24 @@
|
||||
#include "details/enumerate.h"
|
||||
#include "session.h"
|
||||
|
||||
xr::swapchain::swapchain(xr::session & s, vk::raii::Device & device, vk::Format format, int32_t width, int32_t height, int sample_count, uint32_t array_size)
|
||||
xr::swapchain::swapchain(
|
||||
xr::instance & inst,
|
||||
xr::session & s,
|
||||
vk::raii::Device & device,
|
||||
vk::Format format,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
int sample_count,
|
||||
uint32_t array_size,
|
||||
XrFoveationProfileFB foveated) :
|
||||
width_(width),
|
||||
height_(height),
|
||||
sample_count_(sample_count),
|
||||
format_(format)
|
||||
{
|
||||
assert(sample_count == 1);
|
||||
if (foveated)
|
||||
update = inst.get_proc<PFN_xrUpdateSwapchainFB>("xrUpdateSwapchainFB");
|
||||
|
||||
XrSwapchainUsageFlags usage_flags;
|
||||
|
||||
@@ -43,8 +58,14 @@ xr::swapchain::swapchain(xr::session & s, vk::raii::Device & device, vk::Format
|
||||
break;
|
||||
}
|
||||
|
||||
XrSwapchainCreateInfoFoveationFB foveation_info{
|
||||
.type = XR_TYPE_SWAPCHAIN_CREATE_INFO_FOVEATION_FB,
|
||||
.flags = XR_SWAPCHAIN_CREATE_FOVEATION_FRAGMENT_DENSITY_MAP_BIT_FB,
|
||||
};
|
||||
|
||||
XrSwapchainCreateInfo create_info{
|
||||
.type = XR_TYPE_SWAPCHAIN_CREATE_INFO,
|
||||
.next = foveated ? &foveation_info : nullptr,
|
||||
.createFlags = 0,
|
||||
.usageFlags = usage_flags,
|
||||
.format = static_cast<VkFormat>(format),
|
||||
@@ -56,19 +77,31 @@ xr::swapchain::swapchain(xr::session & s, vk::raii::Device & device, vk::Format
|
||||
.mipCount = 1,
|
||||
};
|
||||
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
sample_count_ = sample_count;
|
||||
format_ = format;
|
||||
|
||||
CHECK_XR(xrCreateSwapchain(s, &create_info, &id));
|
||||
|
||||
std::vector<XrSwapchainImageVulkanKHR> array =
|
||||
details::enumerate<XrSwapchainImageVulkanKHR>(xrEnumerateSwapchainImages, id);
|
||||
std::tuple<std::vector<XrSwapchainImageVulkanKHR>, std::vector<XrSwapchainImageFoveationVulkanFB>> array;
|
||||
auto & images = std::get<0>(array);
|
||||
auto & foveation = std::get<1>(array);
|
||||
if (foveated)
|
||||
{
|
||||
update_foveation(foveated);
|
||||
details::enumerate2(xrEnumerateSwapchainImages, array, id);
|
||||
assert(images.size() == foveation.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
details::enumerate(xrEnumerateSwapchainImages, images, id);
|
||||
}
|
||||
|
||||
images_.resize(array.size());
|
||||
for (uint32_t i = 0; i < array.size(); i++)
|
||||
images_[i].image = array[i].image;
|
||||
images_.resize(images.size());
|
||||
for (uint32_t i = 0; i < images.size(); i++)
|
||||
{
|
||||
images_[i].image = images[i].image;
|
||||
if (foveated)
|
||||
{
|
||||
images_[i].foveation = foveation[i].image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int xr::swapchain::acquire()
|
||||
@@ -106,3 +139,12 @@ void xr::swapchain::release()
|
||||
auto lock = application::get_queue().lock();
|
||||
CHECK_XR(xrReleaseSwapchainImage(id, &release_info));
|
||||
}
|
||||
|
||||
void xr::swapchain::update_foveation(XrFoveationProfileFB foveation)
|
||||
{
|
||||
XrSwapchainStateFoveationFB update_info{
|
||||
.type = XR_TYPE_SWAPCHAIN_STATE_FOVEATION_FB,
|
||||
.profile = foveation,
|
||||
};
|
||||
CHECK_XR(update(id, (XrSwapchainStateBaseHeaderFB *)&update_info));
|
||||
}
|
||||
|
||||
+15
-1
@@ -30,6 +30,7 @@
|
||||
|
||||
namespace xr
|
||||
{
|
||||
class instance;
|
||||
class session;
|
||||
|
||||
class swapchain : public utils::handle<XrSwapchain, xrDestroySwapchain>
|
||||
@@ -38,9 +39,11 @@ public:
|
||||
struct image
|
||||
{
|
||||
vk::Image image{};
|
||||
vk::Image foveation{};
|
||||
};
|
||||
|
||||
private:
|
||||
PFN_xrUpdateSwapchainFB update;
|
||||
int32_t width_;
|
||||
int32_t height_;
|
||||
int sample_count_;
|
||||
@@ -50,7 +53,16 @@ private:
|
||||
|
||||
public:
|
||||
swapchain() = default;
|
||||
swapchain(session &, vk::raii::Device & device, vk::Format format, int32_t width, int32_t height, int sample_count = 1, uint32_t array_size = 1);
|
||||
swapchain(
|
||||
instance &,
|
||||
session &,
|
||||
vk::raii::Device & device,
|
||||
vk::Format format,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
int sample_count = 1,
|
||||
uint32_t array_size = 1,
|
||||
XrFoveationProfileFB foveation = XR_NULL_HANDLE);
|
||||
|
||||
int32_t width() const
|
||||
{
|
||||
@@ -84,5 +96,7 @@ public:
|
||||
int acquire();
|
||||
bool wait(XrDuration timeout = XR_INFINITE_DURATION);
|
||||
void release();
|
||||
|
||||
void update_foveation(XrFoveationProfileFB foveation);
|
||||
};
|
||||
} // namespace xr
|
||||
|
||||
Reference in New Issue
Block a user