Dawn: Make ValidateFeatureSupportedWithToggles generate no error
This CL make PhysicalDevice::ValidateFeatureSupportedWithToggles returns
a structure to indicate if the validation failed and the failure message,
instead of creating an error that may by caught when debugging.
Issue: dawn:2176
Change-Id: Ifde957a8d23553ef4a19079d1bc5d3e19a58bae3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/157944
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index 40ffc2c..a120050 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -217,7 +217,10 @@
// disabled AllowUnsafeAPIS.
for (uint32_t i = 0; i < descriptor->requiredFeatureCount; ++i) {
wgpu::FeatureName feature = descriptor->requiredFeatures[i];
- DAWN_TRY(mPhysicalDevice->ValidateFeatureSupportedWithToggles(feature, deviceToggles));
+ FeatureValidationResult result =
+ mPhysicalDevice->ValidateFeatureSupportedWithToggles(feature, deviceToggles);
+ DAWN_INVALID_IF(!result.success, "Invalid feature required: %s",
+ result.errorMessage.c_str());
}
if (descriptor->requiredLimits != nullptr) {
diff --git a/src/dawn/native/PhysicalDevice.cpp b/src/dawn/native/PhysicalDevice.cpp
index c4d48a3..848acc3 100644
--- a/src/dawn/native/PhysicalDevice.cpp
+++ b/src/dawn/native/PhysicalDevice.cpp
@@ -39,6 +39,10 @@
namespace dawn::native {
+FeatureValidationResult::FeatureValidationResult() : success(true) {}
+FeatureValidationResult::FeatureValidationResult(std::string errorMsg)
+ : success(false), errorMessage(errorMsg) {}
+
PhysicalDeviceBase::PhysicalDeviceBase(InstanceBase* instance, wgpu::BackendType backend)
: mInstance(instance), mBackend(backend) {}
@@ -118,13 +122,7 @@
bool PhysicalDeviceBase::IsFeatureSupportedWithToggles(wgpu::FeatureName feature,
const TogglesState& toggles) const {
- MaybeError validateResult = ValidateFeatureSupportedWithToggles(feature, toggles);
- if (validateResult.IsError()) {
- validateResult.AcquireError();
- return false;
- } else {
- return true;
- }
+ return ValidateFeatureSupportedWithToggles(feature, toggles).success;
}
void PhysicalDeviceBase::GetDefaultLimitsForSupportedFeatureLevel(Limits* limits) const {
@@ -165,19 +163,27 @@
mSupportedFeatures.EnableFeature(feature);
}
-MaybeError PhysicalDeviceBase::ValidateFeatureSupportedWithToggles(
+FeatureValidationResult PhysicalDeviceBase::ValidateFeatureSupportedWithToggles(
wgpu::FeatureName feature,
const TogglesState& toggles) const {
- DAWN_TRY(ValidateFeatureName(feature));
- DAWN_INVALID_IF(!mSupportedFeatures.IsEnabled(feature),
- "Requested feature %s is not supported.", feature);
+ auto validateNameResult = ValidateFeatureName(feature);
+ if (validateNameResult.IsError()) {
+ return FeatureValidationResult(validateNameResult.AcquireError()->GetMessage());
+ }
+
+ if (!mSupportedFeatures.IsEnabled(feature)) {
+ return FeatureValidationResult(
+ absl::StrFormat("Requested feature %s is not supported.", feature));
+ }
const FeatureInfo* featureInfo = GetInstance()->GetFeatureInfo(feature);
// Experimental features are guarded by the AllowUnsafeAPIs toggle.
if (featureInfo->featureState == FeatureInfo::FeatureState::Experimental) {
// AllowUnsafeAPIs toggle is by default disabled if not explicitly enabled.
- DAWN_INVALID_IF(!toggles.IsEnabled(Toggle::AllowUnsafeAPIs),
- "Feature %s is guarded by toggle allow_unsafe_apis.", featureInfo->name);
+ if (!toggles.IsEnabled(Toggle::AllowUnsafeAPIs)) {
+ return FeatureValidationResult(absl::StrFormat(
+ "Feature %s is guarded by toggle allow_unsafe_apis.", featureInfo->name));
+ }
}
// Do backend-specific validation.
diff --git a/src/dawn/native/PhysicalDevice.h b/src/dawn/native/PhysicalDevice.h
index 11821f4..8ec396b 100644
--- a/src/dawn/native/PhysicalDevice.h
+++ b/src/dawn/native/PhysicalDevice.h
@@ -47,6 +47,16 @@
class DeviceBase;
+struct FeatureValidationResult {
+ // Constructor of successful result
+ FeatureValidationResult();
+ // Constructor of failed result
+ explicit FeatureValidationResult(std::string errorMsg);
+
+ bool success;
+ std::string errorMessage;
+};
+
class PhysicalDeviceBase : public RefCounted {
public:
PhysicalDeviceBase(InstanceBase* instance, wgpu::BackendType backend);
@@ -93,8 +103,8 @@
virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0;
// Check if a feature os supported by this adapter AND suitable with given toggles.
- MaybeError ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature,
- const TogglesState& toggles) const;
+ FeatureValidationResult ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature,
+ const TogglesState& toggles) const;
protected:
uint32_t mVendorId = 0xFFFFFFFF;
@@ -132,7 +142,7 @@
virtual void InitializeVendorArchitectureImpl();
- virtual MaybeError ValidateFeatureSupportedWithTogglesImpl(
+ virtual FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TogglesState& toggles) const = 0;
diff --git a/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp b/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
index 3791abc..a53a4c5 100644
--- a/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
+++ b/src/dawn/native/d3d11/PhysicalDeviceD3D11.cpp
@@ -246,7 +246,7 @@
return {};
}
-MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
+FeatureValidationResult PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TogglesState& toggles) const {
return {};
diff --git a/src/dawn/native/d3d11/PhysicalDeviceD3D11.h b/src/dawn/native/d3d11/PhysicalDeviceD3D11.h
index d6328cb..81655bc 100644
--- a/src/dawn/native/d3d11/PhysicalDeviceD3D11.h
+++ b/src/dawn/native/d3d11/PhysicalDeviceD3D11.h
@@ -68,8 +68,9 @@
void InitializeSupportedFeaturesImpl() override;
MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override;
- MaybeError ValidateFeatureSupportedWithTogglesImpl(wgpu::FeatureName feature,
- const TogglesState& toggles) const override;
+ FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
+ wgpu::FeatureName feature,
+ const TogglesState& toggles) const override;
ComPtr<ID3D11Device> mD3d11Device;
D3D_FEATURE_LEVEL mFeatureLevel;
DeviceInfo mDeviceInfo = {};
diff --git a/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp b/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
index 70d67c6..c9b5a30 100644
--- a/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
+++ b/src/dawn/native/d3d12/PhysicalDeviceD3D12.cpp
@@ -375,15 +375,18 @@
return {};
}
-MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
+FeatureValidationResult PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TogglesState& toggles) const {
// shader-f16 feature and chromium-experimental-dp4a feature require DXC 1.4 or higher for
// D3D12. Note that DXC version is checked in InitializeSupportedFeaturesImpl.
if (feature == wgpu::FeatureName::ShaderF16 ||
feature == wgpu::FeatureName::ChromiumExperimentalDp4a) {
- DAWN_INVALID_IF(!toggles.IsEnabled(Toggle::UseDXC), "Feature %s requires DXC for D3D12.",
- GetInstance()->GetFeatureInfo(feature)->name);
+ if (!toggles.IsEnabled(Toggle::UseDXC)) {
+ return FeatureValidationResult(
+ absl::StrFormat("Feature %s requires DXC for D3D12.",
+ GetInstance()->GetFeatureInfo(feature)->name));
+ }
}
return {};
}
diff --git a/src/dawn/native/d3d12/PhysicalDeviceD3D12.h b/src/dawn/native/d3d12/PhysicalDeviceD3D12.h
index c354350..c8a35f4 100644
--- a/src/dawn/native/d3d12/PhysicalDeviceD3D12.h
+++ b/src/dawn/native/d3d12/PhysicalDeviceD3D12.h
@@ -69,8 +69,9 @@
void InitializeSupportedFeaturesImpl() override;
MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override;
- MaybeError ValidateFeatureSupportedWithTogglesImpl(wgpu::FeatureName feature,
- const TogglesState& toggles) const override;
+ FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
+ wgpu::FeatureName feature,
+ const TogglesState& toggles) const override;
MaybeError InitializeDebugLayerFilters();
void CleanUpDebugLayerFilters();
diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm
index aef3ebb..c543b4d 100644
--- a/src/dawn/native/metal/BackendMTL.mm
+++ b/src/dawn/native/metal/BackendMTL.mm
@@ -856,8 +856,9 @@
return {};
}
- MaybeError ValidateFeatureSupportedWithTogglesImpl(wgpu::FeatureName feature,
- const TogglesState& toggles) const override {
+ FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
+ wgpu::FeatureName feature,
+ const TogglesState& toggles) const override {
return {};
}
diff --git a/src/dawn/native/null/DeviceNull.cpp b/src/dawn/native/null/DeviceNull.cpp
index d30a03d..9997aa1 100644
--- a/src/dawn/native/null/DeviceNull.cpp
+++ b/src/dawn/native/null/DeviceNull.cpp
@@ -90,7 +90,7 @@
return Device::Create(adapter, descriptor, deviceToggles);
}
-MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
+FeatureValidationResult PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TogglesState& toggles) const {
return {};
diff --git a/src/dawn/native/null/DeviceNull.h b/src/dawn/native/null/DeviceNull.h
index b6d4d05..4187b07 100644
--- a/src/dawn/native/null/DeviceNull.h
+++ b/src/dawn/native/null/DeviceNull.h
@@ -199,8 +199,9 @@
void InitializeSupportedFeaturesImpl() override;
MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override;
- MaybeError ValidateFeatureSupportedWithTogglesImpl(wgpu::FeatureName feature,
- const TogglesState& toggles) const override;
+ FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
+ wgpu::FeatureName feature,
+ const TogglesState& toggles) const override;
void SetupBackendAdapterToggles(TogglesState* adapterToggles) const override;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
diff --git a/src/dawn/native/opengl/PhysicalDeviceGL.cpp b/src/dawn/native/opengl/PhysicalDeviceGL.cpp
index ccee276..87cd92f 100644
--- a/src/dawn/native/opengl/PhysicalDeviceGL.cpp
+++ b/src/dawn/native/opengl/PhysicalDeviceGL.cpp
@@ -418,7 +418,7 @@
return featureLevel == FeatureLevel::Compatibility;
}
-MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
+FeatureValidationResult PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TogglesState& toggles) const {
return {};
diff --git a/src/dawn/native/opengl/PhysicalDeviceGL.h b/src/dawn/native/opengl/PhysicalDeviceGL.h
index 8c9fb22..e0bec2b 100644
--- a/src/dawn/native/opengl/PhysicalDeviceGL.h
+++ b/src/dawn/native/opengl/PhysicalDeviceGL.h
@@ -55,8 +55,9 @@
void InitializeSupportedFeaturesImpl() override;
MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override;
- MaybeError ValidateFeatureSupportedWithTogglesImpl(wgpu::FeatureName feature,
- const TogglesState& toggles) const override;
+ FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
+ wgpu::FeatureName feature,
+ const TogglesState& toggles) const override;
void SetupBackendAdapterToggles(TogglesState* adapterToggles) const override;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
diff --git a/src/dawn/native/vulkan/PhysicalDeviceVk.cpp b/src/dawn/native/vulkan/PhysicalDeviceVk.cpp
index 51dbb18..52b26f5 100644
--- a/src/dawn/native/vulkan/PhysicalDeviceVk.cpp
+++ b/src/dawn/native/vulkan/PhysicalDeviceVk.cpp
@@ -693,7 +693,7 @@
return Device::Create(adapter, descriptor, deviceToggles);
}
-MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
+FeatureValidationResult PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(
wgpu::FeatureName feature,
const TogglesState& toggles) const {
return {};
diff --git a/src/dawn/native/vulkan/PhysicalDeviceVk.h b/src/dawn/native/vulkan/PhysicalDeviceVk.h
index ee44640..a0bc315 100644
--- a/src/dawn/native/vulkan/PhysicalDeviceVk.h
+++ b/src/dawn/native/vulkan/PhysicalDeviceVk.h
@@ -66,8 +66,9 @@
void InitializeSupportedFeaturesImpl() override;
MaybeError InitializeSupportedLimitsImpl(CombinedLimits* limits) override;
- MaybeError ValidateFeatureSupportedWithTogglesImpl(wgpu::FeatureName feature,
- const TogglesState& toggles) const override;
+ FeatureValidationResult ValidateFeatureSupportedWithTogglesImpl(
+ wgpu::FeatureName feature,
+ const TogglesState& toggles) const override;
void SetupBackendAdapterToggles(TogglesState* adapterToggles) const override;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;