14SamplerLibraryMTL::SamplerLibraryMTL(id<MTLDevice>
device) : device_(
device) {}
16SamplerLibraryMTL::~SamplerLibraryMTL() =
default;
18raw_ptr<const Sampler> SamplerLibraryMTL::GetSampler(
19 const SamplerDescriptor& descriptor) {
20 uint64_t p_key = SamplerDescriptor::ToKey(descriptor);
21 for (
const auto& [
key, value] : samplers_) {
23 return raw_ptr(value);
27 return raw_ptr<const Sampler>(
nullptr);
29 auto desc = [[MTLSamplerDescriptor alloc] init];
38 std::clamp<NSUInteger>(descriptor.max_anisotropy, 1u, 16u);
39 if (@available(iOS 14.0, macos 10.12, *)) {
40 desc.borderColor = MTLSamplerBorderColorTransparentBlack;
43 if (!descriptor.label.empty()) {
44 desc.label = @(descriptor.label.data());
48 auto mtl_sampler = [device_ newSamplerStateWithDescriptor:desc];
50 return raw_ptr<const Sampler>(
nullptr);
54 std::shared_ptr<SamplerMTL>(
new SamplerMTL(descriptor, mtl_sampler));
55 samplers_.push_back(std::make_pair(p_key, std::move(sampler)));
56 return raw_ptr(samplers_.back().second);
constexpr MTLSamplerMipFilter ToMTLSamplerMipFilter(MipFilter filter)
constexpr MTLSamplerAddressMode ToMTLSamplerAddressMode(SamplerAddressMode mode)
constexpr MTLSamplerMinMagFilter ToMTLSamplerMinMagFilter(MinMagFilter filter)