Skip to content

Commit

Permalink
gatling: clean Hydra resource destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
pablode committed Jul 30, 2024
1 parent 99e1e18 commit 7e5458f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
29 changes: 19 additions & 10 deletions src/gatling/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<UsdImagingDelegate> sceneDelegate = std::make_unique<UsdImagingDelegate>(renderIndex, SdfPath::AbsoluteRootPath());
sceneDelegate->Populate(stage->GetPseudoRoot());
sceneDelegate->SetTime(0);
sceneDelegate->SetRefineLevelFallback(4);

HdCamera* camera = _FindCamera(stage, renderIndex, settings.cameraPath);
if (!camera)
Expand Down Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions src/gi/impl/Gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 7e5458f

Please sign in to comment.