From f07477a1cef3a16e65e8e99e6ba839c485e56e7c Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 11 Jan 2022 09:30:34 +0000 Subject: [PATCH] Remove deprecated DawnNative Adapter getters. Bug: dawn:824 Change-Id: I4e73598ccd8eb5ce85c8a0ed86629daef4b575c6 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/75584 Reviewed-by: Brandon Jones Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez --- src/dawn_native/Adapter.cpp | 36 ++++++++----------- src/dawn_native/Adapter.h | 9 ++--- src/dawn_native/DawnNative.cpp | 49 ++------------------------ src/dawn_native/d3d12/AdapterD3D12.cpp | 6 ++-- src/dawn_native/d3d12/D3D12Info.cpp | 2 +- src/dawn_native/d3d12/DeviceD3D12.cpp | 11 +++--- src/dawn_native/metal/BackendMTL.mm | 8 ++--- src/dawn_native/metal/DeviceMTL.mm | 14 ++++---- src/dawn_native/null/DeviceNull.cpp | 4 ++- src/dawn_native/opengl/BackendGL.cpp | 6 ++-- src/dawn_native/vulkan/AdapterVk.cpp | 6 ++-- src/include/dawn_native/DawnNative.h | 30 ---------------- src/tests/DawnTest.cpp | 18 +++++----- src/tests/DawnTest.h | 2 +- 14 files changed, 62 insertions(+), 139 deletions(-) diff --git a/src/dawn_native/Adapter.cpp b/src/dawn_native/Adapter.cpp index d4355266db..f8a5d91c59 100644 --- a/src/dawn_native/Adapter.cpp +++ b/src/dawn_native/Adapter.cpp @@ -33,14 +33,12 @@ namespace dawn_native { InitializeSupportedFeaturesImpl(), "gathering supported features for \"%s\" - \"%s\" (vendorId=%#06x deviceId=%#06x " "backend=%s type=%s)", - mPCIInfo.name, mDriverDescription, mPCIInfo.vendorId, mPCIInfo.deviceId, mBackend, - mAdapterType); + mName, mDriverDescription, mVendorId, mDeviceId, mBackend, mAdapterType); DAWN_TRY_CONTEXT( InitializeSupportedLimitsImpl(&mLimits), "gathering supported limits for \"%s\" - \"%s\" (vendorId=%#06x deviceId=%#06x " "backend=%s type=%s)", - mPCIInfo.name, mDriverDescription, mPCIInfo.vendorId, mPCIInfo.deviceId, mBackend, - mAdapterType); + mName, mDriverDescription, mVendorId, mDeviceId, mBackend, mAdapterType); // Enforce internal Dawn constants. mLimits.v1.maxVertexBufferArrayStride = @@ -77,9 +75,9 @@ namespace dawn_native { } void AdapterBase::APIGetProperties(AdapterProperties* properties) const { - properties->vendorID = mPCIInfo.vendorId; - properties->deviceID = mPCIInfo.deviceId; - properties->name = mPCIInfo.name.c_str(); + properties->vendorID = mVendorId; + properties->deviceID = mDeviceId; + properties->name = mName.c_str(); properties->driverDescription = mDriverDescription.c_str(); properties->adapterType = mAdapterType; properties->backendType = mBackend; @@ -125,22 +123,18 @@ namespace dawn_native { callback(status, ToAPI(device.Detach()), nullptr, userdata); } + uint32_t AdapterBase::GetVendorId() const { + return mVendorId; + } + + uint32_t AdapterBase::GetDeviceId() const { + return mDeviceId; + } + wgpu::BackendType AdapterBase::GetBackendType() const { return mBackend; } - wgpu::AdapterType AdapterBase::GetAdapterType() const { - return mAdapterType; - } - - const std::string& AdapterBase::GetDriverDescription() const { - return mDriverDescription; - } - - const PCIInfo& AdapterBase::GetPCIInfo() const { - return mPCIInfo; - } - InstanceBase* AdapterBase::GetInstance() const { return mInstance; } @@ -161,8 +155,8 @@ namespace dawn_native { WGPUDeviceProperties AdapterBase::GetAdapterProperties() const { WGPUDeviceProperties adapterProperties = {}; - adapterProperties.deviceID = mPCIInfo.deviceId; - adapterProperties.vendorID = mPCIInfo.vendorId; + adapterProperties.deviceID = mDeviceId; + adapterProperties.vendorID = mVendorId; adapterProperties.adapterType = static_cast(mAdapterType); mSupportedFeatures.InitializeDeviceProperties(&adapterProperties); diff --git a/src/dawn_native/Adapter.h b/src/dawn_native/Adapter.h index 12de0aa188..3636bfcff5 100644 --- a/src/dawn_native/Adapter.h +++ b/src/dawn_native/Adapter.h @@ -47,10 +47,9 @@ namespace dawn_native { void* userdata); DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr); + uint32_t GetVendorId() const; + uint32_t GetDeviceId() const; wgpu::BackendType GetBackendType() const; - wgpu::AdapterType GetAdapterType() const; - const std::string& GetDriverDescription() const; - const PCIInfo& GetPCIInfo() const; InstanceBase* GetInstance() const; void ResetInternalDeviceForTesting(); @@ -67,7 +66,9 @@ namespace dawn_native { virtual bool SupportsExternalImages() const = 0; protected: - PCIInfo mPCIInfo = {}; + uint32_t mVendorId = 0xFFFFFFFF; + uint32_t mDeviceId = 0xFFFFFFFF; + std::string mName; wgpu::AdapterType mAdapterType = wgpu::AdapterType::Unknown; std::string mDriverDescription; FeaturesSet mSupportedFeatures; diff --git a/src/dawn_native/DawnNative.cpp b/src/dawn_native/DawnNative.cpp index 80772f02e3..3736dc10a5 100644 --- a/src/dawn_native/DawnNative.cpp +++ b/src/dawn_native/DawnNative.cpp @@ -86,56 +86,11 @@ namespace dawn_native { Adapter& Adapter::operator=(const Adapter& other) = default; void Adapter::GetProperties(wgpu::AdapterProperties* properties) const { - properties->backendType = mImpl->GetBackendType(); - properties->adapterType = mImpl->GetAdapterType(); - properties->driverDescription = mImpl->GetDriverDescription().c_str(); - properties->deviceID = mImpl->GetPCIInfo().deviceId; - properties->vendorID = mImpl->GetPCIInfo().vendorId; - properties->name = mImpl->GetPCIInfo().name.c_str(); + GetProperties(reinterpret_cast(properties)); } void Adapter::GetProperties(WGPUAdapterProperties* properties) const { - GetProperties(reinterpret_cast(properties)); - } - - BackendType Adapter::GetBackendType() const { - switch (mImpl->GetBackendType()) { - case wgpu::BackendType::D3D12: - return BackendType::D3D12; - case wgpu::BackendType::Metal: - return BackendType::Metal; - case wgpu::BackendType::Null: - return BackendType::Null; - case wgpu::BackendType::OpenGL: - return BackendType::OpenGL; - case wgpu::BackendType::Vulkan: - return BackendType::Vulkan; - case wgpu::BackendType::OpenGLES: - return BackendType::OpenGLES; - - case wgpu::BackendType::D3D11: - case wgpu::BackendType::WebGPU: - break; - } - UNREACHABLE(); - } - - DeviceType Adapter::GetDeviceType() const { - switch (mImpl->GetAdapterType()) { - case wgpu::AdapterType::DiscreteGPU: - return DeviceType::DiscreteGPU; - case wgpu::AdapterType::IntegratedGPU: - return DeviceType::IntegratedGPU; - case wgpu::AdapterType::CPU: - return DeviceType::CPU; - case wgpu::AdapterType::Unknown: - return DeviceType::Unknown; - } - UNREACHABLE(); - } - - const PCIInfo& Adapter::GetPCIInfo() const { - return mImpl->GetPCIInfo(); + mImpl->APIGetProperties(FromAPI(properties)); } WGPUAdapter Adapter::Get() const { diff --git a/src/dawn_native/d3d12/AdapterD3D12.cpp b/src/dawn_native/d3d12/AdapterD3D12.cpp index e2182e794c..1f17979f7d 100644 --- a/src/dawn_native/d3d12/AdapterD3D12.cpp +++ b/src/dawn_native/d3d12/AdapterD3D12.cpp @@ -76,9 +76,9 @@ namespace dawn_native::d3d12 { DXGI_ADAPTER_DESC1 adapterDesc; mHardwareAdapter->GetDesc1(&adapterDesc); - mPCIInfo.deviceId = adapterDesc.DeviceId; - mPCIInfo.vendorId = adapterDesc.VendorId; - mPCIInfo.name = WCharToUTF8(adapterDesc.Description); + mDeviceId = adapterDesc.DeviceId; + mVendorId = adapterDesc.VendorId; + mName = WCharToUTF8(adapterDesc.Description); DAWN_TRY_ASSIGN(mDeviceInfo, GatherDeviceInfo(*this)); diff --git a/src/dawn_native/d3d12/D3D12Info.cpp b/src/dawn_native/d3d12/D3D12Info.cpp index 3f10b11251..ab68487cc4 100644 --- a/src/dawn_native/d3d12/D3D12Info.cpp +++ b/src/dawn_native/d3d12/D3D12Info.cpp @@ -54,7 +54,7 @@ namespace dawn_native::d3d12 { // with RENDER_PASS_TIER_1 available, so fall back to a software emulated render // pass on these platforms. if (featureOptions5.RenderPassesTier < D3D12_RENDER_PASS_TIER_1 || - !gpu_info::IsIntel(adapter.GetPCIInfo().vendorId)) { + !gpu_info::IsIntel(adapter.GetVendorId())) { info.supportsRenderPass = true; } } diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index 54c2a71b67..d0d06c1a4a 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -584,15 +584,16 @@ namespace dawn_native::d3d12 { // By default use the maximum shader-visible heap size allowed. SetToggle(Toggle::UseD3D12SmallShaderVisibleHeapForTesting, false); - PCIInfo pciInfo = GetAdapter()->GetPCIInfo(); + uint32_t deviceId = GetAdapter()->GetDeviceId(); + uint32_t vendorId = GetAdapter()->GetVendorId(); // Currently this workaround is only needed on Intel Gen9 and Gen9.5 GPUs. // See http://crbug.com/1161355 for more information. - if (gpu_info::IsIntel(pciInfo.vendorId) && - (gpu_info::IsSkylake(pciInfo.deviceId) || gpu_info::IsKabylake(pciInfo.deviceId) || - gpu_info::IsCoffeelake(pciInfo.deviceId))) { + if (gpu_info::IsIntel(vendorId) && + (gpu_info::IsSkylake(deviceId) || gpu_info::IsKabylake(deviceId) || + gpu_info::IsCoffeelake(deviceId))) { constexpr gpu_info::D3DDriverVersion kFirstDriverVersionWithFix = {30, 0, 100, 9864}; - if (gpu_info::CompareD3DDriverVersion(pciInfo.vendorId, + if (gpu_info::CompareD3DDriverVersion(vendorId, ToBackend(GetAdapter())->GetDriverVersion(), kFirstDriverVersionWithFix) < 0) { SetToggle( diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm index f6034b5164..fd5e5070d7 100644 --- a/src/dawn_native/metal/BackendMTL.mm +++ b/src/dawn_native/metal/BackendMTL.mm @@ -243,12 +243,12 @@ namespace dawn_native::metal { public: Adapter(InstanceBase* instance, id device) : AdapterBase(instance, wgpu::BackendType::Metal), mDevice(device) { - mPCIInfo.name = std::string([[*mDevice name] UTF8String]); + mName = std::string([[*mDevice name] UTF8String]); PCIIDs ids; if (!instance->ConsumedError(GetDevicePCIInfo(device, &ids))) { - mPCIInfo.vendorId = ids.vendorId; - mPCIInfo.deviceId = ids.deviceId; + mVendorId = ids.vendorId; + mDeviceId = ids.deviceId; } #if defined(DAWN_PLATFORM_IOS) @@ -311,7 +311,7 @@ namespace dawn_native::metal { // fails to call without any copy commands on MTLBlitCommandEncoder. This issue // has been fixed on macOS 11.0. See crbug.com/dawn/545 enableTimestampQuery &= - !(gpu_info::IsAMD(GetPCIInfo().vendorId) && IsMacOSVersionAtLeast(11)); + !(gpu_info::IsAMD(mVendorId) && IsMacOSVersionAtLeast(11)); #endif if (enableTimestampQuery) { diff --git a/src/dawn_native/metal/DeviceMTL.mm b/src/dawn_native/metal/DeviceMTL.mm index ccba9d1107..978b2f64f1 100644 --- a/src/dawn_native/metal/DeviceMTL.mm +++ b/src/dawn_native/metal/DeviceMTL.mm @@ -137,8 +137,7 @@ namespace dawn_native::metal { if (IsFeatureEnabled(Feature::TimestampQuery)) { // Make a best guess of timestamp period based on device vendor info, and converge it to // an accurate value by the following calculations. - mTimestampPeriod = - gpu_info::IsIntel(GetAdapter()->GetPCIInfo().vendorId) ? 83.333f : 1.0f; + mTimestampPeriod = gpu_info::IsIntel(GetAdapter()->GetVendorId()) ? 83.333f : 1.0f; // Initialize kalman filter parameters mKalmanInfo = std::make_unique(); @@ -199,27 +198,28 @@ namespace dawn_native::metal { // TODO(crbug.com/dawn/846): tighten this workaround when the driver bug is fixed. SetToggle(Toggle::AlwaysResolveIntoZeroLevelAndLayer, true); - const PCIInfo& pciInfo = GetAdapter()->GetPCIInfo(); + uint32_t deviceId = GetAdapter()->GetDeviceId(); + uint32_t vendorId = GetAdapter()->GetVendorId(); // TODO(crbug.com/dawn/847): Use MTLStorageModeShared instead of MTLStorageModePrivate when // creating MTLCounterSampleBuffer in QuerySet on Intel platforms, otherwise it fails to // create the buffer. Change to use MTLStorageModePrivate when the bug is fixed. if (@available(macOS 10.15, iOS 14.0, *)) { - bool useSharedMode = gpu_info::IsIntel(pciInfo.vendorId); + bool useSharedMode = gpu_info::IsIntel(vendorId); SetToggle(Toggle::MetalUseSharedModeForCounterSampleBuffer, useSharedMode); } // TODO(crbug.com/dawn/1071): r8unorm and rg8unorm textures with multiple mip levels don't // clear properly on Intel Macs. - if (gpu_info::IsIntel(pciInfo.vendorId)) { + if (gpu_info::IsIntel(vendorId)) { SetToggle(Toggle::DisableR8RG8Mipmaps, true); } // On some Intel GPU vertex only render pipeline get wrong depth result if no fragment // shader provided. Create a dummy fragment shader module to work around this issue. - if (gpu_info::IsIntel(this->GetAdapter()->GetPCIInfo().vendorId)) { + if (gpu_info::IsIntel(vendorId)) { bool useDummyFragmentShader = true; - if (gpu_info::IsSkylake(this->GetAdapter()->GetPCIInfo().deviceId)) { + if (gpu_info::IsSkylake(deviceId)) { useDummyFragmentShader = false; } SetToggle(Toggle::UseDummyFragmentInVertexOnlyPipeline, useDummyFragmentShader); diff --git a/src/dawn_native/null/DeviceNull.cpp b/src/dawn_native/null/DeviceNull.cpp index dad3afafd4..548426cd86 100644 --- a/src/dawn_native/null/DeviceNull.cpp +++ b/src/dawn_native/null/DeviceNull.cpp @@ -25,7 +25,9 @@ namespace dawn_native::null { // Implementation of pre-Device objects: the null adapter, null backend connection and Connect() Adapter::Adapter(InstanceBase* instance) : AdapterBase(instance, wgpu::BackendType::Null) { - mPCIInfo.name = "Null backend"; + mVendorId = 0; + mDeviceId = 0; + mName = "Null backend"; mAdapterType = wgpu::AdapterType::CPU; MaybeError err = Initialize(); ASSERT(err.IsSuccess()); diff --git a/src/dawn_native/opengl/BackendGL.cpp b/src/dawn_native/opengl/BackendGL.cpp index 0c2ee0b9f2..7726ed2102 100644 --- a/src/dawn_native/opengl/BackendGL.cpp +++ b/src/dawn_native/opengl/BackendGL.cpp @@ -186,16 +186,16 @@ namespace dawn_native::opengl { } mFunctions.Enable(GL_SAMPLE_MASK); - mPCIInfo.name = reinterpret_cast(mFunctions.GetString(GL_RENDERER)); + mName = reinterpret_cast(mFunctions.GetString(GL_RENDERER)); // Workaroud to find vendor id from vendor name const char* vendor = reinterpret_cast(mFunctions.GetString(GL_VENDOR)); - mPCIInfo.vendorId = GetVendorIdFromVendors(vendor); + mVendorId = GetVendorIdFromVendors(vendor); mDriverDescription = std::string("OpenGL version ") + reinterpret_cast(mFunctions.GetString(GL_VERSION)); - if (mPCIInfo.name.find("SwiftShader") != std::string::npos) { + if (mName.find("SwiftShader") != std::string::npos) { mAdapterType = wgpu::AdapterType::CPU; } diff --git a/src/dawn_native/vulkan/AdapterVk.cpp b/src/dawn_native/vulkan/AdapterVk.cpp index 4b81ba0e03..9ac789edf0 100644 --- a/src/dawn_native/vulkan/AdapterVk.cpp +++ b/src/dawn_native/vulkan/AdapterVk.cpp @@ -65,9 +65,9 @@ namespace dawn_native::vulkan { "Vulkan driver version: " + std::to_string(mDeviceInfo.properties.driverVersion); } - mPCIInfo.deviceId = mDeviceInfo.properties.deviceID; - mPCIInfo.vendorId = mDeviceInfo.properties.vendorID; - mPCIInfo.name = mDeviceInfo.properties.deviceName; + mDeviceId = mDeviceInfo.properties.deviceID; + mVendorId = mDeviceInfo.properties.vendorID; + mName = mDeviceInfo.properties.deviceName; switch (mDeviceInfo.properties.deviceType) { case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: diff --git a/src/include/dawn_native/DawnNative.h b/src/include/dawn_native/DawnNative.h index 2ca2c481fe..82df6883d8 100644 --- a/src/include/dawn_native/DawnNative.h +++ b/src/include/dawn_native/DawnNative.h @@ -33,31 +33,6 @@ namespace wgpu { namespace dawn_native { - // DEPRECATED: use WGPUAdapterProperties instead. - struct PCIInfo { - uint32_t deviceId = 0; - uint32_t vendorId = 0; - std::string name; - }; - - // DEPRECATED: use WGPUBackendType instead. - enum class BackendType { - D3D12, - Metal, - Null, - OpenGL, - OpenGLES, - Vulkan, - }; - - // DEPRECATED: use WGPUAdapterType instead. - enum class DeviceType { - DiscreteGPU, - IntegratedGPU, - CPU, - Unknown, - }; - class InstanceBase; class AdapterBase; @@ -100,11 +75,6 @@ namespace dawn_native { Adapter(const Adapter& other); Adapter& operator=(const Adapter& other); - // DEPRECATED: use GetProperties instead. - BackendType GetBackendType() const; - DeviceType GetDeviceType() const; - const PCIInfo& GetPCIInfo() const; - // Essentially webgpu.h's wgpuAdapterGetProperties while we don't have WGPUAdapter in // dawn.json void GetProperties(wgpu::AdapterProperties* properties) const; diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 189fa3c307..4102c0f09e 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -323,11 +323,11 @@ void DawnTestEnvironment::ParseArgs(int argc, char** argv) { std::string type; while (std::getline(ss, type, ',')) { if (strcmp(type.c_str(), "discrete") == 0) { - mDevicePreferences.push_back(dawn_native::DeviceType::DiscreteGPU); + mDevicePreferences.push_back(wgpu::AdapterType::DiscreteGPU); } else if (strcmp(type.c_str(), "integrated") == 0) { - mDevicePreferences.push_back(dawn_native::DeviceType::IntegratedGPU); + mDevicePreferences.push_back(wgpu::AdapterType::IntegratedGPU); } else if (strcmp(type.c_str(), "cpu") == 0) { - mDevicePreferences.push_back(dawn_native::DeviceType::CPU); + mDevicePreferences.push_back(wgpu::AdapterType::CPU); } else { dawn::ErrorLog() << "Invalid device type preference: " << type; UNREACHABLE(); @@ -474,14 +474,14 @@ GLFWwindow* DawnTestEnvironment::GetOpenGLESWindow() const { void DawnTestEnvironment::SelectPreferredAdapterProperties(const dawn_native::Instance* instance) { // Get the first available preferred device type. - dawn_native::DeviceType preferredDeviceType = static_cast(-1); + wgpu::AdapterType preferredDeviceType = static_cast(-1); bool hasDevicePreference = false; - for (dawn_native::DeviceType devicePreference : mDevicePreferences) { + for (wgpu::AdapterType devicePreference : mDevicePreferences) { for (const dawn_native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; adapter.GetProperties(&properties); - if (adapter.GetDeviceType() == devicePreference) { + if (properties.adapterType == devicePreference) { preferredDeviceType = devicePreference; hasDevicePreference = true; break; @@ -517,12 +517,12 @@ void DawnTestEnvironment::SelectPreferredAdapterProperties(const dawn_native::In selected &= // The device type doesn't match the first available preferred type for that // backend, if present. - (adapter.GetDeviceType() == preferredDeviceType) || + (properties.adapterType == preferredDeviceType) || // Always select Unknown OpenGL adapters if we don't want a CPU adapter. // OpenGL will usually be unknown because we can't query the device type. // If we ever have Swiftshader GL (unlikely), we could set the DeviceType properly. - (preferredDeviceType != dawn_native::DeviceType::CPU && - adapter.GetDeviceType() == dawn_native::DeviceType::Unknown && + (preferredDeviceType != wgpu::AdapterType::CPU && + properties.adapterType == wgpu::AdapterType::Unknown && (properties.backendType == wgpu::BackendType::OpenGL || properties.backendType == wgpu::BackendType::OpenGLES)) || // Always select the Null backend. There are few tests on this backend, and they run diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index cbc8fe9857..5496bb7a90 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -261,7 +261,7 @@ class DawnTestEnvironment : public testing::Environment { ToggleParser mToggleParser; - std::vector mDevicePreferences; + std::vector mDevicePreferences; std::vector mAdapterProperties; std::unique_ptr mPlatformDebugLogger;