Add Debug Tracing in Dawn

Add more trace event in Dawn to better understand workflow in Dawn.
These trace events focus on tick() and MapAsync() related in flight
task.

Bug: dawn:1335
Change-Id: Iac35959f315c221c8539137efbf35039458a6f77
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86620
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shaobo Yan <shaobo.yan@intel.com>
This commit is contained in:
Shaobo 2022-04-19 00:25:34 +00:00 committed by Dawn LUCI CQ
parent c373a87542
commit e4c799071b
8 changed files with 40 additions and 8 deletions

View File

@ -23,6 +23,8 @@
#include "dawn/native/ObjectType_autogen.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"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/tracing/TraceEvent.h"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
@ -35,7 +37,9 @@ namespace dawn::native {
MapRequestTask(Ref<BufferBase> buffer, MapRequestID id) MapRequestTask(Ref<BufferBase> buffer, MapRequestID id)
: buffer(std::move(buffer)), id(id) { : buffer(std::move(buffer)), id(id) {
} }
void Finish() override { void Finish(dawn::platform::Platform* platform, ExecutionSerial serial) override {
TRACE_EVENT1(platform, General, "Buffer::TaskInFlight::Finished", "serial",
uint64_t(serial));
buffer->OnMapRequestCompleted(id, WGPUBufferMapAsyncStatus_Success); buffer->OnMapRequestCompleted(id, WGPUBufferMapAsyncStatus_Success);
} }
void HandleDeviceLoss() override { void HandleDeviceLoss() override {
@ -350,6 +354,8 @@ namespace dawn::native {
} }
std::unique_ptr<MapRequestTask> request = std::unique_ptr<MapRequestTask> request =
std::make_unique<MapRequestTask>(this, mLastMapID); std::make_unique<MapRequestTask>(this, mLastMapID);
TRACE_EVENT1(GetDevice()->GetPlatform(), General, "Buffer::APIMapAsync", "serial",
uint64_t(GetDevice()->GetPendingCommandSerial()));
GetDevice()->GetQueue()->TrackTask(std::move(request), GetDevice()->GetQueue()->TrackTask(std::move(request),
GetDevice()->GetPendingCommandSerial()); GetDevice()->GetPendingCommandSerial());
} }

View File

@ -1158,6 +1158,10 @@ namespace dawn::native {
if (IsLost() || ConsumedError(Tick())) { if (IsLost() || ConsumedError(Tick())) {
return false; return false;
} }
TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APITick::IsDeviceIdle", "isDeviceIdle",
IsDeviceIdle());
return !IsDeviceIdle(); return !IsDeviceIdle();
} }

View File

