Skip to content

Commit f7169d4

Browse files
committed
hello_xr: Make Vulkan's mirror window optional
The Vulkan's mirror window is disabled default. Signed-off-by: utzcoz <[email protected]>
1 parent f122f9f commit f7169d4

File tree

3 files changed

+31
-29
lines changed

3 files changed

+31
-29
lines changed

src/tests/hello_xr/graphicsplugin_vulkan.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
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
10481043
struct 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

12751270
struct 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

src/tests/hello_xr/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,13 @@ void ShowHelp() {
6868
// TODO: Improve/update when things are more settled.
6969
Log::Write(Log::Level::Info,
7070
"HelloXr --graphics|-g <Graphics API> [--formfactor|-ff <Form factor>] [--viewconfig|-vc <View config>] "
71-
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--verbose|-v]");
71+
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--mirrorwindow|-mw <Mirror Window>] [--verbose|-v]");
7272
Log::Write(Log::Level::Info, "Graphics APIs: D3D11, D3D12, OpenGLES, OpenGL, Vulkan2, Vulkan");
7373
Log::Write(Log::Level::Info, "Form factors: Hmd, Handheld");
7474
Log::Write(Log::Level::Info, "View configurations: Mono, Stereo");
7575
Log::Write(Log::Level::Info, "Environment blend modes: Opaque, Additive, AlphaBlend");
7676
Log::Write(Log::Level::Info, "Spaces: View, Local, Stage");
77+
Log::Write(Log::Level::Info, "Enable Mirror Window: true, false");
7778
}
7879

7980
bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
@@ -99,6 +100,8 @@ bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
99100
options.EnvironmentBlendMode = getNextArg();
100101
} else if (EqualsIgnoreCase(arg, "--space") || EqualsIgnoreCase(arg, "-s")) {
101102
options.AppSpace = getNextArg();
103+
} else if (EqualsIgnoreCase(arg, "--mirrorwindow") || EqualsIgnoreCase(arg, "-mw")) {
104+
options.EnableMirrorWindow = EqualsIgnoreCase(getNextArg(), "true");
102105
} else if (EqualsIgnoreCase(arg, "--verbose") || EqualsIgnoreCase(arg, "-v")) {
103106
Log::SetLevel(Log::Level::Verbose);
104107
} else if (EqualsIgnoreCase(arg, "--help") || EqualsIgnoreCase(arg, "-h")) {

src/tests/hello_xr/options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ struct Options {
6363

6464
std::string AppSpace{"Local"};
6565

66+
bool EnableMirrorWindow = false;
67+
6668
struct {
6769
XrFormFactor FormFactor{XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY};
6870

0 commit comments

Comments
 (0)