diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index 3290a07787..c0456af4bd 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -845,6 +845,14 @@ class MultiGeneratorFromDawnJSON(Generator): FileRender('dawn_native/webgpu_absl_format.cpp', 'src/dawn_native/webgpu_absl_format_autogen.cpp', frontend_params)) + renders.append( + FileRender('dawn_native/ObjectType.h', + 'src/dawn_native/ObjectType_autogen.h', + frontend_params)) + renders.append( + FileRender('dawn_native/ObjectType.cpp', + 'src/dawn_native/ObjectType_autogen.cpp', + frontend_params)) if 'dawn_wire' in targets: additional_params = compute_wire_params(params_dawn, wire_json) diff --git a/generator/templates/dawn_native/ObjectType.cpp b/generator/templates/dawn_native/ObjectType.cpp new file mode 100644 index 0000000000..df3e0fce8a --- /dev/null +++ b/generator/templates/dawn_native/ObjectType.cpp @@ -0,0 +1,30 @@ +//* Copyright 2020 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/ObjectType_autogen.h" + +namespace dawn_native { + + const char* ObjectTypeAsString(ObjectType type) { + switch (type) { + {% for type in by_category["object"] %} + case ObjectType::{{type.name.CamelCase()}}: + return "{{type.name.CamelCase()}}"; + {% endfor %} + default: + UNREACHABLE(); + } + } + +} // namespace dawn_native diff --git a/generator/templates/dawn_native/ObjectType.h b/generator/templates/dawn_native/ObjectType.h new file mode 100644 index 0000000000..c9c8feacd8 --- /dev/null +++ b/generator/templates/dawn_native/ObjectType.h @@ -0,0 +1,36 @@ +//* Copyright 2020 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. + +#ifndef DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_ +#define DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_ + +#include "common/ityp_array.h" + +namespace dawn_native { + + enum class ObjectType : uint32_t { + {% for type in by_category["object"] %} + {{type.name.CamelCase()}}, + {% endfor %} + }; + + template + using PerObjectType = ityp::array; + + const char* ObjectTypeAsString(ObjectType type); + +} // namespace dawn_native + + +#endif // DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_ diff --git a/generator/templates/dawn_native/webgpu_absl_format.cpp b/generator/templates/dawn_native/webgpu_absl_format.cpp index 0ba124d0b9..db748f3dac 100644 --- a/generator/templates/dawn_native/webgpu_absl_format.cpp +++ b/generator/templates/dawn_native/webgpu_absl_format.cpp @@ -14,13 +14,10 @@ #include "dawn_native/webgpu_absl_format_autogen.h" -{% set skip_types = ["texture view", "instance", "surface"] %} - -{% for type in by_category["object"] %} - {% if type.name.canonical_case() not in skip_types %} - #include "dawn_native/{{type.name.CamelCase()}}.h" - {% endif %} -{% endfor %} +#include "dawn_native/Device.h" +#include "dawn_native/ObjectBase.h" +#include "dawn_native/ObjectType_autogen.h" +#include "dawn_native/Texture.h" namespace dawn_native { @@ -28,12 +25,11 @@ namespace dawn_native { // Objects // - // TODO(dawn:563) Detect the type of ObjectBase references and use the right formatter. absl::FormatConvertResult - AbslFormatConvert(const ObjectBase* value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s) { - s->Append("[Object"); + AbslFormatConvert(const DeviceBase* value, + const absl::FormatConversionSpec& spec, + absl::FormatSink* s) { + s->Append("[Device"); const std::string& label = value->GetLabel(); if (!label.empty()) { s->Append(absl::StrFormat(" \"%s\"", label)); @@ -42,30 +38,26 @@ namespace dawn_native { return {true}; } - {% for type in by_category["object"] %} - {% if type.name.canonical_case() not in skip_types %} - absl::FormatConvertResult - AbslFormatConvert(const {{as_frontendType(type)}} value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s) { - s->Append("[{{as_cppType(type.name)}}"); - const std::string& label = value->GetLabel(); - if (!label.empty()) { - s->Append(absl::StrFormat(" \"%s\"", label)); - } - s->Append("]"); - return {true}; - } - {% endif %} - {% endfor %} + absl::FormatConvertResult + AbslFormatConvert(const ApiObjectBase* value, + const absl::FormatConversionSpec& spec, + absl::FormatSink* s) { + s->Append("["); + s->Append(ObjectTypeAsString(value->GetType())); + const std::string& label = value->GetLabel(); + if (!label.empty()) { + s->Append(absl::StrFormat(" \"%s\"", label)); + } + s->Append("]"); + return {true}; + } - // Special case for textureViews, since frequently the texture will be the - // thing that's labeled. absl::FormatConvertResult AbslFormatConvert(const TextureViewBase* value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s) { - s->Append("[TextureView"); + const absl::FormatConversionSpec& spec, + absl::FormatSink* s) { + s->Append("["); + s->Append(ObjectTypeAsString(value->GetType())); const std::string& label = value->GetLabel(); if (!label.empty()) { s->Append(absl::StrFormat(" \"%s\"", label)); diff --git a/generator/templates/dawn_native/webgpu_absl_format.h b/generator/templates/dawn_native/webgpu_absl_format.h index 2ff9b83843..4cf85c64a3 100644 --- a/generator/templates/dawn_native/webgpu_absl_format.h +++ b/generator/templates/dawn_native/webgpu_absl_format.h @@ -21,29 +21,29 @@ namespace dawn_native { - {% set skip_types = ["instance", "surface"] %} - {% set pure_frontend_types = ["command encoder", "compute pass encoder", "render pass encoder", "render bundle encoder"] %} - // // Objects // - class ObjectBase; + class DeviceBase; absl::FormatConvertResult - AbslFormatConvert(const ObjectBase* value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s); + AbslFormatConvert(const DeviceBase* value, + const absl::FormatConversionSpec& spec, + absl::FormatSink* s); - {% for type in by_category["object"] %} - {% set Base = "" if type.name.canonical_case() in pure_frontend_types else "Base" %} - {% if type.name.canonical_case() not in skip_types %} - class {{type.name.CamelCase()}}{{Base}}; - absl::FormatConvertResult - AbslFormatConvert(const {{type.name.CamelCase()}}{{Base}}* value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s); - {% endif %} - {% endfor %} + class ApiObjectBase; + absl::FormatConvertResult + AbslFormatConvert(const ApiObjectBase* value, + const absl::FormatConversionSpec& spec, + absl::FormatSink* s); + + // Special case for TextureViews, since frequently the texture will be the + // thing that's labeled. + class TextureViewBase; + absl::FormatConvertResult + AbslFormatConvert(const TextureViewBase* value, + const absl::FormatConversionSpec& spec, + absl::FormatSink* s); // // Descriptors @@ -55,8 +55,8 @@ namespace dawn_native { {% if member.name.canonical_case() == "label" %} absl::FormatConvertResult AbslFormatConvert(const {{as_cppType(type.name)}}* value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s); + const absl::FormatConversionSpec& spec, + absl::FormatSink* s); {% endif %} {% endfor %} {% endfor %} @@ -71,8 +71,8 @@ namespace wgpu { {% for type in by_category["enum"] %} absl::FormatConvertResult AbslFormatConvert({{as_cppType(type.name)}} value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s); + const absl::FormatConversionSpec& spec, + absl::FormatSink* s); {% endfor %} // @@ -82,8 +82,8 @@ namespace wgpu { {% for type in by_category["bitmask"] %} absl::FormatConvertResult AbslFormatConvert({{as_cppType(type.name)}} value, - const absl::FormatConversionSpec& spec, - absl::FormatSink* s); + const absl::FormatConversionSpec& spec, + absl::FormatSink* s); {% endfor %} } // namespace dawn_native diff --git a/src/dawn_native/AttachmentState.cpp b/src/dawn_native/AttachmentState.cpp index c643859b63..427db42bb9 100644 --- a/src/dawn_native/AttachmentState.cpp +++ b/src/dawn_native/AttachmentState.cpp @@ -126,7 +126,7 @@ namespace dawn_native { } AttachmentState::AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint) - : AttachmentStateBlueprint(blueprint), CachedObject(device, kLabelNotImplemented) { + : AttachmentStateBlueprint(blueprint), ObjectBase(device) { } AttachmentState::~AttachmentState() { diff --git a/src/dawn_native/AttachmentState.h b/src/dawn_native/AttachmentState.h index ce8b8aaf14..6c1e434971 100644 --- a/src/dawn_native/AttachmentState.h +++ b/src/dawn_native/AttachmentState.h @@ -20,6 +20,7 @@ #include "common/ityp_bitset.h" #include "dawn_native/CachedObject.h" #include "dawn_native/IntegerTypes.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -59,7 +60,9 @@ namespace dawn_native { uint32_t mSampleCount = 0; }; - class AttachmentState final : public AttachmentStateBlueprint, public CachedObject { + class AttachmentState final : public AttachmentStateBlueprint, + public ObjectBase, + public CachedObject { public: AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint); diff --git a/src/dawn_native/BUILD.gn b/src/dawn_native/BUILD.gn index 0242cddc28..bcbcbd8161 100644 --- a/src/dawn_native/BUILD.gn +++ b/src/dawn_native/BUILD.gn @@ -111,6 +111,8 @@ dawn_json_generator("dawn_native_utils_gen") { "src/dawn_native/ValidationUtils_autogen.cpp", "src/dawn_native/webgpu_absl_format_autogen.h", "src/dawn_native/webgpu_absl_format_autogen.cpp", + "src/dawn_native/ObjectType_autogen.h", + "src/dawn_native/ObjectType_autogen.cpp", ] } diff --git a/src/dawn_native/BindGroup.cpp b/src/dawn_native/BindGroup.cpp index 1b417295ec..0a8beaf1c2 100644 --- a/src/dawn_native/BindGroup.cpp +++ b/src/dawn_native/BindGroup.cpp @@ -22,6 +22,8 @@ #include "dawn_native/ChainUtils_autogen.h" #include "dawn_native/Device.h" #include "dawn_native/ExternalTexture.h" +#include "dawn_native/ObjectBase.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/Sampler.h" #include "dawn_native/Texture.h" @@ -317,7 +319,7 @@ namespace dawn_native { BindGroupBase::BindGroupBase(DeviceBase* device, const BindGroupDescriptor* descriptor, void* bindingDataStart) - : ObjectBase(device, kLabelNotImplemented), + : ApiObjectBase(device, kLabelNotImplemented), mLayout(descriptor->layout), mBindingData(mLayout->ComputeBindingDataPointers(bindingDataStart)) { for (BindingIndex i{0}; i < mLayout->GetBindingCount(); ++i) { @@ -397,7 +399,7 @@ namespace dawn_native { } BindGroupBase::BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag), mBindingData() { + : ApiObjectBase(device, tag), mBindingData() { } // static @@ -405,6 +407,10 @@ namespace dawn_native { return new BindGroupBase(device, ObjectBase::kError); } + ObjectType BindGroupBase::GetType() const { + return ObjectType::BindGroup; + } + BindGroupLayoutBase* BindGroupBase::GetLayout() { ASSERT(!IsError()); return mLayout.Get(); diff --git a/src/dawn_native/BindGroup.h b/src/dawn_native/BindGroup.h index a636fe8f69..1ce4b9fe43 100644 --- a/src/dawn_native/BindGroup.h +++ b/src/dawn_native/BindGroup.h @@ -39,10 +39,12 @@ namespace dawn_native { uint64_t size; }; - class BindGroupBase : public ObjectBase { + class BindGroupBase : public ApiObjectBase { public: static BindGroupBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + BindGroupLayoutBase* GetLayout(); const BindGroupLayoutBase* GetLayout() const; BufferBinding GetBindingAsBufferBinding(BindingIndex bindingIndex); diff --git a/src/dawn_native/BindGroupLayout.cpp b/src/dawn_native/BindGroupLayout.cpp index 34c8482711..5c2ea42e11 100644 --- a/src/dawn_native/BindGroupLayout.cpp +++ b/src/dawn_native/BindGroupLayout.cpp @@ -18,7 +18,9 @@ #include "dawn_native/ChainUtils_autogen.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectContentHasher.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/PerStage.h" #include "dawn_native/ValidationUtils_autogen.h" @@ -359,7 +361,7 @@ namespace dawn_native { BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor, PipelineCompatibilityToken pipelineCompatibilityToken) - : CachedObject(device, kLabelNotImplemented), + : ApiObjectBase(device, kLabelNotImplemented), mBindingInfo(BindingIndex(descriptor->entryCount)), mPipelineCompatibilityToken(pipelineCompatibilityToken) { std::vector sortedBindings( @@ -386,7 +388,7 @@ namespace dawn_native { } BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : CachedObject(device, tag) { + : ApiObjectBase(device, tag) { } BindGroupLayoutBase::~BindGroupLayoutBase() { @@ -401,6 +403,10 @@ namespace dawn_native { return new BindGroupLayoutBase(device, ObjectBase::kError); } + ObjectType BindGroupLayoutBase::GetType() const { + return ObjectType::BindGroupLayout; + } + const BindGroupLayoutBase::BindingMap& BindGroupLayoutBase::GetBindingMap() const { ASSERT(!IsError()); return mBindingMap; diff --git a/src/dawn_native/BindGroupLayout.h b/src/dawn_native/BindGroupLayout.h index 728e641fb0..5f75eb62ea 100644 --- a/src/dawn_native/BindGroupLayout.h +++ b/src/dawn_native/BindGroupLayout.h @@ -24,6 +24,7 @@ #include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" #include "dawn_native/Forward.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -39,7 +40,7 @@ namespace dawn_native { // Bindings are specified as a |BindingNumber| in the BindGroupLayoutDescriptor. // These numbers may be arbitrary and sparse. Internally, Dawn packs these numbers // into a packed range of |BindingIndex| integers. - class BindGroupLayoutBase : public CachedObject { + class BindGroupLayoutBase : public ApiObjectBase, public CachedObject { public: BindGroupLayoutBase(DeviceBase* device, const BindGroupLayoutDescriptor* descriptor, @@ -48,6 +49,8 @@ namespace dawn_native { static BindGroupLayoutBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + // A map from the BindingNumber to its packed BindingIndex. using BindingMap = std::map; diff --git a/src/dawn_native/Buffer.cpp b/src/dawn_native/Buffer.cpp index 8b90173ff4..5872c68454 100644 --- a/src/dawn_native/Buffer.cpp +++ b/src/dawn_native/Buffer.cpp @@ -20,6 +20,7 @@ #include "dawn_native/Device.h" #include "dawn_native/DynamicUploader.h" #include "dawn_native/ErrorData.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/Queue.h" #include "dawn_native/ValidationUtils_autogen.h" @@ -128,7 +129,7 @@ namespace dawn_native { // Buffer BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor) - : ObjectBase(device, descriptor->label), + : ApiObjectBase(device, descriptor->label), mSize(descriptor->size), mUsage(descriptor->usage), mState(BufferState::Unmapped) { @@ -158,7 +159,7 @@ namespace dawn_native { BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag), mSize(descriptor->size), mState(BufferState::Unmapped) { + : ApiObjectBase(device, tag), mSize(descriptor->size), mState(BufferState::Unmapped) { if (descriptor->mappedAtCreation) { mState = BufferState::MappedAtCreation; mMapOffset = 0; @@ -178,6 +179,10 @@ namespace dawn_native { return new ErrorBuffer(device, descriptor); } + ObjectType BufferBase::GetType() const { + return ObjectType::Buffer; + } + uint64_t BufferBase::GetSize() const { ASSERT(!IsError()); return mSize; diff --git a/src/dawn_native/Buffer.h b/src/dawn_native/Buffer.h index 543ba7129e..4192e2dfac 100644 --- a/src/dawn_native/Buffer.h +++ b/src/dawn_native/Buffer.h @@ -40,7 +40,7 @@ namespace dawn_native { static constexpr wgpu::BufferUsage kMappableBufferUsages = wgpu::BufferUsage::MapRead | wgpu::BufferUsage::MapWrite; - class BufferBase : public ObjectBase { + class BufferBase : public ApiObjectBase { enum class BufferState { Unmapped, Mapped, @@ -53,6 +53,8 @@ namespace dawn_native { static BufferBase* MakeError(DeviceBase* device, const BufferDescriptor* descriptor); + ObjectType GetType() const override; + uint64_t GetSize() const; uint64_t GetAllocatedSize() const; wgpu::BufferUsage GetUsage() const; diff --git a/src/dawn_native/CachedObject.h b/src/dawn_native/CachedObject.h index abf4525386..ff84e1e0d0 100644 --- a/src/dawn_native/CachedObject.h +++ b/src/dawn_native/CachedObject.h @@ -15,8 +15,6 @@ #ifndef DAWNNATIVE_CACHED_OBJECT_H_ #define DAWNNATIVE_CACHED_OBJECT_H_ -#include "dawn_native/ObjectBase.h" - #include namespace dawn_native { @@ -25,10 +23,8 @@ namespace dawn_native { // we increase the refcount of an existing object. // When an object is successfully created, the device should call // SetIsCachedReference() and insert the object into the cache. - class CachedObject : public ObjectBase { + class CachedObject { public: - using ObjectBase::ObjectBase; - bool IsCachedReference() const; // Functor necessary for the unordered_set-based cache. diff --git a/src/dawn_native/CommandBuffer.cpp b/src/dawn_native/CommandBuffer.cpp index 1300cd1afc..5b07bb64a0 100644 --- a/src/dawn_native/CommandBuffer.cpp +++ b/src/dawn_native/CommandBuffer.cpp @@ -20,18 +20,19 @@ #include "dawn_native/CommandValidation.h" #include "dawn_native/Commands.h" #include "dawn_native/Format.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/Texture.h" namespace dawn_native { CommandBufferBase::CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor*) - : ObjectBase(encoder->GetDevice(), kLabelNotImplemented), + : ApiObjectBase(encoder->GetDevice(), kLabelNotImplemented), mCommands(encoder->AcquireCommands()), mResourceUsages(encoder->AcquireResourceUsages()) { } CommandBufferBase::CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : ApiObjectBase(device, tag) { } CommandBufferBase::~CommandBufferBase() { @@ -51,6 +52,10 @@ namespace dawn_native { return new CommandBufferBase(device, ObjectBase::kError); } + ObjectType CommandBufferBase::GetType() const { + return ObjectType::CommandBuffer; + } + MaybeError CommandBufferBase::ValidateCanUseInSubmitNow() const { ASSERT(!IsError()); diff --git a/src/dawn_native/CommandBuffer.h b/src/dawn_native/CommandBuffer.h index 94159a10e9..2800929d36 100644 --- a/src/dawn_native/CommandBuffer.h +++ b/src/dawn_native/CommandBuffer.h @@ -30,19 +30,21 @@ namespace dawn_native { struct CopyTextureToBufferCmd; struct TextureCopy; - class CommandBufferBase : public ObjectBase { + class CommandBufferBase : public ApiObjectBase { public: CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); static CommandBufferBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + MaybeError ValidateCanUseInSubmitNow() const; void Destroy(); const CommandBufferResourceUsage& GetResourceUsages() const; protected: - ~CommandBufferBase(); + ~CommandBufferBase() override; void DoNextSetValidatedBufferLocationsInternal(); diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 143ba7e744..a1da4c6e3e 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -25,6 +25,7 @@ #include "dawn_native/ComputePassEncoder.h" #include "dawn_native/Device.h" #include "dawn_native/ErrorData.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/QueryHelper.h" #include "dawn_native/QuerySet.h" #include "dawn_native/Queue.h" @@ -447,7 +448,11 @@ namespace dawn_native { } // namespace CommandEncoder::CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor*) - : ObjectBase(device, kLabelNotImplemented), mEncodingContext(device, this) { + : ApiObjectBase(device, kLabelNotImplemented), mEncodingContext(device, this) { + } + + ObjectType CommandEncoder::GetType() const { + return ObjectType::CommandEncoder; } CommandBufferResourceUsage CommandEncoder::AcquireResourceUsages() { diff --git a/src/dawn_native/CommandEncoder.h b/src/dawn_native/CommandEncoder.h index b4e883690c..f7597e09ea 100644 --- a/src/dawn_native/CommandEncoder.h +++ b/src/dawn_native/CommandEncoder.h @@ -26,10 +26,12 @@ namespace dawn_native { - class CommandEncoder final : public ObjectBase { + class CommandEncoder final : public ApiObjectBase { public: CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor* descriptor); + ObjectType GetType() const; + CommandIterator AcquireCommands(); CommandBufferResourceUsage AcquireResourceUsages(); diff --git a/src/dawn_native/ComputePassEncoder.cpp b/src/dawn_native/ComputePassEncoder.cpp index 834fa6c629..48c040849c 100644 --- a/src/dawn_native/ComputePassEncoder.cpp +++ b/src/dawn_native/ComputePassEncoder.cpp @@ -20,6 +20,7 @@ #include "dawn_native/Commands.h" #include "dawn_native/ComputePipeline.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/PassResourceUsageTracker.h" #include "dawn_native/QuerySet.h" @@ -57,6 +58,10 @@ namespace dawn_native { return new ComputePassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError); } + ObjectType ComputePassEncoder::GetType() const { + return ObjectType::ComputePassEncoder; + } + void ComputePassEncoder::APIEndPass() { if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { if (IsValidationEnabled()) { diff --git a/src/dawn_native/ComputePassEncoder.h b/src/dawn_native/ComputePassEncoder.h index d21078dbbb..57a975001b 100644 --- a/src/dawn_native/ComputePassEncoder.h +++ b/src/dawn_native/ComputePassEncoder.h @@ -17,6 +17,7 @@ #include "dawn_native/CommandBufferStateTracker.h" #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" #include "dawn_native/PassResourceUsageTracker.h" #include "dawn_native/ProgrammablePassEncoder.h" @@ -34,6 +35,8 @@ namespace dawn_native { CommandEncoder* commandEncoder, EncodingContext* encodingContext); + ObjectType GetType() const override; + void APIEndPass(); void APIDispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1); diff --git a/src/dawn_native/ComputePipeline.cpp b/src/dawn_native/ComputePipeline.cpp index 87b2792528..8360b5608a 100644 --- a/src/dawn_native/ComputePipeline.cpp +++ b/src/dawn_native/ComputePipeline.cpp @@ -16,6 +16,7 @@ #include "dawn_native/Device.h" #include "dawn_native/ObjectContentHasher.h" +#include "dawn_native/ObjectType_autogen.h" namespace dawn_native { @@ -65,6 +66,10 @@ namespace dawn_native { return new ComputePipelineBase(device, ObjectBase::kError); } + ObjectType ComputePipelineBase::GetType() const { + return ObjectType::ComputePipeline; + } + bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a, const ComputePipelineBase* b) const { return PipelineBase::EqualForCache(a, b); diff --git a/src/dawn_native/ComputePipeline.h b/src/dawn_native/ComputePipeline.h index 95e58a604a..1c134e65ea 100644 --- a/src/dawn_native/ComputePipeline.h +++ b/src/dawn_native/ComputePipeline.h @@ -16,6 +16,7 @@ #define DAWNNATIVE_COMPUTEPIPELINE_H_ #include "common/NonCopyable.h" +#include "dawn_native/Forward.h" #include "dawn_native/Pipeline.h" namespace dawn_native { @@ -33,6 +34,8 @@ namespace dawn_native { static ComputePipelineBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + // Functors necessary for the unordered_set-based cache. struct EqualityFunc { bool operator()(const ComputePipelineBase* a, const ComputePipelineBase* b) const; diff --git a/src/dawn_native/DawnNative.cpp b/src/dawn_native/DawnNative.cpp index 06c21c3de4..1b2eddc74a 100644 --- a/src/dawn_native/DawnNative.cpp +++ b/src/dawn_native/DawnNative.cpp @@ -246,7 +246,7 @@ namespace dawn_native { } const char* GetObjectLabelForTesting(void* objectHandle) { - ObjectBase* object = reinterpret_cast(objectHandle); + ApiObjectBase* object = reinterpret_cast(objectHandle); return object->GetLabel().c_str(); } diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index 35f105d4f4..e1c87acb09 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -33,6 +33,7 @@ #include "dawn_native/ExternalTexture.h" #include "dawn_native/Instance.h" #include "dawn_native/InternalPipelineStore.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/PersistentCache.h" #include "dawn_native/PipelineLayout.h" #include "dawn_native/QuerySet.h" @@ -47,6 +48,7 @@ #include "dawn_native/ValidationUtils_autogen.h" #include "dawn_platform/DawnPlatform.h" +#include #include namespace dawn_native { @@ -471,7 +473,7 @@ namespace dawn_native { return mPersistentCache.get(); } - MaybeError DeviceBase::ValidateObject(const ObjectBase* object) const { + MaybeError DeviceBase::ValidateObject(const ApiObjectBase* object) const { ASSERT(object != nullptr); DAWN_INVALID_IF(object->GetDevice() != this, "%s is associated with %s, and cannot be used with %s.", object, @@ -506,6 +508,10 @@ namespace dawn_native { return mState != State::Alive; } + std::mutex* DeviceBase::GetObjectListMutex(ObjectType type) { + return &mObjectLists[type].mutex; + } + AdapterBase* DeviceBase::GetAdapter() const { return mAdapter; } diff --git a/src/dawn_native/Device.h b/src/dawn_native/Device.h index 3f4ad43ea4..f3c6209c8e 100644 --- a/src/dawn_native/Device.h +++ b/src/dawn_native/Device.h @@ -22,11 +22,14 @@ #include "dawn_native/Forward.h" #include "dawn_native/Limits.h" #include "dawn_native/ObjectBase.h" +#include "dawn_native/ObjectType_autogen.h" +#include "dawn_native/StagingBuffer.h" #include "dawn_native/Toggles.h" #include "dawn_native/DawnNative.h" #include "dawn_native/dawn_platform.h" +#include #include namespace dawn_platform { @@ -75,7 +78,7 @@ namespace dawn_native { return false; } - MaybeError ValidateObject(const ObjectBase* object) const; + MaybeError ValidateObject(const ApiObjectBase* object) const; AdapterBase* GetAdapter() const; dawn_platform::Platform* GetPlatform() const; @@ -257,6 +260,7 @@ namespace dawn_native { }; State GetState() const; bool IsLost() const; + std::mutex* GetObjectListMutex(ObjectType type); std::vector GetEnabledExtensions() const; std::vector GetTogglesUsed() const; @@ -451,6 +455,14 @@ namespace dawn_native { State mState = State::BeingCreated; + // Encompasses the mutex and the actual list that contains all live objects "owned" by the + // device. + struct ApiObjectList { + std::mutex mutex; + LinkedList objects; + }; + PerObjectType mObjectLists; + FormatTable mFormatTable; TogglesSet mEnabledToggles; diff --git a/src/dawn_native/ExternalTexture.cpp b/src/dawn_native/ExternalTexture.cpp index 5923ef0765..d70b9b7064 100644 --- a/src/dawn_native/ExternalTexture.cpp +++ b/src/dawn_native/ExternalTexture.cpp @@ -15,6 +15,7 @@ #include "dawn_native/ExternalTexture.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/Texture.h" #include "dawn_native/dawn_platform.h" @@ -86,12 +87,12 @@ namespace dawn_native { ExternalTextureBase::ExternalTextureBase(DeviceBase* device, const ExternalTextureDescriptor* descriptor) - : ObjectBase(device, kLabelNotImplemented), mState(ExternalTextureState::Alive) { + : ApiObjectBase(device, kLabelNotImplemented), mState(ExternalTextureState::Alive) { textureViews[0] = descriptor->plane0; } ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : ApiObjectBase(device, tag) { } const std::array, kMaxPlanesPerFormat>& @@ -120,4 +121,8 @@ namespace dawn_native { return new ExternalTextureBase(device, ObjectBase::kError); } -} // namespace dawn_native \ No newline at end of file + ObjectType ExternalTextureBase::GetType() const { + return ObjectType::ExternalTexture; + } + +} // namespace dawn_native diff --git a/src/dawn_native/ExternalTexture.h b/src/dawn_native/ExternalTexture.h index b197b295ec..d16147472c 100644 --- a/src/dawn_native/ExternalTexture.h +++ b/src/dawn_native/ExternalTexture.h @@ -16,6 +16,7 @@ #define DAWNNATIVE_EXTERNALTEXTURE_H_ #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" #include "dawn_native/ObjectBase.h" #include "dawn_native/Subresource.h" @@ -29,7 +30,7 @@ namespace dawn_native { MaybeError ValidateExternalTextureDescriptor(const DeviceBase* device, const ExternalTextureDescriptor* descriptor); - class ExternalTextureBase : public ObjectBase { + class ExternalTextureBase : public ApiObjectBase { public: static ResultOrError> Create( DeviceBase* device, @@ -41,6 +42,8 @@ namespace dawn_native { static ExternalTextureBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + void APIDestroy(); private: @@ -52,4 +55,4 @@ namespace dawn_native { }; } // namespace dawn_native -#endif // DAWNNATIVE_EXTERNALTEXTURE_H_ \ No newline at end of file +#endif // DAWNNATIVE_EXTERNALTEXTURE_H_ diff --git a/src/dawn_native/Forward.h b/src/dawn_native/Forward.h index beaa5d3947..61b628cb41 100644 --- a/src/dawn_native/Forward.h +++ b/src/dawn_native/Forward.h @@ -22,6 +22,8 @@ class Ref; namespace dawn_native { + enum class ObjectType : uint32_t; + class AdapterBase; class BindGroupBase; class BindGroupLayoutBase; diff --git a/src/dawn_native/ObjectBase.cpp b/src/dawn_native/ObjectBase.cpp index bc90c80e27..e33722fd73 100644 --- a/src/dawn_native/ObjectBase.cpp +++ b/src/dawn_native/ObjectBase.cpp @@ -13,29 +13,21 @@ // limitations under the License. #include "dawn_native/ObjectBase.h" +#include "dawn_native/Device.h" + +#include namespace dawn_native { static constexpr uint64_t kErrorPayload = 0; static constexpr uint64_t kNotErrorPayload = 1; - ObjectBase::ObjectBase(DeviceBase* device, const char* label) - : RefCounted(kNotErrorPayload), mDevice(device) { - if (label) { - mLabel = label; - } + ObjectBase::ObjectBase(DeviceBase* device) : RefCounted(kNotErrorPayload), mDevice(device) { } ObjectBase::ObjectBase(DeviceBase* device, ErrorTag) : RefCounted(kErrorPayload), mDevice(device) { } - ObjectBase::ObjectBase(DeviceBase* device, LabelNotImplementedTag) - : RefCounted(kNotErrorPayload), mDevice(device) { - } - - const std::string& ObjectBase::GetLabel() const { - return mLabel; - } DeviceBase* ObjectBase::GetDevice() const { return mDevice; @@ -45,12 +37,37 @@ namespace dawn_native { return GetRefCountPayload() == kErrorPayload; } - void ObjectBase::APISetLabel(const char* label) { + bool ObjectBase::IsAlive() const { + return mDevice != nullptr; + } + + void ObjectBase::DestroyObject() { + mDevice = nullptr; + } + + ApiObjectBase::ApiObjectBase(DeviceBase* device, const char* label) : ObjectBase(device) { + if (label) { + mLabel = label; + } + } + + ApiObjectBase::ApiObjectBase(DeviceBase* device, ErrorTag tag) : ObjectBase(device, tag) { + } + + ApiObjectBase::ApiObjectBase(DeviceBase* device, LabelNotImplementedTag tag) + : ObjectBase(device) { + } + + void ApiObjectBase::APISetLabel(const char* label) { mLabel = label; SetLabelImpl(); } - void ObjectBase::SetLabelImpl() { + const std::string& ApiObjectBase::GetLabel() const { + return mLabel; + } + + void ApiObjectBase::SetLabelImpl() { } } // namespace dawn_native diff --git a/src/dawn_native/ObjectBase.h b/src/dawn_native/ObjectBase.h index b0df7aa8ba..17d32f8ff4 100644 --- a/src/dawn_native/ObjectBase.h +++ b/src/dawn_native/ObjectBase.h @@ -15,7 +15,9 @@ #ifndef DAWNNATIVE_OBJECTBASE_H_ #define DAWNNATIVE_OBJECTBASE_H_ +#include "common/LinkedList.h" #include "common/RefCounted.h" +#include "dawn_native/Forward.h" #include @@ -27,16 +29,32 @@ namespace dawn_native { public: struct ErrorTag {}; static constexpr ErrorTag kError = {}; - struct LabelNotImplementedTag {}; - static constexpr LabelNotImplementedTag kLabelNotImplemented = {}; - ObjectBase(DeviceBase* device, LabelNotImplementedTag tag); - ObjectBase(DeviceBase* device, const char* label); + explicit ObjectBase(DeviceBase* device); ObjectBase(DeviceBase* device, ErrorTag tag); DeviceBase* GetDevice() const; - const std::string& GetLabel() const; bool IsError() const; + bool IsAlive() const; + void DestroyObject(); + + private: + // Pointer to owning device, if nullptr, that means that the object is no longer alive or + // valid. + DeviceBase* mDevice; + }; + + class ApiObjectBase : public ObjectBase, public LinkNode { + public: + struct LabelNotImplementedTag {}; + static constexpr LabelNotImplementedTag kLabelNotImplemented = {}; + + ApiObjectBase(DeviceBase* device, LabelNotImplementedTag tag); + ApiObjectBase(DeviceBase* device, const char* label); + ApiObjectBase(DeviceBase* device, ErrorTag tag); + + virtual ObjectType GetType() const = 0; + const std::string& GetLabel() const; // Dawn API void APISetLabel(const char* label); @@ -44,9 +62,7 @@ namespace dawn_native { private: virtual void SetLabelImpl(); - // TODO(dawn:840): Optimize memory footprint for objects that don't have labels. std::string mLabel; - DeviceBase* mDevice; }; } // namespace dawn_native diff --git a/src/dawn_native/Pipeline.cpp b/src/dawn_native/Pipeline.cpp index c1239e3180..4f658c5b5a 100644 --- a/src/dawn_native/Pipeline.cpp +++ b/src/dawn_native/Pipeline.cpp @@ -16,6 +16,7 @@ #include "dawn_native/BindGroupLayout.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectContentHasher.h" #include "dawn_native/PipelineLayout.h" #include "dawn_native/ShaderModule.h" @@ -52,7 +53,7 @@ namespace dawn_native { PipelineLayoutBase* layout, const char* label, std::vector stages) - : CachedObject(device, label), mLayout(layout) { + : ApiObjectBase(device, label), mLayout(layout) { ASSERT(!stages.empty()); for (const StageAndDescriptor& stage : stages) { @@ -89,7 +90,7 @@ namespace dawn_native { } PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : CachedObject(device, tag) { + : ApiObjectBase(device, tag) { } PipelineLayoutBase* PipelineBase::GetLayout() { diff --git a/src/dawn_native/Pipeline.h b/src/dawn_native/Pipeline.h index bc7a339a02..c4a7098ceb 100644 --- a/src/dawn_native/Pipeline.h +++ b/src/dawn_native/Pipeline.h @@ -17,6 +17,7 @@ #include "dawn_native/CachedObject.h" #include "dawn_native/Forward.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/PerStage.h" #include "dawn_native/PipelineLayout.h" #include "dawn_native/ShaderModule.h" @@ -42,7 +43,7 @@ namespace dawn_native { const EntryPointMetadata* metadata = nullptr; }; - class PipelineBase : public CachedObject { + class PipelineBase : public ApiObjectBase, public CachedObject { public: PipelineLayoutBase* GetLayout(); const PipelineLayoutBase* GetLayout() const; diff --git a/src/dawn_native/PipelineLayout.cpp b/src/dawn_native/PipelineLayout.cpp index b2a22c623d..2f96eddf01 100644 --- a/src/dawn_native/PipelineLayout.cpp +++ b/src/dawn_native/PipelineLayout.cpp @@ -20,6 +20,7 @@ #include "dawn_native/BindGroupLayout.h" #include "dawn_native/Device.h" #include "dawn_native/ObjectContentHasher.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/ShaderModule.h" namespace dawn_native { @@ -57,7 +58,7 @@ namespace dawn_native { PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor) - : CachedObject(device, kLabelNotImplemented) { + : ApiObjectBase(device, kLabelNotImplemented) { ASSERT(descriptor->bindGroupLayoutCount <= kMaxBindGroups); for (BindGroupIndex group(0); group < BindGroupIndex(descriptor->bindGroupLayoutCount); ++group) { @@ -67,7 +68,7 @@ namespace dawn_native { } PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : CachedObject(device, tag) { + : ApiObjectBase(device, tag) { } PipelineLayoutBase::~PipelineLayoutBase() { @@ -322,6 +323,10 @@ namespace dawn_native { return std::move(result); } + ObjectType PipelineLayoutBase::GetType() const { + return ObjectType::PipelineLayout; + } + const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(BindGroupIndex group) const { ASSERT(!IsError()); ASSERT(group < kMaxBindGroupsTyped); diff --git a/src/dawn_native/PipelineLayout.h b/src/dawn_native/PipelineLayout.h index a9ee34988a..d130720bac 100644 --- a/src/dawn_native/PipelineLayout.h +++ b/src/dawn_native/PipelineLayout.h @@ -22,6 +22,7 @@ #include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" #include "dawn_native/Forward.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -45,7 +46,7 @@ namespace dawn_native { std::string entryPoint; }; - class PipelineLayoutBase : public CachedObject { + class PipelineLayoutBase : public ApiObjectBase, public CachedObject { public: PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor); ~PipelineLayoutBase() override; @@ -55,6 +56,8 @@ namespace dawn_native { DeviceBase* device, std::vector stages); + ObjectType GetType() const override; + const BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group) const; BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group); const BindGroupLayoutMask& GetBindGroupLayoutsMask() const; diff --git a/src/dawn_native/ProgrammablePassEncoder.cpp b/src/dawn_native/ProgrammablePassEncoder.cpp index 8384620a9f..0c3234e4d9 100644 --- a/src/dawn_native/ProgrammablePassEncoder.cpp +++ b/src/dawn_native/ProgrammablePassEncoder.cpp @@ -21,6 +21,7 @@ #include "dawn_native/CommandBuffer.h" #include "dawn_native/Commands.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/ValidationUtils_autogen.h" #include @@ -29,7 +30,7 @@ namespace dawn_native { ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device, EncodingContext* encodingContext) - : ObjectBase(device, kLabelNotImplemented), + : ApiObjectBase(device, kLabelNotImplemented), mEncodingContext(encodingContext), mValidationEnabled(device->IsValidationEnabled()) { } @@ -37,7 +38,7 @@ namespace dawn_native { ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device, EncodingContext* encodingContext, ErrorTag errorTag) - : ObjectBase(device, errorTag), + : ApiObjectBase(device, errorTag), mEncodingContext(encodingContext), mValidationEnabled(device->IsValidationEnabled()) { } diff --git a/src/dawn_native/ProgrammablePassEncoder.h b/src/dawn_native/ProgrammablePassEncoder.h index 4cea69628b..f58a9090ac 100644 --- a/src/dawn_native/ProgrammablePassEncoder.h +++ b/src/dawn_native/ProgrammablePassEncoder.h @@ -17,6 +17,7 @@ #include "dawn_native/CommandEncoder.h" #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" #include "dawn_native/IntegerTypes.h" #include "dawn_native/ObjectBase.h" @@ -27,7 +28,7 @@ namespace dawn_native { class DeviceBase; // Base class for shared functionality between ComputePassEncoder and RenderPassEncoder. - class ProgrammablePassEncoder : public ObjectBase { + class ProgrammablePassEncoder : public ApiObjectBase { public: ProgrammablePassEncoder(DeviceBase* device, EncodingContext* encodingContext); diff --git a/src/dawn_native/QuerySet.cpp b/src/dawn_native/QuerySet.cpp index 84f5da2176..0128607d87 100644 --- a/src/dawn_native/QuerySet.cpp +++ b/src/dawn_native/QuerySet.cpp @@ -16,6 +16,7 @@ #include "dawn_native/Device.h" #include "dawn_native/Extensions.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/ValidationUtils_autogen.h" #include @@ -114,7 +115,7 @@ namespace dawn_native { } QuerySetBase::QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descriptor) - : ObjectBase(device, kLabelNotImplemented), + : ApiObjectBase(device, kLabelNotImplemented), mQueryType(descriptor->type), mQueryCount(descriptor->count), mState(QuerySetState::Available) { @@ -126,7 +127,7 @@ namespace dawn_native { } QuerySetBase::QuerySetBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : ApiObjectBase(device, tag) { } QuerySetBase::~QuerySetBase() { @@ -139,6 +140,10 @@ namespace dawn_native { return new ErrorQuerySet(device); } + ObjectType QuerySetBase::GetType() const { + return ObjectType::QuerySet; + } + wgpu::QueryType QuerySetBase::GetQueryType() const { return mQueryType; } diff --git a/src/dawn_native/QuerySet.h b/src/dawn_native/QuerySet.h index 32b75c9edc..3ad4e7ca4c 100644 --- a/src/dawn_native/QuerySet.h +++ b/src/dawn_native/QuerySet.h @@ -25,12 +25,14 @@ namespace dawn_native { MaybeError ValidateQuerySetDescriptor(DeviceBase* device, const QuerySetDescriptor* descriptor); - class QuerySetBase : public ObjectBase { + class QuerySetBase : public ApiObjectBase { public: QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descriptor); static QuerySetBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + wgpu::QueryType GetQueryType() const; uint32_t GetQueryCount() const; const std::vector& GetPipelineStatistics() const; diff --git a/src/dawn_native/Queue.cpp b/src/dawn_native/Queue.cpp index 562fad689c..dc81517ff1 100644 --- a/src/dawn_native/Queue.cpp +++ b/src/dawn_native/Queue.cpp @@ -24,6 +24,7 @@ #include "dawn_native/Device.h" #include "dawn_native/DynamicUploader.h" #include "dawn_native/ExternalTexture.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/QuerySet.h" #include "dawn_native/RenderPassEncoder.h" #include "dawn_native/RenderPipeline.h" @@ -161,10 +162,11 @@ namespace dawn_native { QueueBase::TaskInFlight::~TaskInFlight() { } - QueueBase::QueueBase(DeviceBase* device) : ObjectBase(device, kLabelNotImplemented) { + QueueBase::QueueBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) { } - QueueBase::QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag) : ObjectBase(device, tag) { + QueueBase::QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag) + : ApiObjectBase(device, tag) { } QueueBase::~QueueBase() { @@ -176,6 +178,10 @@ namespace dawn_native { return new ErrorQueue(device); } + ObjectType QueueBase::GetType() const { + return ObjectType::Queue; + } + void QueueBase::APISubmit(uint32_t commandCount, CommandBufferBase* const* commands) { SubmitInternal(commandCount, commands); diff --git a/src/dawn_native/Queue.h b/src/dawn_native/Queue.h index 7dc460ddcf..4c76f181c9 100644 --- a/src/dawn_native/Queue.h +++ b/src/dawn_native/Queue.h @@ -25,7 +25,7 @@ namespace dawn_native { - class QueueBase : public ObjectBase { + class QueueBase : public ApiObjectBase { public: struct TaskInFlight { virtual ~TaskInFlight(); @@ -33,9 +33,12 @@ namespace dawn_native { virtual void HandleDeviceLoss() = 0; }; - static QueueBase* MakeError(DeviceBase* device); ~QueueBase() override; + static QueueBase* MakeError(DeviceBase* device); + + ObjectType GetType() const override; + // Dawn API void APISubmit(uint32_t commandCount, CommandBufferBase* const* commands); void APIOnSubmittedWorkDone(uint64_t signalValue, diff --git a/src/dawn_native/RenderBundle.cpp b/src/dawn_native/RenderBundle.cpp index b17031b058..cb81dab75e 100644 --- a/src/dawn_native/RenderBundle.cpp +++ b/src/dawn_native/RenderBundle.cpp @@ -17,6 +17,7 @@ #include "common/BitSetIterator.h" #include "dawn_native/Commands.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/RenderBundleEncoder.h" namespace dawn_native { @@ -26,7 +27,7 @@ namespace dawn_native { Ref attachmentState, RenderPassResourceUsage resourceUsage, IndirectDrawMetadata indirectDrawMetadata) - : ObjectBase(encoder->GetDevice(), kLabelNotImplemented), + : ApiObjectBase(encoder->GetDevice(), kLabelNotImplemented), mCommands(encoder->AcquireCommands()), mIndirectDrawMetadata(std::move(indirectDrawMetadata)), mAttachmentState(std::move(attachmentState)), @@ -43,7 +44,11 @@ namespace dawn_native { } RenderBundleBase::RenderBundleBase(DeviceBase* device, ErrorTag errorTag) - : ObjectBase(device, errorTag) { + : ApiObjectBase(device, errorTag) { + } + + ObjectType RenderBundleBase::GetType() const { + return ObjectType::RenderBundle; } CommandIterator* RenderBundleBase::GetCommands() { diff --git a/src/dawn_native/RenderBundle.h b/src/dawn_native/RenderBundle.h index 40db9243f7..37517d9e60 100644 --- a/src/dawn_native/RenderBundle.h +++ b/src/dawn_native/RenderBundle.h @@ -19,6 +19,7 @@ #include "dawn_native/AttachmentState.h" #include "dawn_native/CommandAllocator.h" #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" #include "dawn_native/IndirectDrawMetadata.h" #include "dawn_native/ObjectBase.h" #include "dawn_native/PassResourceUsage.h" @@ -32,7 +33,7 @@ namespace dawn_native { struct RenderBundleDescriptor; class RenderBundleEncoder; - class RenderBundleBase : public ObjectBase { + class RenderBundleBase : public ApiObjectBase { public: RenderBundleBase(RenderBundleEncoder* encoder, const RenderBundleDescriptor* descriptor, @@ -42,6 +43,8 @@ namespace dawn_native { static RenderBundleBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + CommandIterator* GetCommands(); const AttachmentState* GetAttachmentState() const; diff --git a/src/dawn_native/RenderBundleEncoder.cpp b/src/dawn_native/RenderBundleEncoder.cpp index 7ddda3154c..43db53d35b 100644 --- a/src/dawn_native/RenderBundleEncoder.cpp +++ b/src/dawn_native/RenderBundleEncoder.cpp @@ -18,6 +18,7 @@ #include "dawn_native/Commands.h" #include "dawn_native/Device.h" #include "dawn_native/Format.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/RenderPipeline.h" #include "dawn_native/ValidationUtils_autogen.h" #include "dawn_platform/DawnPlatform.h" @@ -102,6 +103,10 @@ namespace dawn_native { return new RenderBundleEncoder(device, ObjectBase::kError); } + ObjectType RenderBundleEncoder::GetType() const { + return ObjectType::RenderBundleEncoder; + } + CommandIterator RenderBundleEncoder::AcquireCommands() { return mBundleEncodingContext.AcquireCommands(); } diff --git a/src/dawn_native/RenderBundleEncoder.h b/src/dawn_native/RenderBundleEncoder.h index d3463ddcb4..0c7ab447be 100644 --- a/src/dawn_native/RenderBundleEncoder.h +++ b/src/dawn_native/RenderBundleEncoder.h @@ -17,6 +17,7 @@ #include "dawn_native/EncodingContext.h" #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" #include "dawn_native/RenderBundle.h" #include "dawn_native/RenderEncoderBase.h" @@ -32,6 +33,8 @@ namespace dawn_native { const RenderBundleEncoderDescriptor* descriptor); static RenderBundleEncoder* MakeError(DeviceBase* device); + ObjectType GetType() const override; + RenderBundleBase* APIFinish(const RenderBundleDescriptor* descriptor); CommandIterator AcquireCommands(); diff --git a/src/dawn_native/RenderPassEncoder.cpp b/src/dawn_native/RenderPassEncoder.cpp index 250d064ca1..6d073dad93 100644 --- a/src/dawn_native/RenderPassEncoder.cpp +++ b/src/dawn_native/RenderPassEncoder.cpp @@ -20,6 +20,7 @@ #include "dawn_native/CommandValidation.h" #include "dawn_native/Commands.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/QuerySet.h" #include "dawn_native/RenderBundle.h" #include "dawn_native/RenderPipeline.h" @@ -77,6 +78,10 @@ namespace dawn_native { return new RenderPassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError); } + ObjectType RenderPassEncoder::GetType() const { + return ObjectType::RenderPassEncoder; + } + void RenderPassEncoder::TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex) { DAWN_ASSERT(querySet != nullptr); diff --git a/src/dawn_native/RenderPassEncoder.h b/src/dawn_native/RenderPassEncoder.h index 2e25d43313..5aaf32eea0 100644 --- a/src/dawn_native/RenderPassEncoder.h +++ b/src/dawn_native/RenderPassEncoder.h @@ -16,6 +16,7 @@ #define DAWNNATIVE_RENDERPASSENCODER_H_ #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" #include "dawn_native/RenderEncoderBase.h" namespace dawn_native { @@ -37,6 +38,8 @@ namespace dawn_native { CommandEncoder* commandEncoder, EncodingContext* encodingContext); + ObjectType GetType() const override; + void APIEndPass(); void APISetStencilReference(uint32_t reference); diff --git a/src/dawn_native/RenderPipeline.cpp b/src/dawn_native/RenderPipeline.cpp index 79b8002193..e4f70d589e 100644 --- a/src/dawn_native/RenderPipeline.cpp +++ b/src/dawn_native/RenderPipeline.cpp @@ -20,6 +20,7 @@ #include "dawn_native/Device.h" #include "dawn_native/InternalPipelineStore.h" #include "dawn_native/ObjectContentHasher.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/VertexFormat.h" @@ -559,6 +560,10 @@ namespace dawn_native { return new RenderPipelineBase(device, ObjectBase::kError); } + ObjectType RenderPipelineBase::GetType() const { + return ObjectType::RenderPipeline; + } + RenderPipelineBase::~RenderPipelineBase() { if (IsCachedReference()) { GetDevice()->UncacheRenderPipeline(this); diff --git a/src/dawn_native/RenderPipeline.h b/src/dawn_native/RenderPipeline.h index ea618dac33..66f3456b17 100644 --- a/src/dawn_native/RenderPipeline.h +++ b/src/dawn_native/RenderPipeline.h @@ -17,6 +17,7 @@ #include "common/TypedInteger.h" #include "dawn_native/AttachmentState.h" +#include "dawn_native/Forward.h" #include "dawn_native/IntegerTypes.h" #include "dawn_native/Pipeline.h" @@ -62,6 +63,8 @@ namespace dawn_native { static RenderPipelineBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + const ityp::bitset& GetAttributeLocationsUsed() const; const VertexAttributeInfo& GetAttribute(VertexAttributeLocation location) const; diff --git a/src/dawn_native/Sampler.cpp b/src/dawn_native/Sampler.cpp index 935d57f960..4562826f04 100644 --- a/src/dawn_native/Sampler.cpp +++ b/src/dawn_native/Sampler.cpp @@ -72,7 +72,7 @@ namespace dawn_native { // SamplerBase SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor) - : CachedObject(device, kLabelNotImplemented), + : ApiObjectBase(device, kLabelNotImplemented), mAddressModeU(descriptor->addressModeU), mAddressModeV(descriptor->addressModeV), mAddressModeW(descriptor->addressModeW), @@ -86,7 +86,7 @@ namespace dawn_native { } SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : CachedObject(device, tag) { + : ApiObjectBase(device, tag) { } SamplerBase::~SamplerBase() { @@ -100,6 +100,10 @@ namespace dawn_native { return new SamplerBase(device, ObjectBase::kError); } + ObjectType SamplerBase::GetType() const { + return ObjectType::Sampler; + } + bool SamplerBase::IsComparison() const { return mCompareFunction != wgpu::CompareFunction::Undefined; } diff --git a/src/dawn_native/Sampler.h b/src/dawn_native/Sampler.h index aa74966e48..3e7d1fbae4 100644 --- a/src/dawn_native/Sampler.h +++ b/src/dawn_native/Sampler.h @@ -17,6 +17,8 @@ #include "dawn_native/CachedObject.h" #include "dawn_native/Error.h" +#include "dawn_native/Forward.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/dawn_platform.h" @@ -26,13 +28,15 @@ namespace dawn_native { MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor); - class SamplerBase : public CachedObject { + class SamplerBase : public ApiObjectBase, public CachedObject { public: SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor); ~SamplerBase() override; static SamplerBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + bool IsComparison() const; bool IsFiltering() const; diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp index 616548438a..9650f357c7 100644 --- a/src/dawn_native/ShaderModule.cpp +++ b/src/dawn_native/ShaderModule.cpp @@ -1139,7 +1139,7 @@ namespace dawn_native { // ShaderModuleBase ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor) - : CachedObject(device, descriptor->label), mType(Type::Undefined) { + : ApiObjectBase(device, descriptor->label), mType(Type::Undefined) { ASSERT(descriptor->nextInChain != nullptr); const ShaderModuleSPIRVDescriptor* spirvDesc = nullptr; FindInChain(descriptor->nextInChain, &spirvDesc); @@ -1157,7 +1157,7 @@ namespace dawn_native { } ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : CachedObject(device, tag), mType(Type::Undefined) { + : ApiObjectBase(device, tag), mType(Type::Undefined) { } ShaderModuleBase::~ShaderModuleBase() { @@ -1171,6 +1171,10 @@ namespace dawn_native { return AcquireRef(new ShaderModuleBase(device, ObjectBase::kError)); } + ObjectType ShaderModuleBase::GetType() const { + return ObjectType::ShaderModule; + } + bool ShaderModuleBase::HasEntryPoint(const std::string& entryPoint) const { return mEntryPoints.count(entryPoint) > 0; } diff --git a/src/dawn_native/ShaderModule.h b/src/dawn_native/ShaderModule.h index d981d56e71..82737848c2 100644 --- a/src/dawn_native/ShaderModule.h +++ b/src/dawn_native/ShaderModule.h @@ -24,6 +24,7 @@ #include "dawn_native/Format.h" #include "dawn_native/Forward.h" #include "dawn_native/IntegerTypes.h" +#include "dawn_native/ObjectBase.h" #include "dawn_native/PerStage.h" #include "dawn_native/VertexFormat.h" #include "dawn_native/dawn_platform.h" @@ -195,13 +196,15 @@ namespace dawn_native { SingleShaderStage stage; }; - class ShaderModuleBase : public CachedObject { + class ShaderModuleBase : public ApiObjectBase, public CachedObject { public: ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor); ~ShaderModuleBase() override; static Ref MakeError(DeviceBase* device); + ObjectType GetType() const override; + // Return true iff the program has an entrypoint called `entryPoint`. bool HasEntryPoint(const std::string& entryPoint) const; diff --git a/src/dawn_native/SwapChain.cpp b/src/dawn_native/SwapChain.cpp index 46d8a69c8d..2634cd83cb 100644 --- a/src/dawn_native/SwapChain.cpp +++ b/src/dawn_native/SwapChain.cpp @@ -17,6 +17,7 @@ #include "common/Constants.h" #include "dawn_native/Adapter.h" #include "dawn_native/Device.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/Surface.h" #include "dawn_native/Texture.h" #include "dawn_native/ValidationUtils_autogen.h" @@ -112,11 +113,11 @@ namespace dawn_native { // SwapChainBase - SwapChainBase::SwapChainBase(DeviceBase* device) : ObjectBase(device, kLabelNotImplemented) { + SwapChainBase::SwapChainBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) { } SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag) { + : ApiObjectBase(device, tag) { } SwapChainBase::~SwapChainBase() { @@ -127,6 +128,10 @@ namespace dawn_native { return new ErrorSwapChain(device); } + ObjectType SwapChainBase::GetType() const { + return ObjectType::SwapChain; + } + // OldSwapChainBase OldSwapChainBase::OldSwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor) diff --git a/src/dawn_native/SwapChain.h b/src/dawn_native/SwapChain.h index ad67d2679e..4a70431c3b 100644 --- a/src/dawn_native/SwapChain.h +++ b/src/dawn_native/SwapChain.h @@ -30,12 +30,14 @@ namespace dawn_native { TextureDescriptor GetSwapChainBaseTextureDescriptor(NewSwapChainBase* swapChain); - class SwapChainBase : public ObjectBase { + class SwapChainBase : public ApiObjectBase { public: SwapChainBase(DeviceBase* device); static SwapChainBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + // Dawn API virtual void APIConfigure(wgpu::TextureFormat format, wgpu::TextureUsage allowedUsage, diff --git a/src/dawn_native/Texture.cpp b/src/dawn_native/Texture.cpp index e5c18c75d1..9217e1928f 100644 --- a/src/dawn_native/Texture.cpp +++ b/src/dawn_native/Texture.cpp @@ -23,6 +23,7 @@ #include "dawn_native/ChainUtils_autogen.h" #include "dawn_native/Device.h" #include "dawn_native/EnumMaskIterator.h" +#include "dawn_native/ObjectType_autogen.h" #include "dawn_native/PassResourceUsage.h" #include "dawn_native/ValidationUtils_autogen.h" @@ -445,7 +446,7 @@ namespace dawn_native { TextureBase::TextureBase(DeviceBase* device, const TextureDescriptor* descriptor, TextureState state) - : ObjectBase(device, descriptor->label), + : ApiObjectBase(device, descriptor->label), mDimension(descriptor->dimension), mFormat(device->GetValidInternalFormat(descriptor->format)), mSize(descriptor->size), @@ -468,7 +469,7 @@ namespace dawn_native { static Format kUnusedFormat; TextureBase::TextureBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag), mFormat(kUnusedFormat) { + : ApiObjectBase(device, tag), mFormat(kUnusedFormat) { } // static @@ -476,6 +477,10 @@ namespace dawn_native { return new TextureBase(device, ObjectBase::kError); } + ObjectType TextureBase::GetType() const { + return ObjectType::Texture; + } + wgpu::TextureDimension TextureBase::GetDimension() const { ASSERT(!IsError()); return mDimension; @@ -684,7 +689,7 @@ namespace dawn_native { // TextureViewBase TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor) - : ObjectBase(texture->GetDevice(), kLabelNotImplemented), + : ApiObjectBase(texture->GetDevice(), kLabelNotImplemented), mTexture(texture), mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)), mDimension(descriptor->dimension), @@ -694,7 +699,7 @@ namespace dawn_native { } TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag) - : ObjectBase(device, tag), mFormat(kUnusedFormat) { + : ApiObjectBase(device, tag), mFormat(kUnusedFormat) { } // static @@ -702,6 +707,10 @@ namespace dawn_native { return new TextureViewBase(device, ObjectBase::kError); } + ObjectType TextureViewBase::GetType() const { + return ObjectType::TextureView; + } + const TextureBase* TextureViewBase::GetTexture() const { ASSERT(!IsError()); return mTexture.Get(); diff --git a/src/dawn_native/Texture.h b/src/dawn_native/Texture.h index 88a3338787..ca38e94139 100644 --- a/src/dawn_native/Texture.h +++ b/src/dawn_native/Texture.h @@ -42,7 +42,7 @@ namespace dawn_native { static constexpr wgpu::TextureUsage kReadOnlyTextureUsages = wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding; - class TextureBase : public ObjectBase { + class TextureBase : public ApiObjectBase { public: enum class TextureState { OwnedInternal, OwnedExternal, Destroyed }; enum class ClearValue { Zero, NonZero }; @@ -50,6 +50,8 @@ namespace dawn_native { static TextureBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + wgpu::TextureDimension GetDimension() const; const Format& GetFormat() const; const Extent3D& GetSize() const; @@ -113,12 +115,14 @@ namespace dawn_native { std::vector mIsSubresourceContentInitializedAtIndex; }; - class TextureViewBase : public ObjectBase { + class TextureViewBase : public ApiObjectBase { public: TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor); static TextureViewBase* MakeError(DeviceBase* device); + ObjectType GetType() const override; + const TextureBase* GetTexture() const; TextureBase* GetTexture();