Add Vulkan validation layers on Windows

Deploy self-built Vulkan validation layers instead of system installed
one. And it will reuse third_party/angle's Vulkan validation layers if
building with chromium.

Bug: dawn:150
Change-Id: I94e26f7a152fb2a1c39bcb102d60024f4d65eee6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11120
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Li, Hao
2019-11-07 12:13:27 +00:00
committed by Commit Bot service account
parent 64cfaeac4c
commit 0e1bef3251
11 changed files with 264 additions and 0 deletions

View File

@@ -100,6 +100,8 @@ if (is_win || is_linux || is_mac || is_fuchsia) {
"SerialQueue.h",
"SerialStorage.h",
"SwapChainUtils.h",
"SystemUtils.cpp",
"SystemUtils.h",
"vulkan_platform.h",
"windows_with_undefs.h",
"xlib_with_undefs.h",

117
src/common/SystemUtils.cpp Normal file
View File

@@ -0,0 +1,117 @@
// Copyright 2019 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "common/SystemUtils.h"
#if defined(DAWN_PLATFORM_WINDOWS)
# include <Windows.h>
# include <vector>
#elif defined(DAWN_PLATFORM_LINUX)
# include <limits.h>
# include <unistd.h>
# include <cstdlib>
#elif defined(DAWN_PLATFORM_MACOS)
# include <mach-o/dyld.h>
# include <vector>
#endif
#include <array>
#if defined(DAWN_PLATFORM_WINDOWS)
const char* GetPathSeparator() {
return "\\";
}
std::string GetEnvironmentVar(const char* variableName) {
// First pass a size of 0 to get the size of variable value.
char* tempBuf = nullptr;
DWORD result = GetEnvironmentVariableA(variableName, tempBuf, 0);
if (result == 0) {
return "";
}
// Then get variable value with its actual size.
std::vector<char> buffer(result + 1);
if (GetEnvironmentVariableA(variableName, buffer.data(), static_cast<DWORD>(buffer.size())) ==
0) {
return "";
}
return std::string(buffer.data());
}
bool SetEnvironmentVar(const char* variableName, const char* value) {
return SetEnvironmentVariableA(variableName, value) == TRUE;
}
#elif defined(DAWN_PLATFORM_POSIX)
const char* GetPathSeparator() {
return "/";
}
std::string GetEnvironmentVar(const char* variableName) {
char* value = getenv(variableName);
return value == nullptr ? "" : std::string(value);
}
bool SetEnvironmentVar(const char* variableName, const char* value) {
return setenv(variableName, value, 1) == 0;
}
#else
# error "Implement Get/SetEnvironmentVar for your platform."
#endif
#if defined(DAWN_PLATFORM_WINDOWS)
std::string GetExecutablePath() {
std::array<char, MAX_PATH> executableFileBuf;
DWORD executablePathLen = GetModuleFileNameA(nullptr, executableFileBuf.data(),
static_cast<DWORD>(executableFileBuf.size()));
return executablePathLen > 0 ? std::string(executableFileBuf.data()) : "";
}
#elif defined(DAWN_PLATFORM_LINUX)
std::string GetExecutablePath() {
std::array<char, PATH_MAX> path;
ssize_t result = readlink("/proc/self/exe", path.data(), PATH_MAX - 1);
if (result < 0 || static_cast<size_t>(result) >= PATH_MAX - 1) {
return "";
}
path[result] = '\0';
return path.data();
}
#elif defined(DAWN_PLATFORM_MACOS)
std::string GetExecutablePath() {
uint32_t size = 0;
_NSGetExecutablePath(nullptr, &size);
std::vector<char> buffer(size + 1);
if (_NSGetExecutablePath(buffer.data(), &size) != 0) {
return "";
}
buffer[size] = '\0';
return buffer.data();
}
#elif defined(DAWN_PLATFORM_FUCHSIA)
std::string GetExecutablePath() {
// TODO: Implement on Fuchsia
return "";
}
#else
# error "Implement GetExecutablePath for your platform."
#endif
std::string GetExecutableDirectory() {
std::string exePath = GetExecutablePath();
size_t lastPathSepLoc = exePath.find_last_of(GetPathSeparator());
return lastPathSepLoc != std::string::npos ? exePath.substr(0, lastPathSepLoc + 1) : "";
}

27
src/common/SystemUtils.h Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2019 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef COMMON_SYSTEMUTILS_H_
#define COMMON_SYSTEMUTILS_H_
#include "common/Platform.h"
#include <string>
const char* GetPathSeparator();
std::string GetEnvironmentVar(const char* variableName);
bool SetEnvironmentVar(const char* variableName, const char* value);
std::string GetExecutableDirectory();
#endif // COMMON_SYSTEMUTILS_H_