Rebase almost everything to Master

This commit is contained in:
Vindicus999
2025-09-25 09:16:54 -04:00
parent 492ed88ae2
commit cf3c364b42
129 changed files with 13067 additions and 4431 deletions
+47 -35
View File
@@ -18,7 +18,6 @@
*/
#include "render/render_interface.h"
#include "vk/vk_mini_helpers.h"
#include "wivrn_foveation.h"
@@ -45,22 +44,13 @@ bool render_distortion_images_ensure(struct render_resources * r,
bool pre_rotate)
{
if (r->distortion.buffer == VK_NULL_HANDLE)
{
return vk_buffer_init(vk,
sizeof(render_compute_distortion_foveation_data),
VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
&r->distortion.buffer,
&r->distortion.device_memory);
}
r->distortion.buffer = wivrn::wivrn_foveation::instance().get_gpu_buffer();
return true;
}
void render_distortion_images_fini(struct render_resources * r)
{
auto * vk = r->vk;
D(Buffer, r->distortion.buffer);
DF(Memory, r->distortion.device_memory);
r->distortion.buffer = VK_NULL_HANDLE;
}
// a, b: parameters computed by solve_foveation
@@ -321,20 +311,34 @@ wivrn_foveation::wivrn_foveation(wivrn_vk_bundle & bundle, const xrt_hmd_parts &
.commandPool = *command_pool,
.commandBufferCount = 1,
})[0])),
host_buffer(
gpu_buffer(
bundle.device,
{
.size = sizeof(render_compute_distortion_foveation_data),
.usage = vk::BufferUsageFlagBits::eTransferSrc,
.usage = vk::BufferUsageFlagBits::eTransferDst | vk::BufferUsageFlagBits::eStorageBuffer,
},
VmaAllocationCreateInfo{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_ALLOW_TRANSFER_INSTEAD_BIT,
.usage = VMA_MEMORY_USAGE_AUTO,
})
},
"foveation storage buffer")
{
if (not(gpu_buffer.properties() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT))
{
host_buffer = buffer_allocation(
bundle.device,
{
.size = gpu_buffer.info().size,
.usage = vk::BufferUsageFlagBits::eTransferSrc,
},
{
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST,
},
"foveation staging buffer");
}
bundle.name(command_pool, "foveation command pool");
bundle.name(cmd, "foveation command buffer");
bundle.name(vk::Buffer(host_buffer), "foveation staging buffer");
}
void wivrn_foveation::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
@@ -390,7 +394,7 @@ std::array<to_headset::foveation_parameter, 2> wivrn_foveation::get_parameters()
}
static void fill_ubo(
uint32_t * ubo,
std::span<uint32_t> ubo,
const std::vector<uint16_t> & params,
bool flip,
size_t offset,
@@ -399,9 +403,9 @@ static void fill_ubo(
{
assert(params.size() % 2 == 1);
const int n_ratio = (params.size() - 1) / 2;
*ubo = offset;
ubo[0] = offset;
if (flip)
*ubo += size;
ubo[0] += size;
for (auto [i, n]: std::ranges::enumerate_view(params))
{
const int n_source = std::abs(n_ratio - int(i)) + 1;
@@ -412,12 +416,12 @@ static void fill_ubo(
ubo[1] = ubo[0] - n_source;
else
ubo[1] = ubo[0] + n_source;
++ubo;
ubo = ubo.subspan(1);
--count;
}
}
if (count > 0)
std::fill(ubo + 1, ubo + count + 1, *ubo);
if (not ubo.empty())
std::ranges::fill(ubo, ubo[0]);
}
template <typename T>
@@ -435,6 +439,11 @@ static bool operator==(const xrt_fov & a, const xrt_fov & b)
return a.angle_left == b.angle_left and a.angle_right == b.angle_right and a.angle_up == b.angle_up and a.angle_down == b.angle_down;
}
vk::Buffer wivrn_foveation::get_gpu_buffer()
{
return gpu_buffer;
}
vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
vk::Buffer target,
bool flip_y,
@@ -444,14 +453,6 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
if (not target)
return nullptr;
if (target != gpu_buffer)
{
command_pool.reset();
cmd.begin({});
cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)});
cmd.end();
}
// Check if the last value is still valid
std::lock_guard lock(mutex);
if (last.flip_y == flip_y //
@@ -468,6 +469,15 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
)
return nullptr;
assert(target == gpu_buffer);
if (host_buffer)
{
command_pool.reset();
cmd.begin({});
cmd.copyBuffer(host_buffer, target, vk::BufferCopy{.size = sizeof(render_compute_distortion_foveation_data)});
cmd.end();
}
last = {
.gaze = gaze,
.flip_y = flip_y,
@@ -479,7 +489,7 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
compute_params(source, fovs);
auto ubo = (render_compute_distortion_foveation_data *)host_buffer.map();
auto ubo = host_buffer ? host_buffer.data<render_compute_distortion_foveation_data>() : gpu_buffer.data<render_compute_distortion_foveation_data>();
for (size_t view = 0; view < 2; ++view)
{
bool flip = false;
@@ -496,7 +506,7 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
offset = source[view].offset.w;
extent = source[view].extent.w;
}
fill_ubo(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].x, flip, offset, extent, foveated_width);
fill_ubo(std::span(ubo->x + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS), params[view].x, flip, offset, extent, foveated_width);
if (source[view].extent.h < 0)
{
@@ -510,8 +520,10 @@ vk::CommandBuffer wivrn_foveation::update_foveation_buffer(
offset = source[view].offset.h;
extent = source[view].extent.h;
}
fill_ubo(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, params[view].y, flip, offset, extent, foveated_height);
fill_ubo(std::span(ubo->y + view * RENDER_FOVEATION_BUFFER_DIMENSIONS, RENDER_FOVEATION_BUFFER_DIMENSIONS), params[view].y, flip, offset, extent, foveated_height);
}
return *cmd;
if (host_buffer)
return *cmd;
return nullptr;
}
} // namespace wivrn