Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
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.
32 case GrSamplerState::MipmapMode::kNone: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
33 case GrSamplerState::MipmapMode::kNearest: return VK_SAMPLER_MIPMAP_MODE_NEAREST;
34 case GrSamplerState::MipmapMode::kLinear: return VK_SAMPLER_MIPMAP_MODE_LINEAR;
35 }
37}
38
40 const GrVkYcbcrConversionInfo& ycbcrInfo) {
41 static VkFilter vkMinFilterModes[] = {
45 };
46 static VkFilter vkMagFilterModes[] = {
50 };
51
52 VkSamplerCreateInfo createInfo;
53 memset(&createInfo, 0, sizeof(VkSamplerCreateInfo));
55 createInfo.pNext = nullptr;
56 createInfo.flags = 0;
57 createInfo.magFilter = vkMagFilterModes[static_cast<int>(samplerState.filter())];
58 createInfo.minFilter = vkMinFilterModes[static_cast<int>(samplerState.filter())];
60 createInfo.addressModeU = wrap_mode_to_vk_sampler_address(samplerState.wrapModeX());
61 createInfo.addressModeV = wrap_mode_to_vk_sampler_address(samplerState.wrapModeY());
62 createInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE; // Shouldn't matter
63 createInfo.mipLodBias = 0.0f;
64 createInfo.anisotropyEnable = samplerState.isAniso() ? VK_TRUE : VK_FALSE;
65 createInfo.maxAnisotropy = std::min(static_cast<float>(samplerState.maxAniso()),
67 createInfo.compareEnable = VK_FALSE;
68 createInfo.compareOp = VK_COMPARE_OP_NEVER;
69 // Vulkan doesn't have a direct mapping of GL's nearest or linear filters for minFilter since
70 // there is always a mipmapMode. To get the same effect as GL we can set minLod = maxLod = 0.0.
71 // This works since our min and mag filters are the same (this forces us to use mag on the 0
72 // level mip). If the filters weren't the same we could set min = 0 and max = 0.25 to force
73 // the minFilter on mip level 0.
74 createInfo.minLod = 0.0f;
75 bool useMipMaps = samplerState.mipmapped() == skgpu::Mipmapped::kYes;
76 createInfo.maxLod = !useMipMaps ? 0.0f : 10000.0f;
79
80 VkSamplerYcbcrConversionInfo conversionInfo;
81 GrVkSamplerYcbcrConversion* ycbcrConversion = nullptr;
82 if (ycbcrInfo.isValid()) {
84
85 ycbcrConversion =
87 if (!ycbcrConversion) {
88 return nullptr;
89 }
90
92 conversionInfo.pNext = nullptr;
93 conversionInfo.conversion = ycbcrConversion->ycbcrConversion();
94
95 createInfo.pNext = &conversionInfo;
96
99 createInfo.magFilter = VK_FILTER_NEAREST;
100 createInfo.minFilter = VK_FILTER_NEAREST;
101 } else if (
102 !(flags &
104 createInfo.magFilter = ycbcrInfo.fChromaFilter;
105 createInfo.minFilter = ycbcrInfo.fChromaFilter;
106 }
107
108 // Required values when using ycbcr conversion
112 createInfo.anisotropyEnable = VK_FALSE;
114 }
115
116 VkSampler sampler;
118 GR_VK_CALL_RESULT(gpu, result, CreateSampler(gpu->device(), &createInfo, nullptr, &sampler));
119 if (result != VK_SUCCESS) {
120 ycbcrConversion->unref();
121 return nullptr;
122 }
123
124 return new GrVkSampler(gpu, sampler, ycbcrConversion, GenerateKey(samplerState, ycbcrInfo));
125}
126
128 SkASSERT(fSampler);
129 GR_VK_CALL(fGpu->vkInterface(), DestroySampler(fGpu->device(), fSampler, nullptr));
130 if (fYcbcrConversion) {
131 fYcbcrConversion->unref();
132 }
133}
134
136 const GrVkYcbcrConversionInfo& ycbcrInfo) {
137 // In VK the max aniso value is specified in addition to min/mag/mip filters and the
138 // driver is encouraged to consider the other filter settings when doing aniso.
139 return {samplerState.asKey(/*anisoIsOrthogonal=*/true),
141}
static VkSamplerMipmapMode mipmap_mode_to_vk_sampler_mipmap_mode(GrSamplerState::MipmapMode mm)
static VkSamplerAddressMode wrap_mode_to_vk_sampler_address(GrSamplerState::WrapMode wrapMode)
#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 GrVkYcbcrConversionInfo &ycbcrInfo)
VkSamplerYcbcrConversion ycbcrConversion() const
static SK_END_REQUIRE_DENSE Key GenerateKey(const GrVkYcbcrConversionInfo &ycbcrInfo)
void freeGPUData() const override
static SK_END_REQUIRE_DENSE Key GenerateKey(GrSamplerState, const GrVkYcbcrConversionInfo &)
VkSampler sampler() const
Definition GrVkSampler.h:26
static GrVkSampler * Create(GrVkGpu *gpu, GrSamplerState, const GrVkYcbcrConversionInfo &)
FlutterSemanticsFlag flags
GAsyncResult * result
VkBool32 unnormalizedCoordinates
VkSamplerAddressMode addressModeU
VkBorderColor borderColor
VkSamplerMipmapMode mipmapMode
VkSamplerAddressMode addressModeW
VkSamplerCreateFlags flags
VkCompareOp compareOp
VkStructureType sType
VkSamplerAddressMode addressModeV
VkSamplerYcbcrConversion conversion
VkFormatFeatureFlags fFormatFeatures
@ VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT
@ VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT
#define VK_TRUE
@ VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
VkSamplerMipmapMode
@ VK_SAMPLER_MIPMAP_MODE_NEAREST
@ VK_SAMPLER_MIPMAP_MODE_LINEAR
@ VK_COMPARE_OP_NEVER
VkFlags VkFormatFeatureFlags
#define VK_FALSE
VkFilter
@ VK_FILTER_NEAREST
@ VK_FILTER_LINEAR
VkResult
@ VK_SUCCESS
VkSamplerAddressMode
@ VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
@ VK_SAMPLER_ADDRESS_MODE_REPEAT
@ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
@ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
@ VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO
@ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO