Merge branch 'sync' into sneed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user