summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-28 08:36:41 +0100
committerskal <pascal.massimino@gmail.com>2026-02-28 08:36:41 +0100
commitaf06b3512598c81c472fdbbeb4994c7eb8621d4c (patch)
treeca6f56996470913262748e6d9b1a10ac1670ef8f /src/gpu
parent514b8d7141d1346c48c9e301d2b89fd5e5f42cc9 (diff)
refactor(gpu): move SamplerCache impl to .cc, expose single entry point
get_or_create() and clear() moved out of the header-only class. SamplerSpec and presets remain inline (trivial, no deps). handoff(Gemini): sampler_cache split into .h/.cc, sampler_cache.cc added to COMMON_GPU_EFFECTS. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/sampler_cache.cc32
-rw-r--r--src/gpu/sampler_cache.h31
2 files changed, 36 insertions, 27 deletions
diff --git a/src/gpu/sampler_cache.cc b/src/gpu/sampler_cache.cc
new file mode 100644
index 0000000..c61c232
--- /dev/null
+++ b/src/gpu/sampler_cache.cc
@@ -0,0 +1,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();
+}
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();
- }
};