diff --git a/src/dawn_native/vulkan/DeviceVk.cpp b/src/dawn_native/vulkan/DeviceVk.cpp index 725df61f77..8b88141484 100644 --- a/src/dawn_native/vulkan/DeviceVk.cpp +++ b/src/dawn_native/vulkan/DeviceVk.cpp @@ -54,8 +54,8 @@ const char kVulkanLibName[] = "vulkan-1.dll"; namespace dawn_native { namespace vulkan { - dawnDevice CreateDevice(const std::vector& requiredInstanceExtensions) { - return reinterpret_cast(new Device(requiredInstanceExtensions)); + dawnDevice CreateDevice() { + return reinterpret_cast(new Device()); } VkInstance GetInstance(dawnDevice device) { @@ -87,8 +87,8 @@ namespace dawn_native { namespace vulkan { // Device - Device::Device(const std::vector& requiredInstanceExtensions) { - MaybeError maybeError = Initialize(requiredInstanceExtensions); + Device::Device() { + MaybeError maybeError = Initialize(); // In device initialization, the error callback can't have been set yet. // So it's too early to use ConsumedError - consume the error manually. @@ -101,7 +101,7 @@ namespace dawn_native { namespace vulkan { } } - MaybeError Device::Initialize(const std::vector& requiredInstanceExtensions) { + MaybeError Device::Initialize() { if (!mVulkanLib.Open(kVulkanLibName)) { return DAWN_CONTEXT_LOST_ERROR(std::string("Couldn't open ") + kVulkanLibName); } @@ -112,7 +112,7 @@ namespace dawn_native { namespace vulkan { DAWN_TRY_ASSIGN(mGlobalInfo, GatherGlobalInfo(*this)); VulkanGlobalKnobs usedGlobalKnobs = {}; - DAWN_TRY_ASSIGN(usedGlobalKnobs, CreateInstance(requiredInstanceExtensions)); + DAWN_TRY_ASSIGN(usedGlobalKnobs, CreateInstance()); *static_cast(&mGlobalInfo) = usedGlobalKnobs; DAWN_TRY(functions->LoadInstanceProcs(mInstance, mGlobalInfo)); @@ -421,22 +421,11 @@ namespace dawn_native { namespace vulkan { mWaitSemaphores.push_back(semaphore); } - ResultOrError Device::CreateInstance( - const std::vector& requiredExtensions) { + ResultOrError Device::CreateInstance() { VulkanGlobalKnobs usedKnobs = {}; std::vector layersToRequest; - std::vector extensionsToRequest = requiredExtensions; - - auto AddExtensionIfNotPresent = [](std::vector* extensions, - const char* extension) { - for (const char* present : *extensions) { - if (strcmp(present, extension) == 0) { - return; - } - } - extensions->push_back(extension); - }; + std::vector extensionsToRequest; // vktrace works by instering a layer, but we hide it behind a macro due to the vktrace // layer crashes when used without vktrace server started, see this vktrace issue: @@ -463,14 +452,36 @@ namespace dawn_native { namespace vulkan { usedKnobs.standardValidation = true; } if (mGlobalInfo.debugReport) { - AddExtensionIfNotPresent(&extensionsToRequest, kExtensionNameExtDebugReport); + extensionsToRequest.push_back(kExtensionNameExtDebugReport); usedKnobs.debugReport = true; } #endif + // Always request all extensions used to create VkSurfaceKHR objects so that they are + // always available for embedders looking to create VkSurfaceKHR on our VkInstance. + if (mGlobalInfo.macosSurface) { + extensionsToRequest.push_back(kExtensionNameMvkMacosSurface); + usedKnobs.macosSurface = true; + } if (mGlobalInfo.surface) { - AddExtensionIfNotPresent(&extensionsToRequest, kExtensionNameKhrSurface); + extensionsToRequest.push_back(kExtensionNameKhrSurface); usedKnobs.surface = true; } + if (mGlobalInfo.waylandSurface) { + extensionsToRequest.push_back(kExtensionNameKhrWaylandSurface); + usedKnobs.waylandSurface = true; + } + if (mGlobalInfo.win32Surface) { + extensionsToRequest.push_back(kExtensionNameKhrWin32Surface); + usedKnobs.win32Surface = true; + } + if (mGlobalInfo.xcbSurface) { + extensionsToRequest.push_back(kExtensionNameKhrXcbSurface); + usedKnobs.xcbSurface = true; + } + if (mGlobalInfo.xlibSurface) { + extensionsToRequest.push_back(kExtensionNameKhrXlibSurface); + usedKnobs.xlibSurface = true; + } VkApplicationInfo appInfo; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; diff --git a/src/dawn_native/vulkan/DeviceVk.h b/src/dawn_native/vulkan/DeviceVk.h index 4ff27d41f9..b3af48a2d8 100644 --- a/src/dawn_native/vulkan/DeviceVk.h +++ b/src/dawn_native/vulkan/DeviceVk.h @@ -38,7 +38,7 @@ namespace dawn_native { namespace vulkan { class Device : public DeviceBase { public: - Device(const std::vector& requiredInstanceExtensions); + Device(); ~Device(); // Contains all the Vulkan entry points, vkDoFoo is called via device->fn.DoFoo. @@ -96,9 +96,8 @@ namespace dawn_native { namespace vulkan { TextureBase* texture, const TextureViewDescriptor* descriptor) override; - MaybeError Initialize(const std::vector& requiredInstanceExtensions); - ResultOrError CreateInstance( - const std::vector& requiredExtensions); + MaybeError Initialize(); + ResultOrError CreateInstance(); ResultOrError CreateDevice(); void GatherQueueFromDevice(); diff --git a/src/dawn_native/vulkan/VulkanInfo.cpp b/src/dawn_native/vulkan/VulkanInfo.cpp index 625d7c144b..c8c11a84b9 100644 --- a/src/dawn_native/vulkan/VulkanInfo.cpp +++ b/src/dawn_native/vulkan/VulkanInfo.cpp @@ -35,8 +35,13 @@ namespace dawn_native { namespace vulkan { const char kLayerNameRenderDocCapture[] = "VK_LAYER_RENDERDOC_Capture"; const char kExtensionNameExtDebugReport[] = "VK_EXT_debug_report"; + const char kExtensionNameMvkMacosSurface[] = "VK_MVK_macos_surface"; const char kExtensionNameKhrSurface[] = "VK_KHR_surface"; const char kExtensionNameKhrSwapchain[] = "VK_KHR_swapchain"; + const char kExtensionNameKhrWaylandSurface[] = "VK_KHR_wayland_surface"; + const char kExtensionNameKhrWin32Surface[] = "VK_KHR_win32_surface"; + const char kExtensionNameKhrXcbSurface[] = "VK_KHR_xcb_surface"; + const char kExtensionNameKhrXlibSurface[] = "VK_KHR_xlib_surface"; ResultOrError GatherGlobalInfo(const Device& device) { VulkanGlobalInfo info = {}; @@ -91,9 +96,24 @@ namespace dawn_native { namespace vulkan { if (IsExtensionName(extension, kExtensionNameExtDebugReport)) { info.debugReport = true; } + if (IsExtensionName(extension, kExtensionNameMvkMacosSurface)) { + info.macosSurface = true; + } if (IsExtensionName(extension, kExtensionNameKhrSurface)) { info.surface = true; } + if (IsExtensionName(extension, kExtensionNameKhrWaylandSurface)) { + info.waylandSurface = true; + } + if (IsExtensionName(extension, kExtensionNameKhrWin32Surface)) { + info.win32Surface = true; + } + if (IsExtensionName(extension, kExtensionNameKhrXcbSurface)) { + info.xcbSurface = true; + } + if (IsExtensionName(extension, kExtensionNameKhrXlibSurface)) { + info.xlibSurface = true; + } } } diff --git a/src/dawn_native/vulkan/VulkanInfo.h b/src/dawn_native/vulkan/VulkanInfo.h index 383ea9bccb..fee253b84a 100644 --- a/src/dawn_native/vulkan/VulkanInfo.h +++ b/src/dawn_native/vulkan/VulkanInfo.h @@ -29,8 +29,13 @@ namespace dawn_native { namespace vulkan { extern const char kLayerNameRenderDocCapture[]; extern const char kExtensionNameExtDebugReport[]; + extern const char kExtensionNameMvkMacosSurface[]; extern const char kExtensionNameKhrSurface[]; extern const char kExtensionNameKhrSwapchain[]; + extern const char kExtensionNameKhrWaylandSurface[]; + extern const char kExtensionNameKhrWin32Surface[]; + extern const char kExtensionNameKhrXcbSurface[]; + extern const char kExtensionNameKhrXlibSurface[]; // Global information - gathered before the instance is created struct VulkanGlobalKnobs { @@ -41,7 +46,12 @@ namespace dawn_native { namespace vulkan { // Extensions bool debugReport = false; + bool macosSurface = false; bool surface = false; + bool waylandSurface = false; + bool win32Surface = false; + bool xcbSurface = false; + bool xlibSurface = false; }; struct VulkanGlobalInfo : VulkanGlobalKnobs { diff --git a/src/include/dawn_native/VulkanBackend.h b/src/include/dawn_native/VulkanBackend.h index e52e0cec04..9bf7a2a035 100644 --- a/src/include/dawn_native/VulkanBackend.h +++ b/src/include/dawn_native/VulkanBackend.h @@ -24,8 +24,7 @@ #include namespace dawn_native { namespace vulkan { - DAWN_NATIVE_EXPORT dawnDevice - CreateDevice(const std::vector& requiredInstanceExtensions); + DAWN_NATIVE_EXPORT dawnDevice CreateDevice(); DAWN_NATIVE_EXPORT VkInstance GetInstance(dawnDevice device); diff --git a/src/utils/VulkanBinding.cpp b/src/utils/VulkanBinding.cpp index bc3f62bacf..7cae7b4776 100644 --- a/src/utils/VulkanBinding.cpp +++ b/src/utils/VulkanBinding.cpp @@ -28,13 +28,7 @@ namespace utils { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); } dawnDevice CreateDevice() override { - uint32_t extensionCount = 0; - const char** glfwInstanceExtensions = - glfwGetRequiredInstanceExtensions(&extensionCount); - std::vector requiredExtensions(glfwInstanceExtensions, - glfwInstanceExtensions + extensionCount); - - mDevice = dawn_native::vulkan::CreateDevice(requiredExtensions); + mDevice = dawn_native::vulkan::CreateDevice(); return mDevice; } uint64_t GetSwapChainImplementation() override {