Skip to content

Commit

Permalink
Replace GPUAdapter::GetProperties() with GPUAdapter::GetInfo()
Browse files Browse the repository at this point in the history
Bug: 335383516
Change-Id: Ic7df2c293555662b41a8ab590cd50dd0b8dc38e1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/193520
Commit-Queue: Fr <[email protected]>
Reviewed-by: Kai Ninomiya <[email protected]>
Reviewed-by: Corentin Wallez <[email protected]>
  • Loading branch information
beaufortfrancois authored and Dawn LUCI CQ committed Sep 11, 2024
1 parent ca2e375 commit 701dd6f
Show file tree
Hide file tree
Showing 37 changed files with 220 additions and 653 deletions.
6 changes: 3 additions & 3 deletions docs/dawn/features/adapter_properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`wgpu::FeatureName::AdapterPropertiesMemoryHeaps` allows querying memory heap information from the adapter.

`wgpu::AdapterPropertiesMemoryHeaps` may be chained on `wgpu::AdapterProperties` in a call to `wgpu::Adapter::GetProperties` in order to query information about the memory heaps on that adapter.
`wgpu::AdapterPropertiesMemoryHeaps` may be chained on `wgpu::AdapterInfo` in a call to `wgpu::Adapter::GetInfo` in order to query information about the memory heaps on that adapter.
The implementation will write out the number of memory heaps and information about each heap.

