diff options
Diffstat (limited to 'src/gpu/sampler_cache.h')
| -rw-r--r-- | src/gpu/sampler_cache.h | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/src/gpu/sampler_cache.h b/src/gpu/sampler_cache.h index 7d88109..0a2afa0 100644 --- a/src/gpu/sampler_cache.h +++ b/src/gpu/sampler_cache.h @@ -1,4 +1,5 @@ -// Sampler cache - deduplicates samplers across effects +// Sampler cache - deduplicates WGPUSampler objects across effects +// Single entry point: SamplerCache::Get().get_or_create(device, spec) #pragma once #include <map> @@ -9,7 +10,6 @@ struct WGPUSamplerImpl; typedef struct WGPUSamplerImpl* WGPUSampler; #include "platform/platform.h" -#include "util/fatal_error.h" struct SamplerSpec { WGPUAddressMode u, v; @@ -39,24 +39,8 @@ class SamplerCache { return instance; } - WGPUSampler get_or_create(WGPUDevice device, const SamplerSpec& spec) { - // Headless mode: skip sampler creation (compiled out in STRIP_ALL) - 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; - } + WGPUSampler get_or_create(WGPUDevice device, const SamplerSpec& spec); + void clear(); // Common presets static SamplerSpec linear() { @@ -67,11 +51,4 @@ class SamplerCache { return {WGPUAddressMode_ClampToEdge, WGPUAddressMode_ClampToEdge, WGPUFilterMode_Linear, WGPUFilterMode_Linear, 1}; } - - void clear() { - for (auto& pair : cache_) { - wgpuSamplerRelease(pair.second); - } - cache_.clear(); - } }; |
