Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -0,0 +1,364 @@
|
||||
/*
|
||||
* 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 "blitter.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include <format>
|
||||
#include <ranges>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
static const uint32_t num_views = 2;
|
||||
|
||||
blitter::blitter(vk::raii::Device & device, size_t view) :
|
||||
device(device), view(view)
|
||||
{
|
||||
}
|
||||
|
||||
void blitter::reset(const to_headset::video_stream_description & desc)
|
||||
{
|
||||
using channels_t = to_headset::video_stream_description::channels_t;
|
||||
this->desc = desc;
|
||||
|
||||
current = {};
|
||||
target = image_allocation();
|
||||
image_view = nullptr;
|
||||
rp = nullptr;
|
||||
fb = nullptr;
|
||||
sampler = nullptr;
|
||||
pipelines.clear();
|
||||
passthrough_rgb = passthrough_a = -1;
|
||||
|
||||
auto w = desc.width / num_views;
|
||||
for (auto [i, item]: utils::enumerate(desc.items))
|
||||
{
|
||||
if (item.offset_x <= view * w and
|
||||
item.offset_y == 0 and
|
||||
item.offset_x + item.width * item.subsampling >= (view + 1) * w and
|
||||
item.height * item.subsampling >= desc.height)
|
||||
{
|
||||
spdlog::info("Stream {} is eligible for blit-less path on view {}", i, view);
|
||||
switch (item.channels)
|
||||
{
|
||||
case channels_t::colour:
|
||||
passthrough_rgb = i;
|
||||
break;
|
||||
case channels_t::alpha:
|
||||
passthrough_a = i;
|
||||
break;
|
||||
}
|
||||
const bool alpha = item.channels == to_headset::video_stream_description::channels_t::alpha;
|
||||
auto & r = alpha ? current.rect_a : current.rect_rgb;
|
||||
r = vk::Rect2D{
|
||||
.offset = {
|
||||
.x = int32_t(view * w) - item.offset_x,
|
||||
.y = 0,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (passthrough_rgb != -1 and passthrough_a != -1)
|
||||
return;
|
||||
|
||||
target = image_allocation(
|
||||
device,
|
||||
vk::ImageCreateInfo{
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = vk::Format::eB8G8R8A8Srgb,
|
||||
.extent = {
|
||||
.width = w,
|
||||
.height = desc.height,
|
||||
.depth = 1,
|
||||
},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 1,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
|
||||
},
|
||||
{
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
},
|
||||
std::format("blit image {}", view));
|
||||
|
||||
image_view = device.createImageView(vk::ImageViewCreateInfo{
|
||||
.image = vk::Image(target),
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = target.info().format,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = 1,
|
||||
}});
|
||||
|
||||
// render pass
|
||||
{
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_ref,
|
||||
};
|
||||
|
||||
vk::AttachmentDescription color_desc{
|
||||
.format = target.info().format,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
rp = device.createRenderPass(vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &color_desc,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
});
|
||||
}
|
||||
|
||||
fb = device.createFramebuffer(
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *rp,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*image_view,
|
||||
.width = w,
|
||||
.height = desc.height,
|
||||
.layers = 1,
|
||||
});
|
||||
|
||||
sampler = device.createSampler(vk::SamplerCreateInfo{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
|
||||
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
|
||||
});
|
||||
|
||||
pipelines.resize(desc.items.size());
|
||||
for (auto [i, item]: utils::enumerate(desc.items))
|
||||
{
|
||||
pipelines[i].used = item.offset_x < (view + 1) * w and
|
||||
item.offset_x + item.width * item.subsampling > view * w;
|
||||
}
|
||||
|
||||
current.rgb = *image_view;
|
||||
current.sampler_rgb = *sampler;
|
||||
current.rect_rgb = vk::Rect2D{.extent = {w, desc.height}};
|
||||
current.layout_rgb = vk::ImageLayout::eShaderReadOnlyOptimal;
|
||||
}
|
||||
|
||||
void blitter::begin(vk::raii::CommandBuffer & cmd)
|
||||
{
|
||||
assert(not desc.items.empty());
|
||||
if (*fb == VK_NULL_HANDLE)
|
||||
{
|
||||
current.rgb = nullptr;
|
||||
current.a = nullptr;
|
||||
current.sampler_rgb = nullptr;
|
||||
current.sampler_a = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
current.rgb = *image_view;
|
||||
current.sampler_rgb = *sampler;
|
||||
|
||||
cmd.beginRenderPass(
|
||||
{
|
||||
.renderPass = *rp,
|
||||
.framebuffer = *fb,
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = {target.info().extent.width, target.info().extent.height},
|
||||
},
|
||||
},
|
||||
vk::SubpassContents::eInline);
|
||||
}
|
||||
|
||||
void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Sampler sampler, const vk::Extent2D & extent_, vk::ImageView image, vk::ImageLayout layout)
|
||||
{
|
||||
if (stream == passthrough_rgb)
|
||||
{
|
||||
current.rgb = image;
|
||||
current.sampler_rgb = sampler;
|
||||
current.layout_rgb = layout;
|
||||
current.rect_rgb.extent = vk::Extent2D{
|
||||
extent_.width * desc.items[stream].subsampling,
|
||||
extent_.height * desc.items[stream].subsampling,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (stream == passthrough_a)
|
||||
{
|
||||
current.a = image;
|
||||
current.sampler_a = sampler;
|
||||
current.layout_a = layout;
|
||||
current.rect_a.extent = vk::Extent2D{
|
||||
extent_.width * desc.items[stream].subsampling,
|
||||
extent_.height * desc.items[stream].subsampling,
|
||||
};
|
||||
return;
|
||||
}
|
||||
if (pipelines.empty())
|
||||
return;
|
||||
|
||||
assert(stream < pipelines.size());
|
||||
auto & p = pipelines[stream];
|
||||
if (not p.used)
|
||||
return;
|
||||
|
||||
const auto & extent = target.info().extent;
|
||||
const auto & description = desc.items[stream];
|
||||
if (not *p.pipeline)
|
||||
{
|
||||
const bool alpha = description.channels == to_headset::video_stream_description::channels_t::alpha;
|
||||
vk::DescriptorSetLayoutBinding sampler_layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = &sampler,
|
||||
};
|
||||
|
||||
p.set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
|
||||
.flags = vk::DescriptorSetLayoutCreateFlagBits::ePushDescriptorKHR,
|
||||
.bindingCount = 1,
|
||||
.pBindings = &sampler_layout_binding,
|
||||
});
|
||||
|
||||
auto vert_constants = make_specialization_constants(
|
||||
float(description.width) / extent_.width,
|
||||
float(description.height) / extent_.height);
|
||||
|
||||
auto frag_constants = make_specialization_constants(
|
||||
VkBool32(alpha));
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
|
||||
|
||||
p.layout = device.createPipelineLayout(vk::PipelineLayoutCreateInfo{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*p.set_layout,
|
||||
});
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.Stages = {{
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = vert_constants,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = frag_constants,
|
||||
}},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
|
||||
// and scissors is still used, put a vector with one element
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
}},
|
||||
.MultisampleState = {{
|
||||
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
||||
}},
|
||||
.ColorBlendAttachments = {
|
||||
{.colorWriteMask = alpha ? vk::ColorComponentFlagBits::eA
|
||||
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *p.layout,
|
||||
.renderPass = *rp,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
p.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||
spdlog::info("Created blit pipeline for stream {}, view {}", stream, view);
|
||||
}
|
||||
|
||||
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, *p.pipeline);
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.imageView = image,
|
||||
.imageLayout = layout,
|
||||
};
|
||||
cmd.pushDescriptorSetKHR(
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
*p.layout,
|
||||
0,
|
||||
vk::WriteDescriptorSet{
|
||||
.dstBinding = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
});
|
||||
|
||||
int x0 = description.offset_x - view * extent.width;
|
||||
int y0 = description.offset_y;
|
||||
int x1 = x0 + description.width * description.subsampling;
|
||||
int y1 = y0 + description.height * description.subsampling;
|
||||
|
||||
cmd.setViewport(
|
||||
0,
|
||||
vk::Viewport{
|
||||
.x = (float)x0,
|
||||
.y = (float)y0,
|
||||
.width = float(description.width * description.subsampling),
|
||||
.height = float(description.height * description.subsampling),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
});
|
||||
|
||||
x0 = std::clamp<int>(x0, 0, extent.width);
|
||||
x1 = std::clamp<int>(x1, 0, extent.width);
|
||||
y0 = std::clamp<int>(y0, 0, extent.height);
|
||||
y1 = std::clamp<int>(y1, 0, extent.height);
|
||||
|
||||
cmd.setScissor(
|
||||
0,
|
||||
vk::Rect2D{
|
||||
.offset = {.x = x0, .y = y0},
|
||||
.extent = {.width = uint32_t(x1 - x0), .height = uint32_t(y1 - y0)},
|
||||
});
|
||||
cmd.draw(3, 1, 0, 0);
|
||||
}
|
||||
|
||||
blitter::output blitter::end(vk::raii::CommandBuffer & cmd)
|
||||
{
|
||||
if (*fb)
|
||||
cmd.endRenderPass();
|
||||
return current;
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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 "vk/allocation.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class blitter
|
||||
{
|
||||
public:
|
||||
struct output
|
||||
{
|
||||
vk::ImageView rgb;
|
||||
vk::Sampler sampler_rgb;
|
||||
vk::Rect2D rect_rgb;
|
||||
vk::ImageLayout layout_rgb;
|
||||
vk::ImageView a;
|
||||
vk::Sampler sampler_a;
|
||||
vk::Rect2D rect_a;
|
||||
vk::ImageLayout layout_a;
|
||||
};
|
||||
|
||||
private:
|
||||
vk::raii::Device & device;
|
||||
size_t view;
|
||||
to_headset::video_stream_description desc;
|
||||
// indices to simply passthrough, if -1 image needs to be blitted
|
||||
int passthrough_rgb = -1;
|
||||
int passthrough_a = -1;
|
||||
image_allocation target;
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
vk::raii::RenderPass rp = nullptr;
|
||||
vk::raii::Framebuffer fb = nullptr;
|
||||
vk::raii::Sampler sampler = nullptr;
|
||||
struct pipeline_t
|
||||
{
|
||||
vk::raii::DescriptorSetLayout set_layout = nullptr;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
bool used = false; // true if we need this image for blitting
|
||||
};
|
||||
std::vector<pipeline_t> pipelines;
|
||||
output current;
|
||||
|
||||
public:
|
||||
blitter(vk::raii::Device & device, size_t view);
|
||||
|
||||
void reset(const to_headset::video_stream_description & desc);
|
||||
void begin(vk::raii::CommandBuffer &);
|
||||
void push_image(vk::raii::CommandBuffer & buf, uint8_t stream, vk::Sampler sampler, const vk::Extent2D &, vk::ImageView image, vk::ImageLayout);
|
||||
output end(vk::raii::CommandBuffer &);
|
||||
};
|
||||
} // namespace wivrn
|
||||
+40
-85
@@ -17,6 +17,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <uni_algo/case.h>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#ifdef __ANDROID__
|
||||
@@ -139,7 +140,7 @@ static void InputText(const char * label, std::string & text, const ImVec2 & siz
|
||||
return 0;
|
||||
};
|
||||
|
||||
ImGui::InputTextEx(label, nullptr, text.data(), text.size(), size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
|
||||
ImGui::InputTextEx(label, nullptr, text.data(), text.size() + 1, size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
|
||||
}
|
||||
|
||||
static void display_recentering_tip(imgui_context & ctx, const std::string & tip)
|
||||
@@ -771,6 +772,43 @@ void scenes::lobby::gui_settings()
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
|
||||
|
||||
{
|
||||
auto language_name = [&](const std::locale & loc = std::locale()) {
|
||||
return boost::locale::pgettext("language selection, replace with the name of the language", "English", loc);
|
||||
};
|
||||
std::vector<std::tuple<std::string, std::locale, std::string>> languages;
|
||||
for (const auto & msg_info: get_locales())
|
||||
{
|
||||
std::string code = msg_info.language;
|
||||
if (not msg_info.country.empty())
|
||||
code += "_" + msg_info.country;
|
||||
std::locale loc(std::locale(), boost::locale::gnu_gettext::create_messages_facet<char>(msg_info));
|
||||
languages.emplace_back(language_name(loc), loc, std::move(code));
|
||||
}
|
||||
std::ranges::sort(languages, [](auto & l, auto & r) {
|
||||
return una::casesens::collate_utf8(std::get<0>(l), std::get<0>(r)) < 0;
|
||||
});
|
||||
if (ImGui::BeginCombo(_S("Language"), config.locale.empty() ? _S("System language") : language_name().c_str()))
|
||||
{
|
||||
if (ImGui::Selectable(_S("System language"), config.locale.empty(), ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
config.locale.clear();
|
||||
config.save();
|
||||
application::instance().load_locale();
|
||||
}
|
||||
for (const auto & [lang, locale, code]: languages)
|
||||
{
|
||||
if (ImGui::Selectable(lang.c_str(), code == config.locale, ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
config.locale = code;
|
||||
config.save();
|
||||
application::instance().load_locale();
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
}
|
||||
|
||||
if (instance.has_extension(XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME))
|
||||
{
|
||||
const auto & refresh_rates = session.get_refresh_rates();
|
||||
@@ -1034,89 +1072,6 @@ void scenes::lobby::gui_post_processing()
|
||||
ImGui::Unindent();
|
||||
}
|
||||
|
||||
{
|
||||
// SGSR
|
||||
{
|
||||
if (ImGui::Checkbox(_S("Enable Snapdragon Game Super Resolution"), &config.sgsr.enabled))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
imgui_ctx->tooltip(_("On this headset, this setting has been fully superseded by the native Sharpening setting above.\nOnly enable if you know what you're doing."));
|
||||
else
|
||||
imgui_ctx->tooltip(_("Client-side upscaling and sharpening, adds a performance cost on the headset"));
|
||||
}
|
||||
if (application::get_openxr_post_processing_supported())
|
||||
{
|
||||
ImGui::SameLine();
|
||||
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::BeginDisabled(not config.sgsr.enabled);
|
||||
ImGui::Indent();
|
||||
{
|
||||
const auto current = config.sgsr.upscaling_factor;
|
||||
const auto width = stream_view.recommendedImageRectWidth * config.resolution_scale;
|
||||
const auto height = stream_view.recommendedImageRectHeight * config.resolution_scale;
|
||||
auto intScale = int(current * 100);
|
||||
const auto slider = ImGui::SliderInt(
|
||||
_("Upscaling factor").append("##upscaling_factor").c_str(),
|
||||
&intScale,
|
||||
100,
|
||||
200,
|
||||
fmt::format(_F("%d%% - {}x{} per eye"), int(width * current), int(height * current)).c_str());
|
||||
if (slider)
|
||||
{
|
||||
config.sgsr.upscaling_factor = intScale * 0.01;
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (width * current > stream_view.maxImageRectWidth or height * current > stream_view.maxImageRectHeight)
|
||||
{
|
||||
ImGui::TextColored(ImColor(0xf9, 0x73, 0x06) /*orange*/, ICON_FA_TRIANGLE_EXCLAMATION);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("%s", fmt::format(_F("Resolution larger than {}x{} may not be supported by the headset"), stream_view.maxImageRectWidth, stream_view.maxImageRectHeight).c_str());
|
||||
}
|
||||
}
|
||||
{
|
||||
if (ImGui::Checkbox(_S("Use edge direction"), &config.sgsr.use_edge_direction))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Adds an additional performance cost"));
|
||||
}
|
||||
{
|
||||
const float current = config.sgsr.edge_threshold;
|
||||
int intScale = int(current);
|
||||
if (ImGui::SliderInt(_S("Edge threshold"), &intScale, 1, 16, "%d.0"))
|
||||
{
|
||||
config.sgsr.edge_threshold = float(intScale);
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(fmt::format(_F("Recommended: {:.1f}"), 4.0));
|
||||
}
|
||||
{
|
||||
if (ImGui::SliderFloat(_S("Edge sharpness"), &config.sgsr.edge_sharpness, 1.0, 2.0, "%.2f"))
|
||||
{
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(fmt::format(_F("Recommended: {:.1f}"), 2.0));
|
||||
}
|
||||
ImGui::Unindent();
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
@@ -1347,7 +1302,7 @@ void scenes::lobby::gui_licenses()
|
||||
ImGui::Text("%s", _("Licenses").c_str());
|
||||
ImGui::PopFont();
|
||||
|
||||
const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson", "SGSR"};
|
||||
const auto components = {"WiVRn", "FontAwesome", "openxr-loader", "simdjson"};
|
||||
if (not license)
|
||||
{
|
||||
selected_item = *components.begin();
|
||||
|
||||
+95
-389
@@ -17,11 +17,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "constants.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "xr/fb_body_tracker.h"
|
||||
#include "xr/body_tracker.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include "xr/fb_face_tracker2.h"
|
||||
#include "xr/htc_body_tracker.h"
|
||||
#include "xr/pico_body_tracker.h"
|
||||
#include "xr/space.h"
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
@@ -40,8 +38,6 @@
|
||||
#include "utils/contains.h"
|
||||
#include "utils/named_thread.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
@@ -49,6 +45,11 @@
|
||||
#include <thread>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "wivrn_config.h"
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
#include "vk/renderdoc.h"
|
||||
#endif
|
||||
|
||||
using namespace wivrn;
|
||||
|
||||
// clang-format off
|
||||
@@ -151,7 +152,8 @@ static const std::array supported_depth_formats{
|
||||
};
|
||||
|
||||
scenes::stream::stream() :
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats)
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats),
|
||||
blitters{blitter(device, 0), blitter(device, 1)}
|
||||
{
|
||||
}
|
||||
|
||||
@@ -189,7 +191,11 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
self->network_session = std::move(network_session);
|
||||
|
||||
self->network_session->send_control([&]() {
|
||||
from_headset::headset_info_packet info{};
|
||||
from_headset::headset_info_packet info{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
};
|
||||
|
||||
auto view = self->system.view_configuration_views(self->viewconfig)[0];
|
||||
view = override_view(view, guess_model());
|
||||
@@ -251,46 +257,49 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
if (config.check_feature(feature::face_tracking))
|
||||
{
|
||||
info.face_tracking = std::visit(utils::overloaded{
|
||||
[](std::monostate &) {
|
||||
return from_headset::face_type::none;
|
||||
},
|
||||
[](xr::fb_face_tracker2 &) {
|
||||
return from_headset::face_type::fb2;
|
||||
},
|
||||
[](xr::htc_face_tracker &) {
|
||||
return from_headset::face_type::htc;
|
||||
},
|
||||
[](xr::pico_face_tracker &) {
|
||||
return from_headset::face_type::fb2;
|
||||
},
|
||||
},
|
||||
application::get_face_tracker());
|
||||
switch (self->system.face_tracker_supported())
|
||||
{
|
||||
case xr::face_tracker_type::none:
|
||||
info.face_tracking = from_headset::face_type::none;
|
||||
break;
|
||||
case xr::face_tracker_type::fb:
|
||||
case xr::face_tracker_type::pico:
|
||||
info.face_tracking = from_headset::face_type::fb2;
|
||||
break;
|
||||
case xr::face_tracker_type::htc:
|
||||
info.face_tracking = from_headset::face_type::htc;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
info.num_generic_trackers = 0;
|
||||
if (config.check_feature(feature::body_tracking))
|
||||
{
|
||||
info.num_generic_trackers = std::visit(utils::overloaded{
|
||||
[&](std::monostate &) {
|
||||
return size_t(0);
|
||||
},
|
||||
[&](auto & b) {
|
||||
return b.count();
|
||||
},
|
||||
},
|
||||
application::get_body_tracker());
|
||||
switch (self->system.body_tracker_supported())
|
||||
{
|
||||
case xr::body_tracker_type::none:
|
||||
break;
|
||||
case xr::body_tracker_type::fb:
|
||||
info.num_generic_trackers = xr::fb_body_tracker::get_whitelisted_joints(config.fb_lower_body, config.fb_hip).size();
|
||||
break;
|
||||
case xr::body_tracker_type::htc:
|
||||
info.num_generic_trackers = application::get_generic_trackers().size();
|
||||
break;
|
||||
case xr::body_tracker_type::pico:
|
||||
info.num_generic_trackers = xr::pico_body_tracker::joint_whitelist.size();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
info.palm_pose = application::space(xr::spaces::palm_left) or application::space(xr::spaces::palm_right);
|
||||
info.passthrough = self->system.passthrough_supported() != xr::system::passthrough_type::no_passthrough;
|
||||
info.passthrough = self->system.passthrough_supported() != xr::passthrough_type::none;
|
||||
info.system_name = std::string(self->system.properties().systemName);
|
||||
|
||||
audio::get_audio_description(info);
|
||||
if (not(config.check_feature(feature::microphone)))
|
||||
info.microphone = {};
|
||||
|
||||
info.supported_codecs = decoder_impl::supported_codecs();
|
||||
info.supported_codecs = decoder::supported_codecs();
|
||||
return info;
|
||||
}());
|
||||
|
||||
@@ -311,15 +320,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const auto & info = application::get_messages_info();
|
||||
self->network_session->send_control(from_headset::get_application_list{
|
||||
.language = info.language,
|
||||
.country = info.country,
|
||||
.variant = info.variant,
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
const auto & config = application::get_config();
|
||||
self->override_foveation_enable = config.override_foveation_enable;
|
||||
@@ -363,7 +363,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
{
|
||||
self->haptics_actions.emplace(id, haptics_action{
|
||||
.action = action.first,
|
||||
.path = application::string_to_path(path),
|
||||
.path = self->instance.string_to_path(path),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -394,7 +394,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
|
||||
void scenes::stream::on_focused()
|
||||
{
|
||||
gui_status_last_change = application::now();
|
||||
gui_status_last_change = instance.now();
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
// stream_view = override_view(views[0], guess_model());
|
||||
@@ -402,7 +402,7 @@ void scenes::stream::on_focused()
|
||||
height = views[0].recommendedImageRectHeight;
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, application::queue_family_index(), renderer->get_default_material());
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
@@ -470,8 +470,11 @@ void scenes::stream::on_focused()
|
||||
swapchain_imgui,
|
||||
std::vector{vp});
|
||||
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
if (application::get_config().enable_stream_gui)
|
||||
{
|
||||
plots_toggle_1 = get_action("plots_toggle_1").first;
|
||||
plots_toggle_2 = get_action("plots_toggle_2").first;
|
||||
}
|
||||
recenter_left = get_action("recenter_left").first;
|
||||
recenter_right = get_action("recenter_right").first;
|
||||
foveation_pitch = get_action("foveation_pitch").first;
|
||||
@@ -494,6 +497,8 @@ void scenes::stream::on_unfocused()
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
clear_swapchains();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
|
||||
imgui_ctx.reset();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
@@ -524,16 +529,16 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
|
||||
{
|
||||
if (decoder != decoders[stream].decoder.get())
|
||||
return;
|
||||
handle->feedback.received_from_decoder = application::now();
|
||||
handle->feedback.received_from_decoder = instance.now();
|
||||
std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]);
|
||||
}
|
||||
|
||||
if (state_ != state::streaming and std::ranges::all_of(decoders, [](accumulator_images & i) {
|
||||
return i.alpha() or not i.frames().empty();
|
||||
return i.alpha() or not i.empty();
|
||||
}))
|
||||
{
|
||||
state_ = state::streaming;
|
||||
spdlog::info("Stream scene ready at t={}", application::now());
|
||||
spdlog::info("Stream scene ready at t={}", instance.now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,15 +553,14 @@ bool scenes::stream::accumulator_images::alpha() const
|
||||
return decoder->desc().channels == wivrn::to_headset::video_stream_description::channels_t::alpha;
|
||||
}
|
||||
|
||||
std::vector<uint64_t> scenes::stream::accumulator_images::frames() const
|
||||
bool scenes::stream::accumulator_images::empty() const
|
||||
{
|
||||
std::vector<uint64_t> result;
|
||||
for (const auto & frame: latest_frames)
|
||||
{
|
||||
if (frame)
|
||||
result.push_back(frame->feedback.frame_index);
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<shard_accumulator::blit_handle>> scenes::stream::common_frame(XrTime display_time)
|
||||
@@ -766,138 +770,17 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
if (state_ == state::stalled)
|
||||
application::pop_scene();
|
||||
|
||||
assert(swapchain);
|
||||
for (auto & i: decoders)
|
||||
{
|
||||
if (auto sampler = i.decoder->sampler(); sampler and not *i.blit_pipeline)
|
||||
{
|
||||
// Create blit pipeline
|
||||
// Create VkDescriptorSetLayout with an immutable sampler
|
||||
vk::DescriptorSetLayoutBinding sampler_layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = &sampler,
|
||||
};
|
||||
network_session->send_control(from_headset::get_application_list{
|
||||
.language = application::get_messages_info().language,
|
||||
.country = application::get_messages_info().country,
|
||||
.variant = application::get_messages_info().variant,
|
||||
});
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info{
|
||||
.bindingCount = 1,
|
||||
.pBindings = &sampler_layout_binding,
|
||||
};
|
||||
|
||||
i.descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
|
||||
i.descriptor_set = device.allocateDescriptorSets(
|
||||
vk::DescriptorSetAllocateInfo{
|
||||
.descriptorPool = *blit_descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*i.descriptor_set_layout,
|
||||
})[0]
|
||||
.release();
|
||||
|
||||
const auto & description = i.decoder->desc();
|
||||
vk::Extent2D image_size = i.decoder->image_size();
|
||||
std::array useful_size{
|
||||
float(description.width) / image_size.width,
|
||||
float(description.height) / image_size.height,
|
||||
};
|
||||
spdlog::info("useful size: {}x{} with buffer {}x{}",
|
||||
description.width,
|
||||
description.height,
|
||||
image_size.width,
|
||||
image_size.height);
|
||||
|
||||
std::array specialization_constants_desc{
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(float),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(float),
|
||||
.size = sizeof(float),
|
||||
}};
|
||||
|
||||
vk::SpecializationInfo vert_specialization_info;
|
||||
vert_specialization_info.setMapEntries(specialization_constants_desc);
|
||||
vert_specialization_info.setData<float>(useful_size);
|
||||
|
||||
std::array<VkBool32, 2> constants = {
|
||||
need_srgb_conversion(guess_model()),
|
||||
i.alpha(),
|
||||
};
|
||||
std::array frag_specialization_constant_desc = {
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = 0,
|
||||
.size = sizeof(constants[0]),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = sizeof(constants[0]),
|
||||
.size = sizeof(constants[1]),
|
||||
},
|
||||
};
|
||||
vk::SpecializationInfo frag_specialization_info;
|
||||
frag_specialization_info.setMapEntries(frag_specialization_constant_desc);
|
||||
frag_specialization_info.setData<VkBool32>(constants);
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
|
||||
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*i.descriptor_set_layout,
|
||||
};
|
||||
|
||||
i.blit_pipeline_layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.Stages = {{
|
||||
.stage = vk::ShaderStageFlagBits::eVertex,
|
||||
.module = *vertex_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &vert_specialization_info,
|
||||
},
|
||||
{
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &frag_specialization_info,
|
||||
}},
|
||||
.VertexBindingDescriptions = {},
|
||||
.VertexAttributeDescriptions = {},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
// With vk::DynamicState::eViewport, vk::DynamicState::eScissor the number of viewports
|
||||
// and scissors is still used, put a vector with one element
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
}},
|
||||
.MultisampleState = {{
|
||||
.rasterizationSamples = vk::SampleCountFlagBits::e1,
|
||||
}},
|
||||
.ColorBlendAttachments = {
|
||||
{.colorWriteMask = i.alpha() ? vk::ColorComponentFlagBits::eA
|
||||
: vk::ColorComponentFlagBits::eA | vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB}},
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *i.blit_pipeline_layout,
|
||||
.renderPass = *blit_render_pass,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
i.blit_pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
}
|
||||
application::pop_scene();
|
||||
}
|
||||
|
||||
assert(swapchain);
|
||||
if (device.waitForFences(*fence, VK_TRUE, UINT64_MAX) == vk::Result::eTimeout)
|
||||
throw std::runtime_error("Vulkan fence timeout");
|
||||
|
||||
@@ -928,11 +811,13 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
|
||||
std::array<int, view_count> image_indices;
|
||||
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_begin(*vk_instance);
|
||||
#endif
|
||||
command_buffer.reset();
|
||||
|
||||
vk::CommandBufferBeginInfo begin_info;
|
||||
begin_info.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit;
|
||||
command_buffer.begin(begin_info);
|
||||
command_buffer.begin(vk::CommandBufferBeginInfo{
|
||||
.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit,
|
||||
});
|
||||
|
||||
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
||||
|
||||
@@ -947,13 +832,12 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
std::array<wivrn::to_headset::foveation_parameter, 2> foveation{};
|
||||
bool use_alpha = false;
|
||||
|
||||
// Blit images from the decoders
|
||||
for (auto [i, blit_handle]: std::views::zip(decoders, current_blit_handles))
|
||||
for (auto & blit_handle: current_blit_handles)
|
||||
{
|
||||
if (not blit_handle or not *i.blit_pipeline)
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
|
||||
blit_handle->feedback.blitted = application::now();
|
||||
blit_handle->feedback.blitted = instance.now();
|
||||
if (blit_handle->feedback.blitted - blit_handle->feedback.received_from_decoder > 1'000'000'000)
|
||||
state_ = stream::state::stalled;
|
||||
++blit_handle->feedback.times_displayed;
|
||||
@@ -964,27 +848,12 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
foveation = blit_handle->view_info.foveation;
|
||||
use_alpha = blit_handle->view_info.alpha;
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.imageView = *blit_handle->image_view,
|
||||
.imageLayout = vk::ImageLayout::eGeneral,
|
||||
};
|
||||
|
||||
vk::WriteDescriptorSet descriptor_write{
|
||||
.dstSet = i.descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(descriptor_write, {});
|
||||
if (*blit_handle->current_layout != vk::ImageLayout::eGeneral)
|
||||
if (blit_handle->current_layout == vk::ImageLayout::eUndefined)
|
||||
{
|
||||
vk::ImageMemoryBarrier barrier{
|
||||
.srcAccessMask = vk::AccessFlagBits::eNone,
|
||||
.dstAccessMask = vk::AccessFlagBits::eMemoryRead,
|
||||
.oldLayout = *blit_handle->current_layout,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eGeneral,
|
||||
.image = blit_handle->image,
|
||||
.subresourceRange = {
|
||||
@@ -995,72 +864,22 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
};
|
||||
|
||||
command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier);
|
||||
*blit_handle->current_layout = vk::ImageLayout::eGeneral;
|
||||
blit_handle->current_layout = vk::ImageLayout::eGeneral;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t x_offset = 0;
|
||||
for (auto & out: decoder_output)
|
||||
// Blit images from the decoders
|
||||
std::array<blitter::output, view_count> blitted;
|
||||
for (auto [i, b]: utils::enumerate(blitters))
|
||||
{
|
||||
command_buffer.beginRenderPass(
|
||||
{
|
||||
.renderPass = *blit_render_pass,
|
||||
.framebuffer = *out.frame_buffer,
|
||||
.renderArea = {
|
||||
.offset = {0, 0},
|
||||
.extent = decoder_out_size,
|
||||
},
|
||||
.clearValueCount = 0,
|
||||
},
|
||||
vk::SubpassContents::eInline);
|
||||
|
||||
for (const auto & decoder: decoders)
|
||||
b.begin(command_buffer);
|
||||
for (auto [j, blit_handle]: utils::enumerate(current_blit_handles))
|
||||
{
|
||||
if (not *decoder.blit_pipeline)
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
if (decoder.alpha() and not use_alpha)
|
||||
continue;
|
||||
|
||||
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, *decoder.blit_pipeline);
|
||||
|
||||
const auto & description = decoder.decoder->desc();
|
||||
int x0 = description.offset_x - x_offset;
|
||||
int y0 = description.offset_y;
|
||||
int x1 = x0 + description.width * description.subsampling;
|
||||
int y1 = y0 + description.height * description.subsampling;
|
||||
|
||||
vk::Viewport viewport{
|
||||
.x = (float)x0,
|
||||
.y = (float)y0,
|
||||
.width = float(description.width * description.subsampling),
|
||||
.height = float(description.height * description.subsampling),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
};
|
||||
|
||||
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},
|
||||
.extent = {.width = (uint32_t)(x1 - x0), .height = (uint32_t)(y1 - y0)},
|
||||
};
|
||||
|
||||
command_buffer.setViewport(0, viewport);
|
||||
command_buffer.setScissor(0, scissor);
|
||||
|
||||
command_buffer.bindDescriptorSets(
|
||||
vk::PipelineBindPoint::eGraphics,
|
||||
*decoder.blit_pipeline_layout,
|
||||
0,
|
||||
decoder.descriptor_set,
|
||||
nullptr);
|
||||
command_buffer.draw(3, 1, 0, 0);
|
||||
b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout);
|
||||
}
|
||||
command_buffer.endRenderPass();
|
||||
x_offset += decoder_out_size.width;
|
||||
blitted[i] = b.end(command_buffer);
|
||||
}
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 1);
|
||||
@@ -1071,7 +890,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
int32_t max_height = 0;
|
||||
for (size_t i = 0; i < view_count; ++i)
|
||||
{
|
||||
extents[i] = reprojector->defoveated_size(foveation[i]);
|
||||
extents[i] = defoveator->defoveated_size(foveation[i]);
|
||||
max_width = std::max(max_width, extents[i].width);
|
||||
max_height = std::max(max_height, extents[i].height);
|
||||
}
|
||||
@@ -1101,7 +920,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
// defoveate the image
|
||||
int image_index = swapchain.acquire();
|
||||
swapchain.wait();
|
||||
reprojector->reproject(command_buffer, foveation, image_index);
|
||||
defoveator->defoveate(command_buffer, foveation, blitted, image_index);
|
||||
|
||||
command_buffer.writeTimestamp(vk::PipelineStageFlagBits::eBottomOfPipe, *query_pool, 2);
|
||||
|
||||
@@ -1109,6 +928,9 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
vk::SubmitInfo submit_info;
|
||||
submit_info.setCommandBuffers(*command_buffer);
|
||||
queue.lock()->submit(submit_info, *fence);
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_end(*vk_instance);
|
||||
#endif
|
||||
swapchain.release();
|
||||
|
||||
std::vector<XrCompositionLayerProjectionView> layer_view(view_count);
|
||||
@@ -1275,119 +1097,15 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
}
|
||||
|
||||
video_stream_description = description;
|
||||
|
||||
const uint32_t video_width = description.width / view_count;
|
||||
const uint32_t video_height = description.height;
|
||||
|
||||
// Create renderpass
|
||||
{
|
||||
vk::AttachmentDescription color_desc{
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::RenderPassCreateInfo renderpass_info{
|
||||
.flags = {},
|
||||
};
|
||||
renderpass_info.setAttachments(color_desc);
|
||||
renderpass_info.setSubpasses(subpass);
|
||||
|
||||
blit_render_pass = vk::raii::RenderPass(device, renderpass_info);
|
||||
}
|
||||
|
||||
// Create outputs for the decoders
|
||||
decoder_out_size = vk::Extent2D{video_width, video_height};
|
||||
{
|
||||
decoder_out_format = vk::Format::eA8B8G8R8SrgbPack32;
|
||||
|
||||
vk::ImageCreateInfo image_info{
|
||||
.flags = vk::ImageCreateFlags{},
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.extent = {video_width, video_height, 1},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = view_count,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eColorAttachment,
|
||||
.sharingMode = vk::SharingMode::eExclusive,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
};
|
||||
|
||||
VmaAllocationCreateInfo alloc_info{
|
||||
.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||
};
|
||||
|
||||
decoder_out_image = image_allocation{device, image_info, alloc_info};
|
||||
|
||||
vk::ImageViewCreateInfo image_view_info{
|
||||
.image = vk::Image{decoder_out_image},
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.components = {},
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
auto & output = decoder_output[view];
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
vk::DescriptorPoolSize pool_size{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = uint32_t(2 * description.items.size()),
|
||||
};
|
||||
blit_descriptor_pool = vk::raii::DescriptorPool(
|
||||
device,
|
||||
vk::DescriptorPoolCreateInfo{
|
||||
.maxSets = uint32_t(2 * description.items.size()),
|
||||
.poolSizeCount = 1,
|
||||
.pPoolSizes = &pool_size,
|
||||
});
|
||||
}
|
||||
for (auto & b: blitters)
|
||||
b.reset(description);
|
||||
|
||||
for (const auto & [stream_index, item]: utils::enumerate(description.items))
|
||||
{
|
||||
spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y);
|
||||
|
||||
decoders.push_back(accumulator_images{
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, item, description.fps, shared_from_this(), stream_index),
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1400,15 +1118,6 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
const uint32_t video_width = video_stream_description->width / view_count;
|
||||
const uint32_t video_height = video_stream_description->height;
|
||||
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
{
|
||||
const float upscaling_factor = sgsr.upscaling_factor;
|
||||
spdlog::info("Using SGSR with an upscale factor of {}", upscaling_factor);
|
||||
swapchain_width *= upscaling_factor;
|
||||
swapchain_height *= upscaling_factor;
|
||||
}
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
|
||||
swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
@@ -1425,12 +1134,9 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
for (auto & image: swapchain.images())
|
||||
swapchain_images.push_back(image.image);
|
||||
|
||||
reprojector.emplace(
|
||||
defoveator.emplace(
|
||||
device,
|
||||
physical_device,
|
||||
decoder_out_image,
|
||||
vk::Extent2D{.width = video_width, .height = video_height},
|
||||
2,
|
||||
swapchain_images,
|
||||
extent,
|
||||
swapchain.format());
|
||||
|
||||
+19
-23
@@ -23,8 +23,9 @@
|
||||
#include "decoder/shard_accumulator.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include "scene.h"
|
||||
#include "scenes/blitter.h"
|
||||
#include "scenes/input_profile.h"
|
||||
#include "stream_reprojection.h"
|
||||
#include "stream_defoveator.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "wivrn_client.h"
|
||||
@@ -48,6 +49,13 @@ public:
|
||||
};
|
||||
static const size_t image_buffer_size = 3;
|
||||
|
||||
struct app
|
||||
{
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::vector<std::byte> image;
|
||||
};
|
||||
|
||||
private:
|
||||
static const size_t view_count = 2;
|
||||
|
||||
@@ -56,16 +64,12 @@ private:
|
||||
struct accumulator_images
|
||||
{
|
||||
std::unique_ptr<wivrn::shard_accumulator> decoder;
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::DescriptorSet descriptor_set = nullptr;
|
||||
vk::raii::PipelineLayout blit_pipeline_layout = nullptr;
|
||||
vk::raii::Pipeline blit_pipeline = nullptr;
|
||||
// latest frames from oldest to most recent
|
||||
// latest frames, rolling buffer
|
||||
std::array<std::shared_ptr<wivrn::shard_accumulator::blit_handle>, image_buffer_size> latest_frames;
|
||||
|
||||
std::shared_ptr<wivrn::shard_accumulator::blit_handle> frame(uint64_t id) const;
|
||||
bool alpha() const;
|
||||
std::vector<uint64_t> frames() const;
|
||||
bool empty() const;
|
||||
};
|
||||
|
||||
wifi_lock::wifi wifi;
|
||||
@@ -77,9 +81,9 @@ private:
|
||||
std::unique_ptr<wivrn_session> network_session;
|
||||
std::atomic<bool> exiting = false;
|
||||
std::thread network_thread;
|
||||
std::mutex tracking_control_mutex;
|
||||
to_headset::tracking_control tracking_control{};
|
||||
thread_safe<to_headset::tracking_control> tracking_control{};
|
||||
std::array<std::atomic<interaction_profile>, 2> interaction_profiles; // left and right hand
|
||||
std::atomic<bool> interaction_profile_changed = false;
|
||||
std::atomic<bool> recenter_requested = false;
|
||||
std::atomic<XrDuration> display_time_phase = 0;
|
||||
std::atomic<XrDuration> display_time_period = 0;
|
||||
@@ -90,21 +94,10 @@ private:
|
||||
std::shared_mutex decoder_mutex;
|
||||
std::optional<to_headset::video_stream_description> video_stream_description;
|
||||
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
|
||||
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
|
||||
vk::raii::RenderPass blit_render_pass = nullptr;
|
||||
|
||||
vk::Extent2D decoder_out_size;
|
||||
vk::Format decoder_out_format;
|
||||
image_allocation decoder_out_image;
|
||||
std::array<blitter, view_count> blitters;
|
||||
|
||||
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_defoveator> defoveator;
|
||||
|
||||
vk::raii::Fence fence = nullptr;
|
||||
vk::raii::CommandBuffer command_buffer = nullptr;
|
||||
@@ -125,6 +118,8 @@ private:
|
||||
|
||||
std::optional<audio> audio_handle;
|
||||
|
||||
std::optional<xr::hand_tracker> left_hand;
|
||||
std::optional<xr::hand_tracker> right_hand;
|
||||
std::optional<input_profile> input;
|
||||
static inline const uint32_t layer_controllers = 1 << 0;
|
||||
static inline const uint32_t layer_rays = 1 << 1;
|
||||
@@ -176,7 +171,7 @@ private:
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||
|
||||
// Last application list received from server
|
||||
thread_safe<to_headset::application_list> applications;
|
||||
thread_safe<std::vector<app>> applications;
|
||||
|
||||
stream();
|
||||
|
||||
@@ -202,6 +197,7 @@ public:
|
||||
void operator()(to_headset::video_stream_description &&);
|
||||
void operator()(to_headset::refresh_rate_change &&);
|
||||
void operator()(to_headset::application_list &&);
|
||||
void operator()(to_headset::application_icon &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr<wivrn::shard_accumulator::blit_handle> handle);
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "stream_reprojection.h"
|
||||
#include "stream_defoveator.h"
|
||||
#include "application.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/pipeline.h"
|
||||
#include "vk/shader.h"
|
||||
#include "vk/specialization_constants.h"
|
||||
#include <array>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
@@ -31,22 +32,21 @@
|
||||
#include <vulkan/vulkan_core.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
struct stream_reprojection::vertex
|
||||
struct stream_defoveator::vertex
|
||||
{
|
||||
// output image position
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates
|
||||
alignas(8) glm::vec2 uv;
|
||||
// input texture coordinates + shading rate in the first 4 bits of x
|
||||
alignas(8) glm::uvec2 uv;
|
||||
};
|
||||
|
||||
struct SgsrSpecializationConstants
|
||||
struct vert_pc
|
||||
{
|
||||
VkBool32 use_edge_direction;
|
||||
float edge_threshold;
|
||||
float edge_sharpness;
|
||||
glm::ivec4 rgb_rect;
|
||||
glm::ivec4 a_rect;
|
||||
};
|
||||
|
||||
void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
void stream_defoveator::ensure_vertices(size_t num_vertices)
|
||||
{
|
||||
vk::BufferCreateInfo create_info{
|
||||
.size = num_vertices * sizeof(vertex) * view_count,
|
||||
@@ -65,212 +65,81 @@ void stream_reprojection::ensure_vertices(size_t num_vertices)
|
||||
vertices_size = num_vertices * sizeof(vertex);
|
||||
}
|
||||
|
||||
stream_reprojection::vertex * stream_reprojection::get_vertices(size_t view)
|
||||
stream_defoveator::vertex * stream_defoveator::get_vertices(size_t view)
|
||||
{
|
||||
assert(buffer);
|
||||
return reinterpret_cast<vertex *>(reinterpret_cast<uintptr_t>(buffer.map()) + view * vertices_size);
|
||||
}
|
||||
|
||||
stream_reprojection::stream_reprojection(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
vk::Image input_image_,
|
||||
vk::Extent2D input_extent,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format) :
|
||||
view_count(view_count),
|
||||
device(device),
|
||||
input_image(input_image_),
|
||||
input_extent(input_extent),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a)
|
||||
{
|
||||
vk::SamplerCreateInfo sampler_info{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.mipmapMode = vk::SamplerMipmapMode::eNearest,
|
||||
.addressModeU = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeV = vk::SamplerAddressMode::eClampToBorder,
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToBorder,
|
||||
.mipLodBias = 0.0f,
|
||||
.anisotropyEnable = VK_FALSE,
|
||||
.maxAnisotropy = 1,
|
||||
.compareEnable = VK_FALSE,
|
||||
.compareOp = vk::CompareOp::eNever,
|
||||
.minLod = 0.0f,
|
||||
.maxLod = 0.0f,
|
||||
.borderColor = vk::BorderColor::eFloatOpaqueBlack,
|
||||
.unnormalizedCoordinates = VK_FALSE,
|
||||
};
|
||||
auto & target = a ? pipeline_a[view] : pipeline_rgb[view];
|
||||
if (*target.pipeline)
|
||||
return target;
|
||||
|
||||
if (utils::contains(application::get_vk_device_extensions(), VK_IMG_FILTER_CUBIC_EXTENSION_NAME))
|
||||
sampler_info.magFilter = vk::Filter::eCubicIMG;
|
||||
|
||||
sampler = vk::raii::Sampler(device, sampler_info);
|
||||
std::array samplers{rgb, a};
|
||||
int32_t alpha = a ? 1 : 0;
|
||||
|
||||
// Create VkDescriptorSetLayout
|
||||
vk::DescriptorSetLayoutBinding layout_binding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
};
|
||||
|
||||
vk::DescriptorSetLayoutCreateInfo layout_info;
|
||||
layout_info.setBindings(layout_binding);
|
||||
|
||||
descriptor_set_layout = vk::raii::DescriptorSetLayout(device, layout_info);
|
||||
|
||||
std::array pool_size{
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = (uint32_t)view_count,
|
||||
std::array layout_binding{
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = uint32_t(alpha + 1),
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
.pImmutableSamplers = samplers.data(),
|
||||
},
|
||||
};
|
||||
|
||||
vk::DescriptorPoolCreateInfo pool_info{
|
||||
.maxSets = view_count,
|
||||
.poolSizeCount = pool_size.size(),
|
||||
.pPoolSizes = pool_size.data(),
|
||||
target.descriptor_set_layout = device.createDescriptorSetLayout(vk::DescriptorSetLayoutCreateInfo{
|
||||
.bindingCount = layout_binding.size(),
|
||||
.pBindings = layout_binding.data(),
|
||||
});
|
||||
|
||||
target.ds = device.allocateDescriptorSets(vk::DescriptorSetAllocateInfo{
|
||||
.descriptorPool = *ds_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*target.descriptor_set_layout,
|
||||
})[0]
|
||||
.release();
|
||||
|
||||
// pipeline layout
|
||||
vk::PushConstantRange pc_range{
|
||||
.stageFlags = vk::ShaderStageFlagBits::eVertex,
|
||||
.size = sizeof(vert_pc),
|
||||
};
|
||||
|
||||
descriptor_pool = vk::raii::DescriptorPool(device, pool_info);
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info{
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = &*target.descriptor_set_layout,
|
||||
.pushConstantRangeCount = 1,
|
||||
.pPushConstantRanges = &pc_range,
|
||||
};
|
||||
|
||||
// Create image views and descriptor sets
|
||||
for (uint32_t view = 0; view < view_count; ++view)
|
||||
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
const auto & vk_device_extensions = application::get_vk_device_extensions();
|
||||
bool fragment_shading_rate = false;
|
||||
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
|
||||
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
|
||||
{
|
||||
vk::ImageViewCreateInfo iv_info{
|
||||
.image = input_image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = vk::Format::eA8B8G8R8SrgbPack32,
|
||||
.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,
|
||||
},
|
||||
};
|
||||
|
||||
vk::ImageView input_image_view = *input_image_views.emplace_back(device, iv_info);
|
||||
|
||||
vk::DescriptorSetAllocateInfo ds_info{
|
||||
.descriptorPool = *descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*descriptor_set_layout,
|
||||
};
|
||||
|
||||
auto descriptor_set = descriptor_sets.emplace_back(device.allocateDescriptorSets(ds_info)[0].release());
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.sampler = *sampler,
|
||||
.imageView = input_image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = descriptor_set,
|
||||
.dstBinding = 0,
|
||||
.dstArrayElement = 0,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info,
|
||||
},
|
||||
{});
|
||||
const auto & [prop, rate_prop] = physical_device.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFragmentShadingRatePropertiesKHR>();
|
||||
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
fragment_shading_rate = rate_prop.fragmentShadingRateNonTrivialCombinerOps and
|
||||
fragment_feat.primitiveFragmentShadingRate and
|
||||
fragment_feat.attachmentFragmentShadingRate;
|
||||
}
|
||||
|
||||
// Create renderpass
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.initialLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
};
|
||||
subpass.setColorAttachments(color_ref);
|
||||
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
// Vertex shader
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
||||
|
||||
// Fragment shader
|
||||
std::string fragment_shader_name = "reprojection.frag";
|
||||
auto specialization = make_specialization_constants(
|
||||
int32_t(alpha),
|
||||
VkBool32(need_srgb_conversion(guess_model())));
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
|
||||
|
||||
vk::SpecializationInfo fragment_specialization_info;
|
||||
SgsrSpecializationConstants fragment_specialization_constants;
|
||||
std::vector<vk::SpecializationMapEntry> fragment_specialization_constants_desc;
|
||||
const configuration::sgsr_settings sgsr = application::get_config().sgsr;
|
||||
if (sgsr.enabled)
|
||||
{
|
||||
fragment_shader_name = "reprojection_sgsr.frag";
|
||||
|
||||
fragment_specialization_constants = {
|
||||
.use_edge_direction = sgsr.use_edge_direction,
|
||||
.edge_threshold = float(sgsr.edge_threshold / 255.0),
|
||||
.edge_sharpness = sgsr.edge_sharpness,
|
||||
};
|
||||
|
||||
fragment_specialization_constants_desc = {
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 0,
|
||||
.offset = offsetof(SgsrSpecializationConstants, use_edge_direction),
|
||||
.size = sizeof(fragment_specialization_constants.use_edge_direction),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 1,
|
||||
.offset = offsetof(SgsrSpecializationConstants, edge_threshold),
|
||||
.size = sizeof(fragment_specialization_constants.edge_threshold),
|
||||
},
|
||||
vk::SpecializationMapEntry{
|
||||
.constantID = 2,
|
||||
.offset = offsetof(SgsrSpecializationConstants, edge_sharpness),
|
||||
.size = sizeof(fragment_specialization_constants.edge_sharpness),
|
||||
},
|
||||
};
|
||||
|
||||
fragment_specialization_info.setMapEntries(fragment_specialization_constants_desc);
|
||||
fragment_specialization_info.setDataSize(sizeof(fragment_specialization_constants));
|
||||
fragment_specialization_info.setPData(&fragment_specialization_constants);
|
||||
}
|
||||
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, fragment_shader_name);
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::PipelineLayoutCreateInfo pipeline_layout_info;
|
||||
pipeline_layout_info.setSetLayouts(*descriptor_set_layout);
|
||||
|
||||
layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
vk::pipeline_builder pipeline_info{
|
||||
vk::pipeline_builder pipeline_info_builder{
|
||||
.flags = {},
|
||||
.Stages = {
|
||||
{
|
||||
@@ -282,7 +151,7 @@ stream_reprojection::stream_reprojection(
|
||||
.stage = vk::ShaderStageFlagBits::eFragment,
|
||||
.module = *fragment_shader,
|
||||
.pName = "main",
|
||||
.pSpecializationInfo = &fragment_specialization_info,
|
||||
.pSpecializationInfo = specialization,
|
||||
},
|
||||
},
|
||||
.VertexBindingDescriptions = {
|
||||
@@ -302,25 +171,15 @@ stream_reprojection::stream_reprojection(
|
||||
{
|
||||
.location = 1,
|
||||
.binding = 0,
|
||||
.format = vk::Format::eR32G32Sfloat,
|
||||
.format = vk::Format::eR32G32Uint,
|
||||
.offset = offsetof(vertex, uv),
|
||||
},
|
||||
},
|
||||
.InputAssemblyState = {{
|
||||
.topology = vk::PrimitiveTopology::eTriangleStrip,
|
||||
}},
|
||||
.Viewports = {{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = (float)output_extent.width,
|
||||
.height = (float)output_extent.height,
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
}},
|
||||
.Scissors = {{
|
||||
.offset = {.x = 0, .y = 0},
|
||||
.extent = output_extent,
|
||||
}},
|
||||
.Viewports = {{}},
|
||||
.Scissors = {{}},
|
||||
.RasterizationState = {{
|
||||
.polygonMode = vk::PolygonMode::eFill,
|
||||
.lineWidth = 1,
|
||||
@@ -332,12 +191,109 @@ stream_reprojection::stream_reprojection(
|
||||
.ColorBlendAttachments = {{
|
||||
.colorWriteMask = vk::ColorComponentFlagBits::eR | vk::ColorComponentFlagBits::eG | vk::ColorComponentFlagBits::eB | vk::ColorComponentFlagBits::eA,
|
||||
}},
|
||||
.layout = *layout,
|
||||
.DynamicStates = {vk::DynamicState::eViewport, vk::DynamicState::eScissor},
|
||||
.layout = *target.layout,
|
||||
.renderPass = *renderpass,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
pipeline = vk::raii::Pipeline(device, application::get_pipeline_cache(), pipeline_info);
|
||||
vk::GraphicsPipelineCreateInfo pipeline_info(pipeline_info_builder);
|
||||
|
||||
// Variable fragment shading
|
||||
std::array combiner{
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
};
|
||||
vk::PipelineFragmentShadingRateStateCreateInfoKHR shading{
|
||||
.fragmentSize = vk::Extent2D{1, 1},
|
||||
.combinerOps = combiner,
|
||||
};
|
||||
if (fragment_shading_rate)
|
||||
{
|
||||
pipeline_info.pNext = &shading;
|
||||
|
||||
spdlog::info("Available fragment shading rates:");
|
||||
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
|
||||
{
|
||||
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
|
||||
{
|
||||
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
|
||||
int flags = 0;
|
||||
if (rate.fragmentSize.width == 4)
|
||||
flags |= 8;
|
||||
else if (rate.fragmentSize.width == 2)
|
||||
flags |= 4;
|
||||
if (rate.fragmentSize.height == 4)
|
||||
flags |= 2;
|
||||
else if (rate.fragmentSize.height == 2)
|
||||
flags |= 1;
|
||||
for (int y = std::bit_width(rate.fragmentSize.height) - 1; y < 3; ++y)
|
||||
{
|
||||
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
|
||||
{
|
||||
if (fragment_sizes[x][y] == 0)
|
||||
fragment_sizes[x][y] = flags << 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
target.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||
return target;
|
||||
}
|
||||
|
||||
stream_defoveator::stream_defoveator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
std::vector<vk::Image> output_images_,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format) :
|
||||
device(device),
|
||||
physical_device(physical_device),
|
||||
output_images(std::move(output_images_)),
|
||||
output_extent(output_extent)
|
||||
{
|
||||
// Create renderpass
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_ref{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
vk::SubpassDescription subpass{
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_ref,
|
||||
};
|
||||
|
||||
vk::StructureChain renderpass_info{
|
||||
vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
},
|
||||
};
|
||||
|
||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||
|
||||
vk::DescriptorPoolSize pool_size{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = view_count * 4,
|
||||
};
|
||||
|
||||
ds_pool = device.createDescriptorPool(vk::DescriptorPoolCreateInfo{
|
||||
.maxSets = view_count * 2,
|
||||
.poolSizeCount = 1,
|
||||
.pPoolSizes = &pool_size,
|
||||
});
|
||||
|
||||
// Create image views and framebuffers
|
||||
output_image_views.reserve(output_images.size() * view_count);
|
||||
@@ -390,9 +346,25 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
int destination)
|
||||
uint32_t stream_defoveator::shading_rate(int pixels_x, int pixels_y)
|
||||
{
|
||||
int x = 0;
|
||||
if (pixels_x >= 2)
|
||||
x = 1;
|
||||
if (pixels_x >= 4)
|
||||
x = 2;
|
||||
int y = 0;
|
||||
if (pixels_y >= 2)
|
||||
y = 1;
|
||||
if (pixels_y >= 4)
|
||||
y = 2;
|
||||
return fragment_sizes[x][y];
|
||||
}
|
||||
|
||||
void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
int destination)
|
||||
{
|
||||
if (destination < 0 || destination >= (int)output_images.size())
|
||||
throw std::runtime_error("Invalid destination image index");
|
||||
@@ -401,6 +373,7 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
const auto out_size = defoveated_size(foveation[view]);
|
||||
auto vertices = get_vertices(view);
|
||||
const auto & [px, py] = foveation[view];
|
||||
assert(px.size() % 2 == 1);
|
||||
@@ -408,67 +381,64 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
const int n_ratio_y = (py.size() - 1) / 2;
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
glm::vec2 in(0), out(0); // pixel coordinates
|
||||
glm::vec2 in_pixel_size(1. / input_extent.width,
|
||||
1. / input_extent.height);
|
||||
glm::vec2 out_pixel_size(2. / output_extent.width,
|
||||
2. / output_extent.height);
|
||||
command_buffer.setScissor(
|
||||
0,
|
||||
vk::Rect2D{
|
||||
.extent = {.width = uint32_t(out_size.width), .height = uint32_t(out_size.height)},
|
||||
});
|
||||
command_buffer.setViewport(
|
||||
0,
|
||||
vk::Viewport{
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.width = float(out_size.width),
|
||||
.height = float(out_size.height),
|
||||
.minDepth = 0,
|
||||
.maxDepth = 1,
|
||||
});
|
||||
|
||||
glm::uvec2 in(0);
|
||||
glm::vec2 out(-0.5 * out_size.width, -0.5 * out_size.height); // pixel coordinates
|
||||
glm::vec2 out_pixel_size(2. / out_size.width,
|
||||
2. / out_size.height);
|
||||
for (auto [iy, n_out_y]: utils::enumerate_range(py))
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
|
||||
in.x = 0;
|
||||
out.x = 0;
|
||||
out.x = -0.5 * out_size.width;
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in | rate,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
|
||||
.uv = (in + glm::vec2(0, n_out_y)) * in_pixel_size,
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
}
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
in.y += n_out_y;
|
||||
out.y += n_out_y * ratio_y;
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.uv = in * in_pixel_size,
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
command_buffer.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eTopOfPipe,
|
||||
vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
vk::ImageMemoryBarrier{
|
||||
.srcAccessMask = {},
|
||||
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.image = output_images[destination],
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = view_count,
|
||||
},
|
||||
});
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
vk::RenderPassBeginInfo begin_info{
|
||||
@@ -480,9 +450,49 @@ void stream_reprojection::reproject(vk::raii::CommandBuffer & command_buffer,
|
||||
},
|
||||
};
|
||||
|
||||
const auto & input = inputs[view];
|
||||
auto & pipeline = ensure_pipeline(view, input.sampler_rgb, input.sampler_a);
|
||||
|
||||
std::array image_info{
|
||||
vk::DescriptorImageInfo{
|
||||
.sampler = input.sampler_rgb,
|
||||
.imageView = input.rgb,
|
||||
.imageLayout = input.layout_rgb,
|
||||
},
|
||||
vk::DescriptorImageInfo{
|
||||
.sampler = input.sampler_a,
|
||||
.imageView = input.a,
|
||||
.imageLayout = input.layout_a,
|
||||
},
|
||||
};
|
||||
|
||||
std::array descriptor_writes{
|
||||
vk::WriteDescriptorSet{
|
||||
.dstSet = pipeline.ds,
|
||||
.dstBinding = 0,
|
||||
.descriptorCount = input.sampler_a ? 2u : 1u,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = image_info.data(),
|
||||
},
|
||||
};
|
||||
|
||||
vert_pc pc{
|
||||
.rgb_rect = glm::ivec4(input.rect_rgb.offset.x,
|
||||
input.rect_rgb.offset.y,
|
||||
input.rect_rgb.extent.width,
|
||||
input.rect_rgb.extent.height),
|
||||
.a_rect = glm::ivec4(input.rect_a.offset.x,
|
||||
input.rect_a.offset.y,
|
||||
input.rect_a.extent.width,
|
||||
input.rect_a.extent.height),
|
||||
};
|
||||
|
||||
device.updateDescriptorSets(descriptor_writes, {});
|
||||
|
||||
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.bindPipeline(vk::PipelineBindPoint::eGraphics, *pipeline.pipeline);
|
||||
command_buffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, *pipeline.layout, 0, pipeline.ds, {});
|
||||
command_buffer.pushConstants<vert_pc>(*pipeline.layout, vk::ShaderStageFlagBits::eVertex, 0, pc);
|
||||
command_buffer.bindVertexBuffers(0, vk::Buffer(buffer), vertices_size * view);
|
||||
command_buffer.draw(required_vertices(foveation[view]), 1, 0, 0);
|
||||
command_buffer.endRenderPass();
|
||||
@@ -502,7 +512,7 @@ static uint16_t count_pixels(const std::vector<uint16_t> & param)
|
||||
return res;
|
||||
}
|
||||
|
||||
XrExtent2Di stream_reprojection::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
XrExtent2Di stream_defoveator::defoveated_size(const wivrn::to_headset::foveation_parameter & view) const
|
||||
{
|
||||
return {
|
||||
count_pixels(view.x),
|
||||
@@ -19,34 +19,42 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "blitter.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
class stream_reprojection
|
||||
class stream_defoveator
|
||||
{
|
||||
struct vertex;
|
||||
const uint32_t view_count;
|
||||
static const uint32_t view_count = 2;
|
||||
// Vertex buffer
|
||||
buffer_allocation buffer;
|
||||
size_t vertices_size = 0;
|
||||
|
||||
vk::raii::Device & device;
|
||||
vk::raii::PhysicalDevice & physical_device;
|
||||
|
||||
// Graphic pipeline
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::raii::DescriptorPool descriptor_pool = nullptr;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::RenderPass renderpass = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
vk::raii::DescriptorPool ds_pool = nullptr;
|
||||
struct pipeline_t
|
||||
{
|
||||
vk::raii::DescriptorSetLayout descriptor_set_layout = nullptr;
|
||||
vk::DescriptorSet ds;
|
||||
vk::raii::PipelineLayout layout = nullptr;
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
};
|
||||
pipeline_t pipeline_rgb[view_count];
|
||||
pipeline_t pipeline_a[view_count];
|
||||
|
||||
// Source image
|
||||
vk::raii::Sampler sampler = nullptr;
|
||||
vk::Image input_image;
|
||||
std::vector<vk::raii::ImageView> input_image_views;
|
||||
std::vector<vk::DescriptorSet> descriptor_sets;
|
||||
vk::Extent2D input_extent;
|
||||
// Allowed sizes for variable shading rate
|
||||
// indices are for x, y
|
||||
// 0 is 1 pixel
|
||||
// 1 is 2 or 3 pixels
|
||||
// 2 is 4 pixels or more
|
||||
uint32_t fragment_sizes[3][3] = {};
|
||||
|
||||
// Destination images
|
||||
std::vector<vk::Image> output_images;
|
||||
@@ -57,22 +65,23 @@ class stream_reprojection
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
uint32_t shading_rate(int pixels_x, int pixels_y);
|
||||
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
|
||||
|
||||
public:
|
||||
stream_reprojection(
|
||||
stream_defoveator(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
vk::Image input_image,
|
||||
vk::Extent2D input_extent,
|
||||
uint32_t view_count,
|
||||
std::vector<vk::Image> output_images,
|
||||
vk::Extent2D output_extent,
|
||||
vk::Format format);
|
||||
|
||||
stream_reprojection(const stream_reprojection &) = delete;
|
||||
stream_defoveator(const stream_defoveator &) = delete;
|
||||
|
||||
void reproject(
|
||||
void defoveate(
|
||||
vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
int destination);
|
||||
|
||||
XrExtent2Di defoveated_size(const wivrn::to_headset::foveation_parameter &) const;
|
||||
Reference in New Issue
Block a user