Reland "Make dawn_proc print a warning if dawnProcSetProcs is not called."
Reland with a fix to avoid a static initializer.
Original change's description:
> Make dawn_proc print a warning if dawnProcSetProcs is not called.
>
> Fixed: dawn:2488
> Change-Id: Ifc65fef161710e775032a1c7930db307a921612a
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/182120
> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
> Reviewed-by: Austin Eng <enga@chromium.org>
Change-Id: If8bdc53b34a9dd6051c73d8dc21d3f2390ce140e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/182581
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py
index 23ebc55..d6e2091 100644
--- a/generator/dawn_json_generator.py
+++ b/generator/dawn_json_generator.py
@@ -1066,7 +1066,7 @@
if 'proc' in targets:
renders.append(
- FileRender('dawn_proc.c', 'src/dawn/' + prefix + '_proc.c',
+ FileRender('dawn_proc.cpp', 'src/dawn/' + prefix + '_proc.cpp',
[RENDER_PARAMS_BASE, params_dawn]))
renders.append(
FileRender('dawn_thread_dispatch_proc.cpp',
diff --git a/generator/templates/dawn_proc.c b/generator/templates/dawn_proc.cpp
similarity index 76%
rename from generator/templates/dawn_proc.c
rename to generator/templates/dawn_proc.cpp
index ee9faec..57c52d9 100644
--- a/generator/templates/dawn_proc.c
+++ b/generator/templates/dawn_proc.cpp
@@ -32,16 +32,33 @@
// The sanitizer is disabled for calls to procs.* since those functions may be
// dynamically loaded.
#include "dawn/common/Compiler.h"
+#include "dawn/common/Log.h"
-static {{Prefix}}ProcTable procs;
+// A fake wgpuCreateInstance that prints a warning so folks know that they are using dawn_procs and
+// should either use a different target to link against, or call dawnProcSetProcs.
+WGPUInstance CreateInstanceThatWarns(const WGPUInstanceDescriptor* desc) {
+ dawn::ErrorLog() <<
+ R"(The \"null\" {{metadata.namespace}}CreateInstance from {{prefix}}_proc was called which always returns nullptr. You either need to:
+ - call {{prefix}}ProcSetProcs with a {{Prefix}}ProcTable object retrieved somewhere else, or
+ - (most likely) link against a different target that implements {{metadata.api}} directly, for example {{metadata.api.lower()}}_dawn)";
-static {{Prefix}}ProcTable nullProcs;
+ return nullptr;
+}
+
+constexpr {{Prefix}}ProcTable MakeNullProcTable() {
+ {{Prefix}}ProcTable procs = {};
+ procs.createInstance = CreateInstanceThatWarns;
+ return procs;
+}
+
+static {{Prefix}}ProcTable kNullProcs = MakeNullProcTable();
+static {{Prefix}}ProcTable procs = MakeNullProcTable();
void {{prefix}}ProcSetProcs(const {{Prefix}}ProcTable* procs_) {
if (procs_) {
procs = *procs_;
} else {
- procs = nullProcs;
+ procs = kNullProcs;
}
}
diff --git a/src/dawn/BUILD.gn b/src/dawn/BUILD.gn
index 4de344d..2e243b5 100644
--- a/src/dawn/BUILD.gn
+++ b/src/dawn/BUILD.gn
@@ -52,7 +52,7 @@
dawn_json_generator("proc_gen") {
target = "proc"
outputs = [
- "src/dawn/dawn_proc.c",
+ "src/dawn/dawn_proc.cpp",
"src/dawn/dawn_thread_dispatch_proc.cpp",
]
}
diff --git a/src/dawn/native/CMakeLists.txt b/src/dawn/native/CMakeLists.txt
index 6058500..9a3d8d5 100644
--- a/src/dawn/native/CMakeLists.txt
+++ b/src/dawn/native/CMakeLists.txt
@@ -766,10 +766,16 @@
RESULT_VARIABLE "WEBGPU_DAWN_NATIVE_PROC_GEN"
)
+# A convenience target that bundles dawn_native and procs calling it directly so that
+# applications link against it and have WebGPU work without jumping through more hoops.
+# Note that this library name is referenced in several places, search for it and things like:
+# "{{.*}}_dawn" when you rename it.
add_library(webgpu_dawn)
common_compile_options(webgpu_dawn)
-target_link_libraries(webgpu_dawn PRIVATE dawn_native)
-target_link_libraries(webgpu_dawn PUBLIC dawn_headers)
+target_link_libraries(webgpu_dawn
+ PRIVATE dawn_native
+ PUBLIC dawn_headers
+)
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_IMPLEMENTATION")
if(BUILD_SHARED_LIBS)
target_compile_definitions(webgpu_dawn PRIVATE "WGPU_SHARED_LIBRARY")