Add a build target for a webgpu_dawn library

This library binds directly to dawn_native and implements
webgpu.h. It may be built as a single library so it can
be easily used in other projects.

Bug: dawn:1220
Change-Id: I73be8c6455922fa526efd1600446cc46b07e82ed
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/53887
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2021-12-09 20:03:48 +00:00 committed by Dawn LUCI CQ
parent 908f4fe689
commit 63f65465f5
6 changed files with 168 additions and 42 deletions

View File

@ -17,6 +17,7 @@ import("scripts/dawn_overrides_with_defaults.gni")
group("all") { group("all") {
testonly = true testonly = true
deps = [ deps = [
"src/dawn_native:webgpu_dawn",
"src/fuzzers:dawn_fuzzers", "src/fuzzers:dawn_fuzzers",
"src/tests:dawn_tests", "src/tests:dawn_tests",
] ]

View File

@ -786,6 +786,12 @@ class MultiGeneratorFromDawnJSON(Generator):
'src/dawn/dawn_thread_dispatch_proc.cpp', 'src/dawn/dawn_thread_dispatch_proc.cpp',
[RENDER_PARAMS_BASE, params_dawn])) [RENDER_PARAMS_BASE, params_dawn]))
if 'webgpu_dawn_native_proc' in targets:
renders.append(
FileRender('dawn_native/api_dawn_native_proc.cpp',
'src/dawn_native/webgpu_dawn_native_proc.cpp',
[RENDER_PARAMS_BASE, params_dawn]))
if 'dawncpp' in targets: if 'dawncpp' in targets:
renders.append( renders.append(
FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp', FileRender('webgpu_cpp.cpp', 'src/dawn/webgpu_cpp.cpp',

View File

@ -28,8 +28,6 @@
namespace dawn_native { namespace dawn_native {
namespace {
{% for type in by_category["object"] %} {% for type in by_category["object"] %}
{% for method in c_methods(type) %} {% for method in c_methods(type) %}
{% set suffix = as_MethodSuffix(type.name, method.name) %} {% set suffix = as_MethodSuffix(type.name, method.name) %}
@ -74,6 +72,8 @@ namespace dawn_native {
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
namespace {
struct ProcEntry { struct ProcEntry {
WGPUProc proc; WGPUProc proc;
const char* name; const char* name;
@ -84,7 +84,8 @@ namespace dawn_native {
{% endfor %} {% endfor %}
}; };
static constexpr size_t sProcMapSize = sizeof(sProcMap) / sizeof(sProcMap[0]); static constexpr size_t sProcMapSize = sizeof(sProcMap) / sizeof(sProcMap[0]);
}
} // anonymous namespace
WGPUInstance NativeCreateInstance(WGPUInstanceDescriptor const* descriptor) { WGPUInstance NativeCreateInstance(WGPUInstanceDescriptor const* descriptor) {
return ToAPI(InstanceBase::Create(FromAPI(descriptor))); return ToAPI(InstanceBase::Create(FromAPI(descriptor)));

View File

@ -0,0 +1,75 @@
// Copyright 2021 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.
#include <dawn/{{metadata.api.lower()}}.h>
namespace dawn_native {
// This file should be kept in sync with generator/templates/dawn_native/ProcTable.cpp
{% for function in by_category["function"] %}
extern {{as_cType(function.return_type.name)}} Native{{as_cppType(function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endfor %}
{% for type in by_category["object"] %}
{% for method in c_methods(type) %}
extern {{as_cType(method.return_type.name)}} Native{{as_MethodSuffix(type.name, method.name)}}(
{{-as_cType(type.name)}} cSelf
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
);
{% endfor %}
{% endfor %}
}
extern "C" {
using namespace dawn_native;
{% for function in by_category["function"] %}
{{as_cType(function.return_type.name)}} {{metadata.namespace}}{{as_cppType(function.name)}} (
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_annotated_cType(arg)}}
{%- endfor -%}
) {
return Native{{as_cppType(function.name)}}(
{%- for arg in function.arguments -%}
{% if not loop.first %}, {% endif %}{{as_varName(arg.name)}}
{%- endfor -%}
);
}
{% endfor %}
{% for type in by_category["object"] %}
{% for method in c_methods(type) %}
{{as_cType(method.return_type.name)}} {{metadata.namespace}}{{as_MethodSuffix(type.name, method.name)}}(
{{-as_cType(type.name)}} cSelf
{%- for arg in method.arguments -%}
, {{as_annotated_cType(arg)}}
{%- endfor -%}
) {
return Native{{as_MethodSuffix(type.name, method.name)}}(
cSelf
{%- for arg in method.arguments -%}
, {{as_varName(arg.name)}}
{%- endfor -%}
);
}
{% endfor %}
{% endfor %}
}

View File

@ -746,3 +746,32 @@ dawn_component("dawn_native") {
} }
} }
} }
dawn_json_generator("webgpu_dawn_native_proc_gen") {
target = "webgpu_dawn_native_proc"
outputs = [ "src/dawn_native/webgpu_dawn_native_proc.cpp" ]
}
dawn_component("webgpu_dawn") {
# For a single library - build `webgpu_dawn_shared` with GN args:
# dawn_complete_static_libs = true - to package a single lib
#
# is_debug = false
# - setting this to true makes library over 50Mb
#
# use_custom_libcxx = false
# - Otherwise, libc++ symbols may conflict if the
# library is used outside of Chromium.
#
# dawn_use_swiftshader = false
# angle_enable_swiftshader = false
# - SwiftShader can't be built without use_custom_libcxx.
# It should be built separately.
DEFINE_PREFIX = "WGPU"
sources = get_target_outputs(":webgpu_dawn_native_proc_gen")
deps = [
":dawn_native_static",
":webgpu_dawn_native_proc_gen",
]
}

View File

@ -545,3 +545,17 @@ endif()
if (DAWN_ENABLE_VULKAN) if (DAWN_ENABLE_VULKAN)
target_sources(dawn_native PRIVATE "vulkan/VulkanBackend.cpp") target_sources(dawn_native PRIVATE "vulkan/VulkanBackend.cpp")
endif() endif()
DawnJSONGenerator(
TARGET "webgpu_dawn_native_proc"
PRINT_NAME "Dawn native WebGPU procs"
RESULT_VARIABLE "WEBGPU_DAWN_NATIVE_PROC_GEN"
)
add_library(webgpu_dawn ${DAWN_DUMMY_FILE})
target_link_libraries(webgpu_dawn PRIVATE dawn_native)
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_IMPLEMENTATION")
if(BUILD_SHARED_LIBS)
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_SHARED_LIBRARY")
endif()
target_sources(webgpu_dawn PRIVATE ${WEBGPU_DAWN_NATIVE_PROC_GEN})