Skip to content

Commit 00f5da3

Browse files
utzcozrpavlik
authored andcommitted
hello_xr: Make Vulkan's mirror window optional
The Vulkan's mirror window is disabled default, and we use "--mirrorwindow|-mw true" to enable it. Signed-off-by: utzcoz <[email protected]>
1 parent 88095bc commit 00f5da3

File tree

4 files changed

+44
-36
lines changed

4 files changed

+44
-36
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello_xr: Make Vulkan's mirror window optional

src/tests/hello_xr/graphicsplugin_vulkan.cpp

Lines changed: 29 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};
@@ -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

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

src/tests/hello_xr/main.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ bool UpdateOptionsFromSystemProperties(Options& options) {
6666
#else
6767
void ShowHelp() {
6868
// TODO: Improve/update when things are more settled.
69-
Log::Write(Log::Level::Info,
70-
"HelloXr --graphics|-g <Graphics API> [--formfactor|-ff <Form factor>] [--viewconfig|-vc <View config>] "
71-
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--verbose|-v]");
72-
Log::Write(Log::Level::Info, "Graphics APIs: D3D11, D3D12, OpenGLES, OpenGL, Vulkan2, Vulkan, Metal");
73-
Log::Write(Log::Level::Info, "Form factors: Hmd, Handheld");
74-
Log::Write(Log::Level::Info, "View configurations: Mono, Stereo");
75-
Log::Write(Log::Level::Info, "Environment blend modes: Opaque, Additive, AlphaBlend");
76-
Log::Write(Log::Level::Info, "Spaces: View, Local, Stage");
69+
Log::Write(
70+
Log::Level::Info,
71+
"HelloXr --graphics|-g <Graphics API> [--formfactor|-ff <Form factor>] [--viewconfig|-vc <View config>] "
72+
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--mirrorwindow|-mw <Enable Vulkan Mirror Window>] [--verbose|-v]");
73+
Log::Write(Log::Level::Info, "Graphics APIs: D3D11, D3D12, OpenGLES, OpenGL, Vulkan2, Vulkan, Metal");
74+
Log::Write(Log::Level::Info, "Form factors: Hmd, Handheld");
75+
Log::Write(Log::Level::Info, "View configurations: Mono, Stereo");
76+
Log::Write(Log::Level::Info, "Environment blend modes: Opaque, Additive, AlphaBlend");
77+
Log::Write(Log::Level::Info, "Spaces: View, Local, Stage");
78+
Log::Write(Log::Level::Info, "Enable Vulkan Mirror Window: true, false");
7779
}
7880

7981
bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
@@ -99,6 +101,8 @@ bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
99101
options.EnvironmentBlendMode = getNextArg();
100102
} else if (EqualsIgnoreCase(arg, "--space") || EqualsIgnoreCase(arg, "-s")) {
101103
options.AppSpace = getNextArg();
104+
} else if (EqualsIgnoreCase(arg, "--mirrorwindow") || EqualsIgnoreCase(arg, "-mw")) {
105+
options.EnableMirrorWindow = EqualsIgnoreCase(getNextArg(), "true");
102106
} else if (EqualsIgnoreCase(arg, "--verbose") || EqualsIgnoreCase(arg, "-v")) {
103107
Log::SetLevel(Log::Level::Verbose);
104108
} 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)