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