core: Drain WebGPU render-thread cleanup jobs (#4367)

This commit is contained in:
Sargun Vohra
2026-07-24 01:11:26 -07:00
committed by GitHub
parent 15fcee54dc
commit 5bcdc704b8
6 changed files with 16 additions and 5 deletions

View File

@@ -310,6 +310,8 @@ AndroidWebGPURendererBackend::AndroidWebGPURendererBackend(ANativeWindow* window
}
AndroidWebGPURendererBackend::~AndroidWebGPURendererBackend() {
context.reset();
if (impl) {
if (impl->currentTextureView) {
wgpuTextureViewRelease(impl->currentTextureView);

View File

@@ -751,6 +751,8 @@ GLFWWebGPUBackend::~GLFWWebGPUBackend() {
// Mark any in-flight frame as completed so tear-down logic can continue.
frameInProgress.store(false, std::memory_order_release);
context.reset();
{
std::lock_guard<SpinLock> guard(textureStateLock);

View File

@@ -231,6 +231,8 @@ MLNMapViewWebGPUImpl::MLNMapViewWebGPUImpl(MLNMapView* nativeView_)
}
MLNMapViewWebGPUImpl::~MLNMapViewWebGPUImpl() {
context.reset();
if (!impl) return;
if (impl->currentTextureView) {

View File

@@ -53,10 +53,12 @@ Context::Context(RendererBackend& backend_)
backend(backend_),
globalUniformBuffers(std::make_unique<UniformBufferArray>()) {}
Context::~Context() = default;
Context::~Context() {
backend.getThreadPool().runRenderJobs(true /* closeQueue */);
}
void Context::beginFrame() {
// Begin a new frame - WebGPU command recording starts here
backend.getThreadPool().runRenderJobs();
}
void Context::endFrame() {
@@ -64,11 +66,11 @@ void Context::endFrame() {
}
void Context::performCleanup() {
// Clean up unused resources
backend.getThreadPool().runRenderJobs();
}
void Context::reduceMemoryUsage() {
// Free cached resources to reduce memory
backend.getThreadPool().runRenderJobs();
}
std::unique_ptr<gfx::OffscreenTexture> Context::createOffscreenTexture(Size size,

View File

@@ -202,6 +202,7 @@ HeadlessBackend::HeadlessBackend(Size size_, SwapBehaviour swapBehaviour_, gfx::
HeadlessBackend::~HeadlessBackend() {
// Explicitly reset the renderable resource
setResource(nullptr);
context.reset();
if (impl) {
// Clean up textures

View File

@@ -46,7 +46,9 @@ RendererBackend::RendererBackend(const gfx::ContextMode contextMode_)
: gfx::RendererBackend(contextMode_),
impl(std::make_unique<Impl>()) {}
RendererBackend::~RendererBackend() = default;
RendererBackend::~RendererBackend() {
context.reset();
}
void RendererBackend::activate() {
// Activation logic if needed