Add Backend Validation Levels Option to Dawn Tests

Refactors DawnTest's backend validation options to use an enum, as well
as adds the 'partial' option enable backend validation with a
reduced performance overhead to address TDR issues on the bots.

Bug: dawn:598
Change-Id: I759eff03bd117f1f20ad82aa2b71a87834f42b1d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/40000
Commit-Queue: Brandon Jones <brandon1.jones@intel.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Brandon Jones 2021-02-04 19:32:12 +00:00 committed by Commit Bot service account
parent ef369b9ffc
commit bdbf98afca
7 changed files with 77 additions and 51 deletions

View File

@ -151,11 +151,13 @@ namespace dawn_native {
} }
void Instance::EnableBackendValidation(bool enableBackendValidation) { void Instance::EnableBackendValidation(bool enableBackendValidation) {
mImpl->EnableBackendValidation(enableBackendValidation); if (enableBackendValidation) {
mImpl->SetBackendValidationLevel(BackendValidationLevel::Full);
}
} }
void Instance::EnableGPUBasedBackendValidation(bool enableGPUBasedBackendValidation) { void Instance::SetBackendValidationLevel(BackendValidationLevel level) {
mImpl->EnableGPUBasedBackendValidation(enableGPUBasedBackendValidation); mImpl->SetBackendValidationLevel(level);
} }
void Instance::EnableBeginCaptureOnStartup(bool beginCaptureOnStartup) { void Instance::EnableBeginCaptureOnStartup(bool beginCaptureOnStartup) {

View File

@ -195,20 +195,16 @@ namespace dawn_native {
return false; return false;
} }
void InstanceBase::EnableBackendValidation(bool enableBackendValidation) {
mEnableBackendValidation = enableBackendValidation;
}
bool InstanceBase::IsBackendValidationEnabled() const { bool InstanceBase::IsBackendValidationEnabled() const {
return mEnableBackendValidation; return mBackendValidationLevel != BackendValidationLevel::Disabled;
} }
void InstanceBase::EnableGPUBasedBackendValidation(bool enableGPUBasedBackendValidation) { void InstanceBase::SetBackendValidationLevel(BackendValidationLevel level) {
mEnableGPUValidation = enableGPUBasedBackendValidation; mBackendValidationLevel = level;
} }
bool InstanceBase::IsGPUBasedBackendValidationEnabled() const { BackendValidationLevel InstanceBase::GetBackendValidationLevel() const {
return mEnableGPUValidation; return mBackendValidationLevel;
} }
void InstanceBase::EnableBeginCaptureOnStartup(bool beginCaptureOnStartup) { void InstanceBase::EnableBeginCaptureOnStartup(bool beginCaptureOnStartup) {

View File

@ -57,11 +57,9 @@ namespace dawn_native {
ExtensionsSet ExtensionNamesToExtensionsSet( ExtensionsSet ExtensionNamesToExtensionsSet(
const std::vector<const char*>& requiredExtensions); const std::vector<const char*>& requiredExtensions);
void EnableBackendValidation(bool enableBackendValidation);
bool IsBackendValidationEnabled() const; bool IsBackendValidationEnabled() const;
void SetBackendValidationLevel(BackendValidationLevel level);
void EnableGPUBasedBackendValidation(bool enableGPUBasedBackendValidation); BackendValidationLevel GetBackendValidationLevel() const;
bool IsGPUBasedBackendValidationEnabled() const;
void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup); void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup);
bool IsBeginCaptureOnStartupEnabled() const; bool IsBeginCaptureOnStartupEnabled() const;
@ -89,9 +87,8 @@ namespace dawn_native {
bool mBackendsConnected = false; bool mBackendsConnected = false;
bool mDiscoveredDefaultAdapters = false; bool mDiscoveredDefaultAdapters = false;
bool mEnableBackendValidation = false;
bool mBeginCaptureOnStartup = false; bool mBeginCaptureOnStartup = false;
bool mEnableGPUValidation = false; BackendValidationLevel mBackendValidationLevel = BackendValidationLevel::Disabled;
dawn_platform::Platform* mPlatform = nullptr; dawn_platform::Platform* mPlatform = nullptr;

View File

@ -25,23 +25,25 @@ namespace dawn_native { namespace d3d12 {
namespace { namespace {
ResultOrError<ComPtr<IDXGIFactory4>> CreateFactory(const PlatformFunctions* functions, ResultOrError<ComPtr<IDXGIFactory4>> CreateFactory(const PlatformFunctions* functions,
bool enableBackendValidation, BackendValidationLevel validationLevel,
bool beginCaptureOnStartup, bool beginCaptureOnStartup) {
bool enableGPUBasedBackendValidation) {
ComPtr<IDXGIFactory4> factory; ComPtr<IDXGIFactory4> factory;
uint32_t dxgiFactoryFlags = 0; uint32_t dxgiFactoryFlags = 0;
// Enable the debug layer (requires the Graphics Tools "optional feature"). // Enable the debug layer (requires the Graphics Tools "optional feature").
{ {
if (enableBackendValidation) { if (validationLevel != BackendValidationLevel::Disabled) {
ComPtr<ID3D12Debug1> debugController; ComPtr<ID3D12Debug3> debugController;
if (SUCCEEDED( if (SUCCEEDED(
functions->d3d12GetDebugInterface(IID_PPV_ARGS(&debugController)))) { functions->d3d12GetDebugInterface(IID_PPV_ARGS(&debugController)))) {
ASSERT(debugController != nullptr); ASSERT(debugController != nullptr);
debugController->EnableDebugLayer(); debugController->EnableDebugLayer();
debugController->SetEnableGPUBasedValidation( debugController->SetEnableGPUBasedValidation(true);
enableGPUBasedBackendValidation); if (validationLevel == BackendValidationLevel::Partial) {
debugController->SetGPUBasedValidationFlags(
D3D12_GPU_BASED_VALIDATION_FLAGS_DISABLE_STATE_TRACKING);
}
// Enable additional debug layers. // Enable additional debug layers.
dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG; dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;
@ -97,9 +99,8 @@ namespace dawn_native { namespace d3d12 {
const auto instance = GetInstance(); const auto instance = GetInstance();
DAWN_TRY_ASSIGN(mFactory, DAWN_TRY_ASSIGN(mFactory,
CreateFactory(mFunctions.get(), instance->IsBackendValidationEnabled(), CreateFactory(mFunctions.get(), instance->GetBackendValidationLevel(),
instance->IsBeginCaptureOnStartupEnabled(), instance->IsBeginCaptureOnStartupEnabled()));
instance->IsGPUBasedBackendValidationEnabled()));
return {}; return {};
} }

View File

@ -129,6 +129,8 @@ namespace dawn_native {
AdapterDiscoveryOptionsBase(WGPUBackendType type); AdapterDiscoveryOptionsBase(WGPUBackendType type);
}; };
enum BackendValidationLevel { Full, Partial, Disabled };
// Represents a connection to dawn_native and is used for dependency injection, discovering // Represents a connection to dawn_native and is used for dependency injection, discovering
// system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter). // system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter).
// //
@ -155,15 +157,13 @@ namespace dawn_native {
const ToggleInfo* GetToggleInfo(const char* toggleName); const ToggleInfo* GetToggleInfo(const char* toggleName);
// Enable backend's validation layers if it has. // Enables backend validation layers
void EnableBackendValidation(bool enableBackendValidation); void EnableBackendValidation(bool enableBackendValidation);
void SetBackendValidationLevel(BackendValidationLevel validationLevel);
// Enable debug capture on Dawn startup // Enable debug capture on Dawn startup
void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup); void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup);
// Enable GPU based backend validation if it has.
void EnableGPUBasedBackendValidation(bool enableGPUBasedBackendValidation);
void SetPlatform(dawn_platform::Platform* platform); void SetPlatform(dawn_platform::Platform* platform);
// Returns the underlying WGPUInstance object. // Returns the underlying WGPUInstance object.

View File

@ -212,7 +212,7 @@ void DawnTestEnvironment::SetEnvironment(DawnTestEnvironment* env) {
DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) { DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
ParseArgs(argc, argv); ParseArgs(argc, argv);
if (mEnableBackendValidation) { if (mBackendValidationLevel != dawn_native::BackendValidationLevel::Disabled) {
mPlatformDebugLogger = mPlatformDebugLogger =
std::unique_ptr<utils::PlatformDebugLogger>(utils::CreatePlatformDebugLogger()); std::unique_ptr<utils::PlatformDebugLogger>(utils::CreatePlatformDebugLogger());
} }
@ -240,9 +240,24 @@ void DawnTestEnvironment::ParseArgs(int argc, char** argv) {
continue; continue;
} }
if (strcmp("-d", argv[i]) == 0 || strcmp("--enable-backend-validation", argv[i]) == 0) { constexpr const char kEnableBackendValidationSwitch[] = "--enable-backend-validation";
mEnableBackendValidation = true; argLen = sizeof(kEnableBackendValidationSwitch) - 1;
continue; if (strncmp(argv[i], kEnableBackendValidationSwitch, argLen) == 0) {
const char* level = argv[i] + argLen;
if (level[0] != '\0') {
if (strcmp(level, "=full") == 0) {
mBackendValidationLevel = dawn_native::BackendValidationLevel::Full;
} else if (strcmp(level, "=partial") == 0) {
mBackendValidationLevel = dawn_native::BackendValidationLevel::Partial;
} else if (strcmp(level, "=disabled") == 0) {
mBackendValidationLevel = dawn_native::BackendValidationLevel::Disabled;
} else {
dawn::ErrorLog() << "Invalid backend validation level" << level;
UNREACHABLE();
}
} else {
mBackendValidationLevel = dawn_native::BackendValidationLevel::Full;
}
} }
if (strcmp("-c", argv[i]) == 0 || strcmp("--begin-capture-on-startup", argv[i]) == 0) { if (strcmp("-c", argv[i]) == 0 || strcmp("--begin-capture-on-startup", argv[i]) == 0) {
@ -317,15 +332,18 @@ void DawnTestEnvironment::ParseArgs(int argc, char** argv) {
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
dawn::InfoLog() dawn::InfoLog()
<< "\n\nUsage: " << argv[0] << "\n\nUsage: " << argv[0]
<< " [GTEST_FLAGS...] [-w] [-d] [-c]\n" << " [GTEST_FLAGS...] [-w] [-c]\n"
" [--enable-toggles=toggles] [--disable-toggles=toggles]\n" " [--enable-toggles=toggles] [--disable-toggles=toggles]\n"
" [--adapter-vendor-id=x]" " [--adapter-vendor-id=x] "
" [--exclusive-device-type-preference=integrated,cpu,discrete]\n\n" "[--enable-backend-validation[=full,partial,disabled]]\n"
" [--exclusive-device-type-preference=integrated,cpu,discrete]\n\n"
" -w, --use-wire: Run the tests through the wire (defaults to no wire)\n" " -w, --use-wire: Run the tests through the wire (defaults to no wire)\n"
" -d, --enable-backend-validation: Enable backend validation (defaults"
" to disabled)\n"
" -c, --begin-capture-on-startup: Begin debug capture on startup " " -c, --begin-capture-on-startup: Begin debug capture on startup "
"(defaults to no capture)\n" "(defaults to no capture)\n"
" --enable-backend-validation: Enables backend validation. Defaults to 'full'\n"
" to enable all available backend validation. Set to 'partial' to\n"
" enable a subset of backend validation with less performance overhead.\n"
" Set to 'disabled' to run with no validation (same as no flag).\n"
" --enable-toggles: Comma-delimited list of Dawn toggles to enable.\n" " --enable-toggles: Comma-delimited list of Dawn toggles to enable.\n"
" ex.) skip_validation,use_tint_generator,disable_robustness,turn_off_vsync\n" " ex.) skip_validation,use_tint_generator,disable_robustness,turn_off_vsync\n"
" --disable-toggles: Comma-delimited list of Dawn toggles to disable\n" " --disable-toggles: Comma-delimited list of Dawn toggles to disable\n"
@ -341,10 +359,8 @@ void DawnTestEnvironment::ParseArgs(int argc, char** argv) {
std::unique_ptr<dawn_native::Instance> DawnTestEnvironment::CreateInstanceAndDiscoverAdapters() { std::unique_ptr<dawn_native::Instance> DawnTestEnvironment::CreateInstanceAndDiscoverAdapters() {
auto instance = std::make_unique<dawn_native::Instance>(); auto instance = std::make_unique<dawn_native::Instance>();
instance->EnableBackendValidation(mEnableBackendValidation);
instance->EnableGPUBasedBackendValidation(mEnableBackendValidation);
instance->EnableBeginCaptureOnStartup(mBeginCaptureOnStartup); instance->EnableBeginCaptureOnStartup(mBeginCaptureOnStartup);
instance->SetBackendValidationLevel(mBackendValidationLevel);
instance->DiscoverDefaultAdapters(); instance->DiscoverDefaultAdapters();
#ifdef DAWN_ENABLE_BACKEND_OPENGL #ifdef DAWN_ENABLE_BACKEND_OPENGL
@ -498,8 +514,21 @@ void DawnTestEnvironment::PrintTestConfigurationAndAdapterInfo(
"UseWire: " "UseWire: "
<< (mUseWire ? "true" : "false") << (mUseWire ? "true" : "false")
<< "\n" << "\n"
"EnableBackendValidation: " "BackendValidation: ";
<< (mEnableBackendValidation ? "true" : "false");
switch (mBackendValidationLevel) {
case dawn_native::BackendValidationLevel::Full:
log << "full";
break;
case dawn_native::BackendValidationLevel::Partial:
log << "partial";
break;
case dawn_native::BackendValidationLevel::Disabled:
log << "disabled";
break;
default:
UNREACHABLE();
}
if (GetEnabledToggles().size() > 0) { if (GetEnabledToggles().size() > 0) {
log << "\n" log << "\n"
@ -563,8 +592,8 @@ bool DawnTestEnvironment::UsesWire() const {
return mUseWire; return mUseWire;
} }
bool DawnTestEnvironment::IsBackendValidationEnabled() const { dawn_native::BackendValidationLevel DawnTestEnvironment::GetBackendValidationLevel() const {
return mEnableBackendValidation; return mBackendValidationLevel;
} }
dawn_native::Instance* DawnTestEnvironment::GetInstance() const { dawn_native::Instance* DawnTestEnvironment::GetInstance() const {
@ -700,7 +729,7 @@ bool DawnTestBase::UsesWire() const {
} }
bool DawnTestBase::IsBackendValidationEnabled() const { bool DawnTestBase::IsBackendValidationEnabled() const {
return gTestEnv->IsBackendValidationEnabled(); return gTestEnv->GetBackendValidationLevel() != dawn_native::BackendValidationLevel::Disabled;
} }
bool DawnTestBase::HasWGSL() const { bool DawnTestBase::HasWGSL() const {

View File

@ -206,7 +206,7 @@ class DawnTestEnvironment : public testing::Environment {
void TearDown() override; void TearDown() override;
bool UsesWire() const; bool UsesWire() const;
bool IsBackendValidationEnabled() const; dawn_native::BackendValidationLevel GetBackendValidationLevel() const;
dawn_native::Instance* GetInstance() const; dawn_native::Instance* GetInstance() const;
bool HasVendorIdFilter() const; bool HasVendorIdFilter() const;
uint32_t GetVendorIdFilter() const; uint32_t GetVendorIdFilter() const;
@ -227,7 +227,8 @@ class DawnTestEnvironment : public testing::Environment {
void PrintTestConfigurationAndAdapterInfo(dawn_native::Instance* instance) const; void PrintTestConfigurationAndAdapterInfo(dawn_native::Instance* instance) const;
bool mUseWire = false; bool mUseWire = false;
bool mEnableBackendValidation = false; dawn_native::BackendValidationLevel mBackendValidationLevel =
dawn_native::BackendValidationLevel::Disabled;
bool mBeginCaptureOnStartup = false; bool mBeginCaptureOnStartup = false;
bool mHasVendorIdFilter = false; bool mHasVendorIdFilter = false;
uint32_t mVendorIdFilter = 0; uint32_t mVendorIdFilter = 0;