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 
6 
7 #include <algorithm>
8 
11 
12 namespace impeller {
13 
15  const std::weak_ptr<DeviceHolderVK>& device_holder,
16  uint32_t max_sampler_anisotropy)
17  : device_holder_(device_holder),
18  max_sampler_anisotropy_(max_sampler_anisotropy) {}
19 
21 
23  mips_disabled_workaround_ = workarounds.broken_mipmap_generation;
24 }
25 
26 raw_ptr<const Sampler> SamplerLibraryVK::GetSampler(
27  const SamplerDescriptor& desc) {
28  SamplerDescriptor desc_copy = desc;
29  if (mips_disabled_workaround_) {
30  desc_copy.mip_filter = MipFilter::kBase;
31  }
32  // Clamp to the device limit before keying the cache so that all values
33  // beyond the limit share one sampler. The limit is 1 (disabled) when the
34  // samplerAnisotropy feature is unavailable. The upper bound is floored at 1
35  // so std::clamp never sees an inverted range if a driver reports below 1.
36  desc_copy.max_anisotropy = static_cast<uint8_t>(
37  std::clamp<uint32_t>(desc_copy.max_anisotropy, 1u,
38  std::max<uint32_t>(1u, max_sampler_anisotropy_)));
39 
40  uint64_t p_key = SamplerDescriptor::ToKey(desc_copy);
41  for (const auto& [key, value] : samplers_) {
42  if (key == p_key) {
43  return raw_ptr(value);
44  }
45  }
46  auto device_holder = device_holder_.lock();
47  if (!device_holder || !device_holder->GetDevice()) {
48  return raw_ptr<const Sampler>(nullptr);
49  }
50  samplers_.push_back(std::make_pair(
51  p_key,
52  std::make_shared<SamplerVK>(device_holder->GetDevice(), desc_copy)));
53  return raw_ptr(samplers_.back().second);
54 }
55 
56 } // namespace impeller
SamplerLibraryVK(const std::weak_ptr< DeviceHolderVK > &device_holder, uint32_t max_sampler_anisotropy)
void ApplyWorkarounds(const WorkaroundsVK &workarounds)
A wrapper around a raw ptr that adds additional unopt mode only checks.
Definition: raw_ptr.h:15
int32_t value
@ kBase
The texture is sampled as if it only had a single mipmap level.
static uint64_t ToKey(const SamplerDescriptor &d)
A non-exhaustive set of driver specific workarounds.