@ -135,8 +135,10 @@ namespace dawn::native {
SubmittedWorkDone(WGPUQueueWorkDoneCallback callback, void* userdata) SubmittedWorkDone(WGPUQueueWorkDoneCallback callback, void* userdata)
: mCallback(callback), mUserdata(userdata) { : mCallback(callback), mUserdata(userdata) {
} }
void Finish() override { void Finish(dawn::platform::Platform* platform, ExecutionSerial serial) override {
ASSERT(mCallback != nullptr); ASSERT(mCallback != nullptr);
TRACE_EVENT1(platform, General, "Queue::SubmittedWorkDone::Finished", "serial",
uint64_t(serial));
mCallback(WGPUQueueWorkDoneStatus_Success, mUserdata); mCallback(WGPUQueueWorkDoneStatus_Success, mUserdata);
mCallback = nullptr; mCallback = nullptr;
} }
@ -220,6 +222,9 @@ namespace dawn::native {
// commands (this is non-observable outside of tests so it's ok to do deviate a bit from the // commands (this is non-observable outside of tests so it's ok to do deviate a bit from the
// spec). // spec).
TrackTask(std::move(task), GetDevice()->GetPendingCommandSerial()); TrackTask(std::move(task), GetDevice()->GetPendingCommandSerial());
TRACE_EVENT1(GetDevice()->GetPlatform(), General, "Queue::APIOnSubmittedWorkDone", "serial",
uint64_t(GetDevice()->GetPendingCommandSerial()));
} }
void QueueBase::TrackTask(std::unique_ptr<TaskInFlight> task, ExecutionSerial serial) { void QueueBase::TrackTask(std::unique_ptr<TaskInFlight> task, ExecutionSerial serial) {
@ -233,6 +238,9 @@ namespace dawn::native {
// To prevent the reentrant call from invalidating mTasksInFlight while in use by the first // To prevent the reentrant call from invalidating mTasksInFlight while in use by the first
// call, we remove the tasks to finish from the queue, update mTasksInFlight, then run the // call, we remove the tasks to finish from the queue, update mTasksInFlight, then run the
// callbacks. // callbacks.
TRACE_EVENT1(GetDevice()->GetPlatform(), General, "Queue::Tick", "finishedSerial",
uint64_t(finishedSerial));
std::vector<std::unique_ptr<TaskInFlight>> tasks; std::vector<std::unique_ptr<TaskInFlight>> tasks;
for (auto& task : mTasksInFlight.IterateUpTo(finishedSerial)) { for (auto& task : mTasksInFlight.IterateUpTo(finishedSerial)) {
tasks.push_back(std::move(task)); tasks.push_back(std::move(task));
@ -240,7 +248,7 @@ namespace dawn::native {
mTasksInFlight.ClearUpTo(finishedSerial); mTasksInFlight.ClearUpTo(finishedSerial);
for (auto& task : tasks) { for (auto& task : tasks) {
task->Finish(); task->Finish(GetDevice()->GetPlatform(), finishedSerial);
} }
} }

View File

@ -21,7 +21,9 @@
#include "dawn/native/IntegerTypes.h" #include "dawn/native/IntegerTypes.h"
#include "dawn/native/ObjectBase.h" #include "dawn/native/ObjectBase.h"
#include "dawn/native/DawnNative.h"
#include "dawn/native/dawn_platform.h" #include "dawn/native/dawn_platform.h"
#include "dawn/platform/DawnPlatform.h"
namespace dawn::native { namespace dawn::native {
@ -29,7 +31,7 @@ namespace dawn::native {
public: public:
struct TaskInFlight { struct TaskInFlight {
virtual ~TaskInFlight(); virtual ~TaskInFlight();
virtual void Finish() = 0; virtual void Finish(dawn::platform::Platform* platform, ExecutionSerial serial) = 0;
virtual void HandleDeviceLoss() = 0; virtual void HandleDeviceLoss() = 0;
}; };

View File

@ -25,6 +25,8 @@
#include "dawn/native/d3d12/HeapD3D12.h" #include "dawn/native/d3d12/HeapD3D12.h"
#include "dawn/native/d3d12/ResidencyManagerD3D12.h" #include "dawn/native/d3d12/ResidencyManagerD3D12.h"
#include "dawn/native/d3d12/UtilsD3D12.h" #include "dawn/native/d3d12/UtilsD3D12.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/tracing/TraceEvent.h"
namespace dawn::native::d3d12 { namespace dawn::native::d3d12 {
@ -320,6 +322,8 @@ namespace dawn::native::d3d12 {
const char* contextInfo) { const char* contextInfo) {
// The mapped buffer can be accessed at any time, so it must be locked to ensure it is never // The mapped buffer can be accessed at any time, so it must be locked to ensure it is never
// evicted. This buffer should already have been made resident when it was created. // evicted. This buffer should already have been made resident when it was created.
TRACE_EVENT0(GetDevice()->GetPlatform(), General, "BufferD3D12::MapInternal");
Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap()); Heap* heap = ToBackend(mResourceAllocation.GetResourceHeap());
DAWN_TRY(ToBackend(GetDevice())->GetResidencyManager()->LockAllocation(heap)); DAWN_TRY(ToBackend(GetDevice())->GetResidencyManager()->LockAllocation(heap));

View File

@ -41,6 +41,8 @@
#include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h" #include "dawn/native/d3d12/StagingDescriptorAllocatorD3D12.h"
#include "dawn/native/d3d12/SwapChainD3D12.h" #include "dawn/native/d3d12/SwapChainD3D12.h"
#include "dawn/native/d3d12/UtilsD3D12.h" #include "dawn/native/d3d12/UtilsD3D12.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/tracing/TraceEvent.h"
#include <sstream> #include <sstream>
@ -339,6 +341,9 @@ namespace dawn::native::d3d12 {
MaybeError Device::NextSerial() { MaybeError Device::NextSerial() {
IncrementLastSubmittedCommandSerial(); IncrementLastSubmittedCommandSerial();
TRACE_EVENT1(GetPlatform(), General, "D3D12Device::SignalFence", "serial",
uint64_t(GetLastSubmittedCommandSerial()));
return CheckHRESULT( return CheckHRESULT(
mCommandQueue->Signal(mFence.Get(), uint64_t(GetLastSubmittedCommandSerial())), mCommandQueue->Signal(mFence.Get(), uint64_t(GetLastSubmittedCommandSerial())),
"D3D12 command queue signal fence"); "D3D12 command queue signal fence");

View File

@ -50,13 +50,15 @@ namespace dawn::native::d3d12 {
CommandRecordingContext* commandContext; CommandRecordingContext* commandContext;
DAWN_TRY_ASSIGN(commandContext, device->GetPendingCommandContext()); DAWN_TRY_ASSIGN(commandContext, device->GetPendingCommandContext());
TRACE_EVENT_BEGIN0(GetDevice()->GetPlatform(), Recording, TRACE_EVENT_BEGIN1(GetDevice()->GetPlatform(), Recording,
"CommandBufferD3D12::RecordCommands"); "CommandBufferD3D12::RecordCommands", "serial",
uint64_t(GetDevice()->GetPendingCommandSerial()));
for (uint32_t i = 0; i < commandCount; ++i) { for (uint32_t i = 0; i < commandCount; ++i) {
DAWN_TRY(ToBackend(commands[i])->RecordCommands(commandContext)); DAWN_TRY(ToBackend(commands[i])->RecordCommands(commandContext));
} }
TRACE_EVENT_END0(GetDevice()->GetPlatform(), Recording, TRACE_EVENT_END1(GetDevice()->GetPlatform(), Recording,
"CommandBufferD3D12::RecordCommands"); "CommandBufferD3D12::RecordCommands", "serial",
uint64_t(GetDevice()->GetPendingCommandSerial()));
DAWN_TRY(device->ExecutePendingCommandContext()); DAWN_TRY(device->ExecutePendingCommandContext());

View File

@ -857,6 +857,7 @@ namespace dawn::platform::TraceEvent {
} }
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned int, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned short, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT) INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned char, TRACE_VALUE_TYPE_UINT)