Refactors dawn_native objects for list tracking and adds destroy skeleton API.

Adds generated headers in dawn_native for object type tracking similar to that used in dawn_wire. Splits ObjectBase into ObjectBase and ApiObjectBase for clearly differentiation, and adds virtual function to identify the type of ApiObjects. Updates error generation to utilize new object typing for generating messages.

Bug: dawn:628, dawn:840, dawn:563
Change-Id: Ia4f831fcbfb29a70ed5a35d47ed622921e744c84
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/64820
Commit-Queue: Loko Kung <lokokung@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Loko Kung 2021-09-28 15:40:01 +00:00 committed by Dawn LUCI CQ
parent 7b04930aa0
commit 8d195d511d
57 changed files with 418 additions and 141 deletions

View File

@ -845,6 +845,14 @@ class MultiGeneratorFromDawnJSON(Generator):
FileRender('dawn_native/webgpu_absl_format.cpp', FileRender('dawn_native/webgpu_absl_format.cpp',
'src/dawn_native/webgpu_absl_format_autogen.cpp', 'src/dawn_native/webgpu_absl_format_autogen.cpp',
frontend_params)) 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: if 'dawn_wire' in targets:
additional_params = compute_wire_params(params_dawn, wire_json) additional_params = compute_wire_params(params_dawn, wire_json)

View File

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

View File

@ -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 <typename T>
using PerObjectType = ityp::array<ObjectType, T, {{len(by_category["object"])}}>;
const char* ObjectTypeAsString(ObjectType type);
} // namespace dawn_native
#endif // DAWNNATIVE_OBJECTTPYE_AUTOGEN_H_

View File

