Skip to content

Commit

Permalink
tint->dawn: Move src/dawn_platform -> src/dawn/platform
Browse files Browse the repository at this point in the history
Bug: dawn:1275
Change-Id: I043c5e6d84e199fe2e753ac43181b125882439bf
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/79082
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
  • Loading branch information
ben-clayton committed Feb 4, 2022
1 parent 20cbe6d commit b2c4d7a
Show file tree
Hide file tree
Showing 39 changed files with 336 additions and 316 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ add_subdirectory(third_party)
add_subdirectory(generator)
add_subdirectory(src/dawn)
add_subdirectory(src/dawn/common)
add_subdirectory(src/dawn_platform)
add_subdirectory(src/dawn/platform)
add_subdirectory(src/dawn_native)
add_subdirectory(src/dawn/wire)
# TODO(dawn:269): Remove once the implementation-based swapchains are removed.
Expand Down
2 changes: 1 addition & 1 deletion docs/dawn/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ This repository contains the implementation of Dawn, which is itself composed of
- [`common`](../src/dawn/common): helper code that is allowed to be used by Dawn's core libraries, `dawn_native` and `dawn_wire`. Also allowed for use in all other Dawn targets.
- [`wire`](../src/dawn/wire): code for an implementation of WebGPU as a client-server architecture.
- [`utils`](../src/dawn/utils): helper code to use Dawn used by tests and samples but disallowed for `dawn_native` and `dawn_wire`.
- [`platform`](../src/dawn/platform): definition of interfaces for dependency injection in `dawn_native` or `dawn_wire`.
- [`dawn_native`](../src/dawn_native): code for the implementation of WebGPU on top of graphics APIs. Files in this folder are the "frontend" while subdirectories are "backends".
- `<backend>`: code for the implementation of the backend on a specific graphics API, for example `d3d12`, `metal` or `vulkan`.
- [`dawn_platform`](../src/dawn_platform): definition of interfaces for dependency injection in `dawn_native` or `dawn_wire`.
- [`fuzzers`](../src/dawn/fuzzers): various fuzzers for Dawn that are running in [Clusterfuzz](https://google.github.io/clusterfuzz/).
- [`include`](../src/include): public headers with subdirectories for each library. Note that some headers are auto-generated and not present directly in the directory.
- [`tests`](../src/tests):
Expand Down
41 changes: 41 additions & 0 deletions src/dawn/platform/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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.

import("../../../scripts/dawn_overrides_with_defaults.gni")

import("${dawn_root}/scripts/dawn_component.gni")

dawn_component("platform") {
DEFINE_PREFIX = "DAWN_PLATFORM"

configs = [ "${dawn_root}/src/dawn/common:internal_config" ]

sources = [
"${dawn_root}/src/include/dawn/platform/DawnPlatform.h",
"${dawn_root}/src/include/dawn/platform/dawn_platform_export.h",
"DawnPlatform.cpp",
"WorkerThread.cpp",
"WorkerThread.h",
"tracing/EventTracer.cpp",
"tracing/EventTracer.h",
"tracing/TraceEvent.h",
]

deps = [ "${dawn_root}/src/dawn/common" ]

public_deps = [
# DawnPlatform.h has #include <dawn/webgpu.h>
"${dawn_root}/src/dawn:dawn_headers",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ if(BUILD_SHARED_LIBS)
endif()

target_sources(dawn_platform PRIVATE
"${DAWN_INCLUDE_DIR}/dawn_platform/DawnPlatform.h"
"${DAWN_INCLUDE_DIR}/dawn_platform/dawn_platform_export.h"
"${DAWN_INCLUDE_DIR}/dawn/platform/DawnPlatform.h"
"${DAWN_INCLUDE_DIR}/dawn/platform/dawn_platform_export.h"
"DawnPlatform.cpp"
"WorkerThread.cpp"
"WorkerThread.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "dawn_platform/DawnPlatform.h"
#include "dawn_platform/WorkerThread.h"
#include "dawn/platform/DawnPlatform.h"
#include "dawn/platform/WorkerThread.h"

#include "dawn/common/Assert.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "dawn_platform/WorkerThread.h"
#include "dawn/platform/WorkerThread.h"

#include <condition_variable>
#include <functional>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define COMMON_WORKERTHREAD_H_

#include "dawn/common/NonCopyable.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn/platform/DawnPlatform.h"

namespace dawn::platform {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "dawn_platform/tracing/EventTracer.h"
#include "dawn/platform/tracing/EventTracer.h"
#include "dawn/common/Assert.h"
#include "dawn_platform/DawnPlatform.h"
#include "dawn/platform/DawnPlatform.h"

namespace dawn::platform::tracing {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef DAWNPLATFORM_TRACING_EVENTTRACER_H_
#define DAWNPLATFORM_TRACING_EVENTTRACER_H_

#include "dawn_platform/dawn_platform_export.h"
#include "dawn/platform/dawn_platform_export.h"

#include <cstdint>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

#include <string>

#include "dawn_platform/tracing/EventTracer.h"
#include "dawn/platform/tracing/EventTracer.h"

// Records a pair of begin and end events called "name" for the current
// scope, with 0, 1 or 2 associated arguments. If the category is not
Expand Down Expand Up @@ -856,137 +856,135 @@ namespace dawn::platform::TraceEvent {
*value = static_cast<unsigned long long>(arg); \
}

INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, 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 char, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE(bool, m_bool, TRACE_VALUE_TYPE_BOOL)
INTERNAL_DECLARE_SET_TRACE_VALUE(double, m_double, TRACE_VALUE_TYPE_DOUBLE)
INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, m_pointer, TRACE_VALUE_TYPE_POINTER)
INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, m_string, TRACE_VALUE_TYPE_STRING)
INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&,
m_string,
TRACE_VALUE_TYPE_COPY_STRING)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(unsigned long long, 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 char, TRACE_VALUE_TYPE_UINT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(long long, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(int, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(short, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE_INT(signed char, TRACE_VALUE_TYPE_INT)
INTERNAL_DECLARE_SET_TRACE_VALUE(bool, m_bool, TRACE_VALUE_TYPE_BOOL)
INTERNAL_DECLARE_SET_TRACE_VALUE(double, m_double, TRACE_VALUE_TYPE_DOUBLE)
INTERNAL_DECLARE_SET_TRACE_VALUE(const void*, m_pointer, TRACE_VALUE_TYPE_POINTER)
INTERNAL_DECLARE_SET_TRACE_VALUE(const char*, m_string, TRACE_VALUE_TYPE_STRING)
INTERNAL_DECLARE_SET_TRACE_VALUE(const TraceStringWithCopy&,
m_string,
TRACE_VALUE_TYPE_COPY_STRING)

#undef INTERNAL_DECLARE_SET_TRACE_VALUE
#undef INTERNAL_DECLARE_SET_TRACE_VALUE_INT

static inline void setTraceValue(const std::string& arg,
unsigned char* type,
uint64_t* value) {
TraceValueUnion typeValue;
typeValue.m_string = arg.data();
*type = TRACE_VALUE_TYPE_COPY_STRING;
*value = typeValue.m_uint;
}
static inline void setTraceValue(const std::string& arg, unsigned char* type, uint64_t* value) {
TraceValueUnion typeValue;
typeValue.m_string = arg.data();
*type = TRACE_VALUE_TYPE_COPY_STRING;
*value = typeValue.m_uint;
}

// These addTraceEvent template functions are defined here instead of in the
// macro, because the arg values could be temporary string objects. In order to
// store pointers to the internal c_str and pass through to the tracing API, the
// arg values must live throughout these procedures.

static inline dawn::platform::tracing::TraceEventHandle addTraceEvent(
dawn::platform::Platform* platform,
char phase,
const unsigned char* categoryEnabled,
const char* name,
unsigned long long id,
unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/) {
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id,
zeroNumArgs, 0, 0, 0, flags);
}
// These addTraceEvent template functions are defined here instead of in the
// macro, because the arg values could be temporary string objects. In order to
// store pointers to the internal c_str and pass through to the tracing API, the
// arg values must live throughout these procedures.

static inline dawn::platform::tracing::TraceEventHandle addTraceEvent(
dawn::platform::Platform* platform,
char phase,
const unsigned char* categoryEnabled,
const char* name,
unsigned long long id,
unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/) {
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id,
zeroNumArgs, 0, 0, 0, flags);
}

template <class ARG1_TYPE>
static inline dawn::platform::tracing::TraceEventHandle addTraceEvent(
dawn::platform::Platform* platform,
char phase,
const unsigned char* categoryEnabled,
const char* name,
unsigned long long id,
unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/,
const char* arg1Name,
const ARG1_TYPE& arg1Val) {
const int numArgs = 1;
unsigned char argTypes[1];
uint64_t argValues[1];
setTraceValue(arg1Val, &argTypes[0], &argValues[0]);
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id,
numArgs, &arg1Name, argTypes, argValues, flags);
}
template <class ARG1_TYPE>
static inline dawn::platform::tracing::TraceEventHandle addTraceEvent(
dawn::platform::Platform* platform,
char phase,
const unsigned char* categoryEnabled,
const char* name,
unsigned long long id,
unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/,
const char* arg1Name,
const ARG1_TYPE& arg1Val) {
const int numArgs = 1;
unsigned char argTypes[1];
uint64_t argValues[1];
setTraceValue(arg1Val, &argTypes[0], &argValues[0]);
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, numArgs,
&arg1Name, argTypes, argValues, flags);
}

template <class ARG1_TYPE, class ARG2_TYPE>
static inline dawn::platform::tracing::TraceEventHandle addTraceEvent(
dawn::platform::Platform* platform,
char phase,
const unsigned char* categoryEnabled,
const char* name,
unsigned long long id,
unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/,
const char* arg1Name,
const ARG1_TYPE& arg1Val,
const char* arg2Name,
const ARG2_TYPE& arg2Val) {
const int numArgs = 2;
const char* argNames[2] = {arg1Name, arg2Name};
unsigned char argTypes[2];
uint64_t argValues[2];
setTraceValue(arg1Val, &argTypes[0], &argValues[0]);
setTraceValue(arg2Val, &argTypes[1], &argValues[1]);
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id,
numArgs, argNames, argTypes, argValues, flags);
}
template <class ARG1_TYPE, class ARG2_TYPE>
static inline dawn::platform::tracing::TraceEventHandle addTraceEvent(
dawn::platform::Platform* platform,
char phase,
const unsigned char* categoryEnabled,
const char* name,
unsigned long long id,
unsigned char flags,
int /*unused, helps avoid empty __VA_ARGS__*/,
const char* arg1Name,
const ARG1_TYPE& arg1Val,
const char* arg2Name,
const ARG2_TYPE& arg2Val) {
const int numArgs = 2;
const char* argNames[2] = {arg1Name, arg2Name};
unsigned char argTypes[2];
uint64_t argValues[2];
setTraceValue(arg1Val, &argTypes[0], &argValues[0]);
setTraceValue(arg2Val, &argTypes[1], &argValues[1]);
return TRACE_EVENT_API_ADD_TRACE_EVENT(platform, phase, categoryEnabled, name, id, numArgs,
argNames, argTypes, argValues, flags);
}

// Used by TRACE_EVENTx macro. Do not use directly.
class TraceEndOnScopeClose {
public:
// Note: members of m_data intentionally left uninitialized. See initialize.
TraceEndOnScopeClose() : m_pdata(0) {
}
~TraceEndOnScopeClose() {
if (m_pdata)
addEventIfEnabled();
}
// Used by TRACE_EVENTx macro. Do not use directly.
class TraceEndOnScopeClose {
public:
// Note: members of m_data intentionally left uninitialized. See initialize.
TraceEndOnScopeClose() : m_pdata(0) {
}
~TraceEndOnScopeClose() {
if (m_pdata)
addEventIfEnabled();
}

void initialize(dawn::platform::Platform* platform,
const unsigned char* categoryEnabled,
const char* name) {
m_data.platform = platform;
m_data.categoryEnabled = categoryEnabled;
m_data.name = name;
m_pdata = &m_data;
}
void initialize(dawn::platform::Platform* platform,
const unsigned char* categoryEnabled,
const char* name) {
m_data.platform = platform;
m_data.categoryEnabled = categoryEnabled;
m_data.name = name;
m_pdata = &m_data;
}

private:
// Add the end event if the category is still enabled.
void addEventIfEnabled() {
// Only called when m_pdata is non-null.
if (*m_pdata->categoryEnabled) {
TRACE_EVENT_API_ADD_TRACE_EVENT(
m_pdata->platform, TRACE_EVENT_PHASE_END, m_pdata->categoryEnabled,
m_pdata->name, noEventId, zeroNumArgs, 0, 0, 0, TRACE_EVENT_FLAG_NONE);
}
private:
// Add the end event if the category is still enabled.
void addEventIfEnabled() {
// Only called when m_pdata is non-null.
if (*m_pdata->categoryEnabled) {
TRACE_EVENT_API_ADD_TRACE_EVENT(m_pdata->platform, TRACE_EVENT_PHASE_END,
m_pdata->categoryEnabled, m_pdata->name, noEventId,
zeroNumArgs, 0, 0, 0, TRACE_EVENT_FLAG_NONE);
}
}

// This Data struct workaround is to avoid initializing all the members
// in Data during construction of this object, since this object is always
// constructed, even when tracing is disabled. If the members of Data were
// members of this class instead, compiler warnings occur about potential
// uninitialized accesses.
struct Data {
dawn::platform::Platform* platform;
const unsigned char* categoryEnabled;
const char* name;
};
Data* m_pdata;
Data m_data;
// This Data struct workaround is to avoid initializing all the members
// in Data during construction of this object, since this object is always
// constructed, even when tracing is disabled. If the members of Data were
// members of this class instead, compiler warnings occur about potential
// uninitialized accesses.
struct Data {
dawn::platform::Platform* platform;
const unsigned char* categoryEnabled;
const char* name;
};
Data* m_pdata;
Data m_data;
};

} // namespace dawn::platform::TraceEvent

Expand Down
2 changes: 1 addition & 1 deletion src/dawn_native/AsyncTask.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "dawn_native/AsyncTask.h"

#include "dawn_platform/DawnPlatform.h"
#include "dawn/platform/DawnPlatform.h"

namespace dawn::native {

Expand Down
Loading

0 comments on commit b2c4d7a

Please sign in to comment.