Fix leak of AttachmentState
Unlike API objects, the AttachmentState object is only used internally and should have no external references. We should not increment the reference count on creation because it is Ref'ed internally. This patch also adds ASSERTs that all Device caches are empty when the Device is destroyed. Bug: dawn:154 Change-Id: I5dd46bde03c0be920356444e6b1214ed38e833e8 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9761 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
421584173c
commit
bb10a91876
|
@ -77,6 +77,14 @@ namespace dawn_native {
|
||||||
// Devices must explicitly free the uploader
|
// Devices must explicitly free the uploader
|
||||||
ASSERT(mDynamicUploader == nullptr);
|
ASSERT(mDynamicUploader == nullptr);
|
||||||
ASSERT(mDeferredCreateBufferMappedAsyncResults.empty());
|
ASSERT(mDeferredCreateBufferMappedAsyncResults.empty());
|
||||||
|
|
||||||
|
ASSERT(mCaches->attachmentStates.empty());
|
||||||
|
ASSERT(mCaches->bindGroupLayouts.empty());
|
||||||
|
ASSERT(mCaches->computePipelines.empty());
|
||||||
|
ASSERT(mCaches->pipelineLayouts.empty());
|
||||||
|
ASSERT(mCaches->renderPipelines.empty());
|
||||||
|
ASSERT(mCaches->samplers.empty());
|
||||||
|
ASSERT(mCaches->shaderModules.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceBase::HandleError(const char* message) {
|
void DeviceBase::HandleError(const char* message) {
|
||||||
|
@ -255,35 +263,33 @@ namespace dawn_native {
|
||||||
ASSERT(removedCount == 1);
|
ASSERT(removedCount == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentState* DeviceBase::GetOrCreateAttachmentState(
|
Ref<AttachmentState> DeviceBase::GetOrCreateAttachmentState(
|
||||||
const RenderPipelineDescriptor* descriptor) {
|
const RenderPipelineDescriptor* descriptor) {
|
||||||
AttachmentStateBlueprint blueprint(descriptor);
|
AttachmentStateBlueprint blueprint(descriptor);
|
||||||
|
|
||||||
auto iter = mCaches->attachmentStates.find(&blueprint);
|
auto iter = mCaches->attachmentStates.find(&blueprint);
|
||||||
if (iter != mCaches->attachmentStates.end()) {
|
if (iter != mCaches->attachmentStates.end()) {
|
||||||
AttachmentState* cachedState = static_cast<AttachmentState*>(*iter);
|
return static_cast<AttachmentState*>(*iter);
|
||||||
cachedState->Reference();
|
|
||||||
return cachedState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentState* attachmentState = new AttachmentState(this, blueprint);
|
Ref<AttachmentState> attachmentState = new AttachmentState(this, blueprint);
|
||||||
mCaches->attachmentStates.insert(attachmentState);
|
attachmentState->Release();
|
||||||
|
mCaches->attachmentStates.insert(attachmentState.Get());
|
||||||
return attachmentState;
|
return attachmentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentState* DeviceBase::GetOrCreateAttachmentState(
|
Ref<AttachmentState> DeviceBase::GetOrCreateAttachmentState(
|
||||||
const RenderPassDescriptor* descriptor) {
|
const RenderPassDescriptor* descriptor) {
|
||||||
AttachmentStateBlueprint blueprint(descriptor);
|
AttachmentStateBlueprint blueprint(descriptor);
|
||||||
|
|
||||||
auto iter = mCaches->attachmentStates.find(&blueprint);
|
auto iter = mCaches->attachmentStates.find(&blueprint);
|
||||||
if (iter != mCaches->attachmentStates.end()) {
|
if (iter != mCaches->attachmentStates.end()) {
|
||||||
AttachmentState* cachedState = static_cast<AttachmentState*>(*iter);
|
return static_cast<AttachmentState*>(*iter);
|
||||||
cachedState->Reference();
|
|
||||||
return cachedState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachmentState* attachmentState = new AttachmentState(this, blueprint);
|
Ref<AttachmentState> attachmentState = new AttachmentState(this, blueprint);
|
||||||
mCaches->attachmentStates.insert(attachmentState);
|
attachmentState->Release();
|
||||||
|
mCaches->attachmentStates.insert(attachmentState.Get());
|
||||||
return attachmentState;
|
return attachmentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,8 +115,8 @@ namespace dawn_native {
|
||||||
const ShaderModuleDescriptor* descriptor);
|
const ShaderModuleDescriptor* descriptor);
|
||||||
void UncacheShaderModule(ShaderModuleBase* obj);
|
void UncacheShaderModule(ShaderModuleBase* obj);
|
||||||
|
|
||||||
AttachmentState* GetOrCreateAttachmentState(const RenderPipelineDescriptor* descriptor);
|
Ref<AttachmentState> GetOrCreateAttachmentState(const RenderPipelineDescriptor* descriptor);
|
||||||
AttachmentState* GetOrCreateAttachmentState(const RenderPassDescriptor* descriptor);
|
Ref<AttachmentState> GetOrCreateAttachmentState(const RenderPassDescriptor* descriptor);
|
||||||
void UncacheAttachmentState(AttachmentState* obj);
|
void UncacheAttachmentState(AttachmentState* obj);
|
||||||
|
|
||||||
// Dawn API
|
// Dawn API
|
||||||
|
|
Loading…
Reference in New Issue