diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-11 19:34:34 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-11 19:34:34 +0100 |
| commit | 3530fcd7414ea24c8916adc1e490f71c02ac96f1 (patch) | |
| tree | e94769ad3ce10dff875034d4096f9663d48cb2b9 | |
| parent | ba16f44c689e0bde3c50052c247c234029c9a816 (diff) | |
fix: Release cached samplers before WGPU shutdown
SamplerCache singleton never released samplers, causing device to retain
references at shutdown. Add clear() method and call before fixture cleanup.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| -rw-r--r-- | src/gpu/sampler_cache.h | 7 | ||||
| -rw-r--r-- | tools/cnn_test.cc | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/gpu/sampler_cache.h b/src/gpu/sampler_cache.h index 0f012a8..5df3958 100644 --- a/src/gpu/sampler_cache.h +++ b/src/gpu/sampler_cache.h @@ -58,4 +58,11 @@ public: return {WGPUAddressMode_ClampToEdge, WGPUAddressMode_ClampToEdge, WGPUFilterMode_Linear, WGPUFilterMode_Linear, 1}; } + + void clear() { + for (auto& pair : cache_) { + wgpuSamplerRelease(pair.second); + } + cache_.clear(); + } }; diff --git a/tools/cnn_test.cc b/tools/cnn_test.cc index 4ce9637..fa4394f 100644 --- a/tools/cnn_test.cc +++ b/tools/cnn_test.cc @@ -281,6 +281,7 @@ int main(int argc, char** argv) { WGPUTexture input_texture = load_texture(device, queue, args.input_path, &width, &height); if (!input_texture) { + SamplerCache::Get().clear(); fixture.shutdown(); return 1; } @@ -311,6 +312,7 @@ int main(int argc, char** argv) { if (pipeline_final) wgpuRenderPipelineRelease(pipeline_final); wgpuTextureViewRelease(input_view); wgpuTextureRelease(input_texture); + SamplerCache::Get().clear(); fixture.shutdown(); return 1; } @@ -448,6 +450,7 @@ int main(int argc, char** argv) { wgpuBindGroupLayoutRelease(bgl); wgpuRenderPipelineRelease(pipeline_final); wgpuRenderPipelineRelease(pipeline_intermediate); + SamplerCache::Get().clear(); fixture.shutdown(); return 1; } @@ -474,6 +477,7 @@ int main(int argc, char** argv) { wgpuBindGroupLayoutRelease(bgl); wgpuRenderPipelineRelease(pipeline_final); wgpuRenderPipelineRelease(pipeline_intermediate); + SamplerCache::Get().clear(); fixture.shutdown(); return 1; } @@ -540,6 +544,7 @@ int main(int argc, char** argv) { wgpuRenderPipelineRelease(pipeline_final); wgpuTextureViewRelease(input_view); wgpuTextureRelease(input_texture); + SamplerCache::Get().clear(); fixture.shutdown(); return 0; |
