From bdde209ed99e7f510d33b0734165210baf153ae3 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 22 Nov 2017 17:27:17 -0500 Subject: [PATCH] VulkanBinding: make a dummy Vulkan swapchain impl --- src/include/nxt/nxt_wsi.h | 5 ++++ src/utils/VulkanBinding.cpp | 48 ++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/include/nxt/nxt_wsi.h b/src/include/nxt/nxt_wsi.h index 76828ca741..025925d281 100644 --- a/src/include/nxt/nxt_wsi.h +++ b/src/include/nxt/nxt_wsi.h @@ -66,4 +66,9 @@ typedef struct { } nxtWSIContextGL; #endif +#ifdef NXT_ENABLE_BACKEND_VULKAN +typedef struct { +} nxtWSIContextVulkan; +#endif + #endif // NXT_WSI_H diff --git a/src/utils/VulkanBinding.cpp b/src/utils/VulkanBinding.cpp index 0caacce870..8ed48a2a58 100644 --- a/src/utils/VulkanBinding.cpp +++ b/src/utils/VulkanBinding.cpp @@ -14,6 +14,9 @@ #include "utils/BackendBinding.h" +#include "nxt/nxt_wsi.h" +#include "utils/SwapChainImpl.h" + namespace backend { namespace vulkan { void Init(nxtProcTable* procs, nxtDevice* device); @@ -22,6 +25,43 @@ namespace backend { namespace utils { + class SwapChainImplVulkan : SwapChainImpl { + public: + static nxtSwapChainImplementation Create(GLFWwindow* window) { + auto impl = GenerateSwapChainImplementation(); + impl.userData = new SwapChainImplVulkan(window); + return impl; + } + + private: + GLFWwindow* window = nullptr; + + SwapChainImplVulkan(GLFWwindow* window) + : window(window) { + } + + ~SwapChainImplVulkan() { + } + + // For GenerateSwapChainImplementation + friend class SwapChainImpl; + + void Init(nxtWSIContextVulkan*) { + } + + nxtSwapChainError Configure(nxtTextureFormat, nxtTextureUsageBit, uint32_t, uint32_t) { + return NXT_SWAP_CHAIN_NO_ERROR; + } + + nxtSwapChainError GetNextTexture(nxtSwapChainNextTexture*) { + return NXT_SWAP_CHAIN_NO_ERROR; + } + + nxtSwapChainError Present() { + return NXT_SWAP_CHAIN_NO_ERROR; + } + }; + class VulkanBinding : public BackendBinding { public: void SetupGLFWWindowHints() override { @@ -30,11 +70,17 @@ namespace utils { backend::vulkan::Init(procs, device); } uint64_t GetSwapChainImplementation() override { - return 0; + if (swapchainImpl.userData == nullptr) { + swapchainImpl = SwapChainImplVulkan::Create(window); + } + return reinterpret_cast(&swapchainImpl); } nxtTextureFormat GetPreferredSwapChainTextureFormat() override { return NXT_TEXTURE_FORMAT_R8_G8_B8_A8_UNORM; } + + private: + nxtSwapChainImplementation swapchainImpl = {}; };