Enable D3D12 validation layers

Run end2end tests with argument '-d' or '--enable-backend-validation'

Change-Id: I34a3f453dcd3a57d76301801ae2abe42f847cb1b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/7140
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Hao Li <hao.x.li@intel.com>
This commit is contained in:
Li Hao 2019-05-15 06:06:26 +00:00 committed by Commit Bot service account
parent 2e56970932
commit 0195dbf908
8 changed files with 58 additions and 21 deletions

View File

@ -99,4 +99,11 @@ namespace dawn_native {
return mImpl->GetToggleInfo(toggleName);
}
void Instance::EnableBackendValidation(bool enableBackendValidation) {
mImpl->EnableBackendValidation(enableBackendValidation);
}
bool Instance::IsBackendValidationEnabled() {
return mImpl->IsBackendValidationEnabled();
}
} // namespace dawn_native

View File

@ -230,4 +230,12 @@ namespace dawn_native {
return false;
}
void InstanceBase::EnableBackendValidation(bool enableBackendValidation) {
mEnableBackendValidation = enableBackendValidation;
}
bool InstanceBase::IsBackendValidationEnabled() {
return mEnableBackendValidation;
}
} // namespace dawn_native

View File

@ -51,6 +51,9 @@ namespace dawn_native {
Toggle ToggleNameToEnum(const char* toggleName);
const char* ToggleEnumToName(Toggle toggle);
void EnableBackendValidation(bool enableBackendValidation);
bool IsBackendValidationEnabled();
private:
// Lazily creates connections to all backends that have been compiled.
void EnsureBackendConnections();
@ -66,6 +69,7 @@ namespace dawn_native {
bool mDiscoveredDefaultAdapters = false;
bool mToggleNameToEnumMapInitialized = false;
bool mEnableBackendValidation = false;
std::vector<std::unique_ptr<BackendConnection>> mBackends;
std::vector<std::unique_ptr<AdapterBase>> mAdapters;

View File

@ -23,30 +23,33 @@ namespace dawn_native { namespace d3d12 {
namespace {
ResultOrError<ComPtr<IDXGIFactory4>> CreateFactory(const PlatformFunctions* functions) {
ResultOrError<ComPtr<IDXGIFactory4>> CreateFactory(const PlatformFunctions* functions,
bool enableBackendValidation) {
ComPtr<IDXGIFactory4> factory;
uint32_t dxgiFactoryFlags = 0;
#if defined(DAWN_ENABLE_ASSERTS)
// Enable the debug layer (requires the Graphics Tools "optional feature").
{
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(functions->d3d12GetDebugInterface(IID_PPV_ARGS(&debugController)))) {
ASSERT(debugController != nullptr);
debugController->EnableDebugLayer();
if (enableBackendValidation) {
ComPtr<ID3D12Debug> debugController;
if (SUCCEEDED(
functions->d3d12GetDebugInterface(IID_PPV_ARGS(&debugController)))) {
ASSERT(debugController != nullptr);
debugController->EnableDebugLayer();
// Enable additional debug layers.
dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;
}
// Enable additional debug layers.
dxgiFactoryFlags |= DXGI_CREATE_FACTORY_DEBUG;
}
ComPtr<IDXGIDebug1> dxgiDebug;
if (SUCCEEDED(functions->dxgiGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug)))) {
ASSERT(dxgiDebug != nullptr);
dxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL,
DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_ALL));
ComPtr<IDXGIDebug1> dxgiDebug;
if (SUCCEEDED(functions->dxgiGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug)))) {
ASSERT(dxgiDebug != nullptr);
dxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL,
DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_ALL));
}
}
}
#endif // defined(DAWN_ENABLE_ASSERTS)
if (FAILED(functions->createDxgiFactory2(dxgiFactoryFlags, IID_PPV_ARGS(&factory)))) {
return DAWN_CONTEXT_LOST_ERROR("Failed to create a DXGI factory");
@ -65,7 +68,8 @@ namespace dawn_native { namespace d3d12 {
mFunctions = std::make_unique<PlatformFunctions>();
DAWN_TRY(mFunctions->LoadFunctions());
DAWN_TRY_ASSIGN(mFactory, CreateFactory(mFunctions.get()));
DAWN_TRY_ASSIGN(
mFactory, CreateFactory(mFunctions.get(), GetInstance()->IsBackendValidationEnabled()));
return {};
}

View File

@ -19,9 +19,7 @@
#include <dxgi1_4.h>
#include <wrl.h>
#if defined(DAWN_ENABLE_ASSERTS)
# include <dxgidebug.h>
#endif // defined(DAWN_ENABLE_ASSERTS)
#include <dxgidebug.h>
using Microsoft::WRL::ComPtr;

View File

@ -125,6 +125,10 @@ namespace dawn_native {
const ToggleInfo* GetToggleInfo(const char* toggleName);
// Enable backend's validation layers if it has.
void EnableBackendValidation(bool enableBackendValidation);
bool IsBackendValidationEnabled();
private:
InstanceBase* mImpl = nullptr;
};

View File

@ -102,9 +102,17 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
continue;
}
if (strcmp("-d", argv[i]) == 0 || strcmp("--enable-backend-validation", argv[i]) == 0) {
mEnableBackendValidation = true;
continue;
}
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
std::cout << "\n\nUsage: " << argv[0] << " [GTEST_FLAGS...] [-w] \n";
std::cout << " -w, --use-wire: Run the tests through the wire (defaults to no wire)";
std::cout << "\n\nUsage: " << argv[0]
<< " [GTEST_FLAGS...] [-w] [--enable-validation-layers]\n";
std::cout << " -w, --use-wire: Run the tests through the wire (defaults to no wire)\n";
std::cout << " -d, --enable-backend-validation: Enable backend validation (defaults"
<< " to disabled)\n";
std::cout << std::endl;
continue;
}
@ -115,6 +123,7 @@ void DawnTestEnvironment::SetUp() {
ASSERT_TRUE(glfwInit());
mInstance = std::make_unique<dawn_native::Instance>();
mInstance->EnableBackendValidation(mEnableBackendValidation);
static constexpr dawn_native::BackendType kAllBackends[] = {
dawn_native::BackendType::D3D12,
@ -134,6 +143,8 @@ void DawnTestEnvironment::SetUp() {
std::cout << "Testing configuration\n";
std::cout << "---------------------\n";
std::cout << "UseWire: " << (mUseWire ? "true" : "false") << "\n";
std::cout << "EnableBackendValidation: " << (mEnableBackendValidation ? "true" : "false")
<< "\n";
std::cout << "\n";
// Preparing for outputting hex numbers

View File

@ -114,6 +114,7 @@ class DawnTestEnvironment : public testing::Environment {
void CreateBackendWindow(dawn_native::BackendType type);
bool mUseWire = false;
bool mEnableBackendValidation = false;
std::unique_ptr<dawn_native::Instance> mInstance;
// Windows don't usually like to be bound to one API than the other, for example switching