Disable fragment shading rate
Causes artifacts due to triangle edges, the performance gain is not worth it
This commit is contained in:
@@ -761,8 +761,6 @@ void application::initialize_vulkan()
|
|||||||
vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
|
vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
|
||||||
vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
|
vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
|
||||||
optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
|
optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
|
||||||
optional_device_extensions.emplace(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
|
|
||||||
optional_device_extensions.emplace(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
|
|
||||||
optional_device_extensions.emplace(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
|
optional_device_extensions.emplace(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
@@ -881,7 +879,6 @@ void application::initialize_vulkan()
|
|||||||
.ppEnabledExtensionNames = vk_device_extensions.data(),
|
.ppEnabledExtensionNames = vk_device_extensions.data(),
|
||||||
.pEnabledFeatures = &device_features,
|
.pEnabledFeatures = &device_features,
|
||||||
},
|
},
|
||||||
vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{},
|
|
||||||
vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{
|
vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{
|
||||||
.samplerYcbcrConversion = true,
|
.samplerYcbcrConversion = true,
|
||||||
},
|
},
|
||||||
@@ -890,22 +887,6 @@ void application::initialize_vulkan()
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
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))
|
|
||||||
{
|
|
||||||
auto [feat, fragment_feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
|
||||||
auto & create_feat = device_create_info.get<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
|
||||||
create_feat.primitiveFragmentShadingRate = fragment_feat.primitiveFragmentShadingRate;
|
|
||||||
create_feat.attachmentFragmentShadingRate = fragment_feat.attachmentFragmentShadingRate;
|
|
||||||
spdlog::info("Fragment shading rate features: primitive={} attachment={}",
|
|
||||||
create_feat.primitiveFragmentShadingRate,
|
|
||||||
create_feat.attachmentFragmentShadingRate);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
device_create_info.unlink<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (utils::contains(vk_device_extensions, VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME))
|
if (utils::contains(vk_device_extensions, VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME))
|
||||||
{
|
{
|
||||||
auto [_, feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
auto [_, feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "stream_defoveator.h"
|
#include "stream_defoveator.h"
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "utils/contains.h"
|
|
||||||
#include "utils/ranges.h"
|
#include "utils/ranges.h"
|
||||||
#include "vk/allocation.h"
|
#include "vk/allocation.h"
|
||||||
#include "vk/pipeline.h"
|
#include "vk/pipeline.h"
|
||||||
@@ -36,7 +35,7 @@ struct stream_defoveator::vertex
|
|||||||
{
|
{
|
||||||
// output image position
|
// output image position
|
||||||
alignas(8) glm::vec2 position;
|
alignas(8) glm::vec2 position;
|
||||||
// input texture coordinates + shading rate in the first 4 bits of x
|
// input texture coordinates
|
||||||
alignas(8) glm::uvec2 uv;
|
alignas(8) glm::uvec2 uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -119,19 +118,9 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
|
|||||||
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||||
|
|
||||||
const auto & vk_device_extensions = application::get_vk_device_extensions();
|
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))
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vertex shader
|
// Vertex shader
|
||||||
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
vk::raii::ShaderModule vertex_shader = load_shader(device, "reprojection.vert");
|
||||||
|
|
||||||
// Fragment shader
|
// Fragment shader
|
||||||
auto specialization = make_specialization_constants(
|
auto specialization = make_specialization_constants(
|
||||||
@@ -139,7 +128,7 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
|
|||||||
VkBool32(need_srgb_conversion(guess_model())));
|
VkBool32(need_srgb_conversion(guess_model())));
|
||||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
|
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
|
||||||
|
|
||||||
vk::pipeline_builder pipeline_info_builder{
|
vk::pipeline_builder pipeline_info{
|
||||||
.flags = {},
|
.flags = {},
|
||||||
.Stages = {
|
.Stages = {
|
||||||
{
|
{
|
||||||
@@ -197,48 +186,6 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
|
|||||||
.subpass = 0,
|
.subpass = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
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);
|
target.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
@@ -346,21 +293,6 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
|||||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||||
std::span<wivrn::blitter::output> inputs,
|
std::span<wivrn::blitter::output> inputs,
|
||||||
@@ -410,14 +342,13 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
|||||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||||
{
|
{
|
||||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
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++ = {
|
*vertices++ = {
|
||||||
.position = out * out_pixel_size,
|
.position = out * out_pixel_size,
|
||||||
.uv = in | rate,
|
.uv = in,
|
||||||
};
|
};
|
||||||
*vertices++ = {
|
*vertices++ = {
|
||||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
||||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
.uv = (in + glm::uvec2(0, n_out_y)),
|
||||||
};
|
};
|
||||||
in.x += n_out_x;
|
in.x += n_out_x;
|
||||||
out.x += n_out_x * ratio_x;
|
out.x += n_out_x * ratio_x;
|
||||||
|
|||||||
@@ -49,13 +49,6 @@ class stream_defoveator
|
|||||||
pipeline_t pipeline_rgb[view_count];
|
pipeline_t pipeline_rgb[view_count];
|
||||||
pipeline_t pipeline_a[view_count];
|
pipeline_t pipeline_a[view_count];
|
||||||
|
|
||||||
// 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
|
// Destination images
|
||||||
std::vector<vk::Image> output_images;
|
std::vector<vk::Image> output_images;
|
||||||
std::vector<vk::raii::ImageView> output_image_views;
|
std::vector<vk::raii::ImageView> output_image_views;
|
||||||
@@ -65,7 +58,6 @@ class stream_defoveator
|
|||||||
void ensure_vertices(size_t num_vertices);
|
void ensure_vertices(size_t num_vertices);
|
||||||
vertex * get_vertices(size_t view);
|
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);
|
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -1,4 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||||
|
* Copyright (C) 2022 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/>.
|
||||||
|
*/
|
||||||
#version 450
|
#version 450
|
||||||
#extension GL_ARB_shading_language_include : require
|
|
||||||
#define VSR 0
|
#ifdef VERT_SHADER
|
||||||
#include "reprojection.glsl.inc"
|
|
||||||
|
layout (location = 0) in vec2 vPosition;
|
||||||
|
layout (location = 1) in uvec2 vUV;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 outUV;
|
||||||
|
|
||||||
|
layout(push_constant) uniform pc
|
||||||
|
{
|
||||||
|
ivec4 rgb_rect;
|
||||||
|
ivec4 a_rect;
|
||||||
|
};
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(vPosition, 0.0, 1.0);
|
||||||
|
vec2 uv = vUV;
|
||||||
|
outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw;
|
||||||
|
outUV.zw = (uv + a_rect.xy) / a_rect.zw;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FRAG_SHADER
|
||||||
|
|
||||||
|
layout(constant_id = 0) const int alpha = 1;
|
||||||
|
layout(constant_id = 1) const bool do_srgb = false;
|
||||||
|
|
||||||
|
layout(set = 0, binding = 0) uniform sampler2D rgb[alpha + 1];
|
||||||
|
|
||||||
|
layout(location = 0) in vec4 inUV;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
float sRGB_to_linear(float x)
|
||||||
|
{
|
||||||
|
if (x <= 0.04045)
|
||||||
|
return x / 12.92;
|
||||||
|
return pow((x + 0.055) / 1.055, 2.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec4 sRGB_to_linear_rgba(vec4 x)
|
||||||
|
{
|
||||||
|
return vec4(
|
||||||
|
sRGB_to_linear(x.r),
|
||||||
|
sRGB_to_linear(x.g),
|
||||||
|
sRGB_to_linear(x.b),
|
||||||
|
x.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
if (alpha == 1)
|
||||||
|
outColor = vec4(texture(rgb[0], inUV.xy).rgb, texture(rgb[1], inUV.zw).r);
|
||||||
|
else
|
||||||
|
outColor = texture(rgb[0], inUV.xy).rgba;
|
||||||
|
|
||||||
|
if (do_srgb)
|
||||||
|
{
|
||||||
|
outColor = sRGB_to_linear_rgba(outColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* WiVRn VR streaming
|
|
||||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
|
||||||
* Copyright (C) 2022 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef VERT_SHADER
|
|
||||||
|
|
||||||
#if VSR
|
|
||||||
#extension GL_EXT_fragment_shading_rate: enable
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
layout (location = 0) in vec2 vPosition;
|
|
||||||
layout (location = 1) in uvec2 vUV;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outUV;
|
|
||||||
|
|
||||||
layout(push_constant) uniform pc
|
|
||||||
{
|
|
||||||
ivec4 rgb_rect;
|
|
||||||
ivec4 a_rect;
|
|
||||||
};
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(vPosition, 0.0, 1.0);
|
|
||||||
#if VSR
|
|
||||||
gl_PrimitiveShadingRateEXT = int(bitfieldExtract(vUV.x, 28, 4));
|
|
||||||
vec2 uv = bitfieldInsert(vUV, uvec2(0), 28, 4);
|
|
||||||
#else
|
|
||||||
vec2 uv = vUV;
|
|
||||||
#endif
|
|
||||||
outUV.xy = (uv + rgb_rect.xy) / rgb_rect.zw;
|
|
||||||
outUV.zw = (uv + a_rect.xy) / a_rect.zw;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FRAG_SHADER
|
|
||||||
|
|
||||||
layout(constant_id = 0) const int alpha = 1;
|
|
||||||
layout(constant_id = 1) const bool do_srgb = false;
|
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform sampler2D rgb[alpha + 1];
|
|
||||||
|
|
||||||
layout(location = 0) in vec4 inUV;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
|
||||||
|
|
||||||
float sRGB_to_linear(float x)
|
|
||||||
{
|
|
||||||
if (x <= 0.04045)
|
|
||||||
return x / 12.92;
|
|
||||||
return pow((x + 0.055) / 1.055, 2.4);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 sRGB_to_linear_rgba(vec4 x)
|
|
||||||
{
|
|
||||||
return vec4(
|
|
||||||
sRGB_to_linear(x.r),
|
|
||||||
sRGB_to_linear(x.g),
|
|
||||||
sRGB_to_linear(x.b),
|
|
||||||
x.a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
if (alpha == 1)
|
|
||||||
outColor = vec4(texture(rgb[0], inUV.xy).rgb, texture(rgb[1], inUV.zw).r);
|
|
||||||
else
|
|
||||||
outColor = texture(rgb[0], inUV.xy).rgba;
|
|
||||||
|
|
||||||
if (do_srgb)
|
|
||||||
{
|
|
||||||
outColor = sRGB_to_linear_rgba(outColor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#version 450
|
|
||||||
#extension GL_ARB_shading_language_include : require
|
|
||||||
#define VSR 1
|
|
||||||
#include "reprojection.glsl.inc"
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user