Fix shader fragment rate vulkan validation error
This commit is contained in:
@@ -214,8 +214,20 @@ stream_reprojection::stream_reprojection(
|
|||||||
|
|
||||||
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
renderpass = vk::raii::RenderPass(device, renderpass_info.get());
|
||||||
|
|
||||||
|
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, "reprojection.vert");
|
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
||||||
|
|
||||||
// Fragment shader
|
// Fragment shader
|
||||||
|
|
||||||
@@ -317,40 +329,31 @@ stream_reprojection::stream_reprojection(
|
|||||||
.fragmentSize = vk::Extent2D{1, 1},
|
.fragmentSize = vk::Extent2D{1, 1},
|
||||||
.combinerOps = combiner,
|
.combinerOps = combiner,
|
||||||
};
|
};
|
||||||
const auto & vk_device_extensions = application::get_vk_device_extensions();
|
if (fragment_shading_rate)
|
||||||
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>();
|
pipeline_info.pNext = &shading;
|
||||||
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
|
||||||
if (rate_prop.fragmentShadingRateNonTrivialCombinerOps and
|
|
||||||
fragment_feat.primitiveFragmentShadingRate and
|
|
||||||
fragment_feat.attachmentFragmentShadingRate)
|
|
||||||
{
|
|
||||||
pipeline_info.pNext = &shading;
|
|
||||||
|
|
||||||
spdlog::info("Available fragment shading rates:");
|
spdlog::info("Available fragment shading rates:");
|
||||||
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
|
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
|
||||||
|
{
|
||||||
|
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
|
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
|
||||||
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;
|
||||||
if (fragment_sizes[x][y] == 0)
|
|
||||||
fragment_sizes[x][y] = flags;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,4 @@
|
|||||||
/*
|
|
||||||
* 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
|
||||||
#extension GL_EXT_fragment_shading_rate: require
|
#define VSR 0
|
||||||
#ifdef VERT_SHADER
|
#include "reprojection.glsl.inc"
|
||||||
|
|
||||||
layout (location = 0) in vec2 vPosition;
|
|
||||||
layout (location = 1) in vec2 vUV;
|
|
||||||
layout (location = 2) in int vShadingRate;
|
|
||||||
|
|
||||||
layout(location = 0) out vec2 outUV;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(vPosition, 0.0, 1.0);
|
|
||||||
outUV = vUV;
|
|
||||||
gl_PrimitiveShadingRateEXT = vShadingRate;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef FRAG_SHADER
|
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform sampler2D texSampler;
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 inUV;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
outColor = texture(texSampler, inUV).rgba;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* 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 vec2 vUV;
|
||||||
|
layout (location = 2) in int vShadingRate;
|
||||||
|
|
||||||
|
layout(location = 0) out vec2 outUV;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vec4(vPosition, 0.0, 1.0);
|
||||||
|
outUV = vUV;
|
||||||
|
#if VSR
|
||||||
|
gl_PrimitiveShadingRateEXT = vShadingRate;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef FRAG_SHADER
|
||||||
|
|
||||||
|
layout(set = 0, binding = 0) uniform sampler2D texSampler;
|
||||||
|
|
||||||
|
layout(location = 0) in vec2 inUV;
|
||||||
|
|
||||||
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
outColor = texture(texSampler, inUV).rgba;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#version 450
|
||||||
|
#extension GL_ARB_shading_language_include : require
|
||||||
|
#define VSR 1
|
||||||
|
#include "reprojection.glsl.inc"
|
||||||
|
|
||||||
Reference in New Issue
Block a user