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