Skip to content

Commit 55da12c

Browse files
halby24claude
andcommitted
feat: expose Dawn debug toggles via requestDevice() dawnToggles option
JS側から dump_shaders や use_user_defined_labels_in_backend などの Dawn デバッグトグルを有効化・無効化できるようにする。 WebGPU仕様外の非標準拡張フィールドとして GPUDeviceDescriptor に追加。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7af78d4 commit 55da12c

4 files changed

Lines changed: 98 additions & 2 deletions

File tree

packages/webgpu/cpp/rnwgpu/api/GPUAdapter.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,45 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
8686
std::string label =
8787
descriptor.has_value() ? descriptor.value()->label.value_or("") : "";
8888

89+
// Extract Dawn toggle data by value before the async lambda captures it
90+
std::optional<rnwgpu::GPUDawnTogglesDescriptor> dawnTogglesData;
91+
if (descriptor.has_value() && descriptor.value()->dawnToggles.has_value()) {
92+
dawnTogglesData = *descriptor.value()->dawnToggles.value();
93+
}
94+
8995
auto creationRuntime = getCreationRuntime();
9096
return _async->postTask(
9197
[this, aDescriptor, descriptor, label = std::move(label),
92-
deviceLostBinding,
98+
deviceLostBinding, dawnTogglesData = std::move(dawnTogglesData),
9399
creationRuntime](const async::AsyncTaskHandle::ResolveFunction &resolve,
94100
const async::AsyncTaskHandle::RejectFunction &reject) {
95101
(void)descriptor;
102+
103+
// Build Dawn toggles chain if provided
104+
wgpu::DawnTogglesDescriptor togglesDesc;
105+
std::vector<const char *> enablePtrs, disablePtrs;
106+
auto localDescriptor = aDescriptor;
107+
108+
if (dawnTogglesData.has_value()) {
109+
const auto &td = *dawnTogglesData;
110+
if (td.enable.has_value() && !td.enable->empty()) {
111+
for (const auto &s : *td.enable) enablePtrs.push_back(s.c_str());
112+
togglesDesc.enabledToggles = enablePtrs.data();
113+
togglesDesc.enabledTogglesCount = enablePtrs.size();
114+
}
115+
if (td.disable.has_value() && !td.disable->empty()) {
116+
for (const auto &s : *td.disable) disablePtrs.push_back(s.c_str());
117+
togglesDesc.disabledToggles = disablePtrs.data();
118+
togglesDesc.disabledTogglesCount = disablePtrs.size();
119+
}
120+
if (!enablePtrs.empty() || !disablePtrs.empty()) {
121+
togglesDesc.nextInChain = localDescriptor.nextInChain;
122+
localDescriptor.nextInChain = &togglesDesc;
123+
}
124+
}
125+
96126
_instance.RequestDevice(
97-
&aDescriptor, wgpu::CallbackMode::AllowProcessEvents,
127+
&localDescriptor, wgpu::CallbackMode::AllowProcessEvents,
98128
[asyncRunner = _async, resolve, reject, label, creationRuntime,
99129
deviceLostBinding](wgpu::RequestDeviceStatus status,
100130
wgpu::Device device,
@@ -131,6 +161,8 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
131161
break;
132162
case wgpu::LoggingType::Verbose:
133163
logLevel = "Verbose";
164+
Logger::logToConsole("%s: %.*s", logLevel,
165+
static_cast<int>(msg.length), msg.data);
134166
break;
135167
case wgpu::LoggingType::Info:
136168
logLevel = "Info";
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
#include <optional>
3+
#include <string>
4+
#include <vector>
5+
#include "JSIConverter.h"
6+
7+
namespace rnwgpu {
8+
9+
struct GPUDawnTogglesDescriptor {
10+
std::optional<std::vector<std::string>> enable;
11+
std::optional<std::vector<std::string>> disable;
12+
};
13+
14+
template <>
15+
struct JSIConverter<std::shared_ptr<GPUDawnTogglesDescriptor>> {
16+
static std::shared_ptr<GPUDawnTogglesDescriptor>
17+
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
18+
auto result = std::make_shared<GPUDawnTogglesDescriptor>();
19+
if (outOfBounds || arg.isNull() || arg.isUndefined()) return result;
20+
auto obj = arg.asObject(runtime);
21+
if (obj.hasProperty(runtime, "enable")) {
22+
result->enable = JSIConverter<std::vector<std::string>>::fromJSI(
23+
runtime, obj.getProperty(runtime, "enable"), false);
24+
}
25+
if (obj.hasProperty(runtime, "disable")) {
26+
result->disable = JSIConverter<std::vector<std::string>>::fromJSI(
27+
runtime, obj.getProperty(runtime, "disable"), false);
28+
}
29+
return result;
30+
}
31+
static jsi::Value toJSI(jsi::Runtime &,
32+
std::shared_ptr<GPUDawnTogglesDescriptor>) {
33+
throw std::runtime_error("GPUDawnTogglesDescriptor: toJSI not supported");
34+
}
35+
};
36+
37+
} // namespace rnwgpu

packages/webgpu/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "WGPULogger.h"
1212

1313
#include "GPUQueueDescriptor.h"
14+
#include "GPUDawnTogglesDescriptor.h"
1415

1516
namespace jsi = facebook::jsi;
1617

@@ -24,6 +25,7 @@ struct GPUDeviceDescriptor {
2425
std::optional<std::shared_ptr<GPUQueueDescriptor>>
2526
defaultQueue; // GPUQueueDescriptor
2627
std::optional<std::string> label; // string
28+
std::optional<std::shared_ptr<GPUDawnTogglesDescriptor>> dawnToggles;
2729
};
2830

2931
} // namespace rnwgpu
@@ -87,6 +89,12 @@ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUDeviceDescriptor>> {
8789
result->label = JSIConverter<std::optional<std::string>>::fromJSI(
8890
runtime, prop, false);
8991
}
92+
if (value.hasProperty(runtime, "dawnToggles")) {
93+
auto prop = value.getProperty(runtime, "dawnToggles");
94+
result->dawnToggles =
95+
JSIConverter<std::optional<std::shared_ptr<GPUDawnTogglesDescriptor>>>::
96+
fromJSI(runtime, prop, false);
97+
}
9098
}
9199

92100
return result;

packages/webgpu/src/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
type SurfacePointer = bigint;
22

3+
/** Dawn固有のデバッグトグル設定 (WebGPU仕様外) */
4+
export interface DawnTogglesDescriptor {
5+
/**
6+
* 有効化するトグル名の配列
7+
* 例: 'dump_shaders', 'use_user_defined_labels_in_backend',
8+
* 'disable_symbol_renaming', 'emit_hlsl_debug_symbols'
9+
*/
10+
enable?: string[];
11+
/** 無効化するトグル名の配列 */
12+
disable?: string[];
13+
}
14+
15+
declare global {
16+
interface GPUDeviceDescriptor {
17+
/** Dawn固有のトグル設定。非Dawn環境では無視される。 */
18+
dawnToggles?: DawnTogglesDescriptor;
19+
}
20+
}
21+
322
export interface NativeCanvas {
423
surface: SurfacePointer;
524
width: number;

0 commit comments

Comments
 (0)