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,14 @@ 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" );
1357+ if (m_enableMirrorWindow) {
1358+ extensions.push_back (" VK_KHR_surface" );
13641359#if defined(VK_USE_PLATFORM_WIN32_KHR)
1365- extensions.push_back (" VK_KHR_win32_surface" );
1360+ extensions.push_back (" VK_KHR_win32_surface" );
13661361#else
13671362#error CreateSurface not supported on this OS
13681363#endif // defined(VK_USE_PLATFORM_WIN32_KHR)
1369- # endif // defined(USE_MIRROR_WINDOW)
1364+ }
13701365
13711366 VkApplicationInfo appInfo{VK_STRUCTURE_TYPE_APPLICATION_INFO};
13721367 appInfo.pApplicationName = " hello_xr" ;
@@ -1438,9 +1433,9 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
14381433 VkPhysicalDeviceFeatures features{};
14391434 // features.samplerAnisotropy = VK_TRUE;
14401435
1441- # if defined(USE_MIRROR_WINDOW)
1442- deviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1443- # endif
1436+ if (m_enableMirrorWindow) {
1437+ deviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1438+ }
14441439
14451440 VkDeviceCreateInfo deviceInfo{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
14461441 deviceInfo.queueCreateInfoCount = 1 ;
@@ -1532,16 +1527,16 @@ 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 );
1530+ if (m_enableMirrorWindow) {
1531+ m_swapchain.Create (m_vkInstance, m_vkPhysicalDevice, m_vkDevice, m_graphicsBinding.queueFamilyIndex );
15371532
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 ();
1544- # endif
1533+ m_cmdBuffer.Reset ();
1534+ m_cmdBuffer.Begin ();
1535+ m_swapchain.Prepare (m_cmdBuffer.buf );
1536+ m_cmdBuffer.End ();
1537+ m_cmdBuffer.Exec (m_vkQueue);
1538+ m_cmdBuffer.Wait ();
1539+ }
15451540 }
15461541
15471542 int64_t SelectColorSwapchainFormat (const std::vector<int64_t >& runtimeFormats) const override {
@@ -1651,18 +1646,19 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16511646 m_cmdBuffer.End ();
16521647 m_cmdBuffer.Exec (m_vkQueue);
16531648
1654- #if defined(USE_MIRROR_WINDOW)
16551649 // Cycle the window's swapchain on the last view rendered
1656- if (swapchainContext == &m_swapchainImageContexts.back ()) {
1650+ if (m_enableMirrorWindow && swapchainContext == &m_swapchainImageContexts.back ()) {
16571651 m_swapchain.Acquire ();
16581652 m_swapchain.Present (m_vkQueue);
16591653 }
1660- #endif
16611654 }
16621655
16631656 uint32_t GetSupportedSwapchainSampleCount (const XrViewConfigurationView&) override { return VK_SAMPLE_COUNT_1_BIT; }
16641657
1665- void UpdateOptions (const std::shared_ptr<Options>& options) override { m_clearColor = options->GetBackgroundClearColor (); }
1658+ void UpdateOptions (const std::shared_ptr<Options>& options) override {
1659+ m_clearColor = options->GetBackgroundClearColor ();
1660+ m_enableMirrorWindow = options->EnableMirrorWindow ;
1661+ }
16661662
16671663 protected:
16681664 XrGraphicsBindingVulkan2KHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR};
@@ -1683,8 +1679,9 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16831679 PipelineLayout m_pipelineLayout{};
16841680 VertexBuffer<Geometry::Vertex> m_drawBuffer{};
16851681 std::array<float , 4 > m_clearColor;
1682+ bool m_enableMirrorWindow = false ;
16861683
1687- #if defined(USE_MIRROR_WINDOW )
1684+ #if defined(VK_USE_PLATFORM_WIN32_KHR )
16881685 Swapchain m_swapchain{};
16891686#endif
16901687
0 commit comments