Refactors native mock classes to be more like the Null device.

- Plumbs all descriptors through so that the objects act much more like
  a real implementation.
- Lots of changes to DestroyObjectTests.cpp to update usages and test
  through the APIs when applicable.
- Put in defaults for the mock device and make it as easy to use as
  possible.

Change-Id: I85b243a18ec1872aff0172549aec0f599967ea0e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119821
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung
2023-02-22 20:38:37 +00:00
committed by Dawn LUCI CQ
parent 54a104e28f
commit f35f1ff98c
62 changed files with 1505 additions and 902 deletions

View File

@@ -456,10 +456,6 @@ BindGroupBase::BindGroupBase(DeviceBase* device,
GetObjectTrackingList()->Track(this);
}
BindGroupBase::BindGroupBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
BindGroupBase::~BindGroupBase() = default;
void BindGroupBase::DestroyImpl() {

View File

@@ -76,8 +76,6 @@ class BindGroupBase : public ApiObjectBase {
static_assert(std::is_base_of<BindGroupBase, Derived>::value);
}
// Constructor used only for mocking and testing.
explicit BindGroupBase(DeviceBase* device);
void DestroyImpl() override;
~BindGroupBase() override;

View File

@@ -493,11 +493,6 @@ BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag) {}
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device)
: ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
BindGroupLayoutBase::~BindGroupLayoutBase() = default;
void BindGroupLayoutBase::DestroyImpl() {

View File

@@ -135,8 +135,6 @@ class BindGroupLayoutBase : public ApiObjectBase, public CachedObject {
std::string EntriesToString() const;
protected:
// Constructor used only for mocking and testing.
explicit BindGroupLayoutBase(DeviceBase* device);
void DestroyImpl() override;
template <typename BindGroup>

View File

@@ -222,11 +222,6 @@ BufferBase::BufferBase(DeviceBase* device,
}
}
BufferBase::BufferBase(DeviceBase* device, BufferState state)
: ApiObjectBase(device, kLabelNotImplemented), mState(state) {
GetObjectTrackingList()->Track(this);
}
BufferBase::~BufferBase() {
ASSERT(mState == BufferState::Unmapped || mState == BufferState::Destroyed);
}

View File

@@ -96,8 +96,6 @@ class BufferBase : public ApiObjectBase {
protected:
BufferBase(DeviceBase* device, const BufferDescriptor* descriptor);
BufferBase(DeviceBase* device, const BufferDescriptor* descriptor, ObjectBase::ErrorTag tag);
// Constructor used only for mocking and testing.
BufferBase(DeviceBase* device, BufferState state);
void DestroyImpl() override;

View File

@@ -37,7 +37,7 @@ size_t CachedObject::GetContentHash() const {
}
void CachedObject::SetContentHash(size_t contentHash) {
ASSERT(!mIsContentHashInitialized);
ASSERT(!mIsContentHashInitialized || contentHash == mContentHash);
mContentHash = contentHash;
mIsContentHashInitialized = true;
}

View File

@@ -33,11 +33,6 @@ CommandBufferBase::CommandBufferBase(CommandEncoder* encoder,
GetObjectTrackingList()->Track(this);
}
CommandBufferBase::CommandBufferBase(DeviceBase* device)
: ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
CommandBufferBase::CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag) {}

View File

@@ -45,8 +45,6 @@ class CommandBufferBase : public ApiObjectBase {
CommandIterator* GetCommandIteratorForTesting();
protected:
// Constructor used only for mocking and testing.
explicit CommandBufferBase(DeviceBase* device);
void DestroyImpl() override;
CommandIterator mCommands;

View File

@@ -56,10 +56,6 @@ ComputePipelineBase::ComputePipelineBase(DeviceBase* device,
StreamIn(&mCacheKey, CacheKey::Type::ComputePipeline, device->GetCacheKey());
}
ComputePipelineBase::ComputePipelineBase(DeviceBase* device) : PipelineBase(device) {
GetObjectTrackingList()->Track(this);
}
ComputePipelineBase::ComputePipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: PipelineBase(device, tag) {}

View File

@@ -42,8 +42,6 @@ class ComputePipelineBase : public PipelineBase {
};
protected:
// Constructor used only for mocking and testing.
explicit ComputePipelineBase(DeviceBase* device);
void DestroyImpl() override;
private:

View File

@@ -125,6 +125,7 @@ struct LoggingCallbackTask : CallbackTask {
std::string mMessage;
void* mUserdata;
};
} // anonymous namespace
ResultOrError<Ref<PipelineLayoutBase>> ValidateLayoutAndGetComputePipelineDescriptorWithDefaults(
DeviceBase* device,
@@ -167,8 +168,6 @@ ResultOrError<Ref<PipelineLayoutBase>> ValidateLayoutAndGetRenderPipelineDescrip
return layoutRef;
}
} // anonymous namespace
// DeviceBase
DeviceBase::DeviceBase(AdapterBase* adapter,
@@ -210,7 +209,7 @@ DeviceBase::DeviceBase(AdapterBase* adapter,
}
DeviceBase::DeviceBase() : mState(State::Alive), mToggles(ToggleStage::Device) {
mCaches = std::make_unique<DeviceBase::Caches>();
mFormatTable = BuildFormatTable(this);
}
DeviceBase::~DeviceBase() {

View File

@@ -139,7 +139,7 @@ class DeviceBase : public RefCountedWithExternalCount {
MaybeError ValidateObject(const ApiObjectBase* object) const;
AdapterBase* GetAdapter() const;
dawn::platform::Platform* GetPlatform() const;
virtual dawn::platform::Platform* GetPlatform() const;
// Returns the Format corresponding to the wgpu::TextureFormat or an error if the format
// isn't a valid wgpu::TextureFormat or isn't supported by this device.
@@ -582,6 +582,16 @@ class DeviceBase : public RefCountedWithExternalCount {
CacheKey mDeviceCacheKey;
};
ResultOrError<Ref<PipelineLayoutBase>> ValidateLayoutAndGetComputePipelineDescriptorWithDefaults(
DeviceBase* device,
const ComputePipelineDescriptor& descriptor,
ComputePipelineDescriptor* outDescriptor);
ResultOrError<Ref<PipelineLayoutBase>> ValidateLayoutAndGetRenderPipelineDescriptorWithDefaults(
DeviceBase* device,
const RenderPipelineDescriptor& descriptor,
RenderPipelineDescriptor* outDescriptor);
class IgnoreLazyClearCountScope : public NonMovable {
public:
explicit IgnoreLazyClearCountScope(DeviceBase* device);

View File

@@ -137,11 +137,6 @@ ExternalTextureBase::ExternalTextureBase(DeviceBase* device,
GetObjectTrackingList()->Track(this);
}
ExternalTextureBase::ExternalTextureBase(DeviceBase* device)
: ApiObjectBase(device, kLabelNotImplemented), mState(ExternalTextureState::Alive) {
GetObjectTrackingList()->Track(this);
}
// Error external texture cannot be used in bind group.
ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag), mState(ExternalTextureState::Destroyed) {}

View File

@@ -60,18 +60,16 @@ class ExternalTextureBase : public ApiObjectBase {
void APIDestroy();
protected:
// Constructor used only for mocking and testing.
explicit ExternalTextureBase(DeviceBase* device);
ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor);
void DestroyImpl() override;
MaybeError Initialize(DeviceBase* device, const ExternalTextureDescriptor* descriptor);
~ExternalTextureBase() override;
private:
ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor);
enum class ExternalTextureState { Alive, Destroyed };
ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag);
MaybeError Initialize(DeviceBase* device, const ExternalTextureDescriptor* descriptor);
Ref<TextureBase> mPlaceholderTexture;
Ref<BufferBase> mParamsBuffer;

View File

@@ -197,8 +197,6 @@ PipelineBase::PipelineBase(DeviceBase* device,
}
}
PipelineBase::PipelineBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {}
PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag) {}

