[chromium-style] Adding/moving constructors and destructors.

This CL adds some missing constructors and destructors. Others are moved
from the header file to implementation files.

Bug: dawn:1405
Change-Id: I17e98f6da48518112bafb0876679cc3989ba2548
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/89160
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair 2022-05-09 20:28:54 +00:00 committed by Dawn LUCI CQ
parent c5931800f2
commit 357bfa89d8
36 changed files with 176 additions and 10 deletions

View File

@ -66,6 +66,10 @@ android_LogPriority AndroidLogPriority(LogSeverity severity) {
LogMessage::LogMessage(LogSeverity severity) : mSeverity(severity) {}
LogMessage::LogMessage(LogMessage&& other) = default;
LogMessage& LogMessage::operator=(LogMessage&& other) = default;
LogMessage::~LogMessage() {
std::string fullMessage = mStream.str();

View File

@ -62,8 +62,8 @@ class LogMessage {
explicit LogMessage(LogSeverity severity);
~LogMessage();
LogMessage(LogMessage&& other) = default;
LogMessage& operator=(LogMessage&& other) = default;
LogMessage(LogMessage&& other);
LogMessage& operator=(LogMessage&& other);
template <typename T>
LogMessage& operator<<(T&& value) {

View File

@ -205,6 +205,8 @@ std::optional<std::string> GetModuleDirectory() {
// ScopedEnvironmentVar
ScopedEnvironmentVar::ScopedEnvironmentVar() = default;
ScopedEnvironmentVar::ScopedEnvironmentVar(const char* variableName, const char* value)
: mName(variableName),
mOriginalValue(GetEnvironmentVar(variableName)),

View File

@ -40,7 +40,7 @@ bool IsMacOSVersionAtLeast(uint32_t majorVersion, uint32_t minorVersion = 0);
class ScopedEnvironmentVar {
public:
ScopedEnvironmentVar() = default;
ScopedEnvironmentVar();
ScopedEnvironmentVar(const char* variableName, const char* value);
~ScopedEnvironmentVar();

View File

@ -253,6 +253,7 @@ source_set("sources") {
"ObjectBase.h",
"ObjectContentHasher.cpp",
"ObjectContentHasher.h",
"PassResourceUsage.cpp",
"PassResourceUsage.h",
"PassResourceUsageTracker.cpp",
"PassResourceUsageTracker.h",

View File

@ -119,6 +119,7 @@ target_sources(dawn_native PRIVATE
"Limits.h"
"ObjectBase.cpp"
"ObjectBase.h"
"PassResourceUsage.cpp"
"PassResourceUsage.h"
"PassResourceUsageTracker.cpp"
"PassResourceUsageTracker.h"

View File

@ -70,6 +70,20 @@ static constexpr CommandBufferStateTracker::ValidationAspects kLazyAspects =
1 << VALIDATION_ASPECT_BIND_GROUPS | 1 << VALIDATION_ASPECT_VERTEX_BUFFERS |
1 << VALIDATION_ASPECT_INDEX_BUFFER;
CommandBufferStateTracker::CommandBufferStateTracker() = default;
CommandBufferStateTracker::CommandBufferStateTracker(const CommandBufferStateTracker&) = default;
CommandBufferStateTracker::CommandBufferStateTracker(CommandBufferStateTracker&&) = default;
CommandBufferStateTracker::~CommandBufferStateTracker() = default;
CommandBufferStateTracker& CommandBufferStateTracker::operator=(const CommandBufferStateTracker&) =
default;
CommandBufferStateTracker& CommandBufferStateTracker::operator=(CommandBufferStateTracker&&) =
default;
MaybeError CommandBufferStateTracker::ValidateCanDispatch() {
return ValidateOperation(kDispatchAspects);
}

View File

@ -28,6 +28,14 @@ namespace dawn::native {
class CommandBufferStateTracker {
public:
CommandBufferStateTracker();
CommandBufferStateTracker(const CommandBufferStateTracker&);
CommandBufferStateTracker(CommandBufferStateTracker&&);
~CommandBufferStateTracker();
CommandBufferStateTracker& operator=(const CommandBufferStateTracker&);
CommandBufferStateTracker& operator=(CommandBufferStateTracker&&);
// Non-state-modifying validation functions
MaybeError ValidateCanDispatch();
MaybeError ValidateCanDraw();

View File

@ -42,6 +42,8 @@ OwnedCompilationMessages::OwnedCompilationMessages() {
mCompilationInfo.messages = nullptr;
}
OwnedCompilationMessages::~OwnedCompilationMessages() = default;
void OwnedCompilationMessages::AddMessageForTesting(std::string message,
wgpu::CompilationMessageType type,
uint64_t lineNum,

View File

@ -32,7 +32,7 @@ namespace dawn::native {
class OwnedCompilationMessages : public NonCopyable {
public:
OwnedCompilationMessages();
~OwnedCompilationMessages() = default;
~OwnedCompilationMessages();
void AddMessageForTesting(
std::string message,

View File

@ -35,6 +35,8 @@ std::unique_ptr<ErrorData> ErrorData::Create(InternalErrorType type,
ErrorData::ErrorData(InternalErrorType type, std::string message)
: mType(type), mMessage(std::move(message)) {}
ErrorData::~ErrorData() = default;
void ErrorData::AppendBacktrace(const char* file, const char* function, int line) {
BacktraceRecord record;
record.file = file;

View File

@ -41,6 +41,7 @@ class [[nodiscard]] ErrorData {
const char* function,
int line);
ErrorData(InternalErrorType type, std::string message);
~ErrorData();
struct BacktraceRecord {
const char* file;

View File

@ -0,0 +1,23 @@
// Copyright 2022 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn/native/PassResourceUsage.h"
namespace dawn::native {
ComputePassResourceUsage::ComputePassResourceUsage() = default;
ComputePassResourceUsage::ComputePassResourceUsage(ComputePassResourceUsage&&) = default;
} // namespace dawn::native

View File

@ -58,8 +58,8 @@ struct ComputePassResourceUsage {
// Somehow without this defaulted constructor, MSVC or its STDlib have an issue where they
// use the copy constructor (that's deleted) when doing operations on a
// vector<ComputePassResourceUsage>
ComputePassResourceUsage(ComputePassResourceUsage&&) = default;
ComputePassResourceUsage() = default;
ComputePassResourceUsage(ComputePassResourceUsage&&);
ComputePassResourceUsage();
std::vector<SyncScopeResourceUsage> dispatchUsages;

View File

@ -26,6 +26,14 @@
namespace dawn::native {
SyncScopeUsageTracker::SyncScopeUsageTracker() = default;
SyncScopeUsageTracker::SyncScopeUsageTracker(SyncScopeUsageTracker&&) = default;
SyncScopeUsageTracker::~SyncScopeUsageTracker() = default;
SyncScopeUsageTracker& SyncScopeUsageTracker::operator=(SyncScopeUsageTracker&&) = default;
void SyncScopeUsageTracker::BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage) {
// std::map's operator[] will create the key and return 0 if the key didn't exist
// before.
@ -165,6 +173,10 @@ SyncScopeResourceUsage SyncScopeUsageTracker::AcquireSyncScopeUsage() {
return result;
}
ComputePassResourceUsageTracker::ComputePassResourceUsageTracker() = default;
ComputePassResourceUsageTracker::~ComputePassResourceUsageTracker() = default;
void ComputePassResourceUsageTracker::AddDispatch(SyncScopeResourceUsage scope) {
mUsage.dispatchUsages.push_back(std::move(scope));
}
@ -206,6 +218,16 @@ ComputePassResourceUsage ComputePassResourceUsageTracker::AcquireResourceUsage()
return std::move(mUsage);
}
RenderPassResourceUsageTracker::RenderPassResourceUsageTracker() = default;
RenderPassResourceUsageTracker::RenderPassResourceUsageTracker(RenderPassResourceUsageTracker&&) =
default;
RenderPassResourceUsageTracker::~RenderPassResourceUsageTracker() = default;
RenderPassResourceUsageTracker& RenderPassResourceUsageTracker::operator=(
RenderPassResourceUsageTracker&&) = default;
RenderPassResourceUsage RenderPassResourceUsageTracker::AcquireResourceUsage() {
RenderPassResourceUsage result;
*static_cast<SyncScopeResourceUsage*>(&result) = AcquireSyncScopeUsage();

View File

@ -36,6 +36,12 @@ using QueryAvailabilityMap = std::map<QuerySetBase*, std::vector<bool>>;
// Helper class to build SyncScopeResourceUsages
class SyncScopeUsageTracker {
public:
SyncScopeUsageTracker();
SyncScopeUsageTracker(SyncScopeUsageTracker&&);
~SyncScopeUsageTracker();
SyncScopeUsageTracker& operator=(SyncScopeUsageTracker&&);
void BufferUsedAs(BufferBase* buffer, wgpu::BufferUsage usage);
void TextureViewUsedAs(TextureViewBase* texture, wgpu::TextureUsage usage);
void AddRenderBundleTextureUsage(TextureBase* texture,
@ -56,6 +62,9 @@ class SyncScopeUsageTracker {
// Helper class to build ComputePassResourceUsages
class ComputePassResourceUsageTracker {
public:
ComputePassResourceUsageTracker();
~ComputePassResourceUsageTracker();
void AddDispatch(SyncScopeResourceUsage scope);
void AddReferencedBuffer(BufferBase* buffer);
void AddResourcesReferencedByBindGroup(BindGroupBase* group);
@ -69,6 +78,12 @@ class ComputePassResourceUsageTracker {
// Helper class to build RenderPassResourceUsages
class RenderPassResourceUsageTracker : public SyncScopeUsageTracker {
public:
RenderPassResourceUsageTracker();
RenderPassResourceUsageTracker(RenderPassResourceUsageTracker&&);
~RenderPassResourceUsageTracker();
RenderPassResourceUsageTracker& operator=(RenderPassResourceUsageTracker&&);
void TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex);
const QueryAvailabilityMap& GetQueryAvailabilityMap() const;

View File

@ -546,6 +546,8 @@ TextureBase::TextureBase(DeviceBase* device,
TrackInDevice();
}
TextureBase::~TextureBase() = default;
static Format kUnusedFormat;
TextureBase::TextureBase(DeviceBase* device, TextureState state)
@ -789,6 +791,8 @@ TextureViewBase::TextureViewBase(TextureBase* texture)
TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag), mFormat(kUnusedFormat) {}
TextureViewBase::~TextureViewBase() = default;
void TextureViewBase::DestroyImpl() {}
// static

View File

@ -46,7 +46,9 @@ class TextureBase : public ApiObjectBase {
public:
enum class TextureState { OwnedInternal, OwnedExternal, Destroyed };
enum class ClearValue { Zero, NonZero };
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state);
~TextureBase() override;
static TextureBase* MakeError(DeviceBase* device);
@ -124,6 +126,7 @@ class TextureBase : public ApiObjectBase {
class TextureViewBase : public ApiObjectBase {
public:
TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor);
~TextureViewBase() override;
static TextureViewBase* MakeError(DeviceBase* device);

View File

@ -118,6 +118,8 @@ ComboRenderPassDescriptor::ComboRenderPassDescriptor(
}
}
ComboRenderPassDescriptor::~ComboRenderPassDescriptor() = default;
ComboRenderPassDescriptor::ComboRenderPassDescriptor(const ComboRenderPassDescriptor& other) {
*this = other;
}
@ -349,6 +351,11 @@ BindingInitializationHelper::BindingInitializationHelper(uint32_t binding,
uint64_t size)
: binding(binding), buffer(buffer), offset(offset), size(size) {}
BindingInitializationHelper::BindingInitializationHelper(const BindingInitializationHelper&) =
default;
BindingInitializationHelper::~BindingInitializationHelper() = default;
wgpu::BindGroupEntry BindingInitializationHelper::GetAsBinding() const {
wgpu::BindGroupEntry result;

View File

@ -59,6 +59,7 @@ struct ComboRenderPassDescriptor : public wgpu::RenderPassDescriptor {
public:
ComboRenderPassDescriptor(std::initializer_list<wgpu::TextureView> colorAttachmentInfo,
wgpu::TextureView depthStencil = wgpu::TextureView());
~ComboRenderPassDescriptor();
ComboRenderPassDescriptor(const ComboRenderPassDescriptor& otherRenderPass);
const ComboRenderPassDescriptor& operator=(const ComboRenderPassDescriptor& otherRenderPass);
@ -158,6 +159,8 @@ struct BindingInitializationHelper {
const wgpu::Buffer& buffer,
uint64_t offset = 0,
uint64_t size = wgpu::kWholeSize);
BindingInitializationHelper(const BindingInitializationHelper&);
~BindingInitializationHelper();
wgpu::BindGroupEntry GetAsBinding() const;

View File

@ -89,6 +89,8 @@ dawn_component("wire") {
"client/LimitsAndFeatures.cpp",
"client/LimitsAndFeatures.h",
"client/ObjectAllocator.h",
"client/ObjectBase.cpp",
"client/ObjectBase.h",
"client/Queue.cpp",
"client/Queue.h",
"client/RequestTracker.h",

View File

@ -62,6 +62,8 @@ target_sources(dawn_wire PRIVATE
"client/LimitsAndFeatures.cpp"
"client/LimitsAndFeatures.h"
"client/ObjectAllocator.h"
"client/ObjectBase.cpp"
"client/ObjectBase.h"
"client/Queue.cpp"
"client/Queue.h"
"client/RequestTracker.h"

View File

@ -19,6 +19,8 @@
namespace dawn::wire::client {
Adapter::Adapter(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Adapter::~Adapter() {
mRequestDeviceRequests.CloseAll([](RequestDeviceData* request) {
request->callback(WGPURequestDeviceStatus_Unknown, nullptr,

View File

@ -29,7 +29,9 @@ class Adapter final : public ObjectBase {
public:
using ObjectBase::ObjectBase;
Adapter(Client* client, uint32_t refcount, uint32_t id);
~Adapter();
void CancelCallbacksForDisconnect() override;
bool GetLimits(WGPUSupportedLimits* limits) const;

View File

@ -137,6 +137,8 @@ WGPUBuffer Buffer::CreateError(Device* device) {
return ToAPI(allocation->object.get());
}
Buffer::Buffer(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Buffer::~Buffer() {
ClearAllCallbacks(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback);
FreeMappedData();

View File

@ -33,6 +33,7 @@ class Buffer final : public ObjectBase {
static WGPUBuffer Create(Device* device, const WGPUBufferDescriptor* descriptor);
static WGPUBuffer CreateError(Device* device);
Buffer(Client* client, uint32_t refcount, uint32_t id);
~Buffer();
bool OnMapAsyncCallback(uint64_t requestSerial,

View File

@ -18,6 +18,8 @@
namespace dawn::wire::client {
Instance::Instance(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Instance::~Instance() {
mRequestAdapterRequests.CloseAll([](RequestAdapterData* request) {
request->callback(WGPURequestAdapterStatus_Unknown, nullptr,

View File

@ -28,7 +28,9 @@ class Instance final : public ObjectBase {
public:
using ObjectBase::ObjectBase;
Instance(Client* client, uint32_t refcount, uint32_t id);
~Instance();
void CancelCallbacksForDisconnect() override;
void RequestAdapter(const WGPURequestAdapterOptions* options,

View File

@ -19,6 +19,10 @@
namespace dawn::wire::client {
LimitsAndFeatures::LimitsAndFeatures() = default;
LimitsAndFeatures::~LimitsAndFeatures() = default;
bool LimitsAndFeatures::GetLimits(WGPUSupportedLimits* limits) const {
ASSERT(limits != nullptr);
if (limits->nextInChain != nullptr) {

View File

@ -23,6 +23,9 @@ namespace dawn::wire::client {
class LimitsAndFeatures {
public:
LimitsAndFeatures();
~LimitsAndFeatures();
bool GetLimits(WGPUSupportedLimits* limits) const;
bool HasFeature(WGPUFeatureName feature) const;
size_t EnumerateFeatures(WGPUFeatureName* features) const;

View File

@ -0,0 +1,26 @@
// Copyright 2022 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn/wire/client/ObjectBase.h"
namespace dawn::wire::client {
ObjectBase::ObjectBase(Client* client, uint32_t refcount, uint32_t id)
: client(client), refcount(refcount), id(id) {}
ObjectBase::~ObjectBase() {
RemoveFromList();
}
} // namespace dawn::wire::client

View File

@ -30,10 +30,8 @@ class Client;
// - An ID that is used to refer to this object when talking with the server side
// - A next/prev pointer. They are part of a linked list of objects of the same type.
struct ObjectBase : public LinkNode<ObjectBase> {
ObjectBase(Client* client, uint32_t refcount, uint32_t id)
: client(client), refcount(refcount), id(id) {}
~ObjectBase() { RemoveFromList(); }
ObjectBase(Client* client, uint32_t refcount, uint32_t id);
~ObjectBase();
virtual void CancelCallbacksForDisconnect() {}

View File

@ -19,6 +19,8 @@
namespace dawn::wire::client {
Queue::Queue(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Queue::~Queue() {
ClearAllCallbacks(WGPUQueueWorkDoneStatus_Unknown);
}

View File

@ -26,6 +26,8 @@ namespace dawn::wire::client {
class Queue final : public ObjectBase {
public:
using ObjectBase::ObjectBase;
Queue(Client* client, uint32_t refcount, uint32_t id);
~Queue();
bool OnWorkDoneCallback(uint64_t requestSerial, WGPUQueueWorkDoneStatus status);

View File

@ -18,6 +18,8 @@
namespace dawn::wire::client {
ShaderModule::ShaderModule(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
ShaderModule::~ShaderModule() {
ClearAllCallbacks(WGPUCompilationInfoRequestStatus_Unknown);
}

View File

@ -25,6 +25,8 @@ namespace dawn::wire::client {
class ShaderModule final : public ObjectBase {
public:
using ObjectBase::ObjectBase;
ShaderModule(Client* client, uint32_t refcount, uint32_t id);
~ShaderModule();
void GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata);