| Flutter Impeller |

sampler_library_vk.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/vulkan/sampler_library_vk.h"
6
7 #include "impeller/renderer/backend/vulkan/context_vk.h"
8 #include "impeller/renderer/backend/vulkan/formats_vk.h"
9 #include "impeller/renderer/backend/vulkan/sampler_vk.h"
10
11 namespace impeller {
12
13 SamplerLibraryVK::SamplerLibraryVK(
14 const std::weak_ptr<DeviceHolder>& device_holder)
15 : device_holder_(device_holder) {}
16
17 SamplerLibraryVK::~SamplerLibraryVK() = default;
18
19 std::shared_ptr<const Sampler> SamplerLibraryVK::GetSampler(
20 SamplerDescriptor desc) {
21 auto found = samplers_.find(desc);
22 if (found != samplers_.end()) {
23 return found->second;
24 }
25 auto device_holder = device_holder_.lock();
26 if (!device_holder || !device_holder->GetDevice()) {
27 return nullptr;
28 }
29
30 const auto mip_map = ToVKSamplerMipmapMode(desc.mip_filter);
31
32 const auto min_filter = ToVKSamplerMinMagFilter(desc.min_filter);
33 const auto mag_filter = ToVKSamplerMinMagFilter(desc.mag_filter);
34
35 const auto address_mode_u = ToVKSamplerAddressMode(desc.width_address_mode);
36 const auto address_mode_v = ToVKSamplerAddressMode(desc.height_address_mode);
37 const auto address_mode_w = ToVKSamplerAddressMode(desc.depth_address_mode);
38
39 const auto sampler_create_info =
40 vk::SamplerCreateInfo()
41 .setMagFilter(mag_filter)
42 .setMinFilter(min_filter)
43 .setAddressModeU(address_mode_u)
44 .setAddressModeV(address_mode_v)
45 .setAddressModeW(address_mode_w)
46 .setBorderColor(vk::BorderColor::eFloatTransparentBlack)
47 .setMipmapMode(mip_map);
48
49 auto res =
50 device_holder->GetDevice().createSamplerUnique(sampler_create_info);
51 if (res.result != vk::Result::eSuccess) {
52 FML_LOG(ERROR) << "Failed to create sampler: " << vk::to_string(res.result);
53 return nullptr;
54 }
55
56 auto sampler = std::make_shared<SamplerVK>(desc, std::move(res.value));
57
58 if (!sampler->IsValid()) {
59 return nullptr;
60 }
61
62 if (!desc.label.empty()) {
63 ContextVK::SetDebugName(device_holder->GetDevice(), sampler->GetSampler(),
64 desc.label.c_str());
65 }
66
67 samplers_[desc] = sampler;
68 return sampler;
69 }
70
71 } // namespace impeller
impeller::ToVKSamplerAddressMode
constexpr vk::SamplerAddressMode ToVKSamplerAddressMode(SamplerAddressMode mode)
Definition: formats_vk.h:238
impeller::ToVKSamplerMipmapMode
constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter)
Definition: formats_vk.h:226
formats_vk.h
impeller::ContextVK::SetDebugName
bool SetDebugName(T handle, std::string_view label) const
Definition: context_vk.h:100
impeller::ToVKSamplerMinMagFilter
constexpr vk::Filter ToVKSamplerMinMagFilter(MinMagFilter filter)
Definition: formats_vk.h:215
sampler_vk.h
context_vk.h
sampler_library_vk.h
impeller::SamplerLibraryVK::~SamplerLibraryVK
~SamplerLibraryVK() override
impeller
Definition: aiks_context.cc:10