@ -14,13 +14,10 @@
#include "dawn_native/webgpu_absl_format_autogen.h" #include "dawn_native/webgpu_absl_format_autogen.h"
{% set skip_types = ["texture view", "instance", "surface"] %} #include "dawn_native/Device.h"
#include "dawn_native/ObjectBase.h"
{% for type in by_category["object"] %} #include "dawn_native/ObjectType_autogen.h"
{% if type.name.canonical_case() not in skip_types %} #include "dawn_native/Texture.h"
#include "dawn_native/{{type.name.CamelCase()}}.h"
{% endif %}
{% endfor %}
namespace dawn_native { namespace dawn_native {
@ -28,12 +25,11 @@ namespace dawn_native {
// Objects // Objects
// //
// TODO(dawn:563) Detect the type of ObjectBase references and use the right formatter.
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const ObjectBase* value, AbslFormatConvert(const DeviceBase* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s) { absl::FormatSink* s) {
s->Append("[Object"); s->Append("[Device");
const std::string& label = value->GetLabel(); const std::string& label = value->GetLabel();
if (!label.empty()) { if (!label.empty()) {
s->Append(absl::StrFormat(" \"%s\"", label)); s->Append(absl::StrFormat(" \"%s\"", label));
@ -42,30 +38,26 @@ namespace dawn_native {
return {true}; return {true};
} }
{% for type in by_category["object"] %} absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
{% if type.name.canonical_case() not in skip_types %} AbslFormatConvert(const ApiObjectBase* value,
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> const absl::FormatConversionSpec& spec,
AbslFormatConvert(const {{as_frontendType(type)}} value, absl::FormatSink* s) {
const absl::FormatConversionSpec& spec, s->Append("[");
absl::FormatSink* s) { s->Append(ObjectTypeAsString(value->GetType()));
s->Append("[{{as_cppType(type.name)}}"); const std::string& label = value->GetLabel();
const std::string& label = value->GetLabel(); if (!label.empty()) {
if (!label.empty()) { s->Append(absl::StrFormat(" \"%s\"", label));
s->Append(absl::StrFormat(" \"%s\"", label)); }
} s->Append("]");
s->Append("]"); return {true};
return {true}; }
}
{% endif %}
{% endfor %}
// Special case for textureViews, since frequently the texture will be the
// thing that's labeled.
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const TextureViewBase* value, AbslFormatConvert(const TextureViewBase* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s) { absl::FormatSink* s) {
s->Append("[TextureView"); s->Append("[");
s->Append(ObjectTypeAsString(value->GetType()));
const std::string& label = value->GetLabel(); const std::string& label = value->GetLabel();
if (!label.empty()) { if (!label.empty()) {
s->Append(absl::StrFormat(" \"%s\"", label)); s->Append(absl::StrFormat(" \"%s\"", label));

View File

@ -21,29 +21,29 @@
namespace dawn_native { namespace dawn_native {
{% set skip_types = ["instance", "surface"] %}
{% set pure_frontend_types = ["command encoder", "compute pass encoder", "render pass encoder", "render bundle encoder"] %}
// //
// Objects // Objects
// //
class ObjectBase; class DeviceBase;
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const ObjectBase* value, AbslFormatConvert(const DeviceBase* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s); absl::FormatSink* s);
{% for type in by_category["object"] %} class ApiObjectBase;
{% set Base = "" if type.name.canonical_case() in pure_frontend_types else "Base" %} absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
{% if type.name.canonical_case() not in skip_types %} AbslFormatConvert(const ApiObjectBase* value,
class {{type.name.CamelCase()}}{{Base}}; const absl::FormatConversionSpec& spec,
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatSink* s);
AbslFormatConvert(const {{type.name.CamelCase()}}{{Base}}* value,
const absl::FormatConversionSpec& spec, // Special case for TextureViews, since frequently the texture will be the
absl::FormatSink* s); // thing that's labeled.
{% endif %} class TextureViewBase;
{% endfor %} absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const TextureViewBase* value,
const absl::FormatConversionSpec& spec,
absl::FormatSink* s);
// //
// Descriptors // Descriptors
@ -55,8 +55,8 @@ namespace dawn_native {
{% if member.name.canonical_case() == "label" %} {% if member.name.canonical_case() == "label" %}
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert(const {{as_cppType(type.name)}}* value, AbslFormatConvert(const {{as_cppType(type.name)}}* value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s); absl::FormatSink* s);
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
@ -71,8 +71,8 @@ namespace wgpu {
{% for type in by_category["enum"] %} {% for type in by_category["enum"] %}
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert({{as_cppType(type.name)}} value, AbslFormatConvert({{as_cppType(type.name)}} value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s); absl::FormatSink* s);
{% endfor %} {% endfor %}
// //
@ -82,8 +82,8 @@ namespace wgpu {
{% for type in by_category["bitmask"] %} {% for type in by_category["bitmask"] %}
absl::FormatConvertResult<absl::FormatConversionCharSet::kString> absl::FormatConvertResult<absl::FormatConversionCharSet::kString>
AbslFormatConvert({{as_cppType(type.name)}} value, AbslFormatConvert({{as_cppType(type.name)}} value,
const absl::FormatConversionSpec& spec, const absl::FormatConversionSpec& spec,
absl::FormatSink* s); absl::FormatSink* s);
{% endfor %} {% endfor %}
} // namespace dawn_native } // namespace dawn_native

View File

@ -126,7 +126,7 @@ namespace dawn_native {
} }
AttachmentState::AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint) AttachmentState::AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint)
: AttachmentStateBlueprint(blueprint), CachedObject(device, kLabelNotImplemented) { : AttachmentStateBlueprint(blueprint), ObjectBase(device) {
} }
AttachmentState::~AttachmentState() { AttachmentState::~AttachmentState() {

View File

@ -20,6 +20,7 @@
#include "common/ityp_bitset.h" #include "common/ityp_bitset.h"
#include "dawn_native/CachedObject.h" #include "dawn_native/CachedObject.h"
#include "dawn_native/IntegerTypes.h" #include "dawn_native/IntegerTypes.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -59,7 +60,9 @@ namespace dawn_native {
uint32_t mSampleCount = 0; uint32_t mSampleCount = 0;
}; };
class AttachmentState final : public AttachmentStateBlueprint, public CachedObject { class AttachmentState final : public AttachmentStateBlueprint,
public ObjectBase,
public CachedObject {
public: public:
AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint); AttachmentState(DeviceBase* device, const AttachmentStateBlueprint& blueprint);

View File

@ -111,6 +111,8 @@ dawn_json_generator("dawn_native_utils_gen") {
"src/dawn_native/ValidationUtils_autogen.cpp", "src/dawn_native/ValidationUtils_autogen.cpp",
"src/dawn_native/webgpu_absl_format_autogen.h", "src/dawn_native/webgpu_absl_format_autogen.h",
"src/dawn_native/webgpu_absl_format_autogen.cpp", "src/dawn_native/webgpu_absl_format_autogen.cpp",
"src/dawn_native/ObjectType_autogen.h",
"src/dawn_native/ObjectType_autogen.cpp",
] ]
} }

View File

@ -22,6 +22,8 @@
#include "dawn_native/ChainUtils_autogen.h" #include "dawn_native/ChainUtils_autogen.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ExternalTexture.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/Sampler.h"
#include "dawn_native/Texture.h" #include "dawn_native/Texture.h"
@ -317,7 +319,7 @@ namespace dawn_native {
BindGroupBase::BindGroupBase(DeviceBase* device, BindGroupBase::BindGroupBase(DeviceBase* device,
const BindGroupDescriptor* descriptor, const BindGroupDescriptor* descriptor,
void* bindingDataStart) void* bindingDataStart)
: ObjectBase(device, kLabelNotImplemented), : ApiObjectBase(device, kLabelNotImplemented),
mLayout(descriptor->layout), mLayout(descriptor->layout),
mBindingData(mLayout->ComputeBindingDataPointers(bindingDataStart)) { mBindingData(mLayout->ComputeBindingDataPointers(bindingDataStart)) {
for (BindingIndex i{0}; i < mLayout->GetBindingCount(); ++i) { for (BindingIndex i{0}; i < mLayout->GetBindingCount(); ++i) {
@ -397,7 +399,7 @@ namespace dawn_native {
} }
BindGroupBase::BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag) BindGroupBase::BindGroupBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag), mBindingData() { : ApiObjectBase(device, tag), mBindingData() {
} }
// static // static
@ -405,6 +407,10 @@ namespace dawn_native {
return new BindGroupBase(device, ObjectBase::kError); return new BindGroupBase(device, ObjectBase::kError);
} }
ObjectType BindGroupBase::GetType() const {
return ObjectType::BindGroup;
}
BindGroupLayoutBase* BindGroupBase::GetLayout() { BindGroupLayoutBase* BindGroupBase::GetLayout() {
ASSERT(!IsError()); ASSERT(!IsError());
return mLayout.Get(); return mLayout.Get();

View File

@ -39,10 +39,12 @@ namespace dawn_native {
uint64_t size; uint64_t size;
}; };
class BindGroupBase : public ObjectBase { class BindGroupBase : public ApiObjectBase {
public: public:
static BindGroupBase* MakeError(DeviceBase* device); static BindGroupBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
BindGroupLayoutBase* GetLayout(); BindGroupLayoutBase* GetLayout();
const BindGroupLayoutBase* GetLayout() const; const BindGroupLayoutBase* GetLayout() const;
BufferBinding GetBindingAsBufferBinding(BindingIndex bindingIndex); BufferBinding GetBindingAsBufferBinding(BindingIndex bindingIndex);

View File

@ -18,7 +18,9 @@
#include "dawn_native/ChainUtils_autogen.h" #include "dawn_native/ChainUtils_autogen.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/ObjectContentHasher.h" #include "dawn_native/ObjectContentHasher.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/PerStage.h" #include "dawn_native/PerStage.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
@ -359,7 +361,7 @@ namespace dawn_native {
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor, const BindGroupLayoutDescriptor* descriptor,
PipelineCompatibilityToken pipelineCompatibilityToken) PipelineCompatibilityToken pipelineCompatibilityToken)
: CachedObject(device, kLabelNotImplemented), : ApiObjectBase(device, kLabelNotImplemented),
mBindingInfo(BindingIndex(descriptor->entryCount)), mBindingInfo(BindingIndex(descriptor->entryCount)),
mPipelineCompatibilityToken(pipelineCompatibilityToken) { mPipelineCompatibilityToken(pipelineCompatibilityToken) {
std::vector<BindGroupLayoutEntry> sortedBindings( std::vector<BindGroupLayoutEntry> sortedBindings(
@ -386,7 +388,7 @@ namespace dawn_native {
} }
BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag) BindGroupLayoutBase::BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: CachedObject(device, tag) { : ApiObjectBase(device, tag) {
} }
BindGroupLayoutBase::~BindGroupLayoutBase() { BindGroupLayoutBase::~BindGroupLayoutBase() {
@ -401,6 +403,10 @@ namespace dawn_native {
return new BindGroupLayoutBase(device, ObjectBase::kError); return new BindGroupLayoutBase(device, ObjectBase::kError);
} }
ObjectType BindGroupLayoutBase::GetType() const {
return ObjectType::BindGroupLayout;
}
const BindGroupLayoutBase::BindingMap& BindGroupLayoutBase::GetBindingMap() const { const BindGroupLayoutBase::BindingMap& BindGroupLayoutBase::GetBindingMap() const {
ASSERT(!IsError()); ASSERT(!IsError());
return mBindingMap; return mBindingMap;

View File

@ -24,6 +24,7 @@
#include "dawn_native/CachedObject.h" #include "dawn_native/CachedObject.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -39,7 +40,7 @@ namespace dawn_native {
// Bindings are specified as a |BindingNumber| in the BindGroupLayoutDescriptor. // Bindings are specified as a |BindingNumber| in the BindGroupLayoutDescriptor.
// These numbers may be arbitrary and sparse. Internally, Dawn packs these numbers // These numbers may be arbitrary and sparse. Internally, Dawn packs these numbers
// into a packed range of |BindingIndex| integers. // into a packed range of |BindingIndex| integers.
class BindGroupLayoutBase : public CachedObject { class BindGroupLayoutBase : public ApiObjectBase, public CachedObject {
public: public:
BindGroupLayoutBase(DeviceBase* device, BindGroupLayoutBase(DeviceBase* device,
const BindGroupLayoutDescriptor* descriptor, const BindGroupLayoutDescriptor* descriptor,
@ -48,6 +49,8 @@ namespace dawn_native {
static BindGroupLayoutBase* MakeError(DeviceBase* device); static BindGroupLayoutBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
// A map from the BindingNumber to its packed BindingIndex. // A map from the BindingNumber to its packed BindingIndex.
using BindingMap = std::map<BindingNumber, BindingIndex>; using BindingMap = std::map<BindingNumber, BindingIndex>;

View File

@ -20,6 +20,7 @@
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/DynamicUploader.h" #include "dawn_native/DynamicUploader.h"
#include "dawn_native/ErrorData.h" #include "dawn_native/ErrorData.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/Queue.h" #include "dawn_native/Queue.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
@ -128,7 +129,7 @@ namespace dawn_native {
// Buffer // Buffer
BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor) BufferBase::BufferBase(DeviceBase* device, const BufferDescriptor* descriptor)
: ObjectBase(device, descriptor->label), : ApiObjectBase(device, descriptor->label),
mSize(descriptor->size), mSize(descriptor->size),
mUsage(descriptor->usage), mUsage(descriptor->usage),
mState(BufferState::Unmapped) { mState(BufferState::Unmapped) {
@ -158,7 +159,7 @@ namespace dawn_native {
BufferBase::BufferBase(DeviceBase* device, BufferBase::BufferBase(DeviceBase* device,
const BufferDescriptor* descriptor, const BufferDescriptor* descriptor,
ObjectBase::ErrorTag tag) ObjectBase::ErrorTag tag)
: ObjectBase(device, tag), mSize(descriptor->size), mState(BufferState::Unmapped) { : ApiObjectBase(device, tag), mSize(descriptor->size), mState(BufferState::Unmapped) {
if (descriptor->mappedAtCreation) { if (descriptor->mappedAtCreation) {
mState = BufferState::MappedAtCreation; mState = BufferState::MappedAtCreation;
mMapOffset = 0; mMapOffset = 0;
@ -178,6 +179,10 @@ namespace dawn_native {
return new ErrorBuffer(device, descriptor); return new ErrorBuffer(device, descriptor);
} }
ObjectType BufferBase::GetType() const {
return ObjectType::Buffer;
}
uint64_t BufferBase::GetSize() const { uint64_t BufferBase::GetSize() const {
ASSERT(!IsError()); ASSERT(!IsError());
return mSize; return mSize;

View File

@ -40,7 +40,7 @@ namespace dawn_native {
static constexpr wgpu::BufferUsage kMappableBufferUsages = static constexpr wgpu::BufferUsage kMappableBufferUsages =
wgpu::BufferUsage::MapRead | wgpu::BufferUsage::MapWrite; wgpu::BufferUsage::MapRead | wgpu::BufferUsage::MapWrite;
class BufferBase : public ObjectBase { class BufferBase : public ApiObjectBase {
enum class BufferState { enum class BufferState {
Unmapped, Unmapped,
Mapped, Mapped,
@ -53,6 +53,8 @@ namespace dawn_native {
static BufferBase* MakeError(DeviceBase* device, const BufferDescriptor* descriptor); static BufferBase* MakeError(DeviceBase* device, const BufferDescriptor* descriptor);
ObjectType GetType() const override;
uint64_t GetSize() const; uint64_t GetSize() const;
uint64_t GetAllocatedSize() const; uint64_t GetAllocatedSize() const;
wgpu::BufferUsage GetUsage() const; wgpu::BufferUsage GetUsage() const;

View File

@ -15,8 +15,6 @@
#ifndef DAWNNATIVE_CACHED_OBJECT_H_ #ifndef DAWNNATIVE_CACHED_OBJECT_H_
#define DAWNNATIVE_CACHED_OBJECT_H_ #define DAWNNATIVE_CACHED_OBJECT_H_
#include "dawn_native/ObjectBase.h"
#include <cstddef> #include <cstddef>
namespace dawn_native { namespace dawn_native {
@ -25,10 +23,8 @@ namespace dawn_native {
// we increase the refcount of an existing object. // we increase the refcount of an existing object.
// When an object is successfully created, the device should call // When an object is successfully created, the device should call
// SetIsCachedReference() and insert the object into the cache. // SetIsCachedReference() and insert the object into the cache.
class CachedObject : public ObjectBase { class CachedObject {
public: public:
using ObjectBase::ObjectBase;
bool IsCachedReference() const; bool IsCachedReference() const;
// Functor necessary for the unordered_set<CachedObject*>-based cache. // Functor necessary for the unordered_set<CachedObject*>-based cache.

View File

@ -20,18 +20,19 @@
#include "dawn_native/CommandValidation.h" #include "dawn_native/CommandValidation.h"
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/Format.h" #include "dawn_native/Format.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/Texture.h" #include "dawn_native/Texture.h"
namespace dawn_native { namespace dawn_native {
CommandBufferBase::CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor*) CommandBufferBase::CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor*)
: ObjectBase(encoder->GetDevice(), kLabelNotImplemented), : ApiObjectBase(encoder->GetDevice(), kLabelNotImplemented),
mCommands(encoder->AcquireCommands()), mCommands(encoder->AcquireCommands()),
mResourceUsages(encoder->AcquireResourceUsages()) { mResourceUsages(encoder->AcquireResourceUsages()) {
} }
CommandBufferBase::CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag) CommandBufferBase::CommandBufferBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag) { : ApiObjectBase(device, tag) {
} }
CommandBufferBase::~CommandBufferBase() { CommandBufferBase::~CommandBufferBase() {
@ -51,6 +52,10 @@ namespace dawn_native {
return new CommandBufferBase(device, ObjectBase::kError); return new CommandBufferBase(device, ObjectBase::kError);
} }
ObjectType CommandBufferBase::GetType() const {
return ObjectType::CommandBuffer;
}
MaybeError CommandBufferBase::ValidateCanUseInSubmitNow() const { MaybeError CommandBufferBase::ValidateCanUseInSubmitNow() const {
ASSERT(!IsError()); ASSERT(!IsError());

View File

@ -30,19 +30,21 @@ namespace dawn_native {
struct CopyTextureToBufferCmd; struct CopyTextureToBufferCmd;
struct TextureCopy; struct TextureCopy;
class CommandBufferBase : public ObjectBase { class CommandBufferBase : public ApiObjectBase {
public: public:
CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor); CommandBufferBase(CommandEncoder* encoder, const CommandBufferDescriptor* descriptor);
static CommandBufferBase* MakeError(DeviceBase* device); static CommandBufferBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
MaybeError ValidateCanUseInSubmitNow() const; MaybeError ValidateCanUseInSubmitNow() const;
void Destroy(); void Destroy();
const CommandBufferResourceUsage& GetResourceUsages() const; const CommandBufferResourceUsage& GetResourceUsages() const;
protected: protected:
~CommandBufferBase(); ~CommandBufferBase() override;
void DoNextSetValidatedBufferLocationsInternal(); void DoNextSetValidatedBufferLocationsInternal();

View File

@ -25,6 +25,7 @@
#include "dawn_native/ComputePassEncoder.h" #include "dawn_native/ComputePassEncoder.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ErrorData.h" #include "dawn_native/ErrorData.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/QueryHelper.h" #include "dawn_native/QueryHelper.h"
#include "dawn_native/QuerySet.h" #include "dawn_native/QuerySet.h"
#include "dawn_native/Queue.h" #include "dawn_native/Queue.h"
@ -447,7 +448,11 @@ namespace dawn_native {
} // namespace } // namespace
CommandEncoder::CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor*) 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() { CommandBufferResourceUsage CommandEncoder::AcquireResourceUsages() {

View File

@ -26,10 +26,12 @@
namespace dawn_native { namespace dawn_native {
class CommandEncoder final : public ObjectBase { class CommandEncoder final : public ApiObjectBase {
public: public:
CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor* descriptor); CommandEncoder(DeviceBase* device, const CommandEncoderDescriptor* descriptor);
ObjectType GetType() const;
CommandIterator AcquireCommands(); CommandIterator AcquireCommands();
CommandBufferResourceUsage AcquireResourceUsages(); CommandBufferResourceUsage AcquireResourceUsages();

View File

@ -20,6 +20,7 @@
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/ComputePipeline.h" #include "dawn_native/ComputePipeline.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/PassResourceUsageTracker.h" #include "dawn_native/PassResourceUsageTracker.h"
#include "dawn_native/QuerySet.h" #include "dawn_native/QuerySet.h"
@ -57,6 +58,10 @@ namespace dawn_native {
return new ComputePassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError); return new ComputePassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError);
} }
ObjectType ComputePassEncoder::GetType() const {
return ObjectType::ComputePassEncoder;
}
void ComputePassEncoder::APIEndPass() { void ComputePassEncoder::APIEndPass() {
if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError { if (mEncodingContext->TryEncode(this, [&](CommandAllocator* allocator) -> MaybeError {
if (IsValidationEnabled()) { if (IsValidationEnabled()) {

View File

@ -17,6 +17,7 @@
#include "dawn_native/CommandBufferStateTracker.h" #include "dawn_native/CommandBufferStateTracker.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/PassResourceUsageTracker.h" #include "dawn_native/PassResourceUsageTracker.h"
#include "dawn_native/ProgrammablePassEncoder.h" #include "dawn_native/ProgrammablePassEncoder.h"
@ -34,6 +35,8 @@ namespace dawn_native {
CommandEncoder* commandEncoder, CommandEncoder* commandEncoder,
EncodingContext* encodingContext); EncodingContext* encodingContext);
ObjectType GetType() const override;
void APIEndPass(); void APIEndPass();
void APIDispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1); void APIDispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1);

View File

@ -16,6 +16,7 @@
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectContentHasher.h" #include "dawn_native/ObjectContentHasher.h"
#include "dawn_native/ObjectType_autogen.h"
namespace dawn_native { namespace dawn_native {
@ -65,6 +66,10 @@ namespace dawn_native {
return new ComputePipelineBase(device, ObjectBase::kError); return new ComputePipelineBase(device, ObjectBase::kError);
} }
ObjectType ComputePipelineBase::GetType() const {
return ObjectType::ComputePipeline;
}
bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a, bool ComputePipelineBase::EqualityFunc::operator()(const ComputePipelineBase* a,
const ComputePipelineBase* b) const { const ComputePipelineBase* b) const {
return PipelineBase::EqualForCache(a, b); return PipelineBase::EqualForCache(a, b);

View File

@ -16,6 +16,7 @@
#define DAWNNATIVE_COMPUTEPIPELINE_H_ #define DAWNNATIVE_COMPUTEPIPELINE_H_
#include "common/NonCopyable.h" #include "common/NonCopyable.h"
#include "dawn_native/Forward.h"
#include "dawn_native/Pipeline.h" #include "dawn_native/Pipeline.h"
namespace dawn_native { namespace dawn_native {
@ -33,6 +34,8 @@ namespace dawn_native {
static ComputePipelineBase* MakeError(DeviceBase* device); static ComputePipelineBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
// Functors necessary for the unordered_set<ComputePipelineBase*>-based cache. // Functors necessary for the unordered_set<ComputePipelineBase*>-based cache.
struct EqualityFunc { struct EqualityFunc {
bool operator()(const ComputePipelineBase* a, const ComputePipelineBase* b) const; bool operator()(const ComputePipelineBase* a, const ComputePipelineBase* b) const;

View File

@ -246,7 +246,7 @@ namespace dawn_native {
} }
const char* GetObjectLabelForTesting(void* objectHandle) { const char* GetObjectLabelForTesting(void* objectHandle) {
ObjectBase* object = reinterpret_cast<ObjectBase*>(objectHandle); ApiObjectBase* object = reinterpret_cast<ApiObjectBase*>(objectHandle);
return object->GetLabel().c_str(); return object->GetLabel().c_str();
} }

View File

@ -33,6 +33,7 @@
#include "dawn_native/ExternalTexture.h" #include "dawn_native/ExternalTexture.h"
#include "dawn_native/Instance.h" #include "dawn_native/Instance.h"
#include "dawn_native/InternalPipelineStore.h" #include "dawn_native/InternalPipelineStore.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/PersistentCache.h" #include "dawn_native/PersistentCache.h"
#include "dawn_native/PipelineLayout.h" #include "dawn_native/PipelineLayout.h"
#include "dawn_native/QuerySet.h" #include "dawn_native/QuerySet.h"
@ -47,6 +48,7 @@
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/DawnPlatform.h"
#include <mutex>
#include <unordered_set> #include <unordered_set>
namespace dawn_native { namespace dawn_native {
@ -471,7 +473,7 @@ namespace dawn_native {
return mPersistentCache.get(); return mPersistentCache.get();
} }
MaybeError DeviceBase::ValidateObject(const ObjectBase* object) const { MaybeError DeviceBase::ValidateObject(const ApiObjectBase* object) const {
ASSERT(object != nullptr); ASSERT(object != nullptr);
DAWN_INVALID_IF(object->GetDevice() != this, DAWN_INVALID_IF(object->GetDevice() != this,
"%s is associated with %s, and cannot be used with %s.", object, "%s is associated with %s, and cannot be used with %s.", object,
@ -506,6 +508,10 @@ namespace dawn_native {
return mState != State::Alive; return mState != State::Alive;
} }
std::mutex* DeviceBase::GetObjectListMutex(ObjectType type) {
return &mObjectLists[type].mutex;
}
AdapterBase* DeviceBase::GetAdapter() const { AdapterBase* DeviceBase::GetAdapter() const {
return mAdapter; return mAdapter;
} }

View File

@ -22,11 +22,14 @@
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/Limits.h" #include "dawn_native/Limits.h"
#include "dawn_native/ObjectBase.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/Toggles.h"
#include "dawn_native/DawnNative.h" #include "dawn_native/DawnNative.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
#include <mutex>
#include <utility> #include <utility>
namespace dawn_platform { namespace dawn_platform {
@ -75,7 +78,7 @@ namespace dawn_native {
return false; return false;
} }
MaybeError ValidateObject(const ObjectBase* object) const; MaybeError ValidateObject(const ApiObjectBase* object) const;
AdapterBase* GetAdapter() const; AdapterBase* GetAdapter() const;
dawn_platform::Platform* GetPlatform() const; dawn_platform::Platform* GetPlatform() const;
@ -257,6 +260,7 @@ namespace dawn_native {
}; };
State GetState() const; State GetState() const;
bool IsLost() const; bool IsLost() const;
std::mutex* GetObjectListMutex(ObjectType type);
std::vector<const char*> GetEnabledExtensions() const; std::vector<const char*> GetEnabledExtensions() const;
std::vector<const char*> GetTogglesUsed() const; std::vector<const char*> GetTogglesUsed() const;
@ -451,6 +455,14 @@ namespace dawn_native {
State mState = State::BeingCreated; 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<ApiObjectBase> objects;
};
PerObjectType<ApiObjectList> mObjectLists;
FormatTable mFormatTable; FormatTable mFormatTable;
TogglesSet mEnabledToggles; TogglesSet mEnabledToggles;

View File

@ -15,6 +15,7 @@
#include "dawn_native/ExternalTexture.h" #include "dawn_native/ExternalTexture.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/Texture.h" #include "dawn_native/Texture.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -86,12 +87,12 @@ namespace dawn_native {
ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ExternalTextureBase::ExternalTextureBase(DeviceBase* device,
const ExternalTextureDescriptor* descriptor) const ExternalTextureDescriptor* descriptor)
: ObjectBase(device, kLabelNotImplemented), mState(ExternalTextureState::Alive) { : ApiObjectBase(device, kLabelNotImplemented), mState(ExternalTextureState::Alive) {
textureViews[0] = descriptor->plane0; textureViews[0] = descriptor->plane0;
} }
ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag) ExternalTextureBase::ExternalTextureBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag) { : ApiObjectBase(device, tag) {
} }
const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>& const std::array<Ref<TextureViewBase>, kMaxPlanesPerFormat>&
@ -120,4 +121,8 @@ namespace dawn_native {
return new ExternalTextureBase(device, ObjectBase::kError); return new ExternalTextureBase(device, ObjectBase::kError);
} }
ObjectType ExternalTextureBase::GetType() const {
return ObjectType::ExternalTexture;
}
} // namespace dawn_native } // namespace dawn_native

View File

@ -16,6 +16,7 @@
#define DAWNNATIVE_EXTERNALTEXTURE_H_ #define DAWNNATIVE_EXTERNALTEXTURE_H_
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/Subresource.h" #include "dawn_native/Subresource.h"
@ -29,7 +30,7 @@ namespace dawn_native {
MaybeError ValidateExternalTextureDescriptor(const DeviceBase* device, MaybeError ValidateExternalTextureDescriptor(const DeviceBase* device,
const ExternalTextureDescriptor* descriptor); const ExternalTextureDescriptor* descriptor);
class ExternalTextureBase : public ObjectBase { class ExternalTextureBase : public ApiObjectBase {
public: public:
static ResultOrError<Ref<ExternalTextureBase>> Create( static ResultOrError<Ref<ExternalTextureBase>> Create(
DeviceBase* device, DeviceBase* device,
@ -41,6 +42,8 @@ namespace dawn_native {
static ExternalTextureBase* MakeError(DeviceBase* device); static ExternalTextureBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
void APIDestroy(); void APIDestroy();
private: private:

View File

@ -22,6 +22,8 @@ class Ref;
namespace dawn_native { namespace dawn_native {
enum class ObjectType : uint32_t;
class AdapterBase; class AdapterBase;
class BindGroupBase; class BindGroupBase;
class BindGroupLayoutBase; class BindGroupLayoutBase;

View File

@ -13,29 +13,21 @@
// limitations under the License. // limitations under the License.
#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/Device.h"
#include <mutex>
namespace dawn_native { namespace dawn_native {
static constexpr uint64_t kErrorPayload = 0; static constexpr uint64_t kErrorPayload = 0;
static constexpr uint64_t kNotErrorPayload = 1; static constexpr uint64_t kNotErrorPayload = 1;
ObjectBase::ObjectBase(DeviceBase* device, const char* label) ObjectBase::ObjectBase(DeviceBase* device) : RefCounted(kNotErrorPayload), mDevice(device) {
: RefCounted(kNotErrorPayload), mDevice(device) {
if (label) {
mLabel = label;
}
} }
ObjectBase::ObjectBase(DeviceBase* device, ErrorTag) ObjectBase::ObjectBase(DeviceBase* device, ErrorTag)
: RefCounted(kErrorPayload), mDevice(device) { : 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 { DeviceBase* ObjectBase::GetDevice() const {
return mDevice; return mDevice;
@ -45,12 +37,37 @@ namespace dawn_native {
return GetRefCountPayload() == kErrorPayload; 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; mLabel = label;
SetLabelImpl(); SetLabelImpl();
} }
void ObjectBase::SetLabelImpl() { const std::string& ApiObjectBase::GetLabel() const {
return mLabel;
}
void ApiObjectBase::SetLabelImpl() {
} }
} // namespace dawn_native } // namespace dawn_native

View File

@ -15,7 +15,9 @@
#ifndef DAWNNATIVE_OBJECTBASE_H_ #ifndef DAWNNATIVE_OBJECTBASE_H_
#define DAWNNATIVE_OBJECTBASE_H_ #define DAWNNATIVE_OBJECTBASE_H_
#include "common/LinkedList.h"
#include "common/RefCounted.h" #include "common/RefCounted.h"
#include "dawn_native/Forward.h"
#include <string> #include <string>
@ -27,16 +29,32 @@ namespace dawn_native {
public: public:
struct ErrorTag {}; struct ErrorTag {};
static constexpr ErrorTag kError = {}; static constexpr ErrorTag kError = {};
struct LabelNotImplementedTag {};
static constexpr LabelNotImplementedTag kLabelNotImplemented = {};
ObjectBase(DeviceBase* device, LabelNotImplementedTag tag); explicit ObjectBase(DeviceBase* device);
ObjectBase(DeviceBase* device, const char* label);
ObjectBase(DeviceBase* device, ErrorTag tag); ObjectBase(DeviceBase* device, ErrorTag tag);
DeviceBase* GetDevice() const; DeviceBase* GetDevice() const;
const std::string& GetLabel() const;
bool IsError() 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<ApiObjectBase> {
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 // Dawn API
void APISetLabel(const char* label); void APISetLabel(const char* label);
@ -44,9 +62,7 @@ namespace dawn_native {
private: private:
virtual void SetLabelImpl(); virtual void SetLabelImpl();
// TODO(dawn:840): Optimize memory footprint for objects that don't have labels.
std::string mLabel; std::string mLabel;
DeviceBase* mDevice;
}; };
} // namespace dawn_native } // namespace dawn_native

View File

@ -16,6 +16,7 @@
#include "dawn_native/BindGroupLayout.h" #include "dawn_native/BindGroupLayout.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/ObjectContentHasher.h" #include "dawn_native/ObjectContentHasher.h"
#include "dawn_native/PipelineLayout.h" #include "dawn_native/PipelineLayout.h"
#include "dawn_native/ShaderModule.h" #include "dawn_native/ShaderModule.h"
@ -52,7 +53,7 @@ namespace dawn_native {
PipelineLayoutBase* layout, PipelineLayoutBase* layout,
const char* label, const char* label,
std::vector<StageAndDescriptor> stages) std::vector<StageAndDescriptor> stages)
: CachedObject(device, label), mLayout(layout) { : ApiObjectBase(device, label), mLayout(layout) {
ASSERT(!stages.empty()); ASSERT(!stages.empty());
for (const StageAndDescriptor& stage : stages) { for (const StageAndDescriptor& stage : stages) {
@ -89,7 +90,7 @@ namespace dawn_native {
} }
PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag) PipelineBase::PipelineBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: CachedObject(device, tag) { : ApiObjectBase(device, tag) {
} }
PipelineLayoutBase* PipelineBase::GetLayout() { PipelineLayoutBase* PipelineBase::GetLayout() {

View File

@ -17,6 +17,7 @@
#include "dawn_native/CachedObject.h" #include "dawn_native/CachedObject.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/PerStage.h" #include "dawn_native/PerStage.h"
#include "dawn_native/PipelineLayout.h" #include "dawn_native/PipelineLayout.h"
#include "dawn_native/ShaderModule.h" #include "dawn_native/ShaderModule.h"
@ -42,7 +43,7 @@ namespace dawn_native {
const EntryPointMetadata* metadata = nullptr; const EntryPointMetadata* metadata = nullptr;
}; };
class PipelineBase : public CachedObject { class PipelineBase : public ApiObjectBase, public CachedObject {
public: public:
PipelineLayoutBase* GetLayout(); PipelineLayoutBase* GetLayout();
const PipelineLayoutBase* GetLayout() const; const PipelineLayoutBase* GetLayout() const;

View File

@ -20,6 +20,7 @@
#include "dawn_native/BindGroupLayout.h" #include "dawn_native/BindGroupLayout.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectContentHasher.h" #include "dawn_native/ObjectContentHasher.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/ShaderModule.h" #include "dawn_native/ShaderModule.h"
namespace dawn_native { namespace dawn_native {
@ -57,7 +58,7 @@ namespace dawn_native {
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device,
const PipelineLayoutDescriptor* descriptor) const PipelineLayoutDescriptor* descriptor)
: CachedObject(device, kLabelNotImplemented) { : ApiObjectBase(device, kLabelNotImplemented) {
ASSERT(descriptor->bindGroupLayoutCount <= kMaxBindGroups); ASSERT(descriptor->bindGroupLayoutCount <= kMaxBindGroups);
for (BindGroupIndex group(0); group < BindGroupIndex(descriptor->bindGroupLayoutCount); for (BindGroupIndex group(0); group < BindGroupIndex(descriptor->bindGroupLayoutCount);
++group) { ++group) {
@ -67,7 +68,7 @@ namespace dawn_native {
} }
PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag) PipelineLayoutBase::PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: CachedObject(device, tag) { : ApiObjectBase(device, tag) {
} }
PipelineLayoutBase::~PipelineLayoutBase() { PipelineLayoutBase::~PipelineLayoutBase() {
@ -322,6 +323,10 @@ namespace dawn_native {
return std::move(result); return std::move(result);
} }
ObjectType PipelineLayoutBase::GetType() const {
return ObjectType::PipelineLayout;
}
const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(BindGroupIndex group) const { const BindGroupLayoutBase* PipelineLayoutBase::GetBindGroupLayout(BindGroupIndex group) const {
ASSERT(!IsError()); ASSERT(!IsError());
ASSERT(group < kMaxBindGroupsTyped); ASSERT(group < kMaxBindGroupsTyped);

View File

@ -22,6 +22,7 @@
#include "dawn_native/CachedObject.h" #include "dawn_native/CachedObject.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -45,7 +46,7 @@ namespace dawn_native {
std::string entryPoint; std::string entryPoint;
}; };
class PipelineLayoutBase : public CachedObject { class PipelineLayoutBase : public ApiObjectBase, public CachedObject {
public: public:
PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor); PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor);
~PipelineLayoutBase() override; ~PipelineLayoutBase() override;
@ -55,6 +56,8 @@ namespace dawn_native {
DeviceBase* device, DeviceBase* device,
std::vector<StageAndDescriptor> stages); std::vector<StageAndDescriptor> stages);
ObjectType GetType() const override;
const BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group) const; const BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group) const;
BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group); BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group);
const BindGroupLayoutMask& GetBindGroupLayoutsMask() const; const BindGroupLayoutMask& GetBindGroupLayoutsMask() const;

View File

@ -21,6 +21,7 @@
#include "dawn_native/CommandBuffer.h" #include "dawn_native/CommandBuffer.h"
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
#include <cstring> #include <cstring>
@ -29,7 +30,7 @@ namespace dawn_native {
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device, ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
EncodingContext* encodingContext) EncodingContext* encodingContext)
: ObjectBase(device, kLabelNotImplemented), : ApiObjectBase(device, kLabelNotImplemented),
mEncodingContext(encodingContext), mEncodingContext(encodingContext),
mValidationEnabled(device->IsValidationEnabled()) { mValidationEnabled(device->IsValidationEnabled()) {
} }
@ -37,7 +38,7 @@ namespace dawn_native {
ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device, ProgrammablePassEncoder::ProgrammablePassEncoder(DeviceBase* device,
EncodingContext* encodingContext, EncodingContext* encodingContext,
ErrorTag errorTag) ErrorTag errorTag)
: ObjectBase(device, errorTag), : ApiObjectBase(device, errorTag),
mEncodingContext(encodingContext), mEncodingContext(encodingContext),
mValidationEnabled(device->IsValidationEnabled()) { mValidationEnabled(device->IsValidationEnabled()) {
} }

View File

@ -17,6 +17,7 @@
#include "dawn_native/CommandEncoder.h" #include "dawn_native/CommandEncoder.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/IntegerTypes.h" #include "dawn_native/IntegerTypes.h"
#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectBase.h"
@ -27,7 +28,7 @@ namespace dawn_native {
class DeviceBase; class DeviceBase;
// Base class for shared functionality between ComputePassEncoder and RenderPassEncoder. // Base class for shared functionality between ComputePassEncoder and RenderPassEncoder.
class ProgrammablePassEncoder : public ObjectBase { class ProgrammablePassEncoder : public ApiObjectBase {
public: public:
ProgrammablePassEncoder(DeviceBase* device, EncodingContext* encodingContext); ProgrammablePassEncoder(DeviceBase* device, EncodingContext* encodingContext);

View File

@ -16,6 +16,7 @@
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/Extensions.h" #include "dawn_native/Extensions.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
#include <set> #include <set>
@ -114,7 +115,7 @@ namespace dawn_native {
} }
QuerySetBase::QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descriptor) QuerySetBase::QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descriptor)
: ObjectBase(device, kLabelNotImplemented), : ApiObjectBase(device, kLabelNotImplemented),
mQueryType(descriptor->type), mQueryType(descriptor->type),
mQueryCount(descriptor->count), mQueryCount(descriptor->count),
mState(QuerySetState::Available) { mState(QuerySetState::Available) {
@ -126,7 +127,7 @@ namespace dawn_native {
} }
QuerySetBase::QuerySetBase(DeviceBase* device, ObjectBase::ErrorTag tag) QuerySetBase::QuerySetBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag) { : ApiObjectBase(device, tag) {
} }
QuerySetBase::~QuerySetBase() { QuerySetBase::~QuerySetBase() {
@ -139,6 +140,10 @@ namespace dawn_native {
return new ErrorQuerySet(device); return new ErrorQuerySet(device);
} }
ObjectType QuerySetBase::GetType() const {
return ObjectType::QuerySet;
}
wgpu::QueryType QuerySetBase::GetQueryType() const { wgpu::QueryType QuerySetBase::GetQueryType() const {
return mQueryType; return mQueryType;
} }

View File

@ -25,12 +25,14 @@ namespace dawn_native {
MaybeError ValidateQuerySetDescriptor(DeviceBase* device, const QuerySetDescriptor* descriptor); MaybeError ValidateQuerySetDescriptor(DeviceBase* device, const QuerySetDescriptor* descriptor);
class QuerySetBase : public ObjectBase { class QuerySetBase : public ApiObjectBase {
public: public:
QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descriptor); QuerySetBase(DeviceBase* device, const QuerySetDescriptor* descriptor);
static QuerySetBase* MakeError(DeviceBase* device); static QuerySetBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
wgpu::QueryType GetQueryType() const; wgpu::QueryType GetQueryType() const;
uint32_t GetQueryCount() const; uint32_t GetQueryCount() const;
const std::vector<wgpu::PipelineStatisticName>& GetPipelineStatistics() const; const std::vector<wgpu::PipelineStatisticName>& GetPipelineStatistics() const;

View File

@ -24,6 +24,7 @@
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/DynamicUploader.h" #include "dawn_native/DynamicUploader.h"
#include "dawn_native/ExternalTexture.h" #include "dawn_native/ExternalTexture.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/QuerySet.h" #include "dawn_native/QuerySet.h"
#include "dawn_native/RenderPassEncoder.h" #include "dawn_native/RenderPassEncoder.h"
#include "dawn_native/RenderPipeline.h" #include "dawn_native/RenderPipeline.h"
@ -161,10 +162,11 @@ namespace dawn_native {
QueueBase::TaskInFlight::~TaskInFlight() { 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() { QueueBase::~QueueBase() {
@ -176,6 +178,10 @@ namespace dawn_native {
return new ErrorQueue(device); return new ErrorQueue(device);
} }
ObjectType QueueBase::GetType() const {
return ObjectType::Queue;
}
void QueueBase::APISubmit(uint32_t commandCount, CommandBufferBase* const* commands) { void QueueBase::APISubmit(uint32_t commandCount, CommandBufferBase* const* commands) {
SubmitInternal(commandCount, commands); SubmitInternal(commandCount, commands);

View File

@ -25,7 +25,7 @@
namespace dawn_native { namespace dawn_native {
class QueueBase : public ObjectBase { class QueueBase : public ApiObjectBase {
public: public:
struct TaskInFlight { struct TaskInFlight {
virtual ~TaskInFlight(); virtual ~TaskInFlight();
@ -33,9 +33,12 @@ namespace dawn_native {
virtual void HandleDeviceLoss() = 0; virtual void HandleDeviceLoss() = 0;
}; };
static QueueBase* MakeError(DeviceBase* device);
~QueueBase() override; ~QueueBase() override;
static QueueBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
// Dawn API // Dawn API
void APISubmit(uint32_t commandCount, CommandBufferBase* const* commands); void APISubmit(uint32_t commandCount, CommandBufferBase* const* commands);
void APIOnSubmittedWorkDone(uint64_t signalValue, void APIOnSubmittedWorkDone(uint64_t signalValue,

View File

@ -17,6 +17,7 @@
#include "common/BitSetIterator.h" #include "common/BitSetIterator.h"
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/RenderBundleEncoder.h" #include "dawn_native/RenderBundleEncoder.h"
namespace dawn_native { namespace dawn_native {
@ -26,7 +27,7 @@ namespace dawn_native {
Ref<AttachmentState> attachmentState, Ref<AttachmentState> attachmentState,
RenderPassResourceUsage resourceUsage, RenderPassResourceUsage resourceUsage,
IndirectDrawMetadata indirectDrawMetadata) IndirectDrawMetadata indirectDrawMetadata)
: ObjectBase(encoder->GetDevice(), kLabelNotImplemented), : ApiObjectBase(encoder->GetDevice(), kLabelNotImplemented),
mCommands(encoder->AcquireCommands()), mCommands(encoder->AcquireCommands()),
mIndirectDrawMetadata(std::move(indirectDrawMetadata)), mIndirectDrawMetadata(std::move(indirectDrawMetadata)),
mAttachmentState(std::move(attachmentState)), mAttachmentState(std::move(attachmentState)),
@ -43,7 +44,11 @@ namespace dawn_native {
} }
RenderBundleBase::RenderBundleBase(DeviceBase* device, ErrorTag errorTag) RenderBundleBase::RenderBundleBase(DeviceBase* device, ErrorTag errorTag)
: ObjectBase(device, errorTag) { : ApiObjectBase(device, errorTag) {
}
ObjectType RenderBundleBase::GetType() const {
return ObjectType::RenderBundle;
} }
CommandIterator* RenderBundleBase::GetCommands() { CommandIterator* RenderBundleBase::GetCommands() {

View File

@ -19,6 +19,7 @@
#include "dawn_native/AttachmentState.h" #include "dawn_native/AttachmentState.h"
#include "dawn_native/CommandAllocator.h" #include "dawn_native/CommandAllocator.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/IndirectDrawMetadata.h" #include "dawn_native/IndirectDrawMetadata.h"
#include "dawn_native/ObjectBase.h" #include "dawn_native/ObjectBase.h"
#include "dawn_native/PassResourceUsage.h" #include "dawn_native/PassResourceUsage.h"
@ -32,7 +33,7 @@ namespace dawn_native {
struct RenderBundleDescriptor; struct RenderBundleDescriptor;
class RenderBundleEncoder; class RenderBundleEncoder;
class RenderBundleBase : public ObjectBase { class RenderBundleBase : public ApiObjectBase {
public: public:
RenderBundleBase(RenderBundleEncoder* encoder, RenderBundleBase(RenderBundleEncoder* encoder,
const RenderBundleDescriptor* descriptor, const RenderBundleDescriptor* descriptor,
@ -42,6 +43,8 @@ namespace dawn_native {
static RenderBundleBase* MakeError(DeviceBase* device); static RenderBundleBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
CommandIterator* GetCommands(); CommandIterator* GetCommands();
const AttachmentState* GetAttachmentState() const; const AttachmentState* GetAttachmentState() const;

View File

@ -18,6 +18,7 @@
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/Format.h" #include "dawn_native/Format.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/RenderPipeline.h" #include "dawn_native/RenderPipeline.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
#include "dawn_platform/DawnPlatform.h" #include "dawn_platform/DawnPlatform.h"
@ -102,6 +103,10 @@ namespace dawn_native {
return new RenderBundleEncoder(device, ObjectBase::kError); return new RenderBundleEncoder(device, ObjectBase::kError);
} }
ObjectType RenderBundleEncoder::GetType() const {
return ObjectType::RenderBundleEncoder;
}
CommandIterator RenderBundleEncoder::AcquireCommands() { CommandIterator RenderBundleEncoder::AcquireCommands() {
return mBundleEncodingContext.AcquireCommands(); return mBundleEncodingContext.AcquireCommands();
} }

View File

@ -17,6 +17,7 @@
#include "dawn_native/EncodingContext.h" #include "dawn_native/EncodingContext.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/RenderBundle.h" #include "dawn_native/RenderBundle.h"
#include "dawn_native/RenderEncoderBase.h" #include "dawn_native/RenderEncoderBase.h"
@ -32,6 +33,8 @@ namespace dawn_native {
const RenderBundleEncoderDescriptor* descriptor); const RenderBundleEncoderDescriptor* descriptor);
static RenderBundleEncoder* MakeError(DeviceBase* device); static RenderBundleEncoder* MakeError(DeviceBase* device);
ObjectType GetType() const override;
RenderBundleBase* APIFinish(const RenderBundleDescriptor* descriptor); RenderBundleBase* APIFinish(const RenderBundleDescriptor* descriptor);
CommandIterator AcquireCommands(); CommandIterator AcquireCommands();

View File

@ -20,6 +20,7 @@
#include "dawn_native/CommandValidation.h" #include "dawn_native/CommandValidation.h"
#include "dawn_native/Commands.h" #include "dawn_native/Commands.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/QuerySet.h" #include "dawn_native/QuerySet.h"
#include "dawn_native/RenderBundle.h" #include "dawn_native/RenderBundle.h"
#include "dawn_native/RenderPipeline.h" #include "dawn_native/RenderPipeline.h"
@ -77,6 +78,10 @@ namespace dawn_native {
return new RenderPassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError); return new RenderPassEncoder(device, commandEncoder, encodingContext, ObjectBase::kError);
} }
ObjectType RenderPassEncoder::GetType() const {
return ObjectType::RenderPassEncoder;
}
void RenderPassEncoder::TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex) { void RenderPassEncoder::TrackQueryAvailability(QuerySetBase* querySet, uint32_t queryIndex) {
DAWN_ASSERT(querySet != nullptr); DAWN_ASSERT(querySet != nullptr);

View File

@ -16,6 +16,7 @@
#define DAWNNATIVE_RENDERPASSENCODER_H_ #define DAWNNATIVE_RENDERPASSENCODER_H_
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/RenderEncoderBase.h" #include "dawn_native/RenderEncoderBase.h"
namespace dawn_native { namespace dawn_native {
@ -37,6 +38,8 @@ namespace dawn_native {
CommandEncoder* commandEncoder, CommandEncoder* commandEncoder,
EncodingContext* encodingContext); EncodingContext* encodingContext);
ObjectType GetType() const override;
void APIEndPass(); void APIEndPass();
void APISetStencilReference(uint32_t reference); void APISetStencilReference(uint32_t reference);

View File

@ -20,6 +20,7 @@
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/InternalPipelineStore.h" #include "dawn_native/InternalPipelineStore.h"
#include "dawn_native/ObjectContentHasher.h" #include "dawn_native/ObjectContentHasher.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
#include "dawn_native/VertexFormat.h" #include "dawn_native/VertexFormat.h"
@ -559,6 +560,10 @@ namespace dawn_native {
return new RenderPipelineBase(device, ObjectBase::kError); return new RenderPipelineBase(device, ObjectBase::kError);
} }
ObjectType RenderPipelineBase::GetType() const {
return ObjectType::RenderPipeline;
}
RenderPipelineBase::~RenderPipelineBase() { RenderPipelineBase::~RenderPipelineBase() {
if (IsCachedReference()) { if (IsCachedReference()) {
GetDevice()->UncacheRenderPipeline(this); GetDevice()->UncacheRenderPipeline(this);

View File

@ -17,6 +17,7 @@
#include "common/TypedInteger.h" #include "common/TypedInteger.h"
#include "dawn_native/AttachmentState.h" #include "dawn_native/AttachmentState.h"
#include "dawn_native/Forward.h"
#include "dawn_native/IntegerTypes.h" #include "dawn_native/IntegerTypes.h"
#include "dawn_native/Pipeline.h" #include "dawn_native/Pipeline.h"
@ -62,6 +63,8 @@ namespace dawn_native {
static RenderPipelineBase* MakeError(DeviceBase* device); static RenderPipelineBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
const ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes>& const ityp::bitset<VertexAttributeLocation, kMaxVertexAttributes>&
GetAttributeLocationsUsed() const; GetAttributeLocationsUsed() const;
const VertexAttributeInfo& GetAttribute(VertexAttributeLocation location) const; const VertexAttributeInfo& GetAttribute(VertexAttributeLocation location) const;

View File

@ -72,7 +72,7 @@ namespace dawn_native {
// SamplerBase // SamplerBase
SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor) SamplerBase::SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor)
: CachedObject(device, kLabelNotImplemented), : ApiObjectBase(device, kLabelNotImplemented),
mAddressModeU(descriptor->addressModeU), mAddressModeU(descriptor->addressModeU),
mAddressModeV(descriptor->addressModeV), mAddressModeV(descriptor->addressModeV),
mAddressModeW(descriptor->addressModeW), mAddressModeW(descriptor->addressModeW),
@ -86,7 +86,7 @@ namespace dawn_native {
} }
SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag) SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: CachedObject(device, tag) { : ApiObjectBase(device, tag) {
} }
SamplerBase::~SamplerBase() { SamplerBase::~SamplerBase() {
@ -100,6 +100,10 @@ namespace dawn_native {
return new SamplerBase(device, ObjectBase::kError); return new SamplerBase(device, ObjectBase::kError);
} }
ObjectType SamplerBase::GetType() const {
return ObjectType::Sampler;
}
bool SamplerBase::IsComparison() const { bool SamplerBase::IsComparison() const {
return mCompareFunction != wgpu::CompareFunction::Undefined; return mCompareFunction != wgpu::CompareFunction::Undefined;
} }

View File

@ -17,6 +17,8 @@
#include "dawn_native/CachedObject.h" #include "dawn_native/CachedObject.h"
#include "dawn_native/Error.h" #include "dawn_native/Error.h"
#include "dawn_native/Forward.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -26,13 +28,15 @@ namespace dawn_native {
MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor); MaybeError ValidateSamplerDescriptor(DeviceBase* device, const SamplerDescriptor* descriptor);
class SamplerBase : public CachedObject { class SamplerBase : public ApiObjectBase, public CachedObject {
public: public:
SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor); SamplerBase(DeviceBase* device, const SamplerDescriptor* descriptor);
~SamplerBase() override; ~SamplerBase() override;
static SamplerBase* MakeError(DeviceBase* device); static SamplerBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
bool IsComparison() const; bool IsComparison() const;
bool IsFiltering() const; bool IsFiltering() const;

View File

@ -1139,7 +1139,7 @@ namespace dawn_native {
// ShaderModuleBase // ShaderModuleBase
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor) 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); ASSERT(descriptor->nextInChain != nullptr);
const ShaderModuleSPIRVDescriptor* spirvDesc = nullptr; const ShaderModuleSPIRVDescriptor* spirvDesc = nullptr;
FindInChain(descriptor->nextInChain, &spirvDesc); FindInChain(descriptor->nextInChain, &spirvDesc);
@ -1157,7 +1157,7 @@ namespace dawn_native {
} }
ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag) ShaderModuleBase::ShaderModuleBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: CachedObject(device, tag), mType(Type::Undefined) { : ApiObjectBase(device, tag), mType(Type::Undefined) {
} }
ShaderModuleBase::~ShaderModuleBase() { ShaderModuleBase::~ShaderModuleBase() {
@ -1171,6 +1171,10 @@ namespace dawn_native {
return AcquireRef(new ShaderModuleBase(device, ObjectBase::kError)); return AcquireRef(new ShaderModuleBase(device, ObjectBase::kError));
} }
ObjectType ShaderModuleBase::GetType() const {
return ObjectType::ShaderModule;
}
bool ShaderModuleBase::HasEntryPoint(const std::string& entryPoint) const { bool ShaderModuleBase::HasEntryPoint(const std::string& entryPoint) const {
return mEntryPoints.count(entryPoint) > 0; return mEntryPoints.count(entryPoint) > 0;
} }

View File

@ -24,6 +24,7 @@
#include "dawn_native/Format.h" #include "dawn_native/Format.h"
#include "dawn_native/Forward.h" #include "dawn_native/Forward.h"
#include "dawn_native/IntegerTypes.h" #include "dawn_native/IntegerTypes.h"
#include "dawn_native/ObjectBase.h"
#include "dawn_native/PerStage.h" #include "dawn_native/PerStage.h"
#include "dawn_native/VertexFormat.h" #include "dawn_native/VertexFormat.h"
#include "dawn_native/dawn_platform.h" #include "dawn_native/dawn_platform.h"
@ -195,13 +196,15 @@ namespace dawn_native {
SingleShaderStage stage; SingleShaderStage stage;
}; };
class ShaderModuleBase : public CachedObject { class ShaderModuleBase : public ApiObjectBase, public CachedObject {
public: public:
ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor); ShaderModuleBase(DeviceBase* device, const ShaderModuleDescriptor* descriptor);
~ShaderModuleBase() override; ~ShaderModuleBase() override;
static Ref<ShaderModuleBase> MakeError(DeviceBase* device); static Ref<ShaderModuleBase> MakeError(DeviceBase* device);
ObjectType GetType() const override;
// Return true iff the program has an entrypoint called `entryPoint`. // Return true iff the program has an entrypoint called `entryPoint`.
bool HasEntryPoint(const std::string& entryPoint) const; bool HasEntryPoint(const std::string& entryPoint) const;

View File

@ -17,6 +17,7 @@
#include "common/Constants.h" #include "common/Constants.h"
#include "dawn_native/Adapter.h" #include "dawn_native/Adapter.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/Surface.h" #include "dawn_native/Surface.h"
#include "dawn_native/Texture.h" #include "dawn_native/Texture.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
@ -112,11 +113,11 @@ namespace dawn_native {
// SwapChainBase // SwapChainBase
SwapChainBase::SwapChainBase(DeviceBase* device) : ObjectBase(device, kLabelNotImplemented) { SwapChainBase::SwapChainBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {
} }
SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag) SwapChainBase::SwapChainBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag) { : ApiObjectBase(device, tag) {
} }
SwapChainBase::~SwapChainBase() { SwapChainBase::~SwapChainBase() {
@ -127,6 +128,10 @@ namespace dawn_native {
return new ErrorSwapChain(device); return new ErrorSwapChain(device);
} }
ObjectType SwapChainBase::GetType() const {
return ObjectType::SwapChain;
}
// OldSwapChainBase // OldSwapChainBase
OldSwapChainBase::OldSwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor) OldSwapChainBase::OldSwapChainBase(DeviceBase* device, const SwapChainDescriptor* descriptor)

View File

@ -30,12 +30,14 @@ namespace dawn_native {
TextureDescriptor GetSwapChainBaseTextureDescriptor(NewSwapChainBase* swapChain); TextureDescriptor GetSwapChainBaseTextureDescriptor(NewSwapChainBase* swapChain);
class SwapChainBase : public ObjectBase { class SwapChainBase : public ApiObjectBase {
public: public:
SwapChainBase(DeviceBase* device); SwapChainBase(DeviceBase* device);
static SwapChainBase* MakeError(DeviceBase* device); static SwapChainBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
// Dawn API // Dawn API
virtual void APIConfigure(wgpu::TextureFormat format, virtual void APIConfigure(wgpu::TextureFormat format,
wgpu::TextureUsage allowedUsage, wgpu::TextureUsage allowedUsage,

View File

@ -23,6 +23,7 @@
#include "dawn_native/ChainUtils_autogen.h" #include "dawn_native/ChainUtils_autogen.h"
#include "dawn_native/Device.h" #include "dawn_native/Device.h"
#include "dawn_native/EnumMaskIterator.h" #include "dawn_native/EnumMaskIterator.h"
#include "dawn_native/ObjectType_autogen.h"
#include "dawn_native/PassResourceUsage.h" #include "dawn_native/PassResourceUsage.h"
#include "dawn_native/ValidationUtils_autogen.h" #include "dawn_native/ValidationUtils_autogen.h"
@ -445,7 +446,7 @@ namespace dawn_native {
TextureBase::TextureBase(DeviceBase* device, TextureBase::TextureBase(DeviceBase* device,
const TextureDescriptor* descriptor, const TextureDescriptor* descriptor,
TextureState state) TextureState state)
: ObjectBase(device, descriptor->label), : ApiObjectBase(device, descriptor->label),
mDimension(descriptor->dimension), mDimension(descriptor->dimension),
mFormat(device->GetValidInternalFormat(descriptor->format)), mFormat(device->GetValidInternalFormat(descriptor->format)),
mSize(descriptor->size), mSize(descriptor->size),
@ -468,7 +469,7 @@ namespace dawn_native {
static Format kUnusedFormat; static Format kUnusedFormat;
TextureBase::TextureBase(DeviceBase* device, ObjectBase::ErrorTag tag) TextureBase::TextureBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag), mFormat(kUnusedFormat) { : ApiObjectBase(device, tag), mFormat(kUnusedFormat) {
} }
// static // static
@ -476,6 +477,10 @@ namespace dawn_native {
return new TextureBase(device, ObjectBase::kError); return new TextureBase(device, ObjectBase::kError);
} }
ObjectType TextureBase::GetType() const {
return ObjectType::Texture;
}
wgpu::TextureDimension TextureBase::GetDimension() const { wgpu::TextureDimension TextureBase::GetDimension() const {
ASSERT(!IsError()); ASSERT(!IsError());
return mDimension; return mDimension;
@ -684,7 +689,7 @@ namespace dawn_native {
// TextureViewBase // TextureViewBase
TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor) TextureViewBase::TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor)
: ObjectBase(texture->GetDevice(), kLabelNotImplemented), : ApiObjectBase(texture->GetDevice(), kLabelNotImplemented),
mTexture(texture), mTexture(texture),
mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)), mFormat(GetDevice()->GetValidInternalFormat(descriptor->format)),
mDimension(descriptor->dimension), mDimension(descriptor->dimension),
@ -694,7 +699,7 @@ namespace dawn_native {
} }
TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag) TextureViewBase::TextureViewBase(DeviceBase* device, ObjectBase::ErrorTag tag)
: ObjectBase(device, tag), mFormat(kUnusedFormat) { : ApiObjectBase(device, tag), mFormat(kUnusedFormat) {
} }
// static // static
@ -702,6 +707,10 @@ namespace dawn_native {
return new TextureViewBase(device, ObjectBase::kError); return new TextureViewBase(device, ObjectBase::kError);
} }
ObjectType TextureViewBase::GetType() const {
return ObjectType::TextureView;
}
const TextureBase* TextureViewBase::GetTexture() const { const TextureBase* TextureViewBase::GetTexture() const {
ASSERT(!IsError()); ASSERT(!IsError());
return mTexture.Get(); return mTexture.Get();

View File

@ -42,7 +42,7 @@ namespace dawn_native {
static constexpr wgpu::TextureUsage kReadOnlyTextureUsages = static constexpr wgpu::TextureUsage kReadOnlyTextureUsages =
wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding; wgpu::TextureUsage::CopySrc | wgpu::TextureUsage::TextureBinding;
class TextureBase : public ObjectBase { class TextureBase : public ApiObjectBase {
public: public:
enum class TextureState { OwnedInternal, OwnedExternal, Destroyed }; enum class TextureState { OwnedInternal, OwnedExternal, Destroyed };
enum class ClearValue { Zero, NonZero }; enum class ClearValue { Zero, NonZero };
@ -50,6 +50,8 @@ namespace dawn_native {
static TextureBase* MakeError(DeviceBase* device); static TextureBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
wgpu::TextureDimension GetDimension() const; wgpu::TextureDimension GetDimension() const;
const Format& GetFormat() const; const Format& GetFormat() const;
const Extent3D& GetSize() const; const Extent3D& GetSize() const;
@ -113,12 +115,14 @@ namespace dawn_native {
std::vector<bool> mIsSubresourceContentInitializedAtIndex; std::vector<bool> mIsSubresourceContentInitializedAtIndex;
}; };
class TextureViewBase : public ObjectBase { class TextureViewBase : public ApiObjectBase {
public: public:
TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor); TextureViewBase(TextureBase* texture, const TextureViewDescriptor* descriptor);
static TextureViewBase* MakeError(DeviceBase* device); static TextureViewBase* MakeError(DeviceBase* device);
ObjectType GetType() const override;
const TextureBase* GetTexture() const; const TextureBase* GetTexture() const;
TextureBase* GetTexture(); TextureBase* GetTexture();