From 72ba3039eb24f833462526c1c2d46c3a1462247a Mon Sep 17 00:00:00 2001 From: James Price Date: Fri, 7 Jan 2022 09:19:08 +0000 Subject: [PATCH] dawn_node: Fix default adapter selection The Null adapter was always being used when no backend override was specified, instead of the platform's default adapter. Change-Id: I3d8ae62aacda1309a141c3ca39d6e03252fc5e94 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/75700 Auto-Submit: James Price Reviewed-by: Ben Clayton Commit-Queue: Ben Clayton --- src/dawn_node/binding/GPU.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/dawn_node/binding/GPU.cpp b/src/dawn_node/binding/GPU.cpp index 9cbb41341a..c123c1ebc5 100644 --- a/src/dawn_node/binding/GPU.cpp +++ b/src/dawn_node/binding/GPU.cpp @@ -136,21 +136,25 @@ namespace wgpu::binding { promise.Reject("unknown backend '" + forceBackend + "'"); return promise; } + } - bool found = false; - for (size_t i = 0; i < adapters.size(); ++i) { - wgpu::AdapterProperties props; - adapters[i].GetProperties(&props); - if (props.backendType == targetBackendType) { - adapterIndex = i; - found = true; - break; - } + bool found = false; + for (size_t i = 0; i < adapters.size(); ++i) { + wgpu::AdapterProperties props; + adapters[i].GetProperties(&props); + if (props.backendType == targetBackendType) { + adapterIndex = i; + found = true; + break; } - if (!found) { + } + if (!found) { + if (!forceBackend.empty()) { promise.Reject("backend '" + forceBackend + "' not found"); - return promise; + } else { + promise.Reject("no suitable backends found"); } + return promise; } auto adapter = GPUAdapter::Create(env, adapters[adapterIndex], flags_);