From 6315289ee8acc5fdda2cec525fa9320d07aa0220 Mon Sep 17 00:00:00 2001 From: Zhaoming Jiang Date: Fri, 3 Feb 2023 19:13:12 +0000 Subject: [PATCH] Dawn: Make Adapter initialize supported feature never error This CL make vulkan adapter checks essential Vulkan extensions and features in InitializeImpl rather than InitializeSupportedFeaturesImpl. This change makes InitializeSupportedFeaturesImpl never result in Error for all backend, and this CL change the return type of InitializeSupportedFeaturesImpl from MaybeError to void. Bug: dawn:1495 Change-Id: If59c5aa5281776226c157451ee5119052d33ac24 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118031 Kokoro: Kokoro Reviewed-by: Corentin Wallez Commit-Queue: Zhaoming Jiang Reviewed-by: Austin Eng --- src/dawn/native/Adapter.cpp | 7 ++----- src/dawn/native/Adapter.h | 2 +- src/dawn/native/d3d12/AdapterD3D12.cpp | 4 +--- src/dawn/native/d3d12/AdapterD3D12.h | 2 +- src/dawn/native/metal/BackendMTL.mm | 4 +--- src/dawn/native/null/DeviceNull.cpp | 3 +-- src/dawn/native/null/DeviceNull.h | 2 +- src/dawn/native/opengl/AdapterGL.cpp | 4 +--- src/dawn/native/opengl/AdapterGL.h | 2 +- src/dawn/native/vulkan/AdapterVk.cpp | 11 +++++------ src/dawn/native/vulkan/AdapterVk.h | 2 +- 11 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp index 85e16dc03c..1727452ae7 100644 --- a/src/dawn/native/Adapter.cpp +++ b/src/dawn/native/Adapter.cpp @@ -39,11 +39,8 @@ MaybeError AdapterBase::Initialize() { DAWN_TRY_CONTEXT(InitializeImpl(), "initializing adapter (backend=%s)", mBackend); InitializeVendorArchitectureImpl(); - DAWN_TRY_CONTEXT( - InitializeSupportedFeaturesImpl(), - "gathering supported features for \"%s\" - \"%s\" (vendorId=%#06x deviceId=%#06x " - "backend=%s type=%s)", - mName, mDriverDescription, mVendorId, mDeviceId, mBackend, mAdapterType); + InitializeSupportedFeaturesImpl(); + DAWN_TRY_CONTEXT( InitializeSupportedLimitsImpl(&mLimits), "gathering supported limits for \"%s\" - \"%s\" (vendorId=%#06x deviceId=%#06x " diff --git a/src/dawn/native/Adapter.h b/src/dawn/native/Adapter.h index 67b4e88138..f6c105ff9c 100644 --- a/src/dawn/native/Adapter.h +++ b/src/dawn/native/Adapter.h @@ -94,7 +94,7 @@ class AdapterBase : public RefCounted { virtual MaybeError InitializeImpl() = 0; // Check base WebGPU features and discover supported features. - virtual MaybeError InitializeSupportedFeaturesImpl() = 0; + virtual void InitializeSupportedFeaturesImpl() = 0; // Check base WebGPU limits and populate supported limits. virtual MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) = 0; diff --git a/src/dawn/native/d3d12/AdapterD3D12.cpp b/src/dawn/native/d3d12/AdapterD3D12.cpp index b3b7bf4790..077ea8dc7e 100644 --- a/src/dawn/native/d3d12/AdapterD3D12.cpp +++ b/src/dawn/native/d3d12/AdapterD3D12.cpp @@ -122,7 +122,7 @@ bool Adapter::AreTimestampQueriesSupported() const { return true; } -MaybeError Adapter::InitializeSupportedFeaturesImpl() { +void Adapter::InitializeSupportedFeaturesImpl() { if (AreTimestampQueriesSupported()) { mSupportedFeatures.EnableFeature(Feature::TimestampQuery); mSupportedFeatures.EnableFeature(Feature::TimestampQueryInsidePasses); @@ -144,8 +144,6 @@ MaybeError Adapter::InitializeSupportedFeaturesImpl() { mSupportedFeatures.EnableFeature(Feature::ShaderF16); } } - - return {}; } MaybeError Adapter::InitializeSupportedLimitsImpl(CombinedLimits* limits) { diff --git a/src/dawn/native/d3d12/AdapterD3D12.h b/src/dawn/native/d3d12/AdapterD3D12.h index aa3538c196..a751c119de 100644 --- a/src/dawn/native/d3d12/AdapterD3D12.h +++ b/src/dawn/native/d3d12/AdapterD3D12.h @@ -46,7 +46,7 @@ class Adapter : public AdapterBase { bool AreTimestampQueriesSupported() const; MaybeError InitializeImpl() override; - MaybeError InitializeSupportedFeaturesImpl() override; + void InitializeSupportedFeaturesImpl() override; MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override; MaybeError ValidateFeatureSupportedWithTogglesImpl( diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm index 63321e0cbd..8deb039e5e 100644 --- a/src/dawn/native/metal/BackendMTL.mm +++ b/src/dawn/native/metal/BackendMTL.mm @@ -298,7 +298,7 @@ class Adapter : public AdapterBase { MaybeError InitializeImpl() override { return {}; } - MaybeError InitializeSupportedFeaturesImpl() override { + void InitializeSupportedFeaturesImpl() override { // Check compressed texture format with deprecated MTLFeatureSet way. #if DAWN_PLATFORM_IS(MACOS) if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) { @@ -383,8 +383,6 @@ class Adapter : public AdapterBase { mSupportedFeatures.EnableFeature(Feature::IndirectFirstInstance); mSupportedFeatures.EnableFeature(Feature::ShaderF16); mSupportedFeatures.EnableFeature(Feature::RG11B10UfloatRenderable); - - return {}; } void InitializeVendorArchitectureImpl() override { diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp index 7288de0177..77c7a3be1d 100644 --- a/src/dawn/native/null/DeviceNull.cpp +++ b/src/dawn/native/null/DeviceNull.cpp @@ -57,10 +57,9 @@ MaybeError Adapter::InitializeImpl() { return {}; } -MaybeError Adapter::InitializeSupportedFeaturesImpl() { +void Adapter::InitializeSupportedFeaturesImpl() { // Enable all features by default for the convenience of tests. mSupportedFeatures.featuresBitSet.set(); - return {}; } MaybeError Adapter::InitializeSupportedLimitsImpl(CombinedLimits* limits) { diff --git a/src/dawn/native/null/DeviceNull.h b/src/dawn/native/null/DeviceNull.h index 2a8565a788..62c568cb1a 100644 --- a/src/dawn/native/null/DeviceNull.h +++ b/src/dawn/native/null/DeviceNull.h @@ -182,7 +182,7 @@ class Adapter : public AdapterBase { private: MaybeError InitializeImpl() override; - MaybeError InitializeSupportedFeaturesImpl() override; + void InitializeSupportedFeaturesImpl() override; MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override; ResultOrError> CreateDeviceImpl( diff --git a/src/dawn/native/opengl/AdapterGL.cpp b/src/dawn/native/opengl/AdapterGL.cpp index f309c61c8e..918c0be113 100644 --- a/src/dawn/native/opengl/AdapterGL.cpp +++ b/src/dawn/native/opengl/AdapterGL.cpp @@ -90,7 +90,7 @@ MaybeError Adapter::InitializeImpl() { return {}; } -MaybeError Adapter::InitializeSupportedFeaturesImpl() { +void Adapter::InitializeSupportedFeaturesImpl() { // TextureCompressionBC { // BC1, BC2 and BC3 are not supported in OpenGL or OpenGL ES core features. @@ -145,8 +145,6 @@ MaybeError Adapter::InitializeSupportedFeaturesImpl() { if (mFunctions.IsGLExtensionSupported("GL_AMD_gpu_shader_half_float")) { mSupportedFeatures.EnableFeature(Feature::ShaderF16); } - - return {}; } MaybeError Adapter::InitializeSupportedLimitsImpl(CombinedLimits* limits) { diff --git a/src/dawn/native/opengl/AdapterGL.h b/src/dawn/native/opengl/AdapterGL.h index 4d6b0c1b68..8eabedc22a 100644 --- a/src/dawn/native/opengl/AdapterGL.h +++ b/src/dawn/native/opengl/AdapterGL.h @@ -34,7 +34,7 @@ class Adapter : public AdapterBase { private: MaybeError InitializeImpl() override; - MaybeError InitializeSupportedFeaturesImpl() override; + void InitializeSupportedFeaturesImpl() override; MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override; ResultOrError> CreateDeviceImpl( const DeviceDescriptor* descriptor, diff --git a/src/dawn/native/vulkan/AdapterVk.cpp b/src/dawn/native/vulkan/AdapterVk.cpp index 7bcce2a05b..3a9d7e0f2f 100644 --- a/src/dawn/native/vulkan/AdapterVk.cpp +++ b/src/dawn/native/vulkan/AdapterVk.cpp @@ -140,10 +140,7 @@ MaybeError Adapter::InitializeImpl() { break; } - return {}; -} - -MaybeError Adapter::InitializeSupportedFeaturesImpl() { + // Check for essential Vulkan extensions and features // Needed for viewport Y-flip. if (!mDeviceInfo.HasExt(DeviceExt::Maintenance1)) { return DAWN_INTERNAL_ERROR("Vulkan 1.1 or Vulkan 1.0 with KHR_Maintenance1 required."); @@ -182,6 +179,10 @@ MaybeError Adapter::InitializeSupportedFeaturesImpl() { return DAWN_INTERNAL_ERROR("Vulkan sampleRateShading feature required."); } + return {}; +} + +void Adapter::InitializeSupportedFeaturesImpl() { // Initialize supported extensions if (mDeviceInfo.features.textureCompressionBC == VK_TRUE) { mSupportedFeatures.EnableFeature(Feature::TextureCompressionBC); @@ -254,8 +255,6 @@ MaybeError Adapter::InitializeSupportedFeaturesImpl() { // features. mSupportedFeatures.EnableFeature(Feature::MultiPlanarFormats); #endif - - return {}; } MaybeError Adapter::InitializeSupportedLimitsImpl(CombinedLimits* limits) { diff --git a/src/dawn/native/vulkan/AdapterVk.h b/src/dawn/native/vulkan/AdapterVk.h index 4126ae3eda..e5f2a382da 100644 --- a/src/dawn/native/vulkan/AdapterVk.h +++ b/src/dawn/native/vulkan/AdapterVk.h @@ -45,7 +45,7 @@ class Adapter : public AdapterBase { private: MaybeError InitializeImpl() override; - MaybeError InitializeSupportedFeaturesImpl() override; + void InitializeSupportedFeaturesImpl() override; MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override; ResultOrError> CreateDeviceImpl(