From 7e5458f88c8ff083d2b584affb7d6db6ea42dcd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Delgado=20Kr=C3=A4mer?= Date: Tue, 30 Jul 2024 18:47:35 +0200 Subject: [PATCH] gatling: clean Hydra resource destruction --- src/gatling/main.cpp | 29 +++++++++++++++++++---------- src/gi/impl/Gi.cpp | 10 +++++----- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/gatling/main.cpp b/src/gatling/main.cpp index b4058f27..f23af635 100644 --- a/src/gatling/main.cpp +++ b/src/gatling/main.cpp @@ -94,21 +94,21 @@ int main(int argc, const char* argv[]) { // Init plugin. HdRendererPluginRegistry& pluginRegistry = HdRendererPluginRegistry::GetInstance(); - HdRendererPluginHandle pluginHandle = pluginRegistry.GetOrCreateRendererPlugin(_AppTokens->HdGatlingRendererPlugin); + HdRendererPluginHandle plugin = pluginRegistry.GetOrCreateRendererPlugin(_AppTokens->HdGatlingRendererPlugin); - if (!pluginHandle) + if (!plugin) { fprintf(stderr, "HdGatling plugin not found\n"); return EXIT_FAILURE; } - if (!pluginHandle->IsSupported()) + if (!plugin->IsSupported()) { fprintf(stderr, "HdGatling plugin not supported\n"); return EXIT_FAILURE; } - HdRenderDelegate* renderDelegate = pluginHandle->CreateRenderDelegate(); + HdRenderDelegate* renderDelegate = plugin->CreateRenderDelegate(); TF_AXIOM(renderDelegate); // Handle cmdline args. @@ -142,10 +142,10 @@ int main(int argc, const char* argv[]) HdRenderIndex* renderIndex = HdRenderIndex::New(renderDelegate, HdDriverVector()); TF_AXIOM(renderIndex); - UsdImagingDelegate sceneDelegate(renderIndex, SdfPath::AbsoluteRootPath()); - sceneDelegate.Populate(stage->GetPseudoRoot()); - sceneDelegate.SetTime(0); - sceneDelegate.SetRefineLevelFallback(4); + std::unique_ptr sceneDelegate = std::make_unique(renderIndex, SdfPath::AbsoluteRootPath()); + sceneDelegate->Populate(stage->GetPseudoRoot()); + sceneDelegate->SetTime(0); + sceneDelegate->SetRefineLevelFallback(4); HdCamera* camera = _FindCamera(stage, renderIndex, settings.cameraPath); if (!camera) @@ -241,13 +241,22 @@ int main(int argc, const char* argv[]) VtDictionary metadata; image->Write(storage, metadata); - renderBuffer->Unmap(); writeTimer.Stop(); - printf("Wrote image (%.3fs)\n", writeTimer.GetSeconds()); fflush(stdout); + renderBuffer->Unmap(); + HdRenderParam* renderParam = renderDelegate->GetRenderParam(); + renderBuffer->Finalize(renderParam); renderDelegate->DestroyBprim(renderBuffer); + tasks.clear(); + renderTask.reset(); + renderPass.reset(); + sceneDelegate.reset(); + stage.Reset(); + delete renderIndex; + plugin->DeleteRenderDelegate(renderDelegate); + return EXIT_SUCCESS; } diff --git a/src/gi/impl/Gi.cpp b/src/gi/impl/Gi.cpp index 46c6c8fb..9d3f4874 100644 --- a/src/gi/impl/Gi.cpp +++ b/src/gi/impl/Gi.cpp @@ -412,11 +412,6 @@ namespace gtl s_texSys.reset(); } s_shaderGen.reset(); - if (s_delayedResourceDestroyer) - { - s_delayedResourceDestroyer->destroyAll(); - s_delayedResourceDestroyer.reset(); - } if (s_stager) { s_stager->flush(); @@ -428,6 +423,11 @@ namespace gtl cgpuDestroySampler(s_device, s_texSampler); s_texSampler = {}; } + if (s_delayedResourceDestroyer) + { + s_delayedResourceDestroyer->destroyAll(); + s_delayedResourceDestroyer.reset(); + } if (s_device.handle) { cgpuDestroyDevice(s_device);