From 0cc54b8e715c5be85afe5d1da8480119f3a09e31 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Wed, 7 Aug 2024 18:39:32 +0200 Subject: [PATCH] Enable cubic sampling when available --- client/application.cpp | 27 +++++++++++++++------------ client/application.h | 6 ++++++ client/scenes/stream_reprojection.cpp | 4 ++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/client/application.cpp b/client/application.cpp index a095c8d6..1d0fdace 100644 --- a/client/application.cpp +++ b/client/application.cpp @@ -388,7 +388,7 @@ void application::initialize_vulkan() #endif std::vector instance_extensions{}; - std::vector device_extensions{}; + std::unordered_set optional_device_extensions{}; #ifndef NDEBUG bool debug_report_found = false; @@ -418,17 +418,18 @@ void application::initialize_vulkan() } #endif - device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME); + optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME); #ifdef __ANDROID__ - device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME); - device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME); - device_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME); - device_extensions.push_back(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME); - device_extensions.push_back(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME); - device_extensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME); - device_extensions.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME); - device_extensions.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME); + vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME); + vk_device_extensions.push_back(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_MAINTENANCE1_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_BIND_MEMORY_2_EXTENSION_NAME); + vk_device_extensions.push_back(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME); instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); instance_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME); #endif @@ -488,6 +489,8 @@ void application::initialize_vulkan() for (vk::ExtensionProperties & i: vk_physical_device.enumerateDeviceExtensionProperties()) { spdlog::info(" {}", i.extensionName); + if (auto it = optional_device_extensions.find(i.extensionName); it != optional_device_extensions.end()) + vk_device_extensions.push_back(it->data()); } vk::PhysicalDeviceProperties prop = vk_physical_device.getProperties(); @@ -524,8 +527,8 @@ void application::initialize_vulkan() vk::DeviceCreateInfo{ .queueCreateInfoCount = 1, .pQueueCreateInfos = &queueCreateInfo, - .enabledExtensionCount = (uint32_t)device_extensions.size(), - .ppEnabledExtensionNames = device_extensions.data(), + .enabledExtensionCount = (uint32_t)vk_device_extensions.size(), + .ppEnabledExtensionNames = vk_device_extensions.data(), .pEnabledFeatures = &device_features, }, #ifdef __ANDROID__ diff --git a/client/application.h b/client/application.h index 8e78e779..cd7eca70 100644 --- a/client/application.h +++ b/client/application.h @@ -134,6 +134,7 @@ class application : public singleton bool session_visible = false; bool debug_extensions_found = false; std::vector xr_extensions; + std::vector vk_device_extensions; std::atomic exit_requested = false; std::filesystem::path config_path; std::filesystem::path cache_path; @@ -431,6 +432,11 @@ public: return instance().xr_extensions; } + static const std::vector & get_vk_device_extensions() + { + return instance().vk_device_extensions; + } + static configuration & get_config() { assert(instance().config); diff --git a/client/scenes/stream_reprojection.cpp b/client/scenes/stream_reprojection.cpp index 67ba47b2..658b11a0 100644 --- a/client/scenes/stream_reprojection.cpp +++ b/client/scenes/stream_reprojection.cpp @@ -19,6 +19,7 @@ #include "stream_reprojection.h" #include "application.h" +#include "utils/contains.h" #include "vk/allocation.h" #include "vk/pipeline.h" #include "vk/shader.h" @@ -75,6 +76,9 @@ stream_reprojection::stream_reprojection( .unnormalizedCoordinates = VK_FALSE, }; + if (utils::contains(application::get_vk_device_extensions(), VK_IMG_FILTER_CUBIC_EXTENSION_NAME)) + sampler_info.magFilter = vk::Filter::eCubicIMG; + sampler = vk::raii::Sampler(device, sampler_info); size_t uniform_size = sizeof(uniform) + properties.limits.minUniformBufferOffsetAlignment - 1;