Make RefCounted derived objects have private destructors

RefCounted (and derived) destructors should be protected on the class
to ensure the objects can ONLY be destructed by calling Release. This
avoids errors cause by destroying objects out from under code which
has an active reference count.

Unfortunately, many of the 'base' classes must continue having public
destructors because they are used as "blueprint" objects created on
the stack.

Added final on most-derived classes.

Ideas for future improvement:
- Change "base" objects to have protected destructors but create new
blueprint objects that privately derive from base objects. This
limits the blueprint object's usefulness to only be a blueprint.
- Modify createX methods to return Ref<Object> instead of Object*

Change-Id: I6f3b3b178118d135c4342cb912e982a3873d71af
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/18780
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Rafael Cintron 2020-04-06 18:20:02 +00:00 committed by Commit Bot service account
parent 022d074c06
commit c64242d4c2
83 changed files with 209 additions and 191 deletions

View File

@ -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<kMaxColorAttachments> 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

View File

@ -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<BindGroupBase, Derived>::value, "");
}
protected:
~BindGroupBase() override;
private:
BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag);

View File

@ -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) {
}

View File

@ -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,

View File

@ -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<BufferBase*> 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(

View File

@ -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<BufferBase*> CreateBufferInternal(const BufferDescriptor* descriptor);
MaybeError CreateComputePipelineInternal(ComputePipelineBase** result,
const ComputePipelineDescriptor* descriptor);
MaybeError CreatePipelineLayoutInternal(PipelineLayoutBase** result,

View File

@ -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);

View File

@ -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;

View File

@ -26,9 +26,6 @@ namespace dawn_native {
: RefCounted(kErrorPayload), mDevice(device) {
}
ObjectBase::~ObjectBase() {
}
DeviceBase* ObjectBase::GetDevice() const {
return mDevice;
}

View File

@ -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;
};

View File

@ -28,9 +28,6 @@ namespace dawn_native {
ASSERT((payload & kPayloadMask) == payload);
}
RefCounted::~RefCounted() {
}
uint64_t RefCounted::GetRefCountForTesting() const {
return mRefCount >> kPayloadBits;
}

View File

@ -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;
};

View File

@ -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);

View File

@ -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<InstanceBase> mInstance;
Type mType;

View File

@ -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) {
}

View File

@ -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;

View File

@ -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<bool> 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;

View File

@ -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<uint32_t, kMaxBindingsPerGroup> mBindingOffsets;
std::array<uint32_t, DescriptorType::Count> mDescriptorCounts;
D3D12_DESCRIPTOR_RANGE mRanges[DescriptorType::Count];

View File

@ -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;

View File

@ -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,

View File

@ -25,10 +25,9 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<ComputePipeline*> ComputePipeline::Create(
Device* device,
const ComputePipelineDescriptor* descriptor) {
std::unique_ptr<ComputePipeline> pipeline =
std::make_unique<ComputePipeline>(device, descriptor);
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.release();
return pipeline.Detach();
}
MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) {

View File

@ -23,16 +23,16 @@ namespace dawn_native { namespace d3d12 {
class Device;
class ComputePipeline : public ComputePipelineBase {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<ComputePipeline*> Create(Device* device,
const ComputePipelineDescriptor* descriptor);
ComputePipeline() = delete;
~ComputePipeline();
ComPtr<ID3D12PipelineState> GetPipelineState();
private:
~ComputePipeline() override;
using ComputePipelineBase::ComputePipelineBase;
MaybeError Initialize(const ComputePipelineDescriptor* descriptor);
ComPtr<ID3D12PipelineState> mPipelineState;

View File

@ -237,9 +237,9 @@ namespace dawn_native { namespace d3d12 {
return new BindGroupLayout(this, descriptor);
}
ResultOrError<BufferBase*> Device::CreateBufferImpl(const BufferDescriptor* descriptor) {
std::unique_ptr<Buffer> buffer = std::make_unique<Buffer>(this, descriptor);
Ref<Buffer> buffer = AcquireRef(new Buffer(this, descriptor));
DAWN_TRY(buffer->Initialize());
return buffer.release();
return buffer.Detach();
}
CommandBufferBase* Device::CreateCommandBuffer(CommandEncoder* encoder,
const CommandBufferDescriptor* descriptor) {

View File

@ -61,10 +61,9 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<PipelineLayout*> PipelineLayout::Create(
Device* device,
const PipelineLayoutDescriptor* descriptor) {
std::unique_ptr<PipelineLayout> layout =
std::make_unique<PipelineLayout>(device, descriptor);
Ref<PipelineLayout> layout = AcquireRef(new PipelineLayout(device, descriptor));
DAWN_TRY(layout->Initialize());
return layout.release();
return layout.Detach();
}
MaybeError PipelineLayout::Initialize() {

View File

@ -23,7 +23,7 @@ namespace dawn_native { namespace d3d12 {
class Device;
class PipelineLayout : public PipelineLayoutBase {
class PipelineLayout final : public PipelineLayoutBase {
public:
static ResultOrError<PipelineLayout*> Create(Device* device,
const PipelineLayoutDescriptor* descriptor);
@ -37,6 +37,7 @@ namespace dawn_native { namespace d3d12 {
ComPtr<ID3D12RootSignature> GetRootSignature() const;
private:
~PipelineLayout() override = default;
using PipelineLayoutBase::PipelineLayoutBase;
MaybeError Initialize();
std::array<uint32_t, kMaxBindGroups> mCbvUavSrvRootParameterInfo;

View File

@ -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);

View File

@ -293,10 +293,9 @@ namespace dawn_native { namespace d3d12 {
ResultOrError<RenderPipeline*> RenderPipeline::Create(
Device* device,
const RenderPipelineDescriptor* descriptor) {
std::unique_ptr<RenderPipeline> pipeline =
std::make_unique<RenderPipeline>(device, descriptor);
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.release();
return pipeline.Detach();
}
MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) {

View File

@ -23,17 +23,17 @@ namespace dawn_native { namespace d3d12 {
class Device;
class RenderPipeline : public RenderPipelineBase {
class RenderPipeline final : public RenderPipelineBase {
public:
static ResultOrError<RenderPipeline*> Create(Device* device,
const RenderPipelineDescriptor* descriptor);
RenderPipeline() = delete;
~RenderPipeline();
D3D12_PRIMITIVE_TOPOLOGY GetD3D12PrimitiveTopology() const;
ComPtr<ID3D12PipelineState> GetPipelineState();
private:
~RenderPipeline() override;
using RenderPipelineBase::RenderPipelineBase;
MaybeError Initialize(const RenderPipelineDescriptor* descriptor);
D3D12_INPUT_LAYOUT_DESC ComputeInputLayout(

View File

@ -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 = {};
};

View File

@ -27,11 +27,9 @@ namespace dawn_native { namespace d3d12 {
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor) {
std::unique_ptr<ShaderModule> module(new ShaderModule(device, descriptor));
if (!module)
return DAWN_VALIDATION_ERROR("Unable to create ShaderModule");
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
DAWN_TRY(module->Initialize(descriptor));
return module.release();
return module.Detach();
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)

View File

@ -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<ShaderModule*> 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<uint32_t> mSpirv;

View File

@ -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;

View File

@ -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<TextureBase*> Create(Device* device,
const TextureDescriptor* descriptor);
@ -45,8 +45,6 @@ namespace dawn_native { namespace d3d12 {
const TextureDescriptor* descriptor,
ComPtr<ID3D12Resource> 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<IDXGIKeyedMutex> mDxgiKeyedMutex;
};
class TextureView : public TextureViewBase {
class TextureView final : public TextureViewBase {
public:
TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);

View File

@ -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<BindGroup> mBindGroupAllocator;
};

View File

@ -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

View File

@ -27,13 +27,13 @@ namespace dawn_native { namespace metal {
class Buffer : public BufferBase {
public:
Buffer(Device* device, const BufferDescriptor* descriptor);
~Buffer();
id<MTLBuffer> 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;

View File

@ -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,

View File

@ -23,17 +23,17 @@ namespace dawn_native { namespace metal {
class Device;
class ComputePipeline : public ComputePipelineBase {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<ComputePipeline*> Create(Device* device,
const ComputePipelineDescriptor* descriptor);
~ComputePipeline();
void Encode(id<MTLComputeCommandEncoder> encoder);
MTLSize GetLocalWorkGroupSize() const;
bool RequiresStorageBufferLength() const;
private:
~ComputePipeline() override;
using ComputePipelineBase::ComputePipelineBase;
MaybeError Initialize(const ComputePipelineDescriptor* descriptor);

View File

@ -23,10 +23,9 @@ namespace dawn_native { namespace metal {
ResultOrError<ComputePipeline*> ComputePipeline::Create(
Device* device,
const ComputePipelineDescriptor* descriptor) {
std::unique_ptr<ComputePipeline> pipeline =
std::make_unique<ComputePipeline>(device, descriptor);
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.release();
return pipeline.Detach();
}
MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) {

View File

@ -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<BindingIndexInfo> mIndexInfo;
PerStage<uint32_t> mBufferBindingCount;
};

View File

@ -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);

View File

@ -23,11 +23,10 @@ namespace dawn_native { namespace metal {
class Device;
class RenderPipeline : public RenderPipelineBase {
class RenderPipeline final : public RenderPipelineBase {
public:
static ResultOrError<RenderPipeline*> 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);

View File

@ -315,10 +315,9 @@ namespace dawn_native { namespace metal {
ResultOrError<RenderPipeline*> RenderPipeline::Create(
Device* device,
const RenderPipelineDescriptor* descriptor) {
std::unique_ptr<RenderPipeline> pipeline =
std::make_unique<RenderPipeline>(device, descriptor);
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.release();
return pipeline.Detach();
}
MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) {

View File

@ -23,15 +23,16 @@ namespace dawn_native { namespace metal {
class Device;
class Sampler : public SamplerBase {
class Sampler final : public SamplerBase {
public:
static ResultOrError<Sampler*> Create(Device* device, const SamplerDescriptor* descriptor);
~Sampler();
id<MTLSamplerState> GetMTLSamplerState();
private:
Sampler(Device* device, const SamplerDescriptor* descriptor);
~Sampler() override;
id<MTLSamplerState> mMtlSamplerState = nil;
};

View File

@ -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<ShaderModule*> 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();

View File

@ -57,11 +57,9 @@ namespace dawn_native { namespace metal {
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor) {
std::unique_ptr<ShaderModule> module(new ShaderModule(device, descriptor));
if (!module)
return DAWN_VALIDATION_ERROR("Unable to create ShaderModule");
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
DAWN_TRY(module->Initialize(descriptor));
return module.release();
return module.Detach();
}
ShaderModule::ShaderModule(Device* device, const ShaderModuleDescriptor* descriptor)

View File

@ -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<CAMetalDrawable> mCurrentDrawable = nil;

View File

@ -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> mtlTexture);
@ -39,7 +39,6 @@ namespace dawn_native { namespace metal {
const ExternalImageDescriptor* descriptor,
IOSurfaceRef ioSurface,
uint32_t plane);
~Texture();
id<MTLTexture> 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<MTLTexture> mMtlTexture = nil;
};
class TextureView : public TextureViewBase {
class TextureView final : public TextureViewBase {
public:
TextureView(TextureBase* texture, const TextureViewDescriptor* descriptor);
~TextureView();
id<MTLTexture> GetMTLTexture();
private:
~TextureView() override;
id<MTLTexture> mMtlTextureView = nil;
};

View File

@ -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<uint8_t[]> 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<Texture> 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;
};

View File

@ -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

View File

@ -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<BindGroup> mBindGroupAllocator;
};

View File

@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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.

View File

@ -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;

View File

@ -50,11 +50,9 @@ namespace dawn_native { namespace opengl {
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor) {
std::unique_ptr<ShaderModule> module(new ShaderModule(device, descriptor));
if (!module)
return DAWN_VALIDATION_ERROR("Unable to create ShaderModule");
Ref<ShaderModule> module = AcquireRef(new ShaderModule(device, descriptor));
DAWN_TRY(module->Initialize(descriptor));
return module.release();
return module.Detach();
}
const char* ShaderModule::GetSource() const {

View File

@ -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<ShaderModule*> 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;

View File

@ -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;
};

View File

@ -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;

View File

@ -75,10 +75,9 @@ namespace dawn_native { namespace vulkan {
ResultOrError<BindGroupLayout*> BindGroupLayout::Create(
Device* device,
const BindGroupLayoutDescriptor* descriptor) {
std::unique_ptr<BindGroupLayout> bgl =
std::make_unique<BindGroupLayout>(device, descriptor);
Ref<BindGroupLayout> bgl = AcquireRef(new BindGroupLayout(device, descriptor));
DAWN_TRY(bgl->Initialize());
return bgl.release();
return bgl.Detach();
}
MaybeError BindGroupLayout::Initialize() {

View File

@ -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<BindGroupLayout*> 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<VkDescriptorPoolSize> mPoolSizes;

View File

@ -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<BindGroup*> 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;

View File

@ -117,9 +117,9 @@ namespace dawn_native { namespace vulkan {
// static
ResultOrError<Buffer*> Buffer::Create(Device* device, const BufferDescriptor* descriptor) {
std::unique_ptr<Buffer> buffer = std::make_unique<Buffer>(device, descriptor);
Ref<Buffer> buffer = AcquireRef(new Buffer(device, descriptor));
DAWN_TRY(buffer->Initialize());
return buffer.release();
return buffer.Detach();
}
MaybeError Buffer::Initialize() {

View File

@ -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<Buffer*> 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();

View File

@ -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,

View File

@ -26,10 +26,9 @@ namespace dawn_native { namespace vulkan {
ResultOrError<ComputePipeline*> ComputePipeline::Create(
Device* device,
const ComputePipelineDescriptor* descriptor) {
std::unique_ptr<ComputePipeline> pipeline =
std::make_unique<ComputePipeline>(device, descriptor);
Ref<ComputePipeline> pipeline = AcquireRef(new ComputePipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.release();
return pipeline.Detach();
}
MaybeError ComputePipeline::Initialize(const ComputePipelineDescriptor* descriptor) {

View File

@ -24,15 +24,15 @@ namespace dawn_native { namespace vulkan {
class Device;
class ComputePipeline : public ComputePipelineBase {
class ComputePipeline final : public ComputePipelineBase {
public:
static ResultOrError<ComputePipeline*> Create(Device* device,
const ComputePipelineDescriptor* descriptor);
~ComputePipeline();
VkPipeline GetHandle() const;
private:
~ComputePipeline() override;
using ComputePipelineBase::ComputePipelineBase;
MaybeError Initialize(const ComputePipelineDescriptor* descriptor);

View File

@ -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

View File

@ -26,10 +26,9 @@ namespace dawn_native { namespace vulkan {
ResultOrError<PipelineLayout*> PipelineLayout::Create(
Device* device,
const PipelineLayoutDescriptor* descriptor) {
std::unique_ptr<PipelineLayout> layout =
std::make_unique<PipelineLayout>(device, descriptor);
Ref<PipelineLayout> layout = AcquireRef(new PipelineLayout(device, descriptor));
DAWN_TRY(layout->Initialize());
return layout.release();
return layout.Detach();
}
MaybeError PipelineLayout::Initialize() {

View File

@ -24,15 +24,15 @@ namespace dawn_native { namespace vulkan {
class Device;
class PipelineLayout : public PipelineLayoutBase {
class PipelineLayout final : public PipelineLayoutBase {
public:
static ResultOrError<PipelineLayout*> Create(Device* device,
const PipelineLayoutDescriptor* descriptor);
~PipelineLayout();
VkPipelineLayout GetHandle() const;
private:
~PipelineLayout() override;
using PipelineLayoutBase::PipelineLayoutBase;
MaybeError Initialize();

View File

@ -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;

View File

@ -327,10 +327,9 @@ namespace dawn_native { namespace vulkan {
ResultOrError<RenderPipeline*> RenderPipeline::Create(
Device* device,
const RenderPipelineDescriptor* descriptor) {
std::unique_ptr<RenderPipeline> pipeline =
std::make_unique<RenderPipeline>(device, descriptor);
Ref<RenderPipeline> pipeline = AcquireRef(new RenderPipeline(device, descriptor));
DAWN_TRY(pipeline->Initialize(descriptor));
return pipeline.release();
return pipeline.Detach();
}
MaybeError RenderPipeline::Initialize(const RenderPipelineDescriptor* descriptor) {

View File

@ -24,15 +24,15 @@ namespace dawn_native { namespace vulkan {
class Device;
class RenderPipeline : public RenderPipelineBase {
class RenderPipeline final : public RenderPipelineBase {
public:
static ResultOrError<RenderPipeline*> Create(Device* device,
const RenderPipelineDescriptor* descriptor);
~RenderPipeline();
VkPipeline GetHandle() const;
private:
~RenderPipeline() override;
using RenderPipelineBase::RenderPipelineBase;
MaybeError Initialize(const RenderPipelineDescriptor* descriptor);

View File

@ -60,9 +60,9 @@ namespace dawn_native { namespace vulkan {
// static
ResultOrError<Sampler*> Sampler::Create(Device* device, const SamplerDescriptor* descriptor) {
std::unique_ptr<Sampler> sampler = std::make_unique<Sampler>(device, descriptor);
Ref<Sampler> sampler = AcquireRef(new Sampler(device, descriptor));
DAWN_TRY(sampler->Initialize(descriptor));
return sampler.release();
return sampler.Detach();
}
MaybeError Sampler::Initialize(const SamplerDescriptor* descriptor) {

View File

@ -24,14 +24,14 @@ namespace dawn_native { namespace vulkan {
class Device;
class Sampler : public SamplerBase {
class Sampler final : public SamplerBase {
public:
static ResultOrError<Sampler*> Create(Device* device, const SamplerDescriptor* descriptor);
~Sampler();
VkSampler GetHandle() const;
private:
~Sampler() override;
using SamplerBase::SamplerBase;
MaybeError Initialize(const SamplerDescriptor* descriptor);

View File

@ -25,11 +25,11 @@ namespace dawn_native { namespace vulkan {
// static
ResultOrError<ShaderModule*> ShaderModule::Create(Device* device,
const ShaderModuleDescriptor* descriptor) {
std::unique_ptr<ShaderModule> module(new ShaderModule(device, descriptor));
Ref<ShaderModule> 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)

View File

@ -24,16 +24,16 @@ namespace dawn_native { namespace vulkan {
class Device;
class ShaderModule : public ShaderModuleBase {
class ShaderModule final : public ShaderModuleBase {
public:
static ResultOrError<ShaderModule*> 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;

View File

@ -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;

View File

@ -407,10 +407,10 @@ namespace dawn_native { namespace vulkan {
// static
ResultOrError<Texture*> Texture::Create(Device* device, const TextureDescriptor* descriptor) {
std::unique_ptr<Texture> texture =
std::make_unique<Texture>(device, descriptor, TextureState::OwnedInternal);
Ref<Texture> 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> texture =
std::make_unique<Texture>(device, textureDescriptor, TextureState::OwnedInternal);
Ref<Texture> 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*> TextureView::Create(TextureBase* texture,
const TextureViewDescriptor* descriptor) {
std::unique_ptr<TextureView> view = std::make_unique<TextureView>(texture, descriptor);
Ref<TextureView> view = AcquireRef(new TextureView(texture, descriptor));
DAWN_TRY(view->Initialize(descriptor));
return view.release();
return view.Detach();
}
MaybeError TextureView::Initialize(const TextureViewDescriptor* descriptor) {

View File

@ -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<Texture*> 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<VkSemaphore> 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<TextureView*> Create(TextureBase* texture,
const TextureViewDescriptor* descriptor);
~TextureView();
VkImageView GetHandle() const;
private:
~TextureView() override;
using TextureViewBase::TextureViewBase;
MaybeError Initialize(const TextureViewDescriptor* descriptor);