diff --git a/src/dawn_native/AttachmentState.h b/src/dawn_native/AttachmentState.h index 74c5432f23..f5d01594b1 100644 --- a/src/dawn_native/AttachmentState.h +++ b/src/dawn_native/AttachmentState.h @@ -56,16 +56,18 @@ namespace dawn_native { uint32_t mSampleCount = 0; }; - class AttachmentState : public AttachmentStateBlueprint, public CachedObject { + class AttachmentState final : public AttachmentStateBlueprint, public CachedObject { public: AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint); - ~AttachmentState() override; std::bitset GetColorAttachmentsMask() const; wgpu::TextureFormat GetColorAttachmentFormat(uint32_t index) const; bool HasDepthStencilAttachment() const; wgpu::TextureFormat GetDepthStencilFormat() const; uint32_t GetSampleCount() const; + + private: + ~AttachmentState() override; }; } // namespace dawn_native diff --git a/src/dawn_native/BindGroup.h b/src/dawn_native/BindGroup.h index becb39ee75..8a64bb6f4a 100644 --- a/src/dawn_native/BindGroup.h +++ b/src/dawn_native/BindGroup.h @@ -41,8 +41,6 @@ namespace dawn_native { class BindGroupBase : public ObjectBase { public: - ~BindGroupBase() override; - static BindGroupBase* MakeError(DeviceBase* device); BindGroupLayoutBase* GetLayout(); @@ -70,6 +68,9 @@ namespace dawn_native { static_assert(std::is_base_of::value, ""); } + protected: + ~BindGroupBase() override; + private: BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag); diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp index 6502475b16..81bf63fd38 100644 --- a/src/dawn_native/Buffer.cpp +++ b/src/dawn_native/Buffer.cpp @@ -28,7 +28,7 @@ namespace dawn_native { namespace { - class ErrorBuffer : public BufferBase { + class ErrorBuffer final : public BufferBase { public: ErrorBuffer(DeviceBase* device) : BufferBase(device, ObjectBase::kError) { } diff --git a/src/dawn_native/Buffer.h b/src/dawn_native/Buffer.h index 387ef5c371..6bf96becb4 100644 --- a/src/dawn_native/Buffer.h +++ b/src/dawn_native/Buffer.h @@ -47,7 +47,6 @@ namespace dawn_native { public: BufferBase(DeviceBase* device, const BufferDescriptor* descriptor); - ~BufferBase(); static BufferBase* MakeError(DeviceBase* device); static BufferBase* MakeErrorMapped(DeviceBase* device, @@ -70,6 +69,7 @@ namespace dawn_native { protected: BufferBase(DeviceBase* device, ObjectBase::ErrorTag tag); + ~BufferBase() override; void CallMapReadCallback(uint32_t serial, WGPUBufferMapAsyncStatus status, diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 674f5f5b7d..87ca07172e 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -462,8 +462,8 @@ namespace dawn_native { } BufferBase* DeviceBase::CreateBuffer(const BufferDescriptor* descriptor) { BufferBase* result = nullptr; - - if (ConsumedError(CreateBufferInternal(&result, descriptor))) { + if (ConsumedError(CreateBufferInternal(descriptor), &result)) { + ASSERT(result == nullptr); return BufferBase::MakeError(this); } @@ -475,11 +475,11 @@ namespace dawn_native { uint8_t* data = nullptr; uint64_t size = descriptor->size; - if (ConsumedError(CreateBufferInternal(&buffer, descriptor)) || + if (ConsumedError(CreateBufferInternal(descriptor), &buffer) || ConsumedError(buffer->MapAtCreation(&data))) { // Map failed. Replace the buffer with an error buffer. if (buffer != nullptr) { - delete buffer; + buffer->Release(); } buffer = BufferBase::MakeErrorMapped(this, size, &data); } @@ -708,14 +708,13 @@ namespace dawn_native { return {}; } - MaybeError DeviceBase::CreateBufferInternal(BufferBase** result, - const BufferDescriptor* descriptor) { + ResultOrError DeviceBase::CreateBufferInternal( + const BufferDescriptor* descriptor) { DAWN_TRY(ValidateIsAlive()); if (IsValidationEnabled()) { DAWN_TRY(ValidateBufferDescriptor(this, descriptor)); } - DAWN_TRY_ASSIGN(*result, CreateBufferImpl(descriptor)); - return {}; + return CreateBufferImpl(descriptor); } MaybeError DeviceBase::CreateComputePipelineInternal( diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index 96c9863dfb..ebe26edd74 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -241,7 +241,7 @@ namespace dawn_native { const BindGroupDescriptor* descriptor); MaybeError CreateBindGroupLayoutInternal(BindGroupLayoutBase** result, const BindGroupLayoutDescriptor* descriptor); - MaybeError CreateBufferInternal(BufferBase** result, const BufferDescriptor* descriptor); + ResultOrError CreateBufferInternal(const BufferDescriptor* descriptor); MaybeError CreateComputePipelineInternal(ComputePipelineBase** result, const ComputePipelineDescriptor* descriptor); MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result, diff --git a/src/dawn_native/ErrorScope.h b/src/dawn_native/ErrorScope.h index fb0bc67e3d..f3a0187f8d 100644 --- a/src/dawn_native/ErrorScope.h +++ b/src/dawn_native/ErrorScope.h @@ -35,11 +35,10 @@ namespace dawn_native { // To simplify ErrorHandling, there is a sentinel root error scope which has // no parent. All uncaptured errors are handled by the root error scope. Its // callback is called immediately once it encounters an error. - class ErrorScope : public RefCounted { + class ErrorScope final : public RefCounted { public: ErrorScope(); // Constructor for the root error scope. ErrorScope(wgpu::ErrorFilter errorFilter, ErrorScope* parent); - ~ErrorScope(); void SetCallback(wgpu::ErrorCallback callback, void* userdata); ErrorScope* GetParent(); @@ -49,6 +48,7 @@ namespace dawn_native { void Destroy(); private: + ~ErrorScope() override; bool IsRoot() const; static void HandleErrorImpl(ErrorScope* scope, wgpu::ErrorType type, const char* message); diff --git a/src/dawn_native/Fence.h b/src/dawn_native/Fence.h index a9845f9cb0..f5596599fe 100644 --- a/src/dawn_native/Fence.h +++ b/src/dawn_native/Fence.h @@ -31,7 +31,6 @@ namespace dawn_native { class Fence final : public ObjectBase { public: Fence(QueueBase* queue, const FenceDescriptor* descriptor); - ~Fence(); static Fence* MakeError(DeviceBase* device); @@ -50,6 +49,7 @@ namespace dawn_native { private: Fence(DeviceBase* device, ObjectBase::ErrorTag tag); + ~Fence() override; MaybeError ValidateOnCompletion(uint64_t value, WGPUFenceCompletionStatus* status) const; diff --git a/src/dawn_native/ObjectBase.cpp b/src/dawn_native/ObjectBase.cpp index 0f8c1a3525..8b4731f338 100644 --- a/src/dawn_native/ObjectBase.cpp +++ b/src/dawn_native/ObjectBase.cpp @@ -26,9 +26,6 @@ namespace dawn_native { : RefCounted(kErrorPayload), mDevice(device) { } - ObjectBase::~ObjectBase() { - } - DeviceBase* ObjectBase::GetDevice() const { return mDevice; } diff --git a/src/dawn_native/ObjectBase.h b/src/dawn_native/ObjectBase.h index 2a1f86a9a4..cb627a02a5 100644 --- a/src/dawn_native/ObjectBase.h +++ b/src/dawn_native/ObjectBase.h @@ -28,11 +28,13 @@ namespace dawn_native { ObjectBase(DeviceBase* device); ObjectBase(DeviceBase* device, ErrorTag tag); - virtual ~ObjectBase(); DeviceBase* GetDevice() const; bool IsError() const; + protected: + ~ObjectBase() override = default; + private: DeviceBase* mDevice; }; diff --git a/src/dawn_native/RefCounted.cpp b/src/dawn_native/RefCounted.cpp index a0e50b8b75..3d8085c445 100644 --- a/src/dawn_native/RefCounted.cpp +++ b/src/dawn_native/RefCounted.cpp @@ -28,9 +28,6 @@ namespace dawn_native { ASSERT((payload & kPayloadMask) == payload); } - RefCounted::~RefCounted() { - } - uint64_t RefCounted::GetRefCountForTesting() const { return mRefCount >> kPayloadBits; } diff --git a/src/dawn_native/RefCounted.h b/src/dawn_native/RefCounted.h index 7b94d2ec08..7e5a1d84f8 100644 --- a/src/dawn_native/RefCounted.h +++ b/src/dawn_native/RefCounted.h @@ -23,7 +23,6 @@ namespace dawn_native { class RefCounted { public: RefCounted(uint64_t payload = 0); - virtual ~RefCounted(); uint64_t GetRefCountForTesting() const; uint64_t GetRefCountPayload() const; @@ -33,6 +32,8 @@ namespace dawn_native { void Release(); protected: + virtual ~RefCounted() = default; + std::atomic_uint64_t mRefCount; }; diff --git a/src/dawn_native/RenderBundle.h b/src/dawn_native/RenderBundle.h index 828c23be96..ed80c69df1 100644 --- a/src/dawn_native/RenderBundle.h +++ b/src/dawn_native/RenderBundle.h @@ -38,7 +38,6 @@ namespace dawn_native { const RenderBundleDescriptor* descriptor, AttachmentState* attachmentState, PassResourceUsage resourceUsage); - ~RenderBundleBase() override; static RenderBundleBase* MakeError(DeviceBase* device); @@ -47,6 +46,9 @@ namespace dawn_native { const AttachmentState* GetAttachmentState() const; const PassResourceUsage& GetResourceUsage() const; + protected: + ~RenderBundleBase() override; + private: RenderBundleBase(DeviceBase* device, ErrorTag errorTag); diff --git a/src/dawn_native/Surface.h b/src/dawn_native/Surface.h index b33cf8a80e..96748b7925 100644 --- a/src/dawn_native/Surface.h +++ b/src/dawn_native/Surface.h @@ -34,7 +34,6 @@ namespace dawn_native { class Surface final : public RefCounted { public: Surface(InstanceBase* instance, const SurfaceDescriptor* descriptor); - ~Surface(); void SetAttachedSwapChain(NewSwapChainBase* swapChain); NewSwapChainBase* GetAttachedSwapChain() const; @@ -56,6 +55,8 @@ namespace dawn_native { uint32_t GetXWindow() const; private: + ~Surface() override; + Ref mInstance; Type mType; diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index 86a9c89d2f..d90c975874 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -25,7 +25,7 @@ namespace dawn_native { namespace { - class ErrorSwapChain : public SwapChainBase { + class ErrorSwapChain final : public SwapChainBase { public: ErrorSwapChain(DeviceBase* device) : SwapChainBase(device, ObjectBase::kError) { } diff --git a/src/dawn_native/SwapChain.h b/src/dawn_native/SwapChain.h index d1d0b7f255..3997611972 100644 --- a/src/dawn_native/SwapChain.h +++ b/src/dawn_native/SwapChain.h @@ -33,7 +33,6 @@ namespace dawn_native { class SwapChainBase : public ObjectBase { public: SwapChainBase(DeviceBase* device); - virtual ~SwapChainBase(); static SwapChainBase* MakeError(DeviceBase* device); @@ -47,13 +46,13 @@ namespace dawn_native { protected: SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag); + ~SwapChainBase() override; }; // The base class for implementation-based SwapChains that are deprecated. class OldSwapChainBase : public SwapChainBase { public: OldSwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor); - ~OldSwapChainBase(); static SwapChainBase* MakeError(DeviceBase* device); @@ -66,6 +65,7 @@ namespace dawn_native { void Present() override; protected: + ~OldSwapChainBase() override; const DawnSwapChainImplementation& GetImplementation(); virtual TextureBase* GetNextTextureImpl(const TextureDescriptor*) = 0; virtual MaybeError OnBeforePresent(TextureBase* texture) = 0; @@ -93,7 +93,6 @@ namespace dawn_native { NewSwapChainBase(DeviceBase* device, Surface* surface, const SwapChainDescriptor* descriptor); - ~NewSwapChainBase() override; // This is called when the swapchain is detached for any reason: // @@ -127,6 +126,9 @@ namespace dawn_native { bool IsAttached() const; wgpu::BackendType GetBackendType() const; + protected: + ~NewSwapChainBase() override; + private: bool mAttached; uint32_t mWidth; diff --git a/src/dawn_native/d3d12/BindGroupD3D12.h b/src/dawn_native/d3d12/BindGroupD3D12.h index dc5fb75665..c4b5436331 100644 --- a/src/dawn_native/d3d12/BindGroupD3D12.h +++ b/src/dawn_native/d3d12/BindGroupD3D12.h @@ -25,12 +25,11 @@ namespace dawn_native { namespace d3d12 { class Device; class ShaderVisibleDescriptorAllocator; - class BindGroup : public BindGroupBase, public PlacementAllocated { + class BindGroup final : public BindGroupBase, public PlacementAllocated { public: static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor); BindGroup(Device* device, const BindGroupDescriptor* descriptor); - ~BindGroup() override; // Returns true if the BindGroup was successfully populated. ResultOrError Populate(ShaderVisibleDescriptorAllocator* allocator); @@ -39,6 +38,8 @@ namespace dawn_native { namespace d3d12 { D3D12_GPU_DESCRIPTOR_HANDLE GetBaseSamplerDescriptor() const; private: + ~BindGroup() override; + Serial mLastUsageSerial = 0; Serial mHeapSerial = 0; diff --git a/src/dawn_native/d3d12/BindGroupLayoutD3D12.h b/src/dawn_native/d3d12/BindGroupLayoutD3D12.h index 7d393ec65d..fa1cfa8db4 100644 --- a/src/dawn_native/d3d12/BindGroupLayoutD3D12.h +++ b/src/dawn_native/d3d12/BindGroupLayoutD3D12.h @@ -25,7 +25,7 @@ namespace dawn_native { namespace d3d12 { class BindGroup; class Device; - class BindGroupLayout : public BindGroupLayoutBase { + class BindGroupLayout final : public BindGroupLayoutBase { public: BindGroupLayout(Device* device, const BindGroupLayoutDescriptor* descriptor); @@ -49,6 +49,7 @@ namespace dawn_native { namespace d3d12 { const D3D12_DESCRIPTOR_RANGE* GetSamplerDescriptorRanges() const; private: + ~BindGroupLayout() override = default; std::array mBindingOffsets; std::array mDescriptorCounts; D3D12_DESCRIPTOR_RANGE mRanges[DescriptorType::Count]; diff --git a/src/dawn_native/d3d12/BufferD3D12.h b/src/dawn_native/d3d12/BufferD3D12.h index aa80d832dd..5a06ead8e1 100644 --- a/src/dawn_native/d3d12/BufferD3D12.h +++ b/src/dawn_native/d3d12/BufferD3D12.h @@ -26,10 +26,9 @@ namespace dawn_native { namespace d3d12 { class CommandRecordingContext; class Device; - class Buffer : public BufferBase { + class Buffer final : public BufferBase { public: Buffer(Device* device, const BufferDescriptor* descriptor); - ~Buffer(); MaybeError Initialize(); @@ -44,6 +43,7 @@ namespace dawn_native { namespace d3d12 { wgpu::BufferUsage newUsage); private: + ~Buffer() override; // Dawn API MaybeError MapReadAsyncImpl(uint32_t serial) override; MaybeError MapWriteAsyncImpl(uint32_t serial) override; diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.h b/src/dawn_native/d3d12/CommandBufferD3D12.h index 6a021f1f8f..b49882b7b0 100644 --- a/src/dawn_native/d3d12/CommandBufferD3D12.h +++ b/src/dawn_native/d3d12/CommandBufferD3D12.h @@ -44,14 +44,14 @@ namespace dawn_native { namespace d3d12 { class RenderPassBuilder; class RenderPipeline; - class CommandBuffer : public CommandBufferBase { + class CommandBuffer final : public CommandBufferBase { public: CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); - ~CommandBuffer(); MaybeError RecordCommands(CommandRecordingContext* commandContext); private: + ~CommandBuffer() override; MaybeError RecordComputePass(CommandRecordingContext* commandContext, BindGroupStateTracker* bindingTracker); MaybeError RecordRenderPass(CommandRecordingContext* commandContext, diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp index 1fc81d635f..fbade96fc2 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.cpp +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.cpp @@ -25,10 +25,9 @@ namespace dawn_native { namespace d3d12 { ResultOrError ComputePipeline::Create( Device* device, const ComputePipelineDescriptor* descriptor) { - std::unique_ptr pipeline = - std::make_unique(device, descriptor); + Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.release(); + return pipeline.Detach(); } MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) { diff --git a/src/dawn_native/d3d12/ComputePipelineD3D12.h b/src/dawn_native/d3d12/ComputePipelineD3D12.h index 9f38bbe8a4..89b6752da5 100644 --- a/src/dawn_native/d3d12/ComputePipelineD3D12.h +++ b/src/dawn_native/d3d12/ComputePipelineD3D12.h @@ -23,16 +23,16 @@ namespace dawn_native { namespace d3d12 { class Device; - class ComputePipeline : public ComputePipelineBase { + class ComputePipeline final : public ComputePipelineBase { public: static ResultOrError Create(Device* device, const ComputePipelineDescriptor* descriptor); ComputePipeline() = delete; - ~ComputePipeline(); ComPtr GetPipelineState(); private: + ~ComputePipeline() override; using ComputePipelineBase::ComputePipelineBase; MaybeError Initialize(const ComputePipelineDescriptor* descriptor); ComPtr mPipelineState; diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 9386398c55..5bb02d8964 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -237,9 +237,9 @@ namespace dawn_native { namespace d3d12 { return new BindGroupLayout(this, descriptor); } ResultOrError Device::CreateBufferImpl(const BufferDescriptor* descriptor) { - std::unique_ptr buffer = std::make_unique(this, descriptor); + Ref buffer = AcquireRef(new Buffer(this, descriptor)); DAWN_TRY(buffer->Initialize()); - return buffer.release(); + return buffer.Detach(); } CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor) { diff --git a/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp b/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp index 868e083347..42be90b268 100644 --- a/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp +++ b/src/dawn_native/d3d12/PipelineLayoutD3D12.cpp @@ -61,10 +61,9 @@ namespace dawn_native { namespace d3d12 { ResultOrError PipelineLayout::Create( Device* device, const PipelineLayoutDescriptor* descriptor) { - std::unique_ptr layout = - std::make_unique(device, descriptor); + Ref layout = AcquireRef(new PipelineLayout(device, descriptor)); DAWN_TRY(layout->Initialize()); - return layout.release(); + return layout.Detach(); } MaybeError PipelineLayout::Initialize() { diff --git a/src/dawn_native/d3d12/PipelineLayoutD3D12.h b/src/dawn_native/d3d12/PipelineLayoutD3D12.h index 5b71137762..3123dc6afb 100644 --- a/src/dawn_native/d3d12/PipelineLayoutD3D12.h +++ b/src/dawn_native/d3d12/PipelineLayoutD3D12.h @@ -23,7 +23,7 @@ namespace dawn_native { namespace d3d12 { class Device; - class PipelineLayout : public PipelineLayoutBase { + class PipelineLayout final : public PipelineLayoutBase { public: static ResultOrError Create(Device* device, const PipelineLayoutDescriptor* descriptor); @@ -37,6 +37,7 @@ namespace dawn_native { namespace d3d12 { ComPtr GetRootSignature() const; private: + ~PipelineLayout() override = default; using PipelineLayoutBase::PipelineLayoutBase; MaybeError Initialize(); std::array mCbvUavSrvRootParameterInfo; diff --git a/src/dawn_native/d3d12/QueueD3D12.h b/src/dawn_native/d3d12/QueueD3D12.h index 0e3c795d9b..f211d0bf58 100644 --- a/src/dawn_native/d3d12/QueueD3D12.h +++ b/src/dawn_native/d3d12/QueueD3D12.h @@ -25,7 +25,7 @@ namespace dawn_native { namespace d3d12 { class Device; class CommandBuffer; - class Queue : public QueueBase { + class Queue final : public QueueBase { public: Queue(Device* device); diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp index 28df6de4c1..85cd0b721c 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.cpp +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.cpp @@ -293,10 +293,9 @@ namespace dawn_native { namespace d3d12 { ResultOrError RenderPipeline::Create( Device* device, const RenderPipelineDescriptor* descriptor) { - std::unique_ptr pipeline = - std::make_unique(device, descriptor); + Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.release(); + return pipeline.Detach(); } MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { diff --git a/src/dawn_native/d3d12/RenderPipelineD3D12.h b/src/dawn_native/d3d12/RenderPipelineD3D12.h index 73408720c6..1d8882de89 100644 --- a/src/dawn_native/d3d12/RenderPipelineD3D12.h +++ b/src/dawn_native/d3d12/RenderPipelineD3D12.h @@ -23,17 +23,17 @@ namespace dawn_native { namespace d3d12 { class Device; - class RenderPipeline : public RenderPipelineBase { + class RenderPipeline final : public RenderPipelineBase { public: static ResultOrError Create(Device* device, const RenderPipelineDescriptor* descriptor); RenderPipeline() = delete; - ~RenderPipeline(); D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const; ComPtr GetPipelineState(); private: + ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; MaybeError Initialize(const RenderPipelineDescriptor* descriptor); D3D12_INPUT_LAYOUT_DESC ComputeInputLayout( diff --git a/src/dawn_native/d3d12/SamplerD3D12.h b/src/dawn_native/d3d12/SamplerD3D12.h index 0c52716b44..59a7d8370a 100644 --- a/src/dawn_native/d3d12/SamplerD3D12.h +++ b/src/dawn_native/d3d12/SamplerD3D12.h @@ -23,13 +23,14 @@ namespace dawn_native { namespace d3d12 { class Device; - class Sampler : public SamplerBase { + class Sampler final : public SamplerBase { public: Sampler(Device* device, const SamplerDescriptor* descriptor); const D3D12_SAMPLER_DESC& GetSamplerDescriptor() const; private: + ~Sampler() override = default; D3D12_SAMPLER_DESC mSamplerDesc = {}; }; diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp index 6e8e38cbb2..086a2599ce 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp @@ -27,11 +27,9 @@ namespace dawn_native { namespace d3d12 { // static ResultOrError ShaderModule::Create(Device* device, const ShaderModuleDescriptor* descriptor) { - std::unique_ptr module(new ShaderModule(device, descriptor)); - if (!module) - return DAWN_VALIDATION_ERROR("Unable to create ShaderModule"); + Ref module = AcquireRef(new ShaderModule(device, descriptor)); DAWN_TRY(module->Initialize(descriptor)); - return module.release(); + return module.Detach(); } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.h b/src/dawn_native/d3d12/ShaderModuleD3D12.h index 0b4aeff19a..289c2dba60 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.h +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.h @@ -22,7 +22,7 @@ namespace dawn_native { namespace d3d12 { class Device; class PipelineLayout; - class ShaderModule : public ShaderModuleBase { + class ShaderModule final : public ShaderModuleBase { public: static ResultOrError Create(Device* device, const ShaderModuleDescriptor* descriptor); @@ -31,6 +31,7 @@ namespace dawn_native { namespace d3d12 { private: ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor); + ~ShaderModule() override = default; MaybeError Initialize(const ShaderModuleDescriptor* descriptor); std::vector mSpirv; diff --git a/src/dawn_native/d3d12/SwapChainD3D12.h b/src/dawn_native/d3d12/SwapChainD3D12.h index d601fdcc96..ee92e09cbf 100644 --- a/src/dawn_native/d3d12/SwapChainD3D12.h +++ b/src/dawn_native/d3d12/SwapChainD3D12.h @@ -21,12 +21,12 @@ namespace dawn_native { namespace d3d12 { class Device; - class SwapChain : public OldSwapChainBase { + class SwapChain final : public OldSwapChainBase { public: SwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~SwapChain(); protected: + ~SwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureBase* texture) override; diff --git a/src/dawn_native/d3d12/TextureD3D12.h b/src/dawn_native/d3d12/TextureD3D12.h index 6c63b5602a..2f4380dda7 100644 --- a/src/dawn_native/d3d12/TextureD3D12.h +++ b/src/dawn_native/d3d12/TextureD3D12.h @@ -32,7 +32,7 @@ namespace dawn_native { namespace d3d12 { const TextureDescriptor* descriptor); MaybeError ValidateTextureDescriptorCanBeWrapped(const TextureDescriptor* descriptor); - class Texture : public TextureBase { + class Texture final : public TextureBase { public: static ResultOrError Create(Device* device, const TextureDescriptor* descriptor); @@ -45,8 +45,6 @@ namespace dawn_native { namespace d3d12 { const TextureDescriptor* descriptor, ComPtr d3d12Texture); - ~Texture(); - DXGI_FORMAT GetD3D12Format() const; ID3D12Resource* GetD3D12Resource() const; @@ -71,6 +69,7 @@ namespace dawn_native { namespace d3d12 { D3D12_RESOURCE_STATES newState); private: + ~Texture() override; using TextureBase::TextureBase; MaybeError InitializeAsInternalTexture(); @@ -108,7 +107,7 @@ namespace dawn_native { namespace d3d12 { ComPtr mDxgiKeyedMutex; }; - class TextureView : public TextureViewBase { + class TextureView final : public TextureViewBase { public: TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); diff --git a/src/dawn_native/metal/BindGroupLayoutMTL.h b/src/dawn_native/metal/BindGroupLayoutMTL.h index 79118355be..c6777db7a7 100644 --- a/src/dawn_native/metal/BindGroupLayoutMTL.h +++ b/src/dawn_native/metal/BindGroupLayoutMTL.h @@ -23,7 +23,7 @@ namespace dawn_native { namespace metal { class BindGroup; class Device; - class BindGroupLayout : public BindGroupLayoutBase { + class BindGroupLayout final : public BindGroupLayoutBase { public: BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); @@ -31,6 +31,7 @@ namespace dawn_native { namespace metal { void DeallocateBindGroup(BindGroup* bindGroup); private: + ~BindGroupLayout() override = default; SlabAllocator mBindGroupAllocator; }; diff --git a/src/dawn_native/metal/BindGroupMTL.h b/src/dawn_native/metal/BindGroupMTL.h index 4a0a22932c..60cbf3162d 100644 --- a/src/dawn_native/metal/BindGroupMTL.h +++ b/src/dawn_native/metal/BindGroupMTL.h @@ -23,12 +23,14 @@ namespace dawn_native { namespace metal { class BindGroupLayout; class Device; - class BindGroup : public BindGroupBase, public PlacementAllocated { + class BindGroup final : public BindGroupBase, public PlacementAllocated { public: BindGroup(Device* device, const BindGroupDescriptor* descriptor); - ~BindGroup() override; static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor); + + private: + ~BindGroup() override; }; }} // namespace dawn_native::metal diff --git a/src/dawn_native/metal/BufferMTL.h b/src/dawn_native/metal/BufferMTL.h index f05f38e751..effd07704d 100644 --- a/src/dawn_native/metal/BufferMTL.h +++ b/src/dawn_native/metal/BufferMTL.h @@ -27,13 +27,13 @@ namespace dawn_native { namespace metal { class Buffer : public BufferBase { public: Buffer(Device* device, const BufferDescriptor* descriptor); - ~Buffer(); id GetMTLBuffer() const; void OnMapCommandSerialFinished(uint32_t mapSerial, bool isWrite); private: + ~Buffer() override; // Dawn API MaybeError MapReadAsyncImpl(uint32_t serial) override; MaybeError MapWriteAsyncImpl(uint32_t serial) override; diff --git a/src/dawn_native/metal/CommandBufferMTL.h b/src/dawn_native/metal/CommandBufferMTL.h index 67a1313eba..e8c81b7dc2 100644 --- a/src/dawn_native/metal/CommandBufferMTL.h +++ b/src/dawn_native/metal/CommandBufferMTL.h @@ -29,14 +29,14 @@ namespace dawn_native { namespace metal { class CommandRecordingContext; class Device; - class CommandBuffer : public CommandBufferBase { + class CommandBuffer final : public CommandBufferBase { public: CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); - ~CommandBuffer(); void FillCommands(CommandRecordingContext* commandContext); private: + ~CommandBuffer() override; void EncodeComputePass(CommandRecordingContext* commandContext); void EncodeRenderPass(CommandRecordingContext* commandContext, MTLRenderPassDescriptor* mtlRenderPass, diff --git a/src/dawn_native/metal/ComputePipelineMTL.h b/src/dawn_native/metal/ComputePipelineMTL.h index 6ff1d01cd0..7c2d34b818 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.h +++ b/src/dawn_native/metal/ComputePipelineMTL.h @@ -23,17 +23,17 @@ namespace dawn_native { namespace metal { class Device; - class ComputePipeline : public ComputePipelineBase { + class ComputePipeline final : public ComputePipelineBase { public: static ResultOrError Create(Device* device, const ComputePipelineDescriptor* descriptor); - ~ComputePipeline(); void Encode(id encoder); MTLSize GetLocalWorkGroupSize() const; bool RequiresStorageBufferLength() const; private: + ~ComputePipeline() override; using ComputePipelineBase::ComputePipelineBase; MaybeError Initialize(const ComputePipelineDescriptor* descriptor); diff --git a/src/dawn_native/metal/ComputePipelineMTL.mm b/src/dawn_native/metal/ComputePipelineMTL.mm index e9252af5df..aca771d244 100644 --- a/src/dawn_native/metal/ComputePipelineMTL.mm +++ b/src/dawn_native/metal/ComputePipelineMTL.mm @@ -23,10 +23,9 @@ namespace dawn_native { namespace metal { ResultOrError ComputePipeline::Create( Device* device, const ComputePipelineDescriptor* descriptor) { - std::unique_ptr pipeline = - std::make_unique(device, descriptor); + Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.release(); + return pipeline.Detach(); } MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) { diff --git a/src/dawn_native/metal/PipelineLayoutMTL.h b/src/dawn_native/metal/PipelineLayoutMTL.h index e66a852a67..6f2f64d8f9 100644 --- a/src/dawn_native/metal/PipelineLayoutMTL.h +++ b/src/dawn_native/metal/PipelineLayoutMTL.h @@ -36,7 +36,7 @@ namespace dawn_native { namespace metal { // The number of Metal buffers Dawn can use in a generic way (i.e. that aren't reserved) static constexpr size_t kGenericMetalBufferSlots = kMetalBufferTableSize - 1; - class PipelineLayout : public PipelineLayoutBase { + class PipelineLayout final : public PipelineLayoutBase { public: PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor); @@ -48,6 +48,7 @@ namespace dawn_native { namespace metal { uint32_t GetBufferBindingCount(SingleShaderStage stage); private: + ~PipelineLayout() override = default; PerStage mIndexInfo; PerStage mBufferBindingCount; }; diff --git a/src/dawn_native/metal/QueueMTL.h b/src/dawn_native/metal/QueueMTL.h index d9869dec70..2dd718e5c0 100644 --- a/src/dawn_native/metal/QueueMTL.h +++ b/src/dawn_native/metal/QueueMTL.h @@ -22,7 +22,7 @@ namespace dawn_native { namespace metal { class CommandBuffer; class Device; - class Queue : public QueueBase { + class Queue final : public QueueBase { public: Queue(Device* device); diff --git a/src/dawn_native/metal/RenderPipelineMTL.h b/src/dawn_native/metal/RenderPipelineMTL.h index 47fc0489ab..e27e1c4e77 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.h +++ b/src/dawn_native/metal/RenderPipelineMTL.h @@ -23,11 +23,10 @@ namespace dawn_native { namespace metal { class Device; - class RenderPipeline : public RenderPipelineBase { + class RenderPipeline final : public RenderPipelineBase { public: static ResultOrError Create(Device* device, const RenderPipelineDescriptor* descriptor); - ~RenderPipeline(); MTLIndexType GetMTLIndexType() const; MTLPrimitiveType GetMTLPrimitiveTopology() const; @@ -45,6 +44,7 @@ namespace dawn_native { namespace metal { wgpu::ShaderStage GetStagesRequiringStorageBufferLength() const; private: + ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; MaybeError Initialize(const RenderPipelineDescriptor* descriptor); diff --git a/src/dawn_native/metal/RenderPipelineMTL.mm b/src/dawn_native/metal/RenderPipelineMTL.mm index 575140f86d..9deba399bd 100644 --- a/src/dawn_native/metal/RenderPipelineMTL.mm +++ b/src/dawn_native/metal/RenderPipelineMTL.mm @@ -315,10 +315,9 @@ namespace dawn_native { namespace metal { ResultOrError RenderPipeline::Create( Device* device, const RenderPipelineDescriptor* descriptor) { - std::unique_ptr pipeline = - std::make_unique(device, descriptor); + Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.release(); + return pipeline.Detach(); } MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { diff --git a/src/dawn_native/metal/SamplerMTL.h b/src/dawn_native/metal/SamplerMTL.h index 205a7ecd2d..31c4ce5641 100644 --- a/src/dawn_native/metal/SamplerMTL.h +++ b/src/dawn_native/metal/SamplerMTL.h @@ -23,15 +23,16 @@ namespace dawn_native { namespace metal { class Device; - class Sampler : public SamplerBase { + class Sampler final : public SamplerBase { public: static ResultOrError Create(Device* device, const SamplerDescriptor* descriptor); - ~Sampler(); id GetMTLSamplerState(); private: Sampler(Device* device, const SamplerDescriptor* descriptor); + ~Sampler() override; + id mMtlSamplerState = nil; }; diff --git a/src/dawn_native/metal/ShaderModuleMTL.h b/src/dawn_native/metal/ShaderModuleMTL.h index b270034d5d..53e9f7d484 100644 --- a/src/dawn_native/metal/ShaderModuleMTL.h +++ b/src/dawn_native/metal/ShaderModuleMTL.h @@ -30,7 +30,7 @@ namespace dawn_native { namespace metal { class Device; class PipelineLayout; - class ShaderModule : public ShaderModuleBase { + class ShaderModule final : public ShaderModuleBase { public: static ResultOrError Create(Device* device, const ShaderModuleDescriptor* descriptor); @@ -50,6 +50,7 @@ namespace dawn_native { namespace metal { private: ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor); + ~ShaderModule() override = default; MaybeError Initialize(const ShaderModuleDescriptor* descriptor); shaderc_spvc::CompileOptions GetMSLCompileOptions(); diff --git a/src/dawn_native/metal/ShaderModuleMTL.mm b/src/dawn_native/metal/ShaderModuleMTL.mm index bb2d4f03eb..7d573fb200 100644 --- a/src/dawn_native/metal/ShaderModuleMTL.mm +++ b/src/dawn_native/metal/ShaderModuleMTL.mm @@ -57,11 +57,9 @@ namespace dawn_native { namespace metal { // static ResultOrError ShaderModule::Create(Device* device, const ShaderModuleDescriptor* descriptor) { - std::unique_ptr module(new ShaderModule(device, descriptor)); - if (!module) - return DAWN_VALIDATION_ERROR("Unable to create ShaderModule"); + Ref module = AcquireRef(new ShaderModule(device, descriptor)); DAWN_TRY(module->Initialize(descriptor)); - return module.release(); + return module.Detach(); } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/metal/SwapChainMTL.h b/src/dawn_native/metal/SwapChainMTL.h index a4cddc1f5a..adfd6322dc 100644 --- a/src/dawn_native/metal/SwapChainMTL.h +++ b/src/dawn_native/metal/SwapChainMTL.h @@ -25,25 +25,26 @@ namespace dawn_native { namespace metal { class Device; class Texture; - class OldSwapChain : public OldSwapChainBase { + class OldSwapChain final : public OldSwapChainBase { public: OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~OldSwapChain(); protected: + ~OldSwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureBase* texture) override; }; - class SwapChain : public NewSwapChainBase { + class SwapChain final : public NewSwapChainBase { public: SwapChain(Device* device, Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor); - ~SwapChain() override; private: + ~SwapChain() override; + CAMetalLayer* mLayer = nullptr; id mCurrentDrawable = nil; diff --git a/src/dawn_native/metal/TextureMTL.h b/src/dawn_native/metal/TextureMTL.h index 0b18089f2a..8e4bce9bd3 100644 --- a/src/dawn_native/metal/TextureMTL.h +++ b/src/dawn_native/metal/TextureMTL.h @@ -31,7 +31,7 @@ namespace dawn_native { namespace metal { IOSurfaceRef ioSurface, uint32_t plane); - class Texture : public TextureBase { + class Texture final : public TextureBase { public: Texture(Device* device, const TextureDescriptor* descriptor); Texture(Device* device, const TextureDescriptor* descriptor, id mtlTexture); @@ -39,7 +39,6 @@ namespace dawn_native { namespace metal { const ExternalImageDescriptor* descriptor, IOSurfaceRef ioSurface, uint32_t plane); - ~Texture(); id GetMTLTexture(); @@ -49,6 +48,8 @@ namespace dawn_native { namespace metal { uint32_t layerCount); private: + ~Texture() override; + void DestroyImpl() override; MaybeError ClearTexture(uint32_t baseMipLevel, @@ -60,14 +61,15 @@ namespace dawn_native { namespace metal { id mMtlTexture = nil; }; - class TextureView : public TextureViewBase { + class TextureView final : public TextureViewBase { public: TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); - ~TextureView(); id GetMTLTexture(); private: + ~TextureView() override; + id mMtlTextureView = nil; }; diff --git a/src/dawn_native/null/DeviceNull.h b/src/dawn_native/null/DeviceNull.h index b41061e743..2a003e20b5 100644 --- a/src/dawn_native/null/DeviceNull.h +++ b/src/dawn_native/null/DeviceNull.h @@ -169,16 +169,17 @@ namespace dawn_native { namespace null { // We don't have the complexity of placement-allocation of bind group data in // the Null backend. This class, keeps the binding data in a separate allocation for simplicity. - class BindGroup : private BindGroupDataHolder, public BindGroupBase { + class BindGroup final : private BindGroupDataHolder, public BindGroupBase { public: BindGroup(DeviceBase* device, const BindGroupDescriptor* descriptor); + + private: ~BindGroup() override = default; }; - class Buffer : public BufferBase { + class Buffer final : public BufferBase { public: Buffer(Device* device, const BufferDescriptor* descriptor); - ~Buffer(); void MapOperationCompleted(uint32_t serial, void* ptr, bool isWrite); void CopyFromStaging(StagingBufferBase* staging, @@ -187,6 +188,8 @@ namespace dawn_native { namespace null { uint64_t size); private: + ~Buffer() override; + // Dawn API MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data) override; MaybeError MapReadAsyncImpl(uint32_t serial) override; @@ -201,33 +204,35 @@ namespace dawn_native { namespace null { std::unique_ptr mBackingData; }; - class CommandBuffer : public CommandBufferBase { + class CommandBuffer final : public CommandBufferBase { public: CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); - ~CommandBuffer(); private: + ~CommandBuffer() override; + CommandIterator mCommands; }; - class Queue : public QueueBase { + class Queue final : public QueueBase { public: Queue(Device* device); - ~Queue(); private: + ~Queue() override; MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override; }; - class SwapChain : public NewSwapChainBase { + class SwapChain final : public NewSwapChainBase { public: SwapChain(Device* device, Surface* surface, NewSwapChainBase* previousSwapChain, const SwapChainDescriptor* descriptor); - ~SwapChain() override; private: + ~SwapChain() override; + Ref mTexture; MaybeError PresentImpl() override; @@ -235,12 +240,12 @@ namespace dawn_native { namespace null { void DetachFromSurfaceImpl() override; }; - class OldSwapChain : public OldSwapChainBase { + class OldSwapChain final : public OldSwapChainBase { public: OldSwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~OldSwapChain(); protected: + ~OldSwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureBase*) override; }; diff --git a/src/dawn_native/opengl/BindGroupGL.h b/src/dawn_native/opengl/BindGroupGL.h index 9ce8ed7915..ad69b640b6 100644 --- a/src/dawn_native/opengl/BindGroupGL.h +++ b/src/dawn_native/opengl/BindGroupGL.h @@ -23,12 +23,14 @@ namespace dawn_native { namespace opengl { class BindGroupLayout; class Device; - class BindGroup : public BindGroupBase, public PlacementAllocated { + class BindGroup final : public BindGroupBase, public PlacementAllocated { public: BindGroup(Device* device, const BindGroupDescriptor* descriptor); - ~BindGroup() override; static BindGroup* Create(Device* device, const BindGroupDescriptor* descriptor); + + private: + ~BindGroup() override; }; }} // namespace dawn_native::opengl diff --git a/src/dawn_native/opengl/BindGroupLayoutGL.h b/src/dawn_native/opengl/BindGroupLayoutGL.h index ab8dab4730..aeba62f54c 100644 --- a/src/dawn_native/opengl/BindGroupLayoutGL.h +++ b/src/dawn_native/opengl/BindGroupLayoutGL.h @@ -23,7 +23,7 @@ namespace dawn_native { namespace opengl { class BindGroup; class Device; - class BindGroupLayout : public BindGroupLayoutBase { + class BindGroupLayout final : public BindGroupLayoutBase { public: BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); @@ -31,6 +31,7 @@ namespace dawn_native { namespace opengl { void DeallocateBindGroup(BindGroup* bindGroup); private: + ~BindGroupLayout() override = default; SlabAllocator mBindGroupAllocator; }; diff --git a/src/dawn_native/opengl/BufferGL.h b/src/dawn_native/opengl/BufferGL.h index 73bc041b93..2211a5c560 100644 --- a/src/dawn_native/opengl/BufferGL.h +++ b/src/dawn_native/opengl/BufferGL.h @@ -23,14 +23,14 @@ namespace dawn_native { namespace opengl { class Device; - class Buffer : public BufferBase { + class Buffer final : public BufferBase { public: Buffer(Device* device, const BufferDescriptor* descriptor); - ~Buffer(); GLuint GetHandle() const; private: + ~Buffer() override; // Dawn API MaybeError SetSubDataImpl(uint32_t start, uint32_t count, const void* data) override; MaybeError MapReadAsyncImpl(uint32_t serial) override; diff --git a/src/dawn_native/opengl/CommandBufferGL.h b/src/dawn_native/opengl/CommandBufferGL.h index 89bde6e1c9..482f10d09d 100644 --- a/src/dawn_native/opengl/CommandBufferGL.h +++ b/src/dawn_native/opengl/CommandBufferGL.h @@ -26,14 +26,14 @@ namespace dawn_native { namespace opengl { class Device; - class CommandBuffer : public CommandBufferBase { + class CommandBuffer final : public CommandBufferBase { public: CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); - ~CommandBuffer(); void Execute(); private: + ~CommandBuffer() override; void ExecuteComputePass(); void ExecuteRenderPass(BeginRenderPassCmd* renderPass); diff --git a/src/dawn_native/opengl/ComputePipelineGL.h b/src/dawn_native/opengl/ComputePipelineGL.h index 73b4fe6818..95f6db9131 100644 --- a/src/dawn_native/opengl/ComputePipelineGL.h +++ b/src/dawn_native/opengl/ComputePipelineGL.h @@ -25,11 +25,14 @@ namespace dawn_native { namespace opengl { class Device; - class ComputePipeline : public ComputePipelineBase, public PipelineGL { + class ComputePipeline final : public ComputePipelineBase, public PipelineGL { public: ComputePipeline(Device* device, const ComputePipelineDescriptor* descriptor); void ApplyNow(); + + private: + ~ComputePipeline() override = default; }; }} // namespace dawn_native::opengl diff --git a/src/dawn_native/opengl/PipelineLayoutGL.h b/src/dawn_native/opengl/PipelineLayoutGL.h index 39eb802088..fb03aaf7ce 100644 --- a/src/dawn_native/opengl/PipelineLayoutGL.h +++ b/src/dawn_native/opengl/PipelineLayoutGL.h @@ -23,7 +23,7 @@ namespace dawn_native { namespace opengl { class Device; - class PipelineLayout : public PipelineLayoutBase { + class PipelineLayout final : public PipelineLayoutBase { public: PipelineLayout(Device* device, const PipelineLayoutDescriptor* descriptor); @@ -36,6 +36,7 @@ namespace dawn_native { namespace opengl { size_t GetNumSampledTextures() const; private: + ~PipelineLayout() override = default; BindingIndexInfo mIndexInfo; size_t mNumSamplers; size_t mNumSampledTextures; diff --git a/src/dawn_native/opengl/QueueGL.h b/src/dawn_native/opengl/QueueGL.h index c18486ce2a..d62e90d09a 100644 --- a/src/dawn_native/opengl/QueueGL.h +++ b/src/dawn_native/opengl/QueueGL.h @@ -22,7 +22,7 @@ namespace dawn_native { namespace opengl { class CommandBuffer; class Device; - class Queue : public QueueBase { + class Queue final : public QueueBase { public: Queue(Device* device); diff --git a/src/dawn_native/opengl/RenderPipelineGL.h b/src/dawn_native/opengl/RenderPipelineGL.h index b8bcb26d2c..2f3363a4bd 100644 --- a/src/dawn_native/opengl/RenderPipelineGL.h +++ b/src/dawn_native/opengl/RenderPipelineGL.h @@ -27,16 +27,16 @@ namespace dawn_native { namespace opengl { class Device; class PersistentPipelineState; - class RenderPipeline : public RenderPipelineBase, public PipelineGL { + class RenderPipeline final : public RenderPipelineBase, public PipelineGL { public: RenderPipeline(Device* device, const RenderPipelineDescriptor* descriptor); - ~RenderPipeline(); GLenum GetGLPrimitiveTopology() const; void ApplyNow(PersistentPipelineState& persistentPipelineState); private: + ~RenderPipeline() override; void CreateVAOForVertexState(const VertexStateDescriptor* vertexState); // TODO(yunchao.he@intel.com): vao need to be deduplicated between pipelines. diff --git a/src/dawn_native/opengl/SamplerGL.h b/src/dawn_native/opengl/SamplerGL.h index 19b185b10f..0644890747 100644 --- a/src/dawn_native/opengl/SamplerGL.h +++ b/src/dawn_native/opengl/SamplerGL.h @@ -23,15 +23,16 @@ namespace dawn_native { namespace opengl { class Device; - class Sampler : public SamplerBase { + class Sampler final : public SamplerBase { public: Sampler(Device* device, const SamplerDescriptor* descriptor); - ~Sampler(); GLuint GetFilteringHandle() const; GLuint GetNonFilteringHandle() const; private: + ~Sampler() override; + void SetupGLSampler(GLuint sampler, const SamplerDescriptor* descriptor, bool forceNearest); GLuint mFilteringHandle; diff --git a/src/dawn_native/opengl/ShaderModuleGL.cpp b/src/dawn_native/opengl/ShaderModuleGL.cpp index 4174fe413a..86398c9087 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.cpp +++ b/src/dawn_native/opengl/ShaderModuleGL.cpp @@ -50,11 +50,9 @@ namespace dawn_native { namespace opengl { // static ResultOrError ShaderModule::Create(Device* device, const ShaderModuleDescriptor* descriptor) { - std::unique_ptr module(new ShaderModule(device, descriptor)); - if (!module) - return DAWN_VALIDATION_ERROR("Unable to create ShaderModule"); + Ref module = AcquireRef(new ShaderModule(device, descriptor)); DAWN_TRY(module->Initialize(descriptor)); - return module.release(); + return module.Detach(); } const char* ShaderModule::GetSource() const { diff --git a/src/dawn_native/opengl/ShaderModuleGL.h b/src/dawn_native/opengl/ShaderModuleGL.h index 5764c583d6..849f2da112 100644 --- a/src/dawn_native/opengl/ShaderModuleGL.h +++ b/src/dawn_native/opengl/ShaderModuleGL.h @@ -38,7 +38,7 @@ namespace dawn_native { namespace opengl { }; bool operator<(const CombinedSampler& a, const CombinedSampler& b); - class ShaderModule : public ShaderModuleBase { + class ShaderModule final : public ShaderModuleBase { public: static ResultOrError Create(Device* device, const ShaderModuleDescriptor* descriptor); @@ -50,6 +50,7 @@ namespace dawn_native { namespace opengl { private: ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor); + ~ShaderModule() override = default; MaybeError Initialize(const ShaderModuleDescriptor* descriptor); CombinedSamplerInfo mCombinedInfo; diff --git a/src/dawn_native/opengl/SwapChainGL.h b/src/dawn_native/opengl/SwapChainGL.h index 2fbe2c8622..a483e70c6b 100644 --- a/src/dawn_native/opengl/SwapChainGL.h +++ b/src/dawn_native/opengl/SwapChainGL.h @@ -23,12 +23,12 @@ namespace dawn_native { namespace opengl { class Device; - class SwapChain : public OldSwapChainBase { + class SwapChain final : public OldSwapChainBase { public: SwapChain(Device* device, const SwapChainDescriptor* descriptor); - ~SwapChain(); protected: + ~SwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureBase* texture) override; }; diff --git a/src/dawn_native/opengl/TextureGL.h b/src/dawn_native/opengl/TextureGL.h index 8e18116ae4..b48cda335d 100644 --- a/src/dawn_native/opengl/TextureGL.h +++ b/src/dawn_native/opengl/TextureGL.h @@ -24,14 +24,13 @@ namespace dawn_native { namespace opengl { class Device; struct GLFormat; - class Texture : public TextureBase { + class Texture final : public TextureBase { public: Texture(Device* device, const TextureDescriptor* descriptor); Texture(Device* device, const TextureDescriptor* descriptor, GLuint handle, TextureState state); - ~Texture(); GLuint GetHandle() const; GLenum GetGLTarget() const; @@ -43,6 +42,8 @@ namespace dawn_native { namespace opengl { uint32_t layerCount); private: + ~Texture() override; + void DestroyImpl() override; MaybeError ClearTexture(GLint baseMipLevel, GLint levelCount, @@ -54,15 +55,16 @@ namespace dawn_native { namespace opengl { GLenum mTarget; }; - class TextureView : public TextureViewBase { + class TextureView final : public TextureViewBase { public: TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor); - ~TextureView(); GLuint GetHandle() const; GLenum GetGLTarget() const; private: + ~TextureView() override; + GLuint mHandle; GLenum mTarget; bool mOwnsHandle; diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp index d69449244a..5c64da0590 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.cpp +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.cpp @@ -75,10 +75,9 @@ namespace dawn_native { namespace vulkan { ResultOrError BindGroupLayout::Create( Device* device, const BindGroupLayoutDescriptor* descriptor) { - std::unique_ptr bgl = - std::make_unique(device, descriptor); + Ref bgl = AcquireRef(new BindGroupLayout(device, descriptor)); DAWN_TRY(bgl->Initialize()); - return bgl.release(); + return bgl.Detach(); } MaybeError BindGroupLayout::Initialize() { diff --git a/src/dawn_native/vulkan/BindGroupLayoutVk.h b/src/dawn_native/vulkan/BindGroupLayoutVk.h index 47d8abef57..e06b36423a 100644 --- a/src/dawn_native/vulkan/BindGroupLayoutVk.h +++ b/src/dawn_native/vulkan/BindGroupLayoutVk.h @@ -47,13 +47,12 @@ namespace dawn_native { namespace vulkan { // the pools are reused when no longer used. Minimizing the number of descriptor pool allocation // is important because creating them can incur GPU memory allocation which is usually an // expensive syscall. - class BindGroupLayout : public BindGroupLayoutBase { + class BindGroupLayout final : public BindGroupLayoutBase { public: static ResultOrError Create(Device* device, const BindGroupLayoutDescriptor* descriptor); BindGroupLayout(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor); - ~BindGroupLayout(); VkDescriptorSetLayout GetHandle() const; @@ -68,6 +67,7 @@ namespace dawn_native { namespace vulkan { void FinishDeallocation(size_t index); private: + ~BindGroupLayout() override; MaybeError Initialize(); std::vector mPoolSizes; diff --git a/src/dawn_native/vulkan/BindGroupVk.h b/src/dawn_native/vulkan/BindGroupVk.h index c912fe2ef2..ce6644589f 100644 --- a/src/dawn_native/vulkan/BindGroupVk.h +++ b/src/dawn_native/vulkan/BindGroupVk.h @@ -25,7 +25,7 @@ namespace dawn_native { namespace vulkan { class Device; - class BindGroup : public BindGroupBase, public PlacementAllocated { + class BindGroup final : public BindGroupBase, public PlacementAllocated { public: static ResultOrError Create(Device* device, const BindGroupDescriptor* descriptor); @@ -33,11 +33,12 @@ namespace dawn_native { namespace vulkan { BindGroup(Device* device, const BindGroupDescriptor* descriptor, DescriptorSetAllocation descriptorSetAllocation); - ~BindGroup() override; VkDescriptorSet GetHandle() const; private: + ~BindGroup() override; + // The descriptor set in this allocation outlives the BindGroup because it is owned by // the BindGroupLayout which is referenced by the BindGroup. DescriptorSetAllocation mDescriptorSetAllocation; diff --git a/src/dawn_native/vulkan/BufferVk.cpp b/src/dawn_native/vulkan/BufferVk.cpp index 4a1af60588..a94088ab72 100644 --- a/src/dawn_native/vulkan/BufferVk.cpp +++ b/src/dawn_native/vulkan/BufferVk.cpp @@ -117,9 +117,9 @@ namespace dawn_native { namespace vulkan { // static ResultOrError Buffer::Create(Device* device, const BufferDescriptor* descriptor) { - std::unique_ptr buffer = std::make_unique(device, descriptor); + Ref buffer = AcquireRef(new Buffer(device, descriptor)); DAWN_TRY(buffer->Initialize()); - return buffer.release(); + return buffer.Detach(); } MaybeError Buffer::Initialize() { diff --git a/src/dawn_native/vulkan/BufferVk.h b/src/dawn_native/vulkan/BufferVk.h index 34a94a43ab..3d7fdf9134 100644 --- a/src/dawn_native/vulkan/BufferVk.h +++ b/src/dawn_native/vulkan/BufferVk.h @@ -26,10 +26,9 @@ namespace dawn_native { namespace vulkan { struct CommandRecordingContext; class Device; - class Buffer : public BufferBase { + class Buffer final : public BufferBase { public: static ResultOrError Create(Device* device, const BufferDescriptor* descriptor); - ~Buffer(); void OnMapReadCommandSerialFinished(uint32_t mapSerial, const void* data); void OnMapWriteCommandSerialFinished(uint32_t mapSerial, void* data); @@ -42,6 +41,7 @@ namespace dawn_native { namespace vulkan { void TransitionUsageNow(CommandRecordingContext* recordingContext, wgpu::BufferUsage usage); private: + ~Buffer() override; using BufferBase::BufferBase; MaybeError Initialize(); diff --git a/src/dawn_native/vulkan/CommandBufferVk.h b/src/dawn_native/vulkan/CommandBufferVk.h index 1b3994941e..c60fa9278f 100644 --- a/src/dawn_native/vulkan/CommandBufferVk.h +++ b/src/dawn_native/vulkan/CommandBufferVk.h @@ -31,16 +31,16 @@ namespace dawn_native { namespace vulkan { struct CommandRecordingContext; class Device; - class CommandBuffer : public CommandBufferBase { + class CommandBuffer final : public CommandBufferBase { public: static CommandBuffer* Create(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); - ~CommandBuffer(); MaybeError RecordCommands(CommandRecordingContext* recordingContext); private: CommandBuffer(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); + ~CommandBuffer() override; void RecordComputePass(CommandRecordingContext* recordingContext); MaybeError RecordRenderPass(CommandRecordingContext* recordingContext, diff --git a/src/dawn_native/vulkan/ComputePipelineVk.cpp b/src/dawn_native/vulkan/ComputePipelineVk.cpp index 16dd8e7d15..b4a9dda9a6 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.cpp +++ b/src/dawn_native/vulkan/ComputePipelineVk.cpp @@ -26,10 +26,9 @@ namespace dawn_native { namespace vulkan { ResultOrError ComputePipeline::Create( Device* device, const ComputePipelineDescriptor* descriptor) { - std::unique_ptr pipeline = - std::make_unique(device, descriptor); + Ref pipeline = AcquireRef(new ComputePipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.release(); + return pipeline.Detach(); } MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/ComputePipelineVk.h b/src/dawn_native/vulkan/ComputePipelineVk.h index ca35847879..6aa98a4ef8 100644 --- a/src/dawn_native/vulkan/ComputePipelineVk.h +++ b/src/dawn_native/vulkan/ComputePipelineVk.h @@ -24,15 +24,15 @@ namespace dawn_native { namespace vulkan { class Device; - class ComputePipeline : public ComputePipelineBase { + class ComputePipeline final : public ComputePipelineBase { public: static ResultOrError Create(Device* device, const ComputePipelineDescriptor* descriptor); - ~ComputePipeline(); VkPipeline GetHandle() const; private: + ~ComputePipeline() override; using ComputePipelineBase::ComputePipelineBase; MaybeError Initialize(const ComputePipelineDescriptor* descriptor); diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index 4561a33863..6ee6b5153c 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -698,7 +698,7 @@ namespace dawn_native { namespace vulkan { waitSemaphores))) { // Delete the Texture if it was created if (result != nullptr) { - delete result; + result->Release(); } // Clear the signal semaphore diff --git a/src/dawn_native/vulkan/PipelineLayoutVk.cpp b/src/dawn_native/vulkan/PipelineLayoutVk.cpp index 847ba60f82..87b47ab77f 100644 --- a/src/dawn_native/vulkan/PipelineLayoutVk.cpp +++ b/src/dawn_native/vulkan/PipelineLayoutVk.cpp @@ -26,10 +26,9 @@ namespace dawn_native { namespace vulkan { ResultOrError PipelineLayout::Create( Device* device, const PipelineLayoutDescriptor* descriptor) { - std::unique_ptr layout = - std::make_unique(device, descriptor); + Ref layout = AcquireRef(new PipelineLayout(device, descriptor)); DAWN_TRY(layout->Initialize()); - return layout.release(); + return layout.Detach(); } MaybeError PipelineLayout::Initialize() { diff --git a/src/dawn_native/vulkan/PipelineLayoutVk.h b/src/dawn_native/vulkan/PipelineLayoutVk.h index 744eb84791..fe136e4d0d 100644 --- a/src/dawn_native/vulkan/PipelineLayoutVk.h +++ b/src/dawn_native/vulkan/PipelineLayoutVk.h @@ -24,15 +24,15 @@ namespace dawn_native { namespace vulkan { class Device; - class PipelineLayout : public PipelineLayoutBase { + class PipelineLayout final : public PipelineLayoutBase { public: static ResultOrError Create(Device* device, const PipelineLayoutDescriptor* descriptor); - ~PipelineLayout(); VkPipelineLayout GetHandle() const; private: + ~PipelineLayout() override; using PipelineLayoutBase::PipelineLayoutBase; MaybeError Initialize(); diff --git a/src/dawn_native/vulkan/QueueVk.h b/src/dawn_native/vulkan/QueueVk.h index 39e8314a25..715f5eb90d 100644 --- a/src/dawn_native/vulkan/QueueVk.h +++ b/src/dawn_native/vulkan/QueueVk.h @@ -22,12 +22,12 @@ namespace dawn_native { namespace vulkan { class CommandBuffer; class Device; - class Queue : public QueueBase { + class Queue final : public QueueBase { public: static Queue* Create(Device* device); - ~Queue(); private: + ~Queue() override; using QueueBase::QueueBase; MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override; diff --git a/src/dawn_native/vulkan/RenderPipelineVk.cpp b/src/dawn_native/vulkan/RenderPipelineVk.cpp index 88447fb73e..5053e01e79 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.cpp +++ b/src/dawn_native/vulkan/RenderPipelineVk.cpp @@ -327,10 +327,9 @@ namespace dawn_native { namespace vulkan { ResultOrError RenderPipeline::Create( Device* device, const RenderPipelineDescriptor* descriptor) { - std::unique_ptr pipeline = - std::make_unique(device, descriptor); + Ref pipeline = AcquireRef(new RenderPipeline(device, descriptor)); DAWN_TRY(pipeline->Initialize(descriptor)); - return pipeline.release(); + return pipeline.Detach(); } MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/RenderPipelineVk.h b/src/dawn_native/vulkan/RenderPipelineVk.h index 6c61a6e5bc..4613f322c3 100644 --- a/src/dawn_native/vulkan/RenderPipelineVk.h +++ b/src/dawn_native/vulkan/RenderPipelineVk.h @@ -24,15 +24,15 @@ namespace dawn_native { namespace vulkan { class Device; - class RenderPipeline : public RenderPipelineBase { + class RenderPipeline final : public RenderPipelineBase { public: static ResultOrError Create(Device* device, const RenderPipelineDescriptor* descriptor); - ~RenderPipeline(); VkPipeline GetHandle() const; private: + ~RenderPipeline() override; using RenderPipelineBase::RenderPipelineBase; MaybeError Initialize(const RenderPipelineDescriptor* descriptor); diff --git a/src/dawn_native/vulkan/SamplerVk.cpp b/src/dawn_native/vulkan/SamplerVk.cpp index 67d70f8d7c..5b8247263e 100644 --- a/src/dawn_native/vulkan/SamplerVk.cpp +++ b/src/dawn_native/vulkan/SamplerVk.cpp @@ -60,9 +60,9 @@ namespace dawn_native { namespace vulkan { // static ResultOrError Sampler::Create(Device* device, const SamplerDescriptor* descriptor) { - std::unique_ptr sampler = std::make_unique(device, descriptor); + Ref sampler = AcquireRef(new Sampler(device, descriptor)); DAWN_TRY(sampler->Initialize(descriptor)); - return sampler.release(); + return sampler.Detach(); } MaybeError Sampler::Initialize(const SamplerDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/SamplerVk.h b/src/dawn_native/vulkan/SamplerVk.h index e7b88747c0..72f7d79b15 100644 --- a/src/dawn_native/vulkan/SamplerVk.h +++ b/src/dawn_native/vulkan/SamplerVk.h @@ -24,14 +24,14 @@ namespace dawn_native { namespace vulkan { class Device; - class Sampler : public SamplerBase { + class Sampler final : public SamplerBase { public: static ResultOrError Create(Device* device, const SamplerDescriptor* descriptor); - ~Sampler(); VkSampler GetHandle() const; private: + ~Sampler() override; using SamplerBase::SamplerBase; MaybeError Initialize(const SamplerDescriptor* descriptor); diff --git a/src/dawn_native/vulkan/ShaderModuleVk.cpp b/src/dawn_native/vulkan/ShaderModuleVk.cpp index 60c6ba6e19..8cc8265120 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.cpp +++ b/src/dawn_native/vulkan/ShaderModuleVk.cpp @@ -25,11 +25,11 @@ namespace dawn_native { namespace vulkan { // static ResultOrError ShaderModule::Create(Device* device, const ShaderModuleDescriptor* descriptor) { - std::unique_ptr module(new ShaderModule(device, descriptor)); + Ref module = AcquireRef(new ShaderModule(device, descriptor)); if (!module) return DAWN_VALIDATION_ERROR("Unable to create ShaderModule"); DAWN_TRY(module->Initialize(descriptor)); - return module.release(); + return module.Detach(); } ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor) diff --git a/src/dawn_native/vulkan/ShaderModuleVk.h b/src/dawn_native/vulkan/ShaderModuleVk.h index 01643920b1..962ccf8146 100644 --- a/src/dawn_native/vulkan/ShaderModuleVk.h +++ b/src/dawn_native/vulkan/ShaderModuleVk.h @@ -24,16 +24,16 @@ namespace dawn_native { namespace vulkan { class Device; - class ShaderModule : public ShaderModuleBase { + class ShaderModule final : public ShaderModuleBase { public: static ResultOrError Create(Device* device, const ShaderModuleDescriptor* descriptor); - ~ShaderModule(); VkShaderModule GetHandle() const; private: ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor); + ~ShaderModule() override; MaybeError Initialize(const ShaderModuleDescriptor* descriptor); VkShaderModule mHandle = VK_NULL_HANDLE; diff --git a/src/dawn_native/vulkan/SwapChainVk.h b/src/dawn_native/vulkan/SwapChainVk.h index f878996e31..7765fc0c50 100644 --- a/src/dawn_native/vulkan/SwapChainVk.h +++ b/src/dawn_native/vulkan/SwapChainVk.h @@ -23,13 +23,13 @@ namespace dawn_native { namespace vulkan { class Device; - class SwapChain : public OldSwapChainBase { + class SwapChain final : public OldSwapChainBase { public: static SwapChain* Create(Device* device, const SwapChainDescriptor* descriptor); - ~SwapChain(); protected: SwapChain(Device* device, const SwapChainDescriptor* descriptor); + ~SwapChain() override; TextureBase* GetNextTextureImpl(const TextureDescriptor* descriptor) override; MaybeError OnBeforePresent(TextureBase* texture) override; diff --git a/src/dawn_native/vulkan/TextureVk.cpp b/src/dawn_native/vulkan/TextureVk.cpp index 90fae81909..a98a2b7bb6 100644 --- a/src/dawn_native/vulkan/TextureVk.cpp +++ b/src/dawn_native/vulkan/TextureVk.cpp @@ -407,10 +407,10 @@ namespace dawn_native { namespace vulkan { // static ResultOrError Texture::Create(Device* device, const TextureDescriptor* descriptor) { - std::unique_ptr texture = - std::make_unique(device, descriptor, TextureState::OwnedInternal); + Ref texture = + AcquireRef(new Texture(device, descriptor, TextureState::OwnedInternal)); DAWN_TRY(texture->InitializeAsInternalTexture()); - return texture.release(); + return texture.Detach(); } // static @@ -419,10 +419,10 @@ namespace dawn_native { namespace vulkan { const ExternalImageDescriptor* descriptor, const TextureDescriptor* textureDescriptor, external_memory::Service* externalMemoryService) { - std::unique_ptr texture = - std::make_unique(device, textureDescriptor, TextureState::OwnedInternal); + Ref texture = + AcquireRef(new Texture(device, textureDescriptor, TextureState::OwnedInternal)); DAWN_TRY(texture->InitializeFromExternal(descriptor, externalMemoryService)); - return texture.release(); + return texture.Detach(); } MaybeError Texture::InitializeAsInternalTexture() { @@ -803,9 +803,9 @@ namespace dawn_native { namespace vulkan { // static ResultOrError TextureView::Create(TextureBase* texture, const TextureViewDescriptor* descriptor) { - std::unique_ptr view = std::make_unique(texture, descriptor); + Ref view = AcquireRef(new TextureView(texture, descriptor)); DAWN_TRY(view->Initialize(descriptor)); - return view.release(); + return view.Detach(); } MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) { diff --git a/src/dawn_native/vulkan/TextureVk.h b/src/dawn_native/vulkan/TextureVk.h index 2c898ffcc1..600e9a676a 100644 --- a/src/dawn_native/vulkan/TextureVk.h +++ b/src/dawn_native/vulkan/TextureVk.h @@ -37,7 +37,7 @@ namespace dawn_native { namespace vulkan { bool IsSampleCountSupported(const dawn_native::vulkan::Device* device, const VkImageCreateInfo& imageCreateInfo); - class Texture : public TextureBase { + class Texture final : public TextureBase { public: // Used to create a regular texture from a descriptor. static ResultOrError Create(Device* device, const TextureDescriptor* descriptor); @@ -52,7 +52,6 @@ namespace dawn_native { namespace vulkan { external_memory::Service* externalMemoryService); Texture(Device* device, const TextureDescriptor* descriptor, VkImage nativeImage); - ~Texture(); VkImage GetHandle() const; VkImageAspectFlags GetVkAspectMask() const; @@ -77,6 +76,7 @@ namespace dawn_native { namespace vulkan { std::vector waitSemaphores); private: + ~Texture() override; using TextureBase::TextureBase; MaybeError InitializeAsInternalTexture(); @@ -113,15 +113,14 @@ namespace dawn_native { namespace vulkan { wgpu::TextureUsage mLastUsage = wgpu::TextureUsage::None; }; - class TextureView : public TextureViewBase { + class TextureView final : public TextureViewBase { public: static ResultOrError Create(TextureBase* texture, const TextureViewDescriptor* descriptor); - ~TextureView(); - VkImageView GetHandle() const; private: + ~TextureView() override; using TextureViewBase::TextureViewBase; MaybeError Initialize(const TextureViewDescriptor* descriptor);