If `wgpu::FeatureName::AdapterPropertiesMemoryHeaps` is not available, the struct will not be populated.
Expand Down Expand Up @@ -33,7 +33,7 @@ struct MemoryHeapInfo {

`wgpu::FeatureName::AdapterPropertiesD3D` allows querying D3D information from the adapter.

`wgpu::AdapterPropertiesD3D` may be chained on `wgpu::AdapterProperties` in a call to `wgpu::Adapter::GetProperties` in order to query D3D information on that adapter.
`wgpu::AdapterPropertiesD3D` may be chained on `wgpu::AdapterInfo` in a call to `wgpu::Adapter::GetInfo` in order to query D3D information on that adapter.

Adds `wgpu::AdapterPropertiesD3D` which is a struct describing the D3D adapter.
```
Expand All @@ -46,7 +46,7 @@ struct AdapterPropertiesD3D {

`wgpu::FeatureName::AdapterPropertiesVk` allows querying Vulkan information from the adapter.

`wgpu::AdapterPropertiesVk` may be chained on `wgpu::AdapterProperties` in a call to `wgpu::Adapter::GetProperties` in order to query Vulkan information on that adapter.
`wgpu::AdapterPropertiesVk` may be chained on `wgpu::AdapterInfo` in a call to `wgpu::Adapter::GetInfo` in order to query Vulkan information on that adapter.

Adds `wgpu::AdapterPropertiesVk` which is a struct describing the Vulkan adapter.
```
Expand Down
2 changes: 0 additions & 2 deletions include/dawn/native/DawnNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ class DAWN_NATIVE_EXPORT Adapter {
// those in webgpu_cpp.h. Update uses of these methods and remove them.
wgpu::Status GetInfo(wgpu::AdapterInfo* info) const;
wgpu::Status GetInfo(WGPUAdapterInfo* info) const;
wgpu::Status GetProperties(wgpu::AdapterProperties* properties) const;
wgpu::Status GetProperties(WGPUAdapterProperties* properties) const;
std::vector<const char*> GetSupportedFeatures() const;
wgpu::ConvertibleStatus GetLimits(WGPUSupportedLimits* limits) const;

Expand Down
30 changes: 4 additions & 26 deletions src/dawn/dawn.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@
{"name": "info", "type": "adapter info", "annotation": "*"}
]
},
{
"name": "get properties",
"returns": "status",
"args": [
{"name": "properties", "type": "adapter properties", "annotation": "*"}
]
},
{
"name": "has feature",
"returns": "bool",
Expand Down Expand Up @@ -236,21 +229,6 @@
{"name": "compatibility mode", "type": "bool", "default": "false", "tags": ["dawn", "emscripten"]}
]
},
"adapter properties": {
"category": "structure",
"extensible": "out",
"members": [
{"name": "vendor ID", "type": "uint32_t"},
{"name": "vendor name", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
{"name": "architecture", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
{"name": "device ID", "type": "uint32_t"},
{"name": "name", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
{"name": "driver description", "type": "char", "annotation": "const*", "length": "strlen", "default": "nullptr"},
{"name": "adapter type", "type": "adapter type"},
{"name": "backend type", "type": "backend type"},
{"name": "compatibility mode", "type": "bool", "default": "false", "tags": ["dawn", "emscripten"]}
]
},
"adapter type": {
"category": "enum",
"emscripten_no_enum_table": true,
Expand Down Expand Up @@ -4866,7 +4844,7 @@
"dawn adapter properties power preference": {
"category": "structure",
"chained": "out",
"chain roots": ["adapter info", "adapter properties"],
"chain roots": ["adapter info"],
"tags": ["dawn"],
"members": [
{"name": "power preference", "type": "power preference", "default": "undefined"}
Expand Down Expand Up @@ -4894,7 +4872,7 @@
"adapter properties memory heaps": {
"category": "structure",
"chained": "out",
"chain roots": ["adapter info", "adapter properties"],
"chain roots": ["adapter info"],
"tags": ["dawn"],
"members": [
{"name": "heap count", "type": "size_t"},
Expand All @@ -4904,7 +4882,7 @@
"adapter properties D3D": {
"category": "structure",
"chained": "out",
"chain roots": ["adapter info", "adapter properties"],
"chain roots": ["adapter info"],
"tags": ["dawn"],
"members": [
{"name": "shader model", "type": "uint32_t"}
Expand All @@ -4913,7 +4891,7 @@
"adapter properties vk": {
"category": "structure",
"chained": "out",
"chain roots": ["adapter info", "adapter properties"],
"chain roots": ["adapter info"],
"tags": ["dawn"],
"members": [
{"name": "driver version", "type": "uint32_t"}
Expand Down
1 change: 0 additions & 1 deletion src/dawn/dawn_wire.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@
"AdapterGetFormatCapabilities",
"AdapterGetInfo",
"AdapterGetInstance",
"AdapterGetProperties",
"AdapterGetLimits",
"AdapterHasFeature",
"AdapterEnumerateFeatures",
Expand Down
8 changes: 4 additions & 4 deletions src/dawn/fuzzers/DawnWireServerAndD3D12BackendFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return DawnWireServerFuzzer::Run(
data, size,
[](const dawn::native::Adapter& adapter) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
return properties.backendType == wgpu::BackendType::D3D12 &&
properties.adapterType == wgpu::AdapterType::CPU;
wgpu::AdapterInfo info;
adapter.GetInfo(&info);
return info.backendType == wgpu::BackendType::D3D12 &&
info.adapterType == wgpu::AdapterType::CPU;
},
true /* supportsErrorInjection */);
}
6 changes: 3 additions & 3 deletions src/dawn/fuzzers/DawnWireServerAndFrontendFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return DawnWireServerFuzzer::Run(
data, size,
[](const dawn::native::Adapter& adapter) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
return properties.backendType == wgpu::BackendType::Null;
wgpu::AdapterInfo info;
adapter.GetInfo(&info);
return info.backendType == wgpu::BackendType::Null;
},
false /* supportsErrorInjection */);
}
6 changes: 3 additions & 3 deletions src/dawn/fuzzers/DawnWireServerAndVulkanBackendFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
return DawnWireServerFuzzer::Run(
data, size,
[](const dawn::native::Adapter& adapter) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
wgpu::AdapterInfo info;
adapter.GetInfo(&info);

return dawn::gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
return dawn::gpu_info::IsGoogleSwiftshader(info.vendorID, info.deviceID);
},
true /* supportsErrorInjection */);
}
6 changes: 3 additions & 3 deletions src/dawn/fuzzers/lpmfuzz/DawnLPMFuzzerAndVulkanBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {

DEFINE_PROTO_FUZZER(const fuzzing::Program& program) {
DawnLPMFuzzer::Run(program, [](const dawn::native::Adapter& adapter) {
wgpu::AdapterProperties properties;
adapter.GetProperties(&properties);
wgpu::AdapterInfo info;
adapter.GetInfo(&info);

return dawn::gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
return dawn::gpu_info::IsGoogleSwiftshader(info.vendorID, info.deviceID);
});
}
96 changes: 22 additions & 74 deletions src/dawn/native/Adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,55 +125,8 @@ wgpu::Status AdapterBase::APIGetLimits(SupportedLimits* limits) const {
wgpu::Status AdapterBase::APIGetInfo(AdapterInfo* info) const {
DAWN_ASSERT(info != nullptr);

AdapterProperties properties = {};
properties.nextInChain = info->nextInChain;
if (GetPropertiesInternal(&properties) == wgpu::Status::Error) {
return wgpu::Status::Error;
}

// Get lengths, with null terminators.
size_t vendorCLen = mPhysicalDevice->GetVendorName().length() + 1;
size_t architectureCLen = mPhysicalDevice->GetArchitectureName().length() + 1;
size_t deviceCLen = mPhysicalDevice->GetName().length() + 1;
size_t descriptionCLen = mPhysicalDevice->GetDriverDescription().length() + 1;

// Allocate space for all strings.
char* ptr = new char[vendorCLen + architectureCLen + deviceCLen + descriptionCLen];

info->vendor = ptr;
memcpy(ptr, mPhysicalDevice->GetVendorName().c_str(), vendorCLen);
ptr += vendorCLen;

info->architecture = ptr;
memcpy(ptr, mPhysicalDevice->GetArchitectureName().c_str(), architectureCLen);
ptr += architectureCLen;

info->device = ptr;
memcpy(ptr, mPhysicalDevice->GetName().c_str(), deviceCLen);
ptr += deviceCLen;

info->description = ptr;
memcpy(ptr, mPhysicalDevice->GetDriverDescription().c_str(), descriptionCLen);
ptr += descriptionCLen;

info->backendType = mPhysicalDevice->GetBackendType();
info->adapterType = mPhysicalDevice->GetAdapterType();
info->vendorID = mPhysicalDevice->GetVendorId();
info->deviceID = mPhysicalDevice->GetDeviceId();
info->compatibilityMode = mFeatureLevel == FeatureLevel::Compatibility;

return wgpu::Status::Success;
}

wgpu::Status AdapterBase::APIGetProperties(AdapterProperties* properties) const {
mInstance->EmitDeprecationWarning("GetProperties is deprecated, use GetInfo instead.");
return GetPropertiesInternal(properties);
}

wgpu::Status AdapterBase::GetPropertiesInternal(AdapterProperties* properties) const {
DAWN_ASSERT(properties != nullptr);
UnpackedPtr<AdapterProperties> unpacked;
if (mInstance->ConsumedError(ValidateAndUnpack(properties), &unpacked)) {
UnpackedPtr<AdapterInfo> unpacked;
if (mInstance->ConsumedError(ValidateAndUnpack(info), &unpacked)) {
return wgpu::Status::Error;
}

Expand Down Expand Up @@ -203,36 +156,36 @@ wgpu::Status AdapterBase::GetPropertiesInternal(AdapterProperties* properties) c

mPhysicalDevice->PopulateBackendProperties(unpacked);

properties->vendorID = mPhysicalDevice->GetVendorId();
properties->deviceID = mPhysicalDevice->GetDeviceId();
properties->adapterType = mPhysicalDevice->GetAdapterType();
properties->backendType = mPhysicalDevice->GetBackendType();
properties->compatibilityMode = mFeatureLevel == FeatureLevel::Compatibility;

// Get lengths, with null terminators.
size_t vendorNameCLen = mPhysicalDevice->GetVendorName().length() + 1;
size_t vendorCLen = mPhysicalDevice->GetVendorName().length() + 1;
size_t architectureCLen = mPhysicalDevice->GetArchitectureName().length() + 1;
size_t nameCLen = mPhysicalDevice->GetName().length() + 1;
size_t driverDescriptionCLen = mPhysicalDevice->GetDriverDescription().length() + 1;
size_t deviceCLen = mPhysicalDevice->GetName().length() + 1;
size_t descriptionCLen = mPhysicalDevice->GetDriverDescription().length() + 1;

// Allocate space for all strings.
char* ptr = new char[vendorNameCLen + architectureCLen + nameCLen + driverDescriptionCLen];
char* ptr = new char[vendorCLen + architectureCLen + deviceCLen + descriptionCLen];

properties->vendorName = ptr;
memcpy(ptr, mPhysicalDevice->GetVendorName().c_str(), vendorNameCLen);
ptr += vendorNameCLen;
info->vendor = ptr;
memcpy(ptr, mPhysicalDevice->GetVendorName().c_str(), vendorCLen);
ptr += vendorCLen;

properties->architecture = ptr;
info->architecture = ptr;
memcpy(ptr, mPhysicalDevice->GetArchitectureName().c_str(), architectureCLen);
ptr += architectureCLen;

properties->name = ptr;
memcpy(ptr, mPhysicalDevice->GetName().c_str(), nameCLen);
ptr += nameCLen;
info->device = ptr;
memcpy(ptr, mPhysicalDevice->GetName().c_str(), deviceCLen);
ptr += deviceCLen;

properties->driverDescription = ptr;
memcpy(ptr, mPhysicalDevice->GetDriverDescription().c_str(), driverDescriptionCLen);
ptr += driverDescriptionCLen;
info->description = ptr;
memcpy(ptr, mPhysicalDevice->GetDriverDescription().c_str(), descriptionCLen);
ptr += descriptionCLen;

info->backendType = mPhysicalDevice->GetBackendType();
info->adapterType = mPhysicalDevice->GetAdapterType();
info->vendorID = mPhysicalDevice->GetVendorId();
info->deviceID = mPhysicalDevice->GetDeviceId();
info->compatibilityMode = mFeatureLevel == FeatureLevel::Compatibility;

return wgpu::Status::Success;
}
Expand All @@ -242,11 +195,6 @@ void APIAdapterInfoFreeMembers(WGPUAdapterInfo info) {
delete[] info.vendor;
}

void APIAdapterPropertiesFreeMembers(WGPUAdapterProperties properties) {
// This single delete is enough because everything is a single allocation.
delete[] properties.vendorName;
}

void APIAdapterPropertiesMemoryHeapsFreeMembers(
WGPUAdapterPropertiesMemoryHeaps memoryHeapProperties) {
delete[] memoryHeapProperties.heapInfo;
Expand Down
3 changes: 0 additions & 3 deletions src/dawn/native/Adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class AdapterBase : public RefCounted, public WeakRefSupport<AdapterBase> {
InstanceBase* APIGetInstance() const;
wgpu::Status APIGetLimits(SupportedLimits* limits) const;
wgpu::Status APIGetInfo(AdapterInfo* info) const;
wgpu::Status APIGetProperties(AdapterProperties* properties) const;
bool APIHasFeature(wgpu::FeatureName feature) const;
size_t APIEnumerateFeatures(wgpu::FeatureName* features) const;
void APIRequestDevice(const DeviceDescriptor* descriptor,
Expand Down Expand Up @@ -93,8 +92,6 @@ class AdapterBase : public RefCounted, public WeakRefSupport<AdapterBase> {
const std::string& GetName() const;

private:
wgpu::Status GetPropertiesInternal(AdapterProperties* properties) const;

std::pair<Ref<DeviceBase::DeviceLostEvent>, ResultOrError<Ref<DeviceBase>>> CreateDevice(
const DeviceDescriptor* rawDescriptor);
ResultOrError<Ref<DeviceBase>> CreateDeviceInternal(const DeviceDescriptor* rawDescriptor,
Expand Down
8 changes: 0 additions & 8 deletions src/dawn/native/DawnNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ wgpu::Status Adapter::GetInfo(WGPUAdapterInfo* info) const {
return mImpl->APIGetInfo(FromAPI(info));
}

wgpu::Status Adapter::GetProperties(wgpu::AdapterProperties* properties) const {
return GetProperties(reinterpret_cast<WGPUAdapterProperties*>(properties));
}

wgpu::Status Adapter::GetProperties(WGPUAdapterProperties* properties) const {
return mImpl->APIGetProperties(FromAPI(properties));
}

WGPUAdapter Adapter::Get() const {
return ToAPI(mImpl);
}
Expand Down
2 changes: 1 addition & 1 deletion src/dawn/native/PhysicalDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class PhysicalDeviceBase : public RefCounted {
const TogglesState& toggles) const;

// Populate backend properties. Ownership of allocations written are owned by the caller.
virtual void PopulateBackendProperties(UnpackedPtr<AdapterProperties>& properties) const = 0;
virtual void PopulateBackendProperties(UnpackedPtr<AdapterInfo>& info) const = 0;

// Populate backend format capabilities. Ownership of allocations written are owned by the
// caller.
Expand Down
6 changes: 3 additions & 3 deletions src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ MaybeError PhysicalDevice::ResetInternalDeviceForTestingImpl() {
return {};
}

void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterProperties>& properties) const {
if (auto* memoryHeapProperties = properties.Get<AdapterPropertiesMemoryHeaps>()) {
void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterInfo>& info) const {
if (auto* memoryHeapProperties = info.Get<AdapterPropertiesMemoryHeaps>()) {
// https://microsoft.github.io/DirectX-Specs/d3d/D3D12GPUUploadHeaps.html describes
// the properties of D3D12 Default/Upload/Readback heaps. The assumption is that these are
// roughly how D3D11 allocates memory has well.
Expand Down Expand Up @@ -336,7 +336,7 @@ void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterProperties>& p
wgpu::HeapProperty::HostUncached | wgpu::HeapProperty::HostCached;
}
}
if (auto* d3dProperties = properties.Get<AdapterPropertiesD3D>()) {
if (auto* d3dProperties = info.Get<AdapterPropertiesD3D>()) {
d3dProperties->shaderModel = GetDeviceInfo().shaderModel;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dawn/native/d3d11/PhysicalDeviceD3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class PhysicalDevice : public d3d::PhysicalDevice {
wgpu::FeatureName feature,
const TogglesState& toggles) const override;

void PopulateBackendProperties(UnpackedPtr<AdapterProperties>& properties) const override;
void PopulateBackendProperties(UnpackedPtr<AdapterInfo>& info) const override;

const bool mIsSharedD3D11Device;
ComPtr<ID3D11Device> mD3D11Device;
Expand Down
6 changes: 3 additions & 3 deletions src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ MaybeError PhysicalDevice::ResetInternalDeviceForTestingImpl() {
return {};
}

void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterProperties>& properties) const {
if (auto* memoryHeapProperties = properties.Get<AdapterPropertiesMemoryHeaps>()) {
void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterInfo>& info) const {
if (auto* memoryHeapProperties = info.Get<AdapterPropertiesMemoryHeaps>()) {
// https://microsoft.github.io/DirectX-Specs/d3d/D3D12GPUUploadHeaps.html describes
// the properties of D3D12 Default/Upload/Readback heaps.
if (mDeviceInfo.isUMA) {
Expand Down Expand Up @@ -849,7 +849,7 @@ void PhysicalDevice::PopulateBackendProperties(UnpackedPtr<AdapterProperties>& p
wgpu::HeapProperty::HostUncached | wgpu::HeapProperty::HostCached;
}
}
if (auto* d3dProperties = properties.Get<AdapterPropertiesD3D>()) {
if (auto* d3dProperties = info.Get<AdapterPropertiesD3D>()) {
// Report highest supported shader model version, instead of actual applied version.
d3dProperties->shaderModel = GetDeviceInfo().highestSupportedShaderModel;
}
Expand Down
2 changes: 1 addition & 1 deletion src/dawn/native/d3d12/PhysicalDeviceD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PhysicalDevice : public d3d::PhysicalDevice {
MaybeError InitializeDebugLayerFilters();
void CleanUpDebugLayerFilters();

void PopulateBackendProperties(UnpackedPtr<AdapterProperties>& properties) const override;
void PopulateBackendProperties(UnpackedPtr<AdapterInfo>& info) const override;

ComPtr<ID3D12Device> mD3d12Device;

Expand Down
Loading

0 comments on commit 701dd6f

Please sign in to comment.