Don't leak default created objects

Sometimes NXT provides default objects for parts of the pipelines, for
example a default pipeline layout. This objects were create with code
like: device->CreateFooBuilder()->GetResult(); and stored in a Ref<>.
This caused the object to have on external reference and two internal
references and not get destroyed when the Ref<> goes out. Call Release
on these objects to remove the external reference and fix the leak.

Was found via the Vulkan validation layers that were complaining that a
VkPipelineLayout was leaked.
This commit is contained in:
Corentin Wallez 2018-01-12 14:18:45 -05:00 committed by Corentin Wallez
parent 348fb1b223
commit d15177d84e
2 changed files with 8 additions and 0 deletions

View File

@ -32,6 +32,8 @@ namespace backend {
->GetDevice() ->GetDevice()
->CreatePipelineLayoutBuilder() ->CreatePipelineLayoutBuilder()
->GetResult(); ->GetResult();
// Remove the external ref objects are created with
mLayout->Release();
} }
auto FillPushConstants = [](const ShaderModuleBase* module, PushConstantInfo* info) { auto FillPushConstants = [](const ShaderModuleBase* module, PushConstantInfo* info) {

View File

@ -89,9 +89,13 @@ namespace backend {
// the device // the device
if (!mInputState) { if (!mInputState) {
mInputState = mDevice->CreateInputStateBuilder()->GetResult(); mInputState = mDevice->CreateInputStateBuilder()->GetResult();
// Remove the external ref objects are created with
mInputState->Release();
} }
if (!mDepthStencilState) { if (!mDepthStencilState) {
mDepthStencilState = mDevice->CreateDepthStencilStateBuilder()->GetResult(); mDepthStencilState = mDevice->CreateDepthStencilStateBuilder()->GetResult();
// Remove the external ref objects are created with
mDepthStencilState->Release();
} }
if (!mRenderPass) { if (!mRenderPass) {
HandleError("Pipeline render pass not set"); HandleError("Pipeline render pass not set");
@ -109,6 +113,8 @@ namespace backend {
for (uint32_t attachmentSlot : for (uint32_t attachmentSlot :
IterateBitSet(subpassInfo.colorAttachmentsSet & ~mBlendStatesSet)) { IterateBitSet(subpassInfo.colorAttachmentsSet & ~mBlendStatesSet)) {
mBlendStates[attachmentSlot] = mDevice->CreateBlendStateBuilder()->GetResult(); mBlendStates[attachmentSlot] = mDevice->CreateBlendStateBuilder()->GetResult();
// Remove the external ref objects are created with
mBlendStates[attachmentSlot]->Release();
} }
return mDevice->CreateRenderPipeline(this); return mDevice->CreateRenderPipeline(this);