Merge branch 'sync' into sneed

This commit is contained in:
Vindicus999
2026-07-01 07:10:14 -04:00
52 changed files with 2365 additions and 289 deletions
+20 -1
View File
@@ -174,8 +174,11 @@ active_runtime::active_runtime() :
try
{
auto ovr_compat = openvr_compat_path();
if (not ovr_compat.empty())
if (ovr_compat.empty())
std::cerr << "Not setting an OpenVR compatibility library" << std::endl;
else
{
std::cerr << "Setting the OpenVR compatibility library to " << ovr_compat.native() << std::endl;
if (not wivrn::is_flatpak())
{
auto vrclient = ovr_compat / "bin"
@@ -235,4 +238,20 @@ active_runtime::~active_runtime()
std::cerr << "Cannot unset active OpenVR runtime: " << e.what() << std::endl;
}
}
void active_runtime::cleanup_openxr()
{
for (const auto & manifest: manifest_path())
{
auto active_runtime = xdg_config_home() / ("openxr/1/active_runtime" + get_abi(manifest) + ".json");
std::error_code ec;
if (std::filesystem::equivalent(manifest, active_runtime, ec))
{
std::cerr << "Removing stale file " << active_runtime << std::endl;
std::filesystem::remove(active_runtime, ec);
}
std::filesystem::rename(backup_name(manifest), manifest, ec);
}
}
} // namespace wivrn
+2
View File
@@ -39,5 +39,7 @@ public:
static std::vector<std::filesystem::path> manifest_path();
static std::filesystem::path openvr_compat_path();
static void cleanup_openxr();
};
} // namespace wivrn
+12 -8
View File
@@ -293,7 +293,7 @@ xrt_result_t compositor::layer_commit(xrt_graphics_sync_handle_t sync_handle)
U_LOG_IFL_D(log_level, "frame %ld commit %d layers", frame.rendering.id, layer_accum.layer_count);
if (encode_request >= 0 // encoders have not picked up the previous frame
or layer_accum.layer_count == 0 or not session.connected() or not session.get_offset())
or not session.connected() or not session.get_offset())
{
comp_frame_clear_locked(&frame.rendering);
return XRT_SUCCESS;
@@ -558,14 +558,18 @@ xrt_result_t compositor::get_display_refresh_rate(float * hz)
xrt_result_t compositor::request_display_refresh_rate(float hz)
{
try
requested_refresh_rate = hz;
U_LOG_I("request refresh rate: %fHz", hz);
if (hz > 0)
{
requested_refresh_rate = hz;
session.send_control(to_headset::refresh_rate_change{.hz = hz});
}
catch (std::exception & e)
{
U_LOG_W("refresh rate change failed: %s", e.what());
try
{
session.send_control(to_headset::refresh_rate_change{.hz = hz});
}
catch (std::exception & e)
{
U_LOG_W("refresh rate change failed: %s", e.what());
}
}
return XRT_SUCCESS;
}
+40 -22
View File
@@ -21,6 +21,7 @@
#include "driver/xrt_cast.h"
#include "utils/wivrn_vk_bundle.h"
#include "vk/specialization_constants.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
@@ -41,8 +42,6 @@ struct ubo_data
{
uint32_t x[XRT_MAX_VIEWS * RENDER_FOVEATION_BUFFER_DIMENSIONS];
uint32_t y[XRT_MAX_VIEWS * RENDER_FOVEATION_BUFFER_DIMENSIONS];
uint32_t alpha_width;
VkBool32 alpha;
};
vk::raii::Sampler make_sampler(wivrn::vk_bundle & vk)
@@ -112,20 +111,39 @@ vk::raii::PipelineLayout make_layout(wivrn::vk_bundle & vk, vk::DescriptorSetLay
return res;
}
vk::raii::Pipeline make_pipeline(wivrn::vk_bundle & vk, vk::PipelineLayout layout)
std::array<vk::raii::Pipeline, 2> make_pipelines(wivrn::vk_bundle & vk, vk::PipelineLayout layout, int32_t alpha_width)
{
vk::raii::Pipeline res(
vk.device,
nullptr,
vk::ComputePipelineCreateInfo{
.stage = {
.stage = vk::ShaderStageFlagBits::eCompute,
.module = *vk.load_shader("foveation"),
.pName = "main",
auto shader = vk.load_shader("foveation");
auto spc = make_specialization_constants(alpha_width);
std::array res{
vk::raii::Pipeline{
vk.device,
nullptr,
vk::ComputePipelineCreateInfo{
.stage = {
.stage = vk::ShaderStageFlagBits::eCompute,
.module = *shader,
.pName = "main",
},
.layout = layout,
},
.layout = layout,
});
vk.name(*res, "foveation pipeline");
},
vk::raii::Pipeline{
vk.device,
nullptr,
vk::ComputePipelineCreateInfo{
.stage = {
.stage = vk::ShaderStageFlagBits::eCompute,
.module = *shader,
.pName = "main",
.pSpecializationInfo = spc,
},
.layout = layout,
},
},
};
vk.name(*res[0], "foveation pipeline");
vk.name(*res[1], "foveation+alpha pipeline");
return res;
}
@@ -390,14 +408,14 @@ foveation::foveation(wivrn::vk_bundle & bundle, vk::Extent3D foveated_size) :
.usage = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
},
"foveation storage buffer"),
sampler(make_sampler(bundle)),
ds_layout(make_ds_layout(bundle)),
layout(make_layout(bundle, ds_layout)),
pipeline(make_pipeline(bundle, layout)),
pipeline(make_pipelines(bundle, layout, foveated_size.width / 2)),
descriptor_pool(make_ds_pool(bundle)),
descriptor_set(bundle.device.allocateDescriptorSets(vk::DescriptorSetAllocateInfo{
.descriptorPool = descriptor_pool,
@@ -517,7 +535,7 @@ void foveation::update_ubo(
compute_params();
auto ubo = gpu_buffer.data<ubo_data>();
ubo_data ubo;
for (size_t view = 0; view < 2; ++view)
{
bool flip = false;
@@ -534,7 +552,7 @@ void foveation::update_ubo(
offset = src_rect[view].offset.w;
extent = src_rect[view].extent.w;
}
fill_ubo(std::span(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS),
fill_ubo(std::span(ubo.x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS),
params[view].x,
flip,
offset,
@@ -553,13 +571,15 @@ void foveation::update_ubo(
offset = src_rect[view].offset.h;
extent = src_rect[view].extent.h;
}
fill_ubo(std::span(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS),
fill_ubo(std::span(ubo.y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS),
params[view].y,
flip,
offset,
extent,
foveated_size.height);
}
vmaCopyMemoryToAllocation(vk_allocator::instance(), &ubo, gpu_buffer, 0, sizeof(ubo));
std::memcpy(gpu_buffer.data<ubo_data>(), &ubo, sizeof(ubo));
}
std::array<to_headset::foveation_parameter, 2> foveation::foveate(
@@ -575,8 +595,6 @@ std::array<to_headset::foveation_parameter, 2> foveation::foveate(
{
update_ubo(cmd, flip_y, src_rect, src_fov);
auto ubo = gpu_buffer.data<ubo_data>();
ubo->alpha_width = foveated_size.width / 2;
ubo->alpha = alpha;
std::array src_image_info{
vk::DescriptorImageInfo{
@@ -638,7 +656,7 @@ std::array<to_headset::foveation_parameter, 2> foveation::foveate(
device.updateDescriptorSets(writes, {});
cmd.bindPipeline(vk::PipelineBindPoint::eCompute, *pipeline);
cmd.bindPipeline(vk::PipelineBindPoint::eCompute, *pipeline[alpha]);
cmd.bindDescriptorSets(vk::PipelineBindPoint::eCompute, *layout, 0, descriptor_set, {});
cmd.dispatch(divide_and_round_up(foveated_size.width, 8),
divide_and_round_up(foveated_size.height, 8),
+1 -1
View File
@@ -55,7 +55,7 @@ class foveation
vk::raii::DescriptorSetLayout ds_layout;
vk::raii::PipelineLayout layout;
vk::raii::Pipeline pipeline;
std::array<vk::raii::Pipeline, 2> pipeline;
vk::raii::DescriptorPool descriptor_pool;
vk::DescriptorSet descriptor_set;
+4 -1
View File
@@ -614,7 +614,10 @@ layer_squasher::do_layers(
writes[0].descriptorCount = image_array_size;
}
device.updateDescriptorSets(writes, {});
if (writes[0].descriptorCount == 0)
device.updateDescriptorSets(std::span(writes).subspan(1), {});
else
device.updateDescriptorSets(writes, {});
cmd.bindDescriptorSets(vk::PipelineBindPoint::eCompute, *layout, 0, descriptor_sets[view], {});
auto [w, h] = calc_dispatch_dims_1_view(viewports[view]);
+30 -18
View File
@@ -35,14 +35,13 @@ layout(set = 0, binding = 1, std430) buffer restrict Config
// foveation parameters
uint x[2*MAX_DIM];
uint y[2*MAX_DIM];
// output parameters
uint alpha_width;
bool alpha;
} ubo;
layout(set = 0, binding = 2) uniform writeonly restrict image2DArray luma;
layout(set = 0, binding = 3) uniform writeonly restrict image2DArray chroma;
layout(constant_id = 0) const int alpha_width = 0;
const mat3 color_space = mat3(
// R G B
/* Y */ 0.2126, 0.7152, 0.0722,
@@ -72,24 +71,38 @@ vec3 from_linear_to_srgb(vec3 linear_rgb)
);
}
uint ABfe(uint src,uint off,uint bits){return bitfieldExtract(src,int(off),int(bits));}
uint ABfiM(uint src,uint ins,uint bits){return bitfieldInsert(src,ins,0,int (bits));}
// More complex remap 64x1 to 8x8 which is necessary for 2D wave reductions.
// 543210
// ======
// .xx..x
// y..yy.
// Details,
// LANE TO 8x8 MAPPING
// ===================
// 00 01 08 09 10 11 18 19
// 02 03 0a 0b 12 13 1a 1b
// 04 05 0c 0d 14 15 1c 1d
// 06 07 0e 0f 16 17 1e 1f
// 20 21 28 29 30 31 38 39
// 22 23 2a 2b 32 33 3a 3b
// 24 25 2c 2d 34 35 3c 3d
// 26 27 2e 2f 36 37 3e 3f
uint ARmpRed8x8_x(uint a){return ABfiM(ABfe(a,2u,3u),a,1u);}
uint ARmpRed8x8_y(uint a){return ABfiM(ABfe(a,3u,3u),ABfe(a,1u,2u),2u);}
//uvec2 ARmpRed8x8(uint32_t a){return uvec2(ABfiM(ABfe(a,2u,3u),a,1u),ABfiM(ABfe(a,3u,3u),ABfe(a,1u,2u),2u));}
void main()
{
uint iz = gl_GlobalInvocationID.z;
// In order to know how subgroup are mapped, we have to do the swizzling ourselves
// in the work group, consider pixels in the following order:
//
// 0 1 4 5 8 9 12 13
// 2 3 6 7 10 11 14 15
// 16 17 20 21 24 25 28 29
// 18 19 22 23 26 27 30 31
// ...
// in the work group.
uint id = gl_SubgroupID * gl_SubgroupSize + gl_SubgroupInvocationID;
uint quad = id / 4;
id -= 4 * quad;
uint iy = gl_WorkGroupID.y * gl_WorkGroupSize.y + ARmpRed8x8_y(id);
uint ix = gl_WorkGroupID.x * gl_WorkGroupSize.x + ARmpRed8x8_x(id);
uint iy = gl_WorkGroupID.y * gl_WorkGroupSize.y + 2 * uint(quad / (gl_WorkGroupSize.y / 2)) + id / 2;
uint ymin = ubo.y[MAX_DIM * iz + iy];
uint ymax = ubo.y[MAX_DIM * iz + iy + 1];
if (ymin > ymax)
@@ -98,7 +111,6 @@ void main()
ymin = ymax;
ymax = tmp;
}
uint ix = gl_WorkGroupID.x * gl_WorkGroupSize.x + 2 * (quad % (gl_WorkGroupSize.y / 2)) + (id % 2);
uint xmin = ubo.x[MAX_DIM * iz + ix];
uint xmax = ubo.x[MAX_DIM * iz + ix + 1];
@@ -121,15 +133,15 @@ void main()
vec4 sum = colour + subgroupShuffleDown(colour, 1) + subgroupShuffleDown(colour, 2) + subgroupShuffleDown(colour, 3);
if (id == 0)
if ((id % 4)== 0)
{
// actual chroma
imageStore(chroma, ivec3(ix/2, iy/2, iz), vec4(sum.y, sum.z, 0, 0) / 4);
if (ubo.alpha)
if (alpha_width > 0)
{
// alpha in luma
int offset = int(ubo.alpha_width * iz);
int offset = alpha_width * int(iz);
imageStore(luma, ivec3(offset + ix/2, iy/2, 2), vec4(sum.w, 0, 0, 0) / 4);
imageStore(chroma, ivec3(offset + ix/2, iy/2, 2), vec4(0.5, 0.5, 0, 0));
}
+11 -5
View File
@@ -40,6 +40,7 @@
#include "wivrn_packets.h"
#include "xr/to_string.h"
#include "b_hand_tracker.h"
#include "b_system.h"
#include "target_builder_helpers.h"
#include "util/u_logging.h"
@@ -78,6 +79,7 @@ bool is_forced_extension(const char * ext_name)
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, b_system & system) :
xrt_system_devices{
.get_roles = method_pointer<&wivrn_session::get_roles>,
.create_hand_tracker = b_hand_tracker_create,
.feature_inc = method_pointer<&wivrn_session::feature_inc>,
.feature_dec = method_pointer<&wivrn_session::feature_dec>,
.destroy = method_pointer<&wivrn_session::destroy>,
@@ -401,11 +403,15 @@ void wivrn_session::resume_session()
if (target_fps != current_fps)
{
auto s = settings.lock();
(*this)(from_headset::refresh_rate_changed{
.from = current_fps * s->fps_divider,
.to = target_fps * s->fps_divider,
});
compositor.set_framerate(target_fps);
push_event(
{
.display = {
.type = XRT_SESSION_EVENT_DISPLAY_REFRESH_RATE_CHANGE,
.from_display_refresh_rate_hz = current_fps,
.to_display_refresh_rate_hz = target_fps,
},
});
}
}
+6 -11
View File
@@ -133,13 +133,6 @@ static bool pressure_vessel_openxr_support()
return pv_var and pv_var == std::string_view("1");
}
static void append_delim(std::string & to, std::string_view what, char delim)
{
if (not to.empty())
to += delim;
to += what;
}
// search for the directory in path named needle
// with d = /a/b/c/d/e and needle = c
// return /a/b/c
@@ -159,7 +152,7 @@ static std::string steam_command()
std::string command;
if (not pressure_vessel_openxr_support())
command = "PRESSURE_VESSEL_IMPORT_OPENXR_1_RUNTIMES=1";
command = "PRESSURE_VESSEL_IMPORT_OPENXR_1_RUNTIMES=1 ";
std::string_view home{"\0", 1};
if (auto h = std::getenv("HOME"))
@@ -169,13 +162,13 @@ static std::string steam_command()
{
// /usr cannot be shared in pressure vessel container
if (p.starts_with("/usr"))
append_delim(command, " VR_OVERRIDE=/run/host" + p, ' ');
command += "VR_OVERRIDE=/run/host" + p + ' ';
else if (p.starts_with("/var") and not p.starts_with(home))
append_delim(command, "PRESSURE_VESSEL_FILESYSTEMS_RW=" + find_dir(p, "io.github.wivrn.wivrn").string(), ' ');
command += "PRESSURE_VESSEL_FILESYSTEMS_RW=" + find_dir(p, "io.github.wivrn.wivrn").string() + ' ';
}
if (not command.empty())
command += " %command%";
command += "%command%";
return command;
}
@@ -949,6 +942,8 @@ int inner_main(int argc, char * argv[], bool show_instructions)
std::filesystem::create_directories(socket_path().parent_path());
if (do_active_runtime)
active_runtime::cleanup_openxr();
listen_socket = create_listen_socket();
u_trace_marker_init();
+1 -1
View File
@@ -123,7 +123,7 @@ int get_queue_index(const std::vector<vk::QueueFamilyProperties> & queues, std::
auto count = queues.at(family_index).queueCount;
if (info.queueCount == count)
{
U_LOG_W("Insufficient vulkan queues for family %d", family_index);
U_LOG_D("Insufficient vulkan queues for family %d", family_index);
return -1;
}
return info.queueCount++;