Add label to the trace events for pipeline and shader module creation

This patch adds the object label to the trace events for the creation
of pipeline and shader module so that we can easily know which shader
module or pipeline creation task the trace event belongs to.

BUG=dawn:1167

Change-Id: Ic2de4542d0167437eea2fd600d0f0be3bdd225f9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/70041
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
Jiawei Shao 2021-11-21 11:18:19 +00:00 committed by Dawn LUCI CQ
parent bd3e042383
commit 4e3ddbd955
5 changed files with 60 additions and 30 deletions

View File

@ -20,6 +20,7 @@
#include "dawn_native/RenderPipeline.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h"
#include "utils/WGPUHelpers.h"
namespace dawn_native {
@ -114,10 +115,13 @@ namespace dawn_native {
}
void CreateComputePipelineAsyncTask::Run() {
TRACE_EVENT_FLOW_END0(mComputePipeline->GetDevice()->GetPlatform(), General,
"CreateComputePipelineAsyncTask::RunAsync", this);
TRACE_EVENT0(mComputePipeline->GetDevice()->GetPlatform(), General,
"CreateComputePipelineAsyncTask::Run");
const char* eventLabel = utils::GetLabelForTrace(mComputePipeline->GetLabel().c_str());
TRACE_EVENT_FLOW_END1(mComputePipeline->GetDevice()->GetPlatform(), General,
"CreateComputePipelineAsyncTask::RunAsync", this, "label",
eventLabel);
TRACE_EVENT1(mComputePipeline->GetDevice()->GetPlatform(), General,
"CreateComputePipelineAsyncTask::Run", "label", eventLabel);
MaybeError maybeError = mComputePipeline->Initialize();
std::string errorMessage;
if (maybeError.IsError()) {
@ -133,6 +137,9 @@ namespace dawn_native {
std::unique_ptr<CreateComputePipelineAsyncTask> task) {
DeviceBase* device = task->mComputePipeline->GetDevice();
const char* eventLabel =
utils::GetLabelForTrace(task->mComputePipeline->GetLabel().c_str());
// Using "taskPtr = std::move(task)" causes compilation error while it should be supported
// since C++14:
// https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160
@ -140,8 +147,10 @@ namespace dawn_native {
std::unique_ptr<CreateComputePipelineAsyncTask> innnerTaskPtr(taskPtr);
innnerTaskPtr->Run();
};
TRACE_EVENT_FLOW_BEGIN0(device->GetPlatform(), General,
"CreateComputePipelineAsyncTask::RunAsync", task.get());
TRACE_EVENT_FLOW_BEGIN1(device->GetPlatform(), General,
"CreateComputePipelineAsyncTask::RunAsync", task.get(), "label",
eventLabel);
device->GetAsyncTaskManager()->PostTask(std::move(asyncTask));
}
@ -156,10 +165,12 @@ namespace dawn_native {
}
void CreateRenderPipelineAsyncTask::Run() {
TRACE_EVENT_FLOW_END0(mRenderPipeline->GetDevice()->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::RunAsync", this);
TRACE_EVENT0(mRenderPipeline->GetDevice()->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::Run");
const char* eventLabel = utils::GetLabelForTrace(mRenderPipeline->GetLabel().c_str());
TRACE_EVENT_FLOW_END1(mRenderPipeline->GetDevice()->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::RunAsync", this, "label", eventLabel);
TRACE_EVENT1(mRenderPipeline->GetDevice()->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::Run", "label", eventLabel);
MaybeError maybeError = mRenderPipeline->Initialize();
std::string errorMessage;
if (maybeError.IsError()) {
@ -175,6 +186,8 @@ namespace dawn_native {
std::unique_ptr<CreateRenderPipelineAsyncTask> task) {
DeviceBase* device = task->mRenderPipeline->GetDevice();
const char* eventLabel = utils::GetLabelForTrace(task->mRenderPipeline->GetLabel().c_str());
// Using "taskPtr = std::move(task)" causes compilation error while it should be supported
// since C++14:
// https://docs.microsoft.com/en-us/cpp/cpp/lambda-expressions-in-cpp?view=msvc-160
@ -182,8 +195,10 @@ namespace dawn_native {
std::unique_ptr<CreateRenderPipelineAsyncTask> innerTaskPtr(taskPtr);
innerTaskPtr->Run();
};
TRACE_EVENT_FLOW_BEGIN0(device->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::RunAsync", task.get());
TRACE_EVENT_FLOW_BEGIN1(device->GetPlatform(), General,
"CreateRenderPipelineAsyncTask::RunAsync", task.get(), "label",
eventLabel);
device->GetAsyncTaskManager()->PostTask(std::move(asyncTask));
}
} // namespace dawn_native

View File

@ -45,6 +45,7 @@
#include "dawn_native/ValidationUtils_autogen.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/tracing/TraceEvent.h"
#include "utils/WGPUHelpers.h"
#include <array>
#include <mutex>
@ -911,7 +912,9 @@ namespace dawn_native {
}
ComputePipelineBase* DeviceBase::APICreateComputePipeline(
const ComputePipelineDescriptor* descriptor) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateComputePipeline");
TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateComputePipeline", "label",
utils::GetLabelForTrace(descriptor->label));
Ref<ComputePipelineBase> result;
if (ConsumedError(CreateComputePipeline(descriptor), &result,
"calling %s.CreateComputePipeline(%s).", this, descriptor)) {
@ -922,7 +925,9 @@ namespace dawn_native {
void DeviceBase::APICreateComputePipelineAsync(const ComputePipelineDescriptor* descriptor,
WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateComputePipelineAsync");
TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateComputePipelineAsync", "label",
utils::GetLabelForTrace(descriptor->label));
MaybeError maybeResult = CreateComputePipelineAsync(descriptor, callback, userdata);
// Call the callback directly when a validation error has been found in the front-end
@ -962,7 +967,8 @@ namespace dawn_native {
void DeviceBase::APICreateRenderPipelineAsync(const RenderPipelineDescriptor* descriptor,
WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateRenderPipelineAsync");
TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateRenderPipelineAsync", "label",
utils::GetLabelForTrace(descriptor->label));
// TODO(dawn:563): Add validation error context.
MaybeError maybeResult = CreateRenderPipelineAsync(descriptor, callback, userdata);
@ -986,7 +992,9 @@ namespace dawn_native {
}
RenderPipelineBase* DeviceBase::APICreateRenderPipeline(
const RenderPipelineDescriptor* descriptor) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateRenderPipeline");
TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateRenderPipeline", "label",
utils::GetLabelForTrace(descriptor->label));
Ref<RenderPipelineBase> result;
if (ConsumedError(CreateRenderPipeline(descriptor), &result,
"calling %s.CreateRenderPipeline(%s).", this, descriptor)) {
@ -995,7 +1003,9 @@ namespace dawn_native {
return result.Detach();
}
ShaderModuleBase* DeviceBase::APICreateShaderModule(const ShaderModuleDescriptor* descriptor) {
TRACE_EVENT0(GetPlatform(), General, "DeviceBase::APICreateShaderModule");
TRACE_EVENT1(GetPlatform(), General, "DeviceBase::APICreateShaderModule", "label",
utils::GetLabelForTrace(descriptor->label));
Ref<ShaderModuleBase> result;
std::unique_ptr<OwnedCompilationMessages> compilationMessages(
std::make_unique<OwnedCompilationMessages>());

View File

@ -185,4 +185,8 @@ namespace dawn_native { namespace utils {
return device->CreateBindGroup(&descriptor);
}
const char* GetLabelForTrace(const char* label) {
return (label == nullptr || strlen(label) == 0) ? "None" : label;
}
}} // namespace dawn_native::utils

View File

@ -115,6 +115,9 @@ namespace dawn_native { namespace utils {
DeviceBase* device,
const Ref<BindGroupLayoutBase>& layout,
std::initializer_list<BindingInitializationHelper> entriesInitializer);
const char* GetLabelForTrace(const char* label);
}} // namespace dawn_native::utils
#endif // DAWNNATIVE_UTILS_WGPUHELPERS_H_

View File

@ -841,8 +841,7 @@ namespace dawn_platform { namespace TraceEvent {
// value in the return arguments. This allows this API to avoid declaring any
// structures so that it is portable to third_party libraries.
#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, value_type_id) \
static inline void setTraceValue(actual_type arg, unsigned char* type, \
unsigned long long* value) { \
static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \
TraceValueUnion typeValue; \
typeValue.union_member = arg; \
*type = value_type_id; \
@ -850,8 +849,7 @@ namespace dawn_platform { namespace TraceEvent {
}
// Simpler form for int types that can be safely casted.
#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \
static inline void setTraceValue(actual_type arg, unsigned char* type, \
unsigned long long* value) { \
static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \
*type = value_type_id; \
*value = static_cast<unsigned long long>(arg); \
}
@ -877,7 +875,7 @@ namespace dawn_platform { namespace TraceEvent {
static inline void setTraceValue(const std::string& arg,
unsigned char* type,
unsigned long long* value) {
uint64_t* value) {
TraceValueUnion typeValue;
typeValue.m_string = arg.data();
*type = TRACE_VALUE_TYPE_COPY_STRING;