Enable Queue, Device labels to be set. (Take 2)

Queue labels can be set by the defaultQueue.label member of the device
descriptor or the setQueue method.

Device labels can be set label member of the device
descriptor or the setQueue method.

D3D12 and VK backend label support included.

Bug: dawn:1323
Change-Id: Ic44f1fac268c20d5338220eaf959d949a5f66536
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/85843
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Brandon Jones <bajones@chromium.org>
This commit is contained in:
Brandon Jones 2022-04-12 03:28:40 +00:00 committed by Dawn LUCI CQ
parent 1ed28fbdfd
commit 8085367233
24 changed files with 168 additions and 68 deletions

View File

@ -153,7 +153,7 @@
{"name": "required features count", "type": "uint32_t", "default": 0},
{"name": "required features", "type": "feature name", "annotation": "const*", "length": "required features count", "default": "nullptr"},
{"name": "required limits", "type": "required limits", "annotation": "const*", "optional": true},
{"name": "default queue", "type": "queue descriptor", "tags": ["upstream"]}
{"name": "default queue", "type": "queue descriptor"}
]
},
"dawn toggles device descriptor": {
@ -203,8 +203,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -239,8 +237,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -431,8 +427,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -527,8 +521,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -670,8 +662,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -833,8 +823,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -1152,6 +1140,13 @@
{"name": "callback", "type": "error callback"},
{"name": "userdata", "type": "void", "annotation": "*"}
]
},
{
"name": "set label",
"returns": "void",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
}
]
},
@ -1303,8 +1298,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -1500,8 +1493,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -1577,8 +1568,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -1663,13 +1652,19 @@
{"name": "copy size", "type": "extent 3D", "annotation": "const*"},
{"name": "options", "type": "copy texture for browser options", "annotation": "const*"}
]
},
{
"name": "set label",
"returns": "void",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
}
]
},
"queue descriptor": {
"category": "structure",
"extensible": "in",
"tags": ["upstream"],
"members": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen", "optional": true}
]
@ -1791,8 +1786,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -2027,8 +2020,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -2210,8 +2201,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -2486,8 +2475,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]
@ -2692,8 +2679,6 @@
{
"name": "set label",
"returns": "void",
"tags": ["dawn"],
"_TODO": "needs an upstream equivalent",
"args": [
{"name": "label", "type": "char", "annotation": "const*", "length": "strlen"}
]

View File

@ -198,6 +198,10 @@ namespace dawn::native {
mFormatTable = BuildFormatTable(this);
SetDefaultToggles();
if (descriptor->label != nullptr && strlen(descriptor->label) != 0) {
mLabel = descriptor->label;
}
}
DeviceBase::DeviceBase() : mState(State::Alive) {
@ -210,8 +214,8 @@ namespace dawn::native {
mQueue = nullptr;
}
MaybeError DeviceBase::Initialize(QueueBase* defaultQueue) {
mQueue = AcquireRef(defaultQueue);
MaybeError DeviceBase::Initialize(Ref<QueueBase> defaultQueue) {
mQueue = std::move(defaultQueue);
#if defined(DAWN_ENABLE_ASSERTS)
mUncapturedErrorCallback = [](WGPUErrorType, char const*, void*) {

View File

@ -382,7 +382,7 @@ namespace dawn::native {
void SetToggle(Toggle toggle, bool isEnabled);
void ForceSetToggle(Toggle toggle, bool isEnabled);
MaybeError Initialize(QueueBase* defaultQueue);
MaybeError Initialize(Ref<QueueBase> defaultQueue);
void DestroyObjects();
void Destroy();

View File

@ -170,7 +170,8 @@ namespace dawn::native {
QueueBase::TaskInFlight::~TaskInFlight() {
}
QueueBase::QueueBase(DeviceBase* device) : ApiObjectBase(device, kLabelNotImplemented) {
QueueBase::QueueBase(DeviceBase* device, const QueueDescriptor* descriptor)
: ApiObjectBase(device, descriptor->label) {
}
QueueBase::QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag)

View File

@ -67,7 +67,7 @@ namespace dawn::native {
void HandleDeviceLoss();
protected:
QueueBase(DeviceBase* device);
QueueBase(DeviceBase* device, const QueueDescriptor* descriptor);
QueueBase(DeviceBase* device, ObjectBase::ErrorTag tag);
void DestroyImpl() override;

View File

@ -59,11 +59,11 @@ namespace dawn::native::d3d12 {
ResultOrError<Ref<Device>> Device::Create(Adapter* adapter,
const DeviceDescriptor* descriptor) {
Ref<Device> device = AcquireRef(new Device(adapter, descriptor));
DAWN_TRY(device->Initialize());
DAWN_TRY(device->Initialize(descriptor));
return device;
}
MaybeError Device::Initialize() {
MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
InitTogglesFromDriver();
mD3d12Device = ToBackend(GetAdapter())->GetDevice();
@ -163,7 +163,7 @@ namespace dawn::native::d3d12 {
GetD3D12Device()->CreateCommandSignature(&programDesc, NULL,
IID_PPV_ARGS(&mDrawIndexedIndirectSignature));
DAWN_TRY(DeviceBase::Initialize(new Queue(this)));
DAWN_TRY(DeviceBase::Initialize(Queue::Create(this, &descriptor->defaultQueue)));
// Device shouldn't be used until after DeviceBase::Initialize so we must wait until after
// device initialization to call NextSerial
DAWN_TRY(NextSerial());
@ -174,6 +174,8 @@ namespace dawn::native::d3d12 {
DAWN_TRY(CreateZeroBuffer());
SetLabelImpl();
return {};
}
@ -741,4 +743,8 @@ namespace dawn::native::d3d12 {
return ToBackend(computePipeline)->UsesNumWorkgroups();
}
void Device::SetLabelImpl() {
SetDebugName(this, mD3d12Device.Get(), "Dawn_Device", GetLabel());
}
} // namespace dawn::native::d3d12

View File

@ -45,7 +45,7 @@ namespace dawn::native::d3d12 {
const DeviceDescriptor* descriptor);
~Device() override;
MaybeError Initialize();
MaybeError Initialize(const DeviceDescriptor* descriptor);
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
@ -147,6 +147,9 @@ namespace dawn::native::d3d12 {
bool ShouldDuplicateNumWorkgroupsForDispatchIndirect(
ComputePipelineBase* computePipeline) const override;
// Dawn API
void SetLabelImpl() override;
private:
using DeviceBase::DeviceBase;

View File

@ -21,12 +21,25 @@
#include "dawn/native/d3d12/CommandBufferD3D12.h"
#include "dawn/native/d3d12/D3D12Error.h"
#include "dawn/native/d3d12/DeviceD3D12.h"
#include "dawn/native/d3d12/UtilsD3D12.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/tracing/TraceEvent.h"
namespace dawn::native::d3d12 {
Queue::Queue(Device* device) : QueueBase(device) {
// static
Ref<Queue> Queue::Create(Device* device, const QueueDescriptor* descriptor) {
Ref<Queue> queue = AcquireRef(new Queue(device, descriptor));
queue->Initialize();
return queue;
}
Queue::Queue(Device* device, const QueueDescriptor* descriptor)
: QueueBase(device, descriptor) {
}
void Queue::Initialize() {
SetLabelImpl();
}
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
@ -51,4 +64,11 @@ namespace dawn::native::d3d12 {
return {};
}
void Queue::SetLabelImpl() {
Device* device = ToBackend(GetDevice());
// TODO(crbug.com/dawn/1344): When we start using multiple queues this needs to be adjusted
// so it doesn't always change the default queue's label.
SetDebugName(device, device->GetCommandQueue().Get(), "Dawn_Queue", GetLabel());
}
} // namespace dawn::native::d3d12

View File

@ -26,10 +26,17 @@ namespace dawn::native::d3d12 {
class Queue final : public QueueBase {
public:
Queue(Device* device);
static Ref<Queue> Create(Device* device, const QueueDescriptor* descriptor);
private:
Queue(Device* device, const QueueDescriptor* descriptor);
void Initialize();
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
// Dawn API
void SetLabelImpl() override;
};
} // namespace dawn::native::d3d12

View File

@ -43,7 +43,7 @@ namespace dawn::native::metal {
const DeviceDescriptor* descriptor);
~Device() override;
MaybeError Initialize();
MaybeError Initialize(const DeviceDescriptor* descriptor);
MaybeError TickImpl() override;

View File

@ -110,7 +110,7 @@ namespace dawn::native::metal {
NSPRef<id<MTLDevice>> mtlDevice,
const DeviceDescriptor* descriptor) {
Ref<Device> device = AcquireRef(new Device(adapter, std::move(mtlDevice), descriptor));
DAWN_TRY(device->Initialize());
DAWN_TRY(device->Initialize(descriptor));
return device;
}
@ -124,7 +124,7 @@ namespace dawn::native::metal {
Destroy();
}
MaybeError Device::Initialize() {
MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
InitTogglesFromDriver();
mCommandQueue.Acquire([*mMtlDevice newCommandQueue]);
@ -155,7 +155,7 @@ namespace dawn::native::metal {
}
}
return DeviceBase::Initialize(new Queue(this));
return DeviceBase::Initialize(AcquireRef(new Queue(this, &descriptor->defaultQueue)));
}
void Device::InitTogglesFromDriver() {

View File

@ -23,7 +23,7 @@ namespace dawn::native::metal {
class Queue final : public QueueBase {
public:
Queue(Device* device);
Queue(Device* device, const QueueDescriptor* descriptor);
private:
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;

View File

@ -26,7 +26,8 @@
namespace dawn::native::metal {
Queue::Queue(Device* device) : QueueBase(device) {
Queue::Queue(Device* device, const QueueDescriptor* descriptor)
: QueueBase(device, descriptor) {
}
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {

View File

@ -103,7 +103,7 @@ namespace dawn::native::null {
ResultOrError<Ref<Device>> Device::Create(Adapter* adapter,
const DeviceDescriptor* descriptor) {
Ref<Device> device = AcquireRef(new Device(adapter, descriptor));
DAWN_TRY(device->Initialize());
DAWN_TRY(device->Initialize(descriptor));
return device;
}
@ -111,8 +111,8 @@ namespace dawn::native::null {
Destroy();
}
MaybeError Device::Initialize() {
return DeviceBase::Initialize(new Queue(this));
MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
return DeviceBase::Initialize(AcquireRef(new Queue(this, &descriptor->defaultQueue)));
}
ResultOrError<Ref<BindGroupBase>> Device::CreateBindGroupImpl(
@ -354,7 +354,8 @@ namespace dawn::native::null {
// Queue
Queue::Queue(Device* device) : QueueBase(device) {
Queue::Queue(Device* device, const QueueDescriptor* descriptor)
: QueueBase(device, descriptor) {
}
Queue::~Queue() {

View File

@ -90,7 +90,7 @@ namespace dawn::native::null {
const DeviceDescriptor* descriptor);
~Device() override;
MaybeError Initialize();
MaybeError Initialize(const DeviceDescriptor* descriptor);
ResultOrError<Ref<CommandBufferBase>> CreateCommandBuffer(
CommandEncoder* encoder,
@ -250,7 +250,7 @@ namespace dawn::native::null {
class Queue final : public QueueBase {
public:
Queue(Device* device);
Queue(Device* device, const QueueDescriptor* descriptor);
private:
~Queue() override;

View File

@ -39,7 +39,7 @@ namespace dawn::native::opengl {
const DeviceDescriptor* descriptor,
const OpenGLFunctions& functions) {
Ref<Device> device = AcquireRef(new Device(adapter, descriptor, functions));
DAWN_TRY(device->Initialize());
DAWN_TRY(device->Initialize(descriptor));
return device;
}
@ -53,11 +53,11 @@ namespace dawn::native::opengl {
Destroy();
}
MaybeError Device::Initialize() {
MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
InitTogglesFromDriver();
mFormatTable = BuildGLFormatTable();
return DeviceBase::Initialize(new Queue(this));
return DeviceBase::Initialize(AcquireRef(new Queue(this, &descriptor->defaultQueue)));
}
void Device::InitTogglesFromDriver() {

View File

@ -42,7 +42,7 @@ namespace dawn::native::opengl {
const OpenGLFunctions& functions);
~Device() override;
MaybeError Initialize();
MaybeError Initialize(const DeviceDescriptor* descriptor);
// Contains all the OpenGL entry points, glDoFoo is called via device->gl.DoFoo.
const OpenGLFunctions gl;

View File

@ -23,7 +23,8 @@
namespace dawn::native::opengl {
Queue::Queue(Device* device) : QueueBase(device) {
Queue::Queue(Device* device, const QueueDescriptor* descriptor)
: QueueBase(device, descriptor) {
}
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {

View File

@ -23,7 +23,7 @@ namespace dawn::native::opengl {
class Queue final : public QueueBase {
public:
Queue(Device* device);
Queue(Device* device, const QueueDescriptor* descriptor);
private:
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;

View File

@ -48,7 +48,7 @@ namespace dawn::native::vulkan {
ResultOrError<Ref<Device>> Device::Create(Adapter* adapter,
const DeviceDescriptor* descriptor) {
Ref<Device> device = AcquireRef(new Device(adapter, descriptor));
DAWN_TRY(device->Initialize());
DAWN_TRY(device->Initialize(descriptor));
return device;
}
@ -57,7 +57,7 @@ namespace dawn::native::vulkan {
InitTogglesFromDriver();
}
MaybeError Device::Initialize() {
MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
// Copy the adapter's device info to the device so that we can change the "knobs"
mDeviceInfo = ToBackend(GetAdapter())->GetDeviceInfo();
@ -101,7 +101,9 @@ namespace dawn::native::vulkan {
// extension is available. Override the decision if it is no applicable.
ApplyUseZeroInitializeWorkgroupMemoryExtensionToggle();
return DeviceBase::Initialize(Queue::Create(this));
SetLabelImpl();
return DeviceBase::Initialize(Queue::Create(this, &descriptor->defaultQueue));
}
Device::~Device() {
@ -1050,4 +1052,12 @@ namespace dawn::native::vulkan {
return mDeviceInfo.properties.limits.timestampPeriod;
}
void Device::SetLabelImpl() {
// VKDevice reinterpret_casts to a uint64_t rather than a uint64_t& like most other types
// because it's a dispatchable handle, and thus doesn't have the VkHandle wrapper that
// Dawn creates for anything defined with VK_DEFINE_NON_DISPATCHABLE_HANDLE.
SetDebugName(this, VK_OBJECT_TYPE_DEVICE, reinterpret_cast<uint64_t>(mVkDevice),
"Dawn_Device", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -47,7 +47,7 @@ namespace dawn::native::vulkan {
const DeviceDescriptor* descriptor);
~Device() override;
MaybeError Initialize();
MaybeError Initialize(const DeviceDescriptor* descriptor);
// Contains all the Vulkan entry points, vkDoFoo is called via device->fn.DoFoo.
const VulkanFunctions fn;
@ -105,6 +105,8 @@ namespace dawn::native::vulkan {
float GetTimestampPeriodInNS() const override;
void SetLabelImpl() override;
private:
Device(Adapter* adapter, const DeviceDescriptor* descriptor);

View File

@ -22,22 +22,30 @@
#include "dawn/native/vulkan/CommandBufferVk.h"
#include "dawn/native/vulkan/CommandRecordingContext.h"
#include "dawn/native/vulkan/DeviceVk.h"
#include "dawn/native/vulkan/UtilsVulkan.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/tracing/TraceEvent.h"
namespace dawn::native::vulkan {
// static
Queue* Queue::Create(Device* device) {
return new Queue(device);
Ref<Queue> Queue::Create(Device* device, const QueueDescriptor* descriptor) {
Ref<Queue> queue = AcquireRef(new Queue(device, descriptor));
queue->Initialize();
return queue;
}
Queue::Queue(Device* device) : QueueBase(device) {
Queue::Queue(Device* device, const QueueDescriptor* descriptor)
: QueueBase(device, descriptor) {
}
Queue::~Queue() {
}
void Queue::Initialize() {
SetLabelImpl();
}
MaybeError Queue::SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) {
Device* device = ToBackend(GetDevice());
@ -56,4 +64,16 @@ namespace dawn::native::vulkan {
return {};
}
void Queue::SetLabelImpl() {
Device* device = ToBackend(GetDevice());
// VKDevice reinterpret_casts to a uint64_t rather than a uint64_t& like most other types
// because it's a dispatchable handle, and thus doesn't have the VkHandle wrapper that
// Dawn creates for anything defined with VK_DEFINE_NON_DISPATCHABLE_HANDLE.
// TODO(crbug.com/dawn/1344): When we start using multiple queues this needs to be adjusted
// so it doesn't always change the default queue's label.
SetDebugName(device, VK_OBJECT_TYPE_QUEUE, reinterpret_cast<uint64_t>(device->GetQueue()),
"Dawn_Queue", GetLabel());
}
} // namespace dawn::native::vulkan

View File

@ -23,14 +23,19 @@ namespace dawn::native::vulkan {
class Queue final : public QueueBase {
public:
static Queue* Create(Device* device);
static Ref<Queue> Create(Device* device, const QueueDescriptor* descriptor);
private:
Queue(Device* device);
Queue(Device* device, const QueueDescriptor* descriptor);
~Queue() override;
using QueueBase::QueueBase;
void Initialize();
MaybeError SubmitImpl(uint32_t commandCount, CommandBufferBase* const* commands) override;
// Dawn API
void SetLabelImpl() override;
};
} // namespace dawn::native::vulkan

View File

@ -318,6 +318,40 @@ TEST_F(LabelTest, QuerySet) {
}
}
TEST_F(LabelTest, Queue) {
DAWN_SKIP_TEST_IF(UsesWire());
std::string label = "test";
// The label should be empty if one was not set.
{
wgpu::DeviceDescriptor descriptor;
wgpu::Device labelDevice = adapter.CreateDevice(&descriptor);
std::string readbackLabel =
dawn::native::GetObjectLabelForTesting(labelDevice.GetQueue().Get());
ASSERT_TRUE(readbackLabel.empty());
}
// Test setting a label through API
{
wgpu::DeviceDescriptor descriptor;
wgpu::Device labelDevice = adapter.CreateDevice(&descriptor);
labelDevice.GetQueue().SetLabel(label.c_str());
std::string readbackLabel =
dawn::native::GetObjectLabelForTesting(labelDevice.GetQueue().Get());
ASSERT_EQ(label, readbackLabel);
}
// Test setting a label through the descriptor.
{
wgpu::DeviceDescriptor descriptor;
descriptor.defaultQueue.label = label.c_str();
wgpu::Device labelDevice = adapter.CreateDevice(&descriptor);
std::string readbackLabel =
dawn::native::GetObjectLabelForTesting(labelDevice.GetQueue().Get());
ASSERT_EQ(label, readbackLabel);
}
}
TEST_F(LabelTest, RenderBundleEncoder) {
DAWN_SKIP_TEST_IF(UsesWire());
std::string label = "test";