Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DXGI interop experiment #130

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions application/platforms/application_sdl3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@ struct WSIPlatformSDL : GraniteWSIPlatform
});
}

uintptr_t get_native_window() override
{
#ifdef _WIN32
SDL_PropertiesID props = SDL_GetWindowProperties(window);
SDL_LockProperties(props);
auto hwnd = static_cast<HWND>(SDL_GetProperty(props, "SDL.window.win32.hwnd", nullptr));
SDL_UnlockProperties(props);
return reinterpret_cast<uintptr_t>(hwnd);
#else
return 0;
#endif
}

void toggle_fullscreen()
{
bool is_fullscreen = (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN) != 0;
Expand Down Expand Up @@ -389,25 +402,12 @@ struct WSIPlatformSDL : GraniteWSIPlatform

void notify_resize(unsigned width_, unsigned height_)
{
uint64_t current_resize_timestamp = swapchain_dimension_update_timestamp;

LOGI("Resize: %u x %u\n", width_, height_);
push_task_to_async_thread([=]() {
resize = true;
width = width_;
height = height_;
});

if (options.threaded)
{
// Give the async thread a chance to catch up with main thread so it can create a new swapchain before
// we invalidate the swapchain again.
// There is a gap when querying swapchain dimensions and when we create the swapchain.
// On most platforms, the query must match the swapchain,
// so if we keep processing OS events, things will get out of sync.
// Need to observe that the async thread updates the swapchain dimensions at least once.
while (current_resize_timestamp == swapchain_dimension_update_timestamp && async_loop_alive)
process_events_main_thread_blocking();
}
}

void notify_current_swapchain_dimensions(unsigned width_, unsigned height_) override
Expand Down
1 change: 1 addition & 0 deletions third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if ((NOT ANDROID) AND (${GRANITE_PLATFORM} MATCHES "SDL"))
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_TIMERS ON CACHE BOOL "" FORCE)
set(SDL_LIBC ON CACHE BOOL "" FORCE)
set(SDL_TEST_LIBRARY OFF CACHE BOOL "" FORCE)
set(SDL_DISABLE_INSTALL ON CACHE BOOL "" FORCE)
# Disable everything we don't care about.
Expand Down
2 changes: 1 addition & 1 deletion third_party/sdl3
Submodule sdl3 updated 425 files
21 changes: 19 additions & 2 deletions util/thread_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

#ifdef __linux__
#include <pthread.h>
#else
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
#endif

namespace Util
Expand All @@ -33,8 +37,21 @@ void set_current_thread_name(const char *name)
#ifdef __linux__
pthread_setname_np(pthread_self(), name);
#else
// TODO: Kinda messy.
(void)name;
using PFN_SetThreadDescription = HRESULT (WINAPI *)(HANDLE, PCWSTR);
auto module = GetModuleHandleA("kernel32.dll");
PFN_SetThreadDescription SetThreadDescription = module ? reinterpret_cast<PFN_SetThreadDescription>(
(void *)GetProcAddress(module, "SetThreadDescription")) : nullptr;

if (SetThreadDescription)
{
std::wstring wname;
while (*name != '\0')
{
wname.push_back(*name);
name++;
}
SetThreadDescription(GetCurrentThread(), wname.c_str());
}
#endif
}
}
4 changes: 4 additions & 0 deletions vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ add_granite_internal_lib(granite-vulkan
query_pool.cpp query_pool.hpp
texture/texture_format.cpp texture/texture_format.hpp)

if (WIN32)
target_sources(granite-vulkan PRIVATE wsi_dxgi.cpp wsi_dxgi.hpp)
endif()

target_include_directories(granite-vulkan PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

if (GRANITE_RENDERDOC_CAPTURE)
Expand Down
Loading
Loading