Don't leak buffers if MapAtCreation fails.
This required changing DeviceBase::CreateBufferImpl to return ResultOrError<Ref<BufferBase>> Bug: chromium:1103154 Change-Id: I1a5811d293333b6ef29c988a08f2f1f84ac65702 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24500 Commit-Queue: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
parent
519edd5890
commit
8a9919980f
|
@ -604,13 +604,13 @@ namespace dawn_native {
|
|||
return result;
|
||||
}
|
||||
BufferBase* DeviceBase::CreateBuffer(const BufferDescriptor* descriptor) {
|
||||
BufferBase* result = nullptr;
|
||||
Ref<BufferBase> result = nullptr;
|
||||
if (ConsumedError(CreateBufferInternal(descriptor), &result)) {
|
||||
ASSERT(result == nullptr);
|
||||
ASSERT(result.Get() == nullptr);
|
||||
return BufferBase::MakeError(this, descriptor);
|
||||
}
|
||||
|
||||
return result;
|
||||
return result.Detach();
|
||||
}
|
||||
WGPUCreateBufferMappedResult DeviceBase::CreateBufferMapped(
|
||||
const BufferDescriptor* descriptor) {
|
||||
|
@ -870,21 +870,21 @@ namespace dawn_native {
|
|||
return {};
|
||||
}
|
||||
|
||||
ResultOrError<BufferBase*> DeviceBase::CreateBufferInternal(
|
||||
ResultOrError<Ref<BufferBase>> DeviceBase::CreateBufferInternal(
|
||||
const BufferDescriptor* descriptor) {
|
||||
DAWN_TRY(ValidateIsAlive());
|
||||
if (IsValidationEnabled()) {
|
||||
DAWN_TRY(ValidateBufferDescriptor(this, descriptor));
|
||||
}
|
||||
|
||||
BufferBase* buffer = nullptr;
|
||||
Ref<BufferBase> buffer;
|
||||
DAWN_TRY_ASSIGN(buffer, CreateBufferImpl(descriptor));
|
||||
|
||||
if (descriptor->mappedAtCreation) {
|
||||
DAWN_TRY(buffer->MapAtCreation());
|
||||
}
|
||||
|
||||
return buffer;
|
||||
return std::move(buffer);
|
||||
}
|
||||
|
||||
MaybeError DeviceBase::CreateComputePipelineInternal(
|
||||
|
|
|
@ -241,7 +241,8 @@ namespace dawn_native {
|
|||
const BindGroupDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
||||
const BufferDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
||||
const ComputePipelineDescriptor* descriptor) = 0;
|
||||
virtual ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
|
@ -273,7 +274,7 @@ namespace dawn_native {
|
|||
const BindGroupDescriptor* descriptor);
|
||||
MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result,
|
||||
const BindGroupLayoutDescriptor* descriptor);
|
||||
ResultOrError<BufferBase*> CreateBufferInternal(const BufferDescriptor* descriptor);
|
||||
ResultOrError<Ref<BufferBase>> CreateBufferInternal(const BufferDescriptor* descriptor);
|
||||
MaybeError CreateComputePipelineInternal(ComputePipelineBase** result,
|
||||
const ComputePipelineDescriptor* descriptor);
|
||||
MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result,
|
||||
|
|
|
@ -270,10 +270,10 @@ namespace dawn_native { namespace d3d12 {
|
|||
const BindGroupLayoutDescriptor* descriptor) {
|
||||
return new BindGroupLayout(this, descriptor);
|
||||
}
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
Ref<Buffer> buffer = AcquireRef(new Buffer(this, descriptor));
|
||||
DAWN_TRY(buffer->Initialize());
|
||||
return buffer.Detach();
|
||||
return std::move(buffer);
|
||||
}
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
|
||||
const CommandBufferDescriptor* descriptor) {
|
||||
|
|
|
@ -138,7 +138,8 @@ namespace dawn_native { namespace d3d12 {
|
|||
const BindGroupDescriptor* descriptor) override;
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
||||
const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
||||
const ComputePipelineDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
|
|
|
@ -27,7 +27,8 @@ namespace dawn_native { namespace metal {
|
|||
|
||||
class Buffer : public BufferBase {
|
||||
public:
|
||||
static ResultOrError<Buffer*> Create(Device* device, const BufferDescriptor* descriptor);
|
||||
static ResultOrError<Ref<Buffer>> Create(Device* device,
|
||||
const BufferDescriptor* descriptor);
|
||||
id<MTLBuffer> GetMTLBuffer() const;
|
||||
|
||||
void ClearBufferContentsToZero(CommandRecordingContext* commandContext);
|
||||
|
|
|
@ -30,10 +30,10 @@ namespace dawn_native { namespace metal {
|
|||
static constexpr uint32_t kMaxBufferSizeFallback = 1024u * 1024u * 1024u;
|
||||
|
||||
// static
|
||||
ResultOrError<Buffer*> Buffer::Create(Device* device, const BufferDescriptor* descriptor) {
|
||||
ResultOrError<Ref<Buffer>> Buffer::Create(Device* device, const BufferDescriptor* descriptor) {
|
||||
Ref<Buffer> buffer = AcquireRef(new Buffer(device, descriptor));
|
||||
DAWN_TRY(buffer->Initialize());
|
||||
return buffer.Detach();
|
||||
return std::move(buffer);
|
||||
}
|
||||
|
||||
MaybeError Buffer::Initialize() {
|
||||
|
|
|
@ -71,7 +71,8 @@ namespace dawn_native { namespace metal {
|
|||
const BindGroupDescriptor* descriptor) override;
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
||||
const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
||||
const ComputePipelineDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
|
|
|
@ -108,7 +108,7 @@ namespace dawn_native { namespace metal {
|
|||
const BindGroupLayoutDescriptor* descriptor) {
|
||||
return new BindGroupLayout(this, descriptor);
|
||||
}
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return Buffer::Create(this, descriptor);
|
||||
}
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
|
||||
|
|
|
@ -100,9 +100,9 @@ namespace dawn_native { namespace null {
|
|||
const BindGroupLayoutDescriptor* descriptor) {
|
||||
return new BindGroupLayout(this, descriptor);
|
||||
}
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
DAWN_TRY(IncrementMemoryUsage(descriptor->size));
|
||||
return new Buffer(this, descriptor);
|
||||
return AcquireRef(new Buffer(this, descriptor));
|
||||
}
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
|
||||
const CommandBufferDescriptor* descriptor) {
|
||||
|
|
|
@ -116,7 +116,8 @@ namespace dawn_native { namespace null {
|
|||
const BindGroupDescriptor* descriptor) override;
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
||||
const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
||||
const ComputePipelineDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
|
|
|
@ -102,8 +102,8 @@ namespace dawn_native { namespace opengl {
|
|||
const BindGroupLayoutDescriptor* descriptor) {
|
||||
return new BindGroupLayout(this, descriptor);
|
||||
}
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return new Buffer(this, descriptor);
|
||||
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return AcquireRef(new Buffer(this, descriptor));
|
||||
}
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
|
||||
const CommandBufferDescriptor* descriptor) {
|
||||
|
|
|
@ -71,7 +71,8 @@ namespace dawn_native { namespace opengl {
|
|||
const BindGroupDescriptor* descriptor) override;
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
||||
const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
||||
const ComputePipelineDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
|
|
|
@ -116,10 +116,10 @@ namespace dawn_native { namespace vulkan {
|
|||
} // namespace
|
||||
|
||||
// static
|
||||
ResultOrError<Buffer*> Buffer::Create(Device* device, const BufferDescriptor* descriptor) {
|
||||
ResultOrError<Ref<Buffer>> Buffer::Create(Device* device, const BufferDescriptor* descriptor) {
|
||||
Ref<Buffer> buffer = AcquireRef(new Buffer(device, descriptor));
|
||||
DAWN_TRY(buffer->Initialize());
|
||||
return buffer.Detach();
|
||||
return std::move(buffer);
|
||||
}
|
||||
|
||||
MaybeError Buffer::Initialize() {
|
||||
|
|
|
@ -28,7 +28,8 @@ namespace dawn_native { namespace vulkan {
|
|||
|
||||
class Buffer final : public BufferBase {
|
||||
public:
|
||||
static ResultOrError<Buffer*> Create(Device* device, const BufferDescriptor* descriptor);
|
||||
static ResultOrError<Ref<Buffer>> Create(Device* device,
|
||||
const BufferDescriptor* descriptor);
|
||||
|
||||
VkBuffer GetHandle() const;
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ namespace dawn_native { namespace vulkan {
|
|||
const BindGroupLayoutDescriptor* descriptor) {
|
||||
return BindGroupLayout::Create(this, descriptor);
|
||||
}
|
||||
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
ResultOrError<Ref<BufferBase>> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
|
||||
return Buffer::Create(this, descriptor);
|
||||
}
|
||||
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
|
||||
|
|
|
@ -107,7 +107,8 @@ namespace dawn_native { namespace vulkan {
|
|||
const BindGroupDescriptor* descriptor) override;
|
||||
ResultOrError<BindGroupLayoutBase*> CreateBindGroupLayoutImpl(
|
||||
const BindGroupLayoutDescriptor* descriptor) override;
|
||||
ResultOrError<BufferBase*> CreateBufferImpl(const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<Ref<BufferBase>> CreateBufferImpl(
|
||||
const BufferDescriptor* descriptor) override;
|
||||
ResultOrError<ComputePipelineBase*> CreateComputePipelineImpl(
|
||||
const ComputePipelineDescriptor* descriptor) override;
|
||||
ResultOrError<PipelineLayoutBase*> CreatePipelineLayoutImpl(
|
||||
|
|
Loading…
Reference in New Issue