View File

@@ -83,9 +83,6 @@ class PipelineBase : public ApiObjectBase, public CachedObject {
std::vector<StageAndDescriptor> stages);
PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag);
// Constructor used only for mocking and testing.
explicit PipelineBase(DeviceBase* device);
private:
MaybeError ValidateGetBindGroupLayout(BindGroupIndex group);

View File

@@ -74,11 +74,6 @@ PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
GetObjectTrackingList()->Track(this);
}
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device)
: ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag) {}

View File

@@ -84,8 +84,6 @@ class PipelineLayoutBase : public ApiObjectBase, public CachedObject {
};
protected:
// Constructor used only for mocking and testing.
explicit PipelineLayoutBase(DeviceBase* device);
PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag);
void DestroyImpl() override;

View File

@@ -111,10 +111,6 @@ QuerySetBase::QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descrip
GetObjectTrackingList()->Track(this);
}
QuerySetBase::QuerySetBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
QuerySetBase::QuerySetBase(DeviceBase* device,
const QuerySetDescriptor* descriptor,
ObjectBase::ErrorTag tag)

View File

@@ -52,8 +52,6 @@ class QuerySetBase : public ApiObjectBase {
const QuerySetDescriptor* descriptor,
ObjectBase::ErrorTag tag);
// Constructor used only for mocking and testing.
explicit QuerySetBase(DeviceBase* device);
void DestroyImpl() override;
~QuerySetBase() override;

