From 4ecd6abf784db8e99b94da8f4cce2cd877310b37 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 14 Nov 2023 12:24:46 +0100 Subject: [PATCH] Vulkan: Make Anisotropy Sampling Optional Anisotropy samplers are optional in Vulkan. This change will disable anisotropy samplers when the feature isn't available on the device. The support for anisotropy samplers is around 90% so would not expect any compatibility issues. Pull Request: https://projects.blender.org/blender/blender/pulls/114833 --- intern/ghost/intern/GHOST_ContextVK.cc | 1 + source/blender/gpu/vulkan/vk_sampler.cc | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/intern/ghost/intern/GHOST_ContextVK.cc b/intern/ghost/intern/GHOST_ContextVK.cc index 5517e8df474..210e5439581 100644 --- a/intern/ghost/intern/GHOST_ContextVK.cc +++ b/intern/ghost/intern/GHOST_ContextVK.cc @@ -233,6 +233,7 @@ class GHOST_DeviceVK { #endif device_features.drawIndirectFirstInstance = VK_TRUE; device_features.fragmentStoresAndAtomics = VK_TRUE; + device_features.samplerAnisotropy = features.features.samplerAnisotropy; VkDeviceCreateInfo device_create_info = {}; device_create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; diff --git a/source/blender/gpu/vulkan/vk_sampler.cc b/source/blender/gpu/vulkan/vk_sampler.cc index f89e72d405c..79813a62ada 100644 --- a/source/blender/gpu/vulkan/vk_sampler.cc +++ b/source/blender/gpu/vulkan/vk_sampler.cc @@ -24,6 +24,8 @@ void VKSampler::create(const GPUSamplerState &sampler_state) BLI_assert(sampler_state.type != GPU_SAMPLER_STATE_TYPE_INTERNAL); BLI_assert(vk_sampler_ == VK_NULL_HANDLE); + const VKDevice &device = VKBackend::get().device_get(); + VkSamplerCreateInfo sampler_info = {}; sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO; @@ -36,7 +38,9 @@ void VKSampler::create(const GPUSamplerState &sampler_state) if (sampler_state.filtering & GPU_SAMPLER_FILTERING_MIPMAP) { sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; } - if (sampler_state.filtering & GPU_SAMPLER_FILTERING_ANISOTROPIC) { + if (device.physical_device_features_get().samplerAnisotropy == VK_TRUE && + sampler_state.filtering & GPU_SAMPLER_FILTERING_ANISOTROPIC) + { sampler_info.anisotropyEnable = VK_TRUE; sampler_info.maxAnisotropy = min_ff(1.0f, U.anisotropic_filter); } @@ -65,7 +69,6 @@ void VKSampler::create(const GPUSamplerState &sampler_state) } VK_ALLOCATION_CALLBACKS - const VKDevice &device = VKBackend::get().device_get(); vkCreateSampler(device.device_get(), &sampler_info, vk_allocation_callbacks, &vk_sampler_); debug::object_label(vk_sampler_, sampler_state.to_string().c_str()); }