diff --git a/src/dawn_native/CreatePipelineAsyncTask.cpp b/src/dawn_native/CreatePipelineAsyncTask.cpp index d3cdb0d859..e241235fa3 100644 --- a/src/dawn_native/CreatePipelineAsyncTask.cpp +++ b/src/dawn_native/CreatePipelineAsyncTask.cpp @@ -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 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 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 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 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 diff --git a/src/dawn_native/Device.cpp b/src/dawn_native/Device.cpp index a65285389e..849c065414 100644 --- a/src/dawn_native/Device.cpp +++ b/src/dawn_native/Device.cpp @@ -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 #include @@ -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 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 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 result; std::unique_ptr compilationMessages( std::make_unique()); diff --git a/src/dawn_native/utils/WGPUHelpers.cpp b/src/dawn_native/utils/WGPUHelpers.cpp index c10c7a77bb..60c2addc82 100644 --- a/src/dawn_native/utils/WGPUHelpers.cpp +++ b/src/dawn_native/utils/WGPUHelpers.cpp @@ -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 diff --git a/src/dawn_native/utils/WGPUHelpers.h b/src/dawn_native/utils/WGPUHelpers.h index 730ab15ac4..108f107d91 100644 --- a/src/dawn_native/utils/WGPUHelpers.h +++ b/src/dawn_native/utils/WGPUHelpers.h @@ -115,6 +115,9 @@ namespace dawn_native { namespace utils { DeviceBase* device, const Ref& layout, std::initializer_list entriesInitializer); + + const char* GetLabelForTrace(const char* label); + }} // namespace dawn_native::utils #endif // DAWNNATIVE_UTILS_WGPUHELPERS_H_ \ No newline at end of file diff --git a/src/dawn_platform/tracing/TraceEvent.h b/src/dawn_platform/tracing/TraceEvent.h index 8b384a6771..8d375ef036 100644 --- a/src/dawn_platform/tracing/TraceEvent.h +++ b/src/dawn_platform/tracing/TraceEvent.h @@ -840,20 +840,18 @@ namespace dawn_platform { namespace TraceEvent { // Define setTraceValue for each allowed type. It stores the type and // 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) { \ - TraceValueUnion typeValue; \ - typeValue.union_member = arg; \ - *type = value_type_id; \ - *value = typeValue.m_uint; \ +#define INTERNAL_DECLARE_SET_TRACE_VALUE(actual_type, union_member, value_type_id) \ + static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \ + TraceValueUnion typeValue; \ + typeValue.union_member = arg; \ + *type = value_type_id; \ + *value = typeValue.m_uint; \ } // 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) { \ - *type = value_type_id; \ - *value = static_cast(arg); \ +#define INTERNAL_DECLARE_SET_TRACE_VALUE_INT(actual_type, value_type_id) \ + static inline void setTraceValue(actual_type arg, unsigned char* type, uint64_t* value) { \ + *type = value_type_id; \ + *value = static_cast(arg); \ } INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, TRACE_VALUE_TYPE_UINT) @@ -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;