diff --git a/include/dawn/native/DawnNative.h b/include/dawn/native/DawnNative.h index c6d720f5d7..033dee2a59 100644 --- a/include/dawn/native/DawnNative.h +++ b/include/dawn/native/DawnNative.h @@ -181,6 +181,9 @@ class DAWN_NATIVE_EXPORT Instance { // Enable debug capture on Dawn startup void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup); + // Enable / disable the adapter blocklist. + void EnableAdapterBlocklist(bool enable); + // TODO(dawn:1374) Deprecate this once it is passed via the descriptor. void SetPlatform(dawn::platform::Platform* platform); diff --git a/src/dawn/native/DawnNative.cpp b/src/dawn/native/DawnNative.cpp index ffc4e88662..5e9f39b7e7 100644 --- a/src/dawn/native/DawnNative.cpp +++ b/src/dawn/native/DawnNative.cpp @@ -235,6 +235,10 @@ void Instance::EnableBeginCaptureOnStartup(bool beginCaptureOnStartup) { mImpl->EnableBeginCaptureOnStartup(beginCaptureOnStartup); } +void Instance::EnableAdapterBlocklist(bool enable) { + mImpl->EnableAdapterBlocklist(enable); +} + // TODO(dawn:1374) Deprecate this once it is passed via the descriptor. void Instance::SetPlatform(dawn::platform::Platform* platform) { mImpl->SetPlatform(platform); diff --git a/src/dawn/native/Instance.cpp b/src/dawn/native/Instance.cpp index 075edec877..a2c490da63 100644 --- a/src/dawn/native/Instance.cpp +++ b/src/dawn/native/Instance.cpp @@ -439,6 +439,14 @@ bool InstanceBase::IsBeginCaptureOnStartupEnabled() const { return mBeginCaptureOnStartup; } +void InstanceBase::EnableAdapterBlocklist(bool enable) { + mEnableAdapterBlocklist = enable; +} + +bool InstanceBase::IsAdapterBlocklistEnabled() const { + return mEnableAdapterBlocklist; +} + void InstanceBase::SetPlatform(dawn::platform::Platform* platform) { if (platform == nullptr) { mPlatform = mDefaultPlatform.get(); diff --git a/src/dawn/native/Instance.h b/src/dawn/native/Instance.h index ac3a11048b..f6d518f1f0 100644 --- a/src/dawn/native/Instance.h +++ b/src/dawn/native/Instance.h @@ -88,6 +88,11 @@ class InstanceBase final : public RefCountedWithExternalCount { void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup); bool IsBeginCaptureOnStartupEnabled() const; + // TODO(crbug.com/dawn/1495): Move this to a Toggle, perhaps on RequestAdapterOptions + // after Toggle refactor is complete. + void EnableAdapterBlocklist(bool enable); + bool IsAdapterBlocklistEnabled() const; + // TODO(dawn:1374): SetPlatform should become a private helper, and SetPlatformForTesting // will become the NOT thread-safe testing version exposed for special testing cases. void SetPlatform(dawn::platform::Platform* platform); @@ -134,6 +139,7 @@ class InstanceBase final : public RefCountedWithExternalCount { bool mDiscoveredDefaultAdapters = false; bool mBeginCaptureOnStartup = false; + bool mEnableAdapterBlocklist = false; BackendValidationLevel mBackendValidationLevel = BackendValidationLevel::Disabled; dawn::platform::Platform* mPlatform = nullptr; diff --git a/src/dawn/native/d3d12/AdapterD3D12.cpp b/src/dawn/native/d3d12/AdapterD3D12.cpp index 060c8ef08e..5104d8059e 100644 --- a/src/dawn/native/d3d12/AdapterD3D12.cpp +++ b/src/dawn/native/d3d12/AdapterD3D12.cpp @@ -17,6 +17,7 @@ #include #include "dawn/common/Constants.h" +#include "dawn/common/Platform.h" #include "dawn/common/WindowsUtils.h" #include "dawn/native/Instance.h" #include "dawn/native/d3d12/BackendD3D12.h" @@ -98,6 +99,16 @@ MaybeError Adapter::InitializeImpl() { mDriverDescription = std::string("D3D12 driver version ") + mDriverVersion.ToString(); } + if (GetInstance()->IsAdapterBlocklistEnabled()) { +#if DAWN_PLATFORM_IS(X86) + DAWN_INVALID_IF(mDeviceInfo.shaderModel >= 60, + "D3D12 x86 adapter is blocklisted. See https://crbug.com/tint/1753."); + + DAWN_INVALID_IF( + gpu_info::IsNvidia(mVendorId), + "D3D12 NVIDIA x86 adapter is blocklisted. See https://crbug.com/dawn/1196."); +#endif + } return {}; } diff --git a/src/dawn/tests/DawnNativeTest.cpp b/src/dawn/tests/DawnNativeTest.cpp index bf66fb159b..bd5cf45945 100644 --- a/src/dawn/tests/DawnNativeTest.cpp +++ b/src/dawn/tests/DawnNativeTest.cpp @@ -46,6 +46,7 @@ DawnNativeTest::~DawnNativeTest() { void DawnNativeTest::SetUp() { instance = std::make_unique(); + instance->EnableAdapterBlocklist(false); platform = CreateTestPlatform(); dawn::native::FromAPI(instance->Get())->SetPlatformForTesting(platform.get()); diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp index fc96b69254..8c2777fc2a 100644 --- a/src/dawn/tests/DawnTest.cpp +++ b/src/dawn/tests/DawnTest.cpp @@ -306,6 +306,7 @@ std::unique_ptr DawnTestEnvironment::CreateInstanceAndDi auto instance = std::make_unique(); instance->EnableBeginCaptureOnStartup(mBeginCaptureOnStartup); instance->SetBackendValidationLevel(mBackendValidationLevel); + instance->EnableAdapterBlocklist(false); #ifdef DAWN_ENABLE_BACKEND_OPENGLES if (GetEnvironmentVar("ANGLE_DEFAULT_PLATFORM").first.empty()) { diff --git a/src/dawn/tests/end2end/DeviceInitializationTests.cpp b/src/dawn/tests/end2end/DeviceInitializationTests.cpp index 023b7acc53..4758220396 100644 --- a/src/dawn/tests/end2end/DeviceInitializationTests.cpp +++ b/src/dawn/tests/end2end/DeviceInitializationTests.cpp @@ -74,6 +74,7 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) { std::vector availableAdapterProperties; { auto instance = std::make_unique(); + instance->EnableAdapterBlocklist(false); instance->DiscoverDefaultAdapters(); for (const dawn::native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; @@ -90,6 +91,7 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) { wgpu::Device device; auto instance = std::make_unique(); + instance->EnableAdapterBlocklist(false); instance->DiscoverDefaultAdapters(); for (dawn::native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; @@ -120,6 +122,7 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) { std::vector availableAdapterProperties; { auto instance = std::make_unique(); + instance->EnableAdapterBlocklist(false); instance->DiscoverDefaultAdapters(); for (const dawn::native::Adapter& adapter : instance->GetAdapters()) { wgpu::AdapterProperties properties; @@ -136,6 +139,7 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) { wgpu::Adapter adapter; auto instance = std::make_unique(); + instance->EnableAdapterBlocklist(false); // Save a pointer to the instance. // It will only be valid as long as the instance is alive. WGPUInstance unsafeInstancePtr = instance->Get();