diff --git a/src/dawn/node/binding/CMakeLists.txt b/src/dawn/node/binding/CMakeLists.txt index a4e427b253..55c3713876 100644 --- a/src/dawn/node/binding/CMakeLists.txt +++ b/src/dawn/node/binding/CMakeLists.txt @@ -25,6 +25,8 @@ add_library(dawn_node_binding STATIC "GPU.h" "GPUAdapter.cpp" "GPUAdapter.h" + "GPUAdapterInfo.cpp" + "GPUAdapterInfo.h" "GPUBindGroup.cpp" "GPUBindGroup.h" "GPUBindGroupLayout.cpp" diff --git a/src/dawn/node/binding/GPUAdapter.cpp b/src/dawn/node/binding/GPUAdapter.cpp index 3b18ffade9..e65378d0cb 100644 --- a/src/dawn/node/binding/GPUAdapter.cpp +++ b/src/dawn/node/binding/GPUAdapter.cpp @@ -21,6 +21,7 @@ #include "src/dawn/node/binding/Converter.h" #include "src/dawn/node/binding/Errors.h" #include "src/dawn/node/binding/Flags.h" +#include "src/dawn/node/binding/GPUAdapterInfo.h" #include "src/dawn/node/binding/GPUDevice.h" #include "src/dawn/node/binding/GPUSupportedFeatures.h" #include "src/dawn/node/binding/GPUSupportedLimits.h" @@ -203,9 +204,15 @@ interop::Promise> GPUAdapter::requestDevi } interop::Promise> GPUAdapter::requestAdapterInfo( - Napi::Env, + Napi::Env env, std::vector unmaskHints) { - UNIMPLEMENTED(); + interop::Promise> promise(env, PROMISE_INFO); + + WGPUAdapterProperties adapterProperties = {}; + adapter_.GetProperties(&adapterProperties); + + promise.Resolve(interop::GPUAdapterInfo::Create(env, adapterProperties)); + return promise; } } // namespace wgpu::binding diff --git a/src/dawn/node/binding/GPUAdapterInfo.cpp b/src/dawn/node/binding/GPUAdapterInfo.cpp new file mode 100644 index 0000000000..8263f4fe6b --- /dev/null +++ b/src/dawn/node/binding/GPUAdapterInfo.cpp @@ -0,0 +1,45 @@ +// Copyright 2023 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/GPUAdapterInfo.h" + +namespace wgpu::binding { + +//////////////////////////////////////////////////////////////////////////////// +// wgpu::bindings::GPUAdapterInfo +//////////////////////////////////////////////////////////////////////////////// + +GPUAdapterInfo::GPUAdapterInfo(WGPUAdapterProperties properties) + : vendor_(properties.vendorName), + architecture_(properties.architecture), + device_(properties.name), + description_(properties.driverDescription) {} + +std::string GPUAdapterInfo::getVendor(Napi::Env) { + return vendor_; +} + +std::string GPUAdapterInfo::getArchitecture(Napi::Env) { + return architecture_; +} + +std::string GPUAdapterInfo::getDevice(Napi::Env) { + return device_; +} + +std::string GPUAdapterInfo::getDescription(Napi::Env) { + return description_; +} + +} // namespace wgpu::binding diff --git a/src/dawn/node/binding/GPUAdapterInfo.h b/src/dawn/node/binding/GPUAdapterInfo.h new file mode 100644 index 0000000000..890322a8eb --- /dev/null +++ b/src/dawn/node/binding/GPUAdapterInfo.h @@ -0,0 +1,48 @@ +// Copyright 2023 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. + +#ifndef SRC_DAWN_NODE_BINDING_GPUADAPTERINFO_H_ +#define SRC_DAWN_NODE_BINDING_GPUADAPTERINFO_H_ + +#include + +#include "dawn/native/DawnNative.h" +#include "dawn/webgpu_cpp.h" + +#include "src/dawn/node/interop/Napi.h" +#include "src/dawn/node/interop/WebGPU.h" + +namespace wgpu::binding { + +// GPUAdapterInfo is an implementation of interop::GPUAdapterInfo. +class GPUAdapterInfo final : public interop::GPUAdapterInfo { + public: + explicit GPUAdapterInfo(WGPUAdapterProperties); + + // interop::GPUAdapterInfo interface compliance + std::string getVendor(Napi::Env) override; + std::string getArchitecture(Napi::Env) override; + std::string getDevice(Napi::Env) override; + std::string getDescription(Napi::Env) override; + + private: + std::string vendor_; + std::string architecture_; + std::string device_; + std::string description_; +}; + +} // namespace wgpu::binding + +#endif // SRC_DAWN_NODE_BINDING_GPUADAPTERINFO_H_