Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
GrVkSampler Class Reference

#include <GrVkSampler.h>

Inheritance diagram for GrVkSampler:
GrVkManagedResource GrManagedResource SkNoncopyable

Classes

struct  Key
 

Public Member Functions

VkSampler sampler () const
 
const VkSampler * samplerPtr () const
 
uint32_t uniqueID () const
 
- Public Member Functions inherited from GrVkManagedResource
 GrVkManagedResource (const GrVkGpu *gpu)
 
- Public Member Functions inherited from GrManagedResource
 GrManagedResource ()
 
virtual ~GrManagedResource ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static GrVkSamplerCreate (GrVkGpu *gpu, GrSamplerState, const skgpu::VulkanYcbcrConversionInfo &)
 
static SK_END_REQUIRE_DENSE Key GenerateKey (GrSamplerState, const skgpu::VulkanYcbcrConversionInfo &)
 
static const KeyGetKey (const GrVkSampler &sampler)
 
static uint32_t Hash (const Key &key)
 

Additional Inherited Members

- Protected Attributes inherited from GrVkManagedResource
const GrVkGpufGpu
 

Detailed Description

Definition at line 23 of file GrVkSampler.h.

Member Function Documentation

◆ Create()

GrVkSampler * GrVkSampler::Create ( GrVkGpu gpu,
GrSamplerState  samplerState,
const skgpu::VulkanYcbcrConversionInfo ycbcrInfo 
)
static

Definition at line 39 of file GrVkSampler.cpp.

41 {
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}
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_RESULT(GPU, RESULT, X)
Definition: GrVkUtil.h:35
#define SkASSERT(cond)
Definition: SkAssert.h:116
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
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
VkDevice device() const
Definition: GrVkGpu.h:71
GrVkResourceProvider & resourceProvider()
Definition: GrVkGpu.h:83
GrVkSamplerYcbcrConversion * findOrCreateCompatibleSamplerYcbcrConversion(const skgpu::VulkanYcbcrConversionInfo &ycbcrInfo)
VkSamplerYcbcrConversion ycbcrConversion() const
VkSampler sampler() const
Definition: GrVkSampler.h:29
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
@ 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
@ VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
Definition: vulkan_core.h:2111
@ VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO
Definition: vulkan_core.h:293
@ VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
Definition: vulkan_core.h:233

◆ GenerateKey()

GrVkSampler::Key GrVkSampler::GenerateKey ( GrSamplerState  samplerState,
const skgpu::VulkanYcbcrConversionInfo ycbcrInfo 
)
static

Definition at line 142 of file GrVkSampler.cpp.

143 {
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}
uint32_t asKey(bool anisoIsOrthogonal) const
static SK_END_REQUIRE_DENSE Key GenerateKey(const skgpu::VulkanYcbcrConversionInfo &ycbcrInfo)

◆ GetKey()

static const Key & GrVkSampler::GetKey ( const GrVkSampler sampler)
inlinestatic

Definition at line 52 of file GrVkSampler.h.

52{ return sampler.fKey; }

◆ Hash()

static uint32_t GrVkSampler::Hash ( const Key key)
inlinestatic

Definition at line 53 of file GrVkSampler.h.

53 {
54 return SkChecksum::Hash32(&key, sizeof(Key));
55 }
uint32_t Hash32(const void *data, size_t bytes, uint32_t seed)
Definition: SkChecksum.cpp:113

◆ sampler()

VkSampler GrVkSampler::sampler ( ) const
inline

Definition at line 29 of file GrVkSampler.h.

29{ return fSampler; }

◆ samplerPtr()

const VkSampler * GrVkSampler::samplerPtr ( ) const
inline

Definition at line 30 of file GrVkSampler.h.

30{ return &fSampler; }

◆ uniqueID()

uint32_t GrVkSampler::uniqueID ( ) const
inline

Definition at line 57 of file GrVkSampler.h.

57{ return fUniqueID; }

The documentation for this class was generated from the following files: