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};
@@ -1280,7 +1275,7 @@ void Swapchain::Present(VkQueue queue, VkSemaphore drawComplete) {
12801275 }
12811276 CHECK_VKRESULT (res, " vkQueuePresentKHR" );
12821277}
1283- #endif // defined(USE_MIRROR_WINDOW )
1278+ #endif // defined(VK_USE_PLATFORM_WIN32_KHR )
12841279
12851280struct VulkanGraphicsPlugin : public IGraphicsPlugin {
12861281 VulkanGraphicsPlugin (const std::shared_ptr<Options>& options, std::shared_ptr<IPlatformPlugin> /* unused*/ )
@@ -1369,14 +1364,12 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
13691364 }
13701365 // TODO add back VK_EXT_debug_report code for compatibility with older systems? (Android)
13711366 }
1372- #if defined(USE_MIRROR_WINDOW)
1373- extensions.push_back (" VK_KHR_surface" );
13741367#if defined(VK_USE_PLATFORM_WIN32_KHR)
1375- extensions.push_back (" VK_KHR_win32_surface" );
1376- #else
1377- #error CreateSurface not supported on this OS
1368+ if (m_enableMirrorWindow) {
1369+ extensions.push_back (" VK_KHR_surface" );
1370+ extensions.push_back (" VK_KHR_win32_surface" );
1371+ }
13781372#endif // defined(VK_USE_PLATFORM_WIN32_KHR)
1379- #endif // defined(USE_MIRROR_WINDOW)
13801373
13811374 VkDebugUtilsMessengerCreateInfoEXT debugInfo{VK_STRUCTURE_TYPE_DEBUG_UTILS_MESSENGER_CREATE_INFO_EXT};
13821375 debugInfo.messageSeverity = VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT;
@@ -1446,8 +1439,10 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
14461439 VkPhysicalDeviceFeatures features{};
14471440 // features.samplerAnisotropy = VK_TRUE;
14481441
1449- #if defined(USE_MIRROR_WINDOW)
1450- deviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1442+ #if defined(VK_USE_PLATFORM_WIN32_KHR)
1443+ if (m_enableMirrorWindow) {
1444+ deviceExtensions.push_back (VK_KHR_SWAPCHAIN_EXTENSION_NAME);
1445+ }
14511446#endif
14521447
14531448 VkDeviceCreateInfo deviceInfo{VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO};
@@ -1540,15 +1535,17 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
15401535 m_drawBuffer.UpdateIndices (Geometry::c_cubeIndices, numCubeIdicies, 0 );
15411536 m_drawBuffer.UpdateVertices (Geometry::c_cubeVertices, numCubeVerticies, 0 );
15421537
1543- #if defined(USE_MIRROR_WINDOW)
1544- m_swapchain.Create (m_vkInstance, m_vkPhysicalDevice, m_vkDevice, m_graphicsBinding.queueFamilyIndex );
1545-
1546- m_cmdBuffer.Reset ();
1547- m_cmdBuffer.Begin ();
1548- m_swapchain.Prepare (m_cmdBuffer.buf );
1549- m_cmdBuffer.End ();
1550- m_cmdBuffer.Exec (m_vkQueue);
1551- m_cmdBuffer.Wait ();
1538+ #if defined(VK_USE_PLATFORM_WIN32_KHR)
1539+ if (m_enableMirrorWindow) {
1540+ m_swapchain.Create (m_vkInstance, m_vkPhysicalDevice, m_vkDevice, m_graphicsBinding.queueFamilyIndex );
1541+
1542+ m_cmdBuffer.Reset ();
1543+ m_cmdBuffer.Begin ();
1544+ m_swapchain.Prepare (m_cmdBuffer.buf );
1545+ m_cmdBuffer.End ();
1546+ m_cmdBuffer.Exec (m_vkQueue);
1547+ m_cmdBuffer.Wait ();
1548+ }
15521549#endif
15531550 }
15541551
@@ -1658,9 +1655,9 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16581655 m_cmdBuffer.End ();
16591656 m_cmdBuffer.Exec (m_vkQueue);
16601657
1661- #if defined(USE_MIRROR_WINDOW )
1658+ #if defined(VK_USE_PLATFORM_WIN32_KHR )
16621659 // Cycle the window's swapchain on the last view rendered
1663- if (swapchainContext == &m_swapchainImageContexts.back ()) {
1660+ if (m_enableMirrorWindow && swapchainContext == &m_swapchainImageContexts.back ()) {
16641661 m_swapchain.Acquire ();
16651662 m_swapchain.Wait ();
16661663 m_swapchain.Present (m_vkQueue);
@@ -1670,7 +1667,10 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16701667
16711668 uint32_t GetSupportedSwapchainSampleCount (const XrViewConfigurationView&) override { return VK_SAMPLE_COUNT_1_BIT; }
16721669
1673- void UpdateOptions (const std::shared_ptr<Options>& options) override { m_clearColor = options->GetBackgroundClearColor (); }
1670+ void UpdateOptions (const std::shared_ptr<Options>& options) override {
1671+ m_clearColor = options->GetBackgroundClearColor ();
1672+ m_enableMirrorWindow = options->EnableMirrorWindow ;
1673+ }
16741674
16751675 protected:
16761676 XrGraphicsBindingVulkan2KHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR};
@@ -1691,8 +1691,9 @@ struct VulkanGraphicsPlugin : public IGraphicsPlugin {
16911691 PipelineLayout m_pipelineLayout{};
16921692 VertexBuffer<Geometry::Vertex> m_drawBuffer{};
16931693 std::array<float , 4 > m_clearColor;
1694+ bool m_enableMirrorWindow = false ;
16941695
1695- #if defined(USE_MIRROR_WINDOW )
1696+ #if defined(VK_USE_PLATFORM_WIN32_KHR )
16961697 Swapchain m_swapchain{};
16971698#endif
16981699
0 commit comments