View File

@@ -672,10 +672,6 @@ RenderPipelineBase::RenderPipelineBase(DeviceBase* device,
StreamIn(&mCacheKey, CacheKey::Type::RenderPipeline, device->GetCacheKey());
}
RenderPipelineBase::RenderPipelineBase(DeviceBase* device) : PipelineBase(device) {
GetObjectTrackingList()->Track(this);
}
RenderPipelineBase::RenderPipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: PipelineBase(device, tag) {}

View File

@@ -113,8 +113,6 @@ class RenderPipelineBase : public PipelineBase {
};
protected:
// Constructor used only for mocking and testing.
explicit RenderPipelineBase(DeviceBase* device);
void DestroyImpl() override;
private:

View File

@@ -89,10 +89,6 @@ SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor
GetObjectTrackingList()->Track(this);
}
SamplerBase::SamplerBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag) {}

View File

@@ -53,8 +53,6 @@ class SamplerBase : public ApiObjectBase, public CachedObject {
uint16_t GetMaxAnisotropy() const { return mMaxAnisotropy; }
protected:
// Constructor used only for mocking and testing.
explicit SamplerBase(DeviceBase* device);
void DestroyImpl() override;
private:

View File

@@ -1111,11 +1111,6 @@ ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescrip
GetObjectTrackingList()->Track(this);
}
ShaderModuleBase::ShaderModuleBase(DeviceBase* device)
: ApiObjectBase(device, kLabelNotImplemented) {
GetObjectTrackingList()->Track(this);
}
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag), mType(Type::Undefined) {}

View File

@@ -286,8 +286,6 @@ class ShaderModuleBase : public ApiObjectBase, public CachedObject {
OwnedCompilationMessages* GetCompilationMessages() const;
protected:
// Constructor used only for mocking and testing.
explicit ShaderModuleBase(DeviceBase* device);
void DestroyImpl() override;
MaybeError InitializeBase(ShaderModuleParseResult* parseResult,

View File

@@ -581,11 +581,6 @@ TextureBase::~TextureBase() = default;
static constexpr Format kUnusedFormat;
TextureBase::TextureBase(DeviceBase* device, TextureState state)
: ApiObjectBase(device, kLabelNotImplemented), mFormat(kUnusedFormat), mState(state) {
GetObjectTrackingList()->Track(this);
}
TextureBase::TextureBase(DeviceBase* device,
const TextureDescriptor* descriptor,
ObjectBase::ErrorTag tag)
@@ -854,13 +849,6 @@ TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescript
GetObjectTrackingList()->Track(this);
}
TextureViewBase::TextureViewBase(TextureBase* texture)
: ApiObjectBase(texture->GetDevice(), kLabelNotImplemented),
mTexture(texture),
mFormat(kUnusedFormat) {
GetObjectTrackingList()->Track(this);
}
TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ApiObjectBase(device, tag), mFormat(kUnusedFormat) {}

View File

@@ -108,8 +108,6 @@ class TextureBase : public ApiObjectBase {
protected:
TextureBase(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state);
// Constructor used only for mocking and testing.
TextureBase(DeviceBase* device, TextureState state);
~TextureBase() override;
void DestroyImpl() override;
@@ -159,8 +157,6 @@ class TextureViewBase : public ApiObjectBase {
const SubresourceRange& GetSubresourceRange() const;
protected:
// Constructor used only for mocking and testing.
explicit TextureViewBase(TextureBase* texture);
void DestroyImpl() override;
private: