Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions backends/webgpu/runtime/WebGPUDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
#include <cstdlib>
#include <memory>
#include <stdexcept>
#ifdef WGPU_BACKEND_ENABLE_PROFILING
#include <vector>
#endif // WGPU_BACKEND_ENABLE_PROFILING

namespace executorch {
namespace backends {
Expand Down Expand Up @@ -143,16 +141,28 @@ WebGPUContext create_webgpu_context() {
device_desc.requiredLimits = &supported_limits;
}

// Request optional features when the adapter advertises them. A feature the
// adapter lacks is skipped (its fast path stays disabled). A feature the
// adapter advertises becomes required of the device, so if the device were
// to reject it, context creation fails below rather than falling back. The
// vector must outlive wgpuAdapterRequestDevice below (device_desc points
// into it).
std::vector<WGPUFeatureName> required_features;
if (wgpuAdapterHasFeature(ctx.adapter, WGPUFeatureName_ShaderF16)) {
required_features.push_back(WGPUFeatureName_ShaderF16);
ctx.shader_f16_supported = true;
}
#ifdef WGPU_BACKEND_ENABLE_PROFILING
// Bench: enable TimestampQuery if available; fail-open (skip timing if not).
std::vector<WGPUFeatureName> required_features;
if (wgpuAdapterHasFeature(ctx.adapter, WGPUFeatureName_TimestampQuery)) {
required_features.push_back(WGPUFeatureName_TimestampQuery);
device_desc.requiredFeatureCount = required_features.size();
device_desc.requiredFeatures = required_features.data();
ctx.timestamp_supported = true;
}
#endif // WGPU_BACKEND_ENABLE_PROFILING
if (!required_features.empty()) {
device_desc.requiredFeatureCount = required_features.size();
device_desc.requiredFeatures = required_features.data();
}

device_desc.uncapturedErrorCallbackInfo.callback = on_device_error;

Expand Down
3 changes: 3 additions & 0 deletions backends/webgpu/runtime/WebGPUDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ struct WebGPUContext {
WGPUAdapter adapter = nullptr;
WGPUDevice device = nullptr;
WGPUQueue queue = nullptr;
// True if the device was created with the ShaderF16 feature; reserved for a
// future fp16 storage/compute path (fp32 is used when false or unset).
bool shader_f16_supported = false;
#ifdef WGPU_BACKEND_ENABLE_PROFILING
// True if the device was created with the TimestampQuery feature (bench).
bool timestamp_supported = false;
Expand Down
Loading