Use specialization constant for alpha/non-alpha
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -397,7 +415,7 @@ foveation::foveation(wivrn::vk_bundle & bundle, vk::Extent3D foveated_size) :
|
||||
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,
|
||||
@@ -577,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{
|
||||
@@ -640,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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
@@ -139,10 +138,10 @@ void main()
|
||||
// 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