1616#include < shaderc/shaderc.hpp>
1717#endif
1818
19- #if defined(VK_USE_PLATFORM_WIN32_KHR)
20- // Define USE_MIRROR_WINDOW to open a otherwise-unused window for e.g. RenderDoc
21- #define USE_MIRROR_WINDOW
22- #endif
23-
2419// glslangValidator doesn't wrap its output in brackets if you don't have it define the whole array.
2520#if defined(USE_GLSLANGVALIDATOR)
2621#define SPV_PREFIX {
@@ -1043,7 +1038,7 @@ struct SwapchainImageContext {
10431038 VulkanDebugObjectNamer m_namer;
10441039};
10451040
1046- #if defined(USE_MIRROR_WINDOW )
1041+ #if defined(VK_USE_PLATFORM_WIN32_KHR )
10471042// Swapchain
10481043struct Swapchain {
10491044 VkFormat format{VK_FORMAT_B8G8R8A8_SRGB};
@@ -1270,7 +1265,7 @@ void Swapchain::Present(VkQueue queue, VkSemaphore drawComplete) {
12701265 }
12711266 CHECK_VKRESULT (res, " vkQueuePresentKHR" );
12721267}
1273- #endif // defined(USE_MIRROR_WINDOW )
1268+ #endif // defined(VK_USE_PLATFORM_WIN32_KHR )
12741269
12751270struct VulkanGraphicsPlugin : public IGraphicsPlugin {
12761271 VulkanGraphicsPlugin (const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> /* unused*/ )
@@ -1359,14 +1354,12 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
13591354 }
13601355 // TODO add back VK_EXT_debug_report code for compatibility with older systems? (Android)
13611356 }
1362- #if defined(USE_MIRROR_WINDOW)
1363- extensions.push_back (" VK_KHR_surface" );
13641357#if defined(VK_USE_PLATFORM_WIN32_KHR)
1365- extensions.push_back (" VK_KHR_win32_surface" );
1366- #else
1367- #error CreateSurface not supported on this OS
1358+ if (m_enableMirrorWindow) {
1359+ extensions.push_back (" VK_KHR_surface" );
1360+ extensions.push_back (" VK_KHR_win32_surface" );
1361+ }
13681362#endif // defined(VK_USE_PLATFORM_WIN32_KHR)
1369- #endif // defined(USE_MIRROR_WINDOW)
13701363
13711364 VkApplicationInfo appInfo{VK_STRUCTURE_TYPE_APPLICATION_INFO};
13721365 appInfo.pApplicationName = " hello_xr" ;
@@ -1438,8 +1431,10 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
14381431 VkPhysicalDeviceFeatures features{};
14391432 // features.samplerAnisotropy = VK_TRUE;
14401433
1441- #if defined(USE_MIRROR_WINDOW)
1442- deviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1434+ #if defined(VK_USE_PLATFORM_WIN32_KHR)
1435+ if (m_enableMirrorWindow) {
1436+ deviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1437+ }
14431438#endif
14441439
14451440 VkDeviceCreateInfo deviceInfo{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
@@ -1532,15 +1527,17 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
15321527 m_drawBuffer.UpdateIndices (Geometry::c_cubeIndices, numCubeIdicies, 0 );
15331528 m_drawBuffer.UpdateVertices (Geometry::c_cubeVertices, numCubeVerticies, 0 );
15341529
1535- #if defined(USE_MIRROR_WINDOW)
1536- m_swapchain.Create (m_vkInstance, m_vkPhysicalDevice, m_vkDevice, m_graphicsBinding.queueFamilyIndex );
1537-
1538- m_cmdBuffer.Reset ();
1539- m_cmdBuffer.Begin ();
1540- m_swapchain.Prepare (m_cmdBuffer.buf );
1541- m_cmdBuffer.End ();
1542- m_cmdBuffer.Exec (m_vkQueue);
1543- m_cmdBuffer.Wait ();
1530+ #if defined(VK_USE_PLATFORM_WIN32_KHR)
1531+ if (m_enableMirrorWindow) {
1532+ m_swapchain.Create (m_vkInstance, m_vkPhysicalDevice, m_vkDevice, m_graphicsBinding.queueFamilyIndex );
1533+
1534+ m_cmdBuffer.Reset ();
1535+ m_cmdBuffer.Begin ();
1536+ m_swapchain.Prepare (m_cmdBuffer.buf );
1537+ m_cmdBuffer.End ();
1538+ m_cmdBuffer.Exec (m_vkQueue);
1539+ m_cmdBuffer.Wait ();
1540+ }
15441541#endif
15451542 }
15461543
@@ -1651,9 +1648,9 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16511648 m_cmdBuffer.End ();
16521649 m_cmdBuffer.Exec (m_vkQueue);
16531650
1654- #if defined(USE_MIRROR_WINDOW )
1651+ #if defined(VK_USE_PLATFORM_WIN32_KHR )
16551652 // Cycle the window's swapchain on the last view rendered
1656- if (swapchainContext == &m_swapchainImageContexts.back ()) {
1653+ if (m_enableMirrorWindow && swapchainContext == &m_swapchainImageContexts.back ()) {
16571654 m_swapchain.Acquire ();
16581655 m_swapchain.Present (m_vkQueue);
16591656 }
@@ -1662,7 +1659,10 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16621659
16631660 uint32_t GetSupportedSwapchainSampleCount (const XrViewConfigurationView&) override { return VK_SAMPLE_COUNT_1_BIT; }
16641661
1665- void UpdateOptions (const std::shared_ptr<Options>& options) override { m_clearColor = options->GetBackgroundClearColor (); }
1662+ void UpdateOptions (const std::shared_ptr<Options>& options) override {
1663+ m_clearColor = options->GetBackgroundClearColor ();
1664+ m_enableMirrorWindow = options->EnableMirrorWindow ;
1665+ }
16661666
16671667 protected:
16681668 XrGraphicsBindingVulkan2KHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR};
@@ -1683,8 +1683,9 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16831683 PipelineLayout m_pipelineLayout{};
16841684 VertexBuffer<Geometry::Vertex> m_drawBuffer{};
16851685 std::array<float , 4 > m_clearColor;
1686+ bool m_enableMirrorWindow = false ;
16861687
1687- #if defined(USE_MIRROR_WINDOW )
1688+ #if defined(VK_USE_PLATFORM_WIN32_KHR )
16881689 Swapchain m_swapchain{};
16891690#endif
16901691
0 commit comments