diff --git a/src/dawn/node/binding/GPUAdapter.cpp b/src/dawn/node/binding/GPUAdapter.cpp index c56b8d6ad1..3f7aa6cc4f 100644 --- a/src/dawn/node/binding/GPUAdapter.cpp +++ b/src/dawn/node/binding/GPUAdapter.cpp @@ -124,6 +124,13 @@ interop::Interface GPUAdapter::getLimits(Napi::Env interop::Interface GPUAdapter::getInfo(Napi::Env env) { wgpu::AdapterInfo info = {}; + wgpu::AdapterPropertiesSubgroups subgroupProperties = {}; + + wgpu::Adapter wgpuAdapter = adapter_.Get(); + if (wgpuAdapter.HasFeature(FeatureName::Subgroups)) { + info.nextInChain = &subgroupProperties; + } + adapter_.GetInfo(&info); return interop::GPUAdapterInfo::Create(env, info); diff --git a/src/dawn/node/binding/GPUAdapterInfo.cpp b/src/dawn/node/binding/GPUAdapterInfo.cpp index 80c75c9e1d..4aeca3335a 100644 --- a/src/dawn/node/binding/GPUAdapterInfo.cpp +++ b/src/dawn/node/binding/GPUAdapterInfo.cpp @@ -40,7 +40,16 @@ GPUAdapterInfo::GPUAdapterInfo(const wgpu::AdapterInfo& info) : vendor_(info.vendor), architecture_(info.architecture), device_(info.device), - description_(info.description) {} + description_(info.description) { + for (wgpu::ChainedStructOut* chain = info.nextInChain; chain; chain = chain->nextInChain) { + if (chain->sType == wgpu::SType::AdapterPropertiesSubgroups) { + subgroup_properties_ = *static_cast(chain); + // Clear to prevent using invalid pointer. + subgroup_properties_->nextInChain = nullptr; + break; + } + } +} std::string GPUAdapterInfo::getVendor(Napi::Env) { return vendor_; @@ -58,4 +67,18 @@ std::string GPUAdapterInfo::getDescription(Napi::Env) { return description_; } +std::variant GPUAdapterInfo::getSubgroupMinSize(Napi::Env) { + if (subgroup_properties_.has_value()) { + return subgroup_properties_->subgroupMinSize; + } + return interop::Undefined; +} + +std::variant GPUAdapterInfo::getSubgroupMaxSize(Napi::Env) { + if (subgroup_properties_.has_value()) { + return subgroup_properties_->subgroupMaxSize; + } + return interop::Undefined; +} + } // namespace wgpu::binding diff --git a/src/dawn/node/binding/GPUAdapterInfo.h b/src/dawn/node/binding/GPUAdapterInfo.h index 965d2da814..d5e84c4c27 100644 --- a/src/dawn/node/binding/GPUAdapterInfo.h +++ b/src/dawn/node/binding/GPUAdapterInfo.h @@ -48,12 +48,15 @@ class GPUAdapterInfo final : public interop::GPUAdapterInfo { std::string getArchitecture(Napi::Env) override; std::string getDevice(Napi::Env) override; std::string getDescription(Napi::Env) override; + std::variant getSubgroupMinSize(Napi::Env) override; + std::variant getSubgroupMaxSize(Napi::Env) override; private: std::string vendor_; std::string architecture_; std::string device_; std::string description_; + std::optional subgroup_properties_; }; } // namespace wgpu::binding diff --git a/src/dawn/node/binding/GPUSupportedLimits.cpp b/src/dawn/node/binding/GPUSupportedLimits.cpp index 48353e6aa4..aa7449c7d8 100644 --- a/src/dawn/node/binding/GPUSupportedLimits.cpp +++ b/src/dawn/node/binding/GPUSupportedLimits.cpp @@ -173,6 +173,7 @@ uint32_t GPUSupportedLimits::getMaxComputeWorkgroupsPerDimension(Napi::Env) { return limits_.limits.maxComputeWorkgroupsPerDimension; } +// TODO(crbug.com/354751907) Move to GPUAdapterInfo std::variant GPUSupportedLimits::getMinSubgroupSize(Napi::Env) { if (subgroup_limits_.has_value()) { return subgroup_limits_->minSubgroupSize; @@ -180,6 +181,7 @@ std::variant GPUSupportedLimits::getMinSubgrou return interop::Undefined; } +// TODO(crbug.com/354751907) Move to GPUAdapterInfo std::variant GPUSupportedLimits::getMaxSubgroupSize(Napi::Env) { if (subgroup_limits_.has_value()) { return subgroup_limits_->maxSubgroupSize; diff --git a/src/dawn/node/binding/GPUSupportedLimits.h b/src/dawn/node/binding/GPUSupportedLimits.h index 7e9a9cb623..f6c0201517 100644 --- a/src/dawn/node/binding/GPUSupportedLimits.h +++ b/src/dawn/node/binding/GPUSupportedLimits.h @@ -73,6 +73,7 @@ class GPUSupportedLimits final : public interop::GPUSupportedLimits { uint32_t getMaxComputeWorkgroupSizeY(Napi::Env) override; uint32_t getMaxComputeWorkgroupSizeZ(Napi::Env) override; uint32_t getMaxComputeWorkgroupsPerDimension(Napi::Env) override; + // TODO(354751907) Move subgroup min and max sizes to AdapterInfo std::variant getMinSubgroupSize(Napi::Env) override; std::variant getMaxSubgroupSize(Napi::Env) override; diff --git a/src/dawn/node/interop/DawnExtensions.idl b/src/dawn/node/interop/DawnExtensions.idl index 27d0ad1f1c..71ddb15655 100644 --- a/src/dawn/node/interop/DawnExtensions.idl +++ b/src/dawn/node/interop/DawnExtensions.idl @@ -44,6 +44,13 @@ interface GPUAdapter { readonly attribute boolean isCompatibilityMode; }; +// Not in webgpu.idl yet +interface GPUAdapterInfo { + readonly attribute (unsigned long or undefined) subgroupMinSize; + readonly attribute (unsigned long or undefined) subgroupMaxSize; +}; + + interface GPUCommandEncoder { undefined writeTimestamp(GPUQuerySet querySet, GPUSize32 queryIndex); }; @@ -68,6 +75,7 @@ enum WGSLFeatureName { "pointer_composite_access", }; +// TODO(crbug.com/354751907) Move to GPUAdapterInfo interface GPUSupportedLimits { readonly attribute (unsigned long or undefined) minSubgroupSize; readonly attribute (unsigned long or undefined) maxSubgroupSize;