Flutter Engine
The Flutter Engine
GrVkSampler.cpp
Go to the documentation of this file.
1/*
2* Copyright 2016 Google Inc.
3*
4* Use of this source code is governed by a BSD-style license that can be
5* found in the LICENSE file.
6*/
7
9
12
14 switch (wrapMode) {
23 }
25}
26
28 switch (mm) {
29 // There is no disable mode. We use max level to disable mip mapping.
30 // It may make more sense to use NEAREST for kNone but Chrome pixel tests seam dependent
31 // on subtle rendering differences introduced by switching this.
35 }
37}
38
40 GrSamplerState samplerState,
41 const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo) {
42 static VkFilter vkMinFilterModes[] = {
46 };
47 static VkFilter vkMagFilterModes[] = {
51 };
52
53 VkSamplerCreateInfo createInfo;
54 memset(&createInfo, 0, sizeof(VkSamplerCreateInfo));
56 createInfo.pNext = nullptr;
57 createInfo.flags = 0;
58 createInfo.magFilter = vkMagFilterModes[static_cast<int>(samplerState.filter())];
59 createInfo.minFilter = vkMinFilterModes[static_cast<int>(samplerState.filter())];
61 createInfo.addressModeU = wrap_mode_to_vk_sampler_address(samplerState.wrapModeX());
62 createInfo.addressModeV = wrap_mode_to_vk_sampler_address(samplerState.wrapModeY());
63 createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; // Shouldn't matter
64 createInfo.mipLodBias = 0.0f;
65 createInfo.anisotropyEnable = samplerState.isAniso() ? VK_TRUE : VK_FALSE;
66 createInfo.maxAnisotropy = std::min(static_cast<float>(samplerState.maxAniso()),
68 createInfo.compareEnable = VK_FALSE;
69 createInfo.compareOp = VK_COMPARE_OP_NEVER;
70 // Vulkan doesn't have a direct mapping of GL's nearest or linear filters for minFilter since
71 // there is always a mipmapMode. To get the same effect as GL we can set minLod = maxLod = 0.0.
72 // This works since our min and mag filters are the same (this forces us to use mag on the 0
73 // level mip). If the filters weren't the same we could set min = 0 and max = 0.25 to force
74 // the minFilter on mip level 0.
75 createInfo.minLod = 0.0f;
76 bool useMipMaps = samplerState.mipmapped() == skgpu::Mipmapped::kYes;
77 createInfo.maxLod = !useMipMaps ? 0.0f : 10000.0f;
80
81 VkSamplerYcbcrConversionInfo conversionInfo;
82 GrVkSamplerYcbcrConversion* ycbcrConversion = nullptr;
83 if (ycbcrInfo.isValid()) {
85
86 ycbcrConversion =
88 if (!ycbcrConversion) {
89 return nullptr;
90 }
91
93 conversionInfo.pNext = nullptr;
94 conversionInfo.conversion = ycbcrConversion->ycbcrConversion();
95
96 createInfo.pNext = &conversionInfo;
97
98 VkFilter chromaFilter = ycbcrInfo.fChromaFilter;
101 createInfo.magFilter = VK_FILTER_NEAREST;
102 createInfo.minFilter = VK_FILTER_NEAREST;
103 // This doesn't explicitly do anything itself, but if we don't support separate
104 // reconstruction filters below, then we need the chromaFilter to match the mag/min here
105 // so we set it nearest. Because we don't currently update the VulkanYcbcrConversionInfo
106 // that we're querying here, this logic around the chromaFilter must match the logic in
107 // the SetupSamplerYcbcrConversionInfo helper function.
108 chromaFilter = VK_FILTER_NEAREST;
109 }
111 createInfo.magFilter = chromaFilter;
112 createInfo.minFilter = chromaFilter;
113 }
114
115 // Required values when using ycbcr conversion
119 createInfo.anisotropyEnable = VK_FALSE;
121 }
122
123 VkSampler sampler;
125 GR_VK_CALL_RESULT(gpu, result, CreateSampler(gpu->device(), &createInfo, nullptr, &sampler));
126 if (result != VK_SUCCESS) {
127 ycbcrConversion->unref();
128 return nullptr;
129 }
130
131 return new GrVkSampler(gpu, sampler, ycbcrConversion, GenerateKey(samplerState, ycbcrInfo));
132}
133
134void GrVkSampler::freeGPUData() const {
135 SkASSERT(fSampler);
136 GR_VK_CALL(fGpu->vkInterface(), DestroySampler(fGpu->device(), fSampler, nullptr));
137 if (fYcbcrConversion) {
138 fYcbcrConversion->unref();
139 }
140}
141
143 const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo) {
144 // In VK the max aniso value is specified in addition to min/mag/mip filters and the
145 // driver is encouraged to consider the other filter settings when doing aniso.
146 return {samplerState.asKey(/*anisoIsOrthogonal=*/true),
148}
static VkSamplerMipmapMode mipmap_mode_to_vk_sampler_mipmap_mode(GrSamplerState::MipmapMode mm)
Definition: GrVkSampler.cpp:27
static VkSamplerAddressMode wrap_mode_to_vk_sampler_address(GrSamplerState::WrapMode wrapMode)
Definition: GrVkSampler.cpp:13
#define GR_VK_CALL(IFACE, X)
Definition: GrVkUtil.h:24
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
Definition: GrVkUtil.h:35
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkMipmapMode
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
constexpr skgpu::Mipmapped mipmapped() const
constexpr WrapMode wrapModeX() const
bool isAniso() const
constexpr Filter filter() const
uint32_t asKey(bool anisoIsOrthogonal) const
constexpr MipmapMode mipmapMode() const
int maxAniso() const
constexpr WrapMode wrapModeY() const
bool supportsYcbcrConversion() const
Definition: GrVkCaps.h:153
float maxSamplerAnisotropy() const
Definition: GrVkCaps.h:183
const GrVkCaps & vkCaps() const
Definition: GrVkGpu.h:61
const skgpu::VulkanInterface * vkInterface() const
Definition: GrVkGpu.h:60
VkDevice device() const
Definition: GrVkGpu.h:71
GrVkResourceProvider & resourceProvider()
Definition: GrVkGpu.h:83
GrVkSamplerYcbcrConversion * findOrCreateCompatibleSamplerYcbcrConversion(const skgpu::VulkanYcbcrConversionInfo &ycbcrInfo)
VkSamplerYcbcrConversion ycbcrConversion() const
static SK_END_REQUIRE_DENSE Key GenerateKey(const skgpu::VulkanYcbcrConversionInfo &ycbcrInfo)
VkSampler sampler() const
Definition: GrVkSampler.h:29
static GrVkSampler * Create(GrVkGpu *gpu, GrSamplerState, const skgpu::VulkanYcbcrConversionInfo &)
Definition: GrVkSampler.cpp:39
static SK_END_REQUIRE_DENSE Key GenerateKey(GrSamplerState, const skgpu::VulkanYcbcrConversionInfo &)
FlutterSemanticsFlag flags
GAsyncResult * result
static float min(float r, float g, float b)
Definition: hsl.cpp:48
static vk::UniqueSampler CreateSampler(const vk::Device &device, const SamplerDescriptor &desc, const std::shared_ptr< YUVConversionVK > &yuv_conversion)
Definition: sampler_vk.cc:14
VkBool32 unnormalizedCoordinates
Definition: vulkan_core.h:3722
VkSamplerAddressMode addressModeU
Definition: vulkan_core.h:3711
VkBool32 anisotropyEnable
Definition: vulkan_core.h:3715
VkBorderColor borderColor
Definition: vulkan_core.h:3721
const void * pNext
Definition: vulkan_core.h:3706
VkSamplerMipmapMode mipmapMode
Definition: vulkan_core.h:3710
VkSamplerAddressMode addressModeW
Definition: vulkan_core.h:3713
VkSamplerCreateFlags flags
Definition: vulkan_core.h:3707
VkCompareOp compareOp
Definition: vulkan_core.h:3718
VkStructureType sType
Definition: vulkan_core.h:3705
VkSamplerAddressMode addressModeV
Definition: vulkan_core.h:3712
VkSamplerYcbcrConversion conversion
Definition: vulkan_core.h:5438
VkFormatFeatureFlags fFormatFeatures
Definition: VulkanTypes.h:112
@ VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
Definition: vulkan_core.h:2271
@ VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT
Definition: vulkan_core.h:2276
#define VK_TRUE
Definition: vulkan_core.h:131
@ VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
Definition: vulkan_core.h:2089
VkSamplerMipmapMode
Definition: vulkan_core.h:2118
@ VK_SAMPLER_MIPMAP_MODE_NEAREST
Definition: vulkan_core.h:2119
@ VK_SAMPLER_MIPMAP_MODE_LINEAR
Definition: vulkan_core.h:2120
@ VK_COMPARE_OP_NEVER
Definition: vulkan_core.h:1919
VkFlags VkFormatFeatureFlags
Definition: vulkan_core.h:2307
#define VK_FALSE
Definition: vulkan_core.h:125
VkFilter
Definition: vulkan_core.h:2100
@ VK_FILTER_NEAREST
Definition: vulkan_core.h:2101
@ VK_FILTER_LINEAR
Definition: vulkan_core.h:2102
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
VkSamplerAddressMode
Definition: vulkan_core.h:2108
@ VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
Definition: vulkan_core.h:2110
@ VK_SAMPLER_ADDRESS_MODE_REPEAT
Definition: vulkan_core.h:2109
@ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
Definition: vulkan_core.h:2111
@ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
Definition: vulkan_core.h:2112
@ VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO
Definition: vulkan_core.h:293
@ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
Definition: vulkan_core.h:233