blob: c61c232d3c18d1301a826c417bad95f7eee13afb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
// Sampler cache implementation
// See sampler_cache.h
#include "gpu/sampler_cache.h"
#include "platform/platform.h"
#include "util/fatal_error.h"
WGPUSampler SamplerCache::get_or_create(WGPUDevice device,
const SamplerSpec& spec) {
HEADLESS_RETURN_VAL_IF_NULL(device, nullptr);
auto it = cache_.find(spec);
if (it != cache_.end())
return it->second;
WGPUSamplerDescriptor desc{};
desc.addressModeU = spec.u;
desc.addressModeV = spec.v;
desc.magFilter = spec.mag;
desc.minFilter = spec.min;
desc.maxAnisotropy = spec.anisotropy;
WGPUSampler sampler = wgpuDeviceCreateSampler(device, &desc);
cache_[spec] = sampler;
return sampler;
}
void SamplerCache::clear() {
for (auto& pair : cache_) {
wgpuSamplerRelease(pair.second);
}
cache_.clear();
}
|