Directly load Swiftshader if no Vulkan driver is available
This may be a short term solution before linking our own version of the Vulkan Loader. Bug: dawn:283 Change-Id: Ifeddeaa5170bccc912c61059071a83c2b5fd9524 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15121 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
0d6619848d
commit
636e6cee4f
11
BUILD.gn
11
BUILD.gn
|
@ -543,9 +543,14 @@ source_set("libdawn_native_sources") {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (use_swiftshader) {
|
if (use_swiftshader) {
|
||||||
data_deps += [ "${dawn_swiftshader_dir}/src/Vulkan:icd_file" ]
|
data_deps += [
|
||||||
defines +=
|
"${dawn_swiftshader_dir}/src/Vulkan:icd_file",
|
||||||
[ "DAWN_SWIFTSHADER_VK_ICD_JSON=\"${swiftshader_icd_file_name}\"" ]
|
"${dawn_swiftshader_dir}/src/Vulkan:swiftshader_libvulkan",
|
||||||
|
]
|
||||||
|
defines += [
|
||||||
|
"DAWN_ENABLE_SWIFTSHADER",
|
||||||
|
"DAWN_SWIFTSHADER_VK_ICD_JSON=\"${swiftshader_icd_file_name}\"",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,16 +21,31 @@
|
||||||
#include "dawn_native/vulkan/AdapterVk.h"
|
#include "dawn_native/vulkan/AdapterVk.h"
|
||||||
#include "dawn_native/vulkan/VulkanError.h"
|
#include "dawn_native/vulkan/VulkanError.h"
|
||||||
|
|
||||||
|
// TODO(crbug.com/dawn/283): Link against the Vulkan Loader and remove this.
|
||||||
|
#if defined(DAWN_ENABLE_SWIFTSHADER)
|
||||||
|
# if defined(DAWN_PLATFORM_LINUX) || defined(DAWN_PLATFORM_FUSCHIA)
|
||||||
|
constexpr char kSwiftshaderLibName[] = "libvk_swiftshader.so";
|
||||||
|
# elif defined(DAWN_PLATFORM_WINDOWS)
|
||||||
|
constexpr char kSwiftshaderLibName[] = "vk_swiftshader.dll";
|
||||||
|
# elif defined(DAWN_PLATFORM_MAC)
|
||||||
|
constexpr char kSwiftshaderLibName[] = "libvk_swiftshader.dylib";
|
||||||
|
# else
|
||||||
|
# error "Unimplemented Swiftshader Vulkan backend platform"
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DAWN_PLATFORM_LINUX)
|
#if defined(DAWN_PLATFORM_LINUX)
|
||||||
# if defined(DAWN_PLATFORM_ANDROID)
|
# if defined(DAWN_PLATFORM_ANDROID)
|
||||||
const char kVulkanLibName[] = "libvulkan.so";
|
constexpr char kVulkanLibName[] = "libvulkan.so";
|
||||||
# else
|
# else
|
||||||
const char kVulkanLibName[] = "libvulkan.so.1";
|
constexpr char kVulkanLibName[] = "libvulkan.so.1";
|
||||||
# endif
|
# endif
|
||||||
#elif defined(DAWN_PLATFORM_WINDOWS)
|
#elif defined(DAWN_PLATFORM_WINDOWS)
|
||||||
const char kVulkanLibName[] = "vulkan-1.dll";
|
constexpr char kVulkanLibName[] = "vulkan-1.dll";
|
||||||
#elif defined(DAWN_PLATFORM_FUCHSIA)
|
#elif defined(DAWN_PLATFORM_FUCHSIA)
|
||||||
const char kVulkanLibName[] = "libvulkan.so";
|
constexpr char kVulkanLibName[] = "libvulkan.so";
|
||||||
|
#elif defined(DAWN_ENABLE_SWIFTSHADER)
|
||||||
|
const char* kVulkanLibName = kSwiftshaderLibName;
|
||||||
#else
|
#else
|
||||||
# error "Unimplemented Vulkan backend platform"
|
# error "Unimplemented Vulkan backend platform"
|
||||||
#endif
|
#endif
|
||||||
|
@ -66,7 +81,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
return mGlobalInfo;
|
return mGlobalInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
MaybeError Backend::Initialize() {
|
MaybeError Backend::LoadVulkan() {
|
||||||
#if defined(DAWN_ENABLE_VULKAN_VALIDATION_LAYERS)
|
#if defined(DAWN_ENABLE_VULKAN_VALIDATION_LAYERS)
|
||||||
if (GetInstance()->IsBackendValidationEnabled()) {
|
if (GetInstance()->IsBackendValidationEnabled()) {
|
||||||
std::string vkDataDir = GetExecutableDirectory() + DAWN_VK_DATA_DIR;
|
std::string vkDataDir = GetExecutableDirectory() + DAWN_VK_DATA_DIR;
|
||||||
|
@ -83,9 +98,25 @@ namespace dawn_native { namespace vulkan {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!mVulkanLib.Open(kVulkanLibName)) {
|
if (mVulkanLib.Open(kVulkanLibName)) {
|
||||||
return DAWN_DEVICE_LOST_ERROR(std::string("Couldn't open ") + kVulkanLibName);
|
return {};
|
||||||
}
|
}
|
||||||
|
dawn::WarningLog() << std::string("Couldn't open ") + kVulkanLibName;
|
||||||
|
|
||||||
|
#if defined(DAWN_ENABLE_SWIFTSHADER)
|
||||||
|
if (strcmp(kVulkanLibName, kSwiftshaderLibName) != 0) {
|
||||||
|
if (mVulkanLib.Open(kSwiftshaderLibName)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
dawn::WarningLog() << std::string("Couldn't open ") + kSwiftshaderLibName;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return DAWN_DEVICE_LOST_ERROR("Couldn't load Vulkan");
|
||||||
|
}
|
||||||
|
|
||||||
|
MaybeError Backend::Initialize() {
|
||||||
|
DAWN_TRY(LoadVulkan());
|
||||||
|
|
||||||
DAWN_TRY(mFunctions.LoadGlobalProcs(mVulkanLib));
|
DAWN_TRY(mFunctions.LoadGlobalProcs(mVulkanLib));
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override;
|
std::vector<std::unique_ptr<AdapterBase>> DiscoverDefaultAdapters() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
MaybeError LoadVulkan();
|
||||||
ResultOrError<VulkanGlobalKnobs> CreateInstance();
|
ResultOrError<VulkanGlobalKnobs> CreateInstance();
|
||||||
|
|
||||||
MaybeError RegisterDebugReport();
|
MaybeError RegisterDebugReport();
|
||||||
|
|
Loading…
Reference in New Issue