mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-26 03:46:49 -08:00
Use multi-layer swapchain for stream
This commit is contained in:
1 parent
b87345a180
commit
198372bc82
7 files changed
+172
-184
No files matched your search
@@ -543,7 +543,6 @@ void application::initialize_vulkan()
|
||||
|
||||
vk::PhysicalDeviceFeatures device_features{
|
||||
.shaderClipDistance = true,
|
||||
// .samplerAnisotropy = true,
|
||||
};
|
||||
|
||||
vk::StructureChain device_create_info{
|
||||
|
||||
+49
-71
@@ -485,7 +485,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
if (state_ == state::stalled)
|
||||
application::pop_scene();
|
||||
|
||||
assert(not swapchains.empty());
|
||||
assert(swapchain);
|
||||
for (auto & i: decoders)
|
||||
{
|
||||
if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline)
|
||||
@@ -643,14 +643,9 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
session.begin_frame();
|
||||
|
||||
int image_index = swapchain.acquire();
|
||||
swapchain.wait();
|
||||
std::array<int, view_count> image_indices;
|
||||
for (size_t swapchain_index = 0; swapchain_index < view_count; swapchain_index++)
|
||||
{
|
||||
int image_index = swapchains[swapchain_index].acquire();
|
||||
swapchains[swapchain_index].wait();
|
||||
|
||||
image_indices[swapchain_index] = image_index;
|
||||
}
|
||||
|
||||
command_buffer.reset();
|
||||
|
||||
@@ -732,7 +727,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
.framebuffer = *out.frame_buffer,
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = out.size,
|
||||
.extent = decoder_out_size,
|
||||
},
|
||||
.clearValueCount = 0,
|
||||
},
|
||||
@@ -762,10 +757,10 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
.maxDepth = 1,
|
||||
};
|
||||
|
||||
x0 = std::clamp<int>(x0, 0, out.size.width);
|
||||
x1 = std::clamp<int>(x1, 0, out.size.width);
|
||||
y0 = std::clamp<int>(y0, 0, out.size.height);
|
||||
y1 = std::clamp<int>(y1, 0, out.size.height);
|
||||
x0 = std::clamp<int>(x0, 0, decoder_out_size.width);
|
||||
x1 = std::clamp<int>(x1, 0, decoder_out_size.width);
|
||||
y0 = std::clamp<int>(y0, 0, decoder_out_size.height);
|
||||
y1 = std::clamp<int>(y1, 0, decoder_out_size.height);
|
||||
|
||||
vk::Rect2D scissor{
|
||||
.offset = {.x = x0, .y = y0},
|
||||
@@ -784,18 +779,14 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
command_buffer.draw(3, 1, 0, 0);
|
||||
}
|
||||
command_buffer.endRenderPass();
|
||||
x_offset += out.size.width;
|
||||
x_offset += decoder_out_size.width;
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
reprojector->set_foveation(foveation);
|
||||
|
||||
// Unfoveate the image to the real pose
|
||||
for (size_t view = 0; view < view_count; view++)
|
||||
{
|
||||
size_t destination_index = view * swapchains[0].images().size() + image_indices[view];
|
||||
reprojector->reproject(command_buffer, view, destination_index);
|
||||
}
|
||||
reprojector->reproject(command_buffer, image_index);
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
|
||||
@@ -827,25 +818,25 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
else
|
||||
session.disable_passthrough();
|
||||
|
||||
for (size_t swapchain_index = 0; swapchain_index < view_count; swapchain_index++)
|
||||
swapchain.release();
|
||||
for (uint32_t view = 0; view < view_count; view++)
|
||||
{
|
||||
swapchains[swapchain_index].release();
|
||||
|
||||
layer_view[swapchain_index] =
|
||||
layer_view[view] =
|
||||
{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW,
|
||||
.pose = pose[swapchain_index],
|
||||
.fov = fov[swapchain_index],
|
||||
.pose = pose[view],
|
||||
.fov = fov[view],
|
||||
|
||||
.subImage = {
|
||||
.swapchain = swapchains[swapchain_index],
|
||||
.swapchain = swapchain,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = {
|
||||
swapchains[swapchain_index].width(),
|
||||
swapchains[swapchain_index].height(),
|
||||
swapchain.width(),
|
||||
swapchain.height(),
|
||||
},
|
||||
},
|
||||
.imageArrayIndex = view,
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -999,20 +990,17 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
}
|
||||
|
||||
// Create outputs for the decoders
|
||||
vk::Extent3D decoder_out_size{video_width, video_height, 1};
|
||||
for (size_t i = 0; i < view_count; i++)
|
||||
decoder_out_size = vk::Extent2D{video_width, video_height};
|
||||
{
|
||||
decoder_output[i].format = vk::Format::eA8B8G8R8SrgbPack32;
|
||||
decoder_output[i].size.width = video_width;
|
||||
decoder_output[i].size.height = video_height;
|
||||
decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32;
|
||||
|
||||
vk::ImageCreateInfo image_info{
|
||||
.flags = vk::ImageCreateFlags{},
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.extent = decoder_out_size,
|
||||
.extent = {video_width, video_height, 1},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 1,
|
||||
.arrayLayers = view_count,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
|
||||
@@ -1024,10 +1012,10 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
};
|
||||
|
||||
decoder_output[i].image = image_allocation{device, image_info, alloc_info};
|
||||
decoder_out_image = image_allocation{device, image_info, alloc_info};
|
||||
|
||||
vk::ImageViewCreateInfo image_view_info{
|
||||
.image = vk::Image{decoder_output[i].image},
|
||||
.image = vk::Image{decoder_out_image},
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {},
|
||||
@@ -1040,18 +1028,24 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
},
|
||||
};
|
||||
|
||||
decoder_output[i].image_view = vk::raii::ImageView(device, image_view_info);
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
auto & output = decoder_output[view];
|
||||
|
||||
decoder_output[i].frame_buffer = vk::raii::Framebuffer(
|
||||
device,
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *blit_render_pass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*decoder_output[i].image_view,
|
||||
.width = decoder_out_size.width,
|
||||
.height = decoder_out_size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
image_view_info.subresourceRange.baseArrayLayer = view;
|
||||
output.image_view = vk::raii::ImageView(device, image_view_info);
|
||||
|
||||
output.frame_buffer = vk::raii::Framebuffer(
|
||||
device,
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *blit_render_pass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*output.image_view,
|
||||
.width = decoder_out_size.width,
|
||||
.height = decoder_out_size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1083,7 +1077,6 @@ void scenes::stream::setup_reprojection_swapchain()
|
||||
std::unique_lock lock(decoder_mutex);
|
||||
device.waitIdle();
|
||||
|
||||
swapchains.clear();
|
||||
const uint32_t video_width = video_stream_description->width / view_count;
|
||||
const uint32_t video_height = video_stream_description->height;
|
||||
const uint32_t swapchain_width = video_width / video_stream_description->foveation[0].x.scale;
|
||||
@@ -1091,36 +1084,21 @@ void scenes::stream::setup_reprojection_swapchain()
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
|
||||
swapchains.reserve(views.size());
|
||||
swapchain = xr::swapchain(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)
|
||||
{
|
||||
XrExtent2Di extent{
|
||||
.width = int32_t(swapchain_width),
|
||||
.height = int32_t(swapchain_height),
|
||||
};
|
||||
swapchains.emplace_back(session, device, swapchain_format, extent.width, extent.height);
|
||||
|
||||
spdlog::info("Created stream swapchain {}: {}x{}", swapchains.size(), extent.width, extent.height);
|
||||
if (extent.width > view.maxImageRectWidth or extent.height > view.maxImageRectHeight)
|
||||
if (swapchain.width() > view.maxImageRectWidth or swapchain.height() > view.maxImageRectHeight)
|
||||
spdlog::warn("Swapchain size larger than maximum {}x{}", view.maxImageRectWidth, view.maxImageRectHeight);
|
||||
}
|
||||
|
||||
spdlog::info("Initializing reprojector");
|
||||
vk::Extent2D extent = {(uint32_t)swapchains[0].width(), (uint32_t)swapchains[0].height()};
|
||||
vk::Extent2D extent = {(uint32_t)swapchain.width(), (uint32_t)swapchain.height()};
|
||||
std::vector<vk::Image> swapchain_images;
|
||||
for (auto & swapchain: swapchains)
|
||||
{
|
||||
for (auto & image: swapchain.images())
|
||||
swapchain_images.push_back(image.image);
|
||||
}
|
||||
for (auto & image: swapchain.images())
|
||||
swapchain_images.push_back(image.image);
|
||||
|
||||
std::vector<vk::Image> images;
|
||||
for (renderpass_output & i: decoder_output)
|
||||
{
|
||||
images.push_back(i.image);
|
||||
}
|
||||
|
||||
reprojector.emplace(device, physical_device, images, swapchain_images, extent, swapchains[0].format(), *video_stream_description);
|
||||
reprojector.emplace(device, physical_device, decoder_out_image, 2, swapchain_images, extent, swapchain.format(), *video_stream_description);
|
||||
}
|
||||
|
||||
scene::meta & scenes::stream::get_meta_scene()
|
||||
|
||||
+11
-11
@@ -72,15 +72,6 @@ private:
|
||||
std::mutex frames_mutex;
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> common_frame(XrTime display_time);
|
||||
|
||||
struct renderpass_output
|
||||
{
|
||||
vk::Extent2D size;
|
||||
vk::Format format;
|
||||
image_allocation image;
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
vk::raii::Framebuffer frame_buffer = nullptr;
|
||||
};
|
||||
|
||||
std::unique_ptr<wivrn_session> network_session;
|
||||
std::atomic<bool> exiting = false;
|
||||
std::thread network_thread;
|
||||
@@ -99,7 +90,16 @@ private:
|
||||
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
|
||||
vk::raii::RenderPass blit_render_pass = nullptr;
|
||||
|
||||
std::array<renderpass_output, view_count> decoder_output{};
|
||||
vk::Extent2D decoder_out_size;
|
||||
vk::Format decoder_out_format;
|
||||
image_allocation decoder_out_image;
|
||||
|
||||
struct renderpass_output
|
||||
{
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
vk::raii::Framebuffer frame_buffer = nullptr;
|
||||
};
|
||||
std::array<renderpass_output, view_count> decoder_output;
|
||||
|
||||
std::optional<stream_reprojection> reprojector;
|
||||
|
||||
@@ -119,7 +119,7 @@ private:
|
||||
|
||||
state state_ = state::initializing;
|
||||
|
||||
std::vector<xr::swapchain> swapchains;
|
||||
xr::swapchain swapchain;
|
||||
xr::swapchain swapchain_imgui;
|
||||
vk::Format swapchain_format;
|
||||
|
||||
|
||||
@@ -31,7 +31,9 @@
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
struct stream_reprojection::uniform
|
||||
namespace
|
||||
{
|
||||
struct uniform
|
||||
{
|
||||
// Foveation parameters
|
||||
alignas(8) glm::vec2 a;
|
||||
@@ -39,18 +41,21 @@ struct stream_reprojection::uniform
|
||||
alignas(8) glm::vec2 lambda;
|
||||
alignas(8) glm::vec2 xc;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
const int nb_reprojection_vertices = 128;
|
||||
|
||||
stream_reprojection::stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
std::vector<vk::Image> input_images_,
|
||||
vk::Image input_image_,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D extent,
|
||||
vk::Format format,
|
||||
const wivrn::to_headset::video_stream_description & description) :
|
||||
input_images(std::move(input_images_)),
|
||||
view_count(view_count),
|
||||
input_image(input_image_),
|
||||
output_images(std::move(output_images_)),
|
||||
extent(extent)
|
||||
{
|
||||
@@ -81,11 +86,11 @@ stream_reprojection::stream_reprojection(
|
||||
|
||||
sampler = vk::raii::Sampler(device, sampler_info);
|
||||
|
||||
size_t uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1;
|
||||
uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1;
|
||||
uniform_size = uniform_size - uniform_size % properties.limits.minUniformBufferOffsetAlignment;
|
||||
|
||||
vk::BufferCreateInfo create_info{
|
||||
.size = uniform_size * input_images.size(),
|
||||
.size = uniform_size * view_count,
|
||||
.usage = vk::BufferUsageFlagBits::eUniformBuffer,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
};
|
||||
@@ -95,9 +100,6 @@ stream_reprojection::stream_reprojection(
|
||||
};
|
||||
|
||||
buffer = buffer_allocation(device, create_info, alloc_info);
|
||||
void * data = buffer.map();
|
||||
for (size_t i = 0; i < input_images.size(); i++)
|
||||
ubo.push_back(reinterpret_cast<uniform *>(reinterpret_cast<uintptr_t>(data) + i * uniform_size));
|
||||
|
||||
// Create VkDescriptorSetLayout
|
||||
std::array layout_binding{
|
||||
@@ -123,30 +125,28 @@ stream_reprojection::stream_reprojection(
|
||||
std::array pool_size{
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = (uint32_t)input_images.size(),
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
},
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eUniformBuffer,
|
||||
.descriptorCount = (uint32_t)input_images.size(),
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
},
|
||||
};
|
||||
|
||||
vk::DescriptorPoolCreateInfo pool_info;
|
||||
pool_info.flags = vk::DescriptorPoolCreateFlags{};
|
||||
pool_info.maxSets = input_images.size();
|
||||
pool_info.setPoolSizes(pool_size);
|
||||
vk::DescriptorPoolCreateInfo pool_info{
|
||||
.maxSets = view_count,
|
||||
.poolSizeCount = pool_size.size(),
|
||||
.pPoolSizes = pool_size.data(),
|
||||
};
|
||||
|
||||
descriptor_pool = vk::raii::DescriptorPool(device, pool_info);
|
||||
|
||||
// Create image views and descriptor sets
|
||||
input_image_views.reserve(input_images.size());
|
||||
descriptor_sets.reserve(input_images.size());
|
||||
VkDeviceSize offset = 0;
|
||||
for (vk::Image image: input_images)
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.image = input_image,
|
||||
.viewType = vk::ImageViewType::e2DArray,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
@@ -158,12 +158,12 @@ stream_reprojection::stream_reprojection(
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.baseArrayLayer = view,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
input_image_views.emplace_back(device, iv_info);
|
||||
vk::ImageView input_image_view = *input_image_views.emplace_back(device, iv_info);
|
||||
|
||||
vk::DescriptorSetAllocateInfo ds_info{
|
||||
.descriptorPool = *descriptor_pool,
|
||||
@@ -171,24 +171,23 @@ stream_reprojection::stream_reprojection(
|
||||
.pSetLayouts = &*descriptor_set_layout,
|
||||
};
|
||||
|
||||
descriptor_sets.push_back(device.allocateDescriptorSets(ds_info)[0].release());
|
||||
auto descriptor_set = descriptor_sets.emplace_back(device.allocateDescriptorSets(ds_info)[0].release());
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.sampler = *sampler,
|
||||
.imageView = *input_image_views.back(),
|
||||
.imageView = input_image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
vk::DescriptorBufferInfo buffer_info{
|
||||
.buffer = buffer,
|
||||
.offset = offset,
|
||||
.offset = uniform_size * view,
|
||||
.range = sizeof(uniform),
|
||||
};
|
||||
offset += uniform_size;
|
||||
|
||||
std::array write{
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_sets.back(),
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
@@ -196,7 +195,7 @@ stream_reprojection::stream_reprojection(
|
||||
.pImageInfo = &image_info,
|
||||
},
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_sets.back(),
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 1,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
@@ -228,11 +227,16 @@ stream_reprojection::stream_reprojection(
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::RenderPassCreateInfo renderpass_info;
|
||||
renderpass_info.setAttachments(attachment);
|
||||
renderpass_info.setSubpasses(subpass);
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info);
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||
@@ -330,75 +334,71 @@ stream_reprojection::stream_reprojection(
|
||||
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
|
||||
// Create image views and framebuffers
|
||||
output_image_views.reserve(output_images.size());
|
||||
framebuffers.reserve(output_images.size());
|
||||
output_image_views.reserve(output_images.size() * view_count);
|
||||
framebuffers.reserve(output_images.size() * view_count);
|
||||
for (vk::Image image: output_images)
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = format,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
.g = vk::ComponentSwizzle::eIdentity,
|
||||
.b = vk::ComponentSwizzle::eIdentity,
|
||||
.a = vk::ComponentSwizzle::eIdentity,
|
||||
},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = image,
|
||||
.viewType = vk::ImageViewType::e2DArray,
|
||||
.format = format,
|
||||
.components = {
|
||||
.r = vk::ComponentSwizzle::eIdentity,
|
||||
.g = vk::ComponentSwizzle::eIdentity,
|
||||
.b = vk::ComponentSwizzle::eIdentity,
|
||||
.a = vk::ComponentSwizzle::eIdentity,
|
||||
},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = view,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
output_image_views.emplace_back(device, iv_info);
|
||||
output_image_views.emplace_back(device, iv_info);
|
||||
|
||||
vk::FramebufferCreateInfo fb_create_info{
|
||||
.renderPass = *renderpass,
|
||||
.width = extent.width,
|
||||
.height = extent.height,
|
||||
.layers = 1,
|
||||
};
|
||||
fb_create_info.setAttachments(*output_image_views.back());
|
||||
vk::FramebufferCreateInfo fb_create_info{
|
||||
.renderPass = *renderpass,
|
||||
.width = extent.width,
|
||||
.height = extent.height,
|
||||
.layers = 1,
|
||||
};
|
||||
fb_create_info.setAttachments(*output_image_views.back());
|
||||
|
||||
framebuffers.emplace_back(device, fb_create_info);
|
||||
framebuffers.emplace_back(device, fb_create_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int source, int destination)
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, int destination)
|
||||
{
|
||||
if (source < 0 || source >= (int)input_images.size())
|
||||
throw std::runtime_error("Invalid source image index");
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
|
||||
if (foveation_parameters[source].x.scale < 1)
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
ubo[source]->a.x = foveation_parameters[source].x.a;
|
||||
ubo[source]->b.x = foveation_parameters[source].x.b;
|
||||
ubo[source]->lambda.x = foveation_parameters[source].x.scale / foveation_parameters[source].x.a;
|
||||
ubo[source]->xc.x = foveation_parameters[source].x.center;
|
||||
}
|
||||
auto & ubo = *reinterpret_cast<uniform *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * uniform_size);
|
||||
if (foveation_parameters[view].x.scale < 1)
|
||||
{
|
||||
ubo.a.x = foveation_parameters[view].x.a;
|
||||
ubo.b.x = foveation_parameters[view].x.b;
|
||||
ubo.lambda.x = foveation_parameters[view].x.scale / foveation_parameters[view].x.a;
|
||||
ubo.xc.x = foveation_parameters[view].x.center;
|
||||
}
|
||||
|
||||
if (foveation_parameters[source].y.scale < 1)
|
||||
{
|
||||
ubo[source]->a.y = foveation_parameters[source].y.a;
|
||||
ubo[source]->b.y = foveation_parameters[source].y.b;
|
||||
ubo[source]->lambda.y = foveation_parameters[source].y.scale / foveation_parameters[source].y.a;
|
||||
ubo[source]->xc.y = foveation_parameters[source].y.center;
|
||||
if (foveation_parameters[view].y.scale < 1)
|
||||
{
|
||||
ubo.a.y = foveation_parameters[view].y.a;
|
||||
ubo.b.y = foveation_parameters[view].y.b;
|
||||
ubo.lambda.y = foveation_parameters[view].y.scale / foveation_parameters[view].y.a;
|
||||
ubo.xc.y = foveation_parameters[view].y.center;
|
||||
}
|
||||
}
|
||||
|
||||
vk::RenderPassBeginInfo begin_info{
|
||||
.renderPass = *renderpass,
|
||||
.framebuffer = *framebuffers[destination],
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = extent,
|
||||
},
|
||||
};
|
||||
|
||||
command_buffer.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eTopOfPipe,
|
||||
vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
@@ -414,15 +414,27 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer, in
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = 1,
|
||||
.layerCount = view_count,
|
||||
},
|
||||
});
|
||||
|
||||
command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline);
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[source], {});
|
||||
command_buffer.draw(6 * nb_reprojection_vertices * nb_reprojection_vertices, 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
vk::RenderPassBeginInfo begin_info{
|
||||
.renderPass = *renderpass,
|
||||
.framebuffer = *framebuffers[destination * view_count + view],
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = extent,
|
||||
},
|
||||
};
|
||||
|
||||
command_buffer.beginRenderPass(begin_info, vk::SubpassContents::eInline);
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *layout, 0, descriptor_sets[view], {});
|
||||
command_buffer.draw(6 * nb_reprojection_vertices * nb_reprojection_vertices, 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
}
|
||||
}
|
||||
|
||||
void stream_reprojection::set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation)
|
||||
|
||||
@@ -26,11 +26,10 @@
|
||||
|
||||
class stream_reprojection
|
||||
{
|
||||
struct uniform;
|
||||
|
||||
const uint32_t view_count;
|
||||
// Uniform buffer
|
||||
buffer_allocation buffer;
|
||||
std::vector<uniform *> ubo;
|
||||
size_t uniform_size;
|
||||
|
||||
// Graphic pipeline
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
@@ -39,9 +38,9 @@ class stream_reprojection
|
||||
vk::raii::RenderPass renderpass = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
|
||||
// Source images
|
||||
// Source image
|
||||
vk::raii::Sampler sampler = nullptr;
|
||||
std::vector<vk::Image> input_images;
|
||||
vk::Image input_image;
|
||||
std::vector<vk::raii::ImageView> input_image_views;
|
||||
std::vector<vk::DescriptorSet> descriptor_sets;
|
||||
|
||||
@@ -58,7 +57,8 @@ public:
|
||||
stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
std::vector<vk::Image> input_images,
|
||||
vk::Image input_image,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images,
|
||||
vk::Extent2D extent,
|
||||
vk::Format format,
|
||||
@@ -68,7 +68,6 @@ public:
|
||||
|
||||
void reproject(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
int source,
|
||||
int destination);
|
||||
|
||||
void set_foveation(std::array<wivrn::to_headset::foveation_parameter, 2> foveation);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#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)
|
||||
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)
|
||||
{
|
||||
assert(sample_count == 1);
|
||||
|
||||
@@ -51,7 +51,7 @@ xr::swapchain::swapchain(xr::session & s, vk::raii::Device & device, vk::Format
|
||||
.width = (uint32_t)width,
|
||||
.height = (uint32_t)height,
|
||||
.faceCount = 1,
|
||||
.arraySize = 1,
|
||||
.arraySize = array_size,
|
||||
.mipCount = 1,
|
||||
};
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ private:
|
||||
|
||||
public:
|
||||
swapchain() = default;
|
||||
swapchain(session &, vk::raii::Device & device, vk::Format format, int32_t width, int32_t height, int sample_count = 1);
|
||||
swapchain(session &, vk::raii::Device & device, vk::Format format, int32_t width, int32_t height, int sample_count = 1, uint32_t array_size = 1);
|
||||
|
||||
int32_t width() const
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user