Skip to content

Commit ae5b6bd

Browse files
committed
Add an ifdef for DXGI interop.
If Granite is used externally, it just complicates things.
1 parent 50f35d3 commit ae5b6bd

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

vulkan/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_granite_internal_lib(granite-vulkan
3131

3232
if (WIN32)
3333
target_sources(granite-vulkan PRIVATE wsi_dxgi.cpp wsi_dxgi.hpp)
34+
target_compile_definitions(granite-vulkan PUBLIC HAVE_WSI_DXGI_INTEROP)
3435
endif()
3536

3637
target_include_directories(granite-vulkan PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

vulkan/wsi.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ bool WSI::init_device()
168168
device->set_context(*context);
169169
platform->event_device_created(device.get());
170170

171-
#ifdef _WIN32
171+
#ifdef HAVE_WSI_DXGI_INTEROP
172172
dxgi.reset(new DXGIInteropSwapchain);
173173
if (!dxgi->init_interop_device(*device))
174174
dxgi.reset();
@@ -184,7 +184,7 @@ bool WSI::init_device(DeviceHandle device_handle)
184184
device = std::move(device_handle);
185185
platform->event_device_created(device.get());
186186

187-
#ifdef _WIN32
187+
#ifdef HAVE_WSI_DXGI_INTEROP
188188
dxgi.reset(new DXGIInteropSwapchain);
189189
if (!dxgi->init_interop_device(*device))
190190
dxgi.reset();
@@ -194,7 +194,7 @@ bool WSI::init_device(DeviceHandle device_handle)
194194
return true;
195195
}
196196

197-
#ifdef _WIN32
197+
#ifdef HAVE_WSI_DXGI_INTEROP
198198
bool WSI::init_surface_swapchain_dxgi(unsigned width, unsigned height)
199199
{
200200
if (!dxgi)
@@ -270,7 +270,7 @@ bool WSI::init_surface_swapchain()
270270
unsigned width = platform->get_surface_width();
271271
unsigned height = platform->get_surface_height();
272272

273-
#ifdef _WIN32
273+
#ifdef HAVE_WSI_DXGI_INTEROP
274274
if (init_surface_swapchain_dxgi(width, height))
275275
return true;
276276
else
@@ -468,7 +468,7 @@ void WSI::drain_swapchain(bool in_tear_down)
468468

469469
void WSI::tear_down_swapchain()
470470
{
471-
#ifdef _WIN32
471+
#ifdef HAVE_WSI_DXGI_INTEROP
472472
// We only do explicit teardown on exit.
473473
dxgi.reset();
474474
#endif
@@ -573,7 +573,7 @@ void WSI::set_low_latency_mode(bool enable)
573573
low_latency_mode_enable = enable;
574574
}
575575

576-
#ifdef _WIN32
576+
#ifdef HAVE_WSI_DXGI_INTEROP
577577
bool WSI::begin_frame_dxgi()
578578
{
579579
Semaphore acquire;
@@ -639,7 +639,7 @@ bool WSI::begin_frame()
639639
LOGI("Waited for vacant frame context for %.3f ms.\n", (next_frame_end - next_frame_start) * 1e-6);
640640
#endif
641641

642-
#ifdef _WIN32
642+
#ifdef HAVE_WSI_DXGI_INTEROP
643643
if (dxgi)
644644
{
645645
if (platform->should_resize())
@@ -763,7 +763,7 @@ bool WSI::begin_frame()
763763
return true;
764764
}
765765

766-
#ifdef _WIN32
766+
#ifdef HAVE_WSI_DXGI_INTEROP
767767
bool WSI::end_frame_dxgi()
768768
{
769769
auto release = device->consume_release_semaphore();
@@ -793,7 +793,7 @@ bool WSI::end_frame()
793793

794794
has_acquired_swapchain_index = false;
795795

796-
#ifdef _WIN32
796+
#ifdef HAVE_WSI_DXGI_INTEROP
797797
if (dxgi)
798798
return end_frame_dxgi();
799799
#endif
@@ -935,7 +935,7 @@ void WSI::update_framebuffer(unsigned width, unsigned height)
935935
{
936936
if (context && device)
937937
{
938-
#ifdef _WIN32
938+
#ifdef HAVE_WSI_DXGI_INTEROP
939939
if (dxgi)
940940
{
941941
if (!init_surface_swapchain_dxgi(width, height))
@@ -963,7 +963,7 @@ bool WSI::update_active_presentation_mode(PresentMode mode)
963963
if (current_present_mode == mode)
964964
return true;
965965

966-
#ifdef _WIN32
966+
#ifdef HAVE_WSI_DXGI_INTEROP
967967
// We set this on Present time.
968968
if (dxgi)
969969
{

vulkan/wsi.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <chrono>
3232
#include <memory>
3333

34-
#ifdef _WIN32
34+
#ifdef HAVE_WSI_DXGI_INTEROP
3535
#include "wsi_dxgi.hpp"
3636
#endif
3737

@@ -368,7 +368,7 @@ class WSI
368368

369369
VkSurfaceFormatKHR find_suitable_present_format(const std::vector<VkSurfaceFormatKHR> &formats, BackbufferFormat desired_format) const;
370370

371-
#ifdef _WIN32
371+
#ifdef HAVE_WSI_DXGI_INTEROP
372372
std::unique_ptr<DXGIInteropSwapchain> dxgi;
373373
bool init_surface_swapchain_dxgi(unsigned width, unsigned height);
374374
bool begin_frame_dxgi();

0 commit comments

Comments
 (0)