diff --git a/src/dawn_node/binding/CMakeLists.txt b/src/dawn_node/binding/CMakeLists.txt index 8627199a6c..b45ad6a338 100644 --- a/src/dawn_node/binding/CMakeLists.txt +++ b/src/dawn_node/binding/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(dawn_node_binding STATIC "Errors.h" "GPU.cpp" "GPU.h" + "GPUAdapter.cpp" "GPUAdapter.h" "GPUBindGroup.cpp" "GPUBindGroup.h" diff --git a/src/dawn_node/binding/GPUAdapter.cpp b/src/dawn_node/binding/GPUAdapter.cpp new file mode 100644 index 0000000000..0d473045b3 --- /dev/null +++ b/src/dawn_node/binding/GPUAdapter.cpp @@ -0,0 +1,61 @@ +// 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 "src/dawn_node/binding/GPUAdapter.h" + +#include "src/dawn_node/binding/GPUDevice.h" +#include "src/dawn_node/binding/GPUSupportedLimits.h" + +namespace wgpu { namespace binding { + + //////////////////////////////////////////////////////////////////////////////// + // wgpu::bindings::GPUAdapter + // TODO(crbug.com/dawn/1133): This is a stub implementation. Properly implement. + //////////////////////////////////////////////////////////////////////////////// + GPUAdapter::GPUAdapter(dawn_native::Adapter a) : adapter_(a) { + } + + std::string GPUAdapter::getName(Napi::Env) { + return "dawn-adapter"; + } + + interop::Interface GPUAdapter::getFeatures(Napi::Env env) { + class Features : public interop::GPUSupportedFeatures {}; + return interop::GPUSupportedFeatures::Create(env); + } + + interop::Interface GPUAdapter::getLimits(Napi::Env env) { + return interop::GPUSupportedLimits::Create(env); + } + + bool GPUAdapter::getIsFallbackAdapter(Napi::Env) { + UNIMPLEMENTED(); + } + + interop::Promise> GPUAdapter::requestDevice( + Napi::Env env, + std::optional descriptor) { + dawn_native::DeviceDescriptor desc{}; // TODO(crbug.com/dawn/1133): Fill in. + interop::Promise> promise(env); + + auto wgpu_device = adapter_.CreateDevice(&desc); + if (wgpu_device) { + promise.Resolve(interop::GPUDevice::Create(env, env, wgpu_device)); + } else { + Napi::Error::New(env, "failed to create device").ThrowAsJavaScriptException(); + } + return promise; + } + +}} // namespace wgpu::binding