Skip to content

Commit 9d25045

Browse files
authored
Merge pull request #130 from Themaister/dxgi-interop-experiment
DXGI interop experiment
2 parents ea9038d + a63bce6 commit 9d25045

File tree

9 files changed

+860
-33
lines changed

9 files changed

+860
-33
lines changed

application/platforms/application_sdl3.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,19 @@ struct WSIPlatformSDL : GraniteWSIPlatform
259259
});
260260
}
261261

262+
uintptr_t get_native_window() override
263+
{
264+
#ifdef _WIN32
265+
SDL_PropertiesID props = SDL_GetWindowProperties(window);
266+
SDL_LockProperties(props);
267+
auto hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
268+
SDL_UnlockProperties(props);
269+
return reinterpret_cast<uintptr_t>(hwnd);
270+
#else
271+
return 0;
272+
#endif
273+
}
274+
262275
void toggle_fullscreen()
263276
{
264277
bool is_fullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
@@ -389,25 +402,12 @@ struct WSIPlatformSDL : GraniteWSIPlatform
389402

390403
void notify_resize(unsigned width_, unsigned height_)
391404
{
392-
uint64_t current_resize_timestamp = swapchain_dimension_update_timestamp;
393-
405+
LOGI("Resize: %u x %u\n", width_, height_);
394406
push_task_to_async_thread([=]() {
395407
resize = true;
396408
width = width_;
397409
height = height_;
398410
});
399-
400-
if (options.threaded)
401-
{
402-
// Give the async thread a chance to catch up with main thread so it can create a new swapchain before
403-
// we invalidate the swapchain again.
404-
// There is a gap when querying swapchain dimensions and when we create the swapchain.
405-
// On most platforms, the query must match the swapchain,
406-
// so if we keep processing OS events, things will get out of sync.
407-
// Need to observe that the async thread updates the swapchain dimensions at least once.
408-
while (current_resize_timestamp == swapchain_dimension_update_timestamp && async_loop_alive)
409-
process_events_main_thread_blocking();
410-
}
411411
}
412412

413413
void notify_current_swapchain_dimensions(unsigned width_, unsigned height_) override

third_party/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ if ((NOT ANDROID) AND (${GRANITE_PLATFORM} MATCHES "SDL"))
102102
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
103103
set(SDL_STATIC ON CACHE BOOL "" FORCE)
104104
set(SDL_TIMERS ON CACHE BOOL "" FORCE)
105+
set(SDL_LIBC ON CACHE BOOL "" FORCE)
105106
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
106107
set(SDL_DISABLE_INSTALL ON CACHE BOOL "" FORCE)
107108
# Disable everything we don't care about.

third_party/sdl3

Submodule sdl3 updated 425 files

util/thread_name.cpp

+19-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#ifdef __linux__
2626
#include <pthread.h>
27+
#else
28+
#define WIN32_LEAN_AND_MEAN
29+
#include <windows.h>
30+
#include <string>
2731
#endif
2832

2933
namespace Util
@@ -33,8 +37,21 @@ void set_current_thread_name(const char *name)
3337
#ifdef __linux__
3438
pthread_setname_np(pthread_self(), name);
3539
#else
36-
// TODO: Kinda messy.
37-
(void)name;
40+
using PFN_SetThreadDescription = HRESULT (WINAPI *)(HANDLE, PCWSTR);
41+
auto module = GetModuleHandleA("kernel32.dll");
42+
PFN_SetThreadDescription SetThreadDescription = module ? reinterpret_cast<PFN_SetThreadDescription>(
43+
(void *)GetProcAddress(module, "SetThreadDescription")) : nullptr;
44+
45+
if (SetThreadDescription)
46+
{
47+
std::wstring wname;
48+
while (*name != '\0')
49+
{
50+
wname.push_back(*name);
51+
name++;
52+
}
53+
SetThreadDescription(GetCurrentThread(), wname.c_str());
54+
}
3855
#endif
3956
}
4057
}

vulkan/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ add_granite_internal_lib(granite-vulkan
2929
query_pool.cpp query_pool.hpp
3030
texture/texture_format.cpp texture/texture_format.hpp)
3131

32+
if (WIN32)
33+
target_sources(granite-vulkan PRIVATE wsi_dxgi.cpp wsi_dxgi.hpp)
34+
endif()
35+
3236
target_include_directories(granite-vulkan PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
3337

3438
if (GRANITE_RENDERDOC_CAPTURE)

0 commit comments

Comments
 (0)