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

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