Skip to content

Commit

Permalink
[node] Expose subgroupMinSize, subgroupMaxSize in GPUAdapterInfo
Browse files Browse the repository at this point in the history
Bug: 354751907
Change-Id: Ib89ce4d66b47062c676a87d19f89dcee6c697ac7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/216254
Reviewed-by: Loko Kung <[email protected]>
Commit-Queue: David Neto <[email protected]>
  • Loading branch information
dneto0 authored and Dawn LUCI CQ committed Dec 5, 2024
1 parent 1dd1bc3 commit ce17851
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/dawn/node/binding/GPUAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ interop::Interface<interop::GPUSupportedLimits> GPUAdapter::getLimits(Napi::Env

interop::Interface<interop::GPUAdapterInfo> 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<GPUAdapterInfo>(env, info);
Expand Down
25 changes: 24 additions & 1 deletion src/dawn/node/binding/GPUAdapterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wgpu::AdapterPropertiesSubgroups*>(chain);
// Clear to prevent using invalid pointer.
subgroup_properties_->nextInChain = nullptr;
break;
}
}
}

std::string GPUAdapterInfo::getVendor(Napi::Env) {
return vendor_;
Expand All @@ -58,4 +67,18 @@ std::string GPUAdapterInfo::getDescription(Napi::Env) {
return description_;
}

std::variant<uint32_t, interop::UndefinedType> GPUAdapterInfo::getSubgroupMinSize(Napi::Env) {
if (subgroup_properties_.has_value()) {
return subgroup_properties_->subgroupMinSize;
}
return interop::Undefined;
}

std::variant<uint32_t, interop::UndefinedType> GPUAdapterInfo::getSubgroupMaxSize(Napi::Env) {
if (subgroup_properties_.has_value()) {
return subgroup_properties_->subgroupMaxSize;
}
return interop::Undefined;
}

} // namespace wgpu::binding
3 changes: 3 additions & 0 deletions src/dawn/node/binding/GPUAdapterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, interop::UndefinedType> getSubgroupMinSize(Napi::Env) override;
std::variant<uint32_t, interop::UndefinedType> getSubgroupMaxSize(Napi::Env) override;

private:
std::string vendor_;
std::string architecture_;
std::string device_;
std::string description_;
std::optional<wgpu::AdapterPropertiesSubgroups> subgroup_properties_;
};

} // namespace wgpu::binding
Expand Down
2 changes: 2 additions & 0 deletions src/dawn/node/binding/GPUSupportedLimits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,15 @@ uint32_t GPUSupportedLimits::getMaxComputeWorkgroupsPerDimension(Napi::Env) {
return limits_.limits.maxComputeWorkgroupsPerDimension;
}

// TODO(crbug.com/354751907) Move to GPUAdapterInfo
std::variant<uint32_t, interop::UndefinedType> GPUSupportedLimits::getMinSubgroupSize(Napi::Env) {
if (subgroup_limits_.has_value()) {
return subgroup_limits_->minSubgroupSize;
}
return interop::Undefined;
}

// TODO(crbug.com/354751907) Move to GPUAdapterInfo
std::variant<uint32_t, interop::UndefinedType> GPUSupportedLimits::getMaxSubgroupSize(Napi::Env) {
if (subgroup_limits_.has_value()) {
return subgroup_limits_->maxSubgroupSize;
Expand Down
1 change: 1 addition & 0 deletions src/dawn/node/binding/GPUSupportedLimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, interop::UndefinedType> getMinSubgroupSize(Napi::Env) override;
std::variant<uint32_t, interop::UndefinedType> getMaxSubgroupSize(Napi::Env) override;

Expand Down
8 changes: 8 additions & 0 deletions src/dawn/node/interop/DawnExtensions.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -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;
Expand Down

0 comments on commit ce17851

Please sign